SLIDER-715 stub REST stop action with test
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/52e55947 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/52e55947 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/52e55947 Branch: refs/heads/develop Commit: 52e559470f082c07acbd132c58a77b2893d63f2e Parents: 68d57cf Author: Steve Loughran <[email protected]> Authored: Wed Jan 14 11:22:49 2015 +0000 Committer: Steve Loughran <[email protected]> Committed: Wed Jan 14 16:28:27 2015 +0000 ---------------------------------------------------------------------- .../server/appmaster/web/rest/RestPaths.java | 1 + .../rest/application/ApplicationResource.java | 33 ++++++++-- .../application/actions/RestActionPing.java | 2 +- .../application/actions/RestActionStop.java | 66 ++++++++++++++++++++ .../rest/application/actions/StopResponse.java | 29 +++++++++ .../slider/agent/rest/RestTestDelegates.groovy | 25 +++++++- .../slider/agent/rest/TestStandaloneREST.groovy | 2 + 7 files changed, 150 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/52e55947/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java index 58520f5..35f3e13 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java @@ -145,4 +145,5 @@ public class RestPaths { public static final String ACTION = "/action"; public static final String ACTION_PING = ACTION + "/ping"; + public static final String ACTION_STOP = ACTION + "/stop"; } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/52e55947/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java index af310b1..6734f73 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java @@ -33,6 +33,8 @@ import org.apache.slider.server.appmaster.web.WebAppApi; import org.apache.slider.server.appmaster.web.rest.AbstractSliderResource; import static org.apache.slider.server.appmaster.web.rest.RestPaths.*; +import org.apache.slider.server.appmaster.web.rest.application.actions.RestActionStop; +import org.apache.slider.server.appmaster.web.rest.application.actions.StopResponse; import org.apache.slider.server.appmaster.web.rest.application.resources.AggregateModelRefresher; import org.apache.slider.server.appmaster.web.rest.application.resources.AppconfRefresher; import org.apache.slider.server.appmaster.web.rest.application.resources.CachedContent; @@ -41,6 +43,7 @@ import org.apache.slider.server.appmaster.web.rest.application.resources.Content import org.apache.slider.server.appmaster.web.rest.application.resources.LiveComponentsRefresher; import org.apache.slider.server.appmaster.web.rest.application.resources.LiveResourcesRefresher; import org.apache.slider.server.appmaster.web.rest.application.actions.RestActionPing; +import org.apache.slider.server.appmaster.web.rest.application.resources.PingResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -301,10 +304,16 @@ public class ApplicationResource extends AbstractSliderResource { } } + /* ************************************************************************ + + ACTION PING + + **************************************************************************/ + @GET @Path(ACTION_PING) @Produces({APPLICATION_JSON}) - public Object actionPingGet(@Context HttpServletRequest request, + public PingResource actionPingGet(@Context HttpServletRequest request, @Context UriInfo uriInfo) { return new RestActionPing().ping(request, uriInfo, ""); } @@ -312,7 +321,7 @@ public class ApplicationResource extends AbstractSliderResource { @POST @Path(ACTION_PING) @Produces({APPLICATION_JSON}) - public Object actionPingPost(@Context HttpServletRequest request, + public PingResource actionPingPost(@Context HttpServletRequest request, @Context UriInfo uriInfo, String body) { return new RestActionPing().ping(request, uriInfo, body); @@ -322,7 +331,7 @@ public class ApplicationResource extends AbstractSliderResource { @Path(ACTION_PING) @Consumes({TEXT_PLAIN}) @Produces({APPLICATION_JSON}) - public Object actionPingPut(@Context HttpServletRequest request, + public PingResource actionPingPut(@Context HttpServletRequest request, @Context UriInfo uriInfo, String body) { return new RestActionPing().ping(request, uriInfo, body); @@ -332,7 +341,7 @@ public class ApplicationResource extends AbstractSliderResource { @Path(ACTION_PING) @Consumes({APPLICATION_JSON}) @Produces({APPLICATION_JSON}) - public Object actionPingDelete(@Context HttpServletRequest request, + public PingResource actionPingDelete(@Context HttpServletRequest request, @Context UriInfo uriInfo) { return new RestActionPing().ping(request, uriInfo, ""); } @@ -345,4 +354,20 @@ public class ApplicationResource extends AbstractSliderResource { return new RestActionPing().ping(request, uriInfo, ""); } + /* ************************************************************************ + + ACTION STOP + + **************************************************************************/ + + + @POST + @Path(ACTION_STOP) + @Produces({APPLICATION_JSON}) + public StopResponse actionStop(@Context HttpServletRequest request, + @Context UriInfo uriInfo, + String body) { + return new RestActionStop(slider).stop(request, uriInfo, body); + } + } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/52e55947/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionPing.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionPing.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionPing.java index 65126ac..f20f296 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionPing.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionPing.java @@ -34,7 +34,7 @@ public class RestActionPing { public RestActionPing() { } - public Object ping(HttpServletRequest request, UriInfo uriInfo, String body) { + public PingResource ping(HttpServletRequest request, UriInfo uriInfo, String body) { String verb = request.getMethod(); log.info("Ping {}", verb); PingResource pingResource = new PingResource(); http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/52e55947/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionStop.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionStop.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionStop.java new file mode 100644 index 0000000..703c1e7 --- /dev/null +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionStop.java @@ -0,0 +1,66 @@ +/* + * 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.server.appmaster.web.rest.application.actions; + +import org.apache.hadoop.yarn.api.records.FinalApplicationStatus; +import org.apache.slider.core.main.LauncherExitCodes; +import org.apache.slider.server.appmaster.actions.ActionStopSlider; +import org.apache.slider.server.appmaster.web.WebAppApi; +import org.apache.slider.server.appmaster.web.rest.application.resources.PingResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.UriInfo; +import java.util.Locale; +import java.util.concurrent.TimeUnit; + +public class RestActionStop { + private static final Logger log = + LoggerFactory.getLogger(RestActionStop.class); + + private final WebAppApi slider; + + public RestActionStop(WebAppApi slider) { + this.slider = slider; + } + + public StopResponse stop(HttpServletRequest request, UriInfo uriInfo, String body) { + String verb = request.getMethod(); + log.info("Ping {}", verb); + StopResponse response = new StopResponse(); + response.verb = verb; + long time = System.currentTimeMillis(); + String text = + String.format(Locale.ENGLISH, + "Stopping action %s received at %tc", + verb, time); + response.text = text; + ActionStopSlider stopSlider = + new ActionStopSlider(text, + 1000, TimeUnit.MILLISECONDS, + LauncherExitCodes.EXIT_SUCCESS, + FinalApplicationStatus.SUCCEEDED, + text); + log.info("SliderAppMasterApi.stopCluster: {}", stopSlider); +// slider.schedule(stopSlider); + + return response; + } +} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/52e55947/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/StopResponse.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/StopResponse.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/StopResponse.java new file mode 100644 index 0000000..9af6a22 --- /dev/null +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/StopResponse.java @@ -0,0 +1,29 @@ +/* + * 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.server.appmaster.web.rest.application.actions; + +import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.codehaus.jackson.map.annotate.JsonSerialize; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) +public class StopResponse { + String verb; + public String text; +} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/52e55947/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy index 430ddf1..5383425 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy @@ -67,7 +67,6 @@ class RestTestDelegates extends SliderTestUtils { getWebPage(appmaster, SYSTEM_METRICS_JSON) } - @Test public void testLiveResources() throws Throwable { describe "Live Resources" ConfTreeOperations tree = fetchConfigTree(appmaster, LIVE_RESOURCES) @@ -84,8 +83,7 @@ class RestTestDelegates extends SliderTestUtils { assert 0 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_COMPLETED) assert 0 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_RELEASING) } - - @Test + public void testLiveContainers() throws Throwable { describe "Application REST ${LIVE_CONTAINERS}" @@ -231,5 +229,26 @@ class RestTestDelegates extends SliderTestUtils { return outcome } + /** + * Test the stop command. + * Important: once executed, the AM is no longer there. + * This must be the last test in the sequence. + */ + public void testStop() { + String target = appendToURL(appmaster, SLIDER_PATH_APPLICATION, ACTION_STOP) + describe "Stop URL $target" + + + URL targetUrl = new URL(target) + def outcome = connectionFactory.execHttpOperation( + HttpVerb.POST, + targetUrl, + new byte[0], + MediaType.TEXT_PLAIN) + log.info "Stopped: $outcome" + + + } + } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/52e55947/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy index 4b907e1..7ae8e2f 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy @@ -112,6 +112,8 @@ class TestStandaloneREST extends AgentMiniClusterTestBase { // and via the proxy proxied.testRESTModel() } + + direct.testStop(); }
