Search in sources :

Example 6 with ApplicationId

use of org.apache.hadoop.yarn.api.records.ApplicationId in project hadoop by apache.

the class TestInMemorySCMStore method testAddResourceRefAddResourceConcurrency.

@Test
public void testAddResourceRefAddResourceConcurrency() throws Exception {
    startEmptyStore();
    final String key = "key1";
    final String fileName = "foo.jar";
    final String user = "user";
    final ApplicationId id = createAppId(1, 1L);
    // add the resource and add the resource ref at the same time
    ExecutorService exec = HadoopExecutors.newFixedThreadPool(2);
    final CountDownLatch start = new CountDownLatch(1);
    Callable<String> addKeyTask = new Callable<String>() {

        public String call() throws Exception {
            start.await();
            return store.addResource(key, fileName);
        }
    };
    Callable<String> addAppIdTask = new Callable<String>() {

        public String call() throws Exception {
            start.await();
            return store.addResourceReference(key, new SharedCacheResourceReference(id, user));
        }
    };
    Future<String> addAppIdFuture = exec.submit(addAppIdTask);
    Future<String> addKeyFuture = exec.submit(addKeyTask);
    // start them at the same time
    start.countDown();
    // get the results
    String addKeyResult = addKeyFuture.get();
    String addAppIdResult = addAppIdFuture.get();
    assertEquals(fileName, addKeyResult);
    System.out.println("addAppId() result: " + addAppIdResult);
    // it may be null or the fileName depending on the timing
    assertTrue(addAppIdResult == null || addAppIdResult.equals(fileName));
    exec.shutdown();
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) CountDownLatch(java.util.concurrent.CountDownLatch) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 7 with ApplicationId

use of org.apache.hadoop.yarn.api.records.ApplicationId in project hadoop by apache.

the class TestInMemorySCMStore method testAddResourceRefNonExistentResource.

@Test
public void testAddResourceRefNonExistentResource() throws Exception {
    startEmptyStore();
    String key = "key1";
    ApplicationId id = createAppId(1, 1L);
    // try adding an app id without adding the key first
    assertNull(store.addResourceReference(key, new SharedCacheResourceReference(id, "user")));
}
Also used : ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Example 8 with ApplicationId

use of org.apache.hadoop.yarn.api.records.ApplicationId in project hadoop by apache.

the class TestRemoteAppChecker method testNonExistentApp.

@Test
public void testNonExistentApp() throws Exception {
    YarnClient client = createCheckerWithMockedClient();
    ApplicationId id = ApplicationId.newInstance(1, 1);
    // test for null
    doReturn(null).when(client).getApplicationReport(id);
    assertFalse(checker.isApplicationActive(id));
    // test for ApplicationNotFoundException
    doThrow(new ApplicationNotFoundException("Throw!")).when(client).getApplicationReport(id);
    assertFalse(checker.isApplicationActive(id));
}
Also used : ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) Test(org.junit.Test)

Example 9 with ApplicationId

use of org.apache.hadoop.yarn.api.records.ApplicationId in project hadoop by apache.

the class TestInMemorySCMStore method startEmptyStore.

private void startEmptyStore() throws Exception {
    doReturn(new ArrayList<ApplicationId>()).when(checker).getActiveApplications();
    doReturn(new HashMap<String, String>()).when(store).getInitialCachedResources(isA(FileSystem.class), isA(Configuration.class));
    this.store.init(new Configuration());
    this.store.start();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId)

Example 10 with ApplicationId

use of org.apache.hadoop.yarn.api.records.ApplicationId in project hadoop by apache.

the class TestInMemorySCMStore method testRemoveRef.

@Test
public void testRemoveRef() throws Exception {
    startEmptyStore();
    String key = "key1";
    String fileName = "foo.jar";
    String user = "user";
    // first add the resource
    store.addResource(key, fileName);
    // add a ref
    ApplicationId id = createAppId(1, 1L);
    SharedCacheResourceReference myRef = new SharedCacheResourceReference(id, user);
    String result = store.addResourceReference(key, myRef);
    assertEquals(fileName, result);
    Collection<SharedCacheResourceReference> refs = store.getResourceReferences(key);
    assertSame(1, refs.size());
    assertEquals(Collections.singleton(myRef), refs);
    // remove the same ref
    store.removeResourceReferences(key, Collections.singleton(myRef), true);
    Collection<SharedCacheResourceReference> newRefs = store.getResourceReferences(key);
    assertTrue(newRefs == null || newRefs.isEmpty());
}
Also used : ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Aggregations

ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)849 Test (org.junit.Test)435 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)255 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)203 Configuration (org.apache.hadoop.conf.Configuration)190 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)154 IOException (java.io.IOException)153 Path (org.apache.hadoop.fs.Path)151 ArrayList (java.util.ArrayList)106 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)102 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)85 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)81 HashMap (java.util.HashMap)80 Resource (org.apache.hadoop.yarn.api.records.Resource)80 File (java.io.File)70 NodeId (org.apache.hadoop.yarn.api.records.NodeId)63 Credentials (org.apache.hadoop.security.Credentials)60 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)60 ApplicationSubmissionContext (org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext)59 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)56