Java Code Examples for org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest

The following examples show how to use org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop   Source File: TestContainerManagerSecurity.java    License: Apache License 2.0 6 votes vote down vote up
private void stopContainer(YarnRPC rpc, Token nmToken,
    List<ContainerId> containerId, ApplicationAttemptId appAttemptId,
    NodeId nodeId) throws Exception {
  StopContainersRequest request =
      StopContainersRequest.newInstance(containerId);
  ContainerManagementProtocol proxy = null;
  try {
    proxy =
        getContainerManagementProtocolProxy(rpc, nmToken, nodeId,
            appAttemptId.toString());
    StopContainersResponse response = proxy.stopContainers(request);
    if (response.getFailedRequests() != null &&
        response.getFailedRequests().containsKey(containerId)) {
      parseAndThrowException(response.getFailedRequests().get(containerId)
          .deSerialize());
    }
  } catch (Exception e) {
    if (proxy != null) {
      rpc.stopProxy(proxy, conf);
    }
  }
}
 
Example 2
Source Project: hadoop   Source File: ContainerManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Stop a list of containers running on this NodeManager.
 */
@Override
public StopContainersResponse stopContainers(StopContainersRequest requests)
    throws YarnException, IOException {

  List<ContainerId> succeededRequests = new ArrayList<ContainerId>();
  Map<ContainerId, SerializedException> failedRequests =
      new HashMap<ContainerId, SerializedException>();
  UserGroupInformation remoteUgi = getRemoteUgi();
  NMTokenIdentifier identifier = selectNMTokenIdentifier(remoteUgi);
  for (ContainerId id : requests.getContainerIds()) {
    try {
      stopContainerInternal(identifier, id);
      succeededRequests.add(id);
    } catch (YarnException e) {
      failedRequests.put(id, SerializedException.newInstance(e));
    }
  }
  return StopContainersResponse
    .newInstance(succeededRequests, failedRequests);
}
 
Example 3
Source Project: hadoop   Source File: Application.java    License: Apache License 2.0 6 votes vote down vote up
public synchronized void finishTask(Task task) throws IOException,
    YarnException {
  Set<Task> tasks = this.tasks.get(task.getPriority());
  if (!tasks.remove(task)) {
    throw new IllegalStateException(
        "Finishing unknown task " + task.getTaskId() + 
        " from application " + applicationId);
  }
  
  NodeManager nodeManager = task.getNodeManager();
  ContainerId containerId = task.getContainerId();
  task.stop();
  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(containerId);
  StopContainersRequest stopRequest =
      StopContainersRequest.newInstance(containerIds);
  nodeManager.stopContainers(stopRequest);
  
  Resources.subtractFrom(used, requestSpec.get(task.getPriority()));
  
  LOG.info("Finished task " + task.getTaskId() + 
      " of application " + applicationId + 
      " on node " + nodeManager.getHostName() + 
      ", currently using " + used + " resources");
}
 
Example 4
Source Project: hadoop   Source File: NMClientImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void stopContainerInternal(ContainerId containerId, NodeId nodeId)
    throws IOException, YarnException {
  ContainerManagementProtocolProxyData proxy = null;
  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(containerId);
  try {
    proxy = cmProxy.getProxy(nodeId.toString(), containerId);
    StopContainersResponse response =
        proxy.getContainerManagementProtocol().stopContainers(
          StopContainersRequest.newInstance(containerIds));
    if (response.getFailedRequests() != null
        && response.getFailedRequests().containsKey(containerId)) {
      Throwable t = response.getFailedRequests().get(containerId)
        .deSerialize();
      parseAndThrowException(t);
    }
  } finally {
    if (proxy != null) {
      cmProxy.mayBeCloseProxy(proxy);
    }
  }
}
 
Example 5
Source Project: big-c   Source File: TestContainerManagerSecurity.java    License: Apache License 2.0 6 votes vote down vote up
private void stopContainer(YarnRPC rpc, Token nmToken,
    List<ContainerId> containerId, ApplicationAttemptId appAttemptId,
    NodeId nodeId) throws Exception {
  StopContainersRequest request =
      StopContainersRequest.newInstance(containerId);
  ContainerManagementProtocol proxy = null;
  try {
    proxy =
        getContainerManagementProtocolProxy(rpc, nmToken, nodeId,
            appAttemptId.toString());
    StopContainersResponse response = proxy.stopContainers(request);
    if (response.getFailedRequests() != null &&
        response.getFailedRequests().containsKey(containerId)) {
      parseAndThrowException(response.getFailedRequests().get(containerId)
          .deSerialize());
    }
  } catch (Exception e) {
    if (proxy != null) {
      rpc.stopProxy(proxy, conf);
    }
  }
}
 
