Skip to content

Commit

Permalink
Prototype new Accumulo entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-turner committed Dec 5, 2017
1 parent 06cb5ed commit 1c07fa6
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 3 deletions.
@@ -0,0 +1,95 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.accumulo.core.client;

import java.io.InputStream;
import java.util.Map;

import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;

/**
* <pre>
* <code>
* // Create a connector using properties files
* String clientProps = "accumulo.properties";
* Connector conn = AccumuloClient.builder().usingProperties(clientProps).build();
*
* // Create a connector with builder
* Connector conn = AccumuloClient.builder()
* .forInstance("inst1", "zkServer")
* .usingCredentials("root", new PasswordToken("abcd1234"))
* .withSsl()
* .build();
* </code>
* </pre>
*
* @author !SpongeBob
*
* @since 1.9
*/
public class AccumuloClient {

public interface ConnectorFactory {
Connector build();
}

public interface InstanceArgs {
AuthenticationArgs forInstance(String instanceName, String zookeepers);
}

/**
* Allow specifying a properties file containing at least instance, zookeepers, and credentials.
*/
public interface PropertyFileOptions extends InstanceArgs {

This comment has been minimized.

Copy link
@keith-turner

keith-turner Dec 5, 2017

Author Owner

The implementation of this could use commons config, but its not exposed in API.

ConnectorFactory usingProperties(String file);

ConnectorFactory usingProperties(InputStream in);

ConnectorFactory usingProperties(Map<String,String> props);
}

public interface AuthenticationArgs {
ConnectionOptions usingCredentials(String principal, AuthenticationToken token);
}

public interface SslOptions extends ConnectorFactory {
public SslOptions withTruststore(String path);

public SslOptions withTruststore(String path, String password, String type);

public SslOptions withKeystore(String path);

public SslOptions withKeystore(String path, String password, String type);
}

public interface SaslOptions extends ConnectorFactory {
public SaslOptions withPrimary(String kerberosServerPrimary);
}

public interface ConnectionOptions extends ConnectorFactory {
public ConnectionOptions withZkTimeout(int timeout);

public SslOptions withSsl();

public SaslOptions withSasl();
}

public static PropertyFileOptions builder() {
return null;
}

}
Expand Up @@ -43,7 +43,9 @@
* Contains a list of property keys recognized by the Accumulo client and convenience methods for setting them.
*
* @since 1.6.0
* @deprecated since 1.9 use {@link AccumuloClient}
*/
@Deprecated
public class ClientConfiguration extends CompositeConfiguration {
private static final Logger log = LoggerFactory.getLogger(ClientConfiguration.class);

Expand Down
Expand Up @@ -59,7 +59,6 @@
* If you do not know the instance names then run accumulo org.apache.accumulo.server.util.ListInstances on an accumulo server.
*
*/

public class ZooKeeperInstance implements Instance {

private static final Logger log = LoggerFactory.getLogger(ZooKeeperInstance.class);
Expand All @@ -82,6 +81,8 @@ public class ZooKeeperInstance implements Instance {
* The name of specific accumulo instance. This is set at initialization time.
* @param zooKeepers
* A comma separated list of zoo keeper server locations. Each location can contain an optional port, of the format host:port.
*
* @see AccumuloClient
*/
public ZooKeeperInstance(String instanceName, String zooKeepers) {
this(ClientConfiguration.loadDefault().withInstance(instanceName).withZkHosts(zooKeepers));
Expand Down Expand Up @@ -135,7 +136,9 @@ public ZooKeeperInstance(UUID instanceId, String zooKeepers, int sessionTimeout)
* Client configuration for specifying connection options. See {@link ClientConfiguration} which extends Configuration with convenience methods
* specific to Accumulo.
* @since 1.6.0
* @deprecated since 1.9 use {@link AccumuloClient}
*/
@Deprecated
public ZooKeeperInstance(Configuration config) {
this(config, new ZooCacheFactory());
}
Expand Down Expand Up @@ -168,8 +171,8 @@ public String getInstanceID() {
String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + instanceName;
byte[] iidb = zooCache.get(instanceNamePath);
if (iidb == null) {
throw new RuntimeException("Instance name " + instanceName
+ " does not exist in zookeeper. Run \"accumulo org.apache.accumulo.server.util.ListInstances\" to see a list.");
throw new RuntimeException(
"Instance name " + instanceName + " does not exist in zookeeper. Run \"accumulo org.apache.accumulo.server.util.ListInstances\" to see a list.");
}
instanceId = new String(iidb, UTF_8);
}
Expand Down

0 comments on commit 1c07fa6

Please sign in to comment.