Search in sources :

Example 1 with SCMStore

use of org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore in project hadoop by apache.

the class TestCleanerTask method testProcessEvictableResource.

@Test
public void testProcessEvictableResource() throws Exception {
    FileSystem fs = mock(FileSystem.class);
    CleanerMetrics metrics = mock(CleanerMetrics.class);
    SCMStore store = mock(SCMStore.class);
    CleanerTask task = createSpiedTask(fs, store, metrics, new ReentrantLock());
    // mock an evictable resource
    when(store.isResourceEvictable(isA(String.class), isA(FileStatus.class))).thenReturn(true);
    FileStatus status = mock(FileStatus.class);
    when(status.getPath()).thenReturn(new Path(ROOT + "/a/b/c/abc"));
    when(store.removeResource(isA(String.class))).thenReturn(true);
    // rename succeeds
    when(fs.rename(isA(Path.class), isA(Path.class))).thenReturn(true);
    // delete returns true
    when(fs.delete(isA(Path.class), anyBoolean())).thenReturn(true);
    // process the resource
    task.processSingleResource(status);
    // the directory should be renamed
    verify(fs).rename(eq(status.getPath()), isA(Path.class));
    // metrics should record a deleted file
    verify(metrics).reportAFileDelete();
    verify(metrics, never()).reportAFileProcess();
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) SCMStore(org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore) FileSystem(org.apache.hadoop.fs.FileSystem) CleanerMetrics(org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics) Test(org.junit.Test)

Example 2 with SCMStore

use of org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore in project hadoop by apache.

the class TestCleanerTask method testProcessFreshResource.

@Test
public void testProcessFreshResource() throws Exception {
    FileSystem fs = mock(FileSystem.class);
    CleanerMetrics metrics = mock(CleanerMetrics.class);
    SCMStore store = mock(SCMStore.class);
    CleanerTask task = createSpiedTask(fs, store, metrics, new ReentrantLock());
    // mock a resource that is not evictable
    when(store.isResourceEvictable(isA(String.class), isA(FileStatus.class))).thenReturn(false);
    FileStatus status = mock(FileStatus.class);
    when(status.getPath()).thenReturn(new Path(ROOT + "/a/b/c/abc"));
    // process the resource
    task.processSingleResource(status);
    // the directory should not be renamed
    verify(fs, never()).rename(eq(status.getPath()), isA(Path.class));
    // metrics should record a processed file (but not delete)
    verify(metrics).reportAFileProcess();
    verify(metrics, never()).reportAFileDelete();
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) SCMStore(org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore) FileSystem(org.apache.hadoop.fs.FileSystem) CleanerMetrics(org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics) Test(org.junit.Test)

Example 3 with SCMStore

use of org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore in project hadoop by apache.

the class TestCleanerTask method testResourceIsInUseHasAnActiveApp.

@Test
public void testResourceIsInUseHasAnActiveApp() throws Exception {
    FileSystem fs = mock(FileSystem.class);
    CleanerMetrics metrics = mock(CleanerMetrics.class);
    SCMStore store = mock(SCMStore.class);
    FileStatus resource = mock(FileStatus.class);
    when(resource.getPath()).thenReturn(new Path(ROOT + "/a/b/c/abc"));
    // resource is stale
    when(store.isResourceEvictable(isA(String.class), isA(FileStatus.class))).thenReturn(true);
    // but still has appIds
    when(store.removeResource(isA(String.class))).thenReturn(false);
    CleanerTask task = createSpiedTask(fs, store, metrics, new ReentrantLock());
    // process the resource
    task.processSingleResource(resource);
    // metrics should record a processed file (but not delete)
    verify(metrics).reportAFileProcess();
    verify(metrics, never()).reportAFileDelete();
}
Also used : Path(org.apache.hadoop.fs.Path) ReentrantLock(java.util.concurrent.locks.ReentrantLock) FileStatus(org.apache.hadoop.fs.FileStatus) SCMStore(org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore) FileSystem(org.apache.hadoop.fs.FileSystem) CleanerMetrics(org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics) Test(org.junit.Test)

Example 4 with SCMStore

use of org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore in project hadoop by apache.

the class TestCleanerTask method testNonExistentRoot.

@Test
public void testNonExistentRoot() throws Exception {
    FileSystem fs = mock(FileSystem.class);
    CleanerMetrics metrics = mock(CleanerMetrics.class);
    SCMStore store = mock(SCMStore.class);
    CleanerTask task = createSpiedTask(fs, store, metrics, new ReentrantLock());
    // the shared cache root does not exist
    when(fs.exists(task.getRootPath())).thenReturn(false);
    task.run();
    // process() should not be called
    verify(task, never()).process();
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) SCMStore(org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore) FileSystem(org.apache.hadoop.fs.FileSystem) CleanerMetrics(org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics) Test(org.junit.Test)

Example 5 with SCMStore

use of org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore in project hadoop by apache.

the class SharedCacheManager method createSCMStoreService.

@SuppressWarnings("unchecked")
private static SCMStore createSCMStoreService(Configuration conf) {
    Class<? extends SCMStore> defaultStoreClass;
    try {
        defaultStoreClass = (Class<? extends SCMStore>) Class.forName(YarnConfiguration.DEFAULT_SCM_STORE_CLASS);
    } catch (Exception e) {
        throw new YarnRuntimeException("Invalid default scm store class" + YarnConfiguration.DEFAULT_SCM_STORE_CLASS, e);
    }
    SCMStore store = ReflectionUtils.newInstance(conf.getClass(YarnConfiguration.SCM_STORE_CLASS, defaultStoreClass, SCMStore.class), conf);
    return store;
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) SCMStore(org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException)

Aggregations

SCMStore (org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore)5 ReentrantLock (java.util.concurrent.locks.ReentrantLock)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 CleanerMetrics (org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics)4 Test (org.junit.Test)4 FileStatus (org.apache.hadoop.fs.FileStatus)3 Path (org.apache.hadoop.fs.Path)3 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)1