Java Code Examples for org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatResponse

The following examples show how to use org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatResponse. 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: YarnServerBuilderUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static NodeHeartbeatResponse newNodeHeartbeatResponse(int responseId,
    NodeAction action, List<ContainerId> containersToCleanUp,
    List<ApplicationId> applicationsToCleanUp,
    MasterKey containerTokenMasterKey, MasterKey nmTokenMasterKey,
    long nextHeartbeatInterval) {
  NodeHeartbeatResponse response = recordFactory
      .newRecordInstance(NodeHeartbeatResponse.class);
  response.setResponseId(responseId);
  response.setNodeAction(action);
  response.setContainerTokenMasterKey(containerTokenMasterKey);
  response.setNMTokenMasterKey(nmTokenMasterKey);
  response.setNextHeartBeatInterval(nextHeartbeatInterval);
  if(containersToCleanUp != null) {
    response.addAllContainersToCleanup(containersToCleanUp);
  }
  if(applicationsToCleanUp != null) {
    response.addAllApplicationsToCleanup(applicationsToCleanUp);
  }
  return response;
}
 
Example 2
Source Project: hadoop   Source File: ResourceTrackerService.java    License: Apache License 2.0 6 votes vote down vote up
private void populateKeys(NodeHeartbeatRequest request,
    NodeHeartbeatResponse nodeHeartBeatResponse) {

  // Check if node's masterKey needs to be updated and if the currentKey has
  // roller over, send it across

  // ContainerTokenMasterKey

  MasterKey nextMasterKeyForNode =
      this.containerTokenSecretManager.getNextKey();
  if (nextMasterKeyForNode != null
      && (request.getLastKnownContainerTokenMasterKey().getKeyId()
          != nextMasterKeyForNode.getKeyId())) {
    nodeHeartBeatResponse.setContainerTokenMasterKey(nextMasterKeyForNode);
  }

  // NMTokenMasterKey

  nextMasterKeyForNode = this.nmTokenSecretManager.getNextKey();
  if (nextMasterKeyForNode != null
      && (request.getLastKnownNMTokenMasterKey().getKeyId() 
          != nextMasterKeyForNode.getKeyId())) {
    nodeHeartBeatResponse.setNMTokenMasterKey(nextMasterKeyForNode);
  }
}
 
Example 3
Source Project: hadoop   Source File: RMNodeImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void updateNodeHeartbeatResponseForCleanup(NodeHeartbeatResponse response) {
  this.writeLock.lock();

  try {
    response.addAllContainersToCleanup(
        new ArrayList<ContainerId>(this.containersToClean));
    response.addAllApplicationsToCleanup(this.finishedApplications);
    response.addContainersToBeRemovedFromNM(
        new ArrayList<ContainerId>(this.containersToBeRemovedFromNM));
    this.containersToClean.clear();
    this.finishedApplications.clear();
    this.containersToBeRemovedFromNM.clear();
  } finally {
    this.writeLock.unlock();
  }
}
 
Example 4
Source Project: hadoop   Source File: TestApplicationCleanup.java    License: Apache License 2.0 6 votes vote down vote up
protected void waitForContainerCleanup(DrainDispatcher dispatcher, MockNM nm,
    NodeHeartbeatResponse resp) throws Exception {
  int waitCount = 0, cleanedConts = 0;
  List<ContainerId> contsToClean;
  do {
    dispatcher.await();
    contsToClean = resp.getContainersToCleanup();
    cleanedConts += contsToClean.size();
    if (cleanedConts >= 1) {
      break;
    }
    Thread.sleep(100);
    resp = nm.nodeHeartbeat(true);
  } while(waitCount++ < 200);

  if (contsToClean.isEmpty()) {
    LOG.error("Failed to get any containers to cleanup");
  } else {
    LOG.info("Got cleanup for " + contsToClean.get(0));
  }
  Assert.assertEquals(1, cleanedConts);
}
 