Example 6
Source Project: big-c   Source File: ContainerManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Stop a list of containers running on this NodeManager.
 */
@Override
public StopContainersResponse stopContainers(StopContainersRequest requests)
    throws YarnException, IOException {

  List<ContainerId> succeededRequests = new ArrayList<ContainerId>();
  Map<ContainerId, SerializedException> failedRequests =
      new HashMap<ContainerId, SerializedException>();
  UserGroupInformation remoteUgi = getRemoteUgi();
  NMTokenIdentifier identifier = selectNMTokenIdentifier(remoteUgi);
  for (ContainerId id : requests.getContainerIds()) {
    try {
      stopContainerInternal(identifier, id);
      succeededRequests.add(id);
    } catch (YarnException e) {
      failedRequests.put(id, SerializedException.newInstance(e));
    }
  }
  return StopContainersResponse
    .newInstance(succeededRequests, failedRequests);
}
 
Example 7
Source Project: big-c   Source File: Application.java    License: Apache License 2.0 6 votes vote down vote up
public synchronized void finishTask(Task task) throws IOException,
    YarnException {
  Set<Task> tasks = this.tasks.get(task.getPriority());
  if (!tasks.remove(task)) {
    throw new IllegalStateException(
        "Finishing unknown task " + task.getTaskId() + 
        " from application " + applicationId);
  }
  
  NodeManager nodeManager = task.getNodeManager();
  ContainerId containerId = task.getContainerId();
  task.stop();
  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(containerId);
  StopContainersRequest stopRequest =
      StopContainersRequest.newInstance(containerIds);
  nodeManager.stopContainers(stopRequest);
  
  Resources.subtractFrom(used, requestSpec.get(task.getPriority()));
  
  LOG.info("Finished task " + task.getTaskId() + 
      " of application " + applicationId + 
      " on node " + nodeManager.getHostName() + 
      ", currently using " + used + " resources");
}
 
Example 8
Source Project: big-c   Source File: NMClientImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void stopContainerInternal(ContainerId containerId, NodeId nodeId)
    throws IOException, YarnException {
  ContainerManagementProtocolProxyData proxy = null;
  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(containerId);
  try {
    proxy = cmProxy.getProxy(nodeId.toString(), containerId);
    StopContainersResponse response =
        proxy.getContainerManagementProtocol().stopContainers(
          StopContainersRequest.newInstance(containerIds));
    if (response.getFailedRequests() != null
        && response.getFailedRequests().containsKey(containerId)) {
      Throwable t = response.getFailedRequests().get(containerId)
        .deSerialize();
      parseAndThrowException(t);
    }
  } finally {
    if (proxy != null) {
      cmProxy.mayBeCloseProxy(proxy);
    }
  }
}
 
