Search in sources :

Example 6 with ExportToGafferResultCache

use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache in project Gaffer by gchq.

the class ExportToGafferResultCacheTest method builderShouldCreatePopulatedOperation.

@Test
@Override
public void builderShouldCreatePopulatedOperation() {
    // When
    final String key = "key";
    final HashSet<String> opAuths = Sets.newHashSet("1", "2");
    final ExportToGafferResultCache op = new ExportToGafferResultCache.Builder().opAuths(opAuths).key(key).build();
    // Then
    assertEquals(key, op.getKey());
    assertEquals(opAuths, op.getOpAuths());
}
Also used : ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.Test)

Example 7 with ExportToGafferResultCache

use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache in project Gaffer by gchq.

the class ExportToGafferResultCacheHandlerTest method shouldHandleOperationByDelegatingToAnExistingExporter.

@Test
public void shouldHandleOperationByDelegatingToAnExistingExporter() throws OperationException {
    // Given
    final List<?> results = Arrays.asList(1, 2, 3);
    final ExportToGafferResultCache export = new ExportToGafferResultCache.Builder().key("key").input(results).build();
    final Context context = new Context();
    final Store store = mock(Store.class);
    final JSONSerialiser jsonSerialiser = mock(JSONSerialiser.class);
    final Long timeToLive = 10000L;
    final String visibility = "visibility value";
    final GafferResultCacheExporter exporter = mock(GafferResultCacheExporter.class);
    context.addExporter(exporter);
    final ExportToGafferResultCacheHandler handler = new ExportToGafferResultCacheHandler();
    handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
    handler.setJsonSerialiser(jsonSerialiser);
    handler.setTimeToLive(timeToLive);
    handler.setVisibility(visibility);
    // When
    final Object handlerResult = handler.doOperation(export, context, store);
    // Then
    verify(exporter).add("key", results);
    assertSame(handlerResult, results);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 8 with ExportToGafferResultCache

use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache 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)

Example 9 with ExportToGafferResultCache

use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache 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)

Aggregations

ExportToGafferResultCache (uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)9 Test (org.junit.Test)5 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)5 GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)3 GetJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails)3 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)2 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)2 GafferResultCacheExporter (uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter)2 Context (uk.gov.gchq.gaffer.store.Context)2 Store (uk.gov.gchq.gaffer.store.Store)2 Operation (uk.gov.gchq.gaffer.operation.Operation)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 Schema (uk.gov.gchq.gaffer.store.schema.Schema)1 User (uk.gov.gchq.gaffer.user.User)1