View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.trace;
20  
21  import org.apache.hadoop.conf.Configuration;
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  import org.apache.htrace.HTraceConfiguration;
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  
27  @InterfaceAudience.Private
28  public class HBaseHTraceConfiguration extends HTraceConfiguration {
29    private static final Log LOG =
30      LogFactory.getLog(HBaseHTraceConfiguration.class);
31  
32    public static final String KEY_PREFIX = "hbase.htrace.";
33  
34    private Configuration conf;
35  
36    private void handleDeprecation(String key) {
37      String oldKey = "hbase." + key;
38      String newKey = KEY_PREFIX + key;
39      String oldValue = conf.get(oldKey);
40      if (oldValue != null) {
41        LOG.warn("Warning: using deprecated configuration key " + oldKey +
42            ".  Please use " + newKey + " instead.");
43        String newValue = conf.get(newKey);
44        if (newValue == null) {
45          conf.set(newKey, oldValue);
46        } else {
47          LOG.warn("Conflicting values for " + newKey + " and " + oldKey +
48              ".  Using " + newValue);
49        }
50      }
51    }
52  
53    public HBaseHTraceConfiguration(Configuration conf) {
54      this.conf = conf;
55      handleDeprecation("local-file-span-receiver.path");
56      handleDeprecation("local-file-span-receiver.capacity");
57      handleDeprecation("sampler.frequency");
58      handleDeprecation("sampler.fraction");
59      handleDeprecation("zipkin.collector-hostname");
60      handleDeprecation("zipkin.collector-port");
61      handleDeprecation("zipkin.num-threads");
62      handleDeprecation("zipkin.traced-service-hostname");
63      handleDeprecation("zipkin.traced-service-port");
64    }
65  
66    @Override
67    public String get(String key) {
68      return conf.get(KEY_PREFIX +key);
69    }
70  
71    @Override
72    public String get(String key, String defaultValue) {
73      return conf.get(KEY_PREFIX + key,defaultValue);
74  
75    }
76  
77    @Override
78    public boolean getBoolean(String key, boolean defaultValue) {
79      return conf.getBoolean(KEY_PREFIX + key, defaultValue);
80    }
81  }