[Gobblin-1069][GOBBLIN-1069] Add NPE check in handleContainerCompletion method
Closes from ZihanLi58/GOBBLIN-1069-new
@@ -620,11 +620,7 @@ public class YarnService extends AbstractIdleService {
*/
protected void handleContainerCompletion(ContainerStatus containerStatus) {
Map.Entry<Container, String> completedContainerEntry = this.containerMap.remove(containerStatus.getContainerId());
- if (completedContainerEntry == null) {
- //No map for this container means we don't maintain this container, directly return
- return;
- }
- String completedInstanceName = completedContainerEntry.getValue();
+ String completedInstanceName = completedContainerEntry == null? "unknown" : completedContainerEntry.getValue();
LOGGER.info(String.format("Container %s running Helix instance %s has completed with exit status %d",
containerStatus.getContainerId(), completedInstanceName, containerStatus.getExitStatus()));
@@ -643,10 +639,9 @@ public class YarnService extends AbstractIdleService {
if (this.shutdownInProgress) {
return;
}
-
+ if(completedContainerEntry != null) {
this.helixInstanceRetryCount.putIfAbsent(completedInstanceName, new AtomicInteger(0));
- int retryCount =
- this.helixInstanceRetryCount.get(completedInstanceName).incrementAndGet();
+ int retryCount = this.helixInstanceRetryCount.get(completedInstanceName).incrementAndGet();
// Populate event metadata
Optional<ImmutableMap.Builder<String, String>> eventMetadataBuilder = Optional.absent();
@@ -658,8 +653,8 @@ public class YarnService extends AbstractIdleService {
if (this.helixInstanceMaxRetries > 0 && retryCount > this.helixInstanceMaxRetries) {
if (this.eventSubmitter.isPresent()) {
- this.eventSubmitter.get().submit(GobblinYarnEventConstants.EventNames.HELIX_INSTANCE_COMPLETION,
- eventMetadataBuilder.get().build());
+ this.eventSubmitter.get()
+ .submit(GobblinYarnEventConstants.EventNames.HELIX_INSTANCE_COMPLETION, eventMetadataBuilder.get().build());
}
LOGGER.warn("Maximum number of retries has been achieved for Helix instance " + completedInstanceName);
@@ -671,14 +666,13 @@ public class YarnService extends AbstractIdleService {
this.unusedHelixInstanceNames.offer(completedInstanceName);
if (this.eventSubmitter.isPresent()) {
- this.eventSubmitter.get().submit(GobblinYarnEventConstants.EventNames.HELIX_INSTANCE_COMPLETION,
- eventMetadataBuilder.get().build());
+ 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));
this.eventBus.post(new NewContainerRequest(
- shouldStickToTheSameNode(containerStatus.getExitStatus()) ?
+ shouldStickToTheSameNode(containerStatus.getExitStatus()) && completedContainerEntry != null ?
Optional.of(completedContainerEntry.getKey()) : Optional.<Container>absent()));
}