Example 5
Source Project: hadoop   Source File: TestResourceTrackerService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test RM read NM next heartBeat Interval correctly from Configuration file,
 * and NM get next heartBeat Interval from RM correctly
 */
@Test (timeout = 50000)
public void testGetNextHeartBeatInterval() throws Exception {
  Configuration conf = new Configuration();
  conf.set(YarnConfiguration.RM_NM_HEARTBEAT_INTERVAL_MS, "4000");

  rm = new MockRM(conf);
  rm.start();

  MockNM nm1 = rm.registerNode("host1:1234", 5120);
  MockNM nm2 = rm.registerNode("host2:5678", 10240);

  NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertEquals(4000, nodeHeartbeat.getNextHeartBeatInterval());

  NodeHeartbeatResponse nodeHeartbeat2 = nm2.nodeHeartbeat(true);
  Assert.assertEquals(4000, nodeHeartbeat2.getNextHeartBeatInterval());

}
 
Example 6
Source Project: hadoop   Source File: TestResourceTrackerService.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReboot() throws Exception {
  Configuration conf = new Configuration();
  rm = new MockRM(conf);
  rm.start();

  MockNM nm1 = rm.registerNode("host1:1234", 5120);
  MockNM nm2 = rm.registerNode("host2:1234", 2048);

  int initialMetricCount = ClusterMetrics.getMetrics().getNumRebootedNMs();
  NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction()));

  nodeHeartbeat = nm2.nodeHeartbeat(
    new HashMap<ApplicationId, List<ContainerStatus>>(), true, -100);
  Assert.assertTrue(NodeAction.RESYNC.equals(nodeHeartbeat.getNodeAction()));
  Assert.assertEquals("Too far behind rm response id:0 nm response id:-100",
    nodeHeartbeat.getDiagnosticsMessage());
  checkRebootedNMCount(rm, ++initialMetricCount);
}
 
Example 7
Source Project: big-c   Source File: YarnServerBuilderUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static NodeHeartbeatResponse newNodeHeartbeatResponse(int responseId,
    NodeAction action, List<ContainerId> containersToCleanUp,
    List<ApplicationId> applicationsToCleanUp,List<NodeContainerUpdate> listNodeContainerUpdate,
    MasterKey containerTokenMasterKey, MasterKey nmTokenMasterKey,
    long nextHeartbeatInterval) {
  NodeHeartbeatResponse response = recordFactory
      .newRecordInstance(NodeHeartbeatResponse.class);
  response.setResponseId(responseId);
  response.setNodeAction(action);
  response.setContainerTokenMasterKey(containerTokenMasterKey);
  response.setNMTokenMasterKey(nmTokenMasterKey);
  response.setNextHeartBeatInterval(nextHeartbeatInterval);
  
  if(containersToCleanUp != null) {
    response.addAllContainersToCleanup(containersToCleanUp);
  }
  if(applicationsToCleanUp != null) {
    response.addAllApplicationsToCleanup(applicationsToCleanUp);
  }
  if(listNodeContainerUpdate != null){
    response.addNodeContainersToUpdate(listNodeContainerUpdate);	
  }
  return response;
}
 
Example 8
Source Project: big-c   Source File: ResourceTrackerService.java    License: Apache License 2.0 6 votes vote down vote up
private void populateKeys(NodeHeartbeatRequest request,
    NodeHeartbeatResponse nodeHeartBeatResponse) {

  // Check if node's masterKey needs to be updated and if the currentKey has
  // roller over, send it across

  // ContainerTokenMasterKey

  MasterKey nextMasterKeyForNode =
      this.containerTokenSecretManager.getNextKey();
  if (nextMasterKeyForNode != null
      && (request.getLastKnownContainerTokenMasterKey().getKeyId()
          != nextMasterKeyForNode.getKeyId())) {
    nodeHeartBeatResponse.setContainerTokenMasterKey(nextMasterKeyForNode);
  }

  // NMTokenMasterKey

  nextMasterKeyForNode = this.nmTokenSecretManager.getNextKey();
  if (nextMasterKeyForNode != null
      && (request.getLastKnownNMTokenMasterKey().getKeyId() 
          != nextMasterKeyForNode.getKeyId())) {
    nodeHeartBeatResponse.setNMTokenMasterKey(nextMasterKeyForNode);
  }
}
 
