You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2015/11/23 18:20:54 UTC

[42/50] incubator-slider git commit: SLIDER-994 node information map to list node entries by role name, not priority

SLIDER-994 node information map to list node entries by role name, not priority


Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/737d7875
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/737d7875
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/737d7875

Branch: refs/heads/develop
Commit: 737d7875120fe29d8d8d9de4317b4f2e188c0022
Parents: 4fb381e
Author: Steve Loughran <st...@apache.org>
Authored: Fri Nov 20 20:16:31 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Fri Nov 20 20:16:31 2015 +0000

----------------------------------------------------------------------
 .../slider/server/appmaster/state/AppState.java     | 14 +++++++-------
 .../slider/server/appmaster/state/NodeInstance.java | 10 ++++++++--
 .../server/appmaster/state/ProviderAppState.java    | 16 ++++++++++++++--
 .../slider/server/appmaster/state/RoleHistory.java  | 14 ++++++++++----
 4 files changed, 39 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/737d7875/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java
index ee5d43d..171cc42 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java
@@ -107,6 +107,7 @@ import static org.apache.slider.api.RoleKeys.ROLE_FAILED_INSTANCES;
 import static org.apache.slider.api.RoleKeys.ROLE_FAILED_RECENTLY_INSTANCES;
 import static org.apache.slider.api.RoleKeys.ROLE_FAILED_STARTING_INSTANCES;
 import static org.apache.slider.api.RoleKeys.ROLE_NODE_FAILED_INSTANCES;
+import static org.apache.slider.api.RoleKeys.ROLE_PENDING_AA_INSTANCES;
 import static org.apache.slider.api.RoleKeys.ROLE_PREEMPTED_INSTANCES;
 import static org.apache.slider.api.RoleKeys.ROLE_RELEASING_INSTANCES;
 import static org.apache.slider.api.RoleKeys.ROLE_REQUESTED_INSTANCES;
@@ -911,10 +912,6 @@ public class AppState {
     appMasterNode.state = STATE_LIVE;
   }
 
-  public RoleInstance getAppMasterNode() {
-    return appMasterNode;
-  }
-
   /**
    * Look up the status entry of a role or raise an exception
    * @param key role ID
@@ -1717,13 +1714,13 @@ public class AppState {
                    now);
     if (providerStatus != null) {
       for (Map.Entry<String, String> entry : providerStatus.entrySet()) {
-        cd.setInfo(entry.getKey(),entry.getValue());
+        cd.setInfo(entry.getKey(), entry.getValue());
       }
     }
     MapOperations infoOps = new MapOperations("info", cd.info);
     infoOps.mergeWithoutOverwrite(applicationInfo);
     SliderUtils.addBuildInfo(infoOps, "status");
-    cd.statistics = new HashMap<String, Map<String, Integer>>();
+    cd.statistics = new HashMap<>();
 
     // build the map of node -> container IDs
     Map<String, List<String>> instanceMap = createRoleToInstanceMap();
@@ -1732,7 +1729,7 @@ public class AppState {
     //build the map of node -> containers
     Map<String, Map<String, ClusterNode>> clusterNodes =
       createRoleToClusterNodeMap();
-    cd.status = new HashMap<String, Object>();
+    cd.status = new HashMap<>();
     cd.status.put(ClusterDescriptionKeys.KEY_CLUSTER_LIVE, clusterNodes);
 
 
@@ -1750,6 +1747,9 @@ public class AppState {
       cd.setRoleOpt(rolename, ROLE_FAILED_RECENTLY_INSTANCES, role.getFailedRecently());
       cd.setRoleOpt(rolename, ROLE_NODE_FAILED_INSTANCES, role.getNodeFailed());
       cd.setRoleOpt(rolename, ROLE_PREEMPTED_INSTANCES, role.getPreempted());
+      if (role.isAntiAffinePlacement()) {
+        cd.setRoleOpt(rolename, ROLE_PENDING_AA_INSTANCES, role.getPendingAntiAffineRequests());
+      }
       Map<String, Integer> stats = role.buildStatistics();
       cd.statistics.put(rolename, stats);
     }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/737d7875/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeInstance.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeInstance.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeInstance.java
index 8d63239..cc17cf0 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeInstance.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeInstance.java
@@ -31,6 +31,7 @@ import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.Map;
 
 /**
  * A node instance -stores information about a node in the cluster.
@@ -299,9 +300,10 @@ public class NodeInstance {
 
   /**
    * Produced a serialized form which can be served up as JSON
+   * @param naming map of priority -> value for naming entries
    * @return a summary of the current role status.
    */
