org.apache.hadoop.yarn.server.api.records.NodeHealthStatus Java Examples

The following examples show how to use org.apache.hadoop.yarn.server.api.records.NodeHealthStatus. 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 File: TestNMExpiry.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public void run() {
  int lastResponseID = 0;
  while (!stopT) {
    try {
      org.apache.hadoop.yarn.server.api.records.NodeStatus nodeStatus =
          recordFactory
              .newRecordInstance(org.apache.hadoop.yarn.server.api.records.NodeStatus.class);
      nodeStatus.setNodeId(request3.getNodeId());
      nodeStatus.setResponseId(lastResponseID);
      nodeStatus.setNodeHealthStatus(recordFactory.newRecordInstance(NodeHealthStatus.class));
      nodeStatus.getNodeHealthStatus().setIsNodeHealthy(true);

      NodeHeartbeatRequest request = recordFactory
          .newRecordInstance(NodeHeartbeatRequest.class);
      request.setNodeStatus(nodeStatus);
      lastResponseID = resourceTrackerService.nodeHeartbeat(request)
          .getResponseId();

      Thread.sleep(1000);
    } catch(Exception e) {
      LOG.info("failed to heartbeat ", e);
    }
  }
}
 
Example #2
Source File: RMNodeImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public NodeState transition(RMNodeImpl rmNode, RMNodeEvent event) {
  RMNodeStatusEvent statusEvent = (RMNodeStatusEvent) event;

  // Switch the last heartbeatresponse.
  rmNode.latestNodeHeartBeatResponse = statusEvent.getLatestResponse();
  NodeHealthStatus remoteNodeHealthStatus = statusEvent.getNodeHealthStatus();
  rmNode.setHealthReport(remoteNodeHealthStatus.getHealthReport());
  rmNode.setLastHealthReportTime(
      remoteNodeHealthStatus.getLastHealthReportTime());
  if (remoteNodeHealthStatus.getIsNodeHealthy()) {
    rmNode.context.getDispatcher().getEventHandler().handle(
        new NodeAddedSchedulerEvent(rmNode));
    rmNode.context.getDispatcher().getEventHandler().handle(
            new NodesListManagerEvent(
                NodesListManagerEventType.NODE_USABLE, rmNode));
    // ??? how about updating metrics before notifying to ensure that
    // notifiers get update metadata because they will very likely query it
    // upon notification
    // Update metrics
    rmNode.updateMetricsForRejoinedNode(NodeState.UNHEALTHY);
    return NodeState.RUNNING;
  }

  return NodeState.UNHEALTHY;
}
 
Example #3
Source File: NodeStatusUpdaterImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private NodeStatus getNodeStatus(int responseId) throws IOException {

    NodeHealthStatus nodeHealthStatus = this.context.getNodeHealthStatus();
    nodeHealthStatus.setHealthReport(healthChecker.getHealthReport());
    nodeHealthStatus.setIsNodeHealthy(healthChecker.isHealthy());
    nodeHealthStatus.setLastHealthReportTime(healthChecker
      .getLastHealthReportTime());
    if (LOG.isDebugEnabled()) {
      LOG.debug("Node's health-status : " + nodeHealthStatus.getIsNodeHealthy()
          + ", " + nodeHealthStatus.getHealthReport());
    }
    List<ContainerStatus> containersStatuses = getContainerStatuses();
    NodeStatus nodeStatus =
        NodeStatus.newInstance(nodeId, responseId, containersStatuses,
          createKeepAliveApplicationList(), nodeHealthStatus);

    return nodeStatus;
  }
 