Example 9
Source Project: big-c   Source File: RMNodeImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void updateNodeHeartbeatResponseForCleanup(NodeHeartbeatResponse response) {
  this.writeLock.lock();

  try {
    response.addAllContainersToCleanup(
        new ArrayList<ContainerId>(this.containersToClean));
    response.addAllApplicationsToCleanup(this.finishedApplications);
    response.addContainersToBeRemovedFromNM(
        new ArrayList<ContainerId>(this.containersToBeRemovedFromNM));
    this.containersToClean.clear();
    this.finishedApplications.clear();
    this.containersToBeRemovedFromNM.clear();
  } finally {
    this.writeLock.unlock();
  }
}
 
Example 10
Source Project: big-c   Source File: TestApplicationCleanup.java    License: Apache License 2.0 6 votes vote down vote up
protected void waitForContainerCleanup(DrainDispatcher dispatcher, MockNM nm,
    NodeHeartbeatResponse resp) throws Exception {
  int waitCount = 0, cleanedConts = 0;
  List<ContainerId> contsToClean;
  do {
    dispatcher.await();
    contsToClean = resp.getContainersToCleanup();
    cleanedConts += contsToClean.size();
    if (cleanedConts >= 1) {
      break;
    }
    Thread.sleep(100);
    resp = nm.nodeHeartbeat(true);
  } while(waitCount++ < 200);

  if (contsToClean.isEmpty()) {
    LOG.error("Failed to get any containers to cleanup");
  } else {
    LOG.info("Got cleanup for " + contsToClean.get(0));
  }
  Assert.assertEquals(1, cleanedConts);
}
 
Example 11
Source Project: big-c   Source File: TestApplicationCleanup.java    License: Apache License 2.0 6 votes vote down vote up
private void waitForAppCleanupMessageRecved(MockNM nm, ApplicationId appId)
    throws Exception {
  while (true) {
    NodeHeartbeatResponse response = nm.nodeHeartbeat(true);
    if (response.getApplicationsToCleanup() != null
        && response.getApplicationsToCleanup().size() == 1
        && appId.equals(response.getApplicationsToCleanup().get(0))) {
      return;
    }

    LOG.info("Haven't got application=" + appId.toString()
        + " in cleanup list from node heartbeat response, "
        + "sleep for a while before next heartbeat");
    Thread.sleep(1000);
  }
}
 
Example 12
Source Project: hadoop   Source File: TestResourceTrackerPBClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
    throws YarnException, IOException {
  if (exception) {
    throw new YarnException("testMessage");
  }
  return recordFactory.newRecordInstance(NodeHeartbeatResponse.class);
}
 
Example 13
Source Project: hadoop   Source File: TestNodeStatusUpdater.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
    throws YarnException, IOException {
  NodeStatus nodeStatus = request.getNodeStatus();
  nodeStatus.setResponseId(heartBeatID++);

  NodeHeartbeatResponse nhResponse = YarnServerBuilderUtils.
      newNodeHeartbeatResponse(heartBeatID, heartBeatNodeAction, null,
          null, null, null, 1000L);
  nhResponse.setDiagnosticsMessage(shutDownMessage);
  return nhResponse;
}
 
