List of usage examples for org.apache.hadoop.yarn.api.protocolrecords StartContainersRequest setStartContainerRequests
@Public @Stable public abstract void setStartContainerRequests(List<StartContainerRequest> request);
From source file:org.apache.tajo.master.YarnContainerProxy.java
License:Apache License
@Override @SuppressWarnings("unchecked") public synchronized void launch(ContainerLaunchContext commonContainerLaunchContext) { LOG.info("Launching Container with Id: " + containerID); if (this.state == ContainerState.KILLED_BEFORE_LAUNCH) { state = ContainerState.DONE;//from www.j ava 2s .c om LOG.error("Container (" + containerID + " was killed before it was launched"); return; } ContainerManagementProtocol proxy = null; try { proxy = getCMProxy(containerID, containerMgrAddress, containerToken); // Construct the actual Container ContainerLaunchContext containerLaunchContext = createContainerLaunchContext( commonContainerLaunchContext); // Now launch the actual container List<StartContainerRequest> startRequestList = new ArrayList<StartContainerRequest>(); StartContainerRequest startRequest = Records.newRecord(StartContainerRequest.class); startRequest.setContainerLaunchContext(containerLaunchContext); startRequestList.add(startRequest); StartContainersRequest startRequests = Records.newRecord(StartContainersRequest.class); startRequests.setStartContainerRequests(startRequestList); StartContainersResponse response = proxy.startContainers(startRequests); ByteBuffer portInfo = response.getAllServicesMetaData().get(PullServerAuxService.PULLSERVER_SERVICEID); if (portInfo != null) { port = PullServerAuxService.deserializeMetaData(portInfo); } LOG.info("PullServer port returned by ContainerManager for " + containerID + " : " + port); if (port < 0) { this.state = ContainerState.FAILED; throw new IllegalStateException( "Invalid shuffle port number " + port + " returned for " + containerID); } this.state = ContainerState.RUNNING; this.hostName = containerMgrAddress.split(":")[0]; context.getResourceAllocator().addContainer(containerID, this); } catch (Throwable t) { String message = "Container launch failed for " + containerID + " : " + StringUtils.stringifyException(t); this.state = ContainerState.FAILED; LOG.error(message); } finally { if (proxy != null) { yarnRPC.stopProxy(proxy, conf); } } }
From source file:org.springframework.yarn.am.container.DefaultContainerLauncher.java
License:Apache License
@Override public void launchContainer(Container container, List<String> commands) { if (log.isDebugEnabled()) { log.debug("Launching container: " + container); }/* ww w .j a v a 2s .c o m*/ ContainerLaunchContext ctx = Records.newRecord(ContainerLaunchContext.class); String stagingId = container.getId().getApplicationAttemptId().getApplicationId().toString(); getResourceLocalizer().setStagingId(stagingId); ctx.setLocalResources(getResourceLocalizer().getResources()); ctx.setCommands(commands); // Yarn doesn't tell container what is its container id // so we do it here Map<String, String> env = getEnvironment(); env.put(YarnSystemConstants.SYARN_CONTAINER_ID, ConverterUtils.toString(container.getId())); ctx.setEnvironment(env); ctx = getInterceptors().preLaunch(container, ctx); StartContainerRequest startContainerRequest = Records.newRecord(StartContainerRequest.class); startContainerRequest.setContainerLaunchContext(ctx); startContainerRequest.setContainerToken(container.getContainerToken()); StartContainersRequest startContainersRequest = Records.newRecord(StartContainersRequest.class); ArrayList<StartContainerRequest> startContainerRequestList = new ArrayList<StartContainerRequest>(); startContainerRequestList.add(startContainerRequest); startContainersRequest.setStartContainerRequests(startContainerRequestList); StartContainersResponse startContainersResponse = getCmTemplate(container) .startContainers(startContainersRequest); Map<ContainerId, SerializedException> failedRequests = startContainersResponse.getFailedRequests(); List<ContainerId> successfullyStartedContainers = startContainersResponse .getSuccessfullyStartedContainers(); // TODO: handle failed/success // notify interested parties of new launched container if (getYarnEventPublisher() != null) { getYarnEventPublisher().publishContainerLaunched(this, container); } }