Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SentryServicePinger.java
Go to the documentation of this file.
1 // Copyright 2014 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.testutil;
16 
17 import org.apache.commons.cli.BasicParser;
18 import org.apache.commons.cli.CommandLine;
19 import org.apache.commons.cli.OptionBuilder;
20 import org.apache.commons.cli.Options;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 
27 
34 public class SentryServicePinger {
35  private final static Logger LOG =
36  LoggerFactory.getLogger(SentryServicePinger.class);
37 
38  // Suppress warnings from OptionBuilder.
39  @SuppressWarnings("static-access")
40  public static void main(String[] args) throws Exception {
41  // Parse command line options to get config file path.
42  Options options = new Options();
43  options.addOption(OptionBuilder.withLongOpt("config_file")
44  .withDescription("Absolute path to a sentry-site.xml config file (string)")
45  .hasArg()
46  .withArgName("CONFIG_FILE")
47  .isRequired()
48  .create('c'));
49  options.addOption(OptionBuilder.withLongOpt("num_pings")
50  .withDescription("Max number of pings to try before failing (int)")
51  .hasArg()
52  .isRequired()
53  .withArgName("NUM_PINGS")
54  .create('n'));
55  options.addOption(OptionBuilder.withLongOpt("sleep_secs")
56  .withDescription("Time (s) to sleep between pings (int)")
57  .hasArg()
58  .withArgName("SLEEP_SECS")
59  .create('s'));
60  BasicParser optionParser = new BasicParser();
61  CommandLine cmdArgs = optionParser.parse(options, args);
62 
63  SentryConfig sentryConfig = new SentryConfig(cmdArgs.getOptionValue("config_file"));
64  int numPings = Integer.parseInt(cmdArgs.getOptionValue("num_pings"));
65  int maxPings = numPings;
66  int sleepSecs = Integer.parseInt(cmdArgs.getOptionValue("sleep_secs"));
67 
68  sentryConfig.loadConfig();
69  while (numPings > 0) {
70  SentryPolicyService policyService = new SentryPolicyService(sentryConfig);
71  try {
72  policyService.listAllRoles(new User(System.getProperty("user.name")));
73  LOG.info("Sentry Service ping succeeded.");
74  System.exit(0);
75  } catch (Exception e) {
76  LOG.error(String.format("Error issing RPC to Sentry Service (attempt %d/%d): ",
77  maxPings - numPings + 1, maxPings), e);
78  Thread.sleep(sleepSecs * 1000);
79  }
80  --numPings;
81  }
82  System.exit(1);
83  }
84 }