umustafi commented on code in PR #3896: URL: https://github.com/apache/gobblin/pull/3896#discussion_r1538376655
########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/proc/ReevaluateDagProc.java: ########## @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gobblin.service.modules.orchestration.proc; + +import java.io.IOException; +import java.util.Optional; +import java.util.Set; + +import com.codahale.metrics.Timer; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.metrics.ServiceMetricNames; +import org.apache.gobblin.metrics.event.TimingEvent; +import org.apache.gobblin.runtime.api.DagActionStore; +import org.apache.gobblin.service.ExecutionStatus; +import org.apache.gobblin.service.modules.flowgraph.Dag; +import org.apache.gobblin.service.modules.flowgraph.DagNodeId; +import org.apache.gobblin.service.modules.orchestration.DagManagementStateStore; +import org.apache.gobblin.service.modules.orchestration.DagManagerUtils; +import org.apache.gobblin.service.modules.orchestration.task.ReevaluateDagTask; +import org.apache.gobblin.service.modules.spec.JobExecutionPlan; +import org.apache.gobblin.service.monitoring.FlowStatusGenerator; +import org.apache.gobblin.service.monitoring.JobStatus; +import org.apache.gobblin.service.monitoring.JobStatusRetriever; + + +/** + * An implementation for {@link DagProc} that launches a new job if there exists a job whose pre-requisite jobs are + * completed successfully. If there are no more jobs to run and no job is running for the Dag, it cleans up the Dag. + */ +@Slf4j +public class ReevaluateDagProc extends DagProc<Optional<Dag.DagNode<JobExecutionPlan>>, Void> { + private final JobStatusRetriever jobStatusRetriever; + private final Timer jobStatusPolledTimer; + private final DagNodeId dagNodeId; + private JobStatus jobStatus; + + public ReevaluateDagProc(ReevaluateDagTask reEvaluateDagTask, JobStatusRetriever jobStatusRetriever) { + super(reEvaluateDagTask); + this.jobStatusRetriever = jobStatusRetriever; + this.jobStatusPolledTimer = metricContext.timer(ServiceMetricNames.JOB_STATUS_POLLED_TIMER); + this.dagNodeId = getDagNodeId(); + } + + @Override + protected Optional<Dag.DagNode<JobExecutionPlan>> initialize(DagManagementStateStore dagManagementStateStore) + throws IOException { + Optional<Dag.DagNode<JobExecutionPlan>> dagNode = dagManagementStateStore.getDagNode(this.dagNodeId); + if (!dagNode.isPresent()) { + log.error("DagNode not found for a Reevaluate DagAction with dag node id {}", this.dagNodeId); + return Optional.empty(); + } + this.jobStatus = DagManagerUtils.pollJobStatus(dagNode.get(), this.jobStatusRetriever, this.jobStatusPolledTimer).get(); + ExecutionStatus executionStatus = ExecutionStatus.valueOf(jobStatus.getEventName()); + if (!FlowStatusGenerator.FINISHED_STATUSES.contains(executionStatus.name())) { + log.warn("Job status for dagNode {} is {}. Expected Statuses are {}", dagNodeId, executionStatus, FlowStatusGenerator.FINISHED_STATUSES); Review Comment: add more to log message to warn that re-evaluate should only be added to store for these finished statuses ########## gobblin-runtime/src/main/java/org/apache/gobblin/runtime/api/DagActionStore.java: ########## @@ -32,7 +32,7 @@ enum DagActionType { LAUNCH, // Launch new flow execution invoked adhoc or through scheduled trigger RETRY, // Invoked through DagManager for flows configured to allow retries CANCEL, // Invoked through DagManager if flow has been stuck in Orchestrated state for a while - ADVANCE // Launch next step in multi-hop dag Review Comment: also make sure to change DagActionStoreChangeEvent ########## gobblin-service/src/main/java/org/apache/gobblin/service/monitoring/DagManagementDagActionStoreChangeMonitor.java: ########## @@ -62,28 +59,18 @@ protected void handleDagAction(DagActionStore.DagAction dagAction, boolean isSta LaunchSubmissionMetricProxy launchSubmissionMetricProxy = isStartup ? ON_STARTUP : POST_STARTUP; try { // todo - add actions for other other type of dag actions - if (dagAction.getDagActionType().equals(DagActionStore.DagActionType.LAUNCH)) { - // If multi-active scheduler is NOT turned on we should not receive these type of events - if (!this.isMultiActiveSchedulerEnabled) { - this.unexpectedLaunchEventErrors.mark(); - throw new RuntimeException(String.format("Received LAUNCH dagAction while not in multi-active scheduler " - + "mode for flowAction: %s", dagAction)); - } - dagManagement.addDagAction(dagAction); - } else { - log.warn("Received unsupported dagAction {}. Expected to be a KILL, RESUME, or LAUNCH", dagAction.getDagActionType()); - this.unexpectedErrors.mark(); + switch (dagAction.getDagActionType()) { + case LAUNCH : + case REEVALUATE : + dagManagement.addDagAction(dagAction); + break; + default: + log.warn("Received unsupported dagAction {}. Expected to be a REEVALUATE or LAUNCH", dagAction.getDagActionType()); + this.unexpectedErrors.mark(); } } catch (IOException e) { log.warn("Failed to addDagAction for flowId {} due to exception {}", dagAction.getFlowId(), e.getMessage()); launchSubmissionMetricProxy.markFailure(); } } - Review Comment: is the super method the same? ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/proc/ReevaluateDagProc.java: ########## @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gobblin.service.modules.orchestration.proc; + +import java.io.IOException; +import java.util.Optional; +import java.util.Set; + +import com.codahale.metrics.Timer; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.metrics.ServiceMetricNames; +import org.apache.gobblin.metrics.event.TimingEvent; +import org.apache.gobblin.runtime.api.DagActionStore; +import org.apache.gobblin.service.ExecutionStatus; +import org.apache.gobblin.service.modules.flowgraph.Dag; +import org.apache.gobblin.service.modules.flowgraph.DagNodeId; +import org.apache.gobblin.service.modules.orchestration.DagManagementStateStore; +import org.apache.gobblin.service.modules.orchestration.DagManagerUtils; +import org.apache.gobblin.service.modules.orchestration.task.ReevaluateDagTask; +import org.apache.gobblin.service.modules.spec.JobExecutionPlan; +import org.apache.gobblin.service.monitoring.FlowStatusGenerator; +import org.apache.gobblin.service.monitoring.JobStatus; +import org.apache.gobblin.service.monitoring.JobStatusRetriever; + + +/** + * An implementation for {@link DagProc} that launches a new job if there exists a job whose pre-requisite jobs are + * completed successfully. If there are no more jobs to run and no job is running for the Dag, it cleans up the Dag. + */ +@Slf4j +public class ReevaluateDagProc extends DagProc<Optional<Dag.DagNode<JobExecutionPlan>>, Void> { + private final JobStatusRetriever jobStatusRetriever; + private final Timer jobStatusPolledTimer; + private final DagNodeId dagNodeId; + private JobStatus jobStatus; + + public ReevaluateDagProc(ReevaluateDagTask reEvaluateDagTask, JobStatusRetriever jobStatusRetriever) { + super(reEvaluateDagTask); + this.jobStatusRetriever = jobStatusRetriever; + this.jobStatusPolledTimer = metricContext.timer(ServiceMetricNames.JOB_STATUS_POLLED_TIMER); + this.dagNodeId = getDagNodeId(); + } + + @Override + protected Optional<Dag.DagNode<JobExecutionPlan>> initialize(DagManagementStateStore dagManagementStateStore) + throws IOException { + Optional<Dag.DagNode<JobExecutionPlan>> dagNode = dagManagementStateStore.getDagNode(this.dagNodeId); + if (!dagNode.isPresent()) { + log.error("DagNode not found for a Reevaluate DagAction with dag node id {}", this.dagNodeId); Review Comment: what would this error signify? when is it possibly valid? what if all dagNodes are cleaned up and job has complete by the time an event is received? is that possible ########## gobblin-service/src/main/java/org/apache/gobblin/service/monitoring/KafkaJobStatusMonitor.java: ########## @@ -275,6 +279,7 @@ static void addJobStatusToStateStore(org.apache.gobblin.configuration.State jobS modifyStateIfRetryRequired(jobStatus); stateStore.put(storeName, tableName, jobStatus); if (isNewStateTransitionToFinal(jobStatus, states)) { Review Comment: this should be guarded by dagProcEngine config ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/proc/DagProcUtils.java: ########## @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gobblin.service.modules.orchestration.proc; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Future; + +import com.google.common.collect.Maps; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.metrics.event.TimingEvent; +import org.apache.gobblin.runtime.api.JobSpec; +import org.apache.gobblin.runtime.api.Spec; +import org.apache.gobblin.runtime.api.SpecExecutor; +import org.apache.gobblin.runtime.api.SpecProducer; +import org.apache.gobblin.service.ExecutionStatus; +import org.apache.gobblin.service.modules.flowgraph.Dag; +import org.apache.gobblin.service.modules.orchestration.DagManagementStateStore; +import org.apache.gobblin.service.modules.orchestration.DagManager; +import org.apache.gobblin.service.modules.orchestration.DagManagerUtils; +import org.apache.gobblin.service.modules.orchestration.TimingEventUtils; +import org.apache.gobblin.service.modules.spec.JobExecutionPlan; + + +@Slf4j +public class DagProcUtils { Review Comment: should event emission methods be put here? ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/proc/ReevaluateDagProc.java: ########## @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gobblin.service.modules.orchestration.proc; + +import java.io.IOException; +import java.util.Optional; +import java.util.Set; + +import com.codahale.metrics.Timer; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.metrics.ServiceMetricNames; +import org.apache.gobblin.metrics.event.TimingEvent; +import org.apache.gobblin.runtime.api.DagActionStore; +import org.apache.gobblin.service.ExecutionStatus; +import org.apache.gobblin.service.modules.flowgraph.Dag; +import org.apache.gobblin.service.modules.flowgraph.DagNodeId; +import org.apache.gobblin.service.modules.orchestration.DagManagementStateStore; +import org.apache.gobblin.service.modules.orchestration.DagManagerUtils; +import org.apache.gobblin.service.modules.orchestration.task.ReevaluateDagTask; +import org.apache.gobblin.service.modules.spec.JobExecutionPlan; +import org.apache.gobblin.service.monitoring.FlowStatusGenerator; +import org.apache.gobblin.service.monitoring.JobStatus; +import org.apache.gobblin.service.monitoring.JobStatusRetriever; + + +/** + * An implementation for {@link DagProc} that launches a new job if there exists a job whose pre-requisite jobs are + * completed successfully. If there are no more jobs to run and no job is running for the Dag, it cleans up the Dag. + */ +@Slf4j +public class ReevaluateDagProc extends DagProc<Optional<Dag.DagNode<JobExecutionPlan>>, Void> { + private final JobStatusRetriever jobStatusRetriever; + private final Timer jobStatusPolledTimer; + private final DagNodeId dagNodeId; + private JobStatus jobStatus; + + public ReevaluateDagProc(ReevaluateDagTask reEvaluateDagTask, JobStatusRetriever jobStatusRetriever) { + super(reEvaluateDagTask); + this.jobStatusRetriever = jobStatusRetriever; + this.jobStatusPolledTimer = metricContext.timer(ServiceMetricNames.JOB_STATUS_POLLED_TIMER); + this.dagNodeId = getDagNodeId(); + } + + @Override + protected Optional<Dag.DagNode<JobExecutionPlan>> initialize(DagManagementStateStore dagManagementStateStore) + throws IOException { + Optional<Dag.DagNode<JobExecutionPlan>> dagNode = dagManagementStateStore.getDagNode(this.dagNodeId); + if (!dagNode.isPresent()) { + log.error("DagNode not found for a Reevaluate DagAction with dag node id {}", this.dagNodeId); + return Optional.empty(); + } + this.jobStatus = DagManagerUtils.pollJobStatus(dagNode.get(), this.jobStatusRetriever, this.jobStatusPolledTimer).get(); + ExecutionStatus executionStatus = ExecutionStatus.valueOf(jobStatus.getEventName()); + if (!FlowStatusGenerator.FINISHED_STATUSES.contains(executionStatus.name())) { + log.warn("Job status for dagNode {} is {}. Expected Statuses are {}", dagNodeId, executionStatus, FlowStatusGenerator.FINISHED_STATUSES); + return Optional.empty(); + } + setStatus(dagManagementStateStore, dagNode.get(), executionStatus); + return dagNode; + } + + @Override + protected Void act(DagManagementStateStore dagManagementStateStore, Optional<Dag.DagNode<JobExecutionPlan>> dagNode) + throws IOException { + if (!dagNode.isPresent()) { Review Comment: comment here to describe what this state means ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/proc/DagProc.java: ########## @@ -46,18 +50,21 @@ public final void process(DagManagementStateStore dagManagementStateStore) throw S state = initialize(dagManagementStateStore); // todo - retry T result = act(dagManagementStateStore, state); // todo - retry commit(dagManagementStateStore, result); // todo - retry - sendNotification(result, eventSubmitter); // todo - retry log.info("{} successfully concluded actions for dagId : {}", getClass().getSimpleName(), getDagId()); } - protected abstract DagManager.DagId getDagId(); + protected DagManager.DagId getDagId() { + return this.dagTask.getDagId(); + } + + protected DagNodeId getDagNodeId() { + return this.dagTask.getDagNodeId(); + } protected abstract S initialize(DagManagementStateStore dagManagementStateStore) throws IOException; protected abstract T act(DagManagementStateStore dagManagementStateStore, S state) throws IOException; - protected abstract void sendNotification(T result, EventSubmitter eventSubmitter) throws IOException; Review Comment: why is this method removed? where are events sent? ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/proc/ReevaluateDagProc.java: ########## @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gobblin.service.modules.orchestration.proc; + +import java.io.IOException; +import java.util.Optional; +import java.util.Set; + +import com.codahale.metrics.Timer; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.metrics.ServiceMetricNames; +import org.apache.gobblin.metrics.event.TimingEvent; +import org.apache.gobblin.runtime.api.DagActionStore; +import org.apache.gobblin.service.ExecutionStatus; +import org.apache.gobblin.service.modules.flowgraph.Dag; +import org.apache.gobblin.service.modules.flowgraph.DagNodeId; +import org.apache.gobblin.service.modules.orchestration.DagManagementStateStore; +import org.apache.gobblin.service.modules.orchestration.DagManagerUtils; +import org.apache.gobblin.service.modules.orchestration.task.ReevaluateDagTask; +import org.apache.gobblin.service.modules.spec.JobExecutionPlan; +import org.apache.gobblin.service.monitoring.FlowStatusGenerator; +import org.apache.gobblin.service.monitoring.JobStatus; +import org.apache.gobblin.service.monitoring.JobStatusRetriever; + + +/** + * An implementation for {@link DagProc} that launches a new job if there exists a job whose pre-requisite jobs are + * completed successfully. If there are no more jobs to run and no job is running for the Dag, it cleans up the Dag. Review Comment: let's also describe how it works in multi-hop with concurrent jobs to kick off case even if we are not supporting at present ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/proc/ReevaluateDagProc.java: ########## @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gobblin.service.modules.orchestration.proc; + +import java.io.IOException; +import java.util.Optional; +import java.util.Set; + +import com.codahale.metrics.Timer; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.metrics.ServiceMetricNames; +import org.apache.gobblin.metrics.event.TimingEvent; +import org.apache.gobblin.runtime.api.DagActionStore; +import org.apache.gobblin.service.ExecutionStatus; +import org.apache.gobblin.service.modules.flowgraph.Dag; +import org.apache.gobblin.service.modules.flowgraph.DagNodeId; +import org.apache.gobblin.service.modules.orchestration.DagManagementStateStore; +import org.apache.gobblin.service.modules.orchestration.DagManagerUtils; +import org.apache.gobblin.service.modules.orchestration.task.ReevaluateDagTask; +import org.apache.gobblin.service.modules.spec.JobExecutionPlan; +import org.apache.gobblin.service.monitoring.FlowStatusGenerator; +import org.apache.gobblin.service.monitoring.JobStatus; +import org.apache.gobblin.service.monitoring.JobStatusRetriever; + + +/** + * An implementation for {@link DagProc} that launches a new job if there exists a job whose pre-requisite jobs are + * completed successfully. If there are no more jobs to run and no job is running for the Dag, it cleans up the Dag. + */ +@Slf4j +public class ReevaluateDagProc extends DagProc<Optional<Dag.DagNode<JobExecutionPlan>>, Void> { + private final JobStatusRetriever jobStatusRetriever; + private final Timer jobStatusPolledTimer; + private final DagNodeId dagNodeId; + private JobStatus jobStatus; + + public ReevaluateDagProc(ReevaluateDagTask reEvaluateDagTask, JobStatusRetriever jobStatusRetriever) { + super(reEvaluateDagTask); + this.jobStatusRetriever = jobStatusRetriever; + this.jobStatusPolledTimer = metricContext.timer(ServiceMetricNames.JOB_STATUS_POLLED_TIMER); + this.dagNodeId = getDagNodeId(); + } + + @Override + protected Optional<Dag.DagNode<JobExecutionPlan>> initialize(DagManagementStateStore dagManagementStateStore) + throws IOException { + Optional<Dag.DagNode<JobExecutionPlan>> dagNode = dagManagementStateStore.getDagNode(this.dagNodeId); + if (!dagNode.isPresent()) { + log.error("DagNode not found for a Reevaluate DagAction with dag node id {}", this.dagNodeId); + return Optional.empty(); + } + this.jobStatus = DagManagerUtils.pollJobStatus(dagNode.get(), this.jobStatusRetriever, this.jobStatusPolledTimer).get(); + ExecutionStatus executionStatus = ExecutionStatus.valueOf(jobStatus.getEventName()); + if (!FlowStatusGenerator.FINISHED_STATUSES.contains(executionStatus.name())) { + log.warn("Job status for dagNode {} is {}. Expected Statuses are {}", dagNodeId, executionStatus, FlowStatusGenerator.FINISHED_STATUSES); + return Optional.empty(); + } + setStatus(dagManagementStateStore, dagNode.get(), executionStatus); Review Comment: does job status retriever not update the job status? ########## gobblin-service/src/test/java/org/apache/gobblin/service/modules/orchestration/proc/ReevaluateDagProcTest.java: ########## @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gobblin.service.modules.orchestration.proc; + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import org.mockito.Mockito; +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.typesafe.config.ConfigFactory; +import com.typesafe.config.ConfigValueFactory; + +import org.apache.gobblin.configuration.ConfigurationKeys; +import org.apache.gobblin.metastore.testing.TestMetastoreDatabaseFactory; +import org.apache.gobblin.runtime.api.DagActionStore; +import org.apache.gobblin.runtime.api.FlowSpec; +import org.apache.gobblin.runtime.api.Spec; +import org.apache.gobblin.runtime.api.SpecNotFoundException; +import org.apache.gobblin.runtime.api.SpecProducer; +import org.apache.gobblin.service.ExecutionStatus; +import org.apache.gobblin.service.modules.flowgraph.Dag; +import org.apache.gobblin.service.modules.orchestration.DagManagementStateStore; +import org.apache.gobblin.service.modules.orchestration.DagManager; +import org.apache.gobblin.service.modules.orchestration.DagManagerTest; +import org.apache.gobblin.service.modules.orchestration.DagManagerUtils; +import org.apache.gobblin.service.modules.orchestration.MostlyMySqlDagManagementStateStoreTest; +import org.apache.gobblin.service.modules.orchestration.task.ReevaluateDagTask; +import org.apache.gobblin.service.modules.spec.JobExecutionPlan; +import org.apache.gobblin.service.monitoring.JobStatus; +import org.apache.gobblin.service.monitoring.JobStatusRetriever; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; + + +public class ReevaluateDagProcTest { + JobStatusRetriever jobStatusRetriever = mock(JobStatusRetriever.class); + + void mockDMSS(DagManagementStateStore dagManagementStateStore) throws IOException, SpecNotFoundException { + doReturn(FlowSpec.builder().build()).when(dagManagementStateStore).getFlowSpec(any()); + doNothing().when(dagManagementStateStore).tryAcquireQuota(any()); + doNothing().when(dagManagementStateStore).addDagNodeState(any(), any()); + doReturn(true).when(dagManagementStateStore).releaseQuota(any()); + } + + @Test + public void testOneNextJobToRun() throws Exception { Review Comment: add desc to these test so we can easily follow what its testing ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/proc/ReevaluateDagProc.java: ########## @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gobblin.service.modules.orchestration.proc; + +import java.io.IOException; +import java.util.Optional; +import java.util.Set; + +import com.codahale.metrics.Timer; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.metrics.ServiceMetricNames; +import org.apache.gobblin.metrics.event.TimingEvent; +import org.apache.gobblin.runtime.api.DagActionStore; +import org.apache.gobblin.service.ExecutionStatus; +import org.apache.gobblin.service.modules.flowgraph.Dag; +import org.apache.gobblin.service.modules.flowgraph.DagNodeId; +import org.apache.gobblin.service.modules.orchestration.DagManagementStateStore; +import org.apache.gobblin.service.modules.orchestration.DagManagerUtils; +import org.apache.gobblin.service.modules.orchestration.task.ReevaluateDagTask; +import org.apache.gobblin.service.modules.spec.JobExecutionPlan; +import org.apache.gobblin.service.monitoring.FlowStatusGenerator; +import org.apache.gobblin.service.monitoring.JobStatus; +import org.apache.gobblin.service.monitoring.JobStatusRetriever; + + +/** + * An implementation for {@link DagProc} that launches a new job if there exists a job whose pre-requisite jobs are + * completed successfully. If there are no more jobs to run and no job is running for the Dag, it cleans up the Dag. + */ +@Slf4j +public class ReevaluateDagProc extends DagProc<Optional<Dag.DagNode<JobExecutionPlan>>, Void> { + private final JobStatusRetriever jobStatusRetriever; + private final Timer jobStatusPolledTimer; + private final DagNodeId dagNodeId; + private JobStatus jobStatus; + + public ReevaluateDagProc(ReevaluateDagTask reEvaluateDagTask, JobStatusRetriever jobStatusRetriever) { + super(reEvaluateDagTask); + this.jobStatusRetriever = jobStatusRetriever; + this.jobStatusPolledTimer = metricContext.timer(ServiceMetricNames.JOB_STATUS_POLLED_TIMER); + this.dagNodeId = getDagNodeId(); + } + + @Override + protected Optional<Dag.DagNode<JobExecutionPlan>> initialize(DagManagementStateStore dagManagementStateStore) + throws IOException { + Optional<Dag.DagNode<JobExecutionPlan>> dagNode = dagManagementStateStore.getDagNode(this.dagNodeId); + if (!dagNode.isPresent()) { + log.error("DagNode not found for a Reevaluate DagAction with dag node id {}", this.dagNodeId); + return Optional.empty(); + } + this.jobStatus = DagManagerUtils.pollJobStatus(dagNode.get(), this.jobStatusRetriever, this.jobStatusPolledTimer).get(); + ExecutionStatus executionStatus = ExecutionStatus.valueOf(jobStatus.getEventName()); + if (!FlowStatusGenerator.FINISHED_STATUSES.contains(executionStatus.name())) { + log.warn("Job status for dagNode {} is {}. Expected Statuses are {}", dagNodeId, executionStatus, FlowStatusGenerator.FINISHED_STATUSES); + return Optional.empty(); + } + setStatus(dagManagementStateStore, dagNode.get(), executionStatus); + return dagNode; + } + + @Override + protected Void act(DagManagementStateStore dagManagementStateStore, Optional<Dag.DagNode<JobExecutionPlan>> dagNode) + throws IOException { + if (!dagNode.isPresent()) { + return null; + } + + ExecutionStatus executionStatus = dagNode.get().getValue().getExecutionStatus(); + onJobFinish(dagManagementStateStore, dagNode.get(), executionStatus); + dagManagementStateStore.deleteDagNodeState(getDagId(), dagNode.get()); + + Dag<JobExecutionPlan> dag = dagManagementStateStore.getDag(getDagId()).get(); + + if (this.jobStatus.isShouldRetry()) { + log.info("Retrying job: {}, current attempts: {}, max attempts: {}", + DagManagerUtils.getFullyQualifiedJobName(dagNode.get()), + jobStatus.getCurrentAttempts(), jobStatus.getMaxAttempts()); + dag.setFlowEvent(null); + DagProcUtils.submitJobToExecutor(dagManagementStateStore, dagNode.get(), getDagId()); + } + + if (!DagProcUtils.hasRunningJobs(getDagId(), dagManagementStateStore)) { + if (dag.getFlowEvent() == null) { + // If the dag flow event is not set, then it is successful + dag.setFlowEvent(TimingEvent.FlowTimings.FLOW_SUCCEEDED); + // send an event before cleaning up dag + DagManagerUtils.emitFlowEvent(eventSubmitter, dag, dag.getFlowEvent()); + // todo - verify if work from PR#3641 is required + dagManagementStateStore.deleteDag(getDagId()); + } else { + DagManagerUtils.emitFlowEvent(eventSubmitter, dag, dag.getFlowEvent()); + dagManagementStateStore.markDagFailed(dag); + } + } + + return null; + } + + /** + * Sets status of a dag node inside the given Dag. + * todo - DMSS should support this functionality like an atomic get-and-set operation. + */ + private void setStatus(DagManagementStateStore dagManagementStateStore, + Dag.DagNode<JobExecutionPlan> dagNode, ExecutionStatus executionStatus) throws IOException { + Dag<JobExecutionPlan> dag = dagManagementStateStore.getDag(getDagId()).get(); + DagNodeId dagNodeId = dagNode.getValue().getId(); + for (Dag.DagNode<JobExecutionPlan> node : dag.getNodes()) { + if (node.getValue().getId().equals(dagNodeId)) { + node.getValue().setExecutionStatus(executionStatus); + dagManagementStateStore.checkpointDag(dag); + return; + } + } + log.error("DagNode with id {} not found in Dag {}", dagNodeId, getDagId()); + } + + /** + * Method that defines the actions to be performed when a job finishes either successfully or with failure. + * This method updates the state of the dag and performs clean up actions as necessary. + */ + private void onJobFinish(DagManagementStateStore dagManagementStateStore, + Dag.DagNode<JobExecutionPlan> dagNode, ExecutionStatus executionStatus) + throws IOException { + String jobName = DagManagerUtils.getFullyQualifiedJobName(dagNode); + log.info("Job {} of Dag {} has finished with status {}", jobName, getDagId(), executionStatus.name()); + // Only decrement counters and quota for jobs that actually ran on the executor, not from a GaaS side failure/skip event + if (dagManagementStateStore.releaseQuota(dagNode)) { + dagManagementStateStore.getDagManagerMetrics().decrementRunningJobMetrics(dagNode); + } + + Dag<JobExecutionPlan> dag = dagManagementStateStore.getDag(getDagId()).get(); + + switch (executionStatus) { + case FAILED: + dag.setMessage("Flow failed because job " + jobName + " failed"); + dag.setFlowEvent(TimingEvent.FlowTimings.FLOW_FAILED); + dagManagementStateStore.getDagManagerMetrics().incrementExecutorFailed(dagNode); + break; + case CANCELLED: + dag.setFlowEvent(TimingEvent.FlowTimings.FLOW_CANCELLED); + break; + case COMPLETE: + dagManagementStateStore.getDagManagerMetrics().incrementExecutorSuccess(dagNode); Review Comment: why no flow event sent here? ########## gobblin-service/src/main/java/org/apache/gobblin/service/monitoring/DagManagementDagActionStoreChangeMonitor.java: ########## @@ -62,28 +59,18 @@ protected void handleDagAction(DagActionStore.DagAction dagAction, boolean isSta LaunchSubmissionMetricProxy launchSubmissionMetricProxy = isStartup ? ON_STARTUP : POST_STARTUP; try { // todo - add actions for other other type of dag actions - if (dagAction.getDagActionType().equals(DagActionStore.DagActionType.LAUNCH)) { - // If multi-active scheduler is NOT turned on we should not receive these type of events - if (!this.isMultiActiveSchedulerEnabled) { Review Comment: at present launch events are only written to `dagActionStore` by the multi active scheduler mode though, otherwise passed directly from scheduler to orchestrator to `dagManager`. Is `dagProcEngine` ever to be enabled without multi-active scheduler mode? I don't think so, so we should keep this check. However, if we do want that option then we have to write launch events to `dagActionStore` instead of `Orchestrator` passing event to `DagManager` directly (or still allow it but have the change event do a no-op in non-multi active scheduler mode). Let's sync on this ########## gobblin-service/src/test/java/org/apache/gobblin/service/modules/orchestration/proc/ReevaluateDagProcTest.java: ########## @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gobblin.service.modules.orchestration.proc; + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import org.mockito.Mockito; +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.typesafe.config.ConfigFactory; +import com.typesafe.config.ConfigValueFactory; + +import org.apache.gobblin.configuration.ConfigurationKeys; +import org.apache.gobblin.metastore.testing.TestMetastoreDatabaseFactory; +import org.apache.gobblin.runtime.api.DagActionStore; +import org.apache.gobblin.runtime.api.FlowSpec; +import org.apache.gobblin.runtime.api.Spec; +import org.apache.gobblin.runtime.api.SpecNotFoundException; +import org.apache.gobblin.runtime.api.SpecProducer; +import org.apache.gobblin.service.ExecutionStatus; +import org.apache.gobblin.service.modules.flowgraph.Dag; +import org.apache.gobblin.service.modules.orchestration.DagManagementStateStore; +import org.apache.gobblin.service.modules.orchestration.DagManager; +import org.apache.gobblin.service.modules.orchestration.DagManagerTest; +import org.apache.gobblin.service.modules.orchestration.DagManagerUtils; +import org.apache.gobblin.service.modules.orchestration.MostlyMySqlDagManagementStateStoreTest; +import org.apache.gobblin.service.modules.orchestration.task.ReevaluateDagTask; +import org.apache.gobblin.service.modules.spec.JobExecutionPlan; +import org.apache.gobblin.service.monitoring.JobStatus; +import org.apache.gobblin.service.monitoring.JobStatusRetriever; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; + + +public class ReevaluateDagProcTest { + JobStatusRetriever jobStatusRetriever = mock(JobStatusRetriever.class); + + void mockDMSS(DagManagementStateStore dagManagementStateStore) throws IOException, SpecNotFoundException { + doReturn(FlowSpec.builder().build()).when(dagManagementStateStore).getFlowSpec(any()); + doNothing().when(dagManagementStateStore).tryAcquireQuota(any()); + doNothing().when(dagManagementStateStore).addDagNodeState(any(), any()); + doReturn(true).when(dagManagementStateStore).releaseQuota(any()); + } + + @Test + public void testOneNextJobToRun() throws Exception { + DagManagementStateStore dagManagementStateStore = spy(MostlyMySqlDagManagementStateStoreTest.getDummyDMSS(TestMetastoreDatabaseFactory.get())); + mockDMSS(dagManagementStateStore); + long flowExecutionId = 12345L; + String flowGroup = "fg"; + String flowName = "fn"; Review Comment: make these global constants and have flowExecutionId a global constant that u increment every time perhaps ########## gobblin-service/src/test/java/org/apache/gobblin/service/modules/orchestration/proc/ReevaluateDagProcTest.java: ########## @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gobblin.service.modules.orchestration.proc; + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import org.mockito.Mockito; +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.typesafe.config.ConfigFactory; +import com.typesafe.config.ConfigValueFactory; + +import org.apache.gobblin.configuration.ConfigurationKeys; +import org.apache.gobblin.metastore.testing.TestMetastoreDatabaseFactory; +import org.apache.gobblin.runtime.api.DagActionStore; +import org.apache.gobblin.runtime.api.FlowSpec; +import org.apache.gobblin.runtime.api.Spec; +import org.apache.gobblin.runtime.api.SpecNotFoundException; +import org.apache.gobblin.runtime.api.SpecProducer; +import org.apache.gobblin.service.ExecutionStatus; +import org.apache.gobblin.service.modules.flowgraph.Dag; +import org.apache.gobblin.service.modules.orchestration.DagManagementStateStore; +import org.apache.gobblin.service.modules.orchestration.DagManager; +import org.apache.gobblin.service.modules.orchestration.DagManagerTest; +import org.apache.gobblin.service.modules.orchestration.DagManagerUtils; +import org.apache.gobblin.service.modules.orchestration.MostlyMySqlDagManagementStateStoreTest; +import org.apache.gobblin.service.modules.orchestration.task.ReevaluateDagTask; +import org.apache.gobblin.service.modules.spec.JobExecutionPlan; +import org.apache.gobblin.service.monitoring.JobStatus; +import org.apache.gobblin.service.monitoring.JobStatusRetriever; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; + + +public class ReevaluateDagProcTest { + JobStatusRetriever jobStatusRetriever = mock(JobStatusRetriever.class); + + void mockDMSS(DagManagementStateStore dagManagementStateStore) throws IOException, SpecNotFoundException { + doReturn(FlowSpec.builder().build()).when(dagManagementStateStore).getFlowSpec(any()); + doNothing().when(dagManagementStateStore).tryAcquireQuota(any()); + doNothing().when(dagManagementStateStore).addDagNodeState(any(), any()); + doReturn(true).when(dagManagementStateStore).releaseQuota(any()); + } + + @Test + public void testOneNextJobToRun() throws Exception { + DagManagementStateStore dagManagementStateStore = spy(MostlyMySqlDagManagementStateStoreTest.getDummyDMSS(TestMetastoreDatabaseFactory.get())); + mockDMSS(dagManagementStateStore); + long flowExecutionId = 12345L; + String flowGroup = "fg"; + String flowName = "fn"; + Dag<JobExecutionPlan> dag = DagManagerTest.buildDag("1", flowExecutionId, DagManager.FailureOption.FINISH_ALL_POSSIBLE.name(), + 2, "user5", ConfigFactory.empty() + .withValue(ConfigurationKeys.FLOW_GROUP_KEY, ConfigValueFactory.fromAnyRef(flowGroup)) + .withValue(ConfigurationKeys.FLOW_NAME_KEY, ConfigValueFactory.fromAnyRef(flowName)) + .withValue(ConfigurationKeys.JOB_GROUP_KEY, ConfigValueFactory.fromAnyRef(flowGroup)) + ); + doReturn(Optional.of(dag)).when(dagManagementStateStore).getDag(any()); + doReturn(Optional.of(dag.getStartNodes().get(0))).when(dagManagementStateStore).getDagNode(any()); + doReturn(Optional.of(dag)).when(dagManagementStateStore).getParentDag(any()); + doNothing().when(dagManagementStateStore).deleteDagNodeState(any(), any()); + Iterator<JobStatus> jobStatusIterator = DagManagerTest.getMockJobStatus(flowName, flowGroup, + flowExecutionId, flowGroup, "job0", String.valueOf(ExecutionStatus.COMPLETE)); + doReturn(jobStatusIterator).when(this.jobStatusRetriever).getJobStatusesForFlowExecution(flowName, flowGroup, + flowExecutionId, "job0", flowGroup); + List<SpecProducer<Spec>> specProducers = dag.getNodes().stream().map(n -> { + try { + return DagManagerUtils.getSpecProducer(n); + } catch (ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toList()); + + ReevaluateDagProc + reEvaluateDagProc = new ReevaluateDagProc(new ReevaluateDagTask(new DagActionStore.DagAction(flowGroup, flowName, + String.valueOf(flowExecutionId), "job0", DagActionStore.DagActionType.REEVALUATE), null), this.jobStatusRetriever); + reEvaluateDagProc.process(dagManagementStateStore); + + long addSpecCount = specProducers.stream() + .mapToLong(p -> Mockito.mockingDetails(p) + .getInvocations() + .stream() + .filter(a -> a.getMethod().getName().equals("addSpec")) + .count()) + .sum(); + + Assert.assertEquals(addSpecCount, 1L); + Assert.assertEquals(Mockito.mockingDetails(dagManagementStateStore).getInvocations().stream() + .filter(a -> a.getMethod().getName().equals("deleteDagNodeState")).count(), 1); + } + + @Test + public void testNoNextJobToRun() throws Exception { + DagManagementStateStore dagManagementStateStore = spy(MostlyMySqlDagManagementStateStoreTest.getDummyDMSS(TestMetastoreDatabaseFactory.get())); + mockDMSS(dagManagementStateStore); + long flowExecutionId = 123456L; + String flowGroup = "fg"; + String flowName = "fn"; + Dag<JobExecutionPlan> dag = DagManagerTest.buildDag("2", flowExecutionId, DagManager.FailureOption.FINISH_ALL_POSSIBLE.name(), + 1, "user5", ConfigFactory.empty() + .withValue(ConfigurationKeys.FLOW_GROUP_KEY, ConfigValueFactory.fromAnyRef(flowGroup)) + .withValue(ConfigurationKeys.FLOW_NAME_KEY, ConfigValueFactory.fromAnyRef(flowName)) + .withValue(ConfigurationKeys.JOB_GROUP_KEY, ConfigValueFactory.fromAnyRef(flowGroup)) + ); + doReturn(Optional.of(dag)).when(dagManagementStateStore).getDag(any()); + doReturn(Optional.of(dag.getStartNodes().get(0))).when(dagManagementStateStore).getDagNode(any()); + doReturn(Optional.of(dag)).when(dagManagementStateStore).getParentDag(any()); + doReturn(true).when(dagManagementStateStore).releaseQuota(any()); + doNothing().when(dagManagementStateStore).deleteDagNodeState(any(), any()); + Iterator<JobStatus> jobStatusIterator = DagManagerTest.getMockJobStatus(flowName, flowGroup, + flowExecutionId, flowGroup, "job0", String.valueOf(ExecutionStatus.COMPLETE)); + doReturn(jobStatusIterator).when(this.jobStatusRetriever).getJobStatusesForFlowExecution(flowName, flowGroup, + flowExecutionId, "job0", flowGroup); + List<SpecProducer<Spec>> specProducers = dag.getNodes().stream().map(n -> { + try { + return DagManagerUtils.getSpecProducer(n); + } catch (ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toList()); + + long addSpecCount = specProducers.stream() + .mapToLong(p -> Mockito.mockingDetails(p) + .getInvocations() + .stream() + .filter(a -> a.getMethod().getName().equals("addSpec")) + .count()) + .sum(); + + ReevaluateDagProc + reEvaluateDagProc = new ReevaluateDagProc(new ReevaluateDagTask(new DagActionStore.DagAction(flowGroup, flowName, + String.valueOf(flowExecutionId), "job0", DagActionStore.DagActionType.REEVALUATE), null), this.jobStatusRetriever); + reEvaluateDagProc.process(dagManagementStateStore); + + Assert.assertEquals(addSpecCount, 0L); + Assert.assertEquals(Mockito.mockingDetails(dagManagementStateStore).getInvocations().stream() + .filter(a -> a.getMethod().getName().equals("deleteDagNodeState")).count(), 1); + Assert.assertEquals(Mockito.mockingDetails(dagManagementStateStore).getInvocations().stream() + .filter(a -> a.getMethod().getName().equals("deleteDag")).count(), 1); Review Comment: explain the assertions ur making in brief -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
