Search in sources :

Example 1 with YarnClientImpl

use of org.apache.hadoop.yarn.client.api.impl.YarnClientImpl in project hadoop by apache.

the class TestYARNRunner method testResourceMgrDelegate.

@Test(timeout = 20000)
public void testResourceMgrDelegate() throws Exception {
    /* we not want a mock of resource mgr delegate */
    final ApplicationClientProtocol clientRMProtocol = mock(ApplicationClientProtocol.class);
    ResourceMgrDelegate delegate = new ResourceMgrDelegate(conf) {

        @Override
        protected void serviceStart() throws Exception {
            assertTrue(this.client instanceof YarnClientImpl);
            ((YarnClientImpl) this.client).setRMClient(clientRMProtocol);
        }
    };
    /* make sure kill calls finish application master */
    when(clientRMProtocol.forceKillApplication(any(KillApplicationRequest.class))).thenReturn(KillApplicationResponse.newInstance(true));
    delegate.killApplication(appId);
    verify(clientRMProtocol).forceKillApplication(any(KillApplicationRequest.class));
    /* make sure getalljobs calls get all applications */
    when(clientRMProtocol.getApplications(any(GetApplicationsRequest.class))).thenReturn(recordFactory.newRecordInstance(GetApplicationsResponse.class));
    delegate.getAllJobs();
    verify(clientRMProtocol).getApplications(any(GetApplicationsRequest.class));
    /* make sure getapplication report is called */
    when(clientRMProtocol.getApplicationReport(any(GetApplicationReportRequest.class))).thenReturn(recordFactory.newRecordInstance(GetApplicationReportResponse.class));
    delegate.getApplicationReport(appId);
    verify(clientRMProtocol).getApplicationReport(any(GetApplicationReportRequest.class));
    /* make sure metrics is called */
    GetClusterMetricsResponse clusterMetricsResponse = recordFactory.newRecordInstance(GetClusterMetricsResponse.class);
    clusterMetricsResponse.setClusterMetrics(recordFactory.newRecordInstance(YarnClusterMetrics.class));
    when(clientRMProtocol.getClusterMetrics(any(GetClusterMetricsRequest.class))).thenReturn(clusterMetricsResponse);
    delegate.getClusterMetrics();
    verify(clientRMProtocol).getClusterMetrics(any(GetClusterMetricsRequest.class));
    when(clientRMProtocol.getClusterNodes(any(GetClusterNodesRequest.class))).thenReturn(recordFactory.newRecordInstance(GetClusterNodesResponse.class));
    delegate.getActiveTrackers();
    verify(clientRMProtocol).getClusterNodes(any(GetClusterNodesRequest.class));
    GetNewApplicationResponse newAppResponse = recordFactory.newRecordInstance(GetNewApplicationResponse.class);
    newAppResponse.setApplicationId(appId);
    when(clientRMProtocol.getNewApplication(any(GetNewApplicationRequest.class))).thenReturn(newAppResponse);
    delegate.getNewJobID();
    verify(clientRMProtocol).getNewApplication(any(GetNewApplicationRequest.class));
    GetQueueInfoResponse queueInfoResponse = recordFactory.newRecordInstance(GetQueueInfoResponse.class);
    queueInfoResponse.setQueueInfo(recordFactory.newRecordInstance(QueueInfo.class));
    when(clientRMProtocol.getQueueInfo(any(GetQueueInfoRequest.class))).thenReturn(queueInfoResponse);
    delegate.getQueues();
    verify(clientRMProtocol).getQueueInfo(any(GetQueueInfoRequest.class));
    GetQueueUserAclsInfoResponse aclResponse = recordFactory.newRecordInstance(GetQueueUserAclsInfoResponse.class);
    when(clientRMProtocol.getQueueUserAcls(any(GetQueueUserAclsInfoRequest.class))).thenReturn(aclResponse);
    delegate.getQueueAclsForCurrentUser();
    verify(clientRMProtocol).getQueueUserAcls(any(GetQueueUserAclsInfoRequest.class));
}
Also used : QueueInfo(org.apache.hadoop.yarn.api.records.QueueInfo) GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) GetNewApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse) YarnClusterMetrics(org.apache.hadoop.yarn.api.records.YarnClusterMetrics) GetQueueInfoRequest(org.apache.hadoop.yarn.api.protocolrecords.GetQueueInfoRequest) GetQueueInfoResponse(org.apache.hadoop.yarn.api.protocolrecords.GetQueueInfoResponse) GetClusterNodesResponse(org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodesResponse) KillApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest) YarnClientImpl(org.apache.hadoop.yarn.client.api.impl.YarnClientImpl) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) GetApplicationsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest) GetNewApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest) GetQueueUserAclsInfoResponse(org.apache.hadoop.yarn.api.protocolrecords.GetQueueUserAclsInfoResponse) GetQueueUserAclsInfoRequest(org.apache.hadoop.yarn.api.protocolrecords.GetQueueUserAclsInfoRequest) GetClusterMetricsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsResponse) GetApplicationsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse) GetClusterMetricsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsRequest) GetApplicationReportResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse) GetClusterNodesRequest(org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodesRequest) Test(org.junit.Test)

