Java Code Examples for org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse#newInstance()

The following examples show how to use org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse#newInstance() . 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: TestAllocateResponse.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testAllocateResponseWithoutIncDecContainers() {
  AllocateResponse r =
      AllocateResponse.newInstance(3, new ArrayList<ContainerStatus>(),
          new ArrayList<Container>(), new ArrayList<NodeReport>(), null,
          AMCommand.AM_RESYNC, 3, null, new ArrayList<NMToken>(), null, null);

  // serde
  AllocateResponseProto p = ((AllocateResponsePBImpl) r).getProto();
  r = new AllocateResponsePBImpl(p);

  // check value
  Assert.assertEquals(0, r.getIncreasedContainers().size());
  Assert.assertEquals(0, r.getDecreasedContainers().size());
}
 
Example 2
Source File: TestLocalContainerAllocator.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public AllocateResponse allocate(AllocateRequest request)
    throws YarnException, IOException {
  Assert.assertEquals("response ID mismatch",
      responseId, request.getResponseId());
  ++responseId;
  org.apache.hadoop.yarn.api.records.Token yarnToken = null;
  if (amToken != null) {
    yarnToken = org.apache.hadoop.yarn.api.records.Token.newInstance(
        amToken.getIdentifier(), amToken.getKind().toString(),
        amToken.getPassword(), amToken.getService().toString());
  }
  return AllocateResponse.newInstance(responseId,
      Collections.<ContainerStatus>emptyList(),
      Collections.<Container>emptyList(),
      Collections.<NodeReport>emptyList(),
      Resources.none(), null, 1, null,
      Collections.<NMToken>emptyList(),
      yarnToken,
      Collections.<ContainerResourceIncrease>emptyList(),
      Collections.<ContainerResourceDecrease>emptyList());
}
 
Example 3
Source File: TestRMContainerAllocator.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public AllocateResponse allocate(AllocateRequest request)
    throws YarnException, IOException {
  lastAsk = request.getAskList();
  for (ResourceRequest req : lastAsk) {
    if (ResourceRequest.ANY.equals(req.getResourceName())) {
      Priority priority = req.getPriority();
      if (priority.equals(RMContainerAllocator.PRIORITY_MAP)) {
        lastAnyAskMap = req.getNumContainers();
      } else if (priority.equals(RMContainerAllocator.PRIORITY_REDUCE)){
        lastAnyAskReduce = req.getNumContainers();
      }
    }
  }
  AllocateResponse response =  AllocateResponse.newInstance(
      request.getResponseId(),
      containersToComplete, containersToAllocate,
      Collections.<NodeReport>emptyList(),
      Resource.newInstance(512000, 1024, 1024), null, 10, null,
      Collections.<NMToken>emptyList());
  containersToComplete.clear();
  containersToAllocate.clear();
  return response;
}
 
Example 4
Source File: TestAllocateResponse.java    From big-c with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testAllocateResponseWithoutIncDecContainers() {
  AllocateResponse r =
      AllocateResponse.newInstance(3, new ArrayList<ContainerStatus>(),
          new ArrayList<Container>(), new ArrayList<NodeReport>(), null,
          AMCommand.AM_RESYNC, 3, null, new ArrayList<NMToken>(), null, null);

  // serde
  AllocateResponseProto p = ((AllocateResponsePBImpl) r).getProto();
  r = new AllocateResponsePBImpl(p);

  // check value
  Assert.assertEquals(0, r.getIncreasedContainers().size());
  Assert.assertEquals(0, r.getDecreasedContainers().size());
}
 
Example 5
Source File: TestLocalContainerAllocator.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public AllocateResponse allocate(AllocateRequest request)
    throws YarnException, IOException {
  Assert.assertEquals("response ID mismatch",
      responseId, request.getResponseId());
  ++responseId;
  org.apache.hadoop.yarn.api.records.Token yarnToken = null;
  if (amToken != null) {
    yarnToken = org.apache.hadoop.yarn.api.records.Token.newInstance(
        amToken.getIdentifier(), amToken.getKind().toString(),
        amToken.getPassword(), amToken.getService().toString());
  }
  return AllocateResponse.newInstance(responseId,
      Collections.<ContainerStatus>emptyList(),
      Collections.<Container>emptyList(),
      Collections.<NodeReport>emptyList(),
      Resources.none(), null, 1, null,
      Collections.<NMToken>emptyList(),
      yarnToken,
      Collections.<ContainerResourceIncrease>emptyList(),
      Collections.<ContainerResourceDecrease>emptyList());
}
 
Example 6
Source File: TestRMContainerAllocator.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public AllocateResponse allocate(AllocateRequest request)
    throws YarnException, IOException {
  lastAsk = request.getAskList();
  for (ResourceRequest req : lastAsk) {
    if (ResourceRequest.ANY.equals(req.getResourceName())) {
      Priority priority = req.getPriority();
      if (priority.equals(RMContainerAllocator.PRIORITY_MAP)) {
        lastAnyAskMap = req.getNumContainers();
      } else if (priority.equals(RMContainerAllocator.PRIORITY_REDUCE)){
        lastAnyAskReduce = req.getNumContainers();
      }
    }
  }
  AllocateResponse response =  AllocateResponse.newInstance(
      request.getResponseId(),
      containersToComplete, containersToAllocate,
      Collections.<NodeReport>emptyList(),
      Resource.newInstance(512000, 1024), null, 10, null,
      Collections.<NMToken>emptyList());
  containersToComplete.clear();
  containersToAllocate.clear();
  return response;
}
 
