public boolean isEmpty(Properties properties) { Objects.requireNonNull(properties); String value = properties.getProperty(getKey()); return (value == null || value.isEmpty()); }
public void setProperty(ClientProperty property, CharSequence value) { properties.setProperty(property.getKey(), value.toString()); }
private ClientConfigGenerate(PrintStream doc) { Objects.nonNull(doc); this.doc = doc; for (ClientProperty prop : ClientProperty.values()) { this.sortedProps.put(prop.getKey(), prop); } }
protected ClientContext getContextForPeer(AccumuloConfiguration localConf, ReplicationTarget target, String principal, AuthenticationToken token) { requireNonNull(localConf); requireNonNull(target); requireNonNull(principal); requireNonNull(token); Properties properties = new Properties(); properties.setProperty(ClientProperty.INSTANCE_NAME.getKey(), instanceName); properties.setProperty(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), zookeepers); properties.setProperty(ClientProperty.AUTH_PRINCIPAL.getKey(), principal); ClientProperty.setAuthenticationToken(properties, token); return new ClientContext(ClientInfo.from(properties, token), localConf); }
public Properties getClientProperties() { Properties props = new Properties(); if (getClientPropertiesFile() != null) { props = ClientInfoImpl.toProperties(getClientPropertiesFile()); } for (Map.Entry<String,String> entry : commandLineProperties.entrySet()) { props.setProperty(entry.getKey(), entry.getValue()); } if (useSsl) { props.setProperty(ClientProperty.SSL_ENABLED.getKey(), "true"); } if (useSasl) { props.setProperty(ClientProperty.SASL_ENABLED.getKey(), "true"); } if (!zooKeeperInstance.isEmpty()) { String instanceName = zooKeeperInstance.get(0); String hosts = zooKeeperInstance.get(1); props.setProperty(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), hosts); props.setProperty(ClientProperty.INSTANCE_NAME.getKey(), instanceName); } // If the user provided the hosts, set the ZK for tracing too if (zooKeeperHosts != null && !zooKeeperHosts.isEmpty()) { props.setProperty(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), zooKeeperHosts); } if (zooKeeperInstanceName != null && !zooKeeperInstanceName.isEmpty()) { props.setProperty(ClientProperty.INSTANCE_NAME.getKey(), zooKeeperInstanceName); } return props; }
public void setBytes(Properties properties, Long bytes) { checkState(getType() == PropertyType.BYTES, "Invalid type setting " + "bytes. Type must be " + PropertyType.BYTES + ", not " + getType()); properties.setProperty(getKey(), bytes.toString()); }
public String getValue(Properties properties) { Objects.requireNonNull(properties); String value = properties.getProperty(getKey()); if (value == null || value.isEmpty()) { value = getDefaultValue(); } Objects.requireNonNull(value); if (isRequired() && value.isEmpty()) { throw new IllegalArgumentException(getKey() + " must be set!"); } if (!type.isValidFormat(value)) { throw new IllegalArgumentException( "Invalid format for type \"" + type + "\" for provided value: " + value); } return value; }
void generateSection(String section, String prefix, String... prefixProps) { beginSection(section); for (String prop : prefixProps) { ClientProperty cp = sortedProps.get(prop); if (cp != null) { property(cp); } } Set<String> prefixSet = Sets.newHashSet(prefixProps); for (ClientProperty prop : sortedProps.values()) { if (prop.getKey().startsWith(prefix) && !prefixSet.contains(prop.getKey())) { property(prop); } } }
public void setTimeInMillis(Properties properties, Long milliseconds) { checkState(getType() == PropertyType.TIMEDURATION, "Invalid type setting " + "time. Type must be " + PropertyType.TIMEDURATION + ", not " + getType()); properties.setProperty(getKey(), milliseconds + "ms"); }
@Override public Properties getProperties() { Properties properties = ClientConfConverter.toProperties(getSiteConfiguration()); properties.setProperty(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), getZooKeepers()); properties.setProperty(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT.getKey(), Integer.toString(getZooKeepersSessionTimeOut())); properties.setProperty(ClientProperty.INSTANCE_NAME.getKey(), getInstanceName()); ClientProperty.setAuthenticationToken(properties, getAuthenticationToken()); properties.setProperty(ClientProperty.AUTH_PRINCIPAL.getKey(), getPrincipal()); return properties; }
@Override void property(ClientProperty prop) { Objects.nonNull(prop); doc.print("| <a name=\"" + prop.getKey().replace(".", "_") + "\" class=\"prop\"></a> " + prop.getKey() + " | "); String defaultValue = sanitize(prop.getDefaultValue()).trim(); if (defaultValue.length() == 0) { defaultValue = "*empty*"; } doc.println( defaultValue + " | " + prop.getSince() + " | " + sanitize(prop.getDescription() + " |")); }
@Override public Properties properties() { ensureOpen(); Properties result = new Properties(); getProperties().forEach((key, value) -> { if (!key.equals(ClientProperty.AUTH_TOKEN.getKey())) { result.setProperty((String) key, (String) value); } }); return result; }
@Override void property(ClientProperty prop) { doc.println("## " + prop.getDescription()); if (!prop.isRequired()) { doc.print("#"); } doc.println(prop.getKey() + "=" + prop.getDefaultValue() + "\n"); } }
public String getUsername() throws Exception { if (username == null) { username = getClientProperties().getProperty(ClientProperty.AUTH_PRINCIPAL.getKey()); if (username == null || username.isEmpty()) { if (ClientProperty.SASL_ENABLED.getBoolean(getClientProperties())) { if (!UserGroupInformation.isSecurityEnabled()) { throw new IllegalArgumentException( "Kerberos security is not" + " enabled. Run with --sasl or set 'sasl.enabled' in" + " accumulo-client.properties"); } UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); username = ugi.getUserName(); } else { throw new IllegalArgumentException("Username is not set. Run with '-u" + " myuser' or set 'auth.principal' in accumulo-client.properties"); } } } return username; }
private SortedMap<KeyExtent,Bulk.Files> computeMappingFromFiles(FileSystem fs, Table.ID tableId, Path dirPath) throws IOException { Executor executor; ExecutorService service = null; if (this.executor != null) { executor = this.executor; } else if (numThreads > 0) { executor = service = Executors.newFixedThreadPool(numThreads); } else { String threads = context.getConfiguration().get(ClientProperty.BULK_LOAD_THREADS.getKey()); executor = service = Executors .newFixedThreadPool(ConfigurationTypeHelper.getNumThreads(threads)); } try { return computeFileToTabletMappings(fs, tableId, dirPath, executor, context); } finally { if (service != null) { service.shutdown(); } } }
@Override public Connector getConnector(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException { Properties properties = ClientConfConverter.toProperties(clientConf); properties.setProperty(ClientProperty.AUTH_PRINCIPAL.getKey(), principal); properties.setProperty(ClientProperty.INSTANCE_NAME.getKey(), getInstanceName()); return new org.apache.accumulo.core.clientImpl.ConnectorImpl( new ClientContext(new ClientInfoImpl(properties, token))); }