Search in sources :

Example 11 with Operation

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

the class Store method executeJob.

/**
     * Executes a given operation chain job and returns the job detail.
     *
     * @param operationChain the operation chain to execute.
     * @param user           the user executing the job
     * @return the job detail
     * @throws OperationException thrown if jobs are not configured.
     */
public JobDetail executeJob(final OperationChain<?> operationChain, final User user) throws OperationException {
    if (null == jobTracker) {
        throw new OperationException("Running jobs has not configured.");
    }
    final Context context = createContext(user);
    if (isSupported(ExportToGafferResultCache.class)) {
        boolean hasExport = false;
        for (final Operation operation : operationChain.getOperations()) {
            if (operation instanceof ExportToGafferResultCache) {
                hasExport = true;
                break;
            }
        }
        if (!hasExport) {
            operationChain.getOperations().add(new ExportToGafferResultCache());
        }
    }
    final JobDetail initialJobDetail = addOrUpdateJobDetail(operationChain, context, null, JobStatus.RUNNING);
    new Thread(() -> {
        try {
            _execute(operationChain, context);
            addOrUpdateJobDetail(operationChain, context, null, JobStatus.FINISHED);
        } catch (final Throwable t) {
            LOGGER.warn("Operation chain job failed to execute", t);
            addOrUpdateJobDetail(operationChain, context, t.getMessage(), JobStatus.FAILED);
        }
    }).start();
    return initialJobDetail;
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) Operation(uk.gov.gchq.gaffer.operation.Operation) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 12 with Operation

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

the class Store method handleOperationChain.

protected <OUTPUT> OUTPUT handleOperationChain(final OperationChain<OUTPUT> operationChain, final Context context) throws OperationException {
    Object result = null;
    for (final Operation op : operationChain.getOperations()) {
        updateOperationInput(op, result);
        result = handleOperation(op, context);
    }
    return (OUTPUT) result;
}
Also used : Operation(uk.gov.gchq.gaffer.operation.Operation)

Aggregations

Operation (uk.gov.gchq.gaffer.operation.Operation)12 Schema (uk.gov.gchq.gaffer.store.schema.Schema)5 Test (org.junit.Test)4 User (uk.gov.gchq.gaffer.user.User)3 InOrder (org.mockito.InOrder)2 GraphHook (uk.gov.gchq.gaffer.graph.hook.GraphHook)2 ExtendedNamedOperation (uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation)2 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)2 GetOperation (uk.gov.gchq.gaffer.operation.GetOperation)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 Store (uk.gov.gchq.gaffer.store.Store)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 UnauthorisedException (uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)1 AddNamedOperation (uk.gov.gchq.gaffer.named.operation.AddNamedOperation)1