use of com.continuuity.weave.internal.ProcessLauncher in project weave by continuuity.
the class ApplicationMasterService method launchRunnable.
/**
* Launches runnables in the provisioned containers.
*/
private void launchRunnable(List<ProcessLauncher<YarnContainerInfo>> launchers, Queue<ProvisionRequest> provisioning) {
for (ProcessLauncher<YarnContainerInfo> processLauncher : launchers) {
LOG.info("Got container {}", processLauncher.getContainerInfo().getId());
ProvisionRequest provisionRequest = provisioning.peek();
if (provisionRequest == null) {
continue;
}
String runnableName = provisionRequest.getRuntimeSpec().getName();
LOG.info("Starting runnable {} with {}", runnableName, processLauncher);
int containerCount = expectedContainers.getExpected(runnableName);
ProcessLauncher.PrepareLaunchContext launchContext = processLauncher.prepareLaunch(ImmutableMap.<String, String>builder().put(EnvKeys.WEAVE_APP_DIR, System.getenv(EnvKeys.WEAVE_APP_DIR)).put(EnvKeys.WEAVE_FS_USER, System.getenv(EnvKeys.WEAVE_FS_USER)).put(EnvKeys.WEAVE_APP_RUN_ID, runId.getId()).put(EnvKeys.WEAVE_APP_NAME, weaveSpec.getName()).put(EnvKeys.WEAVE_ZK_CONNECT, zkClient.getConnectString()).put(EnvKeys.WEAVE_LOG_KAFKA_ZK, getKafkaZKConnect()).build(), getLocalizeFiles(), credentials);
WeaveContainerLauncher launcher = new WeaveContainerLauncher(weaveSpec.getRunnables().get(runnableName), launchContext, ZKClients.namespace(zkClient, getZKNamespace(runnableName)), containerCount, jvmOpts, reservedMemory, getSecureStoreLocation());
runningContainers.start(runnableName, processLauncher.getContainerInfo(), launcher);
// Need to call complete to workaround bug in YARN AMRMClient
if (provisionRequest.containerAcquired()) {
amClient.completeContainerRequest(provisionRequest.getRequestId());
}
if (expectedContainers.getExpected(runnableName) == runningContainers.count(runnableName)) {
LOG.info("Runnable " + runnableName + " fully provisioned with " + containerCount + " instances.");
provisioning.poll();
}
}
}
use of com.continuuity.weave.internal.ProcessLauncher in project weave by continuuity.
the class Hadoop20YarnAMClient method allocate.
@Override
public synchronized void allocate(float progress, AllocateHandler handler) throws Exception {
AllocationResponse response = amrmClient.allocate(progress);
List<ProcessLauncher<YarnContainerInfo>> launchers = Lists.newArrayListWithCapacity(response.getAllocatedContainers().size());
for (Container container : response.getAllocatedContainers()) {
launchers.add(new RunnableProcessLauncher(new Hadoop20YarnContainerInfo(container), nmClient));
}
if (!launchers.isEmpty()) {
handler.acquired(launchers);
// If no process has been launched through the given launcher, return the container.
for (ProcessLauncher<YarnContainerInfo> l : launchers) {
// This cast always works.
RunnableProcessLauncher launcher = (RunnableProcessLauncher) l;
if (!launcher.isLaunched()) {
Container container = launcher.getContainerInfo().getContainer();
LOG.info("Nothing to run in container, releasing it: {}", container);
amrmClient.releaseAssignedContainer(container.getId());
}
}
}
List<YarnContainerStatus> completed = ImmutableList.copyOf(Iterables.transform(response.getCompletedContainersStatuses(), STATUS_TRANSFORM));
if (!completed.isEmpty()) {
handler.completed(completed);
}
}
use of com.continuuity.weave.internal.ProcessLauncher in project weave by continuuity.
the class Hadoop21YarnAMClient method allocate.
@Override
public synchronized void allocate(float progress, AllocateHandler handler) throws Exception {
AllocateResponse allocateResponse = amrmClient.allocate(progress);
List<ProcessLauncher<YarnContainerInfo>> launchers = Lists.newArrayListWithCapacity(allocateResponse.getAllocatedContainers().size());
for (Container container : allocateResponse.getAllocatedContainers()) {
launchers.add(new RunnableProcessLauncher(new Hadoop21YarnContainerInfo(container), nmClient));
}
if (!launchers.isEmpty()) {
handler.acquired(launchers);
// If no process has been launched through the given launcher, return the container.
for (ProcessLauncher<YarnContainerInfo> l : launchers) {
// This cast always works.
RunnableProcessLauncher launcher = (RunnableProcessLauncher) l;
if (!launcher.isLaunched()) {
Container container = launcher.getContainerInfo().getContainer();
LOG.info("Nothing to run in container, releasing it: {}", container);
amrmClient.releaseAssignedContainer(container.getId());
}
}
}
List<YarnContainerStatus> completed = ImmutableList.copyOf(Iterables.transform(allocateResponse.getCompletedContainersStatuses(), STATUS_TRANSFORM));
if (!completed.isEmpty()) {
handler.completed(completed);
}
}
Aggregations