Example #4
Source File: TestNMExpiry.java    From big-c with Apache License 2.0 6 votes vote down vote up
public void run() {
  int lastResponseID = 0;
  while (!stopT) {
    try {
      org.apache.hadoop.yarn.server.api.records.NodeStatus nodeStatus =
          recordFactory
              .newRecordInstance(org.apache.hadoop.yarn.server.api.records.NodeStatus.class);
      nodeStatus.setNodeId(request3.getNodeId());
      nodeStatus.setResponseId(lastResponseID);
      nodeStatus.setNodeHealthStatus(recordFactory.newRecordInstance(NodeHealthStatus.class));
      nodeStatus.getNodeHealthStatus().setIsNodeHealthy(true);

      NodeHeartbeatRequest request = recordFactory
          .newRecordInstance(NodeHeartbeatRequest.class);
      request.setNodeStatus(nodeStatus);
      lastResponseID = resourceTrackerService.nodeHeartbeat(request)
          .getResponseId();

      Thread.sleep(1000);
    } catch(Exception e) {
      LOG.info("failed to heartbeat ", e);
    }
  }
}
 
Example #5
Source File: NodeStatusUpdaterImpl.java    From big-c with Apache License 2.0 6 votes vote down vote up
private NodeStatus getNodeStatus(int responseId) throws IOException {

    NodeHealthStatus nodeHealthStatus = this.context.getNodeHealthStatus();
    nodeHealthStatus.setHealthReport(healthChecker.getHealthReport());
    nodeHealthStatus.setIsNodeHealthy(healthChecker.isHealthy());
    nodeHealthStatus.setLastHealthReportTime(healthChecker
      .getLastHealthReportTime());
    if (LOG.isDebugEnabled()) {
      LOG.debug("Node's health-status : " + nodeHealthStatus.getIsNodeHealthy()
          + ", " + nodeHealthStatus.getHealthReport());
    }
    List<ContainerStatus> containersStatuses = getContainerStatuses();
    NodeStatus nodeStatus =
        NodeStatus.newInstance(nodeId, responseId, containersStatuses,
          createKeepAliveApplicationList(), nodeHealthStatus);

    return nodeStatus;
  }
 
Example #6
Source File: RMNodeImpl.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public NodeState transition(RMNodeImpl rmNode, RMNodeEvent event) {
  RMNodeStatusEvent statusEvent = (RMNodeStatusEvent) event;

  // Switch the last heartbeatresponse.
  rmNode.latestNodeHeartBeatResponse = statusEvent.getLatestResponse();
  NodeHealthStatus remoteNodeHealthStatus = statusEvent.getNodeHealthStatus();
  rmNode.setHealthReport(remoteNodeHealthStatus.getHealthReport());
  rmNode.setLastHealthReportTime(
      remoteNodeHealthStatus.getLastHealthReportTime());
  if (remoteNodeHealthStatus.getIsNodeHealthy()) {
    rmNode.context.getDispatcher().getEventHandler().handle(
        new NodeAddedSchedulerEvent(rmNode));
    rmNode.context.getDispatcher().getEventHandler().handle(
            new NodesListManagerEvent(
                NodesListManagerEventType.NODE_USABLE, rmNode));
    // ??? how about updating metrics before notifying to ensure that
    // notifiers get update metadata because they will very likely query it
    // upon notification
    // Update metrics
    rmNode.updateMetricsForRejoinedNode(NodeState.UNHEALTHY);
    return NodeState.RUNNING;
  }

  return NodeState.UNHEALTHY;
}
 
