Search in sources :

Example 6 with NodeHeartbeatRequest

use of org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest in project hadoop by apache.

the class TestResourceTrackerService method testNodeHeartbeatWithCentralLabelConfig.

@Test
public void testNodeHeartbeatWithCentralLabelConfig() throws Exception {
    writeToHostsFile("host2");
    Configuration conf = new Configuration();
    conf.set(YarnConfiguration.RM_NODES_INCLUDE_FILE_PATH, hostFile.getAbsolutePath());
    conf.set(YarnConfiguration.NODELABEL_CONFIGURATION_TYPE, YarnConfiguration.DEFAULT_NODELABEL_CONFIGURATION_TYPE);
    final RMNodeLabelsManager nodeLabelsMgr = new NullRMNodeLabelsManager();
    rm = new MockRM(conf) {

        @Override
        protected RMNodeLabelsManager createNodeLabelManager() {
            return nodeLabelsMgr;
        }
    };
    rm.start();
    ResourceTrackerService resourceTrackerService = rm.getResourceTrackerService();
    RegisterNodeManagerRequest req = Records.newRecord(RegisterNodeManagerRequest.class);
    NodeId nodeId = NodeId.newInstance("host2", 1234);
    Resource capability = BuilderUtils.newResource(1024, 1);
    req.setResource(capability);
    req.setNodeId(nodeId);
    req.setHttpPort(1234);
    req.setNMVersion(YarnVersionInfo.getVersion());
    req.setNodeLabels(toNodeLabelSet("A", "B", "C"));
    RegisterNodeManagerResponse registerResponse = resourceTrackerService.registerNodeManager(req);
    NodeHeartbeatRequest heartbeatReq = Records.newRecord(NodeHeartbeatRequest.class);
    // Valid heart beat labels
    heartbeatReq.setNodeLabels(toNodeLabelSet("B"));
    heartbeatReq.setNodeStatus(getNodeStatusObject(nodeId));
    heartbeatReq.setLastKnownNMTokenMasterKey(registerResponse.getNMTokenMasterKey());
    heartbeatReq.setLastKnownContainerTokenMasterKey(registerResponse.getContainerTokenMasterKey());
    NodeHeartbeatResponse nodeHeartbeatResponse = resourceTrackerService.nodeHeartbeat(heartbeatReq);
    // response should be ok but the RMacceptNodeLabelsUpdate should be false
    Assert.assertEquals(NodeAction.NORMAL, nodeHeartbeatResponse.getNodeAction());
    // no change in the labels,
    Assert.assertNull(nodeLabelsMgr.getNodeLabels().get(nodeId));
    // heartbeat labels rejected
    Assert.assertFalse("Invalid Node Labels should not accepted by RM", nodeHeartbeatResponse.getAreNodeLabelsAcceptedByRM());
    if (rm != null) {
        rm.stop();
    }
}
Also used : UnRegisterNodeManagerRequest(org.apache.hadoop.yarn.server.api.protocolrecords.UnRegisterNodeManagerRequest) RegisterNodeManagerRequest(org.apache.hadoop.yarn.server.api.protocolrecords.RegisterNodeManagerRequest) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) NodeHeartbeatResponse(org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatResponse) NodeId(org.apache.hadoop.yarn.api.records.NodeId) Resource(org.apache.hadoop.yarn.api.records.Resource) RegisterNodeManagerResponse(org.apache.hadoop.yarn.server.api.protocolrecords.RegisterNodeManagerResponse) NodeHeartbeatRequest(org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest) NullRMNodeLabelsManager(org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager) RMNodeLabelsManager(org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager) NullRMNodeLabelsManager(org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager) Test(org.junit.Test)

Example 7 with NodeHeartbeatRequest

use of org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest in project hadoop by apache.

the class TestMiniYarnClusterNodeUtilization method testUpdateNodeUtilization.

/**
   * Simulates a NM heartbeat using the simulated NodeStatus fixture. Verify
   * both the RMNode and SchedulerNode have been updated with the new
   * utilization.
   */
@Test(timeout = 60000)
public void testUpdateNodeUtilization() throws InterruptedException, IOException, YarnException {
    assertTrue("NMs fail to connect to the RM", cluster.waitForNodeManagersToConnect(10000));
    // Simulate heartbeat using NodeStatus fixture
    NodeHeartbeatRequest request = NodeHeartbeatRequest.newInstance(nodeStatus, null, null, null);
    ResourceTracker tracker = ServerRMProxy.createRMProxy(conf, ResourceTracker.class);
    tracker.nodeHeartbeat(request);
    // Give the heartbeat time to propagate to the RM
    verifySimulatedUtilization();
    // Alter utilization
    int responseId = 10;
    nodeStatus = createNodeStatus(nm.getNMContext().getNodeId(), responseId, CONTAINER_PMEM_2, CONTAINER_VMEM_2, CONTAINER_CPU_2, NODE_PMEM_2, NODE_VMEM_2, NODE_CPU_2);
    nm.setNodeStatus(nodeStatus);
    tracker.nodeHeartbeat(request);
    // Give the heartbeat time to propagate to the RM
    verifySimulatedUtilization();
}
Also used : ResourceTracker(org.apache.hadoop.yarn.server.api.ResourceTracker) NodeHeartbeatRequest(org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest) Test(org.junit.Test)

Example 8 with NodeHeartbeatRequest

use of org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest in project hadoop by apache.

the class NodeManager method heartbeat.

