Search in sources :

Example 21 with YarnClient

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

the class TestYarnClient method setupYarnClient.

private YarnClient setupYarnClient(MiniYARNCluster cluster) {
    final Configuration yarnConf = cluster.getConfig();
    YarnClient client = YarnClient.createYarnClient();
    client.init(yarnConf);
    client.start();
    return client;
}
Also used : CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient)

Example 22 with YarnClient

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

the class TestYarnClient method testListReservationsByReservationId.

@Test
public void testListReservationsByReservationId() throws Exception {
    MiniYARNCluster cluster = setupMiniYARNCluster();
    YarnClient client = setupYarnClient(cluster);
    try {
        Clock clock = new UTCClock();
        long arrival = clock.getTime();
        long duration = 60000;
        long deadline = (long) (arrival + 1.05 * duration);
        ReservationSubmissionRequest sRequest = submitReservationTestHelper(client, arrival, deadline, duration);
        ReservationId reservationID = sRequest.getReservationId();
        ReservationListRequest request = ReservationListRequest.newInstance(ReservationSystemTestUtil.reservationQ, reservationID.toString(), -1, -1, false);
        ReservationListResponse response = client.listReservations(request);
        Assert.assertNotNull(response);
        Assert.assertEquals(1, response.getReservationAllocationState().size());
        Assert.assertEquals(response.getReservationAllocationState().get(0).getReservationId().getId(), reservationID.getId());
        Assert.assertEquals(response.getReservationAllocationState().get(0).getResourceAllocationRequests().size(), 0);
    } finally {
        // clean-up
        if (client != null) {
            client.stop();
        }
        cluster.stop();
    }
}
Also used : ReservationListResponse(org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) ReservationListRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationListRequest) ReservationSubmissionRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest) MiniYARNCluster(org.apache.hadoop.yarn.server.MiniYARNCluster) UTCClock(org.apache.hadoop.yarn.util.UTCClock) Clock(org.apache.hadoop.yarn.util.Clock) UTCClock(org.apache.hadoop.yarn.util.UTCClock) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) Test(org.junit.Test)

Example 23 with YarnClient

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

the class TestYarnClient method testShouldNotRetryForeverForNonNetworkExceptions.

@Test(timeout = 30000, expected = ApplicationNotFoundException.class)
public void testShouldNotRetryForeverForNonNetworkExceptions() throws Exception {
    YarnConfiguration conf = new YarnConfiguration();
    conf.setInt(YarnConfiguration.RESOURCEMANAGER_CONNECT_MAX_WAIT_MS, -1);
    ResourceManager rm = null;
    YarnClient yarnClient = null;
    try {
        // start rm
        rm = new ResourceManager();
        rm.init(conf);
        rm.start();
        yarnClient = YarnClient.createYarnClient();
        yarnClient.init(conf);
        yarnClient.start();
        // create invalid application id
        ApplicationId appId = ApplicationId.newInstance(1430126768L, 10645);
        // RM should throw ApplicationNotFoundException exception
        yarnClient.getApplicationReport(appId);
    } finally {
        if (yarnClient != null) {
            yarnClient.stop();
        }
        if (rm != null) {
            rm.stop();
        }
    }
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ResourceManager(org.apache.hadoop.yarn.server.resourcemanager.ResourceManager) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) Test(org.junit.Test)

Example 24 with YarnClient

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

the class TestYarnClient method testGetApplicationAttempt.

@Test(timeout = 10000)
public void testGetApplicationAttempt() throws YarnException, IOException {
    Configuration conf = new Configuration();
    final YarnClient client = new MockYarnClient();
    client.init(conf);
    client.start();
    List<ApplicationReport> expectedReports = ((MockYarnClient) client).getReports();
    ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(applicationId, 1);
    ApplicationAttemptReport report = client.getApplicationAttemptReport(appAttemptId);
    Assert.assertNotNull(report);
    Assert.assertEquals(report.getApplicationAttemptId().toString(), expectedReports.get(0).getCurrentApplicationAttemptId().toString());
    client.stop();
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) Test(org.junit.Test)

Example 25 with YarnClient

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

the class TestYarnClient method testCreateReservation.

@Test
public void testCreateReservation() throws Exception {
    MiniYARNCluster cluster = setupMiniYARNCluster();
    YarnClient client = setupYarnClient(cluster);
    try {
        Clock clock = new UTCClock();
        long arrival = clock.getTime();
        long duration = 60000;
        long deadline = (long) (arrival + 1.05 * duration);
        ReservationSubmissionRequest sRequest = submitReservationTestHelper(client, arrival, deadline, duration);
        // Submit the reservation again with the same request and make sure it
        // passes.
        client.submitReservation(sRequest);
        // Submit the reservation with the same reservation id but different
        // reservation definition, and ensure YarnException is thrown.
        arrival = clock.getTime();
        ReservationDefinition rDef = sRequest.getReservationDefinition();
        rDef.setArrival(arrival + duration);
        sRequest.setReservationDefinition(rDef);
        try {
            client.submitReservation(sRequest);
            Assert.fail("Reservation submission should fail if a duplicate " + "reservation id is used, but the reservation definition has been " + "updated.");
        } catch (Exception e) {
            Assert.assertTrue(e instanceof YarnException);
        }
    } finally {
        // clean-up
        if (client != null) {
            client.stop();
        }
        cluster.stop();
    }
}
Also used : ReservationDefinition(org.apache.hadoop.yarn.api.records.ReservationDefinition) ReservationSubmissionRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest) MiniYARNCluster(org.apache.hadoop.yarn.server.MiniYARNCluster) UTCClock(org.apache.hadoop.yarn.util.UTCClock) Clock(org.apache.hadoop.yarn.util.Clock) UTCClock(org.apache.hadoop.yarn.util.UTCClock) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ApplicationIdNotProvidedException(org.apache.hadoop.yarn.exceptions.ApplicationIdNotProvidedException) IOException(java.io.IOException) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) Test(org.junit.Test)

Aggregations

YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)89 Test (org.junit.Test)51 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)50 Configuration (org.apache.hadoop.conf.Configuration)45 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)37 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)21 CapacitySchedulerConfiguration (org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration)18 IOException (java.io.IOException)17 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)15 MiniYARNCluster (org.apache.hadoop.yarn.server.MiniYARNCluster)15 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)14 Path (org.apache.hadoop.fs.Path)13 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)13 FileSystem (org.apache.hadoop.fs.FileSystem)11 Matchers.anyString (org.mockito.Matchers.anyString)11 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)9 NodeId (org.apache.hadoop.yarn.api.records.NodeId)9 ArrayList (java.util.ArrayList)8 LocalFileSystem (org.apache.hadoop.fs.LocalFileSystem)8 ReservationSubmissionRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest)7