http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderAMWebApp.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderAMWebApp.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderAMWebApp.java deleted file mode 100644 index 0cac430..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderAMWebApp.java +++ /dev/null @@ -1,109 +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.server.appmaster.web; - -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.health.HealthCheckRegistry; -import com.codahale.metrics.servlets.HealthCheckServlet; -import com.codahale.metrics.servlets.MetricsServlet; -import com.codahale.metrics.servlets.PingServlet; -import com.codahale.metrics.servlets.ThreadDumpServlet; -import com.google.common.base.Preconditions; -import com.sun.jersey.api.container.filter.GZIPContentEncodingFilter; -import com.sun.jersey.api.core.ResourceConfig; -import com.sun.jersey.guice.spi.container.servlet.GuiceContainer; -import com.sun.jersey.spi.container.servlet.ServletContainer; -import org.apache.hadoop.yarn.webapp.Dispatcher; -import org.apache.hadoop.yarn.webapp.GenericExceptionHandler; -import org.apache.hadoop.yarn.webapp.WebApp; -import org.apache.slider.server.appmaster.web.rest.AMWadlGeneratorConfig; -import org.apache.slider.server.appmaster.web.rest.AMWebServices; -import org.apache.slider.server.appmaster.web.rest.SliderJacksonJaxbJsonProvider; - -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import static org.apache.slider.server.appmaster.web.rest.RestPaths.*; - -/** - * - */ -public class SliderAMWebApp extends WebApp { - public static final String BASE_PATH = "slideram"; - public static final String CONTAINER_STATS = "/stats"; - public static final String CLUSTER_SPEC = "/spec"; - - private final WebAppApi webAppApi; - - public SliderAMWebApp(WebAppApi webAppApi) { - Preconditions.checkArgument(webAppApi != null, "webAppApi null"); - this.webAppApi = webAppApi; - } - - @Override - public void setup() { - Logger.getLogger("com.sun.jersey").setLevel(Level.FINEST); - // Make one of these to ensure that the jax-b annotations - // are properly picked up. - bind(SliderJacksonJaxbJsonProvider.class); - - // Get exceptions printed to the screen - bind(GenericExceptionHandler.class); - // bind the REST interface - bind(AMWebServices.class); - - //bind(AMAgentWebServices.class); - route("/", SliderAMController.class); - route(CONTAINER_STATS, SliderAMController.class, "containerStats"); - route(CLUSTER_SPEC, SliderAMController.class, "specification"); - } - - @Override - public void configureServlets() { - setup(); - - serve("/", "/__stop").with(Dispatcher.class); - - for (String path : this.getServePathSpecs()) { - serve(path).with(Dispatcher.class); - } - - serve(SYSTEM_HEALTHCHECK) - .with(new HealthCheckServlet(new HealthCheckRegistry())); - serve(SYSTEM_METRICS).with(new MetricsServlet(new MetricRegistry())); - serve(SYSTEM_PING).with(new PingServlet()); - serve(SYSTEM_THREADS).with(new ThreadDumpServlet()); - - String regex = "(?!/ws)"; - serveRegex(regex).with(SliderDefaultWrapperServlet.class); - - Map<String, String> params = new HashMap<>(); - params.put(ResourceConfig.FEATURE_IMPLICIT_VIEWABLES, "true"); - params.put(ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true"); - params.put(ResourceConfig.FEATURE_XMLROOTELEMENT_PROCESSING, "true"); - params.put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, GZIPContentEncodingFilter.class.getName()); - params.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, GZIPContentEncodingFilter.class.getName()); - //params.put("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.LoggingFilter"); - //params.put("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.LoggingFilter"); - //params.put("com.sun.jersey.config.feature.Trace", "true"); - params.put("com.sun.jersey.config.property.WadlGeneratorConfig", - AMWadlGeneratorConfig.CLASSNAME); - filter("/*").through(GuiceContainer.class, params); - } -}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderDefaultWrapperServlet.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderDefaultWrapperServlet.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderDefaultWrapperServlet.java deleted file mode 100644 index 12c41ac..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderDefaultWrapperServlet.java +++ /dev/null @@ -1,48 +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.server.appmaster.web; - -import com.google.inject.Singleton; -import org.apache.hadoop.yarn.webapp.DefaultWrapperServlet; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -/** - * - */ -@Singleton -public class SliderDefaultWrapperServlet extends DefaultWrapperServlet { - @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - RequestDispatcher rd = getServletContext().getNamedDispatcher("default"); - - HttpServletRequest wrapped = new HttpServletRequestWrapper(req) { - public String getServletPath() { - return ""; - } - }; - - rd.forward(wrapped, resp); - - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/WebAppApi.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/WebAppApi.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/WebAppApi.java deleted file mode 100644 index 02f3f0c..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/WebAppApi.java +++ /dev/null @@ -1,52 +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.server.appmaster.web; - -import org.apache.hadoop.registry.client.api.RegistryOperations; -import org.apache.slider.server.appmaster.actions.QueueAccess; -import org.apache.slider.server.appmaster.management.MetricsAndMonitoring; -import org.apache.slider.server.appmaster.state.AppState; -import org.apache.slider.server.appmaster.state.StateAccessForProviders; - -/** - * Interface to pass information from the Slider AppMaster to the WebApp - */ -public interface WebAppApi { - - /** - * The {@link AppState} for the current cluster - */ - StateAccessForProviders getAppState(); - - /** - * Registry operations accessor - * @return registry access - */ - RegistryOperations getRegistryOperations(); - - /** - * Metrics and monitoring service - * @return the (singleton) instance - */ - MetricsAndMonitoring getMetricsAndMonitoring(); - - /** - * Get the queue accessor - * @return the immediate and scheduled queues - */ - QueueAccess getQueues(); -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/WebAppApiImpl.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/WebAppApiImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/WebAppApiImpl.java deleted file mode 100644 index f88f501..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/WebAppApiImpl.java +++ /dev/null @@ -1,69 +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.server.appmaster.web; - -import org.apache.hadoop.registry.client.api.RegistryOperations; -import org.apache.slider.server.appmaster.actions.QueueAccess; -import org.apache.slider.server.appmaster.management.MetricsAndMonitoring; -import org.apache.slider.server.appmaster.state.StateAccessForProviders; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * - */ -public class WebAppApiImpl implements WebAppApi { - private static final Logger log = LoggerFactory.getLogger(WebAppApiImpl.class); - - protected final StateAccessForProviders appState; - private final RegistryOperations registryOperations; - private final MetricsAndMonitoring metricsAndMonitoring; - private final QueueAccess queues; - - public WebAppApiImpl(StateAccessForProviders appState, - RegistryOperations registryOperations, - MetricsAndMonitoring metricsAndMonitoring, QueueAccess queues) { - checkNotNull(appState); - this.queues = queues; - - this.registryOperations = registryOperations; - this.appState = appState; - this.metricsAndMonitoring = metricsAndMonitoring; - } - - @Override - public StateAccessForProviders getAppState() { - return appState; - } - - @Override - public RegistryOperations getRegistryOperations() { - return registryOperations; - } - - @Override - public MetricsAndMonitoring getMetricsAndMonitoring() { - return metricsAndMonitoring; - } - - @Override - public QueueAccess getQueues() { - return queues; - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/AppLayout.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/AppLayout.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/AppLayout.java deleted file mode 100644 index d9a2cda..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/AppLayout.java +++ /dev/null @@ -1,32 +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.server.appmaster.web.layout; - -import org.apache.hadoop.yarn.webapp.SubView; -import org.apache.slider.server.appmaster.web.view.IndexBlock; - -/** - * - */ -public class AppLayout extends WebUILayout { - - @Override - protected Class<? extends SubView> content() { - return IndexBlock.class; - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/ClusterSpecificationView.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/ClusterSpecificationView.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/ClusterSpecificationView.java deleted file mode 100644 index b54ca71..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/ClusterSpecificationView.java +++ /dev/null @@ -1,32 +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.server.appmaster.web.layout; - -import org.apache.hadoop.yarn.webapp.SubView; -import org.apache.slider.server.appmaster.web.view.ClusterSpecificationBlock; - -/** - * - */ -public class ClusterSpecificationView extends WebUILayout { - - @Override - protected Class<? extends SubView> content() { - return ClusterSpecificationBlock.class; - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/ContainerStatsView.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/ContainerStatsView.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/ContainerStatsView.java deleted file mode 100644 index 39ba0ad..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/ContainerStatsView.java +++ /dev/null @@ -1,33 +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.server.appmaster.web.layout; - -import org.apache.hadoop.yarn.webapp.SubView; -import org.apache.slider.server.appmaster.web.view.ContainerStatsBlock; - - - -/** - * - */ -public class ContainerStatsView extends WebUILayout { - - @Override - protected Class<? extends SubView> content() { - return ContainerStatsBlock.class; - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/WebUILayout.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/WebUILayout.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/WebUILayout.java deleted file mode 100644 index 1681f59..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/layout/WebUILayout.java +++ /dev/null @@ -1,43 +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.server.appmaster.web.layout; - -import org.apache.hadoop.yarn.webapp.SubView; -import org.apache.hadoop.yarn.webapp.view.TwoColumnLayout; -import org.apache.slider.server.appmaster.web.view.NavBlock; - -import static org.apache.hadoop.yarn.webapp.view.JQueryUI.ACCORDION; -import static org.apache.hadoop.yarn.webapp.view.JQueryUI.ACCORDION_ID; -import static org.apache.hadoop.yarn.webapp.view.JQueryUI.initID; - -/** - * - */ -public class WebUILayout extends TwoColumnLayout { - - @Override - protected void preHead(Page.HTML<_> html) { - set(ACCORDION_ID, "nav"); - set(initID(ACCORDION, "nav"), "{autoHeight:false, active:0}"); - } - - @Override - protected Class<? extends SubView> nav() { - return NavBlock.class; - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AMWadlGenerator.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AMWadlGenerator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AMWadlGenerator.java deleted file mode 100644 index 05aaa5b..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AMWadlGenerator.java +++ /dev/null @@ -1,72 +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.server.appmaster.web.rest; - -import com.sun.jersey.server.wadl.ApplicationDescription; -import com.sun.jersey.server.wadl.WadlGenerator; -import com.sun.jersey.server.wadl.WadlGeneratorImpl; -import com.sun.research.ws.wadl.Application; -import com.sun.research.ws.wadl.Resource; -import com.sun.research.ws.wadl.Resources; - -import java.util.Iterator; -import java.util.List; - -/** - * - */ -public class AMWadlGenerator extends WadlGeneratorImpl { - @Override - /** - * This method is called once the WADL application has been assembled, so it - * affords an opportunity to edit the resources presented by the WADL. In - * this case, we're removing the internal "/agents" resources. - */ - public void attachTypes(ApplicationDescription egd) { - super.attachTypes(egd); - - Application application = egd.getApplication(); - List<Resources> resources = application.getResources(); - - for (Resources appResources : resources) { - List<Resource> resourceList = appResources.getResource(); - for (Resource appResource : resourceList) { - String path = appResource.getPath(); - if (RestPaths.SLIDER_CONTEXT_ROOT.equals(path)) { - List<Object> sliderResources = appResource.getMethodOrResource(); - Iterator<Object> itor = sliderResources.iterator(); - while (itor.hasNext()) { - Object sliderRes = itor.next(); - if (sliderRes instanceof Resource) { - Resource res = (Resource) sliderRes; - if (RestPaths.SLIDER_SUBPATH_AGENTS.equals(res.getPath())) { - // assuming I'll get a list modification issue if I remove at this - // point - itor.remove(); - } - } - } - } - } - } - } - - @Override - public void setWadlGeneratorDelegate(WadlGenerator delegate) { - // do nothing - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AMWadlGeneratorConfig.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AMWadlGeneratorConfig.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AMWadlGeneratorConfig.java deleted file mode 100644 index ea9f22b..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AMWadlGeneratorConfig.java +++ /dev/null @@ -1,34 +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.server.appmaster.web.rest; - -import com.sun.jersey.api.wadl.config.WadlGeneratorConfig; -import com.sun.jersey.api.wadl.config.WadlGeneratorDescription; - -import java.util.List; - -/** - * App master's WADL generation support - */ -public class AMWadlGeneratorConfig extends WadlGeneratorConfig { - - public static final String CLASSNAME = "org.apache.slider.server.appmaster.web.rest.AMWadlGeneratorConfig"; - @Override - public List<WadlGeneratorDescription> configure() { - return generator(AMWadlGenerator.class).descriptions(); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AMWebServices.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AMWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AMWebServices.java deleted file mode 100644 index 44259d3..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AMWebServices.java +++ /dev/null @@ -1,85 +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.server.appmaster.web.rest; - -import com.google.inject.Inject; -import com.google.inject.Singleton; -import org.apache.slider.api.resource.Application; -import org.apache.slider.server.appmaster.web.WebAppApi; -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.publisher.PublisherResource; -import org.apache.slider.server.appmaster.web.rest.registry.RegistryResource; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.UriInfo; - -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; -import static org.apache.slider.server.appmaster.web.rest.RestPaths.ACTION_STOP; - -/** - * The available REST services exposed by a slider AM. - */ -@Singleton -@Path(RestPaths.SLIDER_CONTEXT_ROOT) -public class AMWebServices { - - /** AM/WebApp info object */ - private WebAppApi slider; - private final PublisherResource publisherResource; - private final RegistryResource registryResource; - - @Inject - public AMWebServices(WebAppApi slider) { - this.slider = slider; - publisherResource = new PublisherResource(slider); - registryResource = new RegistryResource(slider); - } - //TODO add an endpoint for exposing configs - - @Path(RestPaths.SLIDER_SUBPATH_PUBLISHER) - public PublisherResource getPublisherResource() { - return publisherResource; - } - - @Path(RestPaths.SLIDER_SUBPATH_REGISTRY) - public RegistryResource getRegistryResource() { - return registryResource; - } - - - @GET - @Path(RestPaths.SLIDER_SUBPATH_APPLICATION) - @Produces({APPLICATION_JSON}) - public Application getApplicationResource() { - return slider.getAppState().getApplication(); - } - - @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/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AbstractSliderResource.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AbstractSliderResource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AbstractSliderResource.java deleted file mode 100644 index 7ff83b6..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/AbstractSliderResource.java +++ /dev/null @@ -1,157 +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.server.appmaster.web.rest; - -import org.apache.hadoop.fs.PathNotFoundException; -import org.apache.hadoop.registry.client.exceptions.AuthenticationFailedException; -import org.apache.hadoop.registry.client.exceptions.NoPathPermissionsException; -import org.apache.hadoop.yarn.webapp.ForbiddenException; -import org.apache.hadoop.yarn.webapp.NotFoundException; -import org.apache.slider.server.appmaster.management.MetricsAndMonitoring; -import org.apache.slider.server.appmaster.web.WebAppApi; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; -import java.io.FileNotFoundException; -import java.net.URI; -import java.net.URL; - -/** - * Abstract resource base class for REST resources - * that use the slider WebAppApi - */ -public abstract class AbstractSliderResource { - private static final Logger log = - LoggerFactory.getLogger(AbstractSliderResource.class); - protected final WebAppApi slider; - protected final MetricsAndMonitoring metricsAndMonitoring; - - protected AbstractSliderResource(WebAppApi slider) { - this.slider = slider; - metricsAndMonitoring = slider.getMetricsAndMonitoring(); - } - - /** - * Generate a redirect to the WASL - * @param request to base the URL on - * @return a 302 response - */ - protected Response redirectToAppWadl(HttpServletRequest request) { - try { - URI location = new URL(request.getScheme(), - request.getServerName(), - request.getServerPort(), - RestPaths.APPLICATION_WADL).toURI(); - return Response.temporaryRedirect(location).build(); - } catch (Exception e) { - log.error("Error during redirect to WADL", e); - throw new WebApplicationException(Response.serverError().build()); - } - } - - /** - * Convert any exception caught into a web application - * exception for rethrowing - * @param path path of request - * @param ex exception - * @return an exception to throw - */ - public WebApplicationException buildException(String path, - Exception ex) { - try { - throw ex; - } catch (WebApplicationException e) { - // rethrow direct - throw e; - } catch (FileNotFoundException e) { - return new NotFoundException("Not found: " + path); - } catch (PathNotFoundException e) { - return new NotFoundException("Not found: " + path); - } catch (AuthenticationFailedException e) { - return new ForbiddenException(path); - } catch (NoPathPermissionsException e) { - return new ForbiddenException(path); - } catch (Exception e) { - log.error("Error during generation of response: {}", e, e); - return new WebApplicationException(e); - } - } - - /** - * Mark an GET operation on a path - * @param verb HTTP Verb - * @param path path relative to slider API - */ - protected void mark(String verb, String path) { - metricsAndMonitoring.markMeterAndCounter(verb + "-" + path); - } - - /** - * Mark an GET operation on a path - * @param verb HTTP Verb - * @param path path relative to slider API - */ - protected void mark(String verb, String path, String subpath) { - metricsAndMonitoring.markMeterAndCounter(verb + "-" + path + subpath); - } - - /** - * Mark a GET operation on a path - * @param path path relative to slider API - */ - protected void markGet(String path) { - mark("GET", path); - } - - /** - * Mark a GET operation on a path - * @param path path relative to slider API - */ - protected void markGet(String path, String subpath) { - mark("GET", path, subpath); - } - - /** - * Mark a GET operation on a path - * @param path path relative to slider API - */ - protected void markPost(String path, String subpath) { - mark("POST", path, subpath); - } - - /** - * Mark a GET operation on a path - * @param path path relative to slider API - */ - protected void markPut(String path, String subpath) { - mark("PUT", path, subpath); - } - - /** - * Mark a GET operation on a path - * @param path path relative to slider API - */ - protected void markDelete(String path, String subpath) { - mark("DELETE", path, subpath); - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/InsecureAmFilter.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/InsecureAmFilter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/InsecureAmFilter.java deleted file mode 100644 index b4a92ba..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/InsecureAmFilter.java +++ /dev/null @@ -1,104 +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.server.appmaster.web.rest; - -import org.apache.hadoop.yarn.server.webproxy.WebAppProxyServlet; -import org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter; -import org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpPrincipal; -import org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpServletRequestWrapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -/** - * This is a filter which is used to forward insecure operations - * There's some metrics to track all operations too - */ -public class InsecureAmFilter extends AmIpFilter { - public static final String WS_CONTEXT_ROOT = "slider.rest.context.root"; - protected static final Logger log = - LoggerFactory.getLogger(InsecureAmFilter.class); - - private String wsContextRoot; - - - @Override - public void init(FilterConfig conf) throws ServletException { - super.init(conf); - wsContextRoot = conf.getInitParameter(WS_CONTEXT_ROOT); - if (wsContextRoot == null) { - throw new ServletException("No value set for " + WS_CONTEXT_ROOT); - } - } - - private void rejectNonHttpRequests(ServletRequest req) throws - ServletException { - if (!(req instanceof HttpServletRequest)) { - throw new ServletException("This filter only works for HTTP/HTTPS"); - } - } - - @Override - public void doFilter(ServletRequest req, - ServletResponse resp, - FilterChain chain) throws IOException, ServletException { - rejectNonHttpRequests(req); - HttpServletRequest httpReq = (HttpServletRequest) req; - - - String requestURI = httpReq.getRequestURI(); - if (requestURI == null || !requestURI.startsWith(wsContextRoot)) { - // hand off to the AM filter if it is not the context root - super.doFilter(req, resp, chain); - return; - } - - String user = null; - - if (httpReq.getCookies() != null) { - for (Cookie c : httpReq.getCookies()) { - if (WebAppProxyServlet.PROXY_USER_COOKIE_NAME.equals(c.getName())) { - user = c.getValue(); - break; - } - } - } - - if (user == null) { - log.debug("Could not find " + WebAppProxyServlet.PROXY_USER_COOKIE_NAME - + " cookie, so user will not be set"); - chain.doFilter(req, resp); - } else { - final AmIpPrincipal principal = new AmIpPrincipal(user); - ServletRequest requestWrapper = new AmIpServletRequestWrapper(httpReq, - principal); - chain.doFilter(requestWrapper, resp); - } - - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/InsecureAmFilterInitializer.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/InsecureAmFilterInitializer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/InsecureAmFilterInitializer.java deleted file mode 100644 index 42a5bdd..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/InsecureAmFilterInitializer.java +++ /dev/null @@ -1,102 +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.server.appmaster.web.rest; - -import com.google.common.annotations.VisibleForTesting; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.http.FilterContainer; -import org.apache.hadoop.http.FilterInitializer; -import org.apache.hadoop.http.HttpConfig; -import org.apache.hadoop.yarn.api.ApplicationConstants; -import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.apache.hadoop.yarn.webapp.util.WebAppUtils; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class InsecureAmFilterInitializer extends FilterInitializer { - private static final String FILTER_NAME = "AM_PROXY_FILTER"; - private static final String FILTER_CLASS = - InsecureAmFilter.class.getCanonicalName(); - private static final String HTTPS_PREFIX = "https://"; - private static final String HTTP_PREFIX = "http://"; - - static final String PROXY_HOSTS = "PROXY_HOSTS"; - static final String PROXY_HOSTS_DELIMITER = ","; - static final String PROXY_URI_BASES = "PROXY_URI_BASES"; - static final String PROXY_URI_BASES_DELIMITER = ","; - - private Configuration configuration; - - public static final String NAME = - "org.apache.slider.server.appmaster.web.rest.InsecureAmFilterInitializer"; - - @Override - public void initFilter(FilterContainer container, Configuration conf) { - configuration = conf; - Map<String, String> params = new HashMap<String, String>(); - String proxy = WebAppUtils.getProxyHostAndPort(conf); - String[] parts = proxy.split(":"); - params.put(InsecureAmFilter.PROXY_HOST, parts[0]); - // todo: eventually call WebAppUtils.getHttpSchemePrefix - params.put(InsecureAmFilter.PROXY_URI_BASE, getHttpSchemePrefix() - + proxy + - getApplicationWebProxyBase()); - params.put(InsecureAmFilter.WS_CONTEXT_ROOT, RestPaths.WS_CONTEXT_ROOT); - container.addFilter(FILTER_NAME, FILTER_CLASS, params); - } - - private void classicAmFilterInitializerInit(FilterContainer container, - Configuration conf) { - Map<String, String> params = new HashMap<String, String>(); - List<String> proxies = WebAppUtils.getProxyHostsAndPortsForAmFilter(conf); - StringBuilder sb = new StringBuilder(); - for (String proxy : proxies) { - sb.append(proxy.split(":")[0]).append(PROXY_HOSTS_DELIMITER); - } - sb.setLength(sb.length() - 1); - params.put(PROXY_HOSTS, sb.toString()); - - String prefix = WebAppUtils.getHttpSchemePrefix(conf); - String proxyBase = getApplicationWebProxyBase(); - sb = new StringBuilder(); - for (String proxy : proxies) { - sb.append(prefix).append(proxy).append(proxyBase) - .append(PROXY_HOSTS_DELIMITER); - } - sb.setLength(sb.length() - 1); - params.put(PROXY_URI_BASES, sb.toString()); - - } - - @VisibleForTesting - protected String getApplicationWebProxyBase() { - return System.getenv(ApplicationConstants.APPLICATION_WEB_PROXY_BASE_ENV); - } - - private String getHttpSchemePrefix() { - return HttpConfig.Policy.HTTPS_ONLY == - HttpConfig.Policy.fromString(configuration - .get( - YarnConfiguration.YARN_HTTP_POLICY_KEY, - YarnConfiguration.YARN_HTTP_POLICY_DEFAULT)) - ? HTTPS_PREFIX : HTTP_PREFIX; - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java deleted file mode 100644 index 581f5b4..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java +++ /dev/null @@ -1,155 +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.server.appmaster.web.rest; - -/** - * Paths in the REST App - */ -public class RestPaths { - - public static final String WS_CONTEXT = "ws"; - public static final String AGENT_WS_CONTEXT = "ws"; - - /** - * Root path for the web services context: {@value} - */ - public static final String WS_CONTEXT_ROOT = "/" + WS_CONTEXT; - - /** - * agent content root: {@value} - */ - public static final String SLIDER_CONTEXT_ROOT = WS_CONTEXT_ROOT + "/v1"; - public static final String RELATIVE_API = WS_CONTEXT + "/v1"; - public static final String MANAGEMENT = "mgmt"; - public static final String SLIDER_SUBPATH_MANAGEMENT = "/" + MANAGEMENT; - public static final String SLIDER_SUBPATH_AGENTS = "/agents"; - public static final String SLIDER_SUBPATH_PUBLISHER = "/publisher"; - - - /** - * Publisher: {@value} - */ - public static final String SLIDER_PATH_PUBLISHER = SLIDER_CONTEXT_ROOT - + SLIDER_SUBPATH_PUBLISHER; - - public static final String RELATIVE_PATH_PUBLISHER = RELATIVE_API - + SLIDER_SUBPATH_PUBLISHER; - - /** - * Registry subpath: {@value} - */ - public static final String SLIDER_SUBPATH_REGISTRY = "/registry"; - - /** - * Registry: {@value} - */ - public static final String SLIDER_PATH_REGISTRY = SLIDER_CONTEXT_ROOT - + SLIDER_SUBPATH_REGISTRY; - public static final String RELATIVE_PATH_REGISTRY = RELATIVE_API - + SLIDER_SUBPATH_REGISTRY; - - - /** - * The regular expressions used to define valid configuration names/url path - * fragments: {@value} - */ - public static final String PUBLISHED_CONFIGURATION_REGEXP - = "[a-z0-9][a-z0-9_\\+-]*"; - - public static final String PUBLISHED_CONFIGURATION_SET_REGEXP - = "[a-z0-9][a-z0-9_.\\+-]*"; - - public static final String SLIDER_CONFIGSET = "slider"; - public static final String SLIDER_EXPORTS = "exports"; - - public static final String SLIDER_CLASSPATH = "classpath"; - - /** - * Codahale Metrics - base path: {@value} - */ - - public static final String SYSTEM = "/system"; - - - - /** - * Codahale Metrics - health: {@value} - */ - public static final String SYSTEM_HEALTHCHECK = SYSTEM + "/health"; - /** - * Codahale Metrics - metrics: {@value} - */ - public static final String SYSTEM_METRICS = SYSTEM + "/metrics"; - /** - * Codahale Metrics - metrics as JSON: {@value} - */ - public static final String SYSTEM_METRICS_JSON = SYSTEM_METRICS + "?format=json"; - /** - * Codahale Metrics - ping: {@value} - */ - public static final String SYSTEM_PING = SYSTEM + "/ping"; - /** - * Codahale Metrics - thread dump: {@value} - */ - public static final String SYSTEM_THREADS = SYSTEM + "/threads"; - - /** - * application subpath - */ - public static final String SLIDER_SUBPATH_APPLICATION = "/application"; - - /** - * management path: {@value} - */ - public static final String SLIDER_PATH_APPLICATION = - SLIDER_CONTEXT_ROOT + SLIDER_SUBPATH_APPLICATION; - - - public static final String APPLICATION_WADL = "/application.wadl"; - public static final String LIVE = "/live"; - public static final String LIVE_RESOURCES = "/live/resources"; - public static final String LIVE_CONTAINERS = "/live/containers"; - public static final String LIVE_COMPONENTS = "/live/components"; - public static final String LIVE_NODES = "/live/nodes"; - public static final String LIVE_LIVENESS = "/live/liveness"; - public static final String LIVE_STATISTICS = "/live/statistics"; - public static final String MODEL = "/model"; - public static final String MODEL_DESIRED = MODEL +"/desired"; - public static final String MODEL_DESIRED_APPCONF = MODEL_DESIRED +"/appconf"; - public static final String MODEL_DESIRED_RESOURCES = MODEL_DESIRED +"/resources"; - public static final String MODEL_RESOLVED = "/model/resolved"; - public static final String MODEL_RESOLVED_APPCONF = MODEL_RESOLVED +"/appconf"; - public static final String MODEL_RESOLVED_RESOURCES = MODEL_RESOLVED +"/resources"; - public static final String MODEL_INTERNAL = "/model/internal"; - - public static final String ACTION = "/action"; - public static final String ACTION_PING = ACTION + "/ping"; - public static final String ACTION_STOP = ACTION + "/stop"; - - /** - * Path to a role - * @param name role name - * @return a path to it - */ - public String pathToRole(String name) { - - // ws/v1/slider/application/live/components/$name - return SLIDER_PATH_APPLICATION + LIVE_COMPONENTS + "/" + name; - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/SliderJacksonJaxbJsonProvider.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/SliderJacksonJaxbJsonProvider.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/SliderJacksonJaxbJsonProvider.java deleted file mode 100644 index 86d68a8..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/SliderJacksonJaxbJsonProvider.java +++ /dev/null @@ -1,58 +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.server.appmaster.web.rest; - -import com.google.inject.Singleton; -import org.apache.hadoop.classification.InterfaceAudience.Private; -import org.apache.hadoop.classification.InterfaceStability.Unstable; -import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider; -import org.codehaus.jackson.map.AnnotationIntrospector; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector; -import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.ext.Provider; - -/** - * Implementation of JAX-RS abstractions based on {@link - * JacksonJaxbJsonProvider} needed to deserialize JSON content to, or serialize - * it from, POJO objects. - */ -@Singleton -@Provider -@Unstable -@Private -public class SliderJacksonJaxbJsonProvider extends JacksonJaxbJsonProvider { - - public SliderJacksonJaxbJsonProvider() { - } - - @Override - public ObjectMapper locateMapper(Class<?> type, MediaType mediaType) { - ObjectMapper mapper = super.locateMapper(type, mediaType); - AnnotationIntrospector introspector = new AnnotationIntrospector.Pair( - new JaxbAnnotationIntrospector(), - new JacksonAnnotationIntrospector() - ); - mapper.setAnnotationIntrospector(introspector); - //mapper.setSerializationInclusion(Inclusion.NON_NULL); - return mapper; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResouceContentCacheFactory.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResouceContentCacheFactory.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResouceContentCacheFactory.java deleted file mode 100644 index d23fcee..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResouceContentCacheFactory.java +++ /dev/null @@ -1,36 +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.server.appmaster.web.rest.application; - -import org.apache.slider.server.appmaster.state.StateAccessForProviders; -import org.apache.slider.server.appmaster.web.rest.application.resources.ContentCache; - -public class ApplicationResouceContentCacheFactory { - public static final int LIFESPAN = 500; - - /** - * Build the content cache - * @param state state view - */ - public static ContentCache createContentCache( - StateAccessForProviders state) { - ContentCache cache = new ContentCache(); - return cache; - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionPing.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionPing.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionPing.java deleted file mode 100644 index 96b4f75..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionPing.java +++ /dev/null @@ -1,50 +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.server.appmaster.web.rest.application.actions; - -import org.apache.slider.api.types.PingInformation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.core.UriInfo; -import java.util.Locale; - -public class RestActionPing { - private static final Logger log = - LoggerFactory.getLogger(RestActionPing.class); - - public RestActionPing() { - } - - public PingInformation ping(HttpServletRequest request, UriInfo uriInfo, String body) { - String verb = request.getMethod(); - log.info("Ping {}", verb); - PingInformation pingInformation = new PingInformation(); - pingInformation.time = System.currentTimeMillis(); - pingInformation.verb = verb; - pingInformation.body = body; - String text = - String.format(Locale.ENGLISH, - "Ping verb %s received at %tc", - verb, pingInformation.time); - pingInformation.text = text; - return pingInformation; - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionStop.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionStop.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionStop.java deleted file mode 100644 index 544f589..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/RestActionStop.java +++ /dev/null @@ -1,67 +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.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.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; - log.info(text); - ActionStopSlider stopSlider = - new ActionStopSlider(text, - 1000, - TimeUnit.MILLISECONDS, - LauncherExitCodes.EXIT_SUCCESS, - FinalApplicationStatus.SUCCEEDED, - text); - log.info("SliderAppMasterApi.stopCluster: {}", stopSlider); - slider.getQueues().schedule(stopSlider); - - return response; - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/StopResponse.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/StopResponse.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/StopResponse.java deleted file mode 100644 index d591f57..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/actions/StopResponse.java +++ /dev/null @@ -1,29 +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.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 { - public String verb; - public String text; -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/package-info.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/package-info.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/package-info.java deleted file mode 100644 index 34eb82c..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/package-info.java +++ /dev/null @@ -1,24 +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. - */ - - -/** - * This package contains resources related to the application - * REST API - */ -package org.apache.slider.server.appmaster.web.rest.application; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/CachedContent.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/CachedContent.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/CachedContent.java deleted file mode 100644 index 22fd0fe..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/CachedContent.java +++ /dev/null @@ -1,121 +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.server.appmaster.web.rest.application.resources; - -import com.google.common.base.Preconditions; -import org.apache.hadoop.util.Time; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A cached resource is one that can be stored and served up, with a refresh - * only taking place when the expiry happens. - * - * The refresh check/refresh is synchronized. - * @param <T> type to return - */ -public class CachedContent<T> { - private static final Logger log = - LoggerFactory.getLogger(CachedContent.class); - private T cachedValue; - private long expires; - private final long lifespan; - private final ResourceRefresher<T> refresh; - private int refreshCounter; - - public CachedContent(long lifespan, - ResourceRefresher<T> refresh) { - this.lifespan = lifespan; - this.refresh = refresh; - } - - /** - * Get the value, triggering a refresh if needed - * @return the cached or latest value. - */ - public T get() throws Exception { - maybeRefresh(); - return getCachedValue(); - } - - /** - * Get the cached value without any expiry check - * @return the last value set. May be null. - */ - public synchronized T getCachedValue() { - return cachedValue; - } - - public synchronized int getRefreshCounter() { - return refreshCounter; - } - - /** - * Get the lifespan in millis of the cached value - * @return the lifespan - */ - public long getLifespan() { - return lifespan; - } - - /** - * Maybe refresh the content - * @return true if a refresh took place. - */ - public synchronized boolean maybeRefresh() throws Exception { - long now = now(); - if (cachedValue == null || now >= expires) { - log.debug("Refreshing at time {}", now); - forceRefresh(); - log.debug("Refreshed value now {}", cachedValue); - return true; - } - return false; - } - - protected long now() { - return Time.monotonicNow(); - } - - /** - * Force a refresh and reset the expiry counter - * @return the new value - */ - protected synchronized T forceRefresh() throws Exception { - refreshCounter ++; - T updated = refresh.refresh(); - Preconditions.checkNotNull(updated); - cachedValue = updated; - expires = now() + lifespan; - return cachedValue; - } - - @Override - public String toString() { - final StringBuilder sb = - new StringBuilder("CachedContent{"); - sb.append(" expires=").append(expires); - sb.append(", lifespan=").append(lifespan); - sb.append(", refresh=").append(refresh); - sb.append(", refreshCounter=").append(refreshCounter); - sb.append(", cached=").append(cachedValue); - sb.append('}'); - return sb.toString(); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ContentCache.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ContentCache.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ContentCache.java deleted file mode 100644 index 8f026a1..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ContentCache.java +++ /dev/null @@ -1,67 +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.server.appmaster.web.rest.application.resources; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Cache of content - */ -public class ContentCache extends ConcurrentHashMap<String, CachedContent> { - - public ContentCache(int initialCapacity) { - super(initialCapacity); - } - - public ContentCache() { - } - - - public Object lookup(String key) throws Exception { - CachedContent content = get(key); - if (content == null) { - throw new FileNotFoundException("no content for path " + key); - } - return content.get(); - } - - - /** - * Lookup a cached item. If an exception is raised on the refresh... - * <ol> - * <li>IOExceptions are thrown directly</li> - * <li>Other exceptions are wrapped with an IOExceptions</li> - * </ol> - * @param key - * @return - * @throws IOException - */ - public Object lookupWithIOE(String key) throws IOException { - try { - return lookup(key); - } catch (IOException e) { - throw e; - } catch (Exception e) { - throw new IOException("Looking up " + key + ": " + e, e); - } - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/394183c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ResourceRefresher.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ResourceRefresher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ResourceRefresher.java deleted file mode 100644 index 35f0367..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ResourceRefresher.java +++ /dev/null @@ -1,31 +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.server.appmaster.web.rest.application.resources; - -/** - * Interface which must be implemented to act as a source for cached content. - * @param <T> type to return - */ -public interface ResourceRefresher<T> { - /** - * Build an up to date version of the data - * @return a new instance of the (JSON serializable) data - */ - T refresh() throws Exception; -} --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org