use of org.apache.accumulo.core.client.AccumuloException in project Gaffer by gchq.
the class TableUtils method createTable.
/**
* Creates a table for Gaffer data and enables the correct Bloom filter;
* removes the versioning iterator and adds an aggregator Iterator the
* {@link org.apache.accumulo.core.iterators.user.AgeOffFilter} for the
* specified time period.
*
* @param store the accumulo store
* @throws StoreException failure to create accumulo connection or add iterator settings
* @throws TableExistsException failure to create table
*/
public static synchronized void createTable(final AccumuloStore store) throws StoreException, TableExistsException {
// Create table
final String tableName = store.getProperties().getTable();
if (null == tableName) {
throw new AccumuloRuntimeException("Table name is required.");
}
final Connector connector = store.getConnection();
if (connector.tableOperations().exists(tableName)) {
LOGGER.info("Table {} exists, not creating", tableName);
return;
}
try {
LOGGER.info("Creating table {} as user {}", tableName, connector.whoami());
connector.tableOperations().create(tableName);
final String repFactor = store.getProperties().getTableFileReplicationFactor();
if (null != repFactor) {
LOGGER.info("Table file replication set to {} on table {}", repFactor, tableName);
connector.tableOperations().setProperty(tableName, Property.TABLE_FILE_REPLICATION.getKey(), repFactor);
}
// Enable Bloom filters using ElementFunctor
LOGGER.info("Enabling Bloom filter on table {}", tableName);
connector.tableOperations().setProperty(tableName, Property.TABLE_BLOOM_ENABLED.getKey(), "true");
connector.tableOperations().setProperty(tableName, Property.TABLE_BLOOM_KEY_FUNCTOR.getKey(), store.getKeyPackage().getKeyFunctor().getClass().getName());
// Remove versioning iterator from table for all scopes
LOGGER.info("Removing versioning iterator from table {}", tableName);
final EnumSet<IteratorScope> iteratorScopes = EnumSet.allOf(IteratorScope.class);
connector.tableOperations().removeIterator(tableName, "vers", iteratorScopes);
if (store.getSchema().hasAggregators()) {
// Add Combiner iterator to table for all scopes
LOGGER.info("Adding Aggregator iterator to table {} for all scopes", tableName);
connector.tableOperations().attachIterator(tableName, store.getKeyPackage().getIteratorFactory().getAggregatorIteratorSetting(store));
} else {
LOGGER.info("Aggregator iterator has not been added to table {}", tableName);
}
if (store.getProperties().getEnableValidatorIterator()) {
// Add validator iterator to table for all scopes
LOGGER.info("Adding Validator iterator to table {} for all scopes", tableName);
connector.tableOperations().attachIterator(tableName, store.getKeyPackage().getIteratorFactory().getValidatorIteratorSetting(store));
} else {
LOGGER.info("Validator iterator has not been added to table {}", tableName);
}
} catch (AccumuloSecurityException | TableNotFoundException | AccumuloException | IteratorSettingException e) {
throw new StoreException(e.getMessage(), e);
}
setLocalityGroups(store);
}
use of org.apache.accumulo.core.client.AccumuloException in project presto by prestodb.
the class AccumuloTableManager method setLocalityGroups.
public void setLocalityGroups(String tableName, Map<String, Set<Text>> groups) {
if (groups.isEmpty()) {
return;
}
try {
connector.tableOperations().setLocalityGroups(tableName, groups);
LOG.debug("Set locality groups for %s to %s", tableName, groups);
} catch (AccumuloException | AccumuloSecurityException e) {
throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to set locality groups", e);
} catch (TableNotFoundException e) {
throw new PrestoException(ACCUMULO_TABLE_DNE, "Failed to set locality groups, table does not exist", e);
}
}
use of org.apache.accumulo.core.client.AccumuloException in project presto by prestodb.
the class AccumuloTableManager method setIterator.
public void setIterator(String table, IteratorSetting setting) {
try {
// Remove any existing iterator settings of the same name, if applicable
Map<String, EnumSet<IteratorScope>> iterators = connector.tableOperations().listIterators(table);
if (iterators.containsKey(setting.getName())) {
connector.tableOperations().removeIterator(table, setting.getName(), iterators.get(setting.getName()));
}
connector.tableOperations().attachIterator(table, setting);
} catch (AccumuloSecurityException | AccumuloException e) {
throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to set iterator on table " + table, e);
} catch (TableNotFoundException e) {
throw new PrestoException(ACCUMULO_TABLE_DNE, "Failed to set iterator, table does not exist", e);
}
}
use of org.apache.accumulo.core.client.AccumuloException in project presto by prestodb.
the class AccumuloQueryRunner method getAccumuloConnector.
/**
* Gets the AccumuloConnector singleton, starting the MiniAccumuloCluster on initialization.
* This singleton instance is required so all test cases access the same MiniAccumuloCluster.
*
* @return Accumulo connector
*/
private static Connector getAccumuloConnector() {
if (connector != null) {
return connector;
}
try {
MiniAccumuloCluster accumulo = createMiniAccumuloCluster();
Instance instance = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers());
connector = instance.getConnector(MAC_USER, new PasswordToken(MAC_PASSWORD));
LOG.info("Connection to MAC instance %s at %s established, user %s password %s", accumulo.getInstanceName(), accumulo.getZooKeepers(), MAC_USER, MAC_PASSWORD);
return connector;
} catch (AccumuloException | AccumuloSecurityException | InterruptedException | IOException e) {
throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to get connector to Accumulo", e);
}
}
use of org.apache.accumulo.core.client.AccumuloException 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) {
try {
super.initialize(keyClass, persistentClass, properties);
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 {
try {
encoder = (Encoder) getClass().getClassLoader().loadClass(mapping.encoder).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new IOException(e);
}
}
try {
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 (AccumuloException | AccumuloSecurityException e) {
throw new IOException(e);
}
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
}
Aggregations