use of org.apache.accumulo.core.client.ZooKeeperInstance in project Gaffer by gchq.
the class RFileReaderRDD method getPartitions.
@Override
public Partition[] getPartitions() {
// Get connection
final Connector connector;
try {
final Instance instance = new ZooKeeperInstance(instanceName, zookeepers);
connector = instance.getConnector(user, new PasswordToken(password));
} catch (final AccumuloException | AccumuloSecurityException e) {
throw new RuntimeException("Exception connecting to Accumulo", e);
}
LOGGER.info("Obtained connection to instance {} as user {}", instanceName, user);
try {
// Check user has access
if (!checkAccess(connector, user, tableName)) {
throw new RuntimeException("User " + user + " does not have access to table " + tableName);
}
LOGGER.info("Confirmed user {} has access to table {}", user, tableName);
// Get id and split points for table
final String tableId = connector.tableOperations().tableIdMap().get(tableName);
final int numTablets = connector.tableOperations().listSplits(tableName).size() + 1;
LOGGER.info("Table {} has id {} and {} tablets", tableName, tableId, numTablets);
// Create map from tablet name to information about that tablet, including location of the RFiles
final Map<String, AccumuloTablet> tabletNameToInfo = createTabletMap(connector, user, tableId);
// Create array of partitions
final Partition[] partitions = new Partition[tabletNameToInfo.size()];
for (final AccumuloTablet accumuloTablet : tabletNameToInfo.values()) {
partitions[accumuloTablet.index()] = accumuloTablet;
}
LOGGER.info("Returning {} partitions", partitions.length);
return partitions;
} catch (final TableNotFoundException | AccumuloSecurityException | AccumuloException e) {
throw new RuntimeException("Exception creating partitions", e);
}
}
use of org.apache.accumulo.core.client.ZooKeeperInstance in project gora by apache.
the class AccumuloStore method initialize.
/**
* Initialize the data store by reading the credentials, setting the client's properties up and
* reading the mapping file. Initialize is called when then the call to
* {@link org.apache.gora.store.DataStoreFactory#createDataStore} is made.
*
* @param keyClass
* @param persistentClass
* @param properties
*/
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) throws GoraException {
super.initialize(keyClass, persistentClass, properties);
try {
String mock = DataStoreFactory.findProperty(properties, this, MOCK_PROPERTY, null);
String mappingFile = DataStoreFactory.getMappingFile(properties, this, DEFAULT_MAPPING_FILE);
String user = DataStoreFactory.findProperty(properties, this, USERNAME_PROPERTY, null);
String password = DataStoreFactory.findProperty(properties, this, PASSWORD_PROPERTY, null);
mapping = readMapping(mappingFile);
if (mapping.encoder == null || "".equals(mapping.encoder)) {
encoder = new BinaryEncoder();
} else {
encoder = (Encoder) getClass().getClassLoader().loadClass(mapping.encoder).getDeclaredConstructor().newInstance();
}
AuthenticationToken token = new PasswordToken(password);
if (mock == null || !mock.equals("true")) {
String instance = DataStoreFactory.findProperty(properties, this, INSTANCE_NAME_PROPERTY, null);
String zookeepers = DataStoreFactory.findProperty(properties, this, ZOOKEEPERS_NAME_PROPERTY, null);
conn = new ZooKeeperInstance(instance, zookeepers).getConnector(user, token);
} else {
conn = new MockInstance().getConnector(user, token);
}
credentials = new Credentials(user, token);
if (autoCreateSchema && !schemaExists())
createSchema();
} catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException | AccumuloException | AccumuloSecurityException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException e) {
throw new GoraException(e);
}
}
Aggregations