当前位置: 首页>>代码示例>>Java>>正文


Java GetContainerStatusesRequest.newInstance方法代码示例

本文整理汇总了Java中org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java GetContainerStatusesRequest.newInstance方法的具体用法?Java GetContainerStatusesRequest.newInstance怎么用?Java GetContainerStatusesRequest.newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest的用法示例。


在下文中一共展示了GetContainerStatusesRequest.newInstance方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: waitForContainerState

import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; //导入方法依赖的package包/类
public static void waitForContainerState(ContainerManagementProtocol containerManager,
      ContainerId containerID, ContainerState finalState, int timeOutMax)
      throws InterruptedException, YarnException, IOException {
List<ContainerId> list = new ArrayList<ContainerId>();
list.add(containerID);
GetContainerStatusesRequest request =
    GetContainerStatusesRequest.newInstance(list);
ContainerStatus containerStatus =
    containerManager.getContainerStatuses(request).getContainerStatuses()
      .get(0);
int timeoutSecs = 0;
  while (!containerStatus.getState().equals(finalState)
      && timeoutSecs++ < timeOutMax) {
      Thread.sleep(1000);
      LOG.info("Waiting for container to get into state " + finalState
          + ". Current state is " + containerStatus.getState());
      containerStatus = containerManager.getContainerStatuses(request).getContainerStatuses().get(0);
    }
    LOG.info("Container state is " + containerStatus.getState());
    Assert.assertEquals("ContainerState is not correct (timedout)",
        finalState, containerStatus.getState());
  }
 
开发者ID:naver,项目名称:hadoop,代码行数:23,代码来源:BaseContainerManagerTest.java

示例2: getContainerStatus

