use of uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException in project Gaffer by gchq.
the class AccumuloSingleIDRetrieverTest method testEntitySeedQueryEntitiesOnly.
private void testEntitySeedQueryEntitiesOnly(final AccumuloStore store) throws AccumuloException, StoreException {
setupGraph(store, numEntries);
final User user = new User();
// Create set to query for
final Set<ElementSeed> ids = new HashSet<>();
for (int i = 0; i < numEntries; i++) {
ids.add(new EntitySeed("" + i));
}
final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
AccumuloSingleIDRetriever retriever = null;
final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
operation.setIncludeEntities(true);
operation.setIncludeEdges(IncludeEdgeType.NONE);
try {
retriever = new AccumuloSingleIDRetriever(store, operation, user);
} catch (IteratorSettingException e) {
e.printStackTrace();
}
//Should find only the entities i
assertEquals(numEntries, Iterables.size(retriever));
}
use of uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException in project Gaffer by gchq.
the class AccumuloStore method updateConfiguration.
/**
* Updates a Hadoop {@link Configuration} with information needed to connect to the Accumulo store. It adds
* iterators to apply the provided {@link View}. This method will be used by operations that run MapReduce
* or Spark jobs against the Accumulo store.
*
* @param conf A {@link Configuration} to be updated.
* @param view The {@link View} to be applied.
* @param user The {@link User} to be used.
* @throws StoreException if there is a failure to connect to Accumulo or a problem setting the iterators.
*/
public void updateConfiguration(final Configuration conf, final View view, final User user) throws StoreException {
try {
// Table name
InputConfigurator.setInputTableName(AccumuloInputFormat.class, conf, getProperties().getTable());
// User
addUserToConfiguration(conf);
// Authorizations
Authorizations authorisations;
if (null != user && null != user.getDataAuths()) {
authorisations = new Authorizations(user.getDataAuths().toArray(new String[user.getDataAuths().size()]));
} else {
authorisations = new Authorizations();
}
InputConfigurator.setScanAuthorizations(AccumuloInputFormat.class, conf, authorisations);
// Zookeeper
addZookeeperToConfiguration(conf);
// Add keypackage, schema and view to conf
conf.set(ElementInputFormat.KEY_PACKAGE, getProperties().getKeyPackageClass());
conf.set(ElementInputFormat.SCHEMA, new String(getSchema().toCompactJson(), CommonConstants.UTF_8));
conf.set(ElementInputFormat.VIEW, new String(view.toCompactJson(), CommonConstants.UTF_8));
// Add iterators that depend on the view
if (view.hasGroups()) {
IteratorSetting elementPreFilter = getKeyPackage().getIteratorFactory().getElementPreAggregationFilterIteratorSetting(view, this);
IteratorSetting elementPostFilter = getKeyPackage().getIteratorFactory().getElementPostAggregationFilterIteratorSetting(view, this);
InputConfigurator.addIterator(AccumuloInputFormat.class, conf, elementPostFilter);
InputConfigurator.addIterator(AccumuloInputFormat.class, conf, elementPreFilter);
}
} catch (final AccumuloSecurityException | IteratorSettingException | UnsupportedEncodingException e) {
throw new StoreException(e);
}
}
use of uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException in project Gaffer by gchq.
the class SummariseGroupOverRangesHandler method doOperation.
public CloseableIterable<Element> doOperation(final SummariseGroupOverRanges<Pair<ElementSeed>, Element> operation, final User user, final AccumuloStore store) throws OperationException {
final int numEdgeGroups = operation.getView().getEdgeGroups().size();
final int numEntityGroups = operation.getView().getEntityGroups().size();
if ((numEdgeGroups + numEntityGroups) != 1) {
throw new OperationException("You may only set one Group in your view for this operation.");
}
final String columnFamily;
if (numEdgeGroups == 1) {
columnFamily = (String) operation.getView().getEdgeGroups().toArray()[0];
} else {
columnFamily = (String) operation.getView().getEntityGroups().toArray()[0];
}
final IteratorSettingFactory itrFactory = store.getKeyPackage().getIteratorFactory();
try {
return new AccumuloRangeIDRetriever(store, operation, user, itrFactory.getElementPreAggregationFilterIteratorSetting(operation.getView(), store), itrFactory.getElementPostAggregationFilterIteratorSetting(operation.getView(), store), itrFactory.getEdgeEntityDirectionFilterIteratorSetting(operation), itrFactory.getElementPropertyRangeQueryFilter(operation), itrFactory.getRowIDAggregatorIteratorSetting(store, columnFamily));
} catch (IteratorSettingException | StoreException e) {
throw new OperationException("Failed to get elements", e);
}
}
use of uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException 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);
}
Aggregations