Search in sources :

Example 6 with ExecutionStatus

use of org.apache.gobblin.service.ExecutionStatus in project incubator-gobblin by apache.

the class FlowStatusGeneratorTest method testGetFlowStatusesAcrossGroup.

@Test
public void testGetFlowStatusesAcrossGroup() {
    final long JOB_EXEC_ID = 987L;
    JobStatusRetriever jobStatusRetriever = Mockito.mock(JobStatusRetriever.class);
    // setup: one flow...
    String flowGroup = "myFlowGroup";
    int countPerFlowName = 2;
    String flowName1 = "flowName1";
    long flowExecutionId1 = 111L;
    ExecutionStatus flowStatus1 = ExecutionStatus.ORCHESTRATED;
    // ...with two jobs, each (differently) tagged.
    String f0Js1Status = ExecutionStatus.COMPLETE.name();
    String f0Js1Tag = "step-1";
    String f0Js1JobGroup1 = "job-group-x";
    String f0Js1JobName1 = "job-name-a";
    JobStatus f1Js0 = createFlowJobStatus(flowGroup, flowName1, flowExecutionId1, flowStatus1);
    JobStatus f1Js1 = createJobStatus(flowGroup, flowName1, flowExecutionId1, f0Js1Status, f0Js1Tag, f0Js1JobGroup1, f0Js1JobName1, JOB_EXEC_ID);
    String f0Js2Status = ExecutionStatus.FAILED.name();
    String f0Js2Tag = "step-2";
    String f0Js2JobGroup1 = "job-group-y";
    String f0Js2JobName1 = "job-name-b";
    JobStatus f1Js2 = createJobStatus(flowGroup, flowName1, flowExecutionId1, f0Js2Status, f0Js2Tag, f0Js2JobGroup1, f0Js2JobName1, JOB_EXEC_ID);
    // IMPORTANT: result invariants to honor - ordered by ascending flowName, all of same flowName adjacent, therein descending flowExecutionId
    // NOTE: Three copies of FlowStatus are needed for repeated use, due to mutable, non-rewinding `Iterator FlowStatus.getJobStatusIterator`
    FlowStatus flowStatus = createFlowStatus(flowGroup, flowName1, flowExecutionId1, Arrays.asList(f1Js0, f1Js1, f1Js2), jobStatusRetriever);
    FlowStatus flowStatus2 = createFlowStatus(flowGroup, flowName1, flowExecutionId1, Arrays.asList(f1Js0, f1Js1, f1Js2), jobStatusRetriever);
    FlowStatus flowStatus3 = createFlowStatus(flowGroup, flowName1, flowExecutionId1, Arrays.asList(f1Js0, f1Js1, f1Js2), jobStatusRetriever);
    Mockito.when(jobStatusRetriever.getFlowStatusesForFlowGroupExecutions("myFlowGroup", 2)).thenReturn(Collections.singletonList(flowStatus), Collections.singletonList(flowStatus2), // (for three invocations)
    Collections.singletonList(flowStatus3));
    FlowStatusGenerator flowStatusGenerator = new FlowStatusGenerator(jobStatusRetriever);
    JobStatusMatch.Dependent f0jsmDep1 = JobStatusMatch.Dependent.ofTagged(f0Js1JobGroup1, f0Js1JobName1, JOB_EXEC_ID, f0Js1Status, f0Js1Tag);
    JobStatusMatch.Dependent f0jsmDep2 = JobStatusMatch.Dependent.ofTagged(f0Js2JobGroup1, f0Js2JobName1, JOB_EXEC_ID, f0Js2Status, f0Js2Tag);
    // verify all jobs returned when no tag constraint
    List<FlowStatus> flowStatusesResult = flowStatusGenerator.getFlowStatusesAcrossGroup(flowGroup, countPerFlowName, null);
    Assert.assertEquals(flowStatusesResult.size(), 1);
    assertThat(flowStatusesResult.get(0), FlowStatusMatch.withDependentJobStatuses(flowGroup, flowName1, flowExecutionId1, flowStatus1, Arrays.asList(f0jsmDep1, f0jsmDep2)));
    // verify 'flow pseudo status' plus first job returned against first job's tag
    List<FlowStatus> flowStatusesResult2 = flowStatusGenerator.getFlowStatusesAcrossGroup(flowGroup, countPerFlowName, f0Js1Tag);
    Assert.assertEquals(flowStatusesResult2.size(), 1);
    assertThat(flowStatusesResult2.get(0), FlowStatusMatch.withDependentJobStatuses(flowGroup, flowName1, flowExecutionId1, flowStatus1, Arrays.asList(f0jsmDep1)));
    // verify 'flow pseudo status' plus second job returned against second job's tag
    List<FlowStatus> flowStatusesResult3 = flowStatusGenerator.getFlowStatusesAcrossGroup(flowGroup, countPerFlowName, f0Js2Tag);
    Assert.assertEquals(flowStatusesResult3.size(), 1);
    assertThat(flowStatusesResult3.get(0), FlowStatusMatch.withDependentJobStatuses(flowGroup, flowName1, flowExecutionId1, flowStatus1, Arrays.asList(f0jsmDep2)));
}
Also used : JobStatusMatch(org.apache.gobblin.test.matchers.service.monitoring.JobStatusMatch) ExecutionStatus(org.apache.gobblin.service.ExecutionStatus) Test(org.testng.annotations.Test)

Aggregations

ExecutionStatus (org.apache.gobblin.service.ExecutionStatus)6 HashSet (java.util.HashSet)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 Config (com.typesafe.config.Config)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 JobSpec (org.apache.gobblin.runtime.api.JobSpec)1 SpecExecutor (org.apache.gobblin.runtime.api.SpecExecutor)1 DagNode (org.apache.gobblin.service.modules.flowgraph.Dag.DagNode)1 FailureOption (org.apache.gobblin.service.modules.orchestration.DagManager.FailureOption)1 JobExecutionPlan (org.apache.gobblin.service.modules.spec.JobExecutionPlan)1 JobStatusMatch (org.apache.gobblin.test.matchers.service.monitoring.JobStatusMatch)1 Test (org.testng.annotations.Test)1