public void heartbeat() throws IOException, YarnException {
    NodeStatus nodeStatus = org.apache.hadoop.yarn.server.resourcemanager.NodeManager.createNodeStatus(nodeId, getContainerStatuses(containers));
    nodeStatus.setResponseId(responseID);
    NodeHeartbeatRequest request = recordFactory.newRecordInstance(NodeHeartbeatRequest.class);
    request.setNodeStatus(nodeStatus);
    NodeHeartbeatResponse response = resourceTrackerService.nodeHeartbeat(request);
    responseID = response.getResponseId();
}
Also used : NodeHeartbeatResponse(org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatResponse) NodeHeartbeatRequest(org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest) NodeStatus(org.apache.hadoop.yarn.server.api.records.NodeStatus)

Example 9 with NodeHeartbeatRequest

use of org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest in project hadoop by apache.

the class MockNM method nodeHeartbeat.

public NodeHeartbeatResponse nodeHeartbeat(List<ContainerStatus> updatedStats, List<Container> increasedConts, boolean isHealthy, int resId) throws Exception {
    NodeHeartbeatRequest req = Records.newRecord(NodeHeartbeatRequest.class);
    NodeStatus status = Records.newRecord(NodeStatus.class);
    status.setResponseId(resId);
    status.setNodeId(nodeId);
    ArrayList<ContainerId> completedContainers = new ArrayList<ContainerId>();
    for (ContainerStatus stat : updatedStats) {
        if (stat.getState() == ContainerState.COMPLETE) {
            completedContainers.add(stat.getContainerId());
        }
        containerStats.put(stat.getContainerId(), stat);
    }
    status.setContainersStatuses(new ArrayList<ContainerStatus>(containerStats.values()));
    for (ContainerId cid : completedContainers) {
        containerStats.remove(cid);
    }
    status.setIncreasedContainers(increasedConts);
    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;
    }
    Resource newResource = heartbeatResponse.getResource();
    if (newResource != null) {
        memory = newResource.getMemorySize();
        vCores = newResource.getVirtualCores();
    }
    return heartbeatResponse;
}
Also used : NMContainerStatus(org.apache.hadoop.yarn.server.api.protocolrecords.NMContainerStatus) ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) NodeHeartbeatResponse(org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatResponse) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) MasterKey(org.apache.hadoop.yarn.server.api.records.MasterKey) NodeHeartbeatRequest(org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest) ArrayList(java.util.ArrayList) Resource(org.apache.hadoop.yarn.api.records.Resource) NodeStatus(org.apache.hadoop.yarn.server.api.records.NodeStatus) NodeHealthStatus(org.apache.hadoop.yarn.server.api.records.NodeHealthStatus)

Example 10 with NodeHeartbeatRequest

use of org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest in project hadoop by apache.

the class TestResourceTrackerOnHA method testResourceTrackerOnHA.

@Test(timeout = 15000)
public void testResourceTrackerOnHA() throws Exception {
    NodeId nodeId = NodeId.newInstance("localhost", 0);
    Resource resource = Resource.newInstance(2048, 4);
    // make sure registerNodeManager works when failover happens
    RegisterNodeManagerRequest request = RegisterNodeManagerRequest.newInstance(nodeId, 0, resource, YarnVersionInfo.getVersion(), null, null);
    resourceTracker.registerNodeManager(request);
    Assert.assertTrue(waitForNodeManagerToConnect(10000, nodeId));
    // restart the failover thread, and make sure nodeHeartbeat works
    failoverThread = createAndStartFailoverThread();
    NodeStatus status = NodeStatus.newInstance(NodeId.newInstance("localhost", 0), 0, null, null, null, null, null, null);
    NodeHeartbeatRequest request2 = NodeHeartbeatRequest.newInstance(status, null, null, null);
    resourceTracker.nodeHeartbeat(request2);
}
Also used : RegisterNodeManagerRequest(org.apache.hadoop.yarn.server.api.protocolrecords.RegisterNodeManagerRequest) NodeId(org.apache.hadoop.yarn.api.records.NodeId) Resource(org.apache.hadoop.yarn.api.records.Resource) NodeHeartbeatRequest(org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest) NodeStatus(org.apache.hadoop.yarn.server.api.records.NodeStatus) Test(org.junit.Test)

Aggregations

NodeHeartbeatRequest (org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest)12 Test (org.junit.Test)9 NodeHeartbeatResponse (org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatResponse)7 Resource (org.apache.hadoop.yarn.api.records.Resource)6 RegisterNodeManagerRequest (org.apache.hadoop.yarn.server.api.protocolrecords.RegisterNodeManagerRequest)6 NodeStatus (org.apache.hadoop.yarn.server.api.records.NodeStatus)5 NodeId (org.apache.hadoop.yarn.api.records.NodeId)4 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)4 Configuration (org.apache.hadoop.conf.Configuration)3 RegisterNodeManagerResponse (org.apache.hadoop.yarn.server.api.protocolrecords.RegisterNodeManagerResponse)3 UnRegisterNodeManagerRequest (org.apache.hadoop.yarn.server.api.protocolrecords.UnRegisterNodeManagerRequest)3 NullRMNodeLabelsManager (org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager)3 RMNodeLabelsManager (org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager)3 IOException (java.io.IOException)2 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2 ContainerStatus (org.apache.hadoop.yarn.api.records.ContainerStatus)2 NMContainerStatus (org.apache.hadoop.yarn.server.api.protocolrecords.NMContainerStatus)2 NodeHealthStatus (org.apache.hadoop.yarn.server.api.records.NodeHealthStatus)2 ArrayList (java.util.ArrayList)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1