Search in sources :

Example 16 with OperationException

use of uk.gov.gchq.gaffer.operation.OperationException in project Gaffer by gchq.

the class GetAllJobDetailsHandlerTest method shouldThrowExceptionIfJobTrackerIsNotConfigured.

@Test
public void shouldThrowExceptionIfJobTrackerIsNotConfigured() {
    // Given
    final GetAllJobDetailsHandler handler = new GetAllJobDetailsHandler();
    final GetAllJobDetails operation = mock(GetAllJobDetails.class);
    final Store store = mock(Store.class);
    final User user = mock(User.class);
    given(store.getJobTracker()).willReturn(null);
    // When / Then
    try {
        handler.doOperation(operation, new Context(user), store);
        fail("Exception expected");
    } catch (final OperationException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Test(org.junit.Test)

Example 17 with OperationException

use of uk.gov.gchq.gaffer.operation.OperationException in project Gaffer by gchq.

the class AbstractGetRDDHandler method getConfiguration.

protected Configuration getConfiguration(final GetOperation<?, ?> operation) throws OperationException {
    final Configuration conf = new Configuration();
    final String serialisedConf = operation.getOption(AbstractGetRDDHandler.HADOOP_CONFIGURATION_KEY);
    if (serialisedConf != null) {
        try {
            final ByteArrayInputStream bais = new ByteArrayInputStream(serialisedConf.getBytes(CommonConstants.UTF_8));
            conf.readFields(new DataInputStream(bais));
        } catch (final IOException e) {
            throw new OperationException("Exception decoding Configuration from options", e);
        }
    }
    return conf;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 18 with OperationException

use of uk.gov.gchq.gaffer.operation.OperationException in project Gaffer by gchq.

the class AbstractImportKeyValuePairRDDToAccumuloHandler method doOperation.

public void doOperation(final T operation, final Context context, final AccumuloStore store) throws OperationException {
    final String outputPath = getOutputPath(operation);
    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 = getFailurePath(operation);
    if (null == failurePath || failurePath.isEmpty()) {
        throw new OperationException("Option failurePath must be set for this option to be run against the accumulostore");
    }
    prepareKeyValues(operation, new AccumuloKeyRangePartitioner(store));
    final ImportAccumuloKeyValueFiles importAccumuloKeyValueFiles = new ImportAccumuloKeyValueFiles.Builder().inputPath(outputPath).failurePath(failurePath).build();
    store._execute(new OperationChain<>(importAccumuloKeyValueFiles), context);
}
Also used : ImportAccumuloKeyValueFiles(uk.gov.gchq.gaffer.accumulostore.operation.hdfs.operation.ImportAccumuloKeyValueFiles) AccumuloKeyRangePartitioner(uk.gov.gchq.gaffer.sparkaccumulo.operation.utils.AccumuloKeyRangePartitioner) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 19 with OperationException

use of uk.gov.gchq.gaffer.operation.OperationException in project Gaffer by gchq.

the class AddNamedOperationHandler method doOperation.

/**
     * Adds a NamedOperation to a cache which must be specified in the operation declarations file. An
     * ExtendedNamedOperation is built using the fields on the AddNamedOperation. The operation name and operation chain
     * fields must be set and cannot be left empty, or the build() method will fail and a runtime exception will be
     * thrown. The handler then adds/overwrites the NamedOperation according toa an overwrite flag.
     * @param operation the {@link uk.gov.gchq.gaffer.operation.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 null (since the output is void)
     * @throws OperationException if the operation on the cache fails
     */
@Override
public Void doOperation(final AddNamedOperation 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");
        }
        validate(context.getUser(), operation.getOperationName(), operation.getOperationChain(), cache);
        ExtendedNamedOperation extendedNamedOperation = new ExtendedNamedOperation.Builder().operationChain(operation.getOperationChain()).operationName(operation.getOperationName()).creatorId(context.getUser().getUserId()).readers(operation.getReadAccessRoles()).writers(operation.getWriteAccessRoles()).description(operation.getDescription()).build();
        cache.addNamedOperation(extendedNamedOperation, operation.isOverwriteFlag(), context.getUser());
    } catch (CacheOperationFailedException e) {
        throw new OperationException(e.getMessage(), e);
    }
    return null;
}
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 20 with OperationException

use of uk.gov.gchq.gaffer.operation.OperationException in project Gaffer by gchq.

the class GetJobResultsExample method runExamples.

@Override
public void runExamples() {
    try {
        final OperationChain<JobDetail> opChain = new OperationChain.Builder().first(new GetAllEdges()).then(new ExportToGafferResultCache()).then(new GetJobDetails()).build();
        final JobDetail jobDetails = getGraph().execute(opChain, new User("user01"));
        jobId = jobDetails.getJobId();
    } catch (final OperationException e) {
        throw new RuntimeException(e);
    }
    getJobResults();
}
Also used : GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) User(uk.gov.gchq.gaffer.user.User) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

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