|
@@ -24,10 +24,13 @@ import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.Calendar;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.TimeZone;
|
|
import java.util.TimeZone;
|
|
|
|
+import java.util.Comparator;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.lang3.NotImplementedException;
|
|
import org.apache.commons.lang3.NotImplementedException;
|
|
import org.apache.hadoop.classification.VisibleForTesting;
|
|
import org.apache.hadoop.classification.VisibleForTesting;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.util.Time;
|
|
import org.apache.hadoop.util.curator.ZKCuratorManager;
|
|
import org.apache.hadoop.util.curator.ZKCuratorManager;
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
@@ -98,6 +101,8 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import org.apache.hadoop.thirdparty.protobuf.InvalidProtocolBufferException;
|
|
import org.apache.hadoop.thirdparty.protobuf.InvalidProtocolBufferException;
|
|
|
|
|
|
|
|
+import static org.apache.hadoop.yarn.server.federation.store.utils.FederationStateStoreUtils.filterHomeSubCluster;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* ZooKeeper implementation of {@link FederationStateStore}.
|
|
* ZooKeeper implementation of {@link FederationStateStore}.
|
|
*
|
|
*
|
|
@@ -136,6 +141,7 @@ public class ZookeeperFederationStateStore implements FederationStateStore {
|
|
private String membershipZNode;
|
|
private String membershipZNode;
|
|
private String policiesZNode;
|
|
private String policiesZNode;
|
|
private String reservationsZNode;
|
|
private String reservationsZNode;
|
|
|
|
+ private int maxAppsInStateStore;
|
|
|
|
|
|
private volatile Clock clock = SystemClock.getInstance();
|
|
private volatile Clock clock = SystemClock.getInstance();
|
|
|
|
|
|
@@ -147,6 +153,10 @@ public class ZookeeperFederationStateStore implements FederationStateStore {
|
|
public void init(Configuration conf) throws YarnException {
|
|
public void init(Configuration conf) throws YarnException {
|
|
LOG.info("Initializing ZooKeeper connection");
|
|
LOG.info("Initializing ZooKeeper connection");
|
|
|
|
|
|
|
|
+ maxAppsInStateStore = conf.getInt(
|
|
|
|
+ YarnConfiguration.FEDERATION_STATESTORE_MAX_APPLICATIONS,
|
|
|
|
+ YarnConfiguration.DEFAULT_FEDERATION_STATESTORE_MAX_APPLICATIONS);
|
|
|
|
+
|
|
baseZNode = conf.get(
|
|
baseZNode = conf.get(
|
|
YarnConfiguration.FEDERATION_STATESTORE_ZK_PARENT_PATH,
|
|
YarnConfiguration.FEDERATION_STATESTORE_ZK_PARENT_PATH,
|
|
YarnConfiguration.DEFAULT_FEDERATION_STATESTORE_ZK_PARENT_PATH);
|
|
YarnConfiguration.DEFAULT_FEDERATION_STATESTORE_ZK_PARENT_PATH);
|
|
@@ -258,24 +268,44 @@ public class ZookeeperFederationStateStore implements FederationStateStore {
|
|
@Override
|
|
@Override
|
|
public GetApplicationsHomeSubClusterResponse getApplicationsHomeSubCluster(
|
|
public GetApplicationsHomeSubClusterResponse getApplicationsHomeSubCluster(
|
|
GetApplicationsHomeSubClusterRequest request) throws YarnException {
|
|
GetApplicationsHomeSubClusterRequest request) throws YarnException {
|
|
- long start = clock.getTime();
|
|
|
|
- List<ApplicationHomeSubCluster> result = new ArrayList<>();
|
|
|
|
|
|
+
|
|
|
|
+ if (request == null) {
|
|
|
|
+ throw new YarnException("Missing getApplicationsHomeSubCluster request");
|
|
|
|
+ }
|
|
|
|
|
|
try {
|
|
try {
|
|
- for (String child : zkManager.getChildren(appsZNode)) {
|
|
|
|
- ApplicationId appId = ApplicationId.fromString(child);
|
|
|
|
- SubClusterId homeSubCluster = getApp(appId);
|
|
|
|
- ApplicationHomeSubCluster app =
|
|
|
|
- ApplicationHomeSubCluster.newInstance(appId, homeSubCluster);
|
|
|
|
- result.add(app);
|
|
|
|
- }
|
|
|
|
|
|
+ long start = clock.getTime();
|
|
|
|
+ SubClusterId requestSC = request.getSubClusterId();
|
|
|
|
+ List<String> children = zkManager.getChildren(appsZNode);
|
|
|
|
+ List<ApplicationHomeSubCluster> result = children.stream()
|
|
|
|
+ .map(child -> generateAppHomeSC(child))
|
|
|
|
+ .sorted(Comparator.comparing(ApplicationHomeSubCluster::getCreateTime).reversed())
|
|
|
|
+ .filter(appHomeSC -> filterHomeSubCluster(requestSC, appHomeSC.getHomeSubCluster()))
|
|
|
|
+ .limit(maxAppsInStateStore)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ long end = clock.getTime();
|
|
|
|
+ opDurations.addGetAppsHomeSubClusterDuration(start, end);
|
|
|
|
+ LOG.info("filterSubClusterId = {}, appCount = {}.", requestSC, result.size());
|
|
|
|
+ return GetApplicationsHomeSubClusterResponse.newInstance(result);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
String errMsg = "Cannot get apps: " + e.getMessage();
|
|
String errMsg = "Cannot get apps: " + e.getMessage();
|
|
FederationStateStoreUtils.logAndThrowStoreException(LOG, errMsg);
|
|
FederationStateStoreUtils.logAndThrowStoreException(LOG, errMsg);
|
|
}
|
|
}
|
|
- long end = clock.getTime();
|
|
|
|
- opDurations.addGetAppsHomeSubClusterDuration(start, end);
|
|
|
|
- return GetApplicationsHomeSubClusterResponse.newInstance(result);
|
|
|
|
|
|
+
|
|
|
|
+ throw new YarnException("Cannot get app by request");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private ApplicationHomeSubCluster generateAppHomeSC(String appId) {
|
|
|
|
+ try {
|
|
|
|
+ ApplicationId applicationId = ApplicationId.fromString(appId);
|
|
|
|
+ SubClusterId homeSubCluster = getApp(applicationId);
|
|
|
|
+ ApplicationHomeSubCluster app =
|
|
|
|
+ ApplicationHomeSubCluster.newInstance(applicationId, Time.now(), homeSubCluster);
|
|
|
|
+ return app;
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ LOG.error("get homeSubCluster by appId = {}.", appId);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|