Search in sources :

Example 1 with SCMUploaderNotifyResponse

use of org.apache.hadoop.yarn.server.api.protocolrecords.SCMUploaderNotifyResponse in project hadoop by apache.

the class TestSharedCacheUploader method testSuccess.

/**
   * If verifyAccess, uploadFile, rename, and notification succeed, the upload
   * should succeed
   */
@Test
public void testSuccess() throws Exception {
    Configuration conf = new Configuration();
    conf.setBoolean(YarnConfiguration.SHARED_CACHE_ENABLED, true);
    LocalResource resource = mock(LocalResource.class);
    Path localPath = mock(Path.class);
    when(localPath.getName()).thenReturn("foo.jar");
    String user = "joe";
    SCMUploaderProtocol scmClient = mock(SCMUploaderProtocol.class);
    SCMUploaderNotifyResponse response = mock(SCMUploaderNotifyResponse.class);
    when(response.getAccepted()).thenReturn(true);
    when(scmClient.notify(isA(SCMUploaderNotifyRequest.class))).thenReturn(response);
    FileSystem fs = mock(FileSystem.class);
    // return false when rename is called
    when(fs.rename(isA(Path.class), isA(Path.class))).thenReturn(true);
    FileSystem localFs = FileSystem.getLocal(conf);
    SharedCacheUploader spied = createSpiedUploader(resource, localPath, user, conf, scmClient, fs, localFs);
    // stub verifyAccess() to return true
    doReturn(true).when(spied).verifyAccess();
    // stub getActualPath()
    doReturn(localPath).when(spied).getActualPath();
    // stub computeChecksum()
    doReturn("abcdef0123456789").when(spied).computeChecksum(isA(Path.class));
    // stub uploadFile() to return true
    doReturn(true).when(spied).uploadFile(isA(Path.class), isA(Path.class));
    // stub notifySharedCacheManager to return true
    doReturn(true).when(spied).notifySharedCacheManager(isA(String.class), isA(String.class));
    assertTrue(spied.call());
}
Also used : Path(org.apache.hadoop.fs.Path) SCMUploaderNotifyResponse(org.apache.hadoop.yarn.server.api.protocolrecords.SCMUploaderNotifyResponse) SCMUploaderNotifyRequest(org.apache.hadoop.yarn.server.api.protocolrecords.SCMUploaderNotifyRequest) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) SCMUploaderProtocol(org.apache.hadoop.yarn.server.api.SCMUploaderProtocol) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) Test(org.junit.Test)

Example 2 with SCMUploaderNotifyResponse

use of org.apache.hadoop.yarn.server.api.protocolrecords.SCMUploaderNotifyResponse in project hadoop by apache.

the class SharedCacheUploaderService method notify.

@Override
public SCMUploaderNotifyResponse notify(SCMUploaderNotifyRequest request) throws YarnException, IOException {
    SCMUploaderNotifyResponse response = recordFactory.newRecordInstance(SCMUploaderNotifyResponse.class);
    // TODO (YARN-2774): proper security/authorization needs to be implemented
    String filename = store.addResource(request.getResourceKey(), request.getFileName());
    boolean accepted = filename.equals(request.getFileName());
    if (accepted) {
        this.metrics.incAcceptedUploads();
    } else {
        this.metrics.incRejectedUploads();
    }
    response.setAccepted(accepted);
    return response;
}
Also used : SCMUploaderNotifyResponse(org.apache.hadoop.yarn.server.api.protocolrecords.SCMUploaderNotifyResponse)

Example 3 with SCMUploaderNotifyResponse

use of org.apache.hadoop.yarn.server.api.protocolrecords.SCMUploaderNotifyResponse in project hadoop by apache.

the class TestSharedCacheUploader method testRenameFail.

/**
   * If rename fails, the upload should fail
   */
@Test
public void testRenameFail() throws Exception {
    Configuration conf = new Configuration();
    conf.setBoolean(YarnConfiguration.SHARED_CACHE_ENABLED, true);
    LocalResource resource = mock(LocalResource.class);
    Path localPath = mock(Path.class);
    when(localPath.getName()).thenReturn("foo.jar");
    String user = "joe";
    SCMUploaderProtocol scmClient = mock(SCMUploaderProtocol.class);
    SCMUploaderNotifyResponse response = mock(SCMUploaderNotifyResponse.class);
    when(response.getAccepted()).thenReturn(true);
    when(scmClient.notify(isA(SCMUploaderNotifyRequest.class))).thenReturn(response);
    FileSystem fs = mock(FileSystem.class);
    // return false when rename is called
    when(fs.rename(isA(Path.class), isA(Path.class))).thenReturn(false);
    FileSystem localFs = FileSystem.getLocal(conf);
    SharedCacheUploader spied = createSpiedUploader(resource, localPath, user, conf, scmClient, fs, localFs);
    // stub verifyAccess() to return true
    doReturn(true).when(spied).verifyAccess();
    // stub getActualPath()
    doReturn(localPath).when(spied).getActualPath();
    // stub computeChecksum()
    doReturn("abcdef0123456789").when(spied).computeChecksum(isA(Path.class));
    // stub uploadFile() to return true
    doReturn(true).when(spied).uploadFile(isA(Path.class), isA(Path.class));
    assertFalse(spied.call());
}
Also used : Path(org.apache.hadoop.fs.Path) SCMUploaderNotifyResponse(org.apache.hadoop.yarn.server.api.protocolrecords.SCMUploaderNotifyResponse) SCMUploaderNotifyRequest(org.apache.hadoop.yarn.server.api.protocolrecords.SCMUploaderNotifyRequest) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) SCMUploaderProtocol(org.apache.hadoop.yarn.server.api.SCMUploaderProtocol) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) Test(org.junit.Test)

Aggregations

SCMUploaderNotifyResponse (org.apache.hadoop.yarn.server.api.protocolrecords.SCMUploaderNotifyResponse)3 Configuration (org.apache.hadoop.conf.Configuration)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)2 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)2 SCMUploaderProtocol (org.apache.hadoop.yarn.server.api.SCMUploaderProtocol)2 SCMUploaderNotifyRequest (org.apache.hadoop.yarn.server.api.protocolrecords.SCMUploaderNotifyRequest)2 Test (org.junit.Test)2