Search in sources :

Example 6 with CloseableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.

the class JcsJobTrackerIT method shouldAddJobIdToJobTrackerWhenExecuteJob.

@Test
public void shouldAddJobIdToJobTrackerWhenExecuteJob() throws OperationException, IOException, InterruptedException {
    // Given
    final OperationChain<CloseableIterable<Edge>> opChain = new OperationChain<>(new GetAllEdges());
    final User user = new User("user01");
    // When
    JobDetail jobDetails = graph.executeJob(opChain, user);
    final String jobId = jobDetails.getJobId();
    final JobDetail expectedJobDetail = new JobDetail(jobId, user.getUserId(), opChain, JobStatus.FINISHED, null);
    expectedJobDetail.setStartTime(jobDetails.getStartTime());
    int count = 0;
    while (JobStatus.RUNNING == jobDetails.getStatus() && ++count < 20) {
        Thread.sleep(100);
        jobDetails = graph.execute(new GetJobDetails.Builder().jobId(jobId).build(), user);
    }
    expectedJobDetail.setEndTime(jobDetails.getEndTime());
    // Then
    assertEquals(expectedJobDetail, jobDetails);
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) User(uk.gov.gchq.gaffer.user.User) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.Test)

Example 7 with CloseableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.

the class LoadAndQuery6 method run.

public CloseableIterable<String> run() throws OperationException {
    // [user] Create a user
    // ---------------------------------------------------------
    final User user = new User("user01");
    // ---------------------------------------------------------
    // [graph] create a graph using our schema and store properties
    // ---------------------------------------------------------
    final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
    // ---------------------------------------------------------
    // [add] Create a data generator and add the edges to the graph using an operation chain consisting of:
    // generateElements - generating edges from the data (note these are directed edges)
    // addElements - add the edges to the graph
    // ---------------------------------------------------------
    final DataGenerator6 dataGenerator = new DataGenerator6();
    final List<String> data = DataUtils.loadData(getData());
    final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(dataGenerator).objects(data).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    // [get] Create and execute an operation chain consisting of 3 operations:
    //GetAdjacentEntitySeeds - starting at vertex 1 get all adjacent vertices (vertices at other end of outbound edges)
    //GetRelatedEdges - get outbound edges
    //GenerateObjects - convert the edges back into comma separated strings
    // ---------------------------------------------------------
    final OperationChain<CloseableIterable<String>> opChain = new OperationChain.Builder().first(new GetAdjacentEntitySeeds.Builder().addSeed(new EntitySeed("1")).inOutType(IncludeIncomingOutgoingType.OUTGOING).build()).then(new GetEdges.Builder<EntitySeed>().inOutType(IncludeIncomingOutgoingType.OUTGOING).build()).then(new GenerateObjects.Builder<Edge, String>().generator(dataGenerator).build()).build();
    final CloseableIterable<String> results = graph.execute(opChain, user);
    // ---------------------------------------------------------
    log("\nFiltered edges converted back into comma separated strings. The counts have been aggregated\n");
    for (final String result : results) {
        log("RESULT", result);
    }
    return results;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) GetAdjacentEntitySeeds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) DataGenerator6(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator6) Graph(uk.gov.gchq.gaffer.graph.Graph) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Example 8 with CloseableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.

the class ExportIT method shouldExportResultsInSet.

@Test
public void shouldExportResultsInSet() throws OperationException, IOException {
    // Given
    final OperationChain<CloseableIterable<?>> exportOpChain = new Builder().first(new GetEdges.Builder<>().addSeed(new EntitySeed(SOURCE_DIR_0)).build()).then(new ExportToSet()).then(new GenerateObjects.Builder<Edge, EntitySeed>().generator(new EntitySeedExtractor()).build()).then(new GetEdges<>()).then(new ExportToSet()).then(new GetSetExport()).build();
    // When
    final CloseableIterable<?> export = graph.execute(exportOpChain, getUser());
    // Then
    assertEquals(2, Lists.newArrayList(export).size());
}
Also used : ExportToSet(uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) GetSetExport(uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport) GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) EntitySeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 9 with CloseableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.

the class GeneratorsIT method shouldConvertToDomainObjects.

@Test
public void shouldConvertToDomainObjects() throws OperationException, UnsupportedEncodingException {
    // Given
    final OperationChain<CloseableIterable<DomainObject>> opChain = new OperationChain.Builder().first(new GetElements.Builder<>().addSeed(new EntitySeed(SOURCE_1)).build()).then(new GenerateObjects.Builder<Element, DomainObject>().generator(new BasicGenerator()).outputType(new TypeReference<CloseableIterable<DomainObject>>() {
    }).build()).build();
    // When
    final List<DomainObject> results = Lists.newArrayList(graph.execute(opChain, getUser()));
    final EntityDomainObject entityDomainObject = new EntityDomainObject(SOURCE_1, "3", null);
    final EdgeDomainObject edgeDomainObject = new EdgeDomainObject(SOURCE_1, DEST_1, false, 1, 1L);
    // Then
    assertNotNull(results);
    assertEquals(2, results.size());
    assertThat(results, IsCollectionContaining.hasItems(entityDomainObject, edgeDomainObject));
}
Also used : BasicGenerator(uk.gov.gchq.gaffer.integration.generators.BasicGenerator) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) EntityDomainObject(uk.gov.gchq.gaffer.integration.domain.EntityDomainObject) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) EdgeDomainObject(uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject) GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) EdgeDomainObject(uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject) DomainObject(uk.gov.gchq.gaffer.integration.domain.DomainObject) EntityDomainObject(uk.gov.gchq.gaffer.integration.domain.EntityDomainObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 10 with CloseableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.

the class LoadAndQuery6Test method shouldReturnExpectedStringsViaJson.

@Test
public void shouldReturnExpectedStringsViaJson() throws OperationException, SerialisationException {
    // Given
    final User user01 = new User("user01");
    final JSONSerialiser serialiser = new JSONSerialiser();
    final OperationChain<?> addOpChain = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), OperationChain.class);
    final OperationChain<CloseableIterable<String>> queryOpChain = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), OperationChain.class);
    // Setup graph
    final Graph graph = new Graph.Builder().storeProperties(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_PREFIX + "mockaccumulostore.properties")).addSchemas(StreamUtil.openStreams(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "schema")).build();
    // When
    // Execute the add operation chain on the graph
    graph.execute(addOpChain, user01);
    // Execute the query operation on the graph.
    final CloseableIterable<String> results = graph.execute(queryOpChain, user01);
    // Then
    verifyResults(results);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Graph(uk.gov.gchq.gaffer.graph.Graph) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Test(org.junit.Test)

Aggregations

CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)21 Test (org.junit.Test)16 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)11 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)11 User (uk.gov.gchq.gaffer.user.User)11 Graph (uk.gov.gchq.gaffer.graph.Graph)10 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)6 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)6 Element (uk.gov.gchq.gaffer.data.element.Element)5 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)5 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)5 GetEdges (uk.gov.gchq.gaffer.operation.impl.get.GetEdges)4 SimpleEntityDataObject (uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject)3 SimpleEntityGenerator (uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEntityGenerator)3 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)3 Builder (uk.gov.gchq.gaffer.operation.OperationChain.Builder)3 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)3 SimpleEdgeDataObject (uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject)2 SimpleEdgeGenerator (uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEdgeGenerator)2 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)2