Example 14
Source Project: hadoop   Source File: TestNodeStatusUpdater.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
    throws YarnException, IOException {
  LOG.info("Got heartBeatId: [" + heartBeatID +"]");
  NodeStatus nodeStatus = request.getNodeStatus();
  nodeStatus.setResponseId(heartBeatID++);
  NodeHeartbeatResponse nhResponse = YarnServerBuilderUtils.
      newNodeHeartbeatResponse(heartBeatID, heartBeatNodeAction, null,
          null, null, null, 1000L);

  if (nodeStatus.getKeepAliveApplications() != null
      && nodeStatus.getKeepAliveApplications().size() > 0) {
    for (ApplicationId appId : nodeStatus.getKeepAliveApplications()) {
      List<Long> list = keepAliveRequests.get(appId);
      if (list == null) {
        list = new LinkedList<Long>();
        keepAliveRequests.put(appId, list);
      }
      list.add(System.currentTimeMillis());
    }
  }
  if (heartBeatID == 2) {
    LOG.info("Sending FINISH_APP for application: [" + appId + "]");
    this.context.getApplications().put(appId, mock(Application.class));
    nhResponse.addAllApplicationsToCleanup(Collections.singletonList(appId));
  }
  return nhResponse;
}
 
Example 15
Source Project: incubator-myriad   Source File: TestObjectFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static RMNodeStatusEvent getRMStatusEvent(RMNode node) {
  NodeId id = node.getNodeID();
  NodeHealthStatus hStatus = NodeHealthStatusPBImpl.newInstance(true, "HEALTHY", System.currentTimeMillis());
  List<ContainerStatus> cStatus = Lists.newArrayList(getContainerStatus(node));
  List<ApplicationId> keepAliveIds = Lists.newArrayList(getApplicationId(node.getHttpPort()));
  NodeHeartbeatResponse response = new NodeHeartbeatResponsePBImpl();
  
  return new RMNodeStatusEvent(id, hStatus, cStatus, keepAliveIds, response);
}
 
Example 16
Source Project: hadoop   Source File: MockNodeStatusUpdater.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
    throws YarnException, IOException {
  NodeStatus nodeStatus = request.getNodeStatus();
  LOG.info("Got heartbeat number " + heartBeatID);
  nodeStatus.setResponseId(heartBeatID++);

  NodeHeartbeatResponse nhResponse = YarnServerBuilderUtils
      .newNodeHeartbeatResponse(heartBeatID, null, null,
          null, null, null, 1000L);
  return nhResponse;
}
 
Example 17
Source Project: big-c   Source File: TestResourceTrackerService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Decommissioning using a post-configured exclude hosts file
 */
@Test
public void testAddNewExcludePathToConfiguration() throws Exception {
  Configuration conf = new Configuration();
  rm = new MockRM(conf);
  rm.start();
  MockNM nm1 = rm.registerNode("host1:1234", 5120);
  MockNM nm2 = rm.registerNode("host2:5678", 10240);
  ClusterMetrics metrics = ClusterMetrics.getMetrics();
  assert(metrics != null);
  int initialMetricCount = metrics.getNumDecommisionedNMs();
  NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertEquals(
      NodeAction.NORMAL,
      nodeHeartbeat.getNodeAction());
  nodeHeartbeat = nm2.nodeHeartbeat(true);
  Assert.assertEquals(
      NodeAction.NORMAL,
      nodeHeartbeat.getNodeAction());
  writeToHostsFile("host2");
  conf.set(YarnConfiguration.RM_NODES_EXCLUDE_FILE_PATH, hostFile
      .getAbsolutePath());
  rm.getNodesListManager().refreshNodes(conf);
  checkDecommissionedNMCount(rm, ++initialMetricCount);
  nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertEquals(
      "Node should not have been decomissioned.",
      NodeAction.NORMAL,
      nodeHeartbeat.getNodeAction());
  nodeHeartbeat = nm2.nodeHeartbeat(true);
  Assert.assertEquals("Node should have been decomissioned but is in state" +
      nodeHeartbeat.getNodeAction(),
      NodeAction.SHUTDOWN, nodeHeartbeat.getNodeAction());
}
 
Example 18
Source Project: hadoop   Source File: RMNodeImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NodeHeartbeatResponse getLastNodeHeartBeatResponse() {

  this.readLock.lock();

  try {
    return this.latestNodeHeartBeatResponse;
  } finally {
    this.readLock.unlock();
  }
}
 