-  public synchronized NodeInformation serialize() {
+  public synchronized NodeInformation serialize(Map<Integer, String> naming) {
     NodeInformation info = new NodeInformation();
     info.hostname = hostname;
     // null-handling state constructor
@@ -315,7 +317,11 @@ public class NodeInstance {
     }
     info.entries = new HashMap<>(nodeEntries.size());
     for (NodeEntry nodeEntry : nodeEntries) {
-      info.entries.put(Integer.toString(nodeEntry.rolePriority), nodeEntry.serialize());
+      String name = naming.get(nodeEntry.rolePriority);
+      if (name == null) {
+        name = Integer.toString(nodeEntry.rolePriority);
+      }
+      info.entries.put(name, nodeEntry.serialize());
     }
     return info;
   }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/737d7875/slider-core/src/main/java/org/apache/slider/server/appmaster/state/ProviderAppState.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/ProviderAppState.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/ProviderAppState.java
index 1d96a1c..f544c6a 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/ProviderAppState.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/ProviderAppState.java
@@ -37,6 +37,7 @@ import org.apache.slider.server.services.utility.PatternValidator;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -291,12 +292,23 @@ public class ProviderAppState implements StateAccessForProviders {
 
   @Override
   public Map<String, NodeInformation> getNodeInformationSnapshot() {
-    return appState.getRoleHistory().getNodeInformationSnapshot();
+    return appState.getRoleHistory()
+      .getNodeInformationSnapshot(buildingNamingMap());
+  }
+
+  private Map<Integer, String> buildingNamingMap() {
+    Map<Integer, RoleStatus> statusMap = getRoleStatusMap();
+    Map<Integer, String> naming = new HashMap<>(statusMap.size());
+    for (Map.Entry<Integer, RoleStatus> entry : statusMap.entrySet()) {
+      naming.put(entry.getKey(), entry.getValue().getName());
+    }
+    return naming;
   }
 
   @Override
   public NodeInformation getNodeInformation(String hostname) {
-    return appState.getRoleHistory().getNodeInformation(hostname);
+    return appState.getRoleHistory().getNodeInformation(hostname,
+      buildingNamingMap());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/737d7875/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleHistory.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleHistory.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleHistory.java
index 4d9781d..0584d30 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleHistory.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleHistory.java
@@ -309,11 +309,14 @@ public class RoleHistory {
   /**
    * Get snapshot of the node map
    * @return a snapshot of the current node state
+   * @param naming naming map of priority to enty name; entries must be unique.
+   * It's OK to be incomplete, for those the list falls back to numbers.
    */
-  public synchronized Map<String, NodeInformation> getNodeInformationSnapshot() {
+  public synchronized Map<String, NodeInformation> getNodeInformationSnapshot(
+    Map<Integer, String> naming) {
     Map<String, NodeInformation> result = new HashMap<>(nodemap.size());
     for (Map.Entry<String, NodeInstance> entry : nodemap.entrySet()) {
-      result.put(entry.getKey(), entry.getValue().serialize());
+      result.put(entry.getKey(), entry.getValue().serialize(naming));
     }
     return result;
   }
@@ -321,11 +324,14 @@ public class RoleHistory {
   /**
    * Get the information on a node
    * @param hostname hostname
+   * @param naming naming map of priority to enty name; entries must be unique.
+   * It's OK to be incomplete, for those the list falls back to numbers.
    * @return the information about that host, or null if there is none
    */
-  public NodeInformation getNodeInformation(String hostname) {
+  public NodeInformation getNodeInformation(String hostname,
+    Map<Integer, String> naming) {
     NodeInstance nodeInstance = nodemap.get(hostname);
-    return nodeInstance != null ? nodeInstance.serialize() : null;
+    return nodeInstance != null ? nodeInstance.serialize(naming) : null;
   }
 
   /**