import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; //导入方法依赖的package包/类
private ContainerStatus getContainerStatus(
    Context context, final ContainerManagerImpl cm, ContainerId cid)
    throws  Exception {
  UserGroupInformation user = UserGroupInformation.createRemoteUser(
      cid.getApplicationAttemptId().toString());
  NMTokenIdentifier nmToken = new NMTokenIdentifier(
      cid.getApplicationAttemptId(), context.getNodeId(),
      user.getShortUserName(),
      context.getNMTokenSecretManager().getCurrentKey().getKeyId());
  user.addTokenIdentifier(nmToken);
  List<ContainerId> containerIds = new ArrayList<>();
  containerIds.add(cid);
  final GetContainerStatusesRequest gcsRequest =
      GetContainerStatusesRequest.newInstance(containerIds);
  return user.doAs(
      new PrivilegedExceptionAction<ContainerStatus>() {
        @Override
        public ContainerStatus run() throws Exception {
          return cm.getContainerStatuses(gcsRequest)
              .getContainerStatuses().get(0);
        }
      });
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:24,代码来源:TestContainerManagerRecovery.java

示例3: getContainerStatus

import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; //导入方法依赖的package包/类
private void
    getContainerStatus(YarnRPC rpc,
        org.apache.hadoop.yarn.api.records.Token nmToken,
        ContainerId containerId,
        ApplicationAttemptId appAttemptId, NodeId nodeId,
        boolean isExceptionExpected) throws Exception {
  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(containerId);
  GetContainerStatusesRequest request =
      GetContainerStatusesRequest.newInstance(containerIds);
  ContainerManagementProtocol proxy = null;
  try {
    proxy =
        getContainerManagementProtocolProxy(rpc, nmToken, nodeId,
            appAttemptId.toString());
    GetContainerStatusesResponse statuses = proxy.getContainerStatuses(request);
    if (statuses.getFailedRequests() != null
        && statuses.getFailedRequests().containsKey(containerId)) {
      parseAndThrowException(statuses.getFailedRequests().get(containerId)
        .deSerialize());
    }
  } finally {
    if (proxy != null) {
      rpc.stopProxy(proxy, conf);
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:TestContainerManagerSecurity.java

示例4: testContainerManagerInitialization

import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; //导入方法依赖的package包/类
@Test
public void testContainerManagerInitialization() throws IOException {

  containerManager.start();

  InetAddress localAddr = InetAddress.getLocalHost();
  String fqdn = localAddr.getCanonicalHostName();
  if (!localAddr.getHostAddress().equals(fqdn)) {
    // only check if fqdn is not same as ip
    // api returns ip in case of resolution failure
    Assert.assertEquals(fqdn, context.getNodeId().getHost());
  }

  // Just do a query for a non-existing container.
  boolean throwsException = false;
  try {
    List<ContainerId> containerIds = new ArrayList<ContainerId>();
    ContainerId id =createContainerId(0);
    containerIds.add(id);
    GetContainerStatusesRequest request =
        GetContainerStatusesRequest.newInstance(containerIds);
    GetContainerStatusesResponse response =
        containerManager.getContainerStatuses(request);
    if(response.getFailedRequests().containsKey(id)){
      throw response.getFailedRequests().get(id).deSerialize();
    }
  } catch (Throwable e) {
    throwsException = true;
  }
  Assert.assertTrue(throwsException);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:32,代码来源:TestContainerManager.java

示例5: rebootNodeStatusUpdaterAndRegisterWithRM

import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; //导入方法依赖的package包/类
@Override
protected void rebootNodeStatusUpdaterAndRegisterWithRM() {
  try {
    try {
      // Check status before registerWithRM
      List<ContainerId> containerIds = new ArrayList<>();
      ContainerId cId = TestContainerManager.createContainerId(0);
      containerIds.add(cId);
      GetContainerStatusesRequest gcsRequest =
          GetContainerStatusesRequest.newInstance(containerIds);
      ContainerStatus containerStatus = getContainerManager()
          .getContainerStatuses(gcsRequest).getContainerStatuses().get(0);
      assertEquals(Resource.newInstance(1024, 1),
          containerStatus.getCapability());
      // Call the actual rebootNodeStatusUpdaterAndRegisterWithRM().
      // This function should be synchronized with
      // increaseContainersResource().
      super.rebootNodeStatusUpdaterAndRegisterWithRM();
      // Check status after registerWithRM
      containerStatus = getContainerManager()
          .getContainerStatuses(gcsRequest).getContainerStatuses().get(0);
      assertEquals(Resource.newInstance(4096, 2),
          containerStatus.getCapability());
    } catch (AssertionError ae) {
      ae.printStackTrace();
      assertionFailedInThread.set(true);
    }   finally {
      syncBarrier.await();
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:34,代码来源:TestNodeManagerResync.java

示例6: rebootNodeStatusUpdaterAndRegisterWithRM

import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; //导入方法依赖的package包/类
@Override
protected void rebootNodeStatusUpdaterAndRegisterWithRM() {
  try {
    try {
      // Check status before registerWithRM
      List<ContainerId> containerIds = new ArrayList<>();
      ContainerId cId = TestContainerManager.createContainerId(0);
      containerIds.add(cId);
      GetContainerStatusesRequest gcsRequest =
          GetContainerStatusesRequest.newInstance(containerIds);
      ContainerStatus containerStatus = getContainerManager()
          .getContainerStatuses(gcsRequest).getContainerStatuses().get(0);
      assertEquals(Resource.newInstance(1024, 1),
          containerStatus.getCapability());
      updateBarrier.await();
      // Call the actual rebootNodeStatusUpdaterAndRegisterWithRM().
      // This function should be synchronized with
      // increaseContainersResource().
      updateBarrier.await();
      super.rebootNodeStatusUpdaterAndRegisterWithRM();
      // Check status after registerWithRM
      containerStatus = getContainerManager()
          .getContainerStatuses(gcsRequest).getContainerStatuses().get(0);
      assertEquals(Resource.newInstance(4096, 2),
          containerStatus.getCapability());
    } catch (AssertionError ae) {
      ae.printStackTrace();
      assertionFailedInThread.set(true);
    }   finally {
      syncBarrier.await();
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:36,代码来源:TestNodeManagerResync.java

示例7: test

import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; //导入方法依赖的package包/类
private void test(String rpcClass) throws Exception {
  Configuration conf = new Configuration();
  conf.set(YarnConfiguration.IPC_RPC_IMPL, rpcClass);
  YarnRPC rpc = YarnRPC.create(conf);
  String bindAddr = "localhost:0";
  InetSocketAddress addr = NetUtils.createSocketAddr(bindAddr);
  Server server = rpc.getServer(ContainerManagementProtocol.class, 
          new DummyContainerManager(), addr, conf, null, 1);
  server.start();
  RPC.setProtocolEngine(conf, ContainerManagementProtocolPB.class, ProtobufRpcEngine.class);
  ContainerManagementProtocol proxy = (ContainerManagementProtocol) 
      rpc.getProxy(ContainerManagementProtocol.class, 
          NetUtils.getConnectAddress(server), conf);
  ContainerLaunchContext containerLaunchContext = 
      recordFactory.newRecordInstance(ContainerLaunchContext.class);

  ApplicationId applicationId = ApplicationId.newInstance(0, 0);
  ApplicationAttemptId applicationAttemptId =
      ApplicationAttemptId.newInstance(applicationId, 0);
  ContainerId containerId =
      ContainerId.newContainerId(applicationAttemptId, 100);
  NodeId nodeId = NodeId.newInstance("localhost", 1234);
  Resource resource = Resource.newInstance(1234, 2);
  ContainerTokenIdentifier containerTokenIdentifier =
      new ContainerTokenIdentifier(containerId, "localhost", "user",
        resource, System.currentTimeMillis() + 10000, 42, 42,
        Priority.newInstance(0), 0);
  Token containerToken = newContainerToken(nodeId, "password".getBytes(),
        containerTokenIdentifier);

  StartContainerRequest scRequest =
      StartContainerRequest.newInstance(containerLaunchContext,
        containerToken);
  List<StartContainerRequest> list = new ArrayList<StartContainerRequest>();
  list.add(scRequest);
  StartContainersRequest allRequests =
      StartContainersRequest.newInstance(list);
  proxy.startContainers(allRequests);

  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(containerId);
  GetContainerStatusesRequest gcsRequest =
      GetContainerStatusesRequest.newInstance(containerIds);
  GetContainerStatusesResponse response =
      proxy.getContainerStatuses(gcsRequest);
  List<ContainerStatus> statuses = response.getContainerStatuses();

  //test remote exception
  boolean exception = false;
  try {
    StopContainersRequest stopRequest =
        recordFactory.newRecordInstance(StopContainersRequest.class);
    stopRequest.setContainerIds(containerIds);
    proxy.stopContainers(stopRequest);
    } catch (YarnException e) {
    exception = true;
    Assert.assertTrue(e.getMessage().contains(EXCEPTION_MSG));
    Assert.assertTrue(e.getMessage().contains(EXCEPTION_CAUSE));
    System.out.println("Test Exception is " + e.getMessage());
  } catch (Exception ex) {
    ex.printStackTrace();
  }
  Assert.assertTrue(exception);
  
  server.stop();
  Assert.assertNotNull(statuses.get(0));
  Assert.assertEquals(ContainerState.RUNNING, statuses.get(0).getState());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:69,代码来源:TestRPC.java

示例8: testContainerLaunchAndExit

import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; //导入方法依赖的package包/类
private void testContainerLaunchAndExit(int exitCode) throws IOException,
    InterruptedException, YarnException {

 File scriptFile = Shell.appendScriptExtension(tmpDir, "scriptFile");
 PrintWriter fileWriter = new PrintWriter(scriptFile);
 File processStartFile =
	  new File(tmpDir, "start_file.txt").getAbsoluteFile();

 // ////// Construct the Container-id
 ContainerId cId = createContainerId(0);

 if (Shell.WINDOWS) {
   fileWriter.println("@echo Hello World!> " + processStartFile);
   fileWriter.println("@echo " + cId + ">> " + processStartFile);
   if (exitCode != 0) {
     fileWriter.println("@exit " + exitCode);
   }
 } else {
   fileWriter.write("\numask 0"); // So that start file is readable by the test
   fileWriter.write("\necho Hello World! > " + processStartFile);
   fileWriter.write("\necho $$ >> " + processStartFile); 
   // Have script throw an exit code at the end
   if (exitCode != 0) {
     fileWriter.write("\nexit "+exitCode);
   }
 }
 
 fileWriter.close();

 ContainerLaunchContext containerLaunchContext = 
	  recordFactory.newRecordInstance(ContainerLaunchContext.class);

 URL resource_alpha =
	  ConverterUtils.getYarnUrlFromPath(localFS
			  .makeQualified(new Path(scriptFile.getAbsolutePath())));
 LocalResource rsrc_alpha =
	  recordFactory.newRecordInstance(LocalResource.class);
 rsrc_alpha.setResource(resource_alpha);
 rsrc_alpha.setSize(-1);
 rsrc_alpha.setVisibility(LocalResourceVisibility.APPLICATION);
 rsrc_alpha.setType(LocalResourceType.FILE);
 rsrc_alpha.setTimestamp(scriptFile.lastModified());
 String destinationFile = "dest_file";
 Map<String, LocalResource> localResources = 
	  new HashMap<String, LocalResource>();
 localResources.put(destinationFile, rsrc_alpha);
 containerLaunchContext.setLocalResources(localResources);
 List<String> commands = Arrays.asList(Shell.getRunScriptCommand(scriptFile));
 containerLaunchContext.setCommands(commands);

  StartContainerRequest scRequest =
      StartContainerRequest.newInstance(
        containerLaunchContext,
        createContainerToken(cId, DUMMY_RM_IDENTIFIER, context.getNodeId(),
          user, context.getContainerTokenSecretManager()));
  List<StartContainerRequest> list = new ArrayList<StartContainerRequest>();
  list.add(scRequest);
  StartContainersRequest allRequests =
      StartContainersRequest.newInstance(list);
  containerManager.startContainers(allRequests);

 BaseContainerManagerTest.waitForContainerState(containerManager, cId,
	  ContainerState.COMPLETE);

  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(cId);
  GetContainerStatusesRequest gcsRequest =
      GetContainerStatusesRequest.newInstance(containerIds);
 ContainerStatus containerStatus = 
	  containerManager.getContainerStatuses(gcsRequest).getContainerStatuses().get(0);

 // Verify exit status matches exit state of script
 Assert.assertEquals(exitCode,
	  containerStatus.getExitStatus());	    
}
 
开发者ID:naver,项目名称:hadoop,代码行数:76,代码来源:TestContainerManager.java

示例9: test

import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; //导入方法依赖的package包/类
private void test(String rpcClass) throws Exception {
  Configuration conf = new Configuration();
  conf.set(YarnConfiguration.IPC_RPC_IMPL, rpcClass);
  YarnRPC rpc = YarnRPC.create(conf);
  String bindAddr = "localhost:0";
  InetSocketAddress addr = NetUtils.createSocketAddr(bindAddr);
  Server server = rpc.getServer(ContainerManagementProtocol.class, 
          new DummyContainerManager(), addr, conf, null, 1);
  server.start();
  RPC.setProtocolEngine(conf, ContainerManagementProtocolPB.class, ProtobufRpcEngine.class);
  ContainerManagementProtocol proxy = (ContainerManagementProtocol) 
      rpc.getProxy(ContainerManagementProtocol.class, 
          NetUtils.getConnectAddress(server), conf);
  ContainerLaunchContext containerLaunchContext = 
      recordFactory.newRecordInstance(ContainerLaunchContext.class);

  ApplicationId applicationId = ApplicationId.newInstance(0, 0);
  ApplicationAttemptId applicationAttemptId =
      ApplicationAttemptId.newInstance(applicationId, 0);
  ContainerId containerId =
      ContainerId.newInstance(applicationAttemptId, 100);
  NodeId nodeId = NodeId.newInstance("localhost", 1234);
  Resource resource = Resource.newInstance(1234, 2);
  ContainerTokenIdentifier containerTokenIdentifier =
      new ContainerTokenIdentifier(containerId, "localhost", "user",
        resource, System.currentTimeMillis() + 10000, 42, 42);
  Token containerToken = newContainerToken(nodeId, "password".getBytes(),
        containerTokenIdentifier);

  StartContainerRequest scRequest =
      StartContainerRequest.newInstance(containerLaunchContext,
        containerToken);
  List<StartContainerRequest> list = new ArrayList<StartContainerRequest>();
  list.add(scRequest);
  StartContainersRequest allRequests =
      StartContainersRequest.newInstance(list);
  proxy.startContainers(allRequests);

  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(containerId);
  GetContainerStatusesRequest gcsRequest =
      GetContainerStatusesRequest.newInstance(containerIds);
  GetContainerStatusesResponse response =
      proxy.getContainerStatuses(gcsRequest);
  List<ContainerStatus> statuses = response.getContainerStatuses();

  //test remote exception
  boolean exception = false;
  try {
    StopContainersRequest stopRequest =
        recordFactory.newRecordInstance(StopContainersRequest.class);
    stopRequest.setContainerIds(containerIds);
    proxy.stopContainers(stopRequest);
    } catch (YarnException e) {
    exception = true;
    Assert.assertTrue(e.getMessage().contains(EXCEPTION_MSG));
    Assert.assertTrue(e.getMessage().contains(EXCEPTION_CAUSE));
    System.out.println("Test Exception is " + e.getMessage());
  } catch (Exception ex) {
    ex.printStackTrace();
  }
  Assert.assertTrue(exception);
  
  server.stop();
  Assert.assertNotNull(statuses.get(0));
  Assert.assertEquals(ContainerState.RUNNING, statuses.get(0).getState());
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:68,代码来源:TestRPC.java

示例10: test

import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; //导入方法依赖的package包/类
private void test(String rpcClass) throws Exception {
  Configuration conf = new Configuration();
  conf.set(YarnConfiguration.IPC_RPC_IMPL, rpcClass);
  YarnRPC rpc = YarnRPC.create(conf);
  String bindAddr = "localhost:0";
  InetSocketAddress addr = NetUtils.createSocketAddr(bindAddr);
  Server server = rpc.getServer(ContainerManagementProtocol.class, 
          new DummyContainerManager(), addr, conf, null, 1);
  server.start();
  RPC.setProtocolEngine(conf, ContainerManagementProtocolPB.class, ProtobufRpcEngine.class);
  ContainerManagementProtocol proxy = (ContainerManagementProtocol) 
      rpc.getProxy(ContainerManagementProtocol.class, 
          NetUtils.getConnectAddress(server), conf);
  ContainerLaunchContext containerLaunchContext = 
      recordFactory.newRecordInstance(ContainerLaunchContext.class);

  ApplicationId applicationId = ApplicationId.newInstance(0, 0);
  ApplicationAttemptId applicationAttemptId =
      ApplicationAttemptId.newInstance(applicationId, 0);
  ContainerId containerId =
      ContainerId.newContainerId(applicationAttemptId, 100);
  NodeId nodeId = NodeId.newInstance("localhost", 1234);
  Resource resource = Resource.newInstance(1234, 2);
  ContainerTokenIdentifier containerTokenIdentifier =
      new ContainerTokenIdentifier(containerId, "localhost", "user",
        resource, System.currentTimeMillis() + 10000, 42, 42,
        Priority.newInstance(0), 0, "userFolder");
  Token containerToken = newContainerToken(nodeId, "password".getBytes(),
        containerTokenIdentifier);

  StartContainerRequest scRequest =
      StartContainerRequest.newInstance(containerLaunchContext,
        containerToken);
  List<StartContainerRequest> list = new ArrayList<StartContainerRequest>();
  list.add(scRequest);
  StartContainersRequest allRequests =
      StartContainersRequest.newInstance(list);
  proxy.startContainers(allRequests);

  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(containerId);
  GetContainerStatusesRequest gcsRequest =
      GetContainerStatusesRequest.newInstance(containerIds);
  GetContainerStatusesResponse response =
      proxy.getContainerStatuses(gcsRequest);
  List<ContainerStatus> statuses = response.getContainerStatuses();

  //test remote exception
  boolean exception = false;
  try {
    StopContainersRequest stopRequest =
        recordFactory.newRecordInstance(StopContainersRequest.class);
    stopRequest.setContainerIds(containerIds);
    proxy.stopContainers(stopRequest);
    } catch (YarnException e) {
    exception = true;
    Assert.assertTrue(e.getMessage().contains(EXCEPTION_MSG));
    Assert.assertTrue(e.getMessage().contains(EXCEPTION_CAUSE));
    System.out.println("Test Exception is " + e.getMessage());
  } catch (Exception ex) {
    ex.printStackTrace();
  }
  Assert.assertTrue(exception);
  
  server.stop();
  Assert.assertNotNull(statuses.get(0));
  Assert.assertEquals(ContainerState.RUNNING, statuses.get(0).getState());
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:69,代码来源:TestRPC.java

示例11: testContainerLaunchAndExit

import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; //导入方法依赖的package包/类
private void testContainerLaunchAndExit(int exitCode) throws IOException,
    InterruptedException, YarnException {

 File scriptFile = Shell.appendScriptExtension(tmpDir, "scriptFile");
 PrintWriter fileWriter = new PrintWriter(scriptFile);
 File processStartFile =
	  new File(tmpDir, "start_file.txt").getAbsoluteFile();

 // ////// Construct the Container-id
 ContainerId cId = createContainerId(0);

 if (Shell.WINDOWS) {
   fileWriter.println("@echo Hello World!> " + processStartFile);
   fileWriter.println("@echo " + cId + ">> " + processStartFile);
   if (exitCode != 0) {
     fileWriter.println("@exit " + exitCode);
   }
 } else {
   fileWriter.write("\numask 0"); // So that start file is readable by the test
   fileWriter.write("\necho Hello World! > " + processStartFile);
   fileWriter.write("\necho $$ >> " + processStartFile); 
   // Have script throw an exit code at the end
   if (exitCode != 0) {
     fileWriter.write("\nexit "+exitCode);
   }
 }
 
 fileWriter.close();

 ContainerLaunchContext containerLaunchContext = 
	  recordFactory.newRecordInstance(ContainerLaunchContext.class);

 URL resource_alpha =
	  URL.fromPath(localFS
			  .makeQualified(new Path(scriptFile.getAbsolutePath())));
 LocalResource rsrc_alpha =
	  recordFactory.newRecordInstance(LocalResource.class);
 rsrc_alpha.setResource(resource_alpha);
 rsrc_alpha.setSize(-1);
 rsrc_alpha.setVisibility(LocalResourceVisibility.APPLICATION);
 rsrc_alpha.setType(LocalResourceType.FILE);
 rsrc_alpha.setTimestamp(scriptFile.lastModified());
 String destinationFile = "dest_file";
 Map<String, LocalResource> localResources = 
	  new HashMap<String, LocalResource>();
 localResources.put(destinationFile, rsrc_alpha);
 containerLaunchContext.setLocalResources(localResources);
 List<String> commands = Arrays.asList(Shell.getRunScriptCommand(scriptFile));
 containerLaunchContext.setCommands(commands);

  StartContainerRequest scRequest =
      StartContainerRequest.newInstance(
        containerLaunchContext,
        createContainerToken(cId, DUMMY_RM_IDENTIFIER, context.getNodeId(),
          user, context.getContainerTokenSecretManager(), userFolder));
  List<StartContainerRequest> list = new ArrayList<StartContainerRequest>();
  list.add(scRequest);
  StartContainersRequest allRequests =
      StartContainersRequest.newInstance(list);
  containerManager.startContainers(allRequests);

 BaseContainerManagerTest.waitForContainerState(containerManager, cId,
	  ContainerState.COMPLETE);

  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(cId);
  GetContainerStatusesRequest gcsRequest =
      GetContainerStatusesRequest.newInstance(containerIds);
 ContainerStatus containerStatus = 
	  containerManager.getContainerStatuses(gcsRequest).getContainerStatuses().get(0);

 // Verify exit status matches exit state of script
 Assert.assertEquals(exitCode,
	  containerStatus.getExitStatus());	    
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:76,代码来源:TestContainerManager.java

示例12: testUnauthorizedRequests

import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; //导入方法依赖的package包/类
@Test
public void testUnauthorizedRequests() throws IOException, YarnException {
  containerManager.start();

  // Create a containerId that belongs to an unauthorized appId
  ContainerId cId = createContainerId(0, 1);

  // startContainers()
  ContainerLaunchContext containerLaunchContext =
      recordFactory.newRecordInstance(ContainerLaunchContext.class);
  StartContainerRequest scRequest =
      StartContainerRequest.newInstance(containerLaunchContext,
          createContainerToken(cId, DUMMY_RM_IDENTIFIER, context.getNodeId(),
              user, context.getContainerTokenSecretManager(), userFolder));
  List<StartContainerRequest> list = new ArrayList<>();
  list.add(scRequest);
  StartContainersRequest allRequests =
      StartContainersRequest.newInstance(list);
  StartContainersResponse startResponse =
      containerManager.startContainers(allRequests);

  Assert.assertFalse("Should not be authorized to start container",
      startResponse.getSuccessfullyStartedContainers().contains(cId));
  Assert.assertTrue("Start container request should fail",
      startResponse.getFailedRequests().containsKey(cId));

  // Insert the containerId into context, make it as if it is running
  ContainerTokenIdentifier containerTokenIdentifier =
      BuilderUtils.newContainerTokenIdentifier(scRequest.getContainerToken());
  Container container = new ContainerImpl(conf, null, containerLaunchContext,
      null, metrics, containerTokenIdentifier, context);
  context.getContainers().put(cId, container);

  // stopContainers()
  List<ContainerId> containerIds = new ArrayList<>();
  containerIds.add(cId);
  StopContainersRequest stopRequest =
      StopContainersRequest.newInstance(containerIds);
  StopContainersResponse stopResponse =
      containerManager.stopContainers(stopRequest);

  Assert.assertFalse("Should not be authorized to stop container",
      stopResponse.getSuccessfullyStoppedContainers().contains(cId));
  Assert.assertTrue("Stop container request should fail",
      stopResponse.getFailedRequests().containsKey(cId));

  // getContainerStatuses()
  containerIds = new ArrayList<>();
  containerIds.add(cId);
  GetContainerStatusesRequest request =
      GetContainerStatusesRequest.newInstance(containerIds);
  GetContainerStatusesResponse response =
      containerManager.getContainerStatuses(request);

  Assert.assertEquals("Should not be authorized to get container status",
      response.getContainerStatuses().size(), 0);
  Assert.assertTrue("Get status request should fail",
      response.getFailedRequests().containsKey(cId));
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:60,代码来源:TestContainerManager.java


注:本文中的org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest.newInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。