use of com.continuuity.weave.internal.WeaveContainerController in project weave by continuuity.
the class RunningContainers method stopAll.
/**
* Stops all running services. Only called when the AppMaster stops.
*/
void stopAll() {
containerLock.lock();
try {
// Stop it one by one in reverse order of start sequence
Iterator<String> itor = startSequence.descendingIterator();
List<ListenableFuture<ServiceController.State>> futures = Lists.newLinkedList();
while (itor.hasNext()) {
String runnableName = itor.next();
LOG.info("Stopping all instances of " + runnableName);
futures.clear();
// Parallel stops all running containers of the current runnable.
for (WeaveContainerController controller : containers.row(runnableName).values()) {
futures.add(controller.stop());
}
// Wait for containers to stop. Assumes the future returned by Futures.successfulAsList won't throw exception.
Futures.getUnchecked(Futures.successfulAsList(futures));
LOG.info("Terminated all instances of " + runnableName);
}
containers.clear();
runnableInstances.clear();
} finally {
containerLock.unlock();
}
}
use of com.continuuity.weave.internal.WeaveContainerController in project weave by continuuity.
the class RunningContainers method getRunId.
private RunId getRunId(String runnableName, int instanceId) {
RunId baseId;
Collection<WeaveContainerController> controllers = containers.row(runnableName).values();
if (controllers.isEmpty()) {
baseId = RunIds.generate();
} else {
String id = controllers.iterator().next().getRunId().getId();
baseId = RunIds.fromString(id.substring(0, id.lastIndexOf('-')));
}
return RunIds.fromString(baseId.getId() + '-' + instanceId);
}
use of com.continuuity.weave.internal.WeaveContainerController in project weave by continuuity.
the class RunningContainers method handleCompleted.
/**
* Handle completion of container.
* @param status The completion status.
* @param restartRunnables Set of runnable names that requires restart.
*/
void handleCompleted(YarnContainerStatus status, Multiset<String> restartRunnables) {
containerLock.lock();
String containerId = status.getContainerId();
int exitStatus = status.getExitStatus();
ContainerState state = status.getState();
try {
Map<String, WeaveContainerController> lookup = containers.column(containerId);
if (lookup.isEmpty()) {
// It's OK because if a container is stopped through removeLast, this would be empty.
return;
}
if (lookup.size() != 1) {
LOG.warn("More than one controller found for container {}", containerId);
}
if (exitStatus != 0) {
LOG.warn("Container {} exited abnormally with state {}, exit code {}. Re-request the container.", containerId, state, exitStatus);
restartRunnables.add(lookup.keySet().iterator().next());
} else {
LOG.info("Container {} exited normally with state {}", containerId, state);
}
for (Map.Entry<String, WeaveContainerController> completedEntry : lookup.entrySet()) {
String runnableName = completedEntry.getKey();
WeaveContainerController controller = completedEntry.getValue();
controller.completed(exitStatus);
removeInstanceId(runnableName, getInstanceId(controller.getRunId()));
resourceReport.removeRunnableResources(runnableName, containerId);
}
lookup.clear();
containerChange.signalAll();
} finally {
containerLock.unlock();
}
}
use of com.continuuity.weave.internal.WeaveContainerController in project weave by continuuity.
the class RunningContainers method removeLast.
/**
* Stops and removes the last running container of the given runnable.
*/
void removeLast(String runnableName) {
containerLock.lock();
try {
int maxInstanceId = getMaxInstanceId(runnableName);
if (maxInstanceId < 0) {
LOG.warn("No running container found for {}", runnableName);
return;
}
String lastContainerId = null;
WeaveContainerController lastController = null;
// Find the controller with the maxInstanceId
for (Map.Entry<String, WeaveContainerController> entry : containers.row(runnableName).entrySet()) {
if (getInstanceId(entry.getValue().getRunId()) == maxInstanceId) {
lastContainerId = entry.getKey();
lastController = entry.getValue();
break;
}
}
Preconditions.checkState(lastContainerId != null, "No container found for {} with instanceId = {}", runnableName, maxInstanceId);
LOG.info("Stopping service: {} {}", runnableName, lastController.getRunId());
lastController.stopAndWait();
containers.remove(runnableName, lastContainerId);
removeInstanceId(runnableName, maxInstanceId);
resourceReport.removeRunnableResources(runnableName, lastContainerId);
containerChange.signalAll();
} finally {
containerLock.unlock();
}
}
use of com.continuuity.weave.internal.WeaveContainerController in project weave by continuuity.
the class RunningContainers method sendToRunnable.
void sendToRunnable(String runnableName, Message message, Runnable completion) {
containerLock.lock();
try {
Collection<WeaveContainerController> controllers = containers.row(runnableName).values();
if (controllers.isEmpty()) {
completion.run();
}
AtomicInteger count = new AtomicInteger(controllers.size());
for (WeaveContainerController controller : controllers) {
sendMessage(runnableName, message, controller, count, completion);
}
} finally {
containerLock.unlock();
}
}
Aggregations