Search in sources :

Example 6 with FlinkDeployment

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

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

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

the class FlinkConfigBuilderTest method testApplyTaskManagerSpec.

@Test
public void testApplyTaskManagerSpec() throws Exception {
    FlinkDeployment deploymentClone = ReconciliationUtils.clone(flinkDeployment);
    deploymentClone.getSpec().setPodTemplate(null);
    final Configuration configuration = new FlinkConfigBuilder(deploymentClone, new Configuration()).applyTaskManagerSpec().build();
    final Pod tmPod = OBJECT_MAPPER.readValue(new File(configuration.getString(KubernetesConfigOptions.TASK_MANAGER_POD_TEMPLATE)), Pod.class);
    Assert.assertEquals(MemorySize.parse("2048m"), configuration.get(TaskManagerOptions.TOTAL_PROCESS_MEMORY));
    Assert.assertEquals(Double.valueOf(1), configuration.get(KubernetesConfigOptions.TASK_MANAGER_CPU));
    Assert.assertEquals("pod2 api version", tmPod.getApiVersion());
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Configuration(org.apache.flink.configuration.Configuration) Pod(io.fabric8.kubernetes.api.model.Pod) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 9 with FlinkDeployment

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

the class DeploymentValidatorTest method testError.

private void testError(Consumer<FlinkDeployment> deploymentModifier, String expectedErr) {
    FlinkDeployment deployment = TestUtils.buildApplicationCluster();
    deploymentModifier.accept(deployment);
    Optional<String> error = validator.validate(deployment);
    if (error.isPresent()) {
        assertTrue(error.get(), error.get().startsWith(expectedErr));
    } else {
        fail("Did not get expected error: " + expectedErr);
    }
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment)

Example 10 with FlinkDeployment

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

the class TestUtils method buildSessionCluster.

public static FlinkDeployment buildSessionCluster() {
    FlinkDeployment deployment = new FlinkDeployment();
    deployment.setStatus(new FlinkDeploymentStatus());
    deployment.setMetadata(new ObjectMetaBuilder().withName("test-cluster").withNamespace(TEST_NAMESPACE).build());
    deployment.setSpec(getTestFlinkDeploymentSpec());
    return deployment;
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) FlinkDeploymentStatus(org.apache.flink.kubernetes.operator.crd.status.FlinkDeploymentStatus) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder)

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