Search in sources :

Example 6 with ResourceTracker

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

the class TestNodeStatusUpdaterForLabels method testNodeStatusUpdaterForNodeLabels.

@Test(timeout = 20000)
public void testNodeStatusUpdaterForNodeLabels() throws InterruptedException, IOException {
    final ResourceTrackerForLabels resourceTracker = new ResourceTrackerForLabels();
    nm = new NodeManager() {

        @Override
        protected NodeLabelsProvider createNodeLabelsProvider(Configuration conf) throws IOException {
            return dummyLabelsProviderRef;
        }

        @Override
        protected NodeStatusUpdater createNodeStatusUpdater(Context context, Dispatcher dispatcher, NodeHealthCheckerService healthChecker, NodeLabelsProvider labelsProvider) {
            return new NodeStatusUpdaterImpl(context, dispatcher, healthChecker, metrics, labelsProvider) {

                @Override
                protected ResourceTracker getRMClient() {
                    return resourceTracker;
                }

                @Override
                protected void stopRMProxy() {
                    return;
                }
            };
        }
    };
    YarnConfiguration conf = createNMConfigForDistributeNodeLabels();
    conf.setLong(YarnConfiguration.NM_NODE_LABELS_RESYNC_INTERVAL, 2000);
    conf.set(YarnConfiguration.NM_LOCALIZER_ADDRESS, "0.0.0.0:" + ServerSocketUtil.getPort(8040, 10));
    nm.init(conf);
    resourceTracker.resetNMHeartbeatReceiveFlag();
    nm.start();
    resourceTracker.waitTillRegister();
    assertNLCollectionEquals(dummyLabelsProviderRef.getNodeLabels(), resourceTracker.labels);
    // wait till the first heartbeat
    resourceTracker.waitTillHeartbeat();
    resourceTracker.resetNMHeartbeatReceiveFlag();
    // heartbeat with updated labels
    dummyLabelsProviderRef.setNodeLabels(toNodeLabelSet("P"));
    sendOutofBandHeartBeat();
    resourceTracker.waitTillHeartbeat();
    assertNLCollectionEquals(dummyLabelsProviderRef.getNodeLabels(), resourceTracker.labels);
    resourceTracker.resetNMHeartbeatReceiveFlag();
    // heartbeat without updating labels
    sendOutofBandHeartBeat();
    resourceTracker.waitTillHeartbeat();
    resourceTracker.resetNMHeartbeatReceiveFlag();
    assertNull("If no change in labels then null should be sent as part of request", resourceTracker.labels);
    // provider return with null labels
    dummyLabelsProviderRef.setNodeLabels(null);
    sendOutofBandHeartBeat();
    resourceTracker.waitTillHeartbeat();
    assertNotNull("If provider sends null then empty label set should be sent and not null", resourceTracker.labels);
    assertTrue("If provider sends null then empty labels should be sent", resourceTracker.labels.isEmpty());
    resourceTracker.resetNMHeartbeatReceiveFlag();
    // Since the resync interval is set to 2 sec in every alternate heartbeat
    // the labels will be send along with heartbeat.In loop we sleep for 1 sec
    // so that every sec 1 heartbeat is send.
    int nullLabels = 0;
    int nonNullLabels = 0;
    dummyLabelsProviderRef.setNodeLabels(toNodeLabelSet("P1"));
    for (int i = 0; i < 5; i++) {
        sendOutofBandHeartBeat();
        resourceTracker.waitTillHeartbeat();
        if (null == resourceTracker.labels) {
            nullLabels++;
        } else {
            Assert.assertEquals("In heartbeat PI labels should be send", toNodeLabelSet("P1"), resourceTracker.labels);
            nonNullLabels++;
        }
        resourceTracker.resetNMHeartbeatReceiveFlag();
        Thread.sleep(1000);
    }
    Assert.assertTrue("More than one heartbeat with empty labels expected", nullLabels > 1);
    Assert.assertTrue("More than one heartbeat with labels expected", nonNullLabels > 1);
    nm.stop();
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) NodeLabelsProvider(org.apache.hadoop.yarn.server.nodemanager.nodelabels.NodeLabelsProvider) ResourceTracker(org.apache.hadoop.yarn.server.api.ResourceTracker) IOException(java.io.IOException) Dispatcher(org.apache.hadoop.yarn.event.Dispatcher) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Test(org.junit.Test)

Aggregations

ResourceTracker (org.apache.hadoop.yarn.server.api.ResourceTracker)6 Configuration (org.apache.hadoop.conf.Configuration)5 InetSocketAddress (java.net.InetSocketAddress)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 Server (org.apache.hadoop.ipc.Server)2 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)2 Dispatcher (org.apache.hadoop.yarn.event.Dispatcher)2 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)2 NodeLabelsProvider (org.apache.hadoop.yarn.server.nodemanager.nodelabels.NodeLabelsProvider)2 NodeHeartbeatRequest (org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest)1 BeforeClass (org.junit.BeforeClass)1