Search in sources :

Example 1 with UseSharedCacheResourceResponse

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

the class TestSharedCacheClientImpl method testUseWithResourceName.

@Test
public void testUseWithResourceName() throws Exception {
    Path file = new Path("viewfs://test/path");
    URI useUri = new URI("viewfs://test/path#linkName");
    Path usePath = new Path(useUri);
    UseSharedCacheResourceResponse response = new UseSharedCacheResourceResponsePBImpl();
    response.setPath(file.toString());
    when(cProtocol.use(isA(UseSharedCacheResourceRequest.class))).thenReturn(response);
    Path newPath = client.use(mock(ApplicationId.class), "key", "linkName");
    assertEquals("The paths are not equal!", usePath, newPath);
}
Also used : Path(org.apache.hadoop.fs.Path) UseSharedCacheResourceRequest(org.apache.hadoop.yarn.api.protocolrecords.UseSharedCacheResourceRequest) UseSharedCacheResourceResponse(org.apache.hadoop.yarn.api.protocolrecords.UseSharedCacheResourceResponse) UseSharedCacheResourceResponsePBImpl(org.apache.hadoop.yarn.api.protocolrecords.impl.pb.UseSharedCacheResourceResponsePBImpl) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) URI(java.net.URI) Test(org.junit.Test)

Example 2 with UseSharedCacheResourceResponse

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

the class TestSharedCacheClientImpl method testUseWithSameResourceName.

@Test
public void testUseWithSameResourceName() throws Exception {
    Path file = new Path("viewfs://test/path");
    URI useUri = new URI("viewfs://test/path");
    Path usePath = new Path(useUri);
    UseSharedCacheResourceResponse response = new UseSharedCacheResourceResponsePBImpl();
    response.setPath(file.toString());
    when(cProtocol.use(isA(UseSharedCacheResourceRequest.class))).thenReturn(response);
    Path newPath = client.use(mock(ApplicationId.class), "key", "path");
    assertEquals("The paths are not equal!", usePath, newPath);
}
Also used : Path(org.apache.hadoop.fs.Path) UseSharedCacheResourceRequest(org.apache.hadoop.yarn.api.protocolrecords.UseSharedCacheResourceRequest) UseSharedCacheResourceResponse(org.apache.hadoop.yarn.api.protocolrecords.UseSharedCacheResourceResponse) UseSharedCacheResourceResponsePBImpl(org.apache.hadoop.yarn.api.protocolrecords.impl.pb.UseSharedCacheResourceResponsePBImpl) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) URI(java.net.URI) Test(org.junit.Test)

Example 3 with UseSharedCacheResourceResponse

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

the class ClientProtocolService method use.

@Override
public UseSharedCacheResourceResponse use(UseSharedCacheResourceRequest request) throws YarnException, IOException {
    UseSharedCacheResourceResponse response = recordFactory.newRecordInstance(UseSharedCacheResourceResponse.class);
    UserGroupInformation callerUGI;
    try {
        callerUGI = UserGroupInformation.getCurrentUser();
    } catch (IOException ie) {
        LOG.info("Error getting UGI ", ie);
        throw RPCUtil.getRemoteException(ie);
    }
    String fileName = this.store.addResourceReference(request.getResourceKey(), new SharedCacheResourceReference(request.getAppId(), callerUGI.getShortUserName()));
    if (fileName != null) {
        response.setPath(getCacheEntryFilePath(request.getResourceKey(), fileName));
        this.metrics.incCacheHitCount();
    } else {
        this.metrics.incCacheMissCount();
    }
    return response;
}
Also used : SharedCacheResourceReference(org.apache.hadoop.yarn.server.sharedcachemanager.store.SharedCacheResourceReference) UseSharedCacheResourceResponse(org.apache.hadoop.yarn.api.protocolrecords.UseSharedCacheResourceResponse) IOException(java.io.IOException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 4 with UseSharedCacheResourceResponse

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

the class SharedCacheClientImpl method use.

@Override
public Path use(ApplicationId applicationId, String resourceKey, String resourceName) throws YarnException {
    Path resourcePath = null;
    UseSharedCacheResourceRequest request = Records.newRecord(UseSharedCacheResourceRequest.class);
    request.setAppId(applicationId);
    request.setResourceKey(resourceKey);
    try {
        UseSharedCacheResourceResponse response = this.scmClient.use(request);
        if (response != null && response.getPath() != null) {
            resourcePath = new Path(response.getPath());
        }
    } catch (Exception e) {
        // We don't handle different exceptions separately at this point.
        throw new YarnException(e);
    }
    if (resourcePath != null) {
        if (resourcePath.getName().equals(resourceName)) {
            // so we skip generating the fragment to save space in the MRconfig.
            return resourcePath;
        } else {
            // We are using the shared cache, and a preferred name has been
            // specified that is different than the name of the resource in the
            // shared cache. We need to set the fragment portion of the URI to
            // preserve the desired name.
            URI pathURI = resourcePath.toUri();
            try {
                // We assume that there is no existing fragment in the URI since the
                // shared cache manager does not use fragments.
                pathURI = new URI(pathURI.getScheme(), pathURI.getSchemeSpecificPart(), resourceName);
                resourcePath = new Path(pathURI);
            } catch (URISyntaxException e) {
                throw new YarnException("Could not create a new URI due to syntax errors: " + pathURI.toString(), e);
            }
        }
    }
    return resourcePath;
}
Also used : Path(org.apache.hadoop.fs.Path) UseSharedCacheResourceRequest(org.apache.hadoop.yarn.api.protocolrecords.UseSharedCacheResourceRequest) UseSharedCacheResourceResponse(org.apache.hadoop.yarn.api.protocolrecords.UseSharedCacheResourceResponse) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 5 with UseSharedCacheResourceResponse

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

the class TestSharedCacheClientImpl method testUseCacheMiss.

@Test
public void testUseCacheMiss() throws Exception {
    UseSharedCacheResourceResponse response = new UseSharedCacheResourceResponsePBImpl();
    response.setPath(null);
    when(cProtocol.use(isA(UseSharedCacheResourceRequest.class))).thenReturn(response);
    Path newPath = client.use(mock(ApplicationId.class), "key", null);
    assertNull("The path is not null!", newPath);
}
Also used : UseSharedCacheResourceRequest(org.apache.hadoop.yarn.api.protocolrecords.UseSharedCacheResourceRequest) Path(org.apache.hadoop.fs.Path) UseSharedCacheResourceResponse(org.apache.hadoop.yarn.api.protocolrecords.UseSharedCacheResourceResponse) UseSharedCacheResourceResponsePBImpl(org.apache.hadoop.yarn.api.protocolrecords.impl.pb.UseSharedCacheResourceResponsePBImpl) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Aggregations

UseSharedCacheResourceResponse (org.apache.hadoop.yarn.api.protocolrecords.UseSharedCacheResourceResponse)5 Path (org.apache.hadoop.fs.Path)4 UseSharedCacheResourceRequest (org.apache.hadoop.yarn.api.protocolrecords.UseSharedCacheResourceRequest)4 URI (java.net.URI)3 UseSharedCacheResourceResponsePBImpl (org.apache.hadoop.yarn.api.protocolrecords.impl.pb.UseSharedCacheResourceResponsePBImpl)3 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 SharedCacheResourceReference (org.apache.hadoop.yarn.server.sharedcachemanager.store.SharedCacheResourceReference)1