Example #7
Source File: TestRMWebServicesNodes.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testNodesDefaultWithUnHealthyNode() throws JSONException,
    Exception {

  WebResource r = resource();
  MockNM nm1 = rm.registerNode("h1:1234", 5120);
  MockNM nm2 = rm.registerNode("h2:1235", 5121);
  rm.sendNodeStarted(nm1);
  rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING);
  rm.NMwaitForState(nm2.getNodeId(), NodeState.NEW);

  MockNM nm3 = rm.registerNode("h3:1236", 5122);
  rm.NMwaitForState(nm3.getNodeId(), NodeState.NEW);
  rm.sendNodeStarted(nm3);
  rm.NMwaitForState(nm3.getNodeId(), NodeState.RUNNING);
  RMNodeImpl node = (RMNodeImpl) rm.getRMContext().getRMNodes()
      .get(nm3.getNodeId());
  NodeHealthStatus nodeHealth = NodeHealthStatus.newInstance(false,
      "test health report", System.currentTimeMillis());
  node.handle(new RMNodeStatusEvent(nm3.getNodeId(), nodeHealth,
      new ArrayList<ContainerStatus>(), null, null));
  rm.NMwaitForState(nm3.getNodeId(), NodeState.UNHEALTHY);

  ClientResponse response =
      r.path("ws").path("v1").path("cluster").path("nodes")
        .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);

  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject nodes = json.getJSONObject("nodes");
  assertEquals("incorrect number of elements", 1, nodes.length());
  JSONArray nodeArray = nodes.getJSONArray("node");
  // 3 nodes, including the unhealthy node and the new node.
  assertEquals("incorrect number of elements", 3, nodeArray.length());
}
 
Example #8
Source File: MockNM.java    From hadoop with 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 #9
Source File: NodeStatusPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized NodeHealthStatus getNodeHealthStatus() {
  NodeStatusProtoOrBuilder p = viaProto ? proto : builder;
  if (nodeHealthStatus != null) {
    return nodeHealthStatus;
  }
  if (!p.hasNodeHealthStatus()) {
    return null;
  }
  nodeHealthStatus = convertFromProtoFormat(p.getNodeHealthStatus());
  return nodeHealthStatus;
}
 
Example #10
Source File: NodeStatusPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized NodeHealthStatus getNodeHealthStatus() {
  NodeStatusProtoOrBuilder p = viaProto ? proto : builder;
  if (nodeHealthStatus != null) {
    return nodeHealthStatus;
  }
  if (!p.hasNodeHealthStatus()) {
    return null;
  }
  nodeHealthStatus = convertFromProtoFormat(p.getNodeHealthStatus());
  return nodeHealthStatus;
}
 
Example #11
Source File: TestYarnServerApiClasses.java    From big-c with Apache License 2.0 5 votes vote down vote up
private NodeHealthStatus getNodeHealthStatus() {
  NodeHealthStatus healStatus = recordFactory
      .newRecordInstance(NodeHealthStatus.class);
  healStatus.setHealthReport("healthReport");
  healStatus.setIsNodeHealthy(true);
  healStatus.setLastHealthReportTime(1000);
  return healStatus;

}
 
Example #12
Source File: RMNodeStatusEvent.java    From big-c with Apache License 2.0 5 votes vote down vote up
public RMNodeStatusEvent(NodeId nodeId, NodeHealthStatus nodeHealthStatus,
    List<ContainerStatus> collection, List<ApplicationId> keepAliveAppIds,
    NodeHeartbeatResponse latestResponse) {
  super(nodeId, RMNodeEventType.STATUS_UPDATE);
  this.nodeHealthStatus = nodeHealthStatus;
  this.containersCollection = collection;
  this.keepAliveAppIds = keepAliveAppIds;
  this.latestResponse = latestResponse;
}
 
Example #13
Source File: NodeStatusPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void setNodeHealthStatus(NodeHealthStatus healthStatus) {
  maybeInitBuilder();
  if (healthStatus == null) {
    builder.clearNodeHealthStatus();
  }
  this.nodeHealthStatus = healthStatus;
}
 
Example #14
Source File: NodeManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
public static org.apache.hadoop.yarn.server.api.records.NodeStatus 
createNodeStatus(NodeId nodeId, List<ContainerStatus> containers) {
  RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null);
  org.apache.hadoop.yarn.server.api.records.NodeStatus nodeStatus = 
      recordFactory.newRecordInstance(org.apache.hadoop.yarn.server.api.records.NodeStatus.class);
  nodeStatus.setNodeId(nodeId);
  nodeStatus.setContainersStatuses(containers);
  NodeHealthStatus nodeHealthStatus = 
    recordFactory.newRecordInstance(NodeHealthStatus.class);
  nodeHealthStatus.setIsNodeHealthy(true);
  nodeStatus.setNodeHealthStatus(nodeHealthStatus);
  return nodeStatus;
}
 