Example 2 with YarnClientImpl

use of org.apache.hadoop.yarn.client.api.impl.YarnClientImpl in project hadoop by apache.

the class TestResourceMgrDelegate method testGetRootQueues.

/**
   * Tests that getRootQueues makes a request for the (recursive) child queues
   * @throws IOException
   */
@Test
public void testGetRootQueues() throws IOException, InterruptedException {
    final ApplicationClientProtocol applicationsManager = Mockito.mock(ApplicationClientProtocol.class);
    GetQueueInfoResponse response = Mockito.mock(GetQueueInfoResponse.class);
    org.apache.hadoop.yarn.api.records.QueueInfo queueInfo = Mockito.mock(org.apache.hadoop.yarn.api.records.QueueInfo.class);
    Mockito.when(response.getQueueInfo()).thenReturn(queueInfo);
    try {
        Mockito.when(applicationsManager.getQueueInfo(Mockito.any(GetQueueInfoRequest.class))).thenReturn(response);
    } catch (YarnException e) {
        throw new IOException(e);
    }
    ResourceMgrDelegate delegate = new ResourceMgrDelegate(new YarnConfiguration()) {

        @Override
        protected void serviceStart() throws Exception {
            Assert.assertTrue(this.client instanceof YarnClientImpl);
            ((YarnClientImpl) this.client).setRMClient(applicationsManager);
        }
    };
    delegate.getRootQueues();
    ArgumentCaptor<GetQueueInfoRequest> argument = ArgumentCaptor.forClass(GetQueueInfoRequest.class);
    try {
        Mockito.verify(applicationsManager).getQueueInfo(argument.capture());
    } catch (YarnException e) {
        throw new IOException(e);
    }
    Assert.assertTrue("Children of root queue not requested", argument.getValue().getIncludeChildQueues());
    Assert.assertTrue("Request wasn't to recurse through children", argument.getValue().getRecursive());
}
Also used : GetQueueInfoRequest(org.apache.hadoop.yarn.api.protocolrecords.GetQueueInfoRequest) GetQueueInfoResponse(org.apache.hadoop.yarn.api.protocolrecords.GetQueueInfoResponse) IOException(java.io.IOException) YarnClientImpl(org.apache.hadoop.yarn.client.api.impl.YarnClientImpl) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Test(org.junit.Test)

Example 3 with YarnClientImpl

use of org.apache.hadoop.yarn.client.api.impl.YarnClientImpl in project hadoop by apache.

the class TestYarnClientProtocolProvider method testClusterGetDelegationToken.

@Test
public void testClusterGetDelegationToken() throws Exception {
    Configuration conf = new Configuration(false);
    Cluster cluster = null;
    try {
        conf = new Configuration();
        conf.set(MRConfig.FRAMEWORK_NAME, MRConfig.YARN_FRAMEWORK_NAME);
        cluster = new Cluster(conf);
        YARNRunner yrunner = (YARNRunner) cluster.getClient();
        GetDelegationTokenResponse getDTResponse = recordFactory.newRecordInstance(GetDelegationTokenResponse.class);
        org.apache.hadoop.yarn.api.records.Token rmDTToken = recordFactory.newRecordInstance(org.apache.hadoop.yarn.api.records.Token.class);
        rmDTToken.setIdentifier(ByteBuffer.wrap(new byte[2]));
        rmDTToken.setKind("Testclusterkind");
        rmDTToken.setPassword(ByteBuffer.wrap("testcluster".getBytes()));
        rmDTToken.setService("0.0.0.0:8032");
        getDTResponse.setRMDelegationToken(rmDTToken);
        final ApplicationClientProtocol cRMProtocol = mock(ApplicationClientProtocol.class);
        when(cRMProtocol.getDelegationToken(any(GetDelegationTokenRequest.class))).thenReturn(getDTResponse);
        ResourceMgrDelegate rmgrDelegate = new ResourceMgrDelegate(new YarnConfiguration(conf)) {

            @Override
            protected void serviceStart() throws Exception {
                assertTrue(this.client instanceof YarnClientImpl);
                this.client = spy(this.client);
                doNothing().when(this.client).close();
                ((YarnClientImpl) this.client).setRMClient(cRMProtocol);
            }
        };
        yrunner.setResourceMgrDelegate(rmgrDelegate);
        Token t = cluster.getDelegationToken(new Text(" "));
        assertTrue("Token kind is instead " + t.getKind().toString(), "Testclusterkind".equals(t.getKind().toString()));
    } finally {
        if (cluster != null) {
            cluster.close();
        }
    }
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) GetDelegationTokenResponse(org.apache.hadoop.yarn.api.protocolrecords.GetDelegationTokenResponse) Token(org.apache.hadoop.security.token.Token) Text(org.apache.hadoop.io.Text) YarnClientImpl(org.apache.hadoop.yarn.client.api.impl.YarnClientImpl) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) GetDelegationTokenRequest(org.apache.hadoop.yarn.api.protocolrecords.GetDelegationTokenRequest) ResourceMgrDelegate(org.apache.hadoop.mapred.ResourceMgrDelegate) YARNRunner(org.apache.hadoop.mapred.YARNRunner) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Test(org.junit.Test)

Example 4 with YarnClientImpl

use of org.apache.hadoop.yarn.client.api.impl.YarnClientImpl in project hadoop by apache.

the class TestResourceMgrDelegate method tesAllJobs.

@Test
public void tesAllJobs() throws Exception {
    final ApplicationClientProtocol applicationsManager = Mockito.mock(ApplicationClientProtocol.class);
    GetApplicationsResponse allApplicationsResponse = Records.newRecord(GetApplicationsResponse.class);
    List<ApplicationReport> applications = new ArrayList<ApplicationReport>();
    applications.add(getApplicationReport(YarnApplicationState.FINISHED, FinalApplicationStatus.FAILED));
    applications.add(getApplicationReport(YarnApplicationState.FINISHED, FinalApplicationStatus.SUCCEEDED));
    applications.add(getApplicationReport(YarnApplicationState.FINISHED, FinalApplicationStatus.KILLED));
    applications.add(getApplicationReport(YarnApplicationState.FAILED, FinalApplicationStatus.FAILED));
    allApplicationsResponse.setApplicationList(applications);
    Mockito.when(applicationsManager.getApplications(Mockito.any(GetApplicationsRequest.class))).thenReturn(allApplicationsResponse);
    ResourceMgrDelegate resourceMgrDelegate = new ResourceMgrDelegate(new YarnConfiguration()) {

        @Override
        protected void serviceStart() throws Exception {
            Assert.assertTrue(this.client instanceof YarnClientImpl);
            ((YarnClientImpl) this.client).setRMClient(applicationsManager);
        }
    };
    JobStatus[] allJobs = resourceMgrDelegate.getAllJobs();
    Assert.assertEquals(State.FAILED, allJobs[0].getState());
    Assert.assertEquals(State.SUCCEEDED, allJobs[1].getState());
    Assert.assertEquals(State.KILLED, allJobs[2].getState());
    Assert.assertEquals(State.FAILED, allJobs[3].getState());
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) JobStatus(org.apache.hadoop.mapreduce.JobStatus) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) GetApplicationsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse) ArrayList(java.util.ArrayList) YarnClientImpl(org.apache.hadoop.yarn.client.api.impl.YarnClientImpl) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) GetApplicationsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest) Test(org.junit.Test)

Aggregations

ApplicationClientProtocol (org.apache.hadoop.yarn.api.ApplicationClientProtocol)4 YarnClientImpl (org.apache.hadoop.yarn.client.api.impl.YarnClientImpl)4 Test (org.junit.Test)4 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)3 GetApplicationsRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest)2 GetApplicationsResponse (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse)2 GetQueueInfoRequest (org.apache.hadoop.yarn.api.protocolrecords.GetQueueInfoRequest)2 GetQueueInfoResponse (org.apache.hadoop.yarn.api.protocolrecords.GetQueueInfoResponse)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Configuration (org.apache.hadoop.conf.Configuration)1 Text (org.apache.hadoop.io.Text)1 ResourceMgrDelegate (org.apache.hadoop.mapred.ResourceMgrDelegate)1 YARNRunner (org.apache.hadoop.mapred.YARNRunner)1 JobStatus (org.apache.hadoop.mapreduce.JobStatus)1 Token (org.apache.hadoop.security.token.Token)1 GetApplicationReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest)1 GetApplicationReportResponse (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse)1 GetClusterMetricsRequest (org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsRequest)1 GetClusterMetricsResponse (org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsResponse)1