Search in sources :

Example 6 with OperationException

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);
}
Also used : Tuple2(scala.Tuple2) ImportKeyValuePairRDDToAccumulo(uk.gov.gchq.gaffer.sparkaccumulo.operation.scalardd.ImportKeyValuePairRDDToAccumulo) ElementConverterFunction(uk.gov.gchq.gaffer.sparkaccumulo.operation.utils.scala.ElementConverterFunction) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 7 with OperationException

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;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GetRDDOfAllElements(uk.gov.gchq.gaffer.spark.operation.scalardd.GetRDDOfAllElements) Element(uk.gov.gchq.gaffer.data.element.Element) OperationException(uk.gov.gchq.gaffer.operation.OperationException) ConvertElementToRow(uk.gov.gchq.gaffer.spark.operation.dataframe.ConvertElementToRow)

Example 8 with OperationException

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());
        }
    }
}
Also used : AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 9 with OperationException

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);
    }
}
Also used : ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.CacheOperationFailedException) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 10 with OperationException

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);
    }
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Aggregations

OperationException (uk.gov.gchq.gaffer.operation.OperationException)38 User (uk.gov.gchq.gaffer.user.User)9 StoreException (uk.gov.gchq.gaffer.store.StoreException)7 Element (uk.gov.gchq.gaffer.data.element.Element)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Configuration (org.apache.hadoop.conf.Configuration)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 Path (org.apache.hadoop.fs.Path)4 Test (org.junit.Test)4 Graph (uk.gov.gchq.gaffer.graph.Graph)4 SparkConf (org.apache.spark.SparkConf)3 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)3 Edge (uk.gov.gchq.gaffer.data.element.Edge)3 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)3 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)3 BufferedWriter (java.io.BufferedWriter)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2