Search in sources :

Example 1 with JobStatus

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

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

the class ObserverTest method bringToReadyStatus.

private void bringToReadyStatus(FlinkDeployment deployment) {
    deployment.getStatus().getReconciliationStatus().setLastReconciledSpec(ReconciliationUtils.clone(deployment.getSpec()));
    JobStatus jobStatus = new JobStatus();
    jobStatus.setJobName("jobname");
    jobStatus.setJobId("0000000000");
    jobStatus.setState(JobState.RUNNING.name());
    deployment.getStatus().setJobStatus(jobStatus);
    deployment.getStatus().setJobManagerDeploymentStatus(JobManagerDeploymentStatus.READY);
}
Also used : JobStatus(org.apache.flink.kubernetes.operator.crd.status.JobStatus)

Example 3 with JobStatus

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

the class DeploymentValidatorTest method testValidation.

@Test
public void testValidation() {
    testSuccess(dep -> {
    });
    // Test job validation
    testError(dep -> dep.getSpec().getJob().setJarURI(null), "Jar URI must be defined");
    testError(dep -> dep.getSpec().getJob().setState(JobState.SUSPENDED), "Job must start in running state");
    testError(dep -> dep.getSpec().getJob().setParallelism(0), "Job parallelism must be larger than 0");
    testError(dep -> dep.getSpec().getJob().setParallelism(-1), "Job parallelism must be larger than 0");
    testError(dep -> {
        dep.getSpec().setFlinkConfiguration(new HashMap<>());
        dep.getSpec().getJob().setUpgradeMode(UpgradeMode.LAST_STATE);
    }, "Job could not be upgraded with last-state while HA disabled");
    // Test conf validation
    testSuccess(dep -> dep.getSpec().setFlinkConfiguration(Collections.singletonMap("random", "config")));
    testError(dep -> dep.getSpec().setFlinkConfiguration(Collections.singletonMap(KubernetesConfigOptions.NAMESPACE.key(), "myns")), "Forbidden Flink config key");
    // Test log config validation
    testSuccess(dep -> dep.getSpec().setLogConfiguration(Map.of(Constants.CONFIG_FILE_LOG4J_NAME, "rootLogger.level = INFO")));
    testError(dep -> dep.getSpec().setLogConfiguration(Map.of("random", "config")), "Invalid log config key");
    testError(dep -> {
        dep.getSpec().setFlinkConfiguration(new HashMap<>());
        dep.getSpec().getJobManager().setReplicas(2);
    }, "High availability should be enabled when starting standby JobManagers.");
    testError(dep -> dep.getSpec().getJobManager().setReplicas(0), "JobManager replicas should not be configured less than one.");
    // Test resource validation
    testSuccess(dep -> dep.getSpec().getTaskManager().getResource().setMemory("1G"));
    testSuccess(dep -> dep.getSpec().getTaskManager().getResource().setMemory("100"));
    testError(dep -> dep.getSpec().getTaskManager().getResource().setMemory("invalid"), "TaskManager resource memory parse error");
    testError(dep -> dep.getSpec().getJobManager().getResource().setMemory("invalid"), "JobManager resource memory parse error");
    testError(dep -> dep.getSpec().getTaskManager().getResource().setMemory(null), "TaskManager resource memory must be defined");
    testError(dep -> dep.getSpec().getJobManager().getResource().setMemory(null), "JobManager resource memory must be defined");
    // Test savepoint restore validation
    testSuccess(dep -> {
        dep.setStatus(new FlinkDeploymentStatus());
        dep.getStatus().setJobStatus(new JobStatus());
        dep.getStatus().getJobStatus().getSavepointInfo().setLastSavepoint(Savepoint.of("sp"));
        dep.getStatus().setReconciliationStatus(new ReconciliationStatus());
        dep.getStatus().getReconciliationStatus().setLastReconciledSpec(ReconciliationUtils.clone(dep.getSpec()));
        dep.getStatus().getReconciliationStatus().getLastReconciledSpec().getJob().setState(JobState.SUSPENDED);
        dep.getSpec().getJob().setUpgradeMode(UpgradeMode.SAVEPOINT);
    });
    testError(dep -> {
        dep.setStatus(new FlinkDeploymentStatus());
        dep.getStatus().setJobStatus(new JobStatus());
        dep.getStatus().setReconciliationStatus(new ReconciliationStatus());
        dep.getStatus().getReconciliationStatus().setLastReconciledSpec(ReconciliationUtils.clone(dep.getSpec()));
        dep.getStatus().getReconciliationStatus().getLastReconciledSpec().getJob().setState(JobState.SUSPENDED);
        dep.getSpec().getJob().setUpgradeMode(UpgradeMode.SAVEPOINT);
    }, "Cannot perform savepoint restore without a valid savepoint");
    // Test cluster type validation
    testError(dep -> {
        dep.setStatus(new FlinkDeploymentStatus());
        dep.getStatus().setJobStatus(new JobStatus());
        dep.getStatus().setReconciliationStatus(new ReconciliationStatus());
        dep.getStatus().getReconciliationStatus().setLastReconciledSpec(ReconciliationUtils.clone(dep.getSpec()));
        dep.getSpec().setJob(null);
    }, "Cannot switch from job to session cluster");
    testError(dep -> {
        dep.setStatus(new FlinkDeploymentStatus());
        dep.getStatus().setJobStatus(new JobStatus());
        dep.getStatus().setReconciliationStatus(new ReconciliationStatus());
        dep.getStatus().getReconciliationStatus().setLastReconciledSpec(ReconciliationUtils.clone(dep.getSpec()));
        dep.getStatus().getReconciliationStatus().getLastReconciledSpec().setJob(null);
    }, "Cannot switch from session to job cluster");
}
Also used : JobStatus(org.apache.flink.kubernetes.operator.crd.status.JobStatus) FlinkDeploymentStatus(org.apache.flink.kubernetes.operator.crd.status.FlinkDeploymentStatus) ReconciliationStatus(org.apache.flink.kubernetes.operator.crd.status.ReconciliationStatus) Test(org.junit.jupiter.api.Test)

Example 4 with JobStatus

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

the class JobReconciler method restoreFromLastSavepoint.

private void restoreFromLastSavepoint(FlinkDeployment flinkApp, Configuration effectiveConfig) throws Exception {
    JobStatus jobStatus = flinkApp.getStatus().getJobStatus();
    deployFlinkJob(flinkApp, effectiveConfig, Optional.of(jobStatus.getSavepointInfo().getLastSavepoint().getLocation()));
}
Also used : JobStatus(org.apache.flink.kubernetes.operator.crd.status.JobStatus)

Example 5 with JobStatus

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

the class FlinkSessionJobReconcilerTest method verifyAndSetRunningJobsToStatus.

private void verifyAndSetRunningJobsToStatus(FlinkSessionJob sessionJob, JobState expectedState, String jobStatusObserved, @Nullable String expectedSavepointPath, Map<JobID, TestingFlinkService.SubmittedJobInfo> sessionJobs) {
    var submittedJobInfo = verifyAndReturnTheSubmittedJob(sessionJob, sessionJobs);
    assertEquals(expectedSavepointPath, submittedJobInfo.savepointPath);
    verifyJobState(sessionJob, expectedState, jobStatusObserved);
    JobStatus jobStatus = sessionJob.getStatus().getJobStatus();
    jobStatus.setJobName(submittedJobInfo.jobStatusMessage.getJobName());
    jobStatus.setState("RUNNING");
}
Also used : JobStatus(org.apache.flink.kubernetes.operator.crd.status.JobStatus)

Aggregations

JobStatus (org.apache.flink.kubernetes.operator.crd.status.JobStatus)20 Test (org.junit.jupiter.api.Test)10 FlinkDeployment (org.apache.flink.kubernetes.operator.crd.FlinkDeployment)9 JobID (org.apache.flink.api.common.JobID)4 TestingClusterClient (org.apache.flink.kubernetes.operator.TestingClusterClient)4 FlinkDeploymentStatus (org.apache.flink.kubernetes.operator.crd.status.FlinkDeploymentStatus)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 JobStatusMessage (org.apache.flink.runtime.client.JobStatusMessage)3 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)2 Configuration (org.apache.flink.configuration.Configuration)2 TestingFlinkService (org.apache.flink.kubernetes.operator.TestingFlinkService)2 FlinkDeploymentSpec (org.apache.flink.kubernetes.operator.crd.spec.FlinkDeploymentSpec)2 ReconciliationStatus (org.apache.flink.kubernetes.operator.crd.status.ReconciliationStatus)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 FlinkOperatorConfiguration (org.apache.flink.kubernetes.operator.config.FlinkOperatorConfiguration)1 IngressSpec (org.apache.flink.kubernetes.operator.crd.spec.IngressSpec)1 JobState (org.apache.flink.kubernetes.operator.crd.spec.JobState)1 FlinkDeploymentReconciliationStatus (org.apache.flink.kubernetes.operator.crd.status.FlinkDeploymentReconciliationStatus)1 Savepoint (org.apache.flink.kubernetes.operator.crd.status.Savepoint)1 TriggerResponse (org.apache.flink.runtime.rest.handler.async.TriggerResponse)1