Example #15
Source File: TestRMNodeTransitions.java    From big-c with 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 #16
Source File: TestRMNodeTransitions.java    From big-c with Apache License 2.0 5 votes vote down vote up
private RMNodeImpl getUnhealthyNode() {
  RMNodeImpl node = getRunningNode();
  NodeHealthStatus status = NodeHealthStatus.newInstance(false, "sick",
      System.currentTimeMillis());
  node.handle(new RMNodeStatusEvent(node.getNodeID(), status,
      new ArrayList<ContainerStatus>(), null, null));
  Assert.assertEquals(NodeState.UNHEALTHY, node.getState());
  return node;
}
 
Example #17
Source File: MockNM.java    From big-c with 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 #18
Source File: TestObjectFactory.java    From incubator-myriad with 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 #19
Source File: NMHeartBeatHandlerTest.java    From incubator-myriad with 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 #20
Source File: TestRMNodeTransitions.java    From hadoop with 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 File: NodeStatusPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void setNodeHealthStatus(NodeHealthStatus healthStatus) {
  maybeInitBuilder();
  if (healthStatus == null) {
    builder.clearNodeHealthStatus();
  }
  this.nodeHealthStatus = healthStatus;
}
 
Example #22
Source File: TestYarnServerApiClasses.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private NodeHealthStatus getNodeHealthStatus() {
  NodeHealthStatus healStatus = recordFactory
      .newRecordInstance(NodeHealthStatus.class);
  healStatus.setHealthReport("healthReport");
  healStatus.setIsNodeHealthy(true);
  healStatus.setLastHealthReportTime(1000);
  return healStatus;

}
 
Example #23
Source File: RMNodeStatusEvent.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public RMNodeStatusEvent(NodeId nodeId, NodeHealthStatus nodeHealthStatus,
    List<ContainerStatus> collection, List<ApplicationId> keepAliveAppIds,
    NodeHeartbeatResponse latestResponse) {
  super(nodeId, RMNodeEventType.STATUS_UPDATE);
  this.nodeHealthStatus = nodeHealthStatus;
  this.containersCollection = collection;
  this.keepAliveAppIds = keepAliveAppIds;
  this.latestResponse = latestResponse;
}
 
Example #24
Source File: TestRMWebServicesNodes.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testNodesDefaultWithUnHealthyNode() throws JSONException,
    Exception {

  WebResource r = resource();
  MockNM nm1 = rm.registerNode("h1:1234", 5120);
  MockNM nm2 = rm.registerNode("h2:1235", 5121);
  rm.sendNodeStarted(nm1);
  rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING);
  rm.NMwaitForState(nm2.getNodeId(), NodeState.NEW);

  MockNM nm3 = rm.registerNode("h3:1236", 5122);
  rm.NMwaitForState(nm3.getNodeId(), NodeState.NEW);
  rm.sendNodeStarted(nm3);
  rm.NMwaitForState(nm3.getNodeId(), NodeState.RUNNING);
  RMNodeImpl node = (RMNodeImpl) rm.getRMContext().getRMNodes()
      .get(nm3.getNodeId());
  NodeHealthStatus nodeHealth = NodeHealthStatus.newInstance(false,
      "test health report", System.currentTimeMillis());
  node.handle(new RMNodeStatusEvent(nm3.getNodeId(), nodeHealth,
      new ArrayList<ContainerStatus>(), null, null));
  rm.NMwaitForState(nm3.getNodeId(), NodeState.UNHEALTHY);

  ClientResponse response =
      r.path("ws").path("v1").path("cluster").path("nodes")
        .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);

  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject nodes = json.getJSONObject("nodes");
  assertEquals("incorrect number of elements", 1, nodes.length());
  JSONArray nodeArray = nodes.getJSONArray("node");
  // 3 nodes, including the unhealthy node and the new node.
  assertEquals("incorrect number of elements", 3, nodeArray.length());
}
 
