use of org.apache.accumulo.core.client.ZooKeeperInstance in project incubator-rya by apache.
the class ConfigUtils method getInstance.
/**
* Create an {@link Instance} that may be used to create {@link Connector}s
* to Accumulo. If the configuration has the {@link #USE_MOCK_INSTANCE} flag
* set, then the instance will be be a {@link MockInstance} instead of a
* Zookeeper backed instance.
*
* @param conf - The configuration object that will be interrogated. (not null)
* @return The {@link Instance} that may be used to connect to Accumulo.
*/
public static Instance getInstance(final Configuration conf) {
// Pull out the Accumulo specific configuration values.
final AccumuloRdfConfiguration accConf = new AccumuloRdfConfiguration(conf);
final String instanceName = accConf.getInstanceName();
final String zoookeepers = accConf.getZookeepers();
// Create an Instance a mock if the mock flag is set.
if (useMockInstance(conf)) {
return new MockInstance(instanceName);
}
// Otherwise create an Instance to a Zookeeper managed instance of Accumulo.
return new ZooKeeperInstance(instanceName, zoookeepers);
}
use of org.apache.accumulo.core.client.ZooKeeperInstance in project incubator-rya by apache.
the class AccumuloInstanceDriver method setUpInstance.
/**
* Sets up the {@link MiniAccumuloCluster} or the {@link MockInstance}.
* @throws Exception
*/
public void setUpInstance() throws Exception {
if (!isMock) {
log.info("Setting up " + driverName + " MiniAccumulo cluster...");
// Create and Run MiniAccumulo Cluster
tempDir = Files.createTempDir();
tempDir.deleteOnExit();
miniAccumuloCluster = new MiniAccumuloCluster(tempDir, userpwd);
copyHadoopHomeToTemp();
miniAccumuloCluster.getConfig().setInstanceName(instanceName);
log.info(driverName + " MiniAccumulo instance starting up...");
miniAccumuloCluster.start();
Thread.sleep(1000);
log.info(driverName + " MiniAccumulo instance started");
log.info("Creating connector to " + driverName + " MiniAccumulo instance...");
zooKeeperInstance = new ZooKeeperInstance(miniAccumuloCluster.getClientConfig());
instance = zooKeeperInstance;
connector = zooKeeperInstance.getConnector(user, new PasswordToken(userpwd));
log.info("Created connector to " + driverName + " MiniAccumulo instance");
} else {
log.info("Setting up " + driverName + " mock instance...");
mockInstance = new MockInstance(instanceName);
instance = mockInstance;
connector = mockInstance.getConnector(user, new PasswordToken(userpwd));
log.info("Created connector to " + driverName + " mock instance");
}
zooKeepers = instance.getZooKeepers();
}
use of org.apache.accumulo.core.client.ZooKeeperInstance in project incubator-rya by apache.
the class AccumuloRyaUtils method getScanner.
/**
* Creates a {@link Scanner} of the provided table name using the specified {@link Configuration}.
* @param tablename the name of the table to scan.
* @param config the {@link Configuration}.
* @param shouldAddCommonIterators {@code true} to add the common iterators to the table scanner.
* {@code false} otherwise.
* @return the {@link Scanner} for the table.
* @throws IOException
*/
public static Scanner getScanner(final String tableName, final Configuration config, final boolean shouldAddCommonIterators) throws IOException {
try {
final String instanceName = config.get(ConfigUtils.CLOUDBASE_INSTANCE);
final String zooKeepers = config.get(ConfigUtils.CLOUDBASE_ZOOKEEPERS);
Instance instance;
if (ConfigUtils.useMockInstance(config)) {
instance = new MockInstance(config.get(ConfigUtils.CLOUDBASE_INSTANCE));
} else {
instance = new ZooKeeperInstance(new ClientConfiguration().withInstance(instanceName).withZkHosts(zooKeepers));
}
final String username = ConfigUtils.getUsername(config);
final String password = ConfigUtils.getPassword(config);
final Connector connector = instance.getConnector(username, new PasswordToken(password));
final Authorizations auths = ConfigUtils.getAuthorizations(config);
final Scanner scanner = connector.createScanner(tableName, auths);
if (shouldAddCommonIterators) {
AccumuloRyaUtils.addCommonScannerIteratorsTo(scanner);
}
return scanner;
} catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
log.error("Error connecting to " + tableName);
throw new IOException(e);
}
}
use of org.apache.accumulo.core.client.ZooKeeperInstance in project incubator-rya by apache.
the class RyaBindingSetExporterFactory method build.
@Override
public Optional<IncrementalResultExporter> build(final Context context) throws IncrementalExporterFactoryException, ConfigurationException {
checkNotNull(context);
// Wrap the context's parameters for parsing.
final RyaExportParameters params = new RyaExportParameters(context.getObserverConfiguration().toMap());
if (params.getUseRyaBindingSetExporter()) {
// Setup Zookeeper connection info.
final String accumuloInstance = params.getAccumuloInstanceName().get();
final String zookeeperServers = params.getZookeeperServers().get().replaceAll(";", ",");
final Instance inst = new ZooKeeperInstance(accumuloInstance, zookeeperServers);
try {
// Setup Accumulo connection info.
final String exporterUsername = params.getExporterUsername().get();
final String exporterPassword = params.getExporterPassword().get();
final Connector accumuloConn = inst.getConnector(exporterUsername, new PasswordToken(exporterPassword));
// Setup Rya PCJ Storage.
final String ryaInstanceName = params.getRyaInstanceName().get();
final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, ryaInstanceName);
// Make the exporter.
final IncrementalBindingSetExporter exporter = new RyaBindingSetExporter(pcjStorage);
return Optional.of(exporter);
} catch (final AccumuloException | AccumuloSecurityException e) {
throw new IncrementalExporterFactoryException("Could not initialize the Accumulo connector using the provided configuration.", e);
}
} else {
return Optional.absent();
}
}
use of org.apache.accumulo.core.client.ZooKeeperInstance in project incubator-rya by apache.
the class FluoITBase method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
Logger.getLogger(ClientCnxn.class).setLevel(Level.ERROR);
// Setup and start the Mini Accumulo.
cluster = clusterInstance.getCluster();
// Store a connector to the Mini Accumulo.
instanceName = cluster.getInstanceName();
zookeepers = cluster.getZooKeepers();
final Instance instance = new ZooKeeperInstance(instanceName, zookeepers);
accumuloConn = instance.getConnector(clusterInstance.getUsername(), new PasswordToken(clusterInstance.getPassword()));
}
Aggregations