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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations