|
@@ -92,6 +92,8 @@ public final class FederationStateStoreFacade {
|
|
|
private static final String GET_SUBCLUSTERS_CACHEID = "getSubClusters";
|
|
|
private static final String GET_POLICIES_CONFIGURATIONS_CACHEID =
|
|
|
"getPoliciesConfigurations";
|
|
|
+ private static final String GET_APPLICATION_HOME_SUBCLUSTER_CACHEID =
|
|
|
+ "getApplicationHomeSubCluster";
|
|
|
|
|
|
private static final FederationStateStoreFacade FACADE =
|
|
|
new FederationStateStoreFacade();
|
|
@@ -382,10 +384,19 @@ public final class FederationStateStoreFacade {
|
|
|
*/
|
|
|
public SubClusterId getApplicationHomeSubCluster(ApplicationId appId)
|
|
|
throws YarnException {
|
|
|
- GetApplicationHomeSubClusterResponse response =
|
|
|
- stateStore.getApplicationHomeSubCluster(
|
|
|
+ try {
|
|
|
+ if (isCachingEnabled()) {
|
|
|
+ SubClusterId value = SubClusterId.class.cast(
|
|
|
+ cache.get(buildGetApplicationHomeSubClusterRequest(appId)));
|
|
|
+ return value;
|
|
|
+ } else {
|
|
|
+ GetApplicationHomeSubClusterResponse response = stateStore.getApplicationHomeSubCluster(
|
|
|
GetApplicationHomeSubClusterRequest.newInstance(appId));
|
|
|
- return response.getApplicationHomeSubCluster().getHomeSubCluster();
|
|
|
+ return response.getApplicationHomeSubCluster().getHomeSubCluster();
|
|
|
+ }
|
|
|
+ } catch (Throwable ex) {
|
|
|
+ throw new YarnException(ex);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -548,6 +559,26 @@ public final class FederationStateStoreFacade {
|
|
|
return cacheRequest;
|
|
|
}
|
|
|
|
|
|
+ private Object buildGetApplicationHomeSubClusterRequest(ApplicationId applicationId) {
|
|
|
+ final String cacheKey = buildCacheKey(getClass().getSimpleName(),
|
|
|
+ GET_APPLICATION_HOME_SUBCLUSTER_CACHEID, applicationId.toString());
|
|
|
+ CacheRequest<String, SubClusterId> cacheRequest = new CacheRequest<>(
|
|
|
+ cacheKey,
|
|
|
+ input -> {
|
|
|
+
|
|
|
+ GetApplicationHomeSubClusterRequest request =
|
|
|
+ GetApplicationHomeSubClusterRequest.newInstance(applicationId);
|
|
|
+ GetApplicationHomeSubClusterResponse response =
|
|
|
+ stateStore.getApplicationHomeSubCluster(request);
|
|
|
+
|
|
|
+ ApplicationHomeSubCluster appHomeSubCluster = response.getApplicationHomeSubCluster();
|
|
|
+ SubClusterId subClusterId = appHomeSubCluster.getHomeSubCluster();
|
|
|
+
|
|
|
+ return subClusterId;
|
|
|
+ });
|
|
|
+ return cacheRequest;
|
|
|
+ }
|
|
|
+
|
|
|
protected String buildCacheKey(String typeName, String methodName,
|
|
|
String argName) {
|
|
|
StringBuilder buffer = new StringBuilder();
|
|
@@ -645,6 +676,15 @@ public final class FederationStateStoreFacade {
|
|
|
TResult invoke(T input) throws Exception;
|
|
|
}
|
|
|
|
|
|
+ @VisibleForTesting
|
|
|
+ public Cache<Object, Object> getCache() {
|
|
|
+ return cache;
|
|
|
+ }
|
|
|
+
|
|
|
+ @VisibleForTesting
|
|
|
+ protected Object getAppHomeSubClusterCacheRequest(ApplicationId applicationId) {
|
|
|
+ return buildGetApplicationHomeSubClusterRequest(applicationId);
|
|
|
+ }
|
|
|
|
|
|
@VisibleForTesting
|
|
|
public FederationStateStore getStateStore() {
|