Java Code Examples for org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.NodeHeartbeatResponsePBImpl

The following examples show how to use org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.NodeHeartbeatResponsePBImpl. These examples are extracted from open source projects. 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 Project: hadoop   Source File: TestYarnServerApiClasses.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test NodeHeartbeatResponsePBImpl.
 */

@Test
public void testNodeHeartbeatResponsePBImpl() {
  NodeHeartbeatResponsePBImpl original = new NodeHeartbeatResponsePBImpl();

  original.setDiagnosticsMessage("testDiagnosticMessage");
  original.setContainerTokenMasterKey(getMasterKey());
  original.setNMTokenMasterKey(getMasterKey());
  original.setNextHeartBeatInterval(1000);
  original.setNodeAction(NodeAction.NORMAL);
  original.setResponseId(100);

  NodeHeartbeatResponsePBImpl copy = new NodeHeartbeatResponsePBImpl(
      original.getProto());
  assertEquals(100, copy.getResponseId());
  assertEquals(NodeAction.NORMAL, copy.getNodeAction());
  assertEquals(1000, copy.getNextHeartBeatInterval());
  assertEquals(1, copy.getContainerTokenMasterKey().getKeyId());
  assertEquals(1, copy.getNMTokenMasterKey().getKeyId());
  assertEquals("testDiagnosticMessage", copy.getDiagnosticsMessage());
}
 
Example 2
Source Project: big-c   Source File: TestYarnServerApiClasses.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test NodeHeartbeatResponsePBImpl.
 */

@Test
public void testNodeHeartbeatResponsePBImpl() {
  NodeHeartbeatResponsePBImpl original = new NodeHeartbeatResponsePBImpl();

  original.setDiagnosticsMessage("testDiagnosticMessage");
  original.setContainerTokenMasterKey(getMasterKey());
  original.setNMTokenMasterKey(getMasterKey());
  original.setNextHeartBeatInterval(1000);
  original.setNodeAction(NodeAction.NORMAL);
  original.setResponseId(100);

  NodeHeartbeatResponsePBImpl copy = new NodeHeartbeatResponsePBImpl(
      original.getProto());
  assertEquals(100, copy.getResponseId());
  assertEquals(NodeAction.NORMAL, copy.getNodeAction());
  assertEquals(1000, copy.getNextHeartBeatInterval());
  assertEquals(1, copy.getContainerTokenMasterKey().getKeyId());
  assertEquals(1, copy.getNMTokenMasterKey().getKeyId());
  assertEquals("testDiagnosticMessage", copy.getDiagnosticsMessage());
}
 
Example 3
Source Project: hadoop   Source File: ResourceTrackerPBClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
    throws YarnException, IOException {
  NodeHeartbeatRequestProto requestProto = ((NodeHeartbeatRequestPBImpl)request).getProto();
  try {
    return new NodeHeartbeatResponsePBImpl(proxy.nodeHeartbeat(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 4
Source Project: hadoop   Source File: TestProtocolRecords.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testNodeHeartBeatResponse() throws IOException {
  NodeHeartbeatResponse record =
      Records.newRecord(NodeHeartbeatResponse.class);
  Map<ApplicationId, ByteBuffer> appCredentials =
      new HashMap<ApplicationId, ByteBuffer>();
  Credentials app1Cred = new Credentials();

  Token<DelegationTokenIdentifier> token1 =
      new Token<DelegationTokenIdentifier>();
  token1.setKind(new Text("kind1"));
  app1Cred.addToken(new Text("token1"), token1);
  Token<DelegationTokenIdentifier> token2 =
      new Token<DelegationTokenIdentifier>();
  token2.setKind(new Text("kind2"));
  app1Cred.addToken(new Text("token2"), token2);

  DataOutputBuffer dob = new DataOutputBuffer();
  app1Cred.writeTokenStorageToStream(dob);
  ByteBuffer byteBuffer1 = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
  appCredentials.put(ApplicationId.newInstance(1234, 1), byteBuffer1);
  record.setSystemCredentialsForApps(appCredentials);

  NodeHeartbeatResponse proto =
      new NodeHeartbeatResponsePBImpl(
        ((NodeHeartbeatResponsePBImpl) record).getProto());
  Assert.assertEquals(appCredentials, proto.getSystemCredentialsForApps());
}
 
Example 5
Source Project: big-c   Source File: ResourceTrackerPBClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
    throws YarnException, IOException {
  NodeHeartbeatRequestProto requestProto = ((NodeHeartbeatRequestPBImpl)request).getProto();
  try {
    return new NodeHeartbeatResponsePBImpl(proxy.nodeHeartbeat(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 6
Source Project: big-c   Source File: TestProtocolRecords.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testNodeHeartBeatResponse() throws IOException {
  NodeHeartbeatResponse record =
      Records.newRecord(NodeHeartbeatResponse.class);
  Map<ApplicationId, ByteBuffer> appCredentials =
      new HashMap<ApplicationId, ByteBuffer>();
  Credentials app1Cred = new Credentials();

  Token<DelegationTokenIdentifier> token1 =
      new Token<DelegationTokenIdentifier>();
  token1.setKind(new Text("kind1"));
  app1Cred.addToken(new Text("token1"), token1);
  Token<DelegationTokenIdentifier> token2 =
      new Token<DelegationTokenIdentifier>();
  token2.setKind(new Text("kind2"));
  app1Cred.addToken(new Text("token2"), token2);

  DataOutputBuffer dob = new DataOutputBuffer();
  app1Cred.writeTokenStorageToStream(dob);
  ByteBuffer byteBuffer1 = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
  appCredentials.put(ApplicationId.newInstance(1234, 1), byteBuffer1);
  record.setSystemCredentialsForApps(appCredentials);

  NodeHeartbeatResponse proto =
      new NodeHeartbeatResponsePBImpl(
        ((NodeHeartbeatResponsePBImpl) record).getProto());
  Assert.assertEquals(appCredentials, proto.getSystemCredentialsForApps());
}
 
Example 7
Source Project: incubator-myriad   Source File: TestObjectFactory.java    License: 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 8
Source Project: incubator-myriad   Source File: NMHeartBeatHandlerTest.java    License: 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 9
Source Project: hadoop   Source File: TestNodeStatusUpdater.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testConcurrentAccessToSystemCredentials(){
  final Map<ApplicationId, ByteBuffer> testCredentials = new HashMap<>();
  ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[300]);
  ApplicationId applicationId = ApplicationId.newInstance(123456, 120);
  testCredentials.put(applicationId, byteBuffer);

  final List<Throwable> exceptions = Collections.synchronizedList(new
      ArrayList<Throwable>());

  final int NUM_THREADS = 10;
  final CountDownLatch allDone = new CountDownLatch(NUM_THREADS);
  final ExecutorService threadPool = Executors.newFixedThreadPool(
      NUM_THREADS);

  final AtomicBoolean stop = new AtomicBoolean(false);

  try {
    for (int i = 0; i < NUM_THREADS; i++) {
      threadPool.submit(new Runnable() {
        @Override
        public void run() {
          try {
            for (int i = 0; i < 100 && !stop.get(); i++) {
              NodeHeartbeatResponse nodeHeartBeatResponse =
                  newNodeHeartbeatResponse(0, NodeAction.NORMAL,
                      null, null, null, null, 0);
              nodeHeartBeatResponse.setSystemCredentialsForApps(
                  testCredentials);
              NodeHeartbeatResponseProto proto =
                  ((NodeHeartbeatResponsePBImpl)nodeHeartBeatResponse)
                      .getProto();
              Assert.assertNotNull(proto);
            }
          } catch (Throwable t) {
            exceptions.add(t);
            stop.set(true);
          } finally {
            allDone.countDown();
          }
        }
      });
    }

    int testTimeout = 2;
    Assert.assertTrue("Timeout waiting for more than " + testTimeout + " " +
            "seconds",
        allDone.await(testTimeout, TimeUnit.SECONDS));
  } catch (InterruptedException ie) {
    exceptions.add(ie);
  } finally {
    threadPool.shutdownNow();
  }
  Assert.assertTrue("Test failed with exception(s)" + exceptions,
      exceptions.isEmpty());
}
 
Example 10
Source Project: big-c   Source File: TestNodeStatusUpdater.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testConcurrentAccessToSystemCredentials(){
  final Map<ApplicationId, ByteBuffer> testCredentials = new HashMap<>();
  ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[300]);
  ApplicationId applicationId = ApplicationId.newInstance(123456, 120);
  testCredentials.put(applicationId, byteBuffer);

  final List<Throwable> exceptions = Collections.synchronizedList(new
      ArrayList<Throwable>());

  final int NUM_THREADS = 10;
  final CountDownLatch allDone = new CountDownLatch(NUM_THREADS);
  final ExecutorService threadPool = Executors.newFixedThreadPool(
      NUM_THREADS);

  final AtomicBoolean stop = new AtomicBoolean(false);

  try {
    for (int i = 0; i < NUM_THREADS; i++) {
      threadPool.submit(new Runnable() {
        @Override
        public void run() {
          try {
            for (int i = 0; i < 100 && !stop.get(); i++) {
              NodeHeartbeatResponse nodeHeartBeatResponse =
                  newNodeHeartbeatResponse(0, NodeAction.NORMAL,null,
                      null, null, null, null, 0);
              nodeHeartBeatResponse.setSystemCredentialsForApps(
                  testCredentials);
              NodeHeartbeatResponseProto proto =
                  ((NodeHeartbeatResponsePBImpl)nodeHeartBeatResponse)
                      .getProto();
              Assert.assertNotNull(proto);
            }
          } catch (Throwable t) {
            exceptions.add(t);
            stop.set(true);
          } finally {
            allDone.countDown();
          }
        }
      });
    }

    int testTimeout = 2;
    Assert.assertTrue("Timeout waiting for more than " + testTimeout + " " +
            "seconds",
        allDone.await(testTimeout, TimeUnit.SECONDS));
  } catch (InterruptedException ie) {
    exceptions.add(ie);
  } finally {
    threadPool.shutdownNow();
  }
  Assert.assertTrue("Test failed with exception(s)" + exceptions,
      exceptions.isEmpty());
}