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 */
018
019package org.apache.hadoop.hbase.trace;
020
021import org.apache.hadoop.conf.Configuration;
022import org.apache.htrace.core.HTraceConfiguration;
023import org.apache.yetus.audience.InterfaceAudience;
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026
027@InterfaceAudience.Private
028public class HBaseHTraceConfiguration extends HTraceConfiguration {
029  private static final Logger LOG = LoggerFactory.getLogger(HBaseHTraceConfiguration.class);
030
031  public static final String KEY_PREFIX = "hbase.htrace.";
032
033  private Configuration conf;
034
035  private void handleDeprecation(String key) {
036    String oldKey = "hbase." + key;
037    String newKey = KEY_PREFIX + key;
038    String oldValue = conf.get(oldKey);
039    if (oldValue != null) {
040      LOG.warn("Warning: using deprecated configuration key " + oldKey +
041          ".  Please use " + newKey + " instead.");
042      String newValue = conf.get(newKey);
043      if (newValue == null) {
044        conf.set(newKey, oldValue);
045      } else {
046        LOG.warn("Conflicting values for " + newKey + " and " + oldKey +
047            ".  Using " + newValue);
048      }
049    }
050  }
051
052  public HBaseHTraceConfiguration(Configuration conf) {
053    this.conf = conf;
054    handleDeprecation("local-file-span-receiver.path");
055    handleDeprecation("local-file-span-receiver.capacity");
056    handleDeprecation("sampler.frequency");
057    handleDeprecation("sampler.fraction");
058    handleDeprecation("zipkin.collector-hostname");
059    handleDeprecation("zipkin.collector-port");
060    handleDeprecation("zipkin.num-threads");
061    handleDeprecation("zipkin.traced-service-hostname");
062    handleDeprecation("zipkin.traced-service-port");
063  }
064
065  @Override
066  public String get(String key) {
067    return conf.get(KEY_PREFIX + key);
068  }
069
070  @Override
071  public String get(String key, String defaultValue) {
072    return conf.get(KEY_PREFIX + key,defaultValue);
073
074  }
075
076  @Override
077  public boolean getBoolean(String key, boolean defaultValue) {
078    return conf.getBoolean(KEY_PREFIX + key, defaultValue);
079  }
080}