SLIDER-768 rename SliderAppAPI client (partly to avoid case-sensitivity issues in OS & Git)
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/bbd09a29 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/bbd09a29 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/bbd09a29 Branch: refs/heads/develop Commit: bbd09a2926cb4ef25508efcaaa9d90f36bdeed5a Parents: bcda3c2 Author: Steve Loughran <[email protected]> Authored: Mon Feb 2 15:51:25 2015 +0000 Committer: Steve Loughran <[email protected]> Committed: Mon Feb 2 15:51:25 2015 +0000 ---------------------------------------------------------------------- .../slider/client/rest/RestClientFactory.java | 2 +- .../client/rest/SliderApplicationAPIImpl.java | 254 ------------------ .../client/rest/SliderApplicationApiClient.java | 255 +++++++++++++++++++ .../rest/RestAPIClientTestDelegates.groovy | 8 +- 4 files changed, 260 insertions(+), 259 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/bbd09a29/slider-core/src/main/java/org/apache/slider/client/rest/RestClientFactory.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/rest/RestClientFactory.java b/slider-core/src/main/java/org/apache/slider/client/rest/RestClientFactory.java index dc54ba3..d337ffd 100644 --- a/slider-core/src/main/java/org/apache/slider/client/rest/RestClientFactory.java +++ b/slider-core/src/main/java/org/apache/slider/client/rest/RestClientFactory.java @@ -76,7 +76,7 @@ public class RestClientFactory { */ public SliderApplicationApi createSliderAppApiClient(WebResource appmaster) { WebResource appResource = appmaster.path(SLIDER_PATH_APPLICATION); - return new SliderApplicationApiImpl(jerseyClient, appResource); + return new SliderApplicationApiClient(jerseyClient, appResource); } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/bbd09a29/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationAPIImpl.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationAPIImpl.java b/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationAPIImpl.java deleted file mode 100644 index 676d515..0000000 --- a/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationAPIImpl.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * 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.client.rest; - -import com.google.common.base.Preconditions; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.GenericType; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.representation.Form; -import org.apache.commons.lang.StringUtils; -import org.apache.slider.api.types.ApplicationLivenessInformation; -import org.apache.slider.api.types.ComponentInformation; -import org.apache.slider.api.types.ContainerInformation; -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.restclient.HttpVerb; -import org.apache.slider.api.types.PingResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.core.MediaType; -import java.io.IOException; -import java.util.Map; - -import static org.apache.slider.server.appmaster.web.rest.RestPaths.*; - -/** - * Implementation of the {@link SliderApplicationApi} - */ -public class SliderApplicationApiImpl extends BaseRestClient - implements SliderApplicationApi { - private static final Logger log = - LoggerFactory.getLogger(SliderApplicationApiImpl.class); - private WebResource appResource; - - /** - * Create an instance - * @param jerseyClient jersey client for operations - * @param appResource resource of application API - */ - public SliderApplicationApiImpl(Client jerseyClient, WebResource appResource) { - super(jerseyClient); - this.appResource = appResource; - } - - /** - * Create a resource under the application path set up to accept - * JSON - * @param subpath path under application - * @return a resource under the application path - */ - public WebResource applicationResource(String subpath) { - Preconditions.checkArgument(!StringUtils.isEmpty(subpath), - "empty path"); - Preconditions.checkNotNull(appResource, "Null app resource"); - WebResource resource = appResource.path(subpath); - resource.accept(MediaType.APPLICATION_JSON_TYPE); - return resource; - } - - /** - * Get operation against a path under the Application - * @param <T> type expected - * @param subpath path - * @param c class to instantiate - * @return instance - * @throws IOException on any problem - */ - public <T> T getApplicationResource(String subpath, Class<T> c) - throws IOException { - return appResourceOperation(HttpVerb.GET, subpath, c); - } - - /** - * Get operation against a path under the Application - * @param <T> type expected - * @param subpath path - * @param t type info - * @return instance - * @throws IOException on any problem - */ - public <T> T getApplicationResource(String subpath, GenericType<T> t) - throws IOException { - return appResourceOperation(HttpVerb.GET, subpath, t); - } - - /** - * - * @param method method to exec - * @param <T> type expected - * @param subpath path - * @param c class to instantiate - * @return instance - * @throws IOException on any problem - */ - public <T> T appResourceOperation(HttpVerb method, String subpath, Class<T> c) - throws IOException { - WebResource resource = applicationResource(subpath); - return exec(method, resource, c); - } - - - /** - * Get operation against a path under the Application - * @param <T> type expected - * @param subpath path - * @param t type info - * @return instance - * @throws IOException on any problem - */ - public <T> T appResourceOperation(HttpVerb method, String subpath, - GenericType<T> t) - throws IOException { - WebResource resource = applicationResource(subpath); - return exec(method, resource, t); - } - - - @Override - public AggregateConf getDesiredModel() throws IOException { - return getApplicationResource(MODEL_DESIRED, AggregateConf.class); - } - - @Override - public ConfTreeOperations getDesiredAppconf() throws IOException { - ConfTree resource = - getApplicationResource(MODEL_DESIRED_APPCONF, ConfTree.class); - return new ConfTreeOperations(resource); - } - - @Override - public ConfTreeOperations getDesiredYarnResources() throws IOException { - ConfTree resource = - getApplicationResource(MODEL_DESIRED_RESOURCES, ConfTree.class); - return new ConfTreeOperations(resource); - } - - @Override - public AggregateConf getResolvedModel() throws IOException { - return getApplicationResource(MODEL_RESOLVED, AggregateConf.class); - } - - - @Override - public ConfTreeOperations getResolvedAppconf() throws IOException { - ConfTree resource = - getApplicationResource(MODEL_RESOLVED_APPCONF, ConfTree.class); - return new ConfTreeOperations(resource); - } - - @Override - public ConfTreeOperations getResolvedYarnResources() throws IOException { - ConfTree resource = - getApplicationResource(MODEL_RESOLVED_RESOURCES, ConfTree.class); - return new ConfTreeOperations(resource); - } - - @Override - public ConfTreeOperations getLiveYarnResources() throws IOException { - ConfTree resource = - getApplicationResource(LIVE_RESOURCES, ConfTree.class); - return new ConfTreeOperations(resource); - } - - @Override - public Map<String, ContainerInformation> enumContainers() throws - IOException { - return getApplicationResource(LIVE_CONTAINERS, - new GenericType<Map<String, ContainerInformation>>() { - }); - } - - @Override - public ContainerInformation getContainer(String containerId) throws - IOException { - return getApplicationResource(LIVE_CONTAINERS + "/" + containerId, - ContainerInformation.class); - } - - @Override - public Map<String, ComponentInformation> enumComponents() throws - IOException { - return getApplicationResource(LIVE_COMPONENTS, - new GenericType<Map<String, ComponentInformation>>() { - }); - } - - @Override - public ComponentInformation getComponent(String componentName) throws - IOException { - return getApplicationResource(LIVE_COMPONENTS + "/" + componentName, - ComponentInformation.class); - } - - @Override - public PingResource ping(String text) throws IOException { - return pingPost(text); - } - - /** - * Ping as a GET - * @param text text to include - * @return the response - * @throws IOException on any failure - */ - public PingResource pingGet(String text) throws IOException { - WebResource pingResource = applicationResource(ACTION_PING); - pingResource.getUriBuilder().queryParam("body", text); - return pingResource.get(PingResource.class); - } - - /** - * Ping as a POST - * @param text text to include - * @return the response - * @throws IOException on any failure - */ - public PingResource pingPost(String text) throws IOException { - WebResource pingResource = applicationResource(ACTION_PING); - pingResource.type(MediaType.APPLICATION_JSON_TYPE); - Form f = new Form(); - f.add("text", text); - return pingResource.post(PingResource.class, f); - } - - @Override - public void stop(String text) throws IOException { - WebResource resource = applicationResource(ACTION_STOP); - resource.post(text); - } - - @Override - public ApplicationLivenessInformation getApplicationLiveness() throws IOException { - return getApplicationResource(LIVE_LIVENESS, - ApplicationLivenessInformation.class); - } -} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/bbd09a29/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiClient.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiClient.java b/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiClient.java new file mode 100644 index 0000000..810c9a9 --- /dev/null +++ b/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiClient.java @@ -0,0 +1,255 @@ +/* + * 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.client.rest; + +import com.google.common.base.Preconditions; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.GenericType; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.representation.Form; +import org.apache.commons.lang.StringUtils; +import org.apache.slider.api.types.ApplicationLivenessInformation; +import org.apache.slider.api.types.ComponentInformation; +import org.apache.slider.api.types.ContainerInformation; +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.restclient.HttpVerb; +import org.apache.slider.api.types.PingResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.ws.rs.core.MediaType; +import java.io.IOException; +import java.util.Map; + +import static org.apache.slider.server.appmaster.web.rest.RestPaths.*; + +/** + * Implementation of the {@link SliderApplicationApi} + */ +public class SliderApplicationApiClient extends BaseRestClient + implements SliderApplicationApi { + private static final Logger log = + LoggerFactory.getLogger(SliderApplicationApiClient.class); + private WebResource appResource; + + /** + * Create an instance + * @param jerseyClient jersey client for operations + * @param appResource resource of application API + */ + public SliderApplicationApiClient(Client jerseyClient, + WebResource appResource) { + super(jerseyClient); + this.appResource = appResource; + } + + /** + * Create a resource under the application path set up to accept + * JSON + * @param subpath path under application + * @return a resource under the application path + */ + public WebResource applicationResource(String subpath) { + Preconditions.checkArgument(!StringUtils.isEmpty(subpath), + "empty path"); + Preconditions.checkNotNull(appResource, "Null app resource"); + WebResource resource = appResource.path(subpath); + resource.accept(MediaType.APPLICATION_JSON_TYPE); + return resource; + } + + /** + * Get operation against a path under the Application + * @param <T> type expected + * @param subpath path + * @param c class to instantiate + * @return instance + * @throws IOException on any problem + */ + public <T> T getApplicationResource(String subpath, Class<T> c) + throws IOException { + return appResourceOperation(HttpVerb.GET, subpath, c); + } + + /** + * Get operation against a path under the Application + * @param <T> type expected + * @param subpath path + * @param t type info + * @return instance + * @throws IOException on any problem + */ + public <T> T getApplicationResource(String subpath, GenericType<T> t) + throws IOException { + return appResourceOperation(HttpVerb.GET, subpath, t); + } + + /** + * + * @param method method to exec + * @param <T> type expected + * @param subpath path + * @param c class to instantiate + * @return instance + * @throws IOException on any problem + */ + public <T> T appResourceOperation(HttpVerb method, String subpath, Class<T> c) + throws IOException { + WebResource resource = applicationResource(subpath); + return exec(method, resource, c); + } + + + /** + * Get operation against a path under the Application + * @param <T> type expected + * @param subpath path + * @param t type info + * @return instance + * @throws IOException on any problem + */ + public <T> T appResourceOperation(HttpVerb method, String subpath, + GenericType<T> t) + throws IOException { + WebResource resource = applicationResource(subpath); + return exec(method, resource, t); + } + + + @Override + public AggregateConf getDesiredModel() throws IOException { + return getApplicationResource(MODEL_DESIRED, AggregateConf.class); + } + + @Override + public ConfTreeOperations getDesiredAppconf() throws IOException { + ConfTree resource = + getApplicationResource(MODEL_DESIRED_APPCONF, ConfTree.class); + return new ConfTreeOperations(resource); + } + + @Override + public ConfTreeOperations getDesiredYarnResources() throws IOException { + ConfTree resource = + getApplicationResource(MODEL_DESIRED_RESOURCES, ConfTree.class); + return new ConfTreeOperations(resource); + } + + @Override + public AggregateConf getResolvedModel() throws IOException { + return getApplicationResource(MODEL_RESOLVED, AggregateConf.class); + } + + + @Override + public ConfTreeOperations getResolvedAppconf() throws IOException { + ConfTree resource = + getApplicationResource(MODEL_RESOLVED_APPCONF, ConfTree.class); + return new ConfTreeOperations(resource); + } + + @Override + public ConfTreeOperations getResolvedYarnResources() throws IOException { + ConfTree resource = + getApplicationResource(MODEL_RESOLVED_RESOURCES, ConfTree.class); + return new ConfTreeOperations(resource); + } + + @Override + public ConfTreeOperations getLiveYarnResources() throws IOException { + ConfTree resource = + getApplicationResource(LIVE_RESOURCES, ConfTree.class); + return new ConfTreeOperations(resource); + } + + @Override + public Map<String, ContainerInformation> enumContainers() throws + IOException { + return getApplicationResource(LIVE_CONTAINERS, + new GenericType<Map<String, ContainerInformation>>() { + }); + } + + @Override + public ContainerInformation getContainer(String containerId) throws + IOException { + return getApplicationResource(LIVE_CONTAINERS + "/" + containerId, + ContainerInformation.class); + } + + @Override + public Map<String, ComponentInformation> enumComponents() throws + IOException { + return getApplicationResource(LIVE_COMPONENTS, + new GenericType<Map<String, ComponentInformation>>() { + }); + } + + @Override + public ComponentInformation getComponent(String componentName) throws + IOException { + return getApplicationResource(LIVE_COMPONENTS + "/" + componentName, + ComponentInformation.class); + } + + @Override + public PingResource ping(String text) throws IOException { + return pingPost(text); + } + + /** + * Ping as a GET + * @param text text to include + * @return the response + * @throws IOException on any failure + */ + public PingResource pingGet(String text) throws IOException { + WebResource pingResource = applicationResource(ACTION_PING); + pingResource.getUriBuilder().queryParam("body", text); + return pingResource.get(PingResource.class); + } + + /** + * Ping as a POST + * @param text text to include + * @return the response + * @throws IOException on any failure + */ + public PingResource pingPost(String text) throws IOException { + WebResource pingResource = applicationResource(ACTION_PING); + pingResource.type(MediaType.APPLICATION_JSON_TYPE); + Form f = new Form(); + f.add("text", text); + return pingResource.post(PingResource.class, f); + } + + @Override + public void stop(String text) throws IOException { + WebResource resource = applicationResource(ACTION_STOP); + resource.post(text); + } + + @Override + public ApplicationLivenessInformation getApplicationLiveness() throws IOException { + return getApplicationResource(LIVE_LIVENESS, + ApplicationLivenessInformation.class); + } +} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/bbd09a29/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy index 029cb70..ca4be4d 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy @@ -25,7 +25,7 @@ import groovy.util.logging.Slf4j import org.apache.slider.api.StateValues import org.apache.slider.api.types.ComponentInformation import org.apache.slider.api.types.ContainerInformation -import org.apache.slider.client.rest.SliderApplicationApiImpl +import org.apache.slider.client.rest.SliderApplicationApiClient import org.apache.slider.core.conf.ConfTree import org.apache.slider.core.conf.ConfTreeOperations import org.apache.slider.server.appmaster.web.rest.application.ApplicationResource @@ -40,7 +40,7 @@ import static org.apache.slider.server.appmaster.web.rest.RestPaths.* /** * Uses the Slider Application API for the tests. - * {@link SliderApplicationApiImpl} + * {@link SliderApplicationApiClient} */ @CompileStatic @Slf4j @@ -49,7 +49,7 @@ class RestAPIClientTestDelegates extends AbstractRestTestDelegate { final String appmaster; final String application; final Client jersey; - final SliderApplicationApiImpl appAPI; + final SliderApplicationApiClient appAPI; RestAPIClientTestDelegates(String appmaster, Client jersey, @@ -61,7 +61,7 @@ class RestAPIClientTestDelegates extends AbstractRestTestDelegate { WebResource amResource = jersey.resource(appmaster) amResource.type(MediaType.APPLICATION_JSON) def appResource = amResource.path(SLIDER_PATH_APPLICATION); - appAPI = new SliderApplicationApiImpl(jersey, appResource) + appAPI = new SliderApplicationApiClient(jersey, appResource) }
