use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class AccumuloStore method preInitialise.
/**
* Performs general initialisation without creating the table.
*
* @param graphId The graph ID.
* @param schema The Gaffer Schema.
* @param properties The Accumulo store properties.
* @throws StoreException If the store could not be initialised.
*/
public void preInitialise(final String graphId, final Schema schema, final StoreProperties properties) throws StoreException {
setProperties(properties);
final String deprecatedTableName = getProperties().getTable();
if (null == graphId && null != deprecatedTableName) {
// Deprecated
super.initialise(deprecatedTableName, schema, getProperties());
} else if (null != deprecatedTableName && !deprecatedTableName.equals(graphId)) {
throw new IllegalArgumentException("The table in store.properties should no longer be used. " + "Please use a graphId instead or for now just set the graphId to be the same value as the store.properties table.");
} else {
super.initialise(graphId, schema, getProperties());
}
final String keyPackageClass = getProperties().getKeyPackageClass();
try {
this.keyPackage = Class.forName(keyPackageClass).asSubclass(AccumuloKeyPackage.class).newInstance();
} catch (final InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new StoreException("Unable to construct an instance of key package: " + keyPackageClass, e);
}
this.keyPackage.setSchema(getSchema());
}
use of uk.gov.gchq.gaffer.store.StoreException 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 graphFilters The operation {@link GraphFilters} 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 GraphFilters graphFilters, final User user) throws StoreException {
try {
final View view = graphFilters.getView();
// Table name
LOGGER.info("Updating configuration with table name of {}", getTableName());
InputConfigurator.setInputTableName(AccumuloInputFormat.class, conf, getTableName());
// 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);
LOGGER.info("Updating configuration with authorizations of {}", authorisations);
// Zookeeper
addZookeeperToConfiguration(conf);
// Add keypackage, schema and view to conf
conf.set(ElementInputFormat.KEY_PACKAGE, getProperties().getKeyPackageClass());
LOGGER.info("Updating configuration with key package of {}", getProperties().getKeyPackageClass());
conf.set(ElementInputFormat.SCHEMA, new String(getSchema().toCompactJson(), CommonConstants.UTF_8));
LOGGER.debug("Updating configuration with Schema of {}", getSchema());
conf.set(ElementInputFormat.VIEW, new String(view.toCompactJson(), CommonConstants.UTF_8));
LOGGER.debug("Updating configuration with View of {}", view);
if (view.hasGroups()) {
// Add the columns to fetch
final Collection<org.apache.accumulo.core.util.Pair<Text, Text>> columnFamilyColumnQualifierPairs = Stream.concat(view.getEntityGroups().stream(), view.getEdgeGroups().stream()).map(g -> new org.apache.accumulo.core.util.Pair<>(new Text(g), (Text) null)).collect(Collectors.toSet());
InputConfigurator.fetchColumns(AccumuloInputFormat.class, conf, columnFamilyColumnQualifierPairs);
LOGGER.info("Updated configuration with column family/qualifiers of {}", StringUtils.join(columnFamilyColumnQualifierPairs, ','));
// Add iterators that depend on the view
final IteratorSetting elementPreFilter = getKeyPackage().getIteratorFactory().getElementPreAggregationFilterIteratorSetting(view, this);
if (null != elementPreFilter) {
InputConfigurator.addIterator(AccumuloInputFormat.class, conf, elementPreFilter);
LOGGER.info("Added pre-aggregation filter iterator of {}", elementPreFilter);
}
final IteratorSetting elementPostFilter = getKeyPackage().getIteratorFactory().getElementPostAggregationFilterIteratorSetting(view, this);
if (null != elementPostFilter) {
InputConfigurator.addIterator(AccumuloInputFormat.class, conf, elementPostFilter);
LOGGER.info("Added post-aggregation filter iterator of {}", elementPostFilter);
}
final IteratorSetting edgeEntityDirFilter = getKeyPackage().getIteratorFactory().getEdgeEntityDirectionFilterIteratorSetting(graphFilters);
if (null != edgeEntityDirFilter) {
InputConfigurator.addIterator(AccumuloInputFormat.class, conf, edgeEntityDirFilter);
LOGGER.info("Added edge direction filter iterator of {}", edgeEntityDirFilter);
}
}
} catch (final AccumuloSecurityException | IteratorSettingException | UnsupportedEncodingException e) {
throw new StoreException(e);
}
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class ElementInputFormat method createRecordReader.
@Override
public RecordReader<Element, NullWritable> createRecordReader(final InputSplit split, final TaskAttemptContext context) throws IOException, InterruptedException {
log.setLevel(getLogLevel(context));
final Configuration conf = context.getConfiguration();
final String keyPackageClass = conf.get(KEY_PACKAGE);
final Schema schema = Schema.fromJson(conf.get(SCHEMA).getBytes(CommonConstants.UTF_8));
final View view = View.fromJson(conf.get(VIEW).getBytes(CommonConstants.UTF_8));
try {
return new ElementWithPropertiesRecordReader(keyPackageClass, schema, view);
} catch (final StoreException | SchemaException | SerialisationException e) {
throw new IOException("Exception creating RecordReader", e);
}
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class AddElementsHandler method addElements.
private void addElements(final AddElements addElementsOperation, final HBaseStore store) throws OperationException {
if (null == addElementsOperation.getInput()) {
return;
}
try {
final Table table = store.getTable();
final Iterator<? extends Element> elements = addElementsOperation.getInput().iterator();
final ElementSerialisation serialisation = new ElementSerialisation(store.getSchema());
final int batchSize = store.getProperties().getWriteBufferSize();
List<Put> puts = new ArrayList<>(batchSize);
while (elements.hasNext()) {
for (int i = 0; i < batchSize && elements.hasNext(); i++) {
final Element element = elements.next();
if (null == element) {
i--;
continue;
}
try {
final Pair<Put, Put> putPair = serialisation.getPuts(element);
puts.add(putPair.getFirst());
if (null != putPair.getSecond()) {
i++;
if (i >= batchSize) {
executePuts(table, puts);
puts = new ArrayList<>(batchSize);
i = 0;
}
puts.add(putPair.getSecond());
}
} catch (final Exception e) {
if (addElementsOperation.isValidate() && !addElementsOperation.isSkipInvalidElements()) {
throw e;
}
// otherwise just ignore the error
}
}
executePuts(table, puts);
puts = new ArrayList<>(batchSize);
}
} catch (final IOException | StoreException e) {
throw new OperationException("Failed to add elements", e);
}
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class GetAdjacentIdsHandler method doOperation.
private CloseableIterable<? extends EntityId> doOperation(final GetAdjacentIds op, final User user, final HBaseStore store) throws OperationException {
if (null == op.getInput()) {
// If null seeds no results are returned
return new WrappedCloseableIterable<>();
}
final HBaseRetriever<?> edgeRetriever;
final GetElements getEdges = new GetElements.Builder().options(op.getOptions()).view(new View.Builder().merge(op.getView()).entities(Collections.emptyMap()).build()).inputIds(op.getInput()).directedType(op.getDirectedType()).inOutType(op.getIncludeIncomingOutGoing()).build();
try {
edgeRetriever = store.createRetriever(getEdges, user, getEdges.getInput(), true);
} catch (final StoreException e) {
throw new OperationException(e.getMessage(), e);
}
return new ExtractDestinationEntityId(edgeRetriever);
}
Aggregations