Example #25
Source File: NodeManager.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static org.apache.hadoop.yarn.server.api.records.NodeStatus 
createNodeStatus(NodeId nodeId, List<ContainerStatus> containers) {
  RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null);
  org.apache.hadoop.yarn.server.api.records.NodeStatus nodeStatus = 
      recordFactory.newRecordInstance(org.apache.hadoop.yarn.server.api.records.NodeStatus.class);
  nodeStatus.setNodeId(nodeId);
  nodeStatus.setContainersStatuses(containers);
  NodeHealthStatus nodeHealthStatus = 
    recordFactory.newRecordInstance(NodeHealthStatus.class);
  nodeHealthStatus.setIsNodeHealthy(true);
  nodeStatus.setNodeHealthStatus(nodeHealthStatus);
  return nodeStatus;
}
 
Example #26
Source File: TestRMNodeTransitions.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private RMNodeImpl getUnhealthyNode() {
  RMNodeImpl node = getRunningNode();
  NodeHealthStatus status = NodeHealthStatus.newInstance(false, "sick",
      System.currentTimeMillis());
  node.handle(new RMNodeStatusEvent(node.getNodeID(), status,
      new ArrayList<ContainerStatus>(), null, null));
  Assert.assertEquals(NodeState.UNHEALTHY, node.getState());
  return node;
}
 
Example #27
Source File: TestNodeHealthService.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test
public void testNodeHealthService() throws Exception {
  RecordFactory factory = RecordFactoryProvider.getRecordFactory(null);
  NodeHealthStatus healthStatus =
      factory.newRecordInstance(NodeHealthStatus.class);
  Configuration conf = getConfForNodeHealthScript();
  conf.writeXml(new FileOutputStream(nodeHealthConfigFile));
  conf.addResource(nodeHealthConfigFile.getName());
  writeNodeHealthScriptFile("", true);

  LocalDirsHandlerService dirsHandler = new LocalDirsHandlerService();
  NodeHealthScriptRunner nodeHealthScriptRunner =
      spy(NodeManager.getNodeHealthScriptRunner(conf));
  NodeHealthCheckerService nodeHealthChecker = new NodeHealthCheckerService(
  		nodeHealthScriptRunner, dirsHandler);
  nodeHealthChecker.init(conf);

  doReturn(true).when(nodeHealthScriptRunner).isHealthy();
  doReturn("").when(nodeHealthScriptRunner).getHealthReport();
  setHealthStatus(healthStatus, nodeHealthChecker.isHealthy(),
      nodeHealthChecker.getHealthReport(),
      nodeHealthChecker.getLastHealthReportTime());
  LOG.info("Checking initial healthy condition");
  // Check proper report conditions.
  Assert.assertTrue("Node health status reported unhealthy", healthStatus
      .getIsNodeHealthy());
  Assert.assertTrue("Node health status reported unhealthy", healthStatus
      .getHealthReport().equals(nodeHealthChecker.getHealthReport()));

  doReturn(false).when(nodeHealthScriptRunner).isHealthy();   
  // update health status
  setHealthStatus(healthStatus, nodeHealthChecker.isHealthy(),
      nodeHealthChecker.getHealthReport(),
      nodeHealthChecker.getLastHealthReportTime());
  LOG.info("Checking Healthy--->Unhealthy");
  Assert.assertFalse("Node health status reported healthy", healthStatus
      .getIsNodeHealthy());
  Assert.assertTrue("Node health status reported healthy", healthStatus
      .getHealthReport().equals(nodeHealthChecker.getHealthReport()));

  doReturn(true).when(nodeHealthScriptRunner).isHealthy();
  setHealthStatus(healthStatus, nodeHealthChecker.isHealthy(),
      nodeHealthChecker.getHealthReport(),
      nodeHealthChecker.getLastHealthReportTime());
  LOG.info("Checking UnHealthy--->healthy");
  // Check proper report conditions.
  Assert.assertTrue("Node health status reported unhealthy", healthStatus
      .getIsNodeHealthy());
  Assert.assertTrue("Node health status reported unhealthy", healthStatus
      .getHealthReport().equals(nodeHealthChecker.getHealthReport()));

  // Healthy to timeout transition.
  doReturn(false).when(nodeHealthScriptRunner).isHealthy();
  doReturn(NodeHealthScriptRunner.NODE_HEALTH_SCRIPT_TIMED_OUT_MSG)
      .when(nodeHealthScriptRunner).getHealthReport();
  setHealthStatus(healthStatus, nodeHealthChecker.isHealthy(),
      nodeHealthChecker.getHealthReport(),
      nodeHealthChecker.getLastHealthReportTime());
  LOG.info("Checking Healthy--->timeout");
  Assert.assertFalse("Node health status reported healthy even after timeout",
      healthStatus.getIsNodeHealthy());
  Assert.assertTrue("Node script time out message not propogated",
      healthStatus.getHealthReport().equals(
          NodeHealthScriptRunner.NODE_HEALTH_SCRIPT_TIMED_OUT_MSG
          + NodeHealthCheckerService.SEPARATOR
          + nodeHealthChecker.getDiskHandler().getDisksHealthReport(false)));
}
 
Example #28
Source File: NodeStatusPBImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
private NodeHealthStatus convertFromProtoFormat(NodeHealthStatusProto proto) {
  return new NodeHealthStatusPBImpl(proto);
}
 
Example #29
Source File: NodeStatusPBImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private NodeHealthStatusProto convertToProtoFormat(
    NodeHealthStatus healthStatus) {
  return ((NodeHealthStatusPBImpl) healthStatus).getProto();
}
 
Example #30
Source File: NMSimulator.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public void middleStep() throws Exception {
  // we check the lifetime for each running containers
  ContainerSimulator cs = null;
  synchronized(completedContainerList) {
    while ((cs = containerQueue.poll()) != null) {
      runningContainers.remove(cs.getId());
      completedContainerList.add(cs.getId());
      LOG.debug(MessageFormat.format("Container {0} has completed",
              cs.getId()));
    }
  }
  
  // send heart beat
  NodeHeartbeatRequest beatRequest =
          Records.newRecord(NodeHeartbeatRequest.class);
  beatRequest.setLastKnownNMTokenMasterKey(masterKey);
  NodeStatus ns = Records.newRecord(NodeStatus.class);
  
  ns.setContainersStatuses(generateContainerStatusList());
  ns.setNodeId(node.getNodeID());
  ns.setKeepAliveApplications(new ArrayList<ApplicationId>());
  ns.setResponseId(RESPONSE_ID ++);
  ns.setNodeHealthStatus(NodeHealthStatus.newInstance(true, "", 0));
  beatRequest.setNodeStatus(ns);
  NodeHeartbeatResponse beatResponse =
      rm.getResourceTrackerService().nodeHeartbeat(beatRequest);
  if (! beatResponse.getContainersToCleanup().isEmpty()) {
    // remove from queue
    synchronized(releasedContainerList) {
      for (ContainerId containerId : beatResponse.getContainersToCleanup()){
        if (amContainerList.contains(containerId)) {
          // AM container (not killed?, only release)
          synchronized(amContainerList) {
            amContainerList.remove(containerId);
          }
          LOG.debug(MessageFormat.format("NodeManager {0} releases " +
              "an AM ({1}).", node.getNodeID(), containerId));
        } else {
          cs = runningContainers.remove(containerId);
          containerQueue.remove(cs);
          releasedContainerList.add(containerId);
          LOG.debug(MessageFormat.format("NodeManager {0} releases a " +
              "container ({1}).", node.getNodeID(), containerId));
        }
      }
    }
  }
  if (beatResponse.getNodeAction() == NodeAction.SHUTDOWN) {
    lastStep();
  }
}