Example 19
Source Project: big-c   Source File: TestResourceTrackerService.java    License: Apache License 2.0 5 votes vote down vote up
/**
* Decommissioning using a post-configured include hosts file
*/
@Test
public void testAddNewIncludePathToConfiguration() throws Exception {
  Configuration conf = new Configuration();
  rm = new MockRM(conf);
  rm.start();
  MockNM nm1 = rm.registerNode("host1:1234", 5120);
  MockNM nm2 = rm.registerNode("host2:5678", 10240);
  ClusterMetrics metrics = ClusterMetrics.getMetrics();
  assert(metrics != null);
  int initialMetricCount = metrics.getNumDecommisionedNMs();
  NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertEquals(
      NodeAction.NORMAL,
      nodeHeartbeat.getNodeAction());
  nodeHeartbeat = nm2.nodeHeartbeat(true);
  Assert.assertEquals(
      NodeAction.NORMAL,
      nodeHeartbeat.getNodeAction());
  writeToHostsFile("host1");
  conf.set(YarnConfiguration.RM_NODES_INCLUDE_FILE_PATH, hostFile
      .getAbsolutePath());
  rm.getNodesListManager().refreshNodes(conf);
  checkDecommissionedNMCount(rm, ++initialMetricCount);
  nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertEquals(
      "Node should not have been decomissioned.",
      NodeAction.NORMAL,
      nodeHeartbeat.getNodeAction());
  nodeHeartbeat = nm2.nodeHeartbeat(true);
  Assert.assertEquals("Node should have been decomissioned but is in state" +
      nodeHeartbeat.getNodeAction(),
      NodeAction.SHUTDOWN, nodeHeartbeat.getNodeAction());
}
 
Example 20
Source Project: big-c   Source File: TestRMNodeTransitions.java    License: Apache License 2.0 5 votes vote down vote up
private RMNodeStatusEvent getMockRMNodeStatusEvent() {
  NodeHeartbeatResponse response = mock(NodeHeartbeatResponse.class);

  NodeHealthStatus healthStatus = mock(NodeHealthStatus.class);
  Boolean yes = new Boolean(true);
  doReturn(yes).when(healthStatus).getIsNodeHealthy();
  
  RMNodeStatusEvent event = mock(RMNodeStatusEvent.class);
  doReturn(healthStatus).when(event).getNodeHealthStatus();
  doReturn(response).when(event).getLatestResponse();
  doReturn(RMNodeEventType.STATUS_UPDATE).when(event).getType();
  return event;
}
 
Example 21
Source Project: incubator-myriad   Source File: NMHeartBeatHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
private RMNodeStatusEvent getRMStatusEvent(RMNode node) {
  NodeId id = node.getNodeID();
  NodeHealthStatus hStatus = NodeHealthStatusPBImpl.newInstance(true, "HEALTHY", System.currentTimeMillis());
  List<ContainerStatus> cStatus = Lists.newArrayList(getContainerStatus(node));
  List<ApplicationId> keepAliveIds = Lists.newArrayList(getApplicationId(node.getHttpPort()));
  NodeHeartbeatResponse response = new NodeHeartbeatResponsePBImpl();
  
  return new RMNodeStatusEvent(id, hStatus, cStatus, keepAliveIds, response);
}
 
Example 22
Source Project: hadoop   Source File: TestRMNodeTransitions.java    License: Apache License 2.0 5 votes vote down vote up
private RMNodeStatusEvent getMockRMNodeStatusEvent() {
  NodeHeartbeatResponse response = mock(NodeHeartbeatResponse.class);

  NodeHealthStatus healthStatus = mock(NodeHealthStatus.class);
  Boolean yes = new Boolean(true);
  doReturn(yes).when(healthStatus).getIsNodeHealthy();
  
  RMNodeStatusEvent event = mock(RMNodeStatusEvent.class);
  doReturn(healthStatus).when(event).getNodeHealthStatus();
  doReturn(response).when(event).getLatestResponse();
  doReturn(RMNodeEventType.STATUS_UPDATE).when(event).getType();
  return event;
}
 