Example 9
@Override
public StopContainersResponse stopContainers(StopContainersRequest requests)
    throws YarnException, IOException {
  StopContainersRequestProto requestProto =
      ((StopContainersRequestPBImpl) requests).getProto();
  try {
    return new StopContainersResponsePBImpl(proxy.stopContainers(null,
      requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 10
Source Project: hadoop   Source File: TestRPC.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StopContainersResponse stopContainers(StopContainersRequest request) 
throws YarnException {
  Exception e = new Exception(EXCEPTION_MSG, 
      new Exception(EXCEPTION_CAUSE));
  throw new YarnException(e);
}
 
Example 11
Source Project: hadoop   Source File: TestContainerLaunchRPC.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StopContainersResponse
    stopContainers(StopContainersRequest requests) throws YarnException,
        IOException {
  Exception e = new Exception("Dummy function", new Exception(
      "Dummy function cause"));
  throw new YarnException(e);
}
 
Example 12
Source Project: hadoop   Source File: AMLauncher.java    License: Apache License 2.0 5 votes vote down vote up
private void cleanup() throws IOException, YarnException {
  connect();
  ContainerId containerId = masterContainer.getId();
  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(containerId);
  StopContainersRequest stopRequest =
      StopContainersRequest.newInstance(containerIds);
  StopContainersResponse response =
      containerMgrProxy.stopContainers(stopRequest);
  if (response.getFailedRequests() != null
      && response.getFailedRequests().containsKey(containerId)) {
    Throwable t = response.getFailedRequests().get(containerId).deSerialize();
    parseAndThrowException(t);
  }
}
 
Example 13
Source Project: hadoop   Source File: TestApplicationMasterLauncher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StopContainersResponse stopContainers(StopContainersRequest request)
    throws YarnException {
  LOG.info("Container cleaned up by MyContainerManager");
  cleanedup = true;
  return null;
}
 
Example 14
Source Project: hadoop   Source File: TestContainerLauncher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StopContainersResponse stopContainers(StopContainersRequest request)
    throws IOException {
  Exception e = new Exception("Dummy function", new Exception(
      "Dummy function cause"));
  throw new IOException(e);
}
 
Example 15
@Override
public StopContainersResponse stopContainers(StopContainersRequest requests)
    throws YarnException, IOException {
  StopContainersRequestProto requestProto =
      ((StopContainersRequestPBImpl) requests).getProto();
  try {
    return new StopContainersResponsePBImpl(proxy.stopContainers(null,
      requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 16
Source Project: big-c   Source File: TestRPC.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StopContainersResponse stopContainers(StopContainersRequest request) 
throws YarnException {
  Exception e = new Exception(EXCEPTION_MSG, 
      new Exception(EXCEPTION_CAUSE));
  throw new YarnException(e);
}
 
Example 17
Source Project: big-c   Source File: TestContainerLaunchRPC.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StopContainersResponse
    stopContainers(StopContainersRequest requests) throws YarnException,
        IOException {
  Exception e = new Exception("Dummy function", new Exception(
      "Dummy function cause"));
  throw new YarnException(e);
}
 
Example 18
Source Project: big-c   Source File: AMLauncher.java    License: Apache License 2.0 5 votes vote down vote up
private void cleanup() throws IOException, YarnException {
  connect();
  ContainerId containerId = masterContainer.getId();
  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(containerId);
  StopContainersRequest stopRequest =
      StopContainersRequest.newInstance(containerIds);
  StopContainersResponse response =
      containerMgrProxy.stopContainers(stopRequest);
  if (response.getFailedRequests() != null
      && response.getFailedRequests().containsKey(containerId)) {
    Throwable t = response.getFailedRequests().get(containerId).deSerialize();
    parseAndThrowException(t);
  }
}
 
Example 19
Source Project: big-c   Source File: TestApplicationMasterLauncher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StopContainersResponse stopContainers(StopContainersRequest request)
    throws YarnException {
  LOG.info("Container cleaned up by MyContainerManager");
  cleanedup = true;
  return null;
}
 
Example 20
Source Project: big-c   Source File: TestContainerLauncher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StopContainersResponse stopContainers(StopContainersRequest request)
    throws IOException {
  Exception e = new Exception("Dummy function", new Exception(
      "Dummy function cause"));
  throw new IOException(e);
}
 
Example 21
Source Project: hadoop   Source File: TestRPC.java    License: Apache License 2.0 4 votes vote down vote up
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());
}
 
Example 22
Source Project: hadoop   Source File: TestNMProxy.java    License: Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testNMProxyRetry() throws Exception {
  containerManager.start();
  containerManager.setBlockNewContainerRequests(false);
  StartContainersRequest allRequests =
      Records.newRecord(StartContainersRequest.class);
  ApplicationId appId = ApplicationId.newInstance(1, 1);
  ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 1);

  org.apache.hadoop.yarn.api.records.Token nmToken =
      context.getNMTokenSecretManager().createNMToken(attemptId,
        context.getNodeId(), user);
  final InetSocketAddress address =
      conf.getSocketAddr(YarnConfiguration.NM_BIND_HOST,
        YarnConfiguration.NM_ADDRESS, YarnConfiguration.DEFAULT_NM_ADDRESS,
        YarnConfiguration.DEFAULT_NM_PORT);
  Token<NMTokenIdentifier> token =
      ConverterUtils.convertFromYarn(nmToken,
        SecurityUtil.buildTokenService(address));
  UserGroupInformation ugi = UserGroupInformation.createRemoteUser(user);
  ugi.addToken(token);

  ContainerManagementProtocol proxy =
      NMProxy.createNMProxy(conf, ContainerManagementProtocol.class, ugi,
        YarnRPC.create(conf), address);

  retryCount = 0;
  shouldThrowNMNotYetReadyException = false;
  proxy.startContainers(allRequests);
  Assert.assertEquals(5, retryCount);

  retryCount = 0;
  shouldThrowNMNotYetReadyException = false;
  proxy.stopContainers(Records.newRecord(StopContainersRequest.class));
  Assert.assertEquals(5, retryCount);

  retryCount = 0;
  shouldThrowNMNotYetReadyException = false;
  proxy.getContainerStatuses(Records
    .newRecord(GetContainerStatusesRequest.class));
  Assert.assertEquals(5, retryCount);

  retryCount = 0;
  shouldThrowNMNotYetReadyException = true;
  proxy.startContainers(allRequests);
  Assert.assertEquals(5, retryCount);
}
 
Example 23
Source Project: hadoop   Source File: TestAMAuthorization.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public StopContainersResponse stopContainers(StopContainersRequest request)
    throws YarnException {
  return StopContainersResponse.newInstance(null, null);
}
 
Example 24
Source Project: hadoop   Source File: NodeManager.java    License: Apache License 2.0 4 votes vote down vote up
@Override
synchronized public StopContainersResponse stopContainers(StopContainersRequest request) 
throws YarnException {
  for (ContainerId containerID : request.getContainerIds()) {
    String applicationId =
        String.valueOf(containerID.getApplicationAttemptId()
          .getApplicationId().getId());
    // Mark the container as COMPLETE
    List<Container> applicationContainers = containers.get(containerID.getApplicationAttemptId()
            .getApplicationId());
    for (Container c : applicationContainers) {
      if (c.getId().compareTo(containerID) == 0) {
        ContainerStatus containerStatus = containerStatusMap.get(c);
        containerStatus.setState(ContainerState.COMPLETE);
        containerStatusMap.put(c, containerStatus);
      }
    }

    // Send a heartbeat
    try {
      heartbeat();
    } catch (IOException ioe) {
      throw RPCUtil.getRemoteException(ioe);
    }

    // Remove container and update status
    int ctr = 0;
    Container container = null;
    for (Iterator<Container> i = applicationContainers.iterator(); i
      .hasNext();) {
      container = i.next();
      if (container.getId().compareTo(containerID) == 0) {
        i.remove();
        ++ctr;
      }
    }

    if (ctr != 1) {
      throw new IllegalStateException("Container " + containerID
          + " stopped " + ctr + " times!");
    }

    Resources.addTo(available, container.getResource());
    Resources.subtractFrom(used, container.getResource());

    if (LOG.isDebugEnabled()) {
      LOG.debug("stopContainer:" + " node=" + containerManagerAddress
          + " application=" + applicationId + " container=" + containerID
          + " available=" + available + " used=" + used);
    }
  }
  return StopContainersResponse.newInstance(null,null);
}
 
Example 25
Source Project: hadoop   Source File: ContainerLauncherImpl.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public synchronized void kill() {

  if(this.state == ContainerState.PREP) {
    this.state = ContainerState.KILLED_BEFORE_LAUNCH;
  } else if (!isCompletelyDone()) {
    LOG.info("KILLING " + taskAttemptID);

    ContainerManagementProtocolProxyData proxy = null;
    try {
      proxy = getCMProxy(this.containerMgrAddress, this.containerID);

      // kill the remote container if already launched
      List<ContainerId> ids = new ArrayList<ContainerId>();
      ids.add(this.containerID);
      StopContainersRequest request = StopContainersRequest.newInstance(ids);
      StopContainersResponse response =
          proxy.getContainerManagementProtocol().stopContainers(request);
      if (response.getFailedRequests() != null
          && response.getFailedRequests().containsKey(this.containerID)) {
        throw response.getFailedRequests().get(this.containerID)
          .deSerialize();
      }
    } catch (Throwable t) {
      // ignore the cleanup failure
      String message = "cleanup failed for container "
          + this.containerID + " : "
          + StringUtils.stringifyException(t);
      context.getEventHandler()
          .handle(
              new TaskAttemptDiagnosticsUpdateEvent(this.taskAttemptID,
                  message));
      LOG.warn(message);
    } finally {
      if (proxy != null) {
        cmProxy.mayBeCloseProxy(proxy);
      }
    }
    this.state = ContainerState.DONE;
  }
  // after killing, send killed event to task attempt
  context.getEventHandler().handle(
      new TaskAttemptEvent(this.taskAttemptID,
          TaskAttemptEventType.TA_CONTAINER_CLEANED));
}
 
Example 26
Source Project: hadoop   Source File: TestContainerLauncherImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Test(timeout = 5000)
public void testHandle() throws Exception {
  LOG.info("STARTING testHandle");
  AppContext mockContext = mock(AppContext.class);
  @SuppressWarnings("rawtypes")
  EventHandler mockEventHandler = mock(EventHandler.class);
  when(mockContext.getEventHandler()).thenReturn(mockEventHandler);
  String cmAddress = "127.0.0.1:8000";
  ContainerManagementProtocolClient mockCM =
      mock(ContainerManagementProtocolClient.class);
  ContainerLauncherImplUnderTest ut =
      new ContainerLauncherImplUnderTest(mockContext, mockCM);
  
  Configuration conf = new Configuration();
  ut.init(conf);
  ut.start();
  try {
    ContainerId contId = makeContainerId(0l, 0, 0, 1);
    TaskAttemptId taskAttemptId = makeTaskAttemptId(0l, 0, 0, TaskType.MAP, 0);
    StartContainersResponse startResp =
      recordFactory.newRecordInstance(StartContainersResponse.class);
    startResp.setAllServicesMetaData(serviceResponse);
    

    LOG.info("inserting launch event");
    ContainerRemoteLaunchEvent mockLaunchEvent = 
      mock(ContainerRemoteLaunchEvent.class);
    when(mockLaunchEvent.getType())
      .thenReturn(EventType.CONTAINER_REMOTE_LAUNCH);
    when(mockLaunchEvent.getContainerID())
      .thenReturn(contId);
    when(mockLaunchEvent.getTaskAttemptID()).thenReturn(taskAttemptId);
    when(mockLaunchEvent.getContainerMgrAddress()).thenReturn(cmAddress);
    when(mockCM.startContainers(any(StartContainersRequest.class))).thenReturn(startResp);
    when(mockLaunchEvent.getContainerToken()).thenReturn(
        createNewContainerToken(contId, cmAddress));
    ut.handle(mockLaunchEvent);
    
    ut.waitForPoolToIdle();
    
    verify(mockCM).startContainers(any(StartContainersRequest.class));
    
    LOG.info("inserting cleanup event");
    ContainerLauncherEvent mockCleanupEvent = 
      mock(ContainerLauncherEvent.class);
    when(mockCleanupEvent.getType())
      .thenReturn(EventType.CONTAINER_REMOTE_CLEANUP);
    when(mockCleanupEvent.getContainerID())
      .thenReturn(contId);
    when(mockCleanupEvent.getTaskAttemptID()).thenReturn(taskAttemptId);
    when(mockCleanupEvent.getContainerMgrAddress()).thenReturn(cmAddress);
    ut.handle(mockCleanupEvent);
    
    ut.waitForPoolToIdle();
    
    verify(mockCM).stopContainers(any(StopContainersRequest.class));
  } finally {
    ut.stop();
  }
}
 
Example 27
Source Project: hadoop   Source File: TestContainerLauncherImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Test(timeout = 5000)
public void testOutOfOrder() throws Exception {
  LOG.info("STARTING testOutOfOrder");
  AppContext mockContext = mock(AppContext.class);
  @SuppressWarnings("rawtypes")
  EventHandler mockEventHandler = mock(EventHandler.class);
  when(mockContext.getEventHandler()).thenReturn(mockEventHandler);

  ContainerManagementProtocolClient mockCM =
      mock(ContainerManagementProtocolClient.class);
  ContainerLauncherImplUnderTest ut =
      new ContainerLauncherImplUnderTest(mockContext, mockCM);
  
  Configuration conf = new Configuration();
  ut.init(conf);
  ut.start();
  try {
    ContainerId contId = makeContainerId(0l, 0, 0, 1);
    TaskAttemptId taskAttemptId = makeTaskAttemptId(0l, 0, 0, TaskType.MAP, 0);
    String cmAddress = "127.0.0.1:8000";
    StartContainersResponse startResp =
      recordFactory.newRecordInstance(StartContainersResponse.class);
    startResp.setAllServicesMetaData(serviceResponse);

    LOG.info("inserting cleanup event");
    ContainerLauncherEvent mockCleanupEvent = 
      mock(ContainerLauncherEvent.class);
    when(mockCleanupEvent.getType())
      .thenReturn(EventType.CONTAINER_REMOTE_CLEANUP);
    when(mockCleanupEvent.getContainerID())
      .thenReturn(contId);
    when(mockCleanupEvent.getTaskAttemptID()).thenReturn(taskAttemptId);
    when(mockCleanupEvent.getContainerMgrAddress()).thenReturn(cmAddress);
    ut.handle(mockCleanupEvent);
    
    ut.waitForPoolToIdle();
    
    verify(mockCM, never()).stopContainers(any(StopContainersRequest.class));

    LOG.info("inserting launch event");
    ContainerRemoteLaunchEvent mockLaunchEvent = 
      mock(ContainerRemoteLaunchEvent.class);
    when(mockLaunchEvent.getType())
      .thenReturn(EventType.CONTAINER_REMOTE_LAUNCH);
    when(mockLaunchEvent.getContainerID())
      .thenReturn(contId);
    when(mockLaunchEvent.getTaskAttemptID()).thenReturn(taskAttemptId);
    when(mockLaunchEvent.getContainerMgrAddress()).thenReturn(cmAddress);
    when(mockCM.startContainers(any(StartContainersRequest.class))).thenReturn(startResp);
    when(mockLaunchEvent.getContainerToken()).thenReturn(
        createNewContainerToken(contId, cmAddress));
    ut.handle(mockLaunchEvent);
    
    ut.waitForPoolToIdle();
    
    verify(mockCM, never()).startContainers(any(StartContainersRequest.class));
  } finally {
    ut.stop();
  }
}
 
Example 28
Source Project: hadoop   Source File: TestContainerLauncherImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Test(timeout = 5000)
public void testMyShutdown() throws Exception {
  LOG.info("in test Shutdown");

  AppContext mockContext = mock(AppContext.class);
  @SuppressWarnings("rawtypes")
  EventHandler mockEventHandler = mock(EventHandler.class);
  when(mockContext.getEventHandler()).thenReturn(mockEventHandler);

  ContainerManagementProtocolClient mockCM =
      mock(ContainerManagementProtocolClient.class);
  ContainerLauncherImplUnderTest ut =
      new ContainerLauncherImplUnderTest(mockContext, mockCM);

  Configuration conf = new Configuration();
  ut.init(conf);
  ut.start();
  try {
    ContainerId contId = makeContainerId(0l, 0, 0, 1);
    TaskAttemptId taskAttemptId = makeTaskAttemptId(0l, 0, 0, TaskType.MAP, 0);
    String cmAddress = "127.0.0.1:8000";
    StartContainersResponse startResp =
      recordFactory.newRecordInstance(StartContainersResponse.class);
    startResp.setAllServicesMetaData(serviceResponse);

    LOG.info("inserting launch event");
    ContainerRemoteLaunchEvent mockLaunchEvent =
      mock(ContainerRemoteLaunchEvent.class);
    when(mockLaunchEvent.getType())
      .thenReturn(EventType.CONTAINER_REMOTE_LAUNCH);
    when(mockLaunchEvent.getContainerID())
      .thenReturn(contId);
    when(mockLaunchEvent.getTaskAttemptID()).thenReturn(taskAttemptId);
    when(mockLaunchEvent.getContainerMgrAddress()).thenReturn(cmAddress);
    when(mockCM.startContainers(any(StartContainersRequest.class))).thenReturn(startResp);
    when(mockLaunchEvent.getContainerToken()).thenReturn(
        createNewContainerToken(contId, cmAddress));
    ut.handle(mockLaunchEvent);

    ut.waitForPoolToIdle();

    verify(mockCM).startContainers(any(StartContainersRequest.class));

    // skip cleanup and make sure stop kills the container

  } finally {
    ut.stop();
    verify(mockCM).stopContainers(any(StopContainersRequest.class));
  }
}
 
Example 29
Source Project: hadoop   Source File: TestContainerLauncherImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public StopContainersResponse stopContainers(StopContainersRequest request)
    throws IOException {
  return null;
}
 
Example 30
Source Project: big-c   Source File: TestRPC.java    License: Apache License 2.0 4 votes vote down vote up
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());
}