Search in sources :

Example 1 with TestingFlinkService

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());
}
Also used : JobStatus(org.apache.flink.kubernetes.operator.crd.status.JobStatus) FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) FlinkDeploymentStatus(org.apache.flink.kubernetes.operator.crd.status.FlinkDeploymentStatus) Configuration(org.apache.flink.configuration.Configuration) FlinkOperatorConfiguration(org.apache.flink.kubernetes.operator.config.FlinkOperatorConfiguration) TestingFlinkService(org.apache.flink.kubernetes.operator.TestingFlinkService) Test(org.junit.jupiter.api.Test)

Example 2 with TestingFlinkService

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());
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Configuration(org.apache.flink.configuration.Configuration) FlinkOperatorConfiguration(org.apache.flink.kubernetes.operator.config.FlinkOperatorConfiguration) TestingFlinkService(org.apache.flink.kubernetes.operator.TestingFlinkService) TestingFlinkService(org.apache.flink.kubernetes.operator.TestingFlinkService) FlinkService(org.apache.flink.kubernetes.operator.service.FlinkService) Test(org.junit.jupiter.api.Test)

Example 3 with TestingFlinkService

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());
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Configuration(org.apache.flink.configuration.Configuration) FlinkOperatorConfiguration(org.apache.flink.kubernetes.operator.config.FlinkOperatorConfiguration) TestingFlinkService(org.apache.flink.kubernetes.operator.TestingFlinkService) Test(org.junit.jupiter.api.Test)

Example 4 with TestingFlinkService

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());
}
Also used : Context(io.javaoperatorsdk.operator.api.reconciler.Context) FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Configuration(org.apache.flink.configuration.Configuration) FlinkOperatorConfiguration(org.apache.flink.kubernetes.operator.config.FlinkOperatorConfiguration) TestingFlinkService(org.apache.flink.kubernetes.operator.TestingFlinkService) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.jupiter.api.Test)

Example 5 with TestingFlinkService

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()));
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Configuration(org.apache.flink.configuration.Configuration) TestingFlinkService(org.apache.flink.kubernetes.operator.TestingFlinkService) JobStatusMessage(org.apache.flink.runtime.client.JobStatusMessage) Test(org.junit.jupiter.api.Test)

Aggregations

TestingFlinkService (org.apache.flink.kubernetes.operator.TestingFlinkService)31 Test (org.junit.jupiter.api.Test)27 FlinkDeployment (org.apache.flink.kubernetes.operator.crd.FlinkDeployment)19 Context (io.javaoperatorsdk.operator.api.reconciler.Context)12 Configuration (org.apache.flink.configuration.Configuration)12 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)9 FlinkSessionJob (org.apache.flink.kubernetes.operator.crd.FlinkSessionJob)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 FlinkOperatorConfiguration (org.apache.flink.kubernetes.operator.config.FlinkOperatorConfiguration)6 FlinkDeploymentStatus (org.apache.flink.kubernetes.operator.crd.status.FlinkDeploymentStatus)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 JobStatus (org.apache.flink.kubernetes.operator.crd.status.JobStatus)2 DeploymentFailedException (org.apache.flink.kubernetes.operator.exception.DeploymentFailedException)2 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FlinkConfigManager (org.apache.flink.kubernetes.operator.config.FlinkConfigManager)1 FlinkDeploymentSpec (org.apache.flink.kubernetes.operator.crd.spec.FlinkDeploymentSpec)1 JobSpec (org.apache.flink.kubernetes.operator.crd.spec.JobSpec)1 FlinkSessionJobReconciler (org.apache.flink.kubernetes.operator.reconciler.sessionjob.FlinkSessionJobReconciler)1 FlinkService (org.apache.flink.kubernetes.operator.service.FlinkService)1