001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.master.http.api_v1;
019
020import org.apache.hadoop.conf.Configuration;
021import org.apache.hadoop.hbase.http.jersey.ResponseEntityMapper;
022import org.apache.hadoop.hbase.master.HMaster;
023import org.apache.hadoop.hbase.master.http.gson.GsonSerializationFeature;
024import org.apache.hadoop.hbase.master.http.jersey.MasterFeature;
025import org.apache.yetus.audience.InterfaceAudience;
026
027import org.apache.hbase.thirdparty.org.glassfish.jersey.server.ResourceConfig;
028import org.apache.hbase.thirdparty.org.glassfish.jersey.server.ServerProperties;
029import org.apache.hbase.thirdparty.org.glassfish.jersey.server.TracingConfig;
030
031/**
032 * Encapsulates construction and configuration of the {@link ResourceConfig} that implements the
033 * {@code cluster-metrics} endpoints.
034 */
035@InterfaceAudience.Private
036public final class ResourceConfigFactory {
037
038  private ResourceConfigFactory() {
039  }
040
041  public static ResourceConfig createResourceConfig(Configuration conf, HMaster master) {
042    return new ResourceConfig().setApplicationName("api_v1")
043      .packages(ResourceConfigFactory.class.getPackage().getName())
044      // TODO: anything registered here that does not have necessary bindings won't inject properly
045      // at annotation sites and will result in a WARN logged by o.a.h.t.o.g.j.i.inject.Providers.
046      // These warnings should be treated by the service as fatal errors, but I have not found a
047      // callback API for registering a failed binding handler.
048      .register(ResponseEntityMapper.class).register(GsonSerializationFeature.class)
049      .register(new MasterFeature(master))
050
051      // devs: enable TRACING to see how jersey is dispatching to resources.
052      // in hbase-site.xml, set 'hbase.http.jersey.tracing.type=ON_DEMAND` and
053      // to curl, add `-H X-Jersey-Tracing-Accept:true`
054      .property(ServerProperties.TRACING,
055        conf.get("hbase.http.jersey.tracing.type", TracingConfig.OFF.name()))
056      .property(ServerProperties.TRACING_THRESHOLD,
057        conf.get("hbase.http.jersey.tracing.threshold", "TRACE"));
058  }
059}