ZooKeeperInstance(ClientConfiguration config, ZooCacheFactory zcf) { checkArgument(config != null, "config is null"); // Enable singletons before before getting a zoocache SingletonManager.setMode(Mode.CONNECTOR); this.clientConf = config; this.instanceId = clientConf.get(ClientConfiguration.ClientProperty.INSTANCE_ID); this.instanceName = clientConf.get(ClientConfiguration.ClientProperty.INSTANCE_NAME); if ((instanceId == null) == (instanceName == null)) throw new IllegalArgumentException( "Expected exactly one of instanceName and instanceId to be set; " + (instanceName == null ? "neither" : "both") + " were set"); this.zooKeepers = clientConf.get(ClientConfiguration.ClientProperty.INSTANCE_ZK_HOST); this.zooKeepersSessionTimeOut = (int) ConfigurationTypeHelper .getTimeInMillis(clientConf.get(ClientConfiguration.ClientProperty.INSTANCE_ZK_TIMEOUT)); zooCache = zcf.getZooCache(zooKeepers, zooKeepersSessionTimeOut); if (instanceName != null) { // Validates that the provided instanceName actually exists getInstanceID(); } }
/** * Enable tracing by setting up SpanReceivers for the current process. If host name is null, it * will be determined. If service name is null, the simple name of the class will be used. * Properties required in the client configuration include * {@link org.apache.accumulo.core.client.ClientConfiguration.ClientProperty#TRACE_SPAN_RECEIVERS} * and any properties specific to the span receiver. */ public static void enable(String hostname, String service, ClientConfiguration conf) { String spanReceivers = conf.get(ClientProperty.TRACE_SPAN_RECEIVERS); String zookeepers = conf.get(ClientProperty.INSTANCE_ZK_HOST); long timeout = AccumuloConfiguration .getTimeInMillis(conf.get(ClientProperty.INSTANCE_ZK_TIMEOUT)); String zkPath = conf.get(ClientProperty.TRACE_ZK_PATH); Map<String,String> properties = conf .getAllPropertiesWithPrefix(ClientProperty.TRACE_SPAN_RECEIVER_PREFIX); enableTracing(hostname, service, spanReceivers, zookeepers, timeout, zkPath, properties); }
protected void updateFromConfiguration(ClientConfiguration conf) { // Get the quality of protection to use final String qopValue = conf.get(ClientProperty.RPC_SASL_QOP); this.qop = QualityOfProtection.get(qopValue); // Add in the SASL properties to a map so we don't have to repeatedly construct this map this.saslProperties.put(Sasl.QOP, this.qop.getQuality()); // The primary from the KRB principal on each server (e.g. primary/instance@realm) this.kerberosServerPrimary = conf.get(ClientProperty.KERBEROS_SERVER_PRIMARY); }
String getTraceZKPath() { return super.getClientConfiguration().get(ClientProperty.TRACE_ZK_PATH); } }
public String getUsername() throws Exception { if (null == username) { final ClientConfiguration clientConf = getClientConfiguration(); if (Boolean.parseBoolean(clientConf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED))) { if (!UserGroupInformation.isSecurityEnabled()) { throw new RuntimeException("Kerberos security is not enabled"); } UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); username = ugi.getUserName(); } else { username = System.getProperty("user.name", "root"); } } return username; }
/** * Automatically update the options to use a KerberosToken when SASL is enabled for RPCs. Don't * overwrite the options if the user has provided something specifically. */ public void updateKerberosCredentials(ClientConfiguration clientConfig) { final boolean clientConfSaslEnabled = Boolean .parseBoolean(clientConfig.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED)); if ((saslEnabled || clientConfSaslEnabled) && null == tokenClassName) { tokenClassName = KerberosToken.CLASS_NAME; // ACCUMULO-3701 We need to ensure we're logged in before parseArgs returns as the MapReduce // Job is going to make a copy of the current user (UGI) // when it is instantiated. if (null != keytabPath) { File keytab = new File(keytabPath); if (!keytab.exists() || !keytab.isFile()) { throw new IllegalArgumentException("Keytab isn't a normal file: " + keytabPath); } if (null == principal) { throw new IllegalArgumentException("Principal must be provided if logging in via Keytab"); } try { UserGroupInformation.loginUserFromKeytab(principal, keytab.getAbsolutePath()); } catch (IOException e) { throw new RuntimeException("Failed to log in with keytab", e); } } } }
public String getInstanceName() { if (clientConf.containsKey(ClientProperty.INSTANCE_NAME.getKey())) { return clientConf.get(ClientProperty.INSTANCE_NAME); } String instanceName = conf.get(ACCUMULO_STANDALONE_INSTANCE_NAME_KEY); if (null == instanceName) { instanceName = ACCUMULO_STANDALONE_INSTANCE_NAME_DEFAULT; } return instanceName; }
public String getZooKeepers() { if (clientConf.containsKey(ClientProperty.INSTANCE_ZK_HOST.getKey())) { return clientConf.get(ClientProperty.INSTANCE_ZK_HOST); } String zookeepers = conf.get(ACCUMULO_STANDALONE_ZOOKEEPERS_KEY); if (null == zookeepers) { zookeepers = ACCUMULO_STANDALONE_ZOOKEEPERS_DEFAULT; } return zookeepers; }
ZooKeeperInstance(Configuration config, ZooCacheFactory zcf) { checkArgument(config != null, "config is null"); if (config instanceof ClientConfiguration) { this.clientConf = (ClientConfiguration) config; } else { @SuppressWarnings("deprecation") ClientConfiguration cliConf = new ClientConfiguration(config); this.clientConf = cliConf; } this.instanceId = clientConf.get(ClientProperty.INSTANCE_ID); this.instanceName = clientConf.get(ClientProperty.INSTANCE_NAME); if ((instanceId == null) == (instanceName == null)) throw new IllegalArgumentException( "Expected exactly one of instanceName and instanceId to be set"); this.zooKeepers = clientConf.get(ClientProperty.INSTANCE_ZK_HOST); this.zooKeepersSessionTimeOut = (int) AccumuloConfiguration .getTimeInMillis(clientConf.get(ClientProperty.INSTANCE_ZK_TIMEOUT)); zooCache = zcf.getZooCache(zooKeepers, zooKeepersSessionTimeOut); if (null != instanceName) { // Validates that the provided instanceName actually exists getInstanceID(); } }
public AuthenticationToken getAuthenticationToken() throws Exception { if (null == authenticationToken) { final ClientConfiguration clientConf = getClientConfiguration(); // Automatically use a KerberosToken if the client conf is configured for SASL final boolean saslEnabled = Boolean .parseBoolean(clientConf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED)); if (saslEnabled) { authenticationToken = new KerberosToken(); } } return authenticationToken; }
/** * Get the ZooKeepers. Use the value passed in (if there was one), then fall back to the * ClientConf, finally trying the accumulo-site.xml. * * @param keepers * ZooKeepers passed to the shell * @param clientConfig * ClientConfiguration instance * @return The ZooKeepers to connect to */ static String getZooKeepers(String keepers, ClientConfiguration clientConfig) { if (null != keepers) { return keepers; } if (clientConfig.containsKey(ClientProperty.INSTANCE_ZK_HOST.getKey())) { return clientConfig.get(ClientProperty.INSTANCE_ZK_HOST); } return SiteConfiguration.getInstance().get(Property.INSTANCE_ZK_HOST); }
private static Instance getZooInstance(String instanceName, String keepersOption, ClientConfiguration clientConfig) { UUID instanceId = null; if (instanceName == null) { instanceName = clientConfig.get(ClientProperty.INSTANCE_NAME); } String keepers = getZooKeepers(keepersOption, clientConfig); if (instanceName == null) { AccumuloConfiguration conf = SiteConfiguration.getInstance(); Path instanceDir = new Path(VolumeConfiguration.getVolumeUris(conf)[0], "instance_id"); instanceId = UUID.fromString(ZooUtil.getInstanceIDFromHdfs(instanceDir, conf)); } if (instanceId != null) { return new ZooKeeperInstance(clientConfig.withInstance(instanceId).withZkHosts(keepers)); } else { return new ZooKeeperInstance(clientConfig.withInstance(instanceName).withZkHosts(keepers)); } }
if (Boolean.parseBoolean(clientConf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED))) { log.debug("SASL is enabled, disabling authorization timeout"); disableAuthTimeout = true;