Example 23
Source Project: hadoop   Source File: MockNM.java    License: Apache License 2.0 5 votes vote down vote up
public NodeHeartbeatResponse nodeHeartbeat(ApplicationAttemptId attemptId,
    long containerId, ContainerState containerState) throws Exception {
  HashMap<ApplicationId, List<ContainerStatus>> nodeUpdate =
      new HashMap<ApplicationId, List<ContainerStatus>>(1);
  ContainerStatus containerStatus = BuilderUtils.newContainerStatus(
      BuilderUtils.newContainerId(attemptId, containerId), containerState,
      "Success", 0);
  ArrayList<ContainerStatus> containerStatusList =
      new ArrayList<ContainerStatus>(1);
  containerStatusList.add(containerStatus);
  Log.info("ContainerStatus: " + containerStatus);
  nodeUpdate.put(attemptId.getApplicationId(), containerStatusList);
  return nodeHeartbeat(nodeUpdate, true);
}
 
Example 24
Source Project: hadoop   Source File: MockNM.java    License: Apache License 2.0 5 votes vote down vote up
public NodeHeartbeatResponse nodeHeartbeat(Map<ApplicationId,
    List<ContainerStatus>> conts, boolean isHealthy, int resId) throws Exception {
  NodeHeartbeatRequest req = Records.newRecord(NodeHeartbeatRequest.class);
  NodeStatus status = Records.newRecord(NodeStatus.class);
  status.setResponseId(resId);
  status.setNodeId(nodeId);
  for (Map.Entry<ApplicationId, List<ContainerStatus>> entry : conts.entrySet()) {
    Log.info("entry.getValue() " + entry.getValue());
    status.setContainersStatuses(entry.getValue());
  }
  NodeHealthStatus healthStatus = Records.newRecord(NodeHealthStatus.class);
  healthStatus.setHealthReport("");
  healthStatus.setIsNodeHealthy(isHealthy);
  healthStatus.setLastHealthReportTime(1);
  status.setNodeHealthStatus(healthStatus);
  req.setNodeStatus(status);
  req.setLastKnownContainerTokenMasterKey(this.currentContainerTokenMasterKey);
  req.setLastKnownNMTokenMasterKey(this.currentNMTokenMasterKey);
  NodeHeartbeatResponse heartbeatResponse =
      resourceTracker.nodeHeartbeat(req);
  
  MasterKey masterKeyFromRM = heartbeatResponse.getContainerTokenMasterKey();
  if (masterKeyFromRM != null
      && masterKeyFromRM.getKeyId() != this.currentContainerTokenMasterKey
          .getKeyId()) {
    this.currentContainerTokenMasterKey = masterKeyFromRM;
  }

  masterKeyFromRM = heartbeatResponse.getNMTokenMasterKey();
  if (masterKeyFromRM != null
      && masterKeyFromRM.getKeyId() != this.currentNMTokenMasterKey
          .getKeyId()) {
    this.currentNMTokenMasterKey = masterKeyFromRM;
  }
  
  return heartbeatResponse;
}
 