Example 7
Source File: ProtocolHATestBase.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public AllocateResponse createFakeAllocateResponse() {
  return AllocateResponse.newInstance(-1,
      new ArrayList<ContainerStatus>(),
      new ArrayList<Container>(), new ArrayList<NodeReport>(),
      Resource.newInstance(1024, 2, 2), null, 1,
      null, new ArrayList<NMToken>());
}
 
Example 8
Source File: TestAMRMClientAsync.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private AllocateResponse createAllocateResponse(
    List<ContainerStatus> completed, List<Container> allocated,
    List<NMToken> nmTokens) {
  AllocateResponse response =
      AllocateResponse.newInstance(0, completed, allocated,
          new ArrayList<NodeReport>(), null, null, 1, null, nmTokens);
  return response;
}
 
Example 9
Source File: ProtocolHATestBase.java    From big-c with Apache License 2.0 5 votes vote down vote up
public AllocateResponse createFakeAllocateResponse() {
  return AllocateResponse.newInstance(-1,
      new ArrayList<ContainerStatus>(),
      new ArrayList<Container>(), new ArrayList<NodeReport>(),
      Resource.newInstance(1024, 2), null, 1,
      null, new ArrayList<NMToken>());
}
 
Example 10
Source File: TestAMRMClientAsync.java    From big-c with Apache License 2.0 5 votes vote down vote up
private AllocateResponse createAllocateResponse(
    List<ContainerStatus> completed, List<Container> allocated,
    List<NMToken> nmTokens) {
  AllocateResponse response =
      AllocateResponse.newInstance(0, completed, allocated,
          new ArrayList<NodeReport>(), null, null, 1, null, nmTokens);
  return response;
}
 
Example 11
Source File: TestAllocateResponse.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testAllocateResponseWithIncDecContainers() {
  List<ContainerResourceIncrease> incContainers =
      new ArrayList<ContainerResourceIncrease>();
  List<ContainerResourceDecrease> decContainers =
      new ArrayList<ContainerResourceDecrease>();
  for (int i = 0; i < 3; i++) {
    incContainers.add(ContainerResourceIncrease.newInstance(null,
        Resource.newInstance(1024, i), null));
  }
  for (int i = 0; i < 5; i++) {
    decContainers.add(ContainerResourceDecrease.newInstance(null,
        Resource.newInstance(1024, i)));
  }

  AllocateResponse r =
      AllocateResponse.newInstance(3, new ArrayList<ContainerStatus>(),
          new ArrayList<Container>(), new ArrayList<NodeReport>(), null,
          AMCommand.AM_RESYNC, 3, null, new ArrayList<NMToken>(),
          incContainers, decContainers);

  // serde
  AllocateResponseProto p = ((AllocateResponsePBImpl) r).getProto();
  r = new AllocateResponsePBImpl(p);

  // check value
  Assert
      .assertEquals(incContainers.size(), r.getIncreasedContainers().size());
  Assert
      .assertEquals(decContainers.size(), r.getDecreasedContainers().size());

  for (int i = 0; i < incContainers.size(); i++) {
    Assert.assertEquals(i, r.getIncreasedContainers().get(i).getCapability()
        .getVirtualCores());
  }

  for (int i = 0; i < decContainers.size(); i++) {
    Assert.assertEquals(i, r.getDecreasedContainers().get(i).getCapability()
        .getVirtualCores());
  }
}
 
Example 12
Source File: TestAllocateResponse.java    From big-c with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testAllocateResponseWithIncDecContainers() {
  List<ContainerResourceIncrease> incContainers =
      new ArrayList<ContainerResourceIncrease>();
  List<ContainerResourceDecrease> decContainers =
      new ArrayList<ContainerResourceDecrease>();
  for (int i = 0; i < 3; i++) {
    incContainers.add(ContainerResourceIncrease.newInstance(null,
        Resource.newInstance(1024, i), null));
  }
  for (int i = 0; i < 5; i++) {
    decContainers.add(ContainerResourceDecrease.newInstance(null,
        Resource.newInstance(1024, i)));
  }

  AllocateResponse r =
      AllocateResponse.newInstance(3, new ArrayList<ContainerStatus>(),
          new ArrayList<Container>(), new ArrayList<NodeReport>(), null,
          AMCommand.AM_RESYNC, 3, null, new ArrayList<NMToken>(),
          incContainers, decContainers);

  // serde
  AllocateResponseProto p = ((AllocateResponsePBImpl) r).getProto();
  r = new AllocateResponsePBImpl(p);

  // check value
  Assert
      .assertEquals(incContainers.size(), r.getIncreasedContainers().size());
  Assert
      .assertEquals(decContainers.size(), r.getDecreasedContainers().size());

  for (int i = 0; i < incContainers.size(); i++) {
    Assert.assertEquals(i, r.getIncreasedContainers().get(i).getCapability()
        .getVirtualCores());
  }

  for (int i = 0; i < decContainers.size(); i++) {
    Assert.assertEquals(i, r.getDecreasedContainers().get(i).getCapability()
        .getVirtualCores());
  }
}