use of uk.gov.gchq.gaffer.operation.OperationException in project Gaffer by gchq.
the class ImportRDDOfElementsHandler method doOperation.
public void doOperation(final ImportRDDOfElements operation, final Context context, final AccumuloStore store) throws OperationException {
final String outputPath = operation.getOption(OUTPUT_PATH);
if (null == outputPath || outputPath.isEmpty()) {
throw new OperationException("Option outputPath must be set for this option to be run against the accumulostore");
}
final String failurePath = operation.getOption(FAILURE_PATH);
if (null == failurePath || failurePath.isEmpty()) {
throw new OperationException("Option failurePath must be set for this option to be run against the accumulostore");
}
final ElementConverterFunction func = new ElementConverterFunction(operation.getSparkContext().broadcast(store.getKeyPackage().getKeyConverter(), ACCUMULO_ELEMENT_CONVERTER_CLASS_TAG));
final RDD<Tuple2<Key, Value>> rdd = operation.getInput().flatMap(func, TUPLE2_CLASS_TAG);
final ImportKeyValuePairRDDToAccumulo op = new ImportKeyValuePairRDDToAccumulo.Builder().input(rdd).failurePath(failurePath).outputPath(outputPath).build();
store._execute(new OperationChain<>(op), context);
}
use of uk.gov.gchq.gaffer.operation.OperationException in project Gaffer by gchq.
the class AccumuloStoreRelation method buildScan.
/**
* Creates a <code>DataFrame</code> of all {@link Element}s from the specified groups with columns that are not
* required filtered out.
* <p>
* Currently this does not push the projection down to the store (i.e. it should be implemented in an iterator,
* not in the transform). Issue 320 refers to this.
*
* @param requiredColumns The columns to return.
* @return An {@link RDD} of {@link Row}s containing the requested columns.
*/
@Override
public RDD<Row> buildScan(final String[] requiredColumns) {
try {
LOGGER.info("Building scan with required columns: {}", StringUtils.join(requiredColumns, ','));
LOGGER.info("Building GetRDDOfAllElements with view set to groups {}", StringUtils.join(groups, ','));
final GetRDDOfAllElements operation = new GetRDDOfAllElements(sqlContext.sparkContext());
operation.setView(view);
final RDD<Element> rdd = store.execute(operation, user);
return rdd.map(new ConvertElementToRow(new LinkedHashSet<>(Arrays.asList(requiredColumns)), propertyNeedsConversion, converterByProperty), ClassTagConstants.ROW_CLASS_TAG);
} catch (final OperationException e) {
LOGGER.error("OperationException while executing operation {}", e);
return null;
}
}
use of uk.gov.gchq.gaffer.operation.OperationException in project Gaffer by gchq.
the class AddNamedOperationHandler method validate.
private void validate(final User user, final List<String> parentOperations, final OperationChain<?> operationChain, final INamedOperationCache cache) throws CacheOperationFailedException, OperationException {
for (final Operation op : operationChain.getOperations()) {
if (op instanceof NamedOperation) {
if (parentOperations.contains(((NamedOperation) op).getOperationName())) {
throw new OperationException("The Operation Chain must not be recursive");
}
ExtendedNamedOperation operation = cache.getNamedOperation(((NamedOperation) op).getOperationName(), user);
if (operation == null) {
throw new OperationException("The Operation " + ((NamedOperation) op).getOperationName() + " references an operation which doesn't exist. Unable to create operation");
}
parentOperations.add(((NamedOperation) op).getOperationName());
validate(user, parentOperations, operation.getOperationChain(), cache);
parentOperations.remove(((NamedOperation) op).getOperationName());
}
}
}
use of uk.gov.gchq.gaffer.operation.OperationException in project Gaffer by gchq.
the class NamedOperationHandler method doOperation.
/**
* Gets the requested NamedOperation, updates the input and the view, then executes the operation chain, bypassing
* the Graph.executes graph hooks.
*
* @param operation the {@link Operation} to be executed
* @param context the operation chain context, containing the user who executed the operation
* @param store the {@link Store} the operation should be run on
* @return an object - whatever the last operation in the chain returns
* @throws OperationException thrown when the operation fails
*/
@Override
public Object doOperation(final NamedOperation operation, final Context context, final Store store) throws OperationException {
try {
if (cache == null) {
throw new OperationException("Cache should be initialised in " + "resources/NamedOperationsDeclarations.json and referenced in store.properties");
}
ExtendedNamedOperation namedOperation = cache.getNamedOperation(operation.getOperationName(), context.getUser());
OperationChain<?> operationChain = namedOperation.getOperationChain();
operationChain = new OperationChain<>(exposeNamedOperations(operationChain, context.getUser(), cache));
updateOperationInput(operationChain.getOperations().get(0), operation.getSeeds());
operationChain = updateView(operation.getView(), operationChain);
return store._execute(operationChain, context);
} catch (CacheOperationFailedException e) {
throw new OperationException(e.getMessage(), e);
} catch (ClassCastException e) {
throw new OperationException("Input type " + operation.getInput().getClass().getName() + " was not valid for the operation", e);
}
}
use of uk.gov.gchq.gaffer.operation.OperationException in project Gaffer by gchq.
the class AbstractGetRDDHandler method addIterators.
public void addIterators(final AccumuloStore accumuloStore, final Configuration conf, final User user, final GetElementsOperation<?, ?> operation) throws OperationException {
try {
// Update configuration with instance name, table name, zookeepers, and with view
accumuloStore.updateConfiguration(conf, operation.getView(), user);
// Add iterators based on operation-specific (i.e. not view related) options
final IteratorSetting edgeEntityDirectionFilter = accumuloStore.getKeyPackage().getIteratorFactory().getEdgeEntityDirectionFilterIteratorSetting(operation);
if (edgeEntityDirectionFilter != null) {
InputConfigurator.addIterator(AccumuloInputFormat.class, conf, edgeEntityDirectionFilter);
}
final IteratorSetting queryTimeAggregator = accumuloStore.getKeyPackage().getIteratorFactory().getQueryTimeAggregatorIteratorSetting(operation.getView(), accumuloStore);
if (queryTimeAggregator != null) {
InputConfigurator.addIterator(AccumuloInputFormat.class, conf, queryTimeAggregator);
}
} catch (final StoreException | IteratorSettingException e) {
throw new OperationException("Failed to update configuration", e);
}
}
Aggregations