use of org.apache.flink.kubernetes.operator.TestingFlinkService in project flink-kubernetes-operator by apache.
the class ObserverTest method observeApplicationCluster.
@Test
public void observeApplicationCluster() {
TestingFlinkService flinkService = new TestingFlinkService();
Observer observer = new Observer(flinkService, FlinkOperatorConfiguration.fromConfiguration(new Configuration()));
FlinkDeployment deployment = TestUtils.buildApplicationCluster();
Configuration conf = FlinkUtils.getEffectiveConfig(deployment, new Configuration());
observer.observe(deployment, TestUtils.createEmptyContext(), conf);
deployment.setStatus(new FlinkDeploymentStatus());
deployment.getStatus().getReconciliationStatus().setLastReconciledSpec(deployment.getSpec());
deployment.getStatus().setJobStatus(new JobStatus());
flinkService.submitApplicationCluster(deployment, conf);
// Validate port check logic
flinkService.setPortReady(false);
// Port not ready
observer.observe(deployment, readyContext, conf);
assertEquals(JobManagerDeploymentStatus.DEPLOYING, deployment.getStatus().getJobManagerDeploymentStatus());
observer.observe(deployment, readyContext, conf);
assertEquals(JobManagerDeploymentStatus.DEPLOYING, deployment.getStatus().getJobManagerDeploymentStatus());
flinkService.setPortReady(true);
// Port ready but we have to recheck once again
observer.observe(deployment, readyContext, conf);
assertEquals(JobManagerDeploymentStatus.DEPLOYED_NOT_READY, deployment.getStatus().getJobManagerDeploymentStatus());
// Stable ready
observer.observe(deployment, readyContext, conf);
assertEquals(JobManagerDeploymentStatus.READY, deployment.getStatus().getJobManagerDeploymentStatus());
assertEquals(JobState.RUNNING.name(), deployment.getStatus().getJobStatus().getState());
observer.observe(deployment, readyContext, conf);
assertEquals(JobManagerDeploymentStatus.READY, deployment.getStatus().getJobManagerDeploymentStatus());
assertEquals(JobState.RUNNING.name(), deployment.getStatus().getJobStatus().getState());
assertEquals(deployment.getMetadata().getName(), deployment.getStatus().getJobStatus().getJobName());
// Test listing failure
flinkService.clear();
observer.observe(deployment, readyContext, conf);
assertEquals(JobManagerDeploymentStatus.READY, deployment.getStatus().getJobManagerDeploymentStatus());
assertEquals(Observer.JOB_STATE_UNKNOWN, deployment.getStatus().getJobStatus().getState());
}
use of org.apache.flink.kubernetes.operator.TestingFlinkService in project flink-kubernetes-operator by apache.
the class ObserverTest method observeSessionCluster.
@Test
public void observeSessionCluster() {
FlinkService flinkService = new TestingFlinkService();
Observer observer = new Observer(flinkService, FlinkOperatorConfiguration.fromConfiguration(new Configuration()));
FlinkDeployment deployment = TestUtils.buildSessionCluster();
deployment.getStatus().getReconciliationStatus().setLastReconciledSpec(deployment.getSpec());
observer.observe(deployment, readyContext, FlinkUtils.getEffectiveConfig(deployment, new Configuration()));
assertEquals(JobManagerDeploymentStatus.DEPLOYED_NOT_READY, deployment.getStatus().getJobManagerDeploymentStatus());
observer.observe(deployment, readyContext, FlinkUtils.getEffectiveConfig(deployment, new Configuration()));
assertEquals(JobManagerDeploymentStatus.READY, deployment.getStatus().getJobManagerDeploymentStatus());
}
use of org.apache.flink.kubernetes.operator.TestingFlinkService in project flink-kubernetes-operator by apache.
the class ObserverTest method observeSavepoint.
@Test
public void observeSavepoint() throws Exception {
TestingFlinkService flinkService = new TestingFlinkService();
Observer observer = new Observer(flinkService, FlinkOperatorConfiguration.fromConfiguration(new Configuration()));
FlinkDeployment deployment = TestUtils.buildApplicationCluster();
Configuration conf = FlinkUtils.getEffectiveConfig(deployment, new Configuration());
flinkService.submitApplicationCluster(deployment, conf);
bringToReadyStatus(deployment);
observer.observe(deployment, readyContext, conf);
assertEquals(JobManagerDeploymentStatus.READY, deployment.getStatus().getJobManagerDeploymentStatus());
flinkService.triggerSavepoint(deployment, conf);
assertEquals("trigger_0", deployment.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
observer.observe(deployment, readyContext, conf);
assertEquals("savepoint_0", deployment.getStatus().getJobStatus().getSavepointInfo().getLastSavepoint().getLocation());
assertNull(deployment.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
flinkService.triggerSavepoint(deployment, conf);
assertEquals("trigger_1", deployment.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
observer.observe(deployment, readyContext, conf);
assertEquals("savepoint_1", deployment.getStatus().getJobStatus().getSavepointInfo().getLastSavepoint().getLocation());
assertNull(deployment.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
}
use of org.apache.flink.kubernetes.operator.TestingFlinkService in project flink-kubernetes-operator by apache.
the class JobReconcilerTest method triggerSavepoint.
@Test
public void triggerSavepoint() throws Exception {
Context context = TestUtils.createContextWithReadyJobManagerDeployment();
TestingFlinkService flinkService = new TestingFlinkService();
JobReconciler reconciler = new JobReconciler(null, flinkService, operatorConfiguration);
FlinkDeployment deployment = TestUtils.buildApplicationCluster();
Configuration config = FlinkUtils.getEffectiveConfig(deployment, new Configuration());
reconciler.reconcile("test", deployment, context, config);
List<Tuple2<String, JobStatusMessage>> runningJobs = flinkService.listJobs();
verifyAndSetRunningJobsToStatus(deployment, runningJobs);
assertNull(deployment.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
// trigger savepoint
FlinkDeployment spDeployment = ReconciliationUtils.clone(deployment);
long oldValue = spDeployment.getSpec().getJob().getSavepointTriggerNonce();
spDeployment.getSpec().getJob().setSavepointTriggerNonce(oldValue + 1);
reconciler.reconcile("test", spDeployment, context, config);
assertEquals("trigger_0", spDeployment.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
}
use of org.apache.flink.kubernetes.operator.TestingFlinkService in project flink-kubernetes-operator by apache.
the class ApplicationObserverTest method observeSavepoint.
@Test
public void observeSavepoint() throws Exception {
TestingFlinkService flinkService = new TestingFlinkService(kubernetesClient);
ApplicationObserver observer = new ApplicationObserver(null, flinkService, configManager, new TestingStatusHelper<>());
FlinkDeployment deployment = TestUtils.buildApplicationCluster();
Configuration conf = configManager.getDeployConfig(deployment.getMetadata(), deployment.getSpec());
flinkService.submitApplicationCluster(deployment.getSpec().getJob(), conf, false);
bringToReadyStatus(deployment);
assertTrue(ReconciliationUtils.isJobRunning(deployment.getStatus()));
flinkService.triggerSavepoint(deployment.getStatus().getJobStatus().getJobId(), SavepointTriggerType.MANUAL, deployment.getStatus().getJobStatus().getSavepointInfo(), conf);
// pending savepoint
assertEquals("trigger_0", deployment.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
observer.observe(deployment, readyContext);
assertTrue(SavepointUtils.savepointInProgress(deployment.getStatus().getJobStatus()));
deployment.getStatus().getJobStatus().getSavepointInfo().setTriggerId("unknown");
// savepoint error within grace period
assertEquals(0, kubernetesClient.v1().events().inNamespace(deployment.getMetadata().getNamespace()).list().getItems().size());
observer.observe(deployment, readyContext);
assertFalse(SavepointUtils.savepointInProgress(deployment.getStatus().getJobStatus()));
assertEquals(0, kubernetesClient.v1().events().inNamespace(deployment.getMetadata().getNamespace()).list().getItems().size());
deployment.getStatus().getJobStatus().getSavepointInfo().setTriggerId("unknown");
deployment.getStatus().getJobStatus().getSavepointInfo().setTriggerType(SavepointTriggerType.MANUAL);
deployment.getStatus().getJobStatus().getSavepointInfo().setTriggerTimestamp(Instant.now().minus(Duration.ofHours(1)).toEpochMilli());
observer.observe(deployment, readyContext);
assertFalse(SavepointUtils.savepointInProgress(deployment.getStatus().getJobStatus()));
assertEquals(1, kubernetesClient.v1().events().inNamespace(deployment.getMetadata().getNamespace()).list().getItems().size());
assertEquals(1, kubernetesClient.v1().events().inNamespace(deployment.getMetadata().getNamespace()).list().getItems().get(0).getCount());
// savepoint success
flinkService.triggerSavepoint(deployment.getStatus().getJobStatus().getJobId(), SavepointTriggerType.MANUAL, deployment.getStatus().getJobStatus().getSavepointInfo(), conf);
assertEquals("trigger_1", deployment.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
observer.observe(deployment, readyContext);
observer.observe(deployment, readyContext);
assertEquals("savepoint_0", deployment.getStatus().getJobStatus().getSavepointInfo().getLastSavepoint().getLocation());
assertFalse(SavepointUtils.savepointInProgress(deployment.getStatus().getJobStatus()));
// second attempt success
flinkService.triggerSavepoint(deployment.getStatus().getJobStatus().getJobId(), SavepointTriggerType.MANUAL, deployment.getStatus().getJobStatus().getSavepointInfo(), conf);
assertEquals("trigger_2", deployment.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
assertTrue(SavepointUtils.savepointInProgress(deployment.getStatus().getJobStatus()));
observer.observe(deployment, readyContext);
observer.observe(deployment, readyContext);
assertEquals("savepoint_1", deployment.getStatus().getJobStatus().getSavepointInfo().getLastSavepoint().getLocation());
assertFalse(SavepointUtils.savepointInProgress(deployment.getStatus().getJobStatus()));
// application failure after checkpoint trigger
flinkService.triggerSavepoint(deployment.getStatus().getJobStatus().getJobId(), SavepointTriggerType.MANUAL, deployment.getStatus().getJobStatus().getSavepointInfo(), conf);
assertEquals("trigger_3", deployment.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
assertTrue(SavepointUtils.savepointInProgress(deployment.getStatus().getJobStatus()));
flinkService.setPortReady(false);
observer.observe(deployment, readyContext);
assertEquals("savepoint_1", deployment.getStatus().getJobStatus().getSavepointInfo().getLastSavepoint().getLocation());
assertFalse(SavepointUtils.savepointInProgress(deployment.getStatus().getJobStatus()));
assertEquals(1, kubernetesClient.v1().events().inNamespace(deployment.getMetadata().getNamespace()).list().getItems().size());
assertEquals(2, kubernetesClient.v1().events().inNamespace(deployment.getMetadata().getNamespace()).list().getItems().get(0).getCount());
flinkService.setPortReady(true);
observer.observe(deployment, readyContext);
// Simulate Failed job
Tuple2<String, JobStatusMessage> jobTuple = flinkService.listJobs().get(0);
jobTuple.f0 = "last-SP";
jobTuple.f1 = new JobStatusMessage(jobTuple.f1.getJobId(), jobTuple.f1.getJobName(), org.apache.flink.api.common.JobStatus.FAILED, jobTuple.f1.getStartTime());
deployment.getStatus().getJobStatus().getSavepointInfo().setTriggerId("test");
deployment.getStatus().getJobStatus().getSavepointInfo().setTriggerTimestamp(123L);
observer.observe(deployment, readyContext);
assertEquals(org.apache.flink.api.common.JobStatus.FAILED.name(), deployment.getStatus().getJobStatus().getState());
assertEquals("last-SP", deployment.getStatus().getJobStatus().getSavepointInfo().getLastSavepoint().getLocation());
assertFalse(SavepointUtils.savepointInProgress(deployment.getStatus().getJobStatus()));
}
Aggregations