SLIDER-729 move state int enum from ConfigurationDescription to standalone

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

Branch: refs/heads/feature/SLIDER-151_REST_API
Commit: c52183c6cdf657ea680ae1a14a475c5eead39bc6
Parents: a3e2297
Author: Steve Loughran <[email protected]>
Authored: Thu Dec 18 18:03:11 2014 +0000
Committer: Steve Loughran <[email protected]>
Committed: Thu Dec 18 18:03:11 2014 +0000

----------------------------------------------------------------------
 .../apache/slider/api/ClusterDescription.java   | 12 ++---
 .../java/org/apache/slider/api/StateValues.java | 53 ++++++++++++++++++++
 .../org/apache/slider/client/SliderClient.java  |  3 +-
 .../slider/client/SliderClusterOperations.java  |  5 +-
 .../slider/server/appmaster/state/AppState.java | 15 +++---
 .../server/appmaster/state/RoleInstance.java    |  2 +-
 .../resources/ContainerListRefresher.java       |  3 ++
 .../standalone/TestStandaloneAgentWeb.groovy    |  1 +
 .../apache/slider/test/SliderTestUtils.groovy   | 25 ++++++++-
 9 files changed, 101 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c52183c6/slider-core/src/main/java/org/apache/slider/api/ClusterDescription.java
