safeAddCallback(future, callback);
}
// start new containers
for (final Participant participant : response.getContainersToStart()) {
final ContainerId containerId = participant.getInstanceConfig().getContainerId();
updateContainerState(cache, accessor, keyBuilder, cluster, null, participant.getId(),
ContainerState.CONNECTING);
// create the helix participant and add it to cluster
LOG.info("Starting container " + containerId + " for " + participant.getId());
ListenableFuture<Boolean> future =
containerProvider.startContainer(containerId, participant);
FutureCallback<Boolean> callback = new FutureCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
// Do nothing yet, need to wait for live instance
LOG.info("Container " + containerId + " started for " + participant.getId());
}
@Override
public void onFailure(Throwable t) {
LOG.error("Could not start container" + containerId + "for participant "
+ participant.getId(), t);
updateContainerState(cache, accessor, keyBuilder, cluster, null, participant.getId(),
ContainerState.FAILED);
}
};
safeAddCallback(future, callback);
}
// release containers
for (final Participant participant : response.getContainersToRelease()) {
// mark it as finalizing
final ContainerId containerId = participant.getInstanceConfig().getContainerId();
updateContainerState(cache, accessor, keyBuilder, cluster, null, participant.getId(),
ContainerState.FINALIZING);
// remove the participant
LOG.info("Deallocating container " + containerId + " for " + participant.getId());
ListenableFuture<Boolean> future = containerProvider.deallocateContainer(containerId);
FutureCallback<Boolean> callback = new FutureCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
LOG.info("Container " + containerId + " deallocated. Dropping " + participant.getId());
InstanceConfig existingInstance =
helixAdmin.getInstanceConfig(cluster.getId().toString(), participant.getId()
.toString());
helixAdmin.dropInstance(cluster.getId().toString(), existingInstance);
cache.requireFullRefresh();
}
@Override
public void onFailure(Throwable t) {
LOG.error("Could not deallocate container" + containerId + "for participant "
+ participant.getId(), t);
updateContainerState(cache, accessor, keyBuilder, cluster, null, participant.getId(),
ContainerState.FAILED);
}
};
safeAddCallback(future, callback);
}
// stop but don't remove
for (final Participant participant : response.getContainersToStop()) {
// switch to halting
final ContainerId containerId = participant.getInstanceConfig().getContainerId();
updateContainerState(cache, accessor, keyBuilder, cluster, null, participant.getId(),
ContainerState.HALTING);
// stop the container
LOG.info("Stopping container " + containerId + " for " + participant.getId());
ListenableFuture<Boolean> future = containerProvider.stopContainer(containerId);