mikewalch commented on a change in pull request #361: ACCUMULO-4784 - Create
builder for Connector
URL: https://github.com/apache/accumulo/pull/361#discussion_r167097981
##########
File path:
core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java
##########
@@ -193,4 +224,222 @@ public synchronized ReplicationOperations
replicationOperations() {
return replicationops;
}
+
+ public static class ConnectorBuilderImpl implements InstanceArgs,
PropertyOptions, ConnectionInfoOptions, AuthenticationArgs, ConnectionOptions,
SslOptions,
+ SaslOptions, ConnectorFactory {
+
+ private Properties properties = new Properties();
+ private AuthenticationToken token = null;
+
+ @Override
+ public Connector build() throws AccumuloException,
AccumuloSecurityException {
+ return ConnectionInfoFactory.getConnector(new
ConnectionInfoImpl(properties, token));
+ }
+
+ @Override
+ public ConnectionInfo info() {
+ return new ConnectionInfoImpl(properties, token);
+ }
+
+ @Override
+ public AuthenticationArgs forInstance(String instanceName, String
zookeepers) {
+ setProperty(ClientProperty.INSTANCE_NAME, instanceName);
+ setProperty(ClientProperty.INSTANCE_ZOOKEEPERS, zookeepers);
+ return this;
+ }
+
+ @Override
+ public SslOptions withTruststore(String path) {
+ setProperty(ClientProperty.SSL_TRUSTSTORE_PATH, path);
+ return this;
+ }
+
+ @Override
+ public SslOptions withTruststore(String path, String password, String
type) {
+ setProperty(ClientProperty.SSL_TRUSTSTORE_PATH, path);
+ setProperty(ClientProperty.SSL_TRUSTSTORE_PASSWORD, password);
+ setProperty(ClientProperty.SSL_TRUSTSTORE_TYPE, type);
+ return this;
+ }
+
+ @Override
+ public SslOptions withKeystore(String path) {
+ setProperty(ClientProperty.SSL_KEYSTORE_PATH, path);
+ return this;
+ }
+
+ @Override
+ public SslOptions withKeystore(String path, String password, String type) {
+ setProperty(ClientProperty.SSL_KEYSTORE_PATH, path);
+ setProperty(ClientProperty.SSL_KEYSTORE_PASSWORD, password);
+ setProperty(ClientProperty.SSL_KEYSTORE_TYPE, type);
+ return this;
+ }
+
+ @Override
+ public SslOptions useJsse() {
+ setProperty(ClientProperty.SSL_USE_JSSE, "true");
+ return this;
+ }
+
+ @Override
+ public ConnectionOptions withZkTimeout(int timeout) {
+ setProperty(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT_SEC,
Integer.toString(timeout));
+ return this;
+ }
+
+ @Override
+ public SslOptions withSsl() {
+ setProperty(ClientProperty.SSL_ENABLED, "true");
+ return this;
+ }
+
+ @Override
+ public SaslOptions withSasl() {
+ setProperty(ClientProperty.SASL_ENABLED, "true");
+ return this;
+ }
+
+ @Override
+ public ConnectionOptions withBatchWriterConfig(BatchWriterConfig
batchWriterConfig) {
+ setProperty(ClientProperty.BATCH_WRITER_MAX_MEMORY_BYTES,
batchWriterConfig.getMaxMemory());
+ setProperty(ClientProperty.BATCH_WRITER_MAX_LATENCY_SEC,
batchWriterConfig.getMaxLatency(TimeUnit.SECONDS));
+ setProperty(ClientProperty.BATCH_WRITER_MAX_TIMEOUT_SEC,
batchWriterConfig.getTimeout(TimeUnit.SECONDS));
+ setProperty(ClientProperty.BATCH_WRITER_MAX_WRITE_THREADS,
batchWriterConfig.getMaxWriteThreads());
+ setProperty(ClientProperty.BATCH_WRITER_DURABILITY,
batchWriterConfig.getDurability().toString());
+ return this;
+ }
+
+ @Override
+ public SaslOptions withPrimary(String kerberosServerPrimary) {
+ setProperty(ClientProperty.SASL_KERBEROS_SERVER_PRIMARY,
kerberosServerPrimary);
+ return this;
+ }
+
+ @Override
+ public SaslOptions withQop(String qualityOfProtection) {
+ setProperty(ClientProperty.SASL_QOP, qualityOfProtection);
+ return this;
+ }
+
+ @Override
+ public ConnectorFactory usingProperties(String configFile) {
+ Properties properties = new Properties();
+ try (InputStream is = new FileInputStream(configFile)) {
+ properties.load(is);
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ }
+ return usingProperties(properties);
+ }
+
+ @Override
+ public ConnectorFactory usingProperties(Properties properties) {
+ this.properties = properties;
+ String authMethod =
ClientProperty.AUTH_METHOD.getValue(properties).toLowerCase();
+ switch (authMethod) {
+ case "password":
+ String password = ClientProperty.AUTH_PASSWORD.getValue(properties);
+ Objects.nonNull(password);
+ this.token = new PasswordToken(password);
+ this.properties.remove(ClientProperty.AUTH_PASSWORD);
+ break;
+ case "kerberos":
+ String principal = ClientProperty.AUTH_USERNAME.getValue(properties);
+ String keytabPath =
ClientProperty.AUTH_KERBEROS_KEYTAB_PATH.getValue(properties);
+ Objects.nonNull(principal);
+ Objects.nonNull(keytabPath);
+ try {
+ this.token = new KerberosToken(principal, new File(keytabPath));
Review comment:
I think so. I didn't change this.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services