Search in sources :

Example 1 with FlinkDeployment

use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.

the class FlinkDeploymentControllerTest method verifyStatelessUpgrade.

@Test
public void verifyStatelessUpgrade() {
    FlinkDeployment appCluster = TestUtils.buildApplicationCluster();
    appCluster.getSpec().getJob().setUpgradeMode(UpgradeMode.STATELESS);
    appCluster.getSpec().getJob().setInitialSavepointPath("s0");
    testController.reconcile(appCluster, TestUtils.createEmptyContext());
    List<Tuple2<String, JobStatusMessage>> jobs = flinkService.listJobs();
    assertEquals(1, jobs.size());
    assertEquals("s0", jobs.get(0).f0);
    testController.reconcile(appCluster, context);
    testController.reconcile(appCluster, context);
    // Upgrade job
    appCluster = ReconciliationUtils.clone(appCluster);
    appCluster.getSpec().getJob().setParallelism(100);
    UpdateControl<FlinkDeployment> updateControl = testController.reconcile(appCluster, context);
    assertEquals(JobManagerDeploymentStatus.DEPLOYING.toUpdateControl(appCluster, operatorConfiguration).getScheduleDelay(), updateControl.getScheduleDelay());
    testController.reconcile(appCluster, context);
    jobs = flinkService.listJobs();
    assertEquals(1, jobs.size());
    assertEquals(null, jobs.get(0).f0);
    testController.reconcile(appCluster, context);
    testController.reconcile(appCluster, context);
    // Suspend job
    appCluster = ReconciliationUtils.clone(appCluster);
    appCluster.getSpec().getJob().setState(JobState.SUSPENDED);
    testController.reconcile(appCluster, context);
    // Resume from empty state
    appCluster = ReconciliationUtils.clone(appCluster);
    appCluster.getSpec().getJob().setState(JobState.RUNNING);
    testController.reconcile(appCluster, context);
    jobs = flinkService.listJobs();
    assertEquals(1, jobs.size());
    assertEquals(null, jobs.get(0).f0);
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.jupiter.api.Test)

Example 2 with FlinkDeployment

use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.

the class FlinkDeploymentControllerTest method testUpgradeNotReadyCluster.

@Test
public void testUpgradeNotReadyCluster() {
    testUpgradeNotReadyCluster(TestUtils.buildSessionCluster(), true);
    FlinkDeployment appCluster = TestUtils.buildApplicationCluster();
    appCluster.getSpec().getJob().setUpgradeMode(UpgradeMode.STATELESS);
    testUpgradeNotReadyCluster(appCluster, true);
    appCluster = TestUtils.buildApplicationCluster();
    appCluster.getSpec().getJob().setUpgradeMode(UpgradeMode.LAST_STATE);
    testUpgradeNotReadyCluster(appCluster, true);
    appCluster = TestUtils.buildApplicationCluster();
    appCluster.getSpec().getJob().setUpgradeMode(UpgradeMode.SAVEPOINT);
    testUpgradeNotReadyCluster(appCluster, false);
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Test(org.junit.jupiter.api.Test)

Example 3 with FlinkDeployment

use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.

the class FlinkDeploymentControllerTest method verifyUpgradeFromSavepoint.

@Test
public void verifyUpgradeFromSavepoint() {
    FlinkDeployment appCluster = TestUtils.buildApplicationCluster();
    appCluster.getSpec().getJob().setUpgradeMode(UpgradeMode.SAVEPOINT);
    appCluster.getSpec().getJob().setInitialSavepointPath("s0");
    testController.reconcile(appCluster, TestUtils.createEmptyContext());
    List<Tuple2<String, JobStatusMessage>> jobs = flinkService.listJobs();
    assertEquals(1, jobs.size());
    assertEquals("s0", jobs.get(0).f0);
    List<Tuple2<String, JobStatusMessage>> previousJobs = new ArrayList<>(jobs);
    appCluster = ReconciliationUtils.clone(appCluster);
    appCluster.getSpec().getJob().setInitialSavepointPath("s1");
    // Send in a no-op change
    testController.reconcile(appCluster, context);
    assertEquals(previousJobs, new ArrayList<>(flinkService.listJobs()));
    // Upgrade job
    appCluster = ReconciliationUtils.clone(appCluster);
    appCluster.getSpec().getJob().setParallelism(100);
    testController.reconcile(appCluster, context);
    jobs = flinkService.listJobs();
    assertEquals(1, jobs.size());
    assertEquals("savepoint_0", jobs.get(0).f0);
    testController.reconcile(appCluster, context);
    // Suspend job
    appCluster = ReconciliationUtils.clone(appCluster);
    appCluster.getSpec().getJob().setState(JobState.SUSPENDED);
    testController.reconcile(appCluster, context);
    assertEquals(JobManagerDeploymentStatus.MISSING, appCluster.getStatus().getJobManagerDeploymentStatus());
    // Resume from last savepoint
    appCluster = ReconciliationUtils.clone(appCluster);
    appCluster.getSpec().getJob().setState(JobState.RUNNING);
    testController.reconcile(appCluster, TestUtils.createEmptyContext());
    jobs = flinkService.listJobs();
    assertEquals(1, jobs.size());
    assertEquals("savepoint_1", jobs.get(0).f0);
    testController.reconcile(appCluster, context);
    testController.cleanup(appCluster, context);
    jobs = flinkService.listJobs();
    assertEquals(0, jobs.size());
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 4 with FlinkDeployment

use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment 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 5 with FlinkDeployment

use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment 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)

Aggregations

FlinkDeployment (org.apache.flink.kubernetes.operator.crd.FlinkDeployment)66 Test (org.junit.jupiter.api.Test)44 TestingFlinkService (org.apache.flink.kubernetes.operator.TestingFlinkService)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 Configuration (org.apache.flink.configuration.Configuration)16 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)13 Context (io.javaoperatorsdk.operator.api.reconciler.Context)11 JobStatus (org.apache.flink.kubernetes.operator.crd.status.JobStatus)9 FlinkDeploymentStatus (org.apache.flink.kubernetes.operator.crd.status.FlinkDeploymentStatus)8 FlinkOperatorConfiguration (org.apache.flink.kubernetes.operator.config.FlinkOperatorConfiguration)6 FlinkDeploymentSpec (org.apache.flink.kubernetes.operator.crd.spec.FlinkDeploymentSpec)6 DeploymentFailedException (org.apache.flink.kubernetes.operator.exception.DeploymentFailedException)5 JobID (org.apache.flink.api.common.JobID)4 TestingClusterClient (org.apache.flink.kubernetes.operator.TestingClusterClient)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)3 Pod (io.fabric8.kubernetes.api.model.Pod)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 CompletableFuture (java.util.concurrent.CompletableFuture)3