Example 25
Source Project: hadoop   Source File: TestResourceTrackerService.java    License: Apache License 2.0 5 votes vote down vote up
/**
* Decommissioning using a post-configured include hosts file
*/
@Test
public void testAddNewIncludePathToConfiguration() throws Exception {
  Configuration conf = new Configuration();
  rm = new MockRM(conf);
  rm.start();
  MockNM nm1 = rm.registerNode("host1:1234", 5120);
  MockNM nm2 = rm.registerNode("host2:5678", 10240);
  ClusterMetrics metrics = ClusterMetrics.getMetrics();
  assert(metrics != null);
  int initialMetricCount = metrics.getNumDecommisionedNMs();
  NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertEquals(
      NodeAction.NORMAL,
      nodeHeartbeat.getNodeAction());
  nodeHeartbeat = nm2.nodeHeartbeat(true);
  Assert.assertEquals(
      NodeAction.NORMAL,
      nodeHeartbeat.getNodeAction());
  writeToHostsFile("host1");
  conf.set(YarnConfiguration.RM_NODES_INCLUDE_FILE_PATH, hostFile
      .getAbsolutePath());
  rm.getNodesListManager().refreshNodes(conf);
  checkDecommissionedNMCount(rm, ++initialMetricCount);
  nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertEquals(
      "Node should not have been decomissioned.",
      NodeAction.NORMAL,
      nodeHeartbeat.getNodeAction());
  nodeHeartbeat = nm2.nodeHeartbeat(true);
  Assert.assertEquals("Node should have been decomissioned but is in state" +
      nodeHeartbeat.getNodeAction(),
      NodeAction.SHUTDOWN, nodeHeartbeat.getNodeAction());
}
 
Example 26
Source Project: hadoop   Source File: TestResourceTrackerService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Decommissioning using a post-configured exclude hosts file
 */
@Test
public void testAddNewExcludePathToConfiguration() throws Exception {
  Configuration conf = new Configuration();
  rm = new MockRM(conf);
  rm.start();
  MockNM nm1 = rm.registerNode("host1:1234", 5120);
  MockNM nm2 = rm.registerNode("host2:5678", 10240);
  ClusterMetrics metrics = ClusterMetrics.getMetrics();
  assert(metrics != null);
  int initialMetricCount = metrics.getNumDecommisionedNMs();
  NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertEquals(
      NodeAction.NORMAL,
      nodeHeartbeat.getNodeAction());
  nodeHeartbeat = nm2.nodeHeartbeat(true);
  Assert.assertEquals(
      NodeAction.NORMAL,
      nodeHeartbeat.getNodeAction());
  writeToHostsFile("host2");
  conf.set(YarnConfiguration.RM_NODES_EXCLUDE_FILE_PATH, hostFile
      .getAbsolutePath());
  rm.getNodesListManager().refreshNodes(conf);
  checkDecommissionedNMCount(rm, ++initialMetricCount);
  nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertEquals(
      "Node should not have been decomissioned.",
      NodeAction.NORMAL,
      nodeHeartbeat.getNodeAction());
  nodeHeartbeat = nm2.nodeHeartbeat(true);
  Assert.assertEquals("Node should have been decomissioned but is in state" +
      nodeHeartbeat.getNodeAction(),
      NodeAction.SHUTDOWN, nodeHeartbeat.getNodeAction());
}
 
Example 27
Source Project: hadoop   Source File: ProtocolHATestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
    throws YarnException, IOException {
  resetStartFailoverFlag(true);
  // make sure failover has been triggered
  Assert.assertTrue(waittingForFailOver());
  return super.nodeHeartbeat(request);
}
 
Example 28
Source Project: big-c   Source File: ResourceTrackerPBClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
    throws YarnException, IOException {
  NodeHeartbeatRequestProto requestProto = ((NodeHeartbeatRequestPBImpl)request).getProto();
  try {
    return new NodeHeartbeatResponsePBImpl(proxy.nodeHeartbeat(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 29
Source Project: big-c   Source File: TestResourceTrackerPBClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
    throws YarnException, IOException {
  if (exception) {
    throw new YarnException("testMessage");
  }
  return recordFactory.newRecordInstance(NodeHeartbeatResponse.class);
}
 
Example 30
Source Project: big-c   Source File: TestNodeStatusUpdater.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
    throws YarnException, IOException {
  NodeStatus nodeStatus = request.getNodeStatus();
  nodeStatus.setResponseId(heartBeatID++);

  NodeHeartbeatResponse nhResponse = YarnServerBuilderUtils.
      newNodeHeartbeatResponse(heartBeatID, heartBeatNodeAction, null,
          null, null, null, null, 1000L);
  nhResponse.setDiagnosticsMessage(shutDownMessage);
  return nhResponse;
}