本文整理汇总了Java中org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest.setContainerLaunchContext方法的典型用法代码示例。如果您正苦于以下问题:Java StartContainerRequest.setContainerLaunchContext方法的具体用法?Java StartContainerRequest.setContainerLaunchContext怎么用?Java StartContainerRequest.setContainerLaunchContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest
的用法示例。
在下文中一共展示了StartContainerRequest.setContainerLaunchContext方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest; //导入方法依赖的package包/类
@Override
public Cancellable start(YarnContainerInfo containerInfo, YarnLaunchContext launchContext) {
ContainerLaunchContext context = launchContext.getLaunchContext();
context.setUser(System.getProperty("user.name"));
Container container = containerInfo.getContainer();
context.setContainerId(container.getId());
context.setResource(container.getResource());
StartContainerRequest startRequest = Records.newRecord(StartContainerRequest.class);
startRequest.setContainerLaunchContext(context);
ContainerManager manager = connectContainerManager(container);
try {
manager.startContainer(startRequest);
return new ContainerTerminator(container, manager);
} catch (YarnRemoteException e) {
LOG.error("Error in launching process", e);
throw Throwables.propagate(e);
}
}
示例2: run
import org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest; //导入方法依赖的package包/类
/**
* Connects to CM, sets up container launch context
* for shell command and eventually dispatches the container
* start request to the CM.
*/
public void run() {
// Connect to ContainerManager
connectToCM();
// configure the launcher for the Giraph task it will host
StartContainerRequest startReq =
Records.newRecord(StartContainerRequest.class);
startReq.setContainerLaunchContext(buildContainerLaunchContext());
// request CM to start this container as spec'd in ContainerLaunchContext
try {
containerManager.startContainer(startReq);
} catch (YarnRemoteException yre) {
LOG.error("StartContainerRequest failed for containerId=" +
container.getId(), yre);
}
}
示例3: startContainer
import org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest; //导入方法依赖的package包/类
/**
* Runs a command as a process on the container. All binaries needed by the physical process are packaged in the URL
* specified by packagePath.
*/
private void startContainer(Path packagePath,
Container container,
Map<String, String> env,
final String cmd) throws IOException {
log.info("Starting container {} {} {} {}",
new Object[]{packagePath, container, env, cmd});
LocalResource packageResource = Records.newRecord(LocalResource.class);
URL packageUrl = ConverterUtils.getYarnUrlFromPath(packagePath);
FileStatus fileStatus;
fileStatus = packagePath.getFileSystem(yarnConfiguration).getFileStatus(packagePath);
packageResource.setResource(packageUrl);
log.info("Set package resource in YarnContainerRunner for {}", packageUrl);
packageResource.setSize(fileStatus.getLen());
packageResource.setTimestamp(fileStatus.getModificationTime());
packageResource.setType(LocalResourceType.ARCHIVE);
packageResource.setVisibility(LocalResourceVisibility.APPLICATION);
ByteBuffer allTokens;
// copy tokens to start the container
Credentials credentials = UserGroupInformation.getCurrentUser().getCredentials();
DataOutputBuffer dob = new DataOutputBuffer();
credentials.writeTokenStorageToStream(dob);
// now remove the AM->RM token so that containers cannot access it
Iterator iter = credentials.getAllTokens().iterator();
while (iter.hasNext()) {
TokenIdentifier token = ((org.apache.hadoop.security.token.Token) iter.next()).decodeIdentifier();
if (token != null && token.getKind().equals(AMRMTokenIdentifier.KIND_NAME)) {
iter.remove();
}
}
allTokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
Map<String, LocalResource> localResourceMap = new HashMap<>();
localResourceMap.put("__package", packageResource);
// include the resources from the universal resource configurations
LocalizerResourceMapper resourceMapper = new LocalizerResourceMapper(new LocalizerResourceConfig(config), yarnConfiguration);
localResourceMap.putAll(resourceMapper.getResourceMap());
ContainerLaunchContext context = Records.newRecord(ContainerLaunchContext.class);
context.setEnvironment(env);
context.setTokens(allTokens.duplicate());
context.setCommands(new ArrayList<String>() {{add(cmd);}});
context.setLocalResources(localResourceMap);
log.debug("Setting localResourceMap to {}", localResourceMap);
log.debug("Setting context to {}", context);
StartContainerRequest startContainerRequest = Records.newRecord(StartContainerRequest.class);
startContainerRequest.setContainerLaunchContext(context);
log.info("Making an async start request for container {}", container);
nmClientAsync.startContainerAsync(container, context);
}
示例4: launch
import org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest; //导入方法依赖的package包/类
@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;
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);
}
}
}
示例5: launch
import org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest; //导入方法依赖的package包/类
@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;
LOG.error("Container (" + containerID + " was killed before it was launched");
return;
}
ContainerManager proxy = null;
try {
proxy = getCMProxy(containerID, containerMgrAddress,
containerToken);
// Construct the actual Container
ContainerLaunchContext containerLaunchContext = createContainerLaunchContext(commonContainerLaunchContext);
// Now launch the actual container
StartContainerRequest startRequest = Records
.newRecord(StartContainerRequest.class);
startRequest.setContainerLaunchContext(containerLaunchContext);
StartContainerResponse response = proxy.startContainer(startRequest);
ByteBuffer portInfo = response
.getServiceResponse(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);
}
}
}
示例6: launch
import org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public synchronized void launch(NMCommunicatorLaunchRequestEvent event) {
LOG.info("Launching Container with Id: " + event.getContainerId());
if(this.state == ContainerState.KILLED_BEFORE_LAUNCH) {
state = ContainerState.DONE;
sendContainerLaunchFailedMsg(event.getContainerId(),
"Container was killed before it was launched");
return;
}
ContainerManagementProtocolProxyData proxy = null;
try {
proxy = getCMProxy(containerID, containerMgrAddress,
containerToken);
// Construct the actual Container
ContainerLaunchContext containerLaunchContext =
event.getContainerLaunchContext();
// Now launch the actual container
StartContainerRequest startRequest = Records
.newRecord(StartContainerRequest.class);
startRequest.setContainerToken(event.getContainerToken());
startRequest.setContainerLaunchContext(containerLaunchContext);
StartContainersResponse response =
proxy.getContainerManagementProtocol().startContainers(
StartContainersRequest.newInstance(
Collections.singletonList(startRequest)));
if (response.getFailedRequests() != null
&& !response.getFailedRequests().isEmpty()) {
throw response.getFailedRequests().get(containerID).deSerialize();
}
// after launching, send launched event to task attempt to move
// it from ASSIGNED to RUNNING state
context.getEventHandler().handle(
new AMContainerEventLaunched(containerID));
ContainerLaunchedEvent lEvt = new ContainerLaunchedEvent(
containerID, clock.getTime(), context.getApplicationAttemptId());
context.getHistoryHandler().handle(new DAGHistoryEvent(
null, lEvt));
this.state = ContainerState.RUNNING;
} catch (Throwable t) {
String message = "Container launch failed for " + containerID + " : "
+ StringUtils.stringifyException(t);
this.state = ContainerState.FAILED;
sendContainerLaunchFailedMsg(containerID, message);
} finally {
if (proxy != null) {
cmProxy.mayBeCloseProxy(proxy);
}
}
}
示例7: launch
import org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public synchronized void launch(ContainerLaunchRequest event) {
LOG.info("Launching " + event.getContainerId());
if(this.state == ContainerState.KILLED_BEFORE_LAUNCH) {
state = ContainerState.DONE;
sendContainerLaunchFailedMsg(event.getContainerId(),
"Container was killed before it was launched");
return;
}
ContainerManagementProtocolProxyData proxy = null;
try {
proxy = getCMProxy(containerID, containerMgrAddress,
containerToken);
// Construct the actual Container
ContainerLaunchContext containerLaunchContext =
event.getContainerLaunchContext();
// Now launch the actual container
StartContainerRequest startRequest = Records
.newRecord(StartContainerRequest.class);
startRequest.setContainerToken(event.getContainerToken());
startRequest.setContainerLaunchContext(containerLaunchContext);
StartContainersResponse response =
proxy.getContainerManagementProtocol().startContainers(
StartContainersRequest.newInstance(
Collections.singletonList(startRequest)));
if (response.getFailedRequests() != null
&& !response.getFailedRequests().isEmpty()) {
throw response.getFailedRequests().get(containerID).deSerialize();
}
// after launching, send launched event to task attempt to move
// it from ASSIGNED to RUNNING state
getContext().containerLaunched(containerID);
this.state = ContainerState.RUNNING;
int shufflePort = TezRuntimeUtils.INVALID_PORT;
Map<String, java.nio.ByteBuffer> servicesMetaData = response.getAllServicesMetaData();
if (servicesMetaData != null) {
String auxiliaryService = conf.get(TezConfiguration.TEZ_AM_SHUFFLE_AUXILIARY_SERVICE_ID,
TezConfiguration.TEZ_AM_SHUFFLE_AUXILIARY_SERVICE_ID_DEFAULT);
ByteBuffer portInfo = servicesMetaData.get(auxiliaryService);
if (portInfo != null) {
DataInputByteBuffer in = new DataInputByteBuffer();
in.reset(portInfo);
shufflePort = in.readInt();
} else {
LOG.warn("Shuffle port for {} is not present is the services metadata response", auxiliaryService);
}
} else {
LOG.warn("Shuffle port cannot be found since services metadata response is missing");
}
if (deletionTracker != null) {
deletionTracker.addNodeShufflePort(event.getNodeId(), shufflePort);
}
} catch (Throwable t) {
String message = "Container launch failed for " + containerID + " : "
+ ExceptionUtils.getStackTrace(t);
this.state = ContainerState.FAILED;
sendContainerLaunchFailedMsg(containerID, message);
} finally {
if (proxy != null) {
cmProxy.mayBeCloseProxy(proxy);
}
}
}