sv2000 commented on a change in pull request #2911: [Gobblin-1069]Add NPE check 
in handleContainerCompletion method
URL: https://github.com/apache/incubator-gobblin/pull/2911#discussion_r389177278
 
 

 ##########
 File path: gobblin-yarn/src/main/java/org/apache/gobblin/yarn/YarnService.java
 ##########
 @@ -644,42 +635,46 @@ protected void handleContainerCompletion(ContainerStatus 
containerStatus) {
     if (this.shutdownInProgress) {
       return;
     }
+    if(completedContainerEntry != null) {
+      String completedInstanceName = completedContainerEntry.getValue();
 
-    this.helixInstanceRetryCount.putIfAbsent(completedInstanceName, new 
AtomicInteger(0));
-    int retryCount =
-        
this.helixInstanceRetryCount.get(completedInstanceName).incrementAndGet();
+      LOGGER.info(String.format("Container %s running Helix instance %s has 
completed with exit status %d",
+          containerStatus.getContainerId(), completedInstanceName, 
containerStatus.getExitStatus()));
 
-    // Populate event metadata
-    Optional<ImmutableMap.Builder<String, String>> eventMetadataBuilder = 
Optional.absent();
-    if (this.eventSubmitter.isPresent()) {
-      eventMetadataBuilder = 
Optional.of(buildContainerStatusEventMetadata(containerStatus));
-      
eventMetadataBuilder.get().put(GobblinYarnEventConstants.EventMetadata.HELIX_INSTANCE_ID,
 completedInstanceName);
-      
eventMetadataBuilder.get().put(GobblinYarnEventConstants.EventMetadata.CONTAINER_STATUS_RETRY_ATTEMPT,
 retryCount + "");
-    }
+      this.helixInstanceRetryCount.putIfAbsent(completedInstanceName, new 
AtomicInteger(0));
+      int retryCount = 
this.helixInstanceRetryCount.get(completedInstanceName).incrementAndGet();
 
-    if (this.helixInstanceMaxRetries > 0 && retryCount > 
this.helixInstanceMaxRetries) {
+      // Populate event metadata
+      Optional<ImmutableMap.Builder<String, String>> eventMetadataBuilder = 
Optional.absent();
       if (this.eventSubmitter.isPresent()) {
-        
this.eventSubmitter.get().submit(GobblinYarnEventConstants.EventNames.HELIX_INSTANCE_COMPLETION,
-            eventMetadataBuilder.get().build());
+        eventMetadataBuilder = 
Optional.of(buildContainerStatusEventMetadata(containerStatus));
+        
eventMetadataBuilder.get().put(GobblinYarnEventConstants.EventMetadata.HELIX_INSTANCE_ID,
 completedInstanceName);
+        
eventMetadataBuilder.get().put(GobblinYarnEventConstants.EventMetadata.CONTAINER_STATUS_RETRY_ATTEMPT,
 retryCount + "");
       }
 
-      LOGGER.warn("Maximum number of retries has been achieved for Helix 
instance " + completedInstanceName);
-      return;
-    }
+      if (this.helixInstanceMaxRetries > 0 && retryCount > 
this.helixInstanceMaxRetries) {
+        if (this.eventSubmitter.isPresent()) {
+          this.eventSubmitter.get()
+              
.submit(GobblinYarnEventConstants.EventNames.HELIX_INSTANCE_COMPLETION, 
eventMetadataBuilder.get().build());
+        }
 
-    // Add the Helix instance name of the completed container to the queue of 
unused
-    // instance names so they can be reused by a replacement container.
-    this.unusedHelixInstanceNames.offer(completedInstanceName);
+        LOGGER.warn("Maximum number of retries has been achieved for Helix 
instance " + completedInstanceName);
+        return;
+      }
 
-    if (this.eventSubmitter.isPresent()) {
-      
this.eventSubmitter.get().submit(GobblinYarnEventConstants.EventNames.HELIX_INSTANCE_COMPLETION,
-          eventMetadataBuilder.get().build());
-    }
+      // Add the Helix instance name of the completed container to the queue 
of unused
+      // instance names so they can be reused by a replacement container.
+      this.unusedHelixInstanceNames.offer(completedInstanceName);
+
+      if (this.eventSubmitter.isPresent()) {
+        this.eventSubmitter.get()
+            
.submit(GobblinYarnEventConstants.EventNames.HELIX_INSTANCE_COMPLETION, 
eventMetadataBuilder.get().build());
+      }
 
-    LOGGER.info(String.format("Requesting a new container to replace %s to run 
Helix instance %s",
-        containerStatus.getContainerId(), completedInstanceName));
+      LOGGER.info(String.format("Requesting a new container to replace %s to 
run Helix instance %s", containerStatus.getContainerId(), 
completedInstanceName));
 
 Review comment:
   Can we move this log line outside the if block? So:
   LOGGER.info(String.format("Requesting a new container to replace %s to run 
Helix instance %s", containerStatus.getContainerId(), (completedInstanceName != 
null) ? completedInstanceName: "unknown"));

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to