HBASE-21843 RegionGroupingProvider breaks the meta wal file name pattern which may...
[hbase.git] / hbase-server / src / main / java / org / apache / hadoop / hbase / util / ServerCommandLine.java
blobf99a0908cd6a8af9f407b51460710ec2d41748f6
1 /**
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 package org.apache.hadoop.hbase.util;
21 import java.lang.management.ManagementFactory;
22 import java.lang.management.RuntimeMXBean;
23 import java.util.Arrays;
24 import java.util.HashSet;
25 import java.util.Locale;
26 import java.util.Map.Entry;
27 import java.util.Set;
29 import org.apache.hadoop.hbase.HConstants;
30 import org.apache.hadoop.conf.Configuration;
31 import org.apache.hadoop.conf.Configured;
32 import org.apache.hadoop.hbase.HBaseConfiguration;
33 import org.apache.hadoop.util.Tool;
34 import org.apache.hadoop.util.ToolRunner;
35 import org.apache.yetus.audience.InterfaceAudience;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 /**
41 * Base class for command lines that start up various HBase daemons.
43 @InterfaceAudience.Private
44 public abstract class ServerCommandLine extends Configured implements Tool {
45 private static final Logger LOG = LoggerFactory.getLogger(ServerCommandLine.class);
46 @SuppressWarnings("serial")
47 private static final Set<String> DEFAULT_SKIP_WORDS = new HashSet<String>() {
49 add("secret");
50 add("passwd");
51 add("password");
52 add("credential");
56 /**
57 * Implementing subclasses should return a usage string to print out.
59 protected abstract String getUsage();
61 /**
62 * Print usage information for this command line.
64 * @param message if not null, print this message before the usage info.
66 protected void usage(String message) {
67 if (message != null) {
68 System.err.println(message);
69 System.err.println("");
72 System.err.println(getUsage());
75 /**
76 * Log information about the currently running JVM.
78 public static void logJVMInfo() {
79 // Print out vm stats before starting up.
80 RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
81 if (runtime != null) {
82 LOG.info("vmName=" + runtime.getVmName() + ", vmVendor=" +
83 runtime.getVmVendor() + ", vmVersion=" + runtime.getVmVersion());
84 LOG.info("vmInputArguments=" + runtime.getInputArguments());
88 /**
89 * Print into log some of the important hbase attributes.
91 private static void logHBaseConfigs(Configuration conf) {
92 final String [] keys = new String [] {
93 // Expand this list as you see fit.
94 "hbase.tmp.dir",
95 HConstants.HBASE_DIR,
96 HConstants.CLUSTER_DISTRIBUTED,
97 HConstants.ZOOKEEPER_QUORUM,
100 for (String key: keys) {
101 LOG.info(key + ": " + conf.get(key));
106 * Logs information about the currently running JVM process including
107 * the environment variables. Logging of env vars can be disabled by
108 * setting {@code "hbase.envvars.logging.disabled"} to {@code "true"}.
109 * <p>If enabled, you can also exclude environment variables containing
110 * certain substrings by setting {@code "hbase.envvars.logging.skipwords"}
111 * to comma separated list of such substrings.
113 public static void logProcessInfo(Configuration conf) {
114 logHBaseConfigs(conf);
116 // log environment variables unless asked not to
117 if (conf == null || !conf.getBoolean("hbase.envvars.logging.disabled", false)) {
118 Set<String> skipWords = new HashSet<>(DEFAULT_SKIP_WORDS);
119 if (conf != null) {
120 String[] confSkipWords = conf.getStrings("hbase.envvars.logging.skipwords");
121 if (confSkipWords != null) {
122 skipWords.addAll(Arrays.asList(confSkipWords));
126 nextEnv:
127 for (Entry<String, String> entry : System.getenv().entrySet()) {
128 String key = entry.getKey().toLowerCase(Locale.ROOT);
129 String value = entry.getValue().toLowerCase(Locale.ROOT);
130 // exclude variables which may contain skip words
131 for(String skipWord : skipWords) {
132 if (key.contains(skipWord) || value.contains(skipWord))
133 continue nextEnv;
135 LOG.info("env:"+entry);
139 // and JVM info
140 logJVMInfo();
144 * Parse and run the given command line. This may exit the JVM if
145 * a nonzero exit code is returned from <code>run()</code>.
147 public void doMain(String args[]) {
148 try {
149 int ret = ToolRunner.run(HBaseConfiguration.create(), this, args);
150 if (ret != 0) {
151 System.exit(ret);
153 } catch (Exception e) {
154 LOG.error("Failed to run", e);
155 System.exit(-1);