SLIDER-711 container listing work
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/08b979c2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/08b979c2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/08b979c2 Branch: refs/heads/feature/SLIDER-151_REST_API Commit: 08b979c252a4067ddf79eeb21d3d76742cc10719 Parents: c52183c Author: Steve Loughran <[email protected]> Authored: Thu Dec 18 18:04:38 2014 +0000 Committer: Steve Loughran <[email protected]> Committed: Thu Dec 18 18:04:38 2014 +0000 ---------------------------------------------------------------------- .../types/SerializedContainerInformation.java | 13 +++--- .../slider/core/persist/JsonSerDeser.java | 2 + .../slider/server/appmaster/state/AppState.java | 8 ++++ .../server/appmaster/state/RoleInstance.java | 19 ++++++++- .../resources/ContainerListRefresher.java | 1 - .../slider/agent/actions/TestActionList.groovy | 2 +- .../standalone/TestStandaloneAgentWeb.groovy | 45 +++++++++++--------- .../apache/slider/test/SliderTestUtils.groovy | 1 - 8 files changed, 60 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/08b979c2/slider-core/src/main/java/org/apache/slider/api/types/SerializedContainerInformation.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/api/types/SerializedContainerInformation.java b/slider-core/src/main/java/org/apache/slider/api/types/SerializedContainerInformation.java index dfb70f5..e079e7a 100644 --- a/slider-core/src/main/java/org/apache/slider/api/types/SerializedContainerInformation.java +++ b/slider-core/src/main/java/org/apache/slider/api/types/SerializedContainerInformation.java @@ -18,6 +18,7 @@ package org.apache.slider.api.types; +import org.apache.hadoop.registry.client.binding.JsonSerDeser; import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.map.annotate.JsonSerialize; @@ -43,14 +44,14 @@ public class SerializedContainerInformation { * or the log cannot be picked up */ public String[] output; + public String host; + public String hostURL; @Override public String toString() { - final StringBuilder sb = - new StringBuilder("SerializedContainerInformation{"); - sb.append("containerId='").append(containerId).append('\''); - sb.append(", component='").append(component).append('\''); - sb.append('}'); - return sb.toString(); + JsonSerDeser<SerializedContainerInformation> serDeser = + new JsonSerDeser<SerializedContainerInformation>( + SerializedContainerInformation.class); + return serDeser.toString(this); } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/08b979c2/slider-core/src/main/java/org/apache/slider/core/persist/JsonSerDeser.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/core/persist/JsonSerDeser.java b/slider-core/src/main/java/org/apache/slider/core/persist/JsonSerDeser.java index 51aefed..c5908bb 100644 --- a/slider-core/src/main/java/org/apache/slider/core/persist/JsonSerDeser.java +++ b/slider-core/src/main/java/org/apache/slider/core/persist/JsonSerDeser.java @@ -265,4 +265,6 @@ public class JsonSerDeser<T> { mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); return mapper.writeValueAsString(instance); } + + } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/08b979c2/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 61a6077..e9d0371 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 @@ -791,9 +791,13 @@ public class AppState { container.setNodeHttpAddress(nodeHttpAddress); RoleInstance am = new RoleInstance(container); am.role = SliderKeys.COMPONENT_AM; + am.roleId = SliderKeys.ROLE_AM_PRIORITY_INDEX; + am.createTime = System.currentTimeMillis(); + am.startTime = System.currentTimeMillis(); appMasterNode = am; //it is also added to the set of live nodes getLiveNodes().put(containerId, am); + putOwnedContainer(containerId, am); // patch up the role status RoleStatus roleStatus = roleStatusMap.get( @@ -1860,6 +1864,10 @@ public class AppState { List<AbstractRMOperation> operations = new ArrayList<AbstractRMOperation>(targets.size()); for (RoleInstance instance : targets) { + if (instance.roleId == SliderKeys.ROLE_AM_PRIORITY_INDEX) { + // don't worry about the AM + continue; + } Container possible = instance.container; ContainerId id = possible.getId(); if (!instance.released) { http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/08b979c2/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 2790a0d..ad4af1d 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 @@ -233,11 +233,26 @@ public final class RoleInstance implements Cloneable { ProtocolTypes.PROTOCOL_TCP, host, port); addEndpoint(epr); } - + + /** + * Serialize. Some data structures (e.g output) + * may be shared + * @return a serialized form for marshalling as JSON + */ public SerializedContainerInformation serialize() { SerializedContainerInformation info = new SerializedContainerInformation(); info.containerId = id; - + info.component = role; + info.startTime = startTime; + info.createTime = createTime; + info.diagnostics = diagnostics; + info.state = state; + info.host = host; + info.hostURL = hostURL; + info.released = released ? Boolean.TRUE : null; + if (output != null) { + info.output = output; + } return info; } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/08b979c2/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 9049186..7e74062 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 @@ -19,7 +19,6 @@ package org.apache.slider.server.appmaster.web.rest.application.resources; import org.apache.slider.api.types.SerializedContainerInformation; -import org.apache.slider.core.conf.ConfTree; import org.apache.slider.server.appmaster.state.RoleInstance; import org.apache.slider.server.appmaster.state.StateAccessForProviders; http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/08b979c2/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionList.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionList.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionList.groovy index 6baf5b1..bf65b0f 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionList.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionList.groovy @@ -53,7 +53,7 @@ class TestActionList extends AgentMiniClusterTestBase { */ @Test - public void testSuite() throws Throwable { + public void testActionListSuite() throws Throwable { testListThisUserNoClusters() testListLiveCluster() testListMissingCluster() http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/08b979c2/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 9b614d2..4312cf3 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 @@ -21,9 +21,9 @@ package org.apache.slider.agent.standalone import groovy.transform.CompileStatic 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 org.apache.slider.api.types.SerializedContainerInformation import static org.apache.slider.api.ResourceKeys.* import static org.apache.slider.api.StatusKeys.* @@ -31,7 +31,6 @@ import org.apache.slider.client.SliderClient import static org.apache.slider.common.SliderKeys.*; import org.apache.slider.core.conf.ConfTreeOperations import org.apache.slider.core.main.ServiceLauncher -import org.apache.slider.core.persist.ConfTreeSerDeser import static org.apache.slider.server.appmaster.web.rest.RestPaths.*; import org.junit.Test @@ -41,7 +40,9 @@ import static org.apache.slider.server.appmaster.management.MetricsKeys.* @CompileStatic @Slf4j class TestStandaloneAgentWeb extends AgentMiniClusterTestBase { - + + public static final int WEB_STARTUP_TIME = 30000 + @Test public void testStandaloneAgentWeb() throws Throwable { @@ -65,10 +66,11 @@ class TestStandaloneAgentWeb extends AgentMiniClusterTestBase { initConnectionFactory(launcher.configuration) - execHttpRequest(30000) { + execHttpRequest(WEB_STARTUP_TIME) { GET(realappmaster) } - execHttpRequest(30000) { + + execHttpRequest(WEB_STARTUP_TIME) { def metrics = GET(realappmaster, SYSTEM_METRICS) log.info metrics } @@ -99,7 +101,7 @@ class TestStandaloneAgentWeb extends AgentMiniClusterTestBase { }) // now some REST gets - describe "Application REST GETs" + describe "Application REST ${LIVE_RESOURCES}" ConfTreeOperations tree = fetchConfigTree(conf, appmaster, LIVE_RESOURCES) @@ -114,20 +116,23 @@ class TestStandaloneAgentWeb extends AgentMiniClusterTestBase { assert 0 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_COMPLETED) assert 0 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_RELEASING) - } - - public ConfTreeOperations fetchConfigTree( - YarnConfiguration conf, - String appmaster, - String subpath) { - ConfTreeSerDeser serDeser = new ConfTreeSerDeser() - - def json = getWebPage( - appmaster, - SLIDER_PATH_APPLICATION + subpath) - def ctree = serDeser.fromJson(json) - ConfTreeOperations tree = new ConfTreeOperations(ctree) - return tree + describe "Application REST ${LIVE_CONTAINERS}" + + Map<String, SerializedContainerInformation> map = + fetchType(HashMap, appmaster, LIVE_CONTAINERS) + assert map.size() == 1 + log.info "${map}" + SerializedContainerInformation info = (SerializedContainerInformation) map.values()[0] + assert info.containerId + assert map[info.containerId] + + assert info.component == COMPONENT_AM + assert info.createTime > 0 + assert info.exitCode == null + assert info.output == null + assert info.released == null + assert info.state == StateValues.STATE_LIVE + } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/08b979c2/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 b672498..f9857a8 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 @@ -54,7 +54,6 @@ 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
