http://git-wip-us.apache.org/repos/asf/hadoop/blob/31c4a419/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/state/StateAccessForProviders.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/state/StateAccessForProviders.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/state/StateAccessForProviders.java new file mode 100644 index 0000000..ad91183 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/state/StateAccessForProviders.java @@ -0,0 +1,313 @@ +/* + * 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.state; + +import org.apache.hadoop.yarn.api.records.Container; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; +import org.apache.slider.api.ClusterDescription; +import org.apache.slider.api.ClusterNode; +import org.apache.slider.api.StatusKeys; +import org.apache.slider.api.types.ApplicationLivenessInformation; +import org.apache.slider.api.types.ComponentInformation; +import org.apache.slider.api.types.NodeInformation; +import org.apache.slider.api.types.RoleStatistics; +import org.apache.slider.core.conf.AggregateConf; +import org.apache.slider.core.conf.ConfTreeOperations; +import org.apache.slider.core.exceptions.NoSuchNodeException; +import org.apache.slider.core.registry.docstore.PublishedConfigSet; +import org.apache.slider.core.registry.docstore.PublishedExportsSet; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** + * The methods to offer state access to the providers and other parts of + * the system which want read-only access to the state. + */ +public interface StateAccessForProviders { + + /** + * Get a map of role status entries by role Id + * @return the map of currently defined roles. + */ + Map<Integer, RoleStatus> getRoleStatusMap(); + + /** + * Get the name of the application + * @return the name + */ + String getApplicationName(); + + /** + * Get the published configurations + * @return the configuration set + */ + PublishedConfigSet getPublishedSliderConfigurations(); + + /** + * Get the published exports set + * @return + */ + PublishedExportsSet getPublishedExportsSet(); + + /** + * Get a named published config set + * @param name name to look up + * @return the instance or null + */ + PublishedConfigSet getPublishedConfigSet(String name); + + /** + * Get a named published config set, creating it if need be. + * @param name name to look up + * @return the instance -possibly a new one + */ + PublishedConfigSet getOrCreatePublishedConfigSet(String name); + + /** + * List the config sets -this takes a clone of the current set + * @return a list of config sets + */ + List<String> listConfigSets(); + + /** + * Get a map of all the failed containers + * @return map of recorded failed containers + */ + Map<ContainerId, RoleInstance> getFailedContainers(); + + /** + * Get the live containers. + * + * @return the live nodes + */ + Map<ContainerId, RoleInstance> getLiveContainers(); + + /** + * Get the current cluster description + * @return the actual state of the cluster + */ + ClusterDescription getClusterStatus(); + + /** + * Get at the snapshot of the resource config + * Changes here do not affect the application state. + * @return the most recent settings + */ + ConfTreeOperations getResourcesSnapshot(); + + /** + * Get at the snapshot of the appconf config + * Changes here do not affect the application state. + * @return the most recent settings + */ + ConfTreeOperations getAppConfSnapshot(); + + /** + * Get at the snapshot of the internals config. + * Changes here do not affect the application state. + * @return the internals settings + */ + + ConfTreeOperations getInternalsSnapshot(); + + /** + * Flag set to indicate the application is live -this only happens + * after the buildInstance operation + */ + boolean isApplicationLive(); + + long getSnapshotTime(); + + /** + * Get a snapshot of the entire aggregate configuration + * @return the aggregate configuration + */ + AggregateConf getInstanceDefinitionSnapshot(); + + /** + * Get the desired/unresolved value + * @return unresolved + */ + AggregateConf getUnresolvedInstanceDefinition(); + + /** + * Look up a role from its key -or fail + * + * @param key key to resolve + * @return the status + * @throws YarnRuntimeException on no match + */ + RoleStatus lookupRoleStatus(int key); + + /** + * Look up a role from its key -or fail + * + * @param c container in a role + * @return the status + * @throws YarnRuntimeException on no match + */ + RoleStatus lookupRoleStatus(Container c) throws YarnRuntimeException; + + /** + * Look up a role from its key -or fail + * + * @param name container in a role + * @return the status + * @throws YarnRuntimeException on no match + */ + RoleStatus lookupRoleStatus(String name) throws YarnRuntimeException; + + /** + * Clone a list of active containers + * @return the active containers at the time + * the call was made + */ + List<RoleInstance> cloneOwnedContainerList(); + + /** + * Get the number of active containers + * @return the number of active containers the time the call was made + */ + int getNumOwnedContainers(); + + /** + * Get any active container with the given ID + * @param id container Id + * @return the active container or null if it is not found + */ + RoleInstance getOwnedContainer(ContainerId id); + + /** + * Get any active container with the given ID + * @param id container Id + * @return the active container or null if it is not found + */ + RoleInstance getOwnedContainer(String id) throws NoSuchNodeException; + + /** + * Create a clone of the list of live cluster nodes. + * @return the list of nodes, may be empty + */ + List<RoleInstance> cloneLiveContainerInfoList(); + + /** + * Get the {@link RoleInstance} details on a container. + * This is an O(n) operation + * @param containerId the container ID + * @return null if there is no such node + * @throws NoSuchNodeException if the node cannot be found + */ + RoleInstance getLiveInstanceByContainerID(String containerId) + throws NoSuchNodeException; + + /** + * Get the details on a list of instaces referred to by ID. + * Unknown nodes are not returned + * <i>Important: the order of the results are undefined</i> + * @param containerIDs the containers + * @return list of instances + */ + List<RoleInstance> getLiveInstancesByContainerIDs( + Collection<String> containerIDs); + + /** + * Update the cluster description with anything interesting + */ + ClusterDescription refreshClusterStatus(); + + /** + * Get a deep clone of the role status list. Concurrent events may mean this + * list (or indeed, some of the role status entries) may be inconsistent + * @return a snapshot of the role status entries + */ + List<RoleStatus> cloneRoleStatusList(); + + /** + * get application liveness information + * @return a snapshot of the current liveness information + */ + ApplicationLivenessInformation getApplicationLivenessInformation(); + + /** + * Get the live statistics map + * @return a map of statistics values, defined in the {@link StatusKeys} + * keylist. + */ + Map<String, Integer> getLiveStatistics(); + + /** + * Get a snapshot of component information. + * <p> + * This does <i>not</i> include any container list, which + * is more expensive to create. + * @return a map of current role status values. + */ + Map<String, ComponentInformation> getComponentInfoSnapshot(); + + /** + * Find out about the nodes for specific roles + * @return + */ + Map<String, Map<String, ClusterNode>> getRoleClusterNodeMapping(); + + /** + * Enum all role instances by role. + * @param role role, or "" for all roles + * @return a list of instances, may be empty + */ + List<RoleInstance> enumLiveInstancesInRole(String role); + + /** + * Look up all containers of a specific component name + * @param component component/role name + * @return list of instances. This is a snapshot + */ + List<RoleInstance> lookupRoleContainers(String component); + + /** + * Get the JSON serializable information about a component + * @param component component to look up + * @return a structure describing the component. + */ + ComponentInformation getComponentInformation(String component); + + + /** + * Get a clone of the nodemap. + * The instances inside are not cloned + * @return a possibly empty map of hostname top info + */ + Map<String, NodeInformation> getNodeInformationSnapshot(); + + /** + * get information on a node + * @param hostname hostname to look up + * @return the information, or null if there is no information held. + */ + NodeInformation getNodeInformation(String hostname); + + /** + * Get the aggregate statistics across all roles + * @return role statistics + */ + RoleStatistics getRoleStatistics(); +}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/31c4a419/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/AgentService.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/AgentService.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/AgentService.java new file mode 100644 index 0000000..f840035 --- /dev/null +++ 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/AgentService.java @@ -0,0 +1,37 @@ +/* + * 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.slider.server.appmaster.web.rest.agent.AgentWebApp; +import org.apache.slider.server.services.workflow.ClosingService; +import org.apache.slider.server.services.workflow.WorkflowCompositeService; + +/** + * agent service gives the agent webapp lifecycle integration + */ +public class AgentService extends ClosingService<AgentWebApp> { + + + public AgentService(String name) { + super(name); + } + + public AgentService(String name, AgentWebApp app) { + super(name, app); + } + +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/31c4a419/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/HttpCacheHeaders.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/HttpCacheHeaders.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/HttpCacheHeaders.java new file mode 100644 index 0000000..be8960d --- /dev/null +++ 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/HttpCacheHeaders.java @@ -0,0 +1,35 @@ +/* + * 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; + +/* + + + , ); + long now = System.currentTimeMillis(); + httpRes.addDateHeader ( "Expires", now ); + httpRes.addDateHeader ( "Date", now ); + httpRes.addHeader ( "Pragma", "no-cache" ); + */ +public interface HttpCacheHeaders { + String HTTP_HEADER_CACHE_CONTROL = "Cache-Control"; + String HTTP_HEADER_CACHE_CONTROL_NONE = "no-cache"; + String HTTP_HEADER_PRAGMA = "Pragma"; + +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/31c4a419/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderAMController.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/SliderAMController.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/SliderAMController.java new file mode 100644 index 0000000..c3c6e60 --- /dev/null +++ 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/SliderAMController.java @@ -0,0 +1,69 @@ +/* + * 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.Inject; +import org.apache.hadoop.yarn.webapp.Controller; +import org.apache.slider.server.appmaster.web.layout.AppLayout; +import org.apache.slider.server.appmaster.web.layout.ClusterSpecificationView; +import org.apache.slider.server.appmaster.web.layout.ContainerStatsView; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class SliderAMController extends Controller { + private static final Logger log = LoggerFactory.getLogger(SliderAMController.class); + + private final WebAppApi slider; + + @Inject + public SliderAMController(WebAppApi slider, RequestContext ctx) { + super(ctx); + this.slider = slider; + } + + @Override + public void index() { + setTitle("Slider App Master"); + + updateAppState(); + + render(AppLayout.class); + } + + public void containerStats() { + setTitle("Container Statistics"); + + updateAppState(); + + render(ContainerStatsView.class); + } + + public void specification() { + setTitle("Cluster Specification"); + + render(ClusterSpecificationView.class); + } + + private void updateAppState() { + //TODO don't do this on every request? + slider.getAppState().refreshClusterStatus(); + } + +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/31c4a419/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 new file mode 100644 index 0000000..7ecc00c --- /dev/null +++ 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 @@ -0,0 +1,108 @@ +/* + * 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.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.management.MetricsAndMonitoring; +import org.apache.slider.server.appmaster.web.rest.AMWadlGeneratorConfig; +import org.apache.slider.server.appmaster.web.rest.AMWebServices; +import static org.apache.slider.server.appmaster.web.rest.RestPaths.*; +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; + +/** + * + */ +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); + } + + // metrics + MetricsAndMonitoring monitoring = + webAppApi.getMetricsAndMonitoring(); + serve(SYSTEM_HEALTHCHECK).with(new HealthCheckServlet(monitoring.getHealth())); + serve(SYSTEM_METRICS).with(new MetricsServlet(monitoring.getMetrics())); + 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/31c4a419/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 new file mode 100644 index 0000000..12c41ac --- /dev/null +++ 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 @@ -0,0 +1,48 @@ +/* + * 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/31c4a419/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 new file mode 100644 index 0000000..0f99d6d --- /dev/null +++ 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 @@ -0,0 +1,95 @@ +/* + * 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.api.SliderClusterProtocol; +import org.apache.slider.providers.ProviderService; +import org.apache.slider.server.appmaster.AppMasterActionOperations; +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.RoleStatus; +import org.apache.slider.server.appmaster.state.StateAccessForProviders; +import org.apache.slider.server.appmaster.web.rest.agent.AgentRestOperations; +import org.apache.slider.server.appmaster.web.rest.application.resources.ContentCache; +import org.apache.slider.server.services.security.CertificateManager; + +import java.util.Map; + +/** + * Interface to pass information from the Slider AppMaster to the WebApp + */ +public interface WebAppApi { + + /** + * The {@link AppState} for the current cluster + */ + StateAccessForProviders getAppState(); + + /** + * The {@link ProviderService} for the current cluster + */ + ProviderService getProviderService(); + + + /** + * The {@link CertificateManager} for the current cluster + */ + CertificateManager getCertificateManager(); + + /** + * Generate a mapping from role name to its {@link RoleStatus}. Be aware that this + * is a computed value and not just a getter + */ + Map<String, RoleStatus> getRoleStatusByName(); + + /** + * Returns an interface that can support the agent-based REST operations. + */ + AgentRestOperations getAgentRestOperations(); + + /** + * 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(); + + /** + * API for AM operations + * @return current operations implementation + */ + AppMasterActionOperations getAMOperations(); + + /** + * Local cache of content + * @return the cache + */ + ContentCache getContentCache(); +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/31c4a419/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 new file mode 100644 index 0000000..a0fe310 --- /dev/null +++ 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 @@ -0,0 +1,128 @@ +/* + * 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.providers.ProviderService; +import org.apache.slider.server.appmaster.AppMasterActionOperations; +import org.apache.slider.server.appmaster.actions.QueueAccess; +import org.apache.slider.server.appmaster.management.MetricsAndMonitoring; +import org.apache.slider.server.appmaster.state.RoleStatus; +import org.apache.slider.server.appmaster.state.StateAccessForProviders; +import org.apache.slider.server.appmaster.web.rest.agent.AgentRestOperations; +import org.apache.slider.server.appmaster.web.rest.application.resources.ContentCache; +import org.apache.slider.server.services.security.CertificateManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +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; + protected final ProviderService provider; + protected final CertificateManager certificateManager; + private final RegistryOperations registryOperations; + private final MetricsAndMonitoring metricsAndMonitoring; + private final QueueAccess queues; + private final AppMasterActionOperations appMasterOperations; + private final ContentCache contentCache; + + public WebAppApiImpl(StateAccessForProviders appState, + ProviderService provider, + CertificateManager certificateManager, + RegistryOperations registryOperations, + MetricsAndMonitoring metricsAndMonitoring, + QueueAccess queues, + AppMasterActionOperations appMasterOperations, + ContentCache contentCache) { + this.appMasterOperations = appMasterOperations; + this.contentCache = contentCache; + checkNotNull(appState); + checkNotNull(provider); + this.queues = queues; + + this.registryOperations = registryOperations; + this.appState = appState; + this.provider = provider; + this.certificateManager = certificateManager; + this.metricsAndMonitoring = metricsAndMonitoring; + } + + @Override + public StateAccessForProviders getAppState() { + return appState; + } + + @Override + public ProviderService getProviderService() { + return provider; + } + + @Override + public CertificateManager getCertificateManager() { + return certificateManager; + } + + @Override + public Map<String,RoleStatus> getRoleStatusByName() { + List<RoleStatus> roleStatuses = appState.cloneRoleStatusList(); + Map<String, RoleStatus> map = new TreeMap<>(); + for (RoleStatus status : roleStatuses) { + map.put(status.getName(), status); + } + return map; + } + + @Override + public AgentRestOperations getAgentRestOperations() { + return provider.getAgentRestOperations(); + } + + @Override + public RegistryOperations getRegistryOperations() { + return registryOperations; + } + + @Override + public MetricsAndMonitoring getMetricsAndMonitoring() { + return metricsAndMonitoring; + } + + @Override + public QueueAccess getQueues() { + return queues; + } + + @Override + public AppMasterActionOperations getAMOperations() { + return appMasterOperations; + } + + @Override + public ContentCache getContentCache() { + return contentCache; + } +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/31c4a419/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 new file mode 100644 index 0000000..d9a2cda --- /dev/null +++ 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 @@ -0,0 +1,32 @@ +/* + * 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/31c4a419/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 new file mode 100644 index 0000000..b54ca71 --- /dev/null +++ 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 @@ -0,0 +1,32 @@ +/* + * 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/31c4a419/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 new file mode 100644 index 0000000..39ba0ad --- /dev/null +++ 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 @@ -0,0 +1,33 @@ +/* + * 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/31c4a419/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 new file mode 100644 index 0000000..1681f59 --- /dev/null +++ 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 @@ -0,0 +1,43 @@ +/* + * 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/31c4a419/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 new file mode 100644 index 0000000..05aaa5b --- /dev/null +++ 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 @@ -0,0 +1,72 @@ +/* + * 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/31c4a419/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 new file mode 100644 index 0000000..ea9f22b --- /dev/null +++ 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 @@ -0,0 +1,34 @@ +/* + * 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/31c4a419/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 new file mode 100644 index 0000000..03bf703 --- /dev/null +++ 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 @@ -0,0 +1,72 @@ +/* + * 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.server.appmaster.web.WebAppApi; +import org.apache.slider.server.appmaster.web.rest.agent.AgentResource; +import org.apache.slider.server.appmaster.web.rest.application.ApplicationResource; +import org.apache.slider.server.appmaster.web.rest.management.ManagementResource; +import org.apache.slider.server.appmaster.web.rest.publisher.PublisherResource; +import org.apache.slider.server.appmaster.web.rest.registry.RegistryResource; + +import javax.ws.rs.Path; + +/** + * 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 ManagementResource managementResource; + private final PublisherResource publisherResource; + private final RegistryResource registryResource; + private final ApplicationResource applicationResource; + + @Inject + public AMWebServices(WebAppApi slider) { + this.slider = slider; + managementResource = new ManagementResource(slider); + publisherResource = new PublisherResource(slider); + registryResource = new RegistryResource(slider); + applicationResource = new ApplicationResource(slider); + } + + @Path(RestPaths.SLIDER_SUBPATH_MANAGEMENT) + public ManagementResource getManagementResource() { + return managementResource; + } + + @Path(RestPaths.SLIDER_SUBPATH_PUBLISHER) + public PublisherResource getPublisherResource() { + return publisherResource; + } + + @Path(RestPaths.SLIDER_SUBPATH_REGISTRY) + public RegistryResource getRegistryResource() { + return registryResource; + } + + @Path(RestPaths.SLIDER_SUBPATH_APPLICATION) + public ApplicationResource getApplicationResource() { + return applicationResource; + } +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/31c4a419/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 new file mode 100644 index 0000000..7ff83b6 --- /dev/null +++ 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 @@ -0,0 +1,157 @@ +/* + * 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/31c4a419/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 new file mode 100644 index 0000000..d5b6b36 --- /dev/null +++ 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 @@ -0,0 +1,105 @@ +/* + * 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; + HttpServletResponse httpResp = (HttpServletResponse) resp; + + + 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/31c4a419/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 new file mode 100644 index 0000000..42a5bdd --- /dev/null +++ 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 @@ -0,0 +1,102 @@ +/** + * 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/31c4a419/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 new file mode 100644 index 0000000..ae9eb0f --- /dev/null +++ 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 @@ -0,0 +1,172 @@ +/* + * 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 WS_AGENT_CONTEXT_ROOT = "/" + AGENT_WS_CONTEXT; + public static final String V1_SLIDER = "/v1/slider"; + public static final String SLIDER_CONTEXT_ROOT = WS_CONTEXT_ROOT + V1_SLIDER; + public static final String RELATIVE_API = WS_CONTEXT + V1_SLIDER; + public static final String SLIDER_AGENT_CONTEXT_ROOT = WS_AGENT_CONTEXT_ROOT + V1_SLIDER; + 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"; + + + /** + * management path: {@value} + */ + public static final String SLIDER_PATH_MANAGEMENT = SLIDER_CONTEXT_ROOT + + SLIDER_SUBPATH_MANAGEMENT; + + public static final String RELATIVE_PATH_MANAGEMENT = RELATIVE_API + + SLIDER_SUBPATH_MANAGEMENT; + + /** + * Agents: {@value} + */ + public static final String SLIDER_PATH_AGENTS = SLIDER_AGENT_CONTEXT_ROOT + + SLIDER_SUBPATH_AGENTS; + + /** + * 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/31c4a419/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 new file mode 100644 index 0000000..86d68a8 --- /dev/null +++ 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 @@ -0,0 +1,58 @@ +/** + * 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/31c4a419/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/agent/AgentCommandType.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/agent/AgentCommandType.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/agent/AgentCommandType.java new file mode 100644 index 0000000..17cd8f2 --- /dev/null +++ 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/agent/AgentCommandType.java @@ -0,0 +1,23 @@ +/* + * 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.agent; + +public enum AgentCommandType { + EXECUTION_COMMAND, + STATUS_COMMAND, + REGISTRATION_COMMAND +} --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org