Search in sources :

Example 1 with GetTimelineCollectorContextRequest

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

the class TestRPC method testRPCOnCollectorNodeManagerProtocol.

@Test
public void testRPCOnCollectorNodeManagerProtocol() throws IOException {
    Configuration conf = new Configuration();
    conf.set(YarnConfiguration.IPC_RPC_IMPL, HadoopYarnProtoRPC.class.getName());
    YarnRPC rpc = YarnRPC.create(conf);
    String bindAddr = "localhost:0";
    InetSocketAddress addr = NetUtils.createSocketAddr(bindAddr);
    Server server = rpc.getServer(CollectorNodemanagerProtocol.class, new DummyNMCollectorService(), addr, conf, null, 1);
    server.start();
    // Test unrelated protocol wouldn't get response
    ApplicationClientProtocol unknownProxy = (ApplicationClientProtocol) rpc.getProxy(ApplicationClientProtocol.class, NetUtils.getConnectAddress(server), conf);
    try {
        unknownProxy.getNewApplication(Records.newRecord(GetNewApplicationRequest.class));
        Assert.fail("Excepted RPC call to fail with unknown method.");
    } catch (YarnException e) {
        Assert.assertTrue(e.getMessage().matches("Unknown method getNewApplication called on.*" + "org.apache.hadoop.yarn.proto.ApplicationClientProtocol" + "\\$ApplicationClientProtocolService\\$BlockingInterface " + "protocol."));
    } catch (Exception e) {
        e.printStackTrace();
    }
    // Test CollectorNodemanagerProtocol get proper response
    CollectorNodemanagerProtocol proxy = (CollectorNodemanagerProtocol) rpc.getProxy(CollectorNodemanagerProtocol.class, NetUtils.getConnectAddress(server), conf);
    // normally response.
    try {
        ReportNewCollectorInfoRequest request = ReportNewCollectorInfoRequest.newInstance(DEFAULT_APP_ID, DEFAULT_COLLECTOR_ADDR);
        proxy.reportNewCollectorInfo(request);
    } catch (YarnException e) {
        Assert.fail("RPC call failured is not expected here.");
    }
    // DummyNMCollectorService)
    try {
        proxy.reportNewCollectorInfo(Records.newRecord(ReportNewCollectorInfoRequest.class));
        Assert.fail("Excepted RPC call to fail with YarnException.");
    } catch (YarnException e) {
        Assert.assertTrue(e.getMessage().contains(ILLEGAL_NUMBER_MESSAGE));
    }
    // Verify request with a valid app ID
    try {
        GetTimelineCollectorContextRequest request = GetTimelineCollectorContextRequest.newInstance(ApplicationId.newInstance(0, 1));
        GetTimelineCollectorContextResponse response = proxy.getTimelineCollectorContext(request);
        Assert.assertEquals("test_user_id", response.getUserId());
        Assert.assertEquals("test_flow_name", response.getFlowName());
        Assert.assertEquals("test_flow_version", response.getFlowVersion());
        Assert.assertEquals(12345678L, response.getFlowRunId());
    } catch (YarnException | IOException e) {
        Assert.fail("RPC call failured is not expected here.");
    }
    // Verify request with an invalid app ID
    try {
        GetTimelineCollectorContextRequest request = GetTimelineCollectorContextRequest.newInstance(ApplicationId.newInstance(0, 2));
        proxy.getTimelineCollectorContext(request);
        Assert.fail("RPC call failured is expected here.");
    } catch (YarnException | IOException e) {
        Assert.assertTrue(e instanceof YarnException);
        Assert.assertTrue(e.getMessage().contains("The application is not found."));
    }
    server.stop();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Server(org.apache.hadoop.ipc.Server) CollectorNodemanagerProtocol(org.apache.hadoop.yarn.server.api.CollectorNodemanagerProtocol) GetTimelineCollectorContextRequest(org.apache.hadoop.yarn.server.api.protocolrecords.GetTimelineCollectorContextRequest) InetSocketAddress(java.net.InetSocketAddress) ReportNewCollectorInfoRequest(org.apache.hadoop.yarn.server.api.protocolrecords.ReportNewCollectorInfoRequest) YarnRPC(org.apache.hadoop.yarn.ipc.YarnRPC) IOException(java.io.IOException) HadoopYarnProtoRPC(org.apache.hadoop.yarn.ipc.HadoopYarnProtoRPC) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) GetNewApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest) GetTimelineCollectorContextResponse(org.apache.hadoop.yarn.server.api.protocolrecords.GetTimelineCollectorContextResponse) Test(org.junit.Test)

Example 2 with GetTimelineCollectorContextRequest

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

the class NodeTimelineCollectorManager method updateTimelineCollectorContext.

private void updateTimelineCollectorContext(ApplicationId appId, TimelineCollector collector) throws YarnException, IOException {
    GetTimelineCollectorContextRequest request = GetTimelineCollectorContextRequest.newInstance(appId);
    LOG.info("Get timeline collector context for " + appId);
    GetTimelineCollectorContextResponse response = getNMCollectorService().getTimelineCollectorContext(request);
    String userId = response.getUserId();
    if (userId != null && !userId.isEmpty()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Setting the user in the context: " + userId);
        }
        collector.getTimelineEntityContext().setUserId(userId);
    }
    String flowName = response.getFlowName();
    if (flowName != null && !flowName.isEmpty()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Setting the flow name: " + flowName);
        }
        collector.getTimelineEntityContext().setFlowName(flowName);
    }
    String flowVersion = response.getFlowVersion();
    if (flowVersion != null && !flowVersion.isEmpty()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Setting the flow version: " + flowVersion);
        }
        collector.getTimelineEntityContext().setFlowVersion(flowVersion);
    }
    long flowRunId = response.getFlowRunId();
    if (flowRunId != 0L) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Setting the flow run id: " + flowRunId);
        }
        collector.getTimelineEntityContext().setFlowRunId(flowRunId);
    }
}
Also used : GetTimelineCollectorContextRequest(org.apache.hadoop.yarn.server.api.protocolrecords.GetTimelineCollectorContextRequest) GetTimelineCollectorContextResponse(org.apache.hadoop.yarn.server.api.protocolrecords.GetTimelineCollectorContextResponse)

Aggregations

GetTimelineCollectorContextRequest (org.apache.hadoop.yarn.server.api.protocolrecords.GetTimelineCollectorContextRequest)2 GetTimelineCollectorContextResponse (org.apache.hadoop.yarn.server.api.protocolrecords.GetTimelineCollectorContextResponse)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Configuration (org.apache.hadoop.conf.Configuration)1 Server (org.apache.hadoop.ipc.Server)1 ApplicationClientProtocol (org.apache.hadoop.yarn.api.ApplicationClientProtocol)1 GetNewApplicationRequest (org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 HadoopYarnProtoRPC (org.apache.hadoop.yarn.ipc.HadoopYarnProtoRPC)1 YarnRPC (org.apache.hadoop.yarn.ipc.YarnRPC)1 CollectorNodemanagerProtocol (org.apache.hadoop.yarn.server.api.CollectorNodemanagerProtocol)1 ReportNewCollectorInfoRequest (org.apache.hadoop.yarn.server.api.protocolrecords.ReportNewCollectorInfoRequest)1 Test (org.junit.Test)1