Search in sources :

Example 71 with Operation

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

the class NamedOperationHandler method exposeNamedOperations.

private List<Operation> exposeNamedOperations(final OperationChain<?> opChain, final User user, final INamedOperationCache cache) throws CacheOperationFailedException {
    ArrayList<Operation> operations = new ArrayList<>();
    for (final Operation operation : opChain.getOperations()) {
        if (operation instanceof NamedOperation) {
            final NamedOperation namedOp = ((NamedOperation) operation);
            OperationChain<?> innerChain = cache.getNamedOperation(namedOp.getOperationName(), user).getOperationChain();
            updateOperationInput(innerChain.getOperations().get(0), namedOp.getSeeds());
            operations.addAll(exposeNamedOperations(innerChain, user, cache));
        } else {
            operations.add(operation);
        }
    }
    return operations;
}
Also used : ArrayList(java.util.ArrayList) 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) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation)

Example 72 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 73 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)

Example 74 with Operation

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

the class ConditionalTest method shouldCloneTransformInShallowClone.

@Test
public void shouldCloneTransformInShallowClone() {
    // Given
    final Operation transform = mock(Operation.class);
    final Operation transformClone = mock(Operation.class);
    given(transform.shallowClone()).willReturn(transformClone);
    final Conditional conditional = new Conditional(new IsMoreThan(1), transform);
    // When
    final Conditional clone = conditional.shallowClone();
    // Then
    assertNotSame(conditional, clone);
    assertSame(transformClone, clone.getTransform());
    verify(transform).shallowClone();
}
Also used : Operation(uk.gov.gchq.gaffer.operation.Operation) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Test(org.junit.jupiter.api.Test) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest)

Example 75 with Operation

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

the class ScoreOperationChainHandlerTest method shouldResolveScoreOperationChainWithMultipleScoreResolvers.

@Test
public void shouldResolveScoreOperationChainWithMultipleScoreResolvers() throws OperationException {
    // Given
    final ScoreOperationChainHandler handler = new ScoreOperationChainHandler();
    final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
    final ScoreResolver scoreResolver = mock(NamedOperationScoreResolver.class);
    final ScoreResolver scoreResolver1 = mock(DefaultScoreResolver.class);
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    final User user = mock(User.class);
    final ScoreOperationChain scoreOperationChain = mock(ScoreOperationChain.class);
    final StoreProperties storeProperties = mock(StoreProperties.class);
    final GetAdjacentIds op1 = new GetAdjacentIds();
    final AddElements op2 = new AddElements();
    final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(GetAdjacentIds.class, 2);
    handler.setOpScores(opScores);
    final String opName = "namedOp";
    final NamedOperation<Iterable<? extends Element>, Iterable<? extends Element>> namedOp = mock(NamedOperation.class);
    namedOp.setOperationName(opName);
    resolvers.put(namedOp.getClass(), scoreResolver);
    resolvers.put(op2.getClass(), scoreResolver1);
    handler.setScoreResolvers(resolvers);
    given(scoreResolver.getScore(eq(namedOp), any())).willReturn(3);
    given(scoreResolver1.getScore(eq(op2), any())).willReturn(5);
    final OperationChain opChain = new OperationChain(Arrays.asList(op1, op2, namedOp));
    given(context.getUser()).willReturn(user);
    Set<String> opAuths = new HashSet<>();
    opAuths.add("TEST_USER");
    given(user.getOpAuths()).willReturn(opAuths);
    given(scoreOperationChain.getOperationChain()).willReturn(opChain);
    given(store.getProperties()).willReturn(storeProperties);
    // When
    final Object result = handler.doOperation(new ScoreOperationChain.Builder().operationChain(opChain).build(), context, store);
    // Then
    assertEquals(10, result);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Element(uk.gov.gchq.gaffer.data.element.Element) Store(uk.gov.gchq.gaffer.store.Store) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) ScoreOperationChain(uk.gov.gchq.gaffer.operation.impl.ScoreOperationChain) LinkedHashMap(java.util.LinkedHashMap) NamedOperationScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.named.NamedOperationScoreResolver) DefaultScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.DefaultScoreResolver) ScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.ScoreResolver) IfScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.IfScoreResolver) HashSet(java.util.HashSet) Context(uk.gov.gchq.gaffer.store.Context) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ScoreOperationChain(uk.gov.gchq.gaffer.operation.impl.ScoreOperationChain) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Aggregations

Operation (uk.gov.gchq.gaffer.operation.Operation)136 Test (org.junit.jupiter.api.Test)88 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)49 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)44 Schema (uk.gov.gchq.gaffer.store.schema.Schema)41 Context (uk.gov.gchq.gaffer.store.Context)35 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)34 Store (uk.gov.gchq.gaffer.store.Store)28 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)26 LinkedHashMap (java.util.LinkedHashMap)21 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)21 User (uk.gov.gchq.gaffer.user.User)21 ArrayList (java.util.ArrayList)18 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)18 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)17 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)16 HashSet (java.util.HashSet)15 HashMap (java.util.HashMap)13 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)13 OperationException (uk.gov.gchq.gaffer.operation.OperationException)13