----------------------------------------------------------------------
diff --git 
a/slider-core/src/main/java/org/apache/slider/api/ClusterDescription.java 
b/slider-core/src/main/java/org/apache/slider/api/ClusterDescription.java
index 3b0fd2b..8bcff0e 100644
--- a/slider-core/src/main/java/org/apache/slider/api/ClusterDescription.java
+++ b/slider-core/src/main/java/org/apache/slider/api/ClusterDescription.java
@@ -107,28 +107,28 @@ public class ClusterDescription implements Cloneable {
    * Specification is incomplete & cannot
    * be used: {@value}
    */
-  public static final int STATE_INCOMPLETE = 0;
+  public static final int STATE_INCOMPLETE = StateValues.STATE_INCOMPLETE;
 
   /**
    * Spec has been submitted: {@value}
    */
-  public static final int STATE_SUBMITTED = 1;
+  public static final int STATE_SUBMITTED = StateValues.STATE_SUBMITTED;
   /**
    * Cluster created: {@value}
    */
-  public static final int STATE_CREATED = 2;
+  public static final int STATE_CREATED = StateValues.STATE_CREATED;
   /**
    * Live: {@value}
    */
-  public static final int STATE_LIVE = 3;
+  public static final int STATE_LIVE = StateValues.STATE_LIVE;
   /**
    * Stopped
    */
-  public static final int STATE_STOPPED = 4;
+  public static final int STATE_STOPPED = StateValues.STATE_STOPPED;
   /**
    * destroyed
    */
-  public static final int STATE_DESTROYED = 5;
+  public static final int STATE_DESTROYED = StateValues.STATE_DESTROYED;
   
   /**
    * When was the cluster specification created?

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c52183c6/slider-core/src/main/java/org/apache/slider/api/StateValues.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/api/StateValues.java 
b/slider-core/src/main/java/org/apache/slider/api/StateValues.java
new file mode 100644
index 0000000..03751e1
--- /dev/null
+++ b/slider-core/src/main/java/org/apache/slider/api/StateValues.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.slider.api;
+
+/**
+ * Enumeration of state values
+ */
+public class StateValues {
+
+  /**
+   * Specification is incomplete & cannot
+   * be used: {@value}
+   */
+  public static final int STATE_INCOMPLETE = 0;
+
+  /**
+   * Spec has been submitted: {@value}
+   */
+  public static final int STATE_SUBMITTED = 1;
+  /**
+   * Cluster created: {@value}
+   */
+  public static final int STATE_CREATED = 2;
+  /**
+   * Live: {@value}
+   */
+  public static final int STATE_LIVE = 3;
+  /**
+   * Stopped
+   */
+  public static final int STATE_STOPPED = 4;
+  /**
+   * destroyed
+   */
+  public static final int STATE_DESTROYED = 5;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c52183c6/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
----------------------------------------------------------------------
diff --git 
a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java 
b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
index f9aae6f..225b0e0 100644
--- a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
+++ b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
@@ -65,6 +65,7 @@ import org.apache.slider.api.InternalKeys;
 import org.apache.slider.api.OptionKeys;
 import org.apache.slider.api.ResourceKeys;
 import org.apache.slider.api.SliderClusterProtocol;
+import org.apache.slider.api.StateValues;
 import org.apache.slider.api.proto.Messages;
 import org.apache.slider.common.Constants;
 import org.apache.slider.common.SliderExitCodes;
@@ -2769,7 +2770,7 @@ public class SliderClient extends 
AbstractSliderLaunchedService implements RunSe
         .getClusterDescription();
     log.info("Slider AppMaster is accessible");
 
-    if (clusterDescription.state == ClusterDescription.STATE_LIVE) {
+    if (clusterDescription.state == StateValues.STATE_LIVE) {
       AggregateConf instanceDefinition = clusterOperations
           .getInstanceDefinition();
       String imagePath = instanceDefinition.getInternalOperations().get(

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c52183c6/slider-core/src/main/java/org/apache/slider/client/SliderClusterOperations.java
----------------------------------------------------------------------
diff --git 
a/slider-core/src/main/java/org/apache/slider/client/SliderClusterOperations.java
 
b/slider-core/src/main/java/org/apache/slider/client/SliderClusterOperations.java
index e99897c..d722902 100644
--- 
a/slider-core/src/main/java/org/apache/slider/client/SliderClusterOperations.java
+++ 
b/slider-core/src/main/java/org/apache/slider/client/SliderClusterOperations.java
@@ -23,6 +23,7 @@ import org.apache.hadoop.yarn.exceptions.YarnException;
 import org.apache.slider.api.ClusterDescription;
 import org.apache.slider.api.ClusterNode;
 import org.apache.slider.api.SliderClusterProtocol;
+import org.apache.slider.api.StateValues;
 import org.apache.slider.api.proto.Messages;
 import org.apache.slider.common.tools.Duration;
 import org.apache.slider.core.conf.AggregateConf;
@@ -245,7 +246,7 @@ public class SliderClusterOperations {
     throws WaitTimeoutException, IOException, YarnException {
     Duration duration = new Duration(timeout).start();
     boolean live = false;
-    int state = ClusterDescription.STATE_CREATED;
+    int state = StateValues.STATE_CREATED;
 
     log.info("Waiting {} millis for a live node in role {}", timeout, role);
     while (!live) {
@@ -260,7 +261,7 @@ public class SliderClusterOperations {
         roleInstance = getNode(containers[0]);
         if (roleInstance != null) {
           state = roleInstance.state;
-          live = state >= ClusterDescription.STATE_LIVE;
+          live = state >= StateValues.STATE_LIVE;
         }
       }
       if (!live) {

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c52183c6/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 ddba5e2..61a6077 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
@@ -35,6 +35,7 @@ import 
org.apache.hadoop.yarn.api.records.impl.pb.ContainerPBImpl;
 import org.apache.hadoop.yarn.client.api.AMRMClient;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
 import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
+import static org.apache.slider.api.StateValues.*;
 import org.apache.slider.api.ClusterDescription;
 import org.apache.slider.api.ClusterDescriptionKeys;
 import org.apache.slider.api.ClusterDescriptionOperations;
@@ -552,7 +553,7 @@ public class AppState {
   public void initClusterStatus() {
     //copy into cluster status. 
     ClusterDescription status = ClusterDescription.copy(clusterSpec);
-    status.state = ClusterDescription.STATE_CREATED;
+    status.state = STATE_CREATED;
     MapOperations infoOps = new MapOperations("info", status.info);
     infoOps.mergeWithoutOverwrite(applicationInfo);
     SliderUtils.addBuildInfo(infoOps, "status");
@@ -572,7 +573,7 @@ public class AppState {
           StatusKeys.INFO_CREATE_TIME_MILLIS,
           now);
     }
-    status.state = ClusterDescription.STATE_LIVE;
+    status.state = STATE_LIVE;
 
       //set the app state to this status
     setClusterStatus(status);
@@ -819,7 +820,7 @@ public class AppState {
    * indicating the spawned process is up and running.
    */
   public void noteAMLive() {
-    appMasterNode.state = ClusterDescription.STATE_LIVE;
+    appMasterNode.state = STATE_LIVE;
   }
 
   public RoleInstance getAppMasterNode() {
@@ -1074,7 +1075,7 @@ public class AppState {
    */
   public void containerStartSubmitted(Container container,
                                       RoleInstance instance) {
-    instance.state = ClusterDescription.STATE_SUBMITTED;
+    instance.state = STATE_SUBMITTED;
     instance.container = container;
     instance.createTime = now();
     getStartingNodes().put(container.getId(), instance);
@@ -1275,7 +1276,7 @@ public class AppState {
       throw new YarnRuntimeException(
         "Container "+ containerId +"%s is already started");
     }
-    instance.state = ClusterDescription.STATE_LIVE;
+    instance.state = STATE_LIVE;
     RoleStatus roleStatus = lookupRoleStatus(instance.roleId);
     roleStatus.incStarted();
     Container container = instance.container;
@@ -1463,7 +1464,7 @@ public class AppState {
     log.info("Removing node ID {}", id);
     RoleInstance node = getLiveNodes().remove(id);
     if (node != null) {
-      node.state = ClusterDescription.STATE_DESTROYED;
+      node.state = STATE_DESTROYED;
       node.exitCode = status.getExitStatus();
       node.diagnostics = status.getDiagnostics();
       getCompletedNodes().put(id, node);
@@ -2007,7 +2008,7 @@ public class AppState {
     instance.environment = new String[0];
     instance.container = container;
     instance.createTime = now();
-    instance.state = ClusterDescription.STATE_LIVE;
+    instance.state = STATE_LIVE;
     putOwnedContainer(cid, instance);
     //role history gets told
     roleHistory.onContainerAssigned(container);

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c52183c6/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleInstance.java
----------------------------------------------------------------------
diff --git 
a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleInstance.java
 
b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleInstance.java
index 1488fb7..2790a0d 100644
--- 
a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleInstance.java
+++ 
b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleInstance.java
@@ -59,7 +59,7 @@ public final class RoleInstance implements Cloneable {
   public int roleId;
 
   /**
-   * state from {@link ClusterDescription}
+   * state from {@link StateValues}
    */
   public int state;
 

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c52183c6/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ContainerListRefresher.java
----------------------------------------------------------------------
diff --git 
a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ContainerListRefresher.java
 
b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ContainerListRefresher.java
index 7a48509..9049186 100644
--- 
a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ContainerListRefresher.java
+++ 
b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ContainerListRefresher.java
@@ -27,6 +27,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+/**
+ * Refresh the container list.
+ */
 public class ContainerListRefresher implements ResourceRefresher<Map<String, 
SerializedContainerInformation>> {
 
   private final StateAccessForProviders state;

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c52183c6/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAgentWeb.groovy
----------------------------------------------------------------------
diff --git 
a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAgentWeb.groovy
 
b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAgentWeb.groovy
index cbb340f..9b614d2 100644
--- 
a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAgentWeb.groovy
+++ 
b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAgentWeb.groovy
@@ -23,6 +23,7 @@ import groovy.util.logging.Slf4j
 import org.apache.hadoop.yarn.api.records.ApplicationReport
 import org.apache.hadoop.yarn.conf.YarnConfiguration
 import org.apache.slider.agent.AgentMiniClusterTestBase
+import org.apache.slider.api.StateValues
 
 import static org.apache.slider.api.ResourceKeys.*
 import static org.apache.slider.api.StatusKeys.*

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c52183c6/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
----------------------------------------------------------------------
diff --git 
a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy 
b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
index 39dfe39..b672498 100644
--- a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
@@ -41,18 +41,24 @@ import org.apache.hadoop.yarn.webapp.NotFoundException
 import org.apache.slider.api.ClusterDescription
 import org.apache.slider.api.ClusterNode
 import org.apache.slider.api.RoleKeys
+import org.apache.slider.api.StateValues
 import org.apache.slider.client.SliderClient
 import org.apache.slider.common.params.Arguments
 import org.apache.slider.common.tools.Duration
 import org.apache.slider.common.tools.SliderUtils
 import org.apache.slider.core.conf.AggregateConf
+import org.apache.slider.core.conf.ConfTree
+import org.apache.slider.core.conf.ConfTreeOperations
 import org.apache.slider.core.exceptions.BadClusterStateException
 import org.apache.slider.core.exceptions.SliderException
 import org.apache.slider.core.exceptions.WaitTimeoutException
 import org.apache.slider.core.main.ServiceLaunchException
 import org.apache.slider.core.main.ServiceLauncher
+import org.apache.slider.core.persist.ConfTreeSerDeser
+import org.apache.slider.core.persist.JsonSerDeser
 import org.apache.slider.core.registry.docstore.PublishedConfigSet
 import org.apache.slider.server.appmaster.web.HttpCacheHeaders
+import org.apache.slider.server.appmaster.web.rest.RestPaths
 import org.apache.slider.server.services.workflow.ForkedProcessService
 import org.junit.Assert
 import org.junit.Assume
@@ -367,7 +373,7 @@ class SliderTestUtils extends Assert {
       String role)
   throws WaitTimeoutException, IOException, SliderException {
     int state = client.waitForRoleInstanceLive(role, spintime);
-    return state == ClusterDescription.STATE_LIVE;
+    return state == StateValues.STATE_LIVE;
   }
 
   public static ClusterDescription dumpClusterStatus(
@@ -1162,4 +1168,21 @@ class SliderTestUtils extends Assert {
     }
   }
 
+  public <T> T fetchType(
+      Class<T> clazz, String appmaster, String subpath) {
+    JsonSerDeser serDeser = new JsonSerDeser(clazz)
+
+    def json = getWebPage(
+        appmaster,
+        RestPaths.SLIDER_PATH_APPLICATION + subpath)
+    T ctree = (T) serDeser.fromJson(json)
+    return ctree
+  }
+  
+  public ConfTreeOperations fetchConfigTree(
+      YarnConfiguration conf, String appmaster, String subpath) {
+    ConfTree ctree = fetchType(ConfTree, appmaster, subpath)
+    ConfTreeOperations tree = new ConfTreeOperations(ctree)
+    return tree
+  }
 }

Reply via email to