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());
}
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);
}
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");
}
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()));
}
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");
}
Aggregations