Hi,
I am trying to allocate containers on a particular node in Yarn but Yarn is returning me containers on different node although the requested node has resources available.

I checked into the allocate(AllocateRequest request) function of ApplicationMasterService and my request is as follows

/request: ask { priority { priority: 1 } resource_name: "h2" capability { memory: 1000 } num_containers: 2 } ask { priority { priority: 1 } resource_name: "/default-rack" capability { memory: 1000 } num_containers: 2 } ask { priority { priority: 1 } resource_name: "*" capability { memory: 1000 } num_containers: 2 } response_id: 1 progress: 0.0/

but the containers that I am getting back is as follows
[Container: [ContainerId: container_1384381084244_0001_01_000002, NodeId: h1:1234, NodeHttpAddress: h1:2, Resource: <memory:1024, vCores:1>, Priority: 1, Token: Token { kind: ContainerToken, service: h1:1234 }, ], Container: [ContainerId: container_1384381084244_0001_01_000003, NodeId: h1:1234, NodeHttpAddress: h1:2, Resource: <memory:1024, vCores:1>, Priority: 1, Token: Token { kind: ContainerToken, service: h1:1234 }, ]]

I am attaching the test case that I have written along with the mail. It uses classes under org.apache.hadoop.yarn.server.resourcemanager package.

Any pointers would be of great help

Thanks
Gaurav




/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.hadoop.yarn.server.resourcemanager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import junit.framework.Assert;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse;
import org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse;
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
import org.apache.hadoop.yarn.api.records.Container;
import org.apache.hadoop.yarn.api.records.ContainerId;
import org.apache.hadoop.yarn.api.records.ContainerState;
import org.apache.hadoop.yarn.api.records.NMToken;
import org.apache.hadoop.yarn.api.records.ResourceRequest;
import org.apache.hadoop.yarn.api.records.Token;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt;
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState;
import org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.junit.Test;

public class TestAllocation {

  private static final Log LOG = LogFactory.getLog(TestAllocation.class);

  
  @Test
  public void testAppOnMultiNode() throws Exception {
    Logger rootLogger = LogManager.getRootLogger();
    rootLogger.setLevel(Level.DEBUG);
    MockRM rm = new MockRM();
    rm.start();
    MockNM nm1 = rm.registerNode("h1:1234", 5120);
    MockNM nm2 = rm.registerNode("h2:5678", 10240);
    
    RMApp app = rm.submitApp(2000);

    //kick the scheduling
    nm1.nodeHeartbeat(true);

    RMAppAttempt attempt = app.getCurrentAppAttempt();
    MockAM am = rm.sendAMLaunched(attempt.getAppAttemptId());
    am.registerAppAttempt();
    
    
    //request for containers
    int request = 2;
    
    List<Container> conts = am.allocate("h2" , 1000, request, new ArrayList<ContainerId>()).getAllocatedContainers();
    
    nm1.nodeHeartbeat(true);
    nm2.nodeHeartbeat(true);
    
    while(conts.size() < 2){
      conts.addAll(am.allocate("h2" , 1000, request, new ArrayList<ContainerId>()).getAllocatedContainers());
      int contReceived = conts.size();
      LOG.info("Got " + contReceived + " containers. Waiting to get " + 2);
      Thread.sleep(2000);
    }
    
    am.unregisterAppAttempt();
    nm1.nodeHeartbeat(attempt.getAppAttemptId(), 1, ContainerState.COMPLETE);
    am.waitForState(RMAppAttemptState.FINISHED);

    rm.stop();
  }
  
  
  public static void main(String[] args) throws Exception {
    TestAllocation t = new TestAllocation();
    //t.testGetNewAppId();
   // t.testAppWithNoContainers();
    t.testAppOnMultiNode();
  }
}



Reply via email to