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());
}
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);
}
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();
}
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;
}
Aggregations