milleruntime commented on a change in pull request #361: ACCUMULO-4784 - Create
builder for Connector
URL: https://github.com/apache/accumulo/pull/361#discussion_r165191146
##########
File path:
core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java
##########
@@ -193,4 +221,151 @@ public synchronized ReplicationOperations
replicationOperations() {
return replicationops;
}
+
+ public static class ConnectorBuilderImpl implements InstanceArgs,
PropertyOptions, ConnectionInfoOptions, AuthenticationArgs, ConnectionOptions,
SslOptions,
+ SaslOptions, ConnectorFactory {
+
+ private ConnectionInfoImpl info = new ConnectionInfoImpl();
+
+ @Override
+ public Connector build() throws AccumuloException,
AccumuloSecurityException {
+ return info.getConnector();
+ }
+
+ @Override
+ public ConnectionInfo info() {
+ return info;
+ }
+
+ @Override
+ public AuthenticationArgs forInstance(String instanceName, String
zookeepers) {
+ info.setProperty(ClientProperty.INSTANCE_NAME, instanceName);
+ info.setProperty(ClientProperty.INSTANCE_ZOOKEEPERS, zookeepers);
+ return this;
+ }
+
+ @Override
+ public SslOptions withTruststore(String path) {
+ info.setProperty(ClientProperty.SSL_TRUSTSTORE_PATH, path);
+ return this;
+ }
+
+ @Override
+ public SslOptions withTruststore(String path, String password, String
type) {
+ info.setProperty(ClientProperty.SSL_TRUSTSTORE_PATH, path);
+ info.setProperty(ClientProperty.SSL_TRUSTSTORE_PASSWORD, password);
+ info.setProperty(ClientProperty.SSL_TRUSTSTORE_TYPE, type);
+ return this;
+ }
+
+ @Override
+ public SslOptions withKeystore(String path) {
+ info.setProperty(ClientProperty.SSL_KEYSTORE_PATH, path);
+ return this;
+ }
+
+ @Override
+ public SslOptions withKeystore(String path, String password, String type) {
+ info.setProperty(ClientProperty.SSL_KEYSTORE_PATH, path);
+ info.setProperty(ClientProperty.SSL_KEYSTORE_PASSWORD, password);
+ info.setProperty(ClientProperty.SSL_KEYSTORE_TYPE, type);
+ return this;
+ }
+
+ @Override
+ public SslOptions useJsse() {
+ info.setProperty(ClientProperty.SSL_USE_JSSE, "true");
+ return this;
+ }
+
+ @Override
+ public ConnectionOptions withZkTimeout(int timeout) {
+ info.setProperty(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT_SEC,
Integer.toString(timeout));
+ return this;
+ }
+
+ @Override
+ public SslOptions withSsl() {
+ info.setProperty(ClientProperty.SSL_ENABLED, "true");
+ return this;
+ }
+
+ @Override
+ public SaslOptions withSasl() {
+ info.setProperty(ClientProperty.SASL_ENABLED, "true");
+ return this;
+ }
+
+ @Override
+ public ConnectionOptions withBatchWriterConfig(BatchWriterConfig
batchWriterConfig) {
+ info.setProperty(ClientProperty.BATCH_WRITER_MAX_MEMORY_BYTES,
batchWriterConfig.getMaxMemory());
+ info.setProperty(ClientProperty.BATCH_WRITER_MAX_LATENCY_SEC,
batchWriterConfig.getMaxLatency(TimeUnit.SECONDS));
+ info.setProperty(ClientProperty.BATCH_WRITER_MAX_TIMEOUT_SEC,
batchWriterConfig.getTimeout(TimeUnit.SECONDS));
+ info.setProperty(ClientProperty.BATCH_WRITER_MAX_WRITE_THREADS,
batchWriterConfig.getMaxWriteThreads());
+ info.setProperty(ClientProperty.BATCH_WRITER_DURABILITY,
batchWriterConfig.getDurability().toString());
+ return this;
+ }
+
+ @Override
+ public SaslOptions withPrimary(String kerberosServerPrimary) {
+ info.setProperty(ClientProperty.SASL_KERBEROS_SERVER_PRIMARY,
kerberosServerPrimary);
+ return this;
+ }
+
+ @Override
+ public SaslOptions withQop(String qualityOfProtection) {
+ info.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) {
+ info = new ConnectionInfoImpl(properties);
+ return this;
+ }
+
+ @Override
+ public ConnectionOptions usingBasicCredentials(String username,
CharSequence password) {
+ info.setProperty(ClientProperty.AUTH_TYPE, "basic");
+ info.setProperty(ClientProperty.AUTH_BASIC_USERNAME, username);
+ info.setProperty(ClientProperty.AUTH_BASIC_PASSWORD,
password.toString());
+ return this;
+ }
+
+ @Override
+ public ConnectionOptions usingKerberosCredentials(String principal, String
keyTabFile) {
+ info.setProperty(ClientProperty.AUTH_TYPE, "kerberos");
+ info.setProperty(ClientProperty.AUTH_KERBEROS_PRINCIPAL, principal);
+ info.setProperty(ClientProperty.AUTH_KERBEROS_KEYTAB_PATH, keyTabFile);
+ return this;
+ }
+
+ @Override
+ public ConnectionOptions usingCredentials(String principal,
AuthenticationToken token) {
+ if (token instanceof PasswordToken) {
+ return usingBasicCredentials(principal, new String(((PasswordToken)
token).getPassword()));
+ } else if (token instanceof KerberosToken) {
+ return usingKerberosCredentials(principal, ((KerberosToken)
token).getKeytab().getAbsolutePath());
+ } else {
+ throw new IllegalArgumentException("Unknown authentication token
type");
+ }
+ }
+
+ @Override
+ public ConnectorFactory usingConnectionInfo(ConnectionInfo connectionInfo)
{
+ this.info = (ConnectionInfoImpl) connectionInfo;
Review comment:
Setting the type to ConnectionInfo should eliminate this cast.
----------------------------------------------------------------
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