Search in sources :

Example 16 with ApplicationClientProtocol

use of org.apache.hadoop.yarn.api.ApplicationClientProtocol 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 17 with ApplicationClientProtocol

use of org.apache.hadoop.yarn.api.ApplicationClientProtocol in project hadoop by apache.

the class TestApplicationPriorityACLs method submitAppToRMWithValidAcl.

private void submitAppToRMWithValidAcl(String submitter, ApplicationSubmissionContext appSubmissionContext) throws YarnException, IOException, InterruptedException {
    ApplicationClientProtocol submitterClient = getRMClientForUser(submitter);
    SubmitApplicationRequest submitRequest = SubmitApplicationRequest.newInstance(appSubmissionContext);
    submitterClient.submitApplication(submitRequest);
    resourceManager.waitForState(appSubmissionContext.getApplicationId(), RMAppState.ACCEPTED);
}
Also used : ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) SubmitApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest)

Example 18 with ApplicationClientProtocol

use of org.apache.hadoop.yarn.api.ApplicationClientProtocol in project hadoop by apache.

the class TestApplicationPriorityACLs method submitAppToRMWithInValidAcl.

private void submitAppToRMWithInValidAcl(String submitter, ApplicationSubmissionContext appSubmissionContext) throws YarnException, IOException, InterruptedException {
    ApplicationClientProtocol submitterClient = getRMClientForUser(submitter);
    SubmitApplicationRequest submitRequest = SubmitApplicationRequest.newInstance(appSubmissionContext);
    try {
        submitterClient.submitApplication(submitRequest);
    } catch (YarnException ex) {
        Assert.assertTrue(ex.getCause() instanceof RemoteException);
    }
}
Also used : RemoteException(org.apache.hadoop.ipc.RemoteException) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) SubmitApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 19 with ApplicationClientProtocol

use of org.apache.hadoop.yarn.api.ApplicationClientProtocol in project hadoop by apache.

the class TestApplicationPriorityACLs method prepareForAppSubmission.

private ApplicationSubmissionContext prepareForAppSubmission(String submitter, String queueName, Priority priority) throws Exception {
    GetNewApplicationRequest newAppRequest = GetNewApplicationRequest.newInstance();
    ApplicationClientProtocol submitterClient = getRMClientForUser(submitter);
    ApplicationId applicationId = submitterClient.getNewApplication(newAppRequest).getApplicationId();
    Resource resource = BuilderUtils.newResource(1024, 1);
    ContainerLaunchContext amContainerSpec = ContainerLaunchContext.newInstance(null, null, null, null, null, null);
    ApplicationSubmissionContext appSubmissionContext = ApplicationSubmissionContext.newInstance(applicationId, "applicationName", queueName, null, amContainerSpec, false, true, 1, resource, "applicationType");
    appSubmissionContext.setApplicationId(applicationId);
    appSubmissionContext.setQueue(queueName);
    if (null != priority) {
        appSubmissionContext.setPriority(priority);
    }
    return appSubmissionContext;
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource) ApplicationSubmissionContext(org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) GetNewApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest)

Example 20 with ApplicationClientProtocol

use of org.apache.hadoop.yarn.api.ApplicationClientProtocol in project hive by apache.

the class WebHCatJTShim23 method getYarnChildJobs.

/**
   * Queries RM for the list of applications with the given tag that have started
   * after the given timestamp.
   */
private Set<ApplicationId> getYarnChildJobs(String tag, long timestamp) {
    Set<ApplicationId> childYarnJobs = new HashSet<ApplicationId>();
    LOG.info(String.format("Querying RM for tag = %s, starting with ts = %s", tag, timestamp));
    GetApplicationsRequest gar = GetApplicationsRequest.newInstance();
    gar.setScope(ApplicationsRequestScope.OWN);
    gar.setStartRange(timestamp, System.currentTimeMillis());
    gar.setApplicationTags(Collections.singleton(tag));
    try {
        ApplicationClientProtocol proxy = ClientRMProxy.createRMProxy(conf, ApplicationClientProtocol.class);
        GetApplicationsResponse apps = proxy.getApplications(gar);
        List<ApplicationReport> appsList = apps.getApplicationList();
        for (ApplicationReport appReport : appsList) {
            childYarnJobs.add(appReport.getApplicationId());
        }
    } catch (IOException ioe) {
        throw new RuntimeException("Exception occurred while finding child jobs", ioe);
    } catch (YarnException ye) {
        throw new RuntimeException("Exception occurred while finding child jobs", ye);
    }
    return childYarnJobs;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) GetApplicationsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) GetApplicationsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) HashSet(java.util.HashSet)

Aggregations

ApplicationClientProtocol (org.apache.hadoop.yarn.api.ApplicationClientProtocol)42 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)12 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)12 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)11 Test (org.junit.Test)11 IOException (java.io.IOException)9 GetApplicationReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest)8 KillApplicationRequest (org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest)8 Configuration (org.apache.hadoop.conf.Configuration)7 GetNewApplicationRequest (org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest)7 YarnRPC (org.apache.hadoop.yarn.ipc.YarnRPC)7 InetSocketAddress (java.net.InetSocketAddress)6 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)6 AccessControlList (org.apache.hadoop.security.authorize.AccessControlList)5 GetApplicationReportResponse (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse)5 HashSet (java.util.HashSet)4 SubmitApplicationRequest (org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 EnumSet (java.util.EnumSet)3 HashMap (java.util.HashMap)3