tweise commented on a change in pull request #26:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/26#discussion_r817364192



##########
File path: 
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/observer/Observer.java
##########
@@ -27,27 +27,82 @@
 import org.apache.flink.kubernetes.operator.service.FlinkService;
 import org.apache.flink.runtime.client.JobStatusMessage;
 
+import io.fabric8.kubernetes.api.model.apps.Deployment;
+import io.fabric8.kubernetes.api.model.apps.DeploymentSpec;
+import io.fabric8.kubernetes.api.model.apps.DeploymentStatus;
+import io.javaoperatorsdk.operator.api.reconciler.Context;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Optional;
 
 /** Observes the actual state of the running jobs on the Flink cluster. */
-public class JobStatusObserver {
+public class Observer {
 
-    private static final Logger LOG = 
LoggerFactory.getLogger(JobStatusObserver.class);
+    private static final Logger LOG = LoggerFactory.getLogger(Observer.class);
 
     private final FlinkService flinkService;
 
-    public JobStatusObserver(FlinkService flinkService) {
+    public Observer(FlinkService flinkService) {
         this.flinkService = flinkService;
     }
 
-    public boolean observeFlinkJobStatus(FlinkDeployment flinkApp, 
Configuration effectiveConfig)
-            throws Exception {
+    public boolean observe(
+            FlinkDeployment flinkApp, Context context, Configuration 
effectiveConfig) {
+        observeJmDeployment(flinkApp, context);
+        return isReadyToReconcile(flinkApp, effectiveConfig);
+    }
+
+    private void observeJmDeployment(FlinkDeployment flinkApp, Context 
context) {
+        FlinkDeploymentStatus deploymentStatus = flinkApp.getStatus();
+        JobManagerDeploymentStatus previousJmStatus =
+                deploymentStatus.getJobManagerDeploymentStatus();
+
+        if (JobManagerDeploymentStatus.READY == previousJmStatus) {
+            return;
+        }
+
+        if (JobManagerDeploymentStatus.DEPLOYED_NOT_READY == previousJmStatus) 
{
+            
deploymentStatus.setJobManagerDeploymentStatus(JobManagerDeploymentStatus.READY);
+            return;
+        }
+
+        Optional<Deployment> deployment = 
context.getSecondaryResource(Deployment.class);
+        if (deployment.isPresent()) {
+            DeploymentStatus status = deployment.get().getStatus();
+            DeploymentSpec spec = deployment.get().getSpec();
+            if (status != null
+                    && status.getAvailableReplicas() != null
+                    && spec.getReplicas().intValue() == status.getReplicas()
+                    && spec.getReplicas().intValue() == 
status.getAvailableReplicas()) {
+                // typically it takes a few seconds for the REST server to be 
ready
+                LOG.info(

Review comment:
       @gyfora where is the port check happening?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to