Search in sources :

Example 1 with NominalTimeRunFacet

use of io.openlineage.client.OpenLineage.NominalTimeRunFacet in project OpenLineage by OpenLineage.

the class OpenLineageTest method jsonSerialization.

@Test
public void jsonSerialization() throws JsonProcessingException {
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
    URI producer = URI.create("producer");
    OpenLineage ol = new OpenLineage(producer);
    UUID runId = UUID.randomUUID();
    RunFacets runFacets = ol.newRunFacetsBuilder().nominalTime(ol.newNominalTimeRunFacet(now, now)).build();
    Run run = ol.newRun(runId, runFacets);
    String name = "jobName";
    String namespace = "namespace";
    JobFacets jobFacets = ol.newJobFacetsBuilder().build();
    Job job = ol.newJob(namespace, name, jobFacets);
    List<InputDataset> inputs = Arrays.asList(ol.newInputDataset("ins", "input", null, null));
    List<OutputDataset> outputs = Arrays.asList(ol.newOutputDataset("ons", "output", null, null));
    RunEvent runStateUpdate = ol.newRunEvent(OpenLineage.RunEvent.EventType.START, now, run, job, inputs, outputs);
    String json = mapper.writeValueAsString(runStateUpdate);
    RunEvent read = mapper.readValue(json, RunEvent.class);
    assertEquals(producer, read.getProducer());
    assertEquals(runId, read.getRun().getRunId());
    assertEquals(name, read.getJob().getName());
    assertEquals(namespace, read.getJob().getNamespace());
    assertEquals(runStateUpdate.getEventType(), read.getEventType());
    assertEquals(runStateUpdate.getEventTime(), read.getEventTime());
    assertEquals(1, runStateUpdate.getInputs().size());
    NominalTimeRunFacet nominalTime = runStateUpdate.getRun().getFacets().getNominalTime();
    assertEquals(now, nominalTime.getNominalStartTime());
    assertEquals(now, nominalTime.getNominalEndTime());
    InputDataset inputDataset = runStateUpdate.getInputs().get(0);
    assertEquals("ins", inputDataset.getNamespace());
    assertEquals("input", inputDataset.getName());
    assertEquals(1, runStateUpdate.getOutputs().size());
    OutputDataset outputDataset = runStateUpdate.getOutputs().get(0);
    assertEquals("ons", outputDataset.getNamespace());
    assertEquals("output", outputDataset.getName());
    assertEquals(roundTrip(json), roundTrip(mapper.writeValueAsString(read)));
}
Also used : NominalTimeRunFacet(io.openlineage.client.OpenLineage.NominalTimeRunFacet) Run(io.openlineage.client.OpenLineage.Run) URI(java.net.URI) ZonedDateTime(java.time.ZonedDateTime) InputDataset(io.openlineage.client.OpenLineage.InputDataset) OutputDataset(io.openlineage.client.OpenLineage.OutputDataset) UUID(java.util.UUID) RunFacets(io.openlineage.client.OpenLineage.RunFacets) JobFacets(io.openlineage.client.OpenLineage.JobFacets) Job(io.openlineage.client.OpenLineage.Job) RunEvent(io.openlineage.client.OpenLineage.RunEvent) Test(org.junit.Test)

Aggregations

InputDataset (io.openlineage.client.OpenLineage.InputDataset)1 Job (io.openlineage.client.OpenLineage.Job)1 JobFacets (io.openlineage.client.OpenLineage.JobFacets)1 NominalTimeRunFacet (io.openlineage.client.OpenLineage.NominalTimeRunFacet)1 OutputDataset (io.openlineage.client.OpenLineage.OutputDataset)1 Run (io.openlineage.client.OpenLineage.Run)1 RunEvent (io.openlineage.client.OpenLineage.RunEvent)1 RunFacets (io.openlineage.client.OpenLineage.RunFacets)1 URI (java.net.URI)1 ZonedDateTime (java.time.ZonedDateTime)1 UUID (java.util.UUID)1 Test (org.junit.Test)1