Search in sources :

Example 1 with GraphHook

use of uk.gov.gchq.gaffer.graph.hook.GraphHook in project Gaffer by gchq.

the class Graph method executeJob.

/**
     * Performs the given operation chain job on the store.
     * If the operation does not have a view then the graph view is used.
     * NOTE the operationChain may be modified/optimised by the store.
     *
     * @param operationChain the operation chain to be executed.
     * @param user           the user executing the job.
     * @return the job details
     * @throws OperationException thrown if the job fails to run.
     */
public JobDetail executeJob(final OperationChain<?> operationChain, final User user) throws OperationException {
    updateOperationChainView(operationChain);
    for (final GraphHook graphHook : graphHooks) {
        graphHook.preExecute(operationChain, user);
    }
    JobDetail result = store.executeJob(operationChain, user);
    for (final GraphHook graphHook : graphHooks) {
        result = graphHook.postExecute(result, operationChain, user);
    }
    return result;
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook)

Example 2 with GraphHook

use of uk.gov.gchq.gaffer.graph.hook.GraphHook in project Gaffer by gchq.

the class Graph method execute.

/**
     * Performs the given operation chain on the store.
     * If the operation does not have a view then the graph view is used.
     * NOTE the operationChain may be modified/optimised by the store.
     *
     * @param operationChain the operation chain to be executed.
     * @param user           the user executing the operation chain.
     * @param <OUTPUT>       the operation chain output type.
     * @return the operation result.
     * @throws OperationException if an operation fails
     */
public <OUTPUT> OUTPUT execute(final OperationChain<OUTPUT> operationChain, final User user) throws OperationException {
    updateOperationChainView(operationChain);
    for (final GraphHook graphHook : graphHooks) {
        graphHook.preExecute(operationChain, user);
    }
    OUTPUT result = store.execute(operationChain, user);
    for (final GraphHook graphHook : graphHooks) {
        result = graphHook.postExecute(result, operationChain, user);
    }
    return result;
}
Also used : GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook)

Example 3 with GraphHook

use of uk.gov.gchq.gaffer.graph.hook.GraphHook in project Gaffer by gchq.

the class GraphTest method shouldCallAllGraphHooksBeforeOperationChainExecuted.

@Test
public void shouldCallAllGraphHooksBeforeOperationChainExecuted() throws OperationException {
    // Given
    final OperationChain opChain = mock(OperationChain.class);
    given(opChain.getOperations()).willReturn(Collections.singletonList(mock(Operation.class)));
    final User user = mock(User.class);
    final GraphHook hook1 = mock(GraphHook.class);
    final GraphHook hook2 = mock(GraphHook.class);
    final Graph graph = new Graph.Builder().storeProperties(StreamUtil.storeProps(getClass())).addSchema(new Schema.Builder().build()).addHook(hook1).addHook(hook2).build();
    // When
    graph.execute(opChain, user);
    // Then
    final InOrder inOrder = inOrder(hook1, hook2);
    inOrder.verify(hook1).preExecute(opChain, user);
    inOrder.verify(hook2).preExecute(opChain, user);
}
Also used : User(uk.gov.gchq.gaffer.user.User) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Test(org.junit.Test)

Example 4 with GraphHook

use of uk.gov.gchq.gaffer.graph.hook.GraphHook in project Gaffer by gchq.

the class GraphTest method shouldCallAllGraphHooksAfterJobExecuted.

@Test
public void shouldCallAllGraphHooksAfterJobExecuted() throws OperationException {
    // Given
    final User user = mock(User.class);
    final GraphHook hook1 = mock(GraphHook.class);
    final GraphHook hook2 = mock(GraphHook.class);
    final Store store = mock(Store.class);
    final Schema schema = new Schema();
    final JobDetail result1 = mock(JobDetail.class);
    final JobDetail result2 = mock(JobDetail.class);
    final JobDetail result3 = mock(JobDetail.class);
    final OperationChain opChain = mock(OperationChain.class);
    given(store.getSchema()).willReturn(schema);
    given(hook1.postExecute(result1, opChain, user)).willReturn(result2);
    given(hook2.postExecute(result2, opChain, user)).willReturn(result3);
    final Graph graph = new Graph.Builder().storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(schema).addHook(hook1).addHook(hook2).build();
    given(opChain.getOperations()).willReturn(Collections.singletonList(mock(Operation.class)));
    given(store.executeJob(opChain, user)).willReturn(result1);
    // When
    final JobDetail actualResult = graph.executeJob(opChain, user);
    // Then
    final InOrder inOrder = inOrder(hook1, hook2);
    inOrder.verify(hook1).postExecute(result1, opChain, user);
    inOrder.verify(hook2).postExecute(result2, opChain, user);
    assertSame(actualResult, result3);
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) User(uk.gov.gchq.gaffer.user.User) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) Schema(uk.gov.gchq.gaffer.store.schema.Schema) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 5 with GraphHook

use of uk.gov.gchq.gaffer.graph.hook.GraphHook in project Gaffer by gchq.

the class GraphTest method shouldCallAllGraphHooksBeforeJobExecuted.

@Test
public void shouldCallAllGraphHooksBeforeJobExecuted() throws OperationException {
    // Given
    final OperationChain opChain = mock(OperationChain.class);
    given(opChain.getOperations()).willReturn(Collections.singletonList(mock(Operation.class)));
    final User user = mock(User.class);
    final GraphHook hook1 = mock(GraphHook.class);
    final GraphHook hook2 = mock(GraphHook.class);
    final Graph graph = new Graph.Builder().storeProperties(StreamUtil.storeProps(getClass())).addSchema(new Schema.Builder().build()).addHook(hook1).addHook(hook2).build();
    // When
    graph.executeJob(opChain, user);
    // Then
    final InOrder inOrder = inOrder(hook1, hook2);
    inOrder.verify(hook1).preExecute(opChain, user);
    inOrder.verify(hook2).preExecute(opChain, user);
}
Also used : User(uk.gov.gchq.gaffer.user.User) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Test(org.junit.Test)

Aggregations

GraphHook (uk.gov.gchq.gaffer.graph.hook.GraphHook)8 Test (org.junit.Test)6 InOrder (org.mockito.InOrder)6 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)6 Schema (uk.gov.gchq.gaffer.store.schema.Schema)6 User (uk.gov.gchq.gaffer.user.User)6 Store (uk.gov.gchq.gaffer.store.Store)3 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)2 Operation (uk.gov.gchq.gaffer.operation.Operation)2