use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class OperationChainValidatorTest method shouldNotValidateInvalidOperationChain.
@Test
public void shouldNotValidateInvalidOperationChain() {
// Given
Operation operation = Mockito.mock(Operation.class);
given(operation.validate()).willReturn(new ValidationResult("SparkContext is required"));
OperationChain opChain = new OperationChain(operation);
// When
validateOperationChain(opChain, false);
// Then
verify(operation).validate();
}
use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class Graph method updateOperationChainView.
private void updateOperationChainView(final Operations<?> operations) {
for (final Operation operation : operations.getOperations()) {
if (operation instanceof Operations) {
updateOperationChainView((Operations) operation);
} else if (operation instanceof OperationView) {
View opView = ((OperationView) operation).getView();
if (null == opView) {
opView = config.getView();
} else if (!(opView instanceof NamedView) && !opView.hasGroups() && !opView.isAllEdges() && !opView.isAllEntities()) {
// merge with both Entities and Edges
if (!isEmpty(opView.getGlobalElements()) || (isEmpty(opView.getGlobalEdges()) && isEmpty(opView.getGlobalEntities()))) {
opView = new View.Builder().merge(config.getView()).merge(opView).build();
} else {
// We have either global edges or entities in
// opView, but not both
final View originalView = opView;
final View partialConfigView = new View.Builder().merge(config.getView()).removeEdges((x -> isEmpty(originalView.getGlobalEdges()))).removeEntities((x -> isEmpty(originalView.getGlobalEntities()))).build();
opView = new View.Builder().merge(partialConfigView).merge(opView).build();
}
} else if (opView.isAllEdges() || opView.isAllEntities()) {
View.Builder opViewBuilder = new View.Builder().merge(opView);
if (opView.isAllEdges()) {
opViewBuilder.edges(getSchema().getEdgeGroups());
}
if (opView.isAllEntities()) {
opViewBuilder.entities(getSchema().getEntityGroups());
}
opView = opViewBuilder.build();
}
opView.expandGlobalDefinitions();
((OperationView) operation).setView(opView);
}
}
}
use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class SchemaMigration method migrateOperation.
private List<Operation> migrateOperation(final Operation op) {
final OperationView opView = OperationView.class.cast(op);
final Map<String, ViewMigration> migratedEntities = migrateViewElements(entities, opView.getView()::getEntity);
final Map<String, ViewMigration> migratedEdges = migrateViewElements(edges, opView.getView()::getEdge);
final View.Builder viewBuilder = new View.Builder().merge(opView.getView());
for (final Map.Entry<String, ViewMigration> entry : migratedEntities.entrySet()) {
viewBuilder.entity(entry.getKey(), entry.getValue().buildViewElementDefinition());
}
for (final Map.Entry<String, ViewMigration> entry : migratedEdges.entrySet()) {
viewBuilder.edge(entry.getKey(), entry.getValue().buildViewElementDefinition());
}
viewBuilder.config(ViewValidator.SKIP_VIEW_VALIDATION, TRUE);
final View updatedView = viewBuilder.build();
LOGGER.debug("Migrated view: {}", updatedView);
opView.setView(updatedView);
final List<Operation> migrationOps = ViewMigration.createMigrationOps(aggregateAfter, migratedEdges.values(), migratedEntities.values());
if (LOGGER.isDebugEnabled()) {
try {
LOGGER.debug("Migrated operations: {}", StringUtil.toString(JSONSerialiser.serialise(new OperationChain<>(migrationOps), true)));
} catch (final SerialisationException e) {
LOGGER.debug("Failed to json serialise the migration operations: {}", new OperationChain<>(migrationOps));
}
}
return migrationOps;
}
use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class ConditionalTest method shouldNotFailToShallowCloneWhenTransformIsNull.
@Test
public void shouldNotFailToShallowCloneWhenTransformIsNull() {
// Given
final Operation transform = null;
final Conditional conditional = new Conditional(new IsMoreThan(1), transform);
// When
final Conditional clone = conditional.shallowClone();
// Then
assertNotSame(conditional, clone);
assertNull(clone.getTransform());
}
use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class StoreTest method shouldExecuteOperationChainJobAndExportResults.
@Test
public void shouldExecuteOperationChainJobAndExportResults() throws OperationException, InterruptedException, StoreException {
// Given
final Operation operation = new GetVariables.Builder().variableNames(Lists.newArrayList()).build();
final OperationChain<?> opChain = new OperationChain<>(operation);
final StoreProperties properties = mock(StoreProperties.class);
given(properties.getJobExecutorThreadCount()).willReturn(1);
given(properties.getJobTrackerEnabled()).willReturn(true);
final Store store = new StoreImpl();
final Schema schema = new Schema();
store.initialise("graphId", schema, properties);
// When
final JobDetail resultJobDetail = store.executeJob(opChain, context);
// Then
Thread.sleep(1000);
final ArgumentCaptor<JobDetail> jobDetail = ArgumentCaptor.forClass(JobDetail.class);
verify(jobTracker, times(2)).addOrUpdateJob(jobDetail.capture(), eq(user));
assertEquals(jobDetail.getAllValues().get(0), resultJobDetail);
assertEquals(JobStatus.FINISHED, jobDetail.getAllValues().get(1).getStatus());
final ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(exportToGafferResultCacheHandler).doOperation(Mockito.any(ExportToGafferResultCache.class), contextCaptor.capture(), eq(store));
assertSame(user, contextCaptor.getValue().getUser());
}
Aggregations