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