You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ji...@apache.org on 2016/12/07 21:10:06 UTC
[06/76] [abbrv] hadoop git commit: YARN-5461. Initial code ported
from slider-core module. (jianhe)
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/RegistrationResponse.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/RegistrationResponse.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/RegistrationResponse.java
new file mode 100644
index 0000000..80b7a5e
--- /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/RegistrationResponse.java
@@ -0,0 +1,133 @@
+/*
+ * 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;
+
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+public class RegistrationResponse {
+
+ @JsonProperty("response")
+ private RegistrationStatus response;
+
+ /**
+ * exitstatus is a code of error which was rised on server side. exitstatus
+ * = 0 (OK - Default) exitstatus = 1 (Registration failed because different
+ * version of agent and server)
+ */
+ @JsonProperty("exitstatus")
+ private int exitstatus;
+
+ /** log - message, which will be printed to agents log */
+ @JsonProperty("log")
+ private String log;
+
+ /** tags - tags associated with the container */
+ @JsonProperty("tags")
+ private String tags;
+
+ @JsonProperty("package")
+ private String pkg;
+
+ //Response id to start with, usually zero.
+ @JsonProperty("responseId")
+ private long responseId;
+
+ @JsonProperty("statusCommands")
+ private List<StatusCommand> statusCommands = null;
+
+ public RegistrationResponse() {
+ }
+
+ public RegistrationStatus getResponse() {
+ return response;
+ }
+
+ public void setResponse(RegistrationStatus response) {
+ this.response = response;
+ }
+
+ public int getExitstatus() {
+ return exitstatus;
+ }
+
+ public void setExitstatus(int exitstatus) {
+ this.exitstatus = exitstatus;
+ }
+
+ public RegistrationStatus getResponseStatus() {
+ return response;
+ }
+
+ public void setResponseStatus(RegistrationStatus response) {
+ this.response = response;
+ }
+
+ public List<StatusCommand> getStatusCommands() {
+ return statusCommands;
+ }
+
+ public void setStatusCommands(List<StatusCommand> statusCommands) {
+ this.statusCommands = statusCommands;
+ }
+
+ public long getResponseId() {
+ return responseId;
+ }
+
+ public void setResponseId(long responseId) {
+ this.responseId = responseId;
+ }
+
+ public String getTags() {
+ return tags;
+ }
+
+ public void setTags(String tags) {
+ this.tags = tags;
+ }
+
+ public String getLog() {
+ return log;
+ }
+
+ public void setLog(String log) {
+ this.log = log;
+ }
+
+ public String getPkg() {
+ return pkg;
+ }
+
+ public void setPkg(String pkg) {
+ this.pkg = pkg;
+ }
+
+ @Override
+ public String toString() {
+ return "RegistrationResponse{" +
+ "response=" + response +
+ ", responseId=" + responseId +
+ ", statusCommands=" + statusCommands +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/RegistrationStatus.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/RegistrationStatus.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/RegistrationStatus.java
new file mode 100644
index 0000000..8374710
--- /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/RegistrationStatus.java
@@ -0,0 +1,22 @@
+/*
+ * 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 RegistrationStatus {
+ OK,
+ FAILED
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/StatusCommand.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/StatusCommand.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/StatusCommand.java
new file mode 100644
index 0000000..5b205b5
--- /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/StatusCommand.java
@@ -0,0 +1,152 @@
+/*
+ * 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;
+
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Command to report the status of a list of services in roles.
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+public class StatusCommand {
+ public static String STATUS_COMMAND = "STATUS";
+ public static String GET_CONFIG_COMMAND = "GET_CONFIG";
+
+ AgentCommandType agentCommandType;
+
+ private String clusterName;
+ private String serviceName;
+ private String componentName;
+ private Map<String, Map<String, String>> configurations;
+ private Map<String, String> commandParams = new HashMap<String, String>();
+ private Map<String, String> hostLevelParams = new HashMap<String, String>();
+ private String roleCommand;
+ private boolean yarnDockerMode;
+
+ public StatusCommand() {
+ this.agentCommandType = AgentCommandType.STATUS_COMMAND;
+ }
+
+ @JsonProperty("clusterName")
+ public String getClusterName() {
+ return clusterName;
+ }
+
+ @JsonProperty("clusterName")
+ public void setClusterName(String clusterName) {
+ this.clusterName = clusterName;
+ }
+
+ @JsonProperty("serviceName")
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ @JsonProperty("serviceName")
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ @JsonProperty("componentName")
+ public String getComponentName() {
+ return componentName;
+ }
+
+ @JsonProperty("componentName")
+ public void setComponentName(String componentName) {
+ this.componentName = componentName;
+ }
+
+ @JsonProperty("configurations")
+ public Map<String, Map<String, String>> getConfigurations() {
+ return configurations;
+ }
+
+ @JsonProperty("configurations")
+ public void setConfigurations(Map<String, Map<String, String>> configurations) {
+ this.configurations = configurations;
+ }
+
+ @JsonProperty("hostLevelParams")
+ public Map<String, String> getHostLevelParams() {
+ return hostLevelParams;
+ }
+
+ @JsonProperty("hostLevelParams")
+ public void setHostLevelParams(Map<String, String> params) {
+ this.hostLevelParams = params;
+ }
+
+ @JsonProperty("commandParams")
+ public Map<String, String> getCommandParams() {
+ return commandParams;
+ }
+
+ @JsonProperty("commandParams")
+ public void setCommandParams(Map<String, String> commandParams) {
+ this.commandParams = commandParams;
+ }
+
+ @JsonProperty("commandType")
+ public AgentCommandType getCommandType() {
+ return agentCommandType;
+ }
+
+ @JsonProperty("commandType")
+ public void setCommandType(AgentCommandType commandType) {
+ this.agentCommandType = commandType;
+ }
+
+ @JsonProperty("roleCommand")
+ public String getRoleCommand() {
+ return roleCommand;
+ }
+
+ @JsonProperty("roleCommand")
+ public void setRoleCommand(String roleCommand) {
+ this.roleCommand = roleCommand;
+ }
+
+ @JsonProperty("yarnDockerMode")
+ public boolean isYarnDockerMode() {
+ return yarnDockerMode;
+ }
+
+ @JsonProperty("yarnDockerMode")
+ public void setYarnDockerMode(boolean yarnDockerMode) {
+ this.yarnDockerMode = yarnDockerMode;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("StatusCommand [agentCommandType=").append(agentCommandType)
+ .append(", clusterName=").append(clusterName).append(", serviceName=")
+ .append(serviceName).append(", componentName=").append(componentName)
+ .append(", configurations=").append(configurations)
+ .append(", commandParams=").append(commandParams)
+ .append(", hostLevelParams=").append(hostLevelParams)
+ .append(", roleCommand=").append(roleCommand).append("]");
+ return builder.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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
new file mode 100644
index 0000000..2facf16
--- /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/application/ApplicationResouceContentCacheFactory.java
@@ -0,0 +1,63 @@
+/*
+ * 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.AggregateModelRefresher;
+import org.apache.slider.server.appmaster.web.rest.application.resources.AppconfRefresher;
+import org.apache.slider.server.appmaster.web.rest.application.resources.CachedContent;
+import org.apache.slider.server.appmaster.web.rest.application.resources.ContentCache;
+import org.apache.slider.server.appmaster.web.rest.application.resources.LiveComponentsRefresher;
+import org.apache.slider.server.appmaster.web.rest.application.resources.LiveContainersRefresher;
+import org.apache.slider.server.appmaster.web.rest.application.resources.LiveNodesRefresher;
+import org.apache.slider.server.appmaster.web.rest.application.resources.LiveResourcesRefresher;
+import org.apache.slider.server.appmaster.web.rest.application.resources.LiveStatisticsRefresher;
+
+import static org.apache.slider.server.appmaster.web.rest.RestPaths.*;
+
+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();
+ cache.put(LIVE_RESOURCES, new CachedContent<>(LIFESPAN, new LiveResourcesRefresher(state)));
+ cache.put(LIVE_CONTAINERS, new CachedContent<>(LIFESPAN, new LiveContainersRefresher(state)));
+ cache.put(LIVE_COMPONENTS, new CachedContent<>(LIFESPAN, new LiveComponentsRefresher(state)));
+ cache.put(LIVE_NODES, new CachedContent<>(LIFESPAN, new LiveNodesRefresher(state)));
+ cache.put(MODEL_DESIRED,
+ new CachedContent<>(LIFESPAN, new AggregateModelRefresher(state, false)));
+ cache.put(MODEL_RESOLVED,
+ new CachedContent<>(LIFESPAN, new AggregateModelRefresher(state, true)));
+ cache.put(MODEL_RESOLVED_APPCONF,
+ new CachedContent<>(LIFESPAN, new AppconfRefresher(state, false, false)));
+ cache.put(MODEL_RESOLVED_RESOURCES,
+ new CachedContent<>(LIFESPAN, new AppconfRefresher(state, false, true)));
+ cache.put(MODEL_DESIRED_APPCONF,
+ new CachedContent<>(LIFESPAN, new AppconfRefresher(state, true, false)));
+ cache.put(MODEL_DESIRED_RESOURCES,
+ new CachedContent<>(LIFESPAN, new AppconfRefresher(state, true, true)));
+ cache.put(LIVE_STATISTICS, new CachedContent<>(LIFESPAN, new LiveStatisticsRefresher(state)));
+ return cache;
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/ApplicationResource.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/ApplicationResource.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/ApplicationResource.java
new file mode 100644
index 0000000..52068d6
--- /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/application/ApplicationResource.java
@@ -0,0 +1,516 @@
+/*
+ * 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 com.google.common.collect.Lists;
+import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
+import org.apache.hadoop.yarn.webapp.BadRequestException;
+import org.apache.hadoop.yarn.webapp.NotFoundException;
+import org.apache.slider.api.types.ApplicationLivenessInformation;
+import org.apache.slider.api.types.ComponentInformation;
+import org.apache.slider.api.types.ContainerInformation;
+import org.apache.slider.api.types.NodeInformation;
+import org.apache.slider.api.types.NodeInformationList;
+import org.apache.slider.core.conf.AggregateConf;
+import org.apache.slider.core.conf.ConfTree;
+import org.apache.slider.core.exceptions.NoSuchNodeException;
+import org.apache.slider.core.persist.ConfTreeSerDeser;
+import org.apache.slider.server.appmaster.actions.ActionFlexCluster;
+import org.apache.slider.server.appmaster.actions.AsyncAction;
+import org.apache.slider.server.appmaster.actions.QueueAccess;
+import org.apache.slider.server.appmaster.state.RoleInstance;
+import org.apache.slider.server.appmaster.state.StateAccessForProviders;
+import org.apache.slider.server.appmaster.web.WebAppApi;
+import org.apache.slider.server.appmaster.web.rest.AbstractSliderResource;
+import static org.apache.slider.server.appmaster.web.rest.RestPaths.*;
+
+import org.apache.slider.server.appmaster.web.rest.application.actions.RestActionStop;
+import org.apache.slider.server.appmaster.web.rest.application.actions.StopResponse;
+import org.apache.slider.server.appmaster.web.rest.application.resources.ContentCache;
+import org.apache.slider.server.appmaster.web.rest.application.actions.RestActionPing;
+import org.apache.slider.api.types.PingInformation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Singleton;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HEAD;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+
+import static javax.ws.rs.core.MediaType.*;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+@Singleton
+@SuppressWarnings("unchecked")
+public class ApplicationResource extends AbstractSliderResource {
+ private static final Logger log =
+ LoggerFactory.getLogger(ApplicationResource.class);
+
+ public static final List<String> LIVE_ENTRIES = toJsonList("resources",
+ "containers",
+ "components",
+ "nodes",
+ "statistics",
+ "internal");
+
+ public static final List<String> ROOT_ENTRIES =
+ toJsonList("model", "live", "actions");
+
+ public static final List<String> MODEL_ENTRIES =
+ toJsonList("desired", "resolved");
+
+ /**
+ * This is the cache of all content ... each entry is
+ * designed to be self-refreshing on get operations,
+ * so is never very out of date, yet many GETs don't
+ * overload the rest of the system.
+ */
+ private final ContentCache cache;
+ private final StateAccessForProviders state;
+ private final QueueAccess actionQueues;
+
+ public ApplicationResource(WebAppApi slider) {
+ super(slider);
+ state = slider.getAppState();
+ cache = slider.getContentCache();
+ actionQueues = slider.getQueues();
+ }
+
+ /**
+ * Build a new JSON-marshallable list of string elements
+ * @param elements elements
+ * @return something that can be returned
+ */
+ private static List<String> toJsonList(String... elements) {
+ return Lists.newArrayList(elements);
+ }
+
+ @GET
+ @Path("/")
+ @Produces({APPLICATION_JSON})
+ public List<String> getRoot() {
+ markGet(SLIDER_SUBPATH_APPLICATION);
+ return ROOT_ENTRIES;
+ }
+
+ /**
+ * Enum model values: desired and resolved
+ * @return the desired and resolved model
+ */
+ @GET
+ @Path(MODEL)
+ @Produces({APPLICATION_JSON})
+ public List<String> getModel() {
+ markGet(SLIDER_SUBPATH_APPLICATION, MODEL);
+ return MODEL_ENTRIES;
+ }
+
+ @GET
+ @Path(MODEL_DESIRED)
+ @Produces({APPLICATION_JSON})
+ public AggregateConf getModelDesired() {
+ markGet(SLIDER_SUBPATH_APPLICATION, MODEL_DESIRED);
+ return lookupAggregateConf(MODEL_DESIRED);
+ }
+
+ @GET
+ @Path(MODEL_DESIRED_APPCONF)
+ @Produces({APPLICATION_JSON})
+ public ConfTree getModelDesiredAppconf() {
+ markGet(SLIDER_SUBPATH_APPLICATION, MODEL_DESIRED_APPCONF);
+ return lookupConfTree(MODEL_DESIRED_APPCONF);
+ }
+
+ @GET
+ @Path(MODEL_DESIRED_RESOURCES)
+ @Produces({APPLICATION_JSON})
+ public ConfTree getModelDesiredResources() {
+ markGet(SLIDER_SUBPATH_APPLICATION, MODEL_DESIRED_RESOURCES);
+ return lookupConfTree(MODEL_DESIRED_RESOURCES);
+ }
+
+/*
+ @PUT
+ @Path(MODEL_DESIRED_RESOURCES)
+// @Consumes({APPLICATION_JSON, TEXT_PLAIN})
+ @Consumes({TEXT_PLAIN})
+ @Produces({APPLICATION_JSON})
+*/
+ public ConfTree setModelDesiredResources(
+ String json) {
+ markPut(SLIDER_SUBPATH_APPLICATION, MODEL_DESIRED_RESOURCES);
+ int size = json != null ? json.length() : 0;
+ log.info("PUT {} {} bytes:\n{}", MODEL_DESIRED_RESOURCES,
+ size,
+ json);
+ if (size == 0) {
+ log.warn("No JSON in PUT request; rejecting");
+ throw new BadRequestException("No JSON in PUT");
+ }
+
+ try {
+ ConfTreeSerDeser serDeser = new ConfTreeSerDeser();
+ ConfTree updated = serDeser.fromJson(json);
+ queue(new ActionFlexCluster("flex",
+ 1, TimeUnit.MILLISECONDS,
+ updated));
+ // return the updated value, even though it potentially hasn't yet
+ // been executed
+ return updated;
+ } catch (Exception e) {
+ throw buildException("PUT to "+ MODEL_DESIRED_RESOURCES , e);
+ }
+ }
+ @PUT
+ @Path(MODEL_DESIRED_RESOURCES)
+ @Consumes({APPLICATION_JSON})
+ @Produces({APPLICATION_JSON})
+ public ConfTree setModelDesiredResources(
+ ConfTree updated) {
+ try {
+ queue(new ActionFlexCluster("flex",
+ 1, TimeUnit.MILLISECONDS,
+ updated));
+ // return the updated value, even though it potentially hasn't yet
+ // been executed
+ return updated;
+ } catch (Exception e) {
+ throw buildException("PUT to "+ MODEL_DESIRED_RESOURCES , e);
+ }
+ }
+
+
+
+ @GET
+ @Path(MODEL_RESOLVED)
+ @Produces({APPLICATION_JSON})
+ public AggregateConf getModelResolved() {
+ markGet(SLIDER_SUBPATH_APPLICATION, MODEL_RESOLVED);
+ return lookupAggregateConf(MODEL_RESOLVED);
+ }
+
+ @GET
+ @Path(MODEL_RESOLVED_APPCONF)
+ @Produces({APPLICATION_JSON})
+ public ConfTree getModelResolvedAppconf() {
+ markGet(SLIDER_SUBPATH_APPLICATION, MODEL_RESOLVED_APPCONF);
+ return lookupConfTree(MODEL_RESOLVED_APPCONF);
+ }
+
+ @GET
+ @Path(MODEL_RESOLVED_RESOURCES)
+ @Produces({APPLICATION_JSON})
+ public ConfTree getModelResolvedResources() {
+ markGet(SLIDER_SUBPATH_APPLICATION, MODEL_RESOLVED_RESOURCES);
+ return lookupConfTree(MODEL_RESOLVED_RESOURCES);
+ }
+
+ @GET
+ @Path(LIVE)
+ @Produces({APPLICATION_JSON})
+ public List<String> getLive() {
+ markGet(SLIDER_SUBPATH_APPLICATION, LIVE);
+ return LIVE_ENTRIES;
+ }
+
+ @GET
+ @Path(LIVE_RESOURCES)
+ @Produces({APPLICATION_JSON})
+ public ConfTree getLiveResources() {
+ markGet(SLIDER_SUBPATH_APPLICATION, LIVE_RESOURCES);
+ return lookupConfTree(LIVE_RESOURCES);
+ }
+
+ @GET
+ @Path(LIVE_CONTAINERS)
+ @Produces({APPLICATION_JSON})
+ public Map<String, ContainerInformation> getLiveContainers() {
+ markGet(SLIDER_SUBPATH_APPLICATION, LIVE_CONTAINERS);
+ try {
+ return (Map<String, ContainerInformation>)cache.lookup(
+ LIVE_CONTAINERS);
+ } catch (Exception e) {
+ throw buildException(LIVE_CONTAINERS, e);
+ }
+ }
+
+ @GET
+ @Path(LIVE_CONTAINERS + "/{containerId}")
+ @Produces({APPLICATION_JSON})
+ public ContainerInformation getLiveContainer(
+ @PathParam("containerId") String containerId) {
+ markGet(SLIDER_SUBPATH_APPLICATION, LIVE_CONTAINERS);
+ try {
+ RoleInstance id = state.getLiveInstanceByContainerID(containerId);
+ return id.serialize();
+ } catch (NoSuchNodeException e) {
+ throw new NotFoundException("Unknown container: " + containerId);
+ } catch (Exception e) {
+ throw buildException(LIVE_CONTAINERS + "/"+ containerId, e);
+ }
+ }
+
+ @GET
+ @Path(LIVE_COMPONENTS)
+ @Produces({APPLICATION_JSON})
+ public Map<String, ComponentInformation> getLiveComponents() {
+ markGet(SLIDER_SUBPATH_APPLICATION, LIVE_COMPONENTS);
+ try {
+ return (Map<String, ComponentInformation>) cache.lookup(LIVE_COMPONENTS);
+ } catch (Exception e) {
+ throw buildException(LIVE_COMPONENTS, e);
+ }
+ }
+
+ @GET
+ @Path(LIVE_COMPONENTS + "/{component}")
+ @Produces({APPLICATION_JSON})
+ public ComponentInformation getLiveComponent(
+ @PathParam("component") String component) {
+ markGet(SLIDER_SUBPATH_APPLICATION, LIVE_COMPONENTS);
+ try {
+ return state.getComponentInformation(component);
+ } catch (YarnRuntimeException e) {
+ throw new NotFoundException("Unknown component: " + component);
+ } catch (Exception e) {
+ throw buildException(LIVE_CONTAINERS +"/" + component, e);
+ }
+ }
+
+ /**
+ * Liveness information for the application as a whole
+ * @return snapshot of liveness
+ */
+ @GET
+ @Path(LIVE_LIVENESS)
+ @Produces({APPLICATION_JSON})
+ public ApplicationLivenessInformation getLivenessInformation() {
+ markGet(SLIDER_SUBPATH_APPLICATION, LIVE_LIVENESS);
+ try {
+ return state.getApplicationLivenessInformation();
+ } catch (Exception e) {
+ throw buildException(LIVE_CONTAINERS, e);
+ }
+ }
+
+/*
+TODO: decide what structure to return here, then implement
+
+ @GET
+ @Path(LIVE_LIVENESS + "/{component}")
+ @Produces({APPLICATION_JSON})
+ public ApplicationLivenessInformation getLivenessForComponent(
+ @PathParam("component") String component) {
+ markGet(SLIDER_SUBPATH_APPLICATION, LIVE_COMPONENTS);
+ try {
+ RoleStatus roleStatus = state.lookupRoleStatus(component);
+ ApplicationLivenessInformation info = new ApplicationLivenessInformation();
+ info.requested = roleStatus.getRequested();
+ info.allRequestsSatisfied = info.requested == 0;
+ return info;
+ } catch (YarnRuntimeException e) {
+ throw new NotFoundException("Unknown component: " + component);
+ } catch (Exception e) {
+ throw buildException(LIVE_LIVENESS + "/" + component, e);
+ }
+ }
+*/
+
+
+ @GET
+ @Path(LIVE_NODES)
+ @Produces({APPLICATION_JSON})
+ public NodeInformationList getLiveNodes() {
+ markGet(SLIDER_SUBPATH_APPLICATION, LIVE_COMPONENTS);
+ try {
+ return (NodeInformationList) cache.lookup(LIVE_NODES);
+ } catch (Exception e) {
+ throw buildException(LIVE_COMPONENTS, e);
+ }
+ }
+
+ @GET
+ @Path(LIVE_NODES + "/{hostname}")
+ @Produces({APPLICATION_JSON})
+ public NodeInformation getLiveNode(@PathParam("hostname") String hostname) {
+ markGet(SLIDER_SUBPATH_APPLICATION, LIVE_COMPONENTS);
+ try {
+ NodeInformation ni = state.getNodeInformation(hostname);
+ if (ni != null) {
+ return ni;
+ } else {
+ throw new NotFoundException("Unknown node: " + hostname);
+ }
+ } catch (NotFoundException e) {
+ throw e;
+ } catch (Exception e) {
+ throw buildException(LIVE_COMPONENTS + "/" + hostname, e);
+ }
+ }
+
+ /**
+ * Statistics of the application
+ * @return snapshot statistics
+ */
+ @GET
+ @Path(LIVE_STATISTICS)
+ @Produces({APPLICATION_JSON})
+ public Map<String, Integer> getLiveStatistics() {
+ markGet(SLIDER_SUBPATH_APPLICATION, LIVE_LIVENESS);
+ try {
+ return (Map<String, Integer>) cache.lookup(LIVE_STATISTICS);
+ } catch (Exception e) {
+ throw buildException(LIVE_STATISTICS, e);
+ }
+ }
+
+ /**
+ * Helper method; look up an aggregate configuration in the cache from
+ * a key, or raise an exception
+ * @param key key to resolve
+ * @return the configuration
+ * @throws WebApplicationException on a failure
+ */
+ protected AggregateConf lookupAggregateConf(String key) {
+ try {
+ return (AggregateConf) cache.lookup(key);
+ } catch (Exception e) {
+ throw buildException(key, e);
+ }
+ }
+
+
+ /**
+ * Helper method; look up an conf tree in the cache from
+ * a key, or raise an exception
+ * @param key key to resolve
+ * @return the configuration
+ * @throws WebApplicationException on a failure
+ */
+ protected ConfTree lookupConfTree(String key) {
+ try {
+ return (ConfTree) cache.lookup(key);
+ } catch (Exception e) {
+ throw buildException(key, e);
+ }
+ }
+
+ /* ************************************************************************
+
+ ACTION PING
+
+ **************************************************************************/
+
+ @GET
+ @Path(ACTION_PING)
+ @Produces({APPLICATION_JSON})
+ public PingInformation actionPingGet(@Context HttpServletRequest request,
+ @Context UriInfo uriInfo) {
+ markGet(SLIDER_SUBPATH_APPLICATION, ACTION_PING);
+ return new RestActionPing().ping(request, uriInfo, "");
+ }
+
+ @POST
+ @Path(ACTION_PING)
+ @Produces({APPLICATION_JSON})
+ public PingInformation actionPingPost(@Context HttpServletRequest request,
+ @Context UriInfo uriInfo,
+ String body) {
+ markPost(SLIDER_SUBPATH_APPLICATION, ACTION_PING);
+ return new RestActionPing().ping(request, uriInfo, body);
+ }
+
+ @PUT
+ @Path(ACTION_PING)
+ @Consumes({TEXT_PLAIN})
+ @Produces({APPLICATION_JSON})
+ public PingInformation actionPingPut(@Context HttpServletRequest request,
+ @Context UriInfo uriInfo,
+ String body) {
+ markPut(SLIDER_SUBPATH_APPLICATION, ACTION_PING);
+ return new RestActionPing().ping(request, uriInfo, body);
+ }
+
+ @DELETE
+ @Path(ACTION_PING)
+ @Consumes({APPLICATION_JSON})
+ @Produces({APPLICATION_JSON})
+ public PingInformation actionPingDelete(@Context HttpServletRequest request,
+ @Context UriInfo uriInfo) {
+ markDelete(SLIDER_SUBPATH_APPLICATION, ACTION_PING);
+ return new RestActionPing().ping(request, uriInfo, "");
+ }
+
+ @HEAD
+ @Path(ACTION_PING)
+ public Object actionPingHead(@Context HttpServletRequest request,
+ @Context UriInfo uriInfo) {
+ mark("HEAD", SLIDER_SUBPATH_APPLICATION, ACTION_PING);
+ return new RestActionPing().ping(request, uriInfo, "");
+ }
+
+ /* ************************************************************************
+
+ ACTION STOP
+
+ **************************************************************************/
+
+
+ @POST
+ @Path(ACTION_STOP)
+ @Produces({APPLICATION_JSON})
+ public StopResponse actionStop(@Context HttpServletRequest request,
+ @Context UriInfo uriInfo,
+ String body) {
+ markPost(SLIDER_SUBPATH_APPLICATION, ACTION_STOP);
+ return new RestActionStop(slider).stop(request, uriInfo, body);
+ }
+
+ /**
+ * Schedule an action
+ * @param action for delayed execution
+ */
+ public void schedule(AsyncAction action) {
+ actionQueues.schedule(action);
+ }
+
+ /**
+ * Put an action on the immediate queue -to be executed when the queue
+ * reaches it.
+ * @param action action to queue
+ */
+ public void queue(AsyncAction action) {
+ actionQueues.put(action);
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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
new file mode 100644
index 0000000..96b4f75
--- /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/application/actions/RestActionPing.java
@@ -0,0 +1,50 @@
+/*
+ * 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/d8cab88d/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
new file mode 100644
index 0000000..544f589
--- /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/application/actions/RestActionStop.java
@@ -0,0 +1,67 @@
+/*
+ * 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/d8cab88d/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
new file mode 100644
index 0000000..9af6a22
--- /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/application/actions/StopResponse.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.slider.server.appmaster.web.rest.application.actions;
+
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+public class StopResponse {
+ String verb;
+ public String text;
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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
new file mode 100644
index 0000000..34eb82c
--- /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/application/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * 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/d8cab88d/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/AggregateModelRefresher.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/AggregateModelRefresher.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/AggregateModelRefresher.java
new file mode 100644
index 0000000..ee28abf
--- /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/application/resources/AggregateModelRefresher.java
@@ -0,0 +1,47 @@
+/*
+ * 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 org.apache.slider.core.conf.AggregateConf;
+import org.apache.slider.server.appmaster.state.StateAccessForProviders;
+
+/**
+ * Refresh the aggregate desired model via
+ * {@link StateAccessForProviders#getInstanceDefinitionSnapshot()}
+ */
+public class AggregateModelRefresher
+ implements ResourceRefresher<AggregateConf> {
+
+ private final StateAccessForProviders state;
+ private final boolean resolved;
+
+ public AggregateModelRefresher(StateAccessForProviders state,
+ boolean resolved) {
+ this.state = state;
+ this.resolved = resolved;
+ }
+
+ @Override
+ public AggregateConf refresh() throws Exception {
+ return
+ resolved ?
+ state.getInstanceDefinitionSnapshot()
+ : state.getUnresolvedInstanceDefinition();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/AppconfRefresher.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/AppconfRefresher.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/AppconfRefresher.java
new file mode 100644
index 0000000..06460cc
--- /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/application/resources/AppconfRefresher.java
@@ -0,0 +1,55 @@
+/*
+ * 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 org.apache.slider.core.conf.AggregateConf;
+import org.apache.slider.core.conf.ConfTree;
+import org.apache.slider.core.persist.ConfTreeSerDeser;
+import org.apache.slider.server.appmaster.state.StateAccessForProviders;
+
+/**
+ * refresher for resources and application configuration
+ */
+public class AppconfRefresher
+ implements ResourceRefresher<ConfTree> {
+
+ private final StateAccessForProviders state;
+ private final boolean unresolved;
+ private final boolean resources;
+
+ public AppconfRefresher(StateAccessForProviders state,
+ boolean unresolved,
+ boolean resources) {
+ this.state = state;
+ this.unresolved = unresolved;
+ this.resources = resources;
+ }
+
+
+ @Override
+ public ConfTree refresh() throws Exception {
+ AggregateConf aggregateConf =
+ unresolved ?
+ state.getUnresolvedInstanceDefinition():
+ state.getInstanceDefinitionSnapshot();
+ ConfTree ct = resources ? aggregateConf.getResources()
+ : aggregateConf.getAppConf();
+ return new ConfTreeSerDeser().fromInstance(ct);
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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
new file mode 100644
index 0000000..22fd0fe
--- /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/application/resources/CachedContent.java
@@ -0,0 +1,121 @@
+/*
+ * 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/d8cab88d/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
new file mode 100644
index 0000000..8f026a1
--- /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/application/resources/ContentCache.java
@@ -0,0 +1,67 @@
+/*
+ * 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/d8cab88d/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/LiveComponentsRefresher.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/LiveComponentsRefresher.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/LiveComponentsRefresher.java
new file mode 100644
index 0000000..b6627a7
--- /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/application/resources/LiveComponentsRefresher.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.slider.api.types.ComponentInformation;
+import org.apache.slider.server.appmaster.state.StateAccessForProviders;
+
+import java.util.Map;
+
+public class LiveComponentsRefresher
+ implements ResourceRefresher<Map<String, ComponentInformation>> {
+
+ private final StateAccessForProviders state;
+
+ public LiveComponentsRefresher(StateAccessForProviders state) {
+ this.state = state;
+ }
+
+ @Override
+ public Map<String, ComponentInformation> refresh() {
+ return state.getComponentInfoSnapshot();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/LiveContainersRefresher.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/LiveContainersRefresher.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/LiveContainersRefresher.java
new file mode 100644
index 0000000..68bd8a2
--- /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/application/resources/LiveContainersRefresher.java
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.slider.api.types.ContainerInformation;
+import org.apache.slider.server.appmaster.state.RoleInstance;
+import org.apache.slider.server.appmaster.state.StateAccessForProviders;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Refresh the container list.
+ */
+public class LiveContainersRefresher implements ResourceRefresher<Map<String, ContainerInformation>> {
+
+ private final StateAccessForProviders state;
+
+ public LiveContainersRefresher(StateAccessForProviders state) {
+ this.state = state;
+ }
+
+ @Override
+ public Map<String, ContainerInformation> refresh() throws
+ Exception {
+ List<RoleInstance> containerList = state.cloneOwnedContainerList();
+
+ Map<String, ContainerInformation> map = new HashMap<>();
+ for (RoleInstance instance : containerList) {
+ ContainerInformation serialized = instance.serialize();
+ map.put(serialized.containerId, serialized);
+ }
+ return map;
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/LiveNodesRefresher.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/LiveNodesRefresher.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/LiveNodesRefresher.java
new file mode 100644
index 0000000..aeb7a11
--- /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/application/resources/LiveNodesRefresher.java
@@ -0,0 +1,41 @@
+/*
+ * 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 org.apache.slider.api.types.NodeInformationList;
+import org.apache.slider.server.appmaster.state.StateAccessForProviders;
+
+/**
+ * Update the live nodes map
+ */
+public class LiveNodesRefresher
+ implements ResourceRefresher<NodeInformationList> {
+
+ private final StateAccessForProviders state;
+
+ public LiveNodesRefresher(StateAccessForProviders state) {
+ this.state = state;
+ }
+
+ @Override
+ public NodeInformationList refresh() {
+
+ return new NodeInformationList(state.getNodeInformationSnapshot().values());
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/LiveResourcesRefresher.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/LiveResourcesRefresher.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/LiveResourcesRefresher.java
new file mode 100644
index 0000000..f988297
--- /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/application/resources/LiveResourcesRefresher.java
@@ -0,0 +1,68 @@
+/*
+ * 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 org.apache.slider.api.StatusKeys;
+import org.apache.slider.core.conf.ConfTree;
+import org.apache.slider.core.conf.ConfTreeOperations;
+import org.apache.slider.server.appmaster.state.RoleStatus;
+import org.apache.slider.server.appmaster.state.StateAccessForProviders;
+
+import java.util.Map;
+
+public class LiveResourcesRefresher implements ResourceRefresher<ConfTree> {
+
+ private final StateAccessForProviders state;
+
+ public LiveResourcesRefresher(StateAccessForProviders state) {
+ this.state = state;
+ }
+
+ @Override
+ public ConfTree refresh() throws Exception {
+
+ // snapshot resources
+ ConfTreeOperations resources = state.getResourcesSnapshot();
+ // then add actual values
+ Map<Integer, RoleStatus> roleStatusMap = state.getRoleStatusMap();
+
+ for (RoleStatus status : roleStatusMap.values()) {
+ String name = status.getName();
+ resources.setComponentOpt(name,
+ StatusKeys.COMPONENT_INSTANCES_REQUESTING,
+ status.getRequested());
+ resources.setComponentOpt(name,
+ StatusKeys.COMPONENT_INSTANCES_ACTUAL,
+ status.getActual());
+ resources.setComponentOpt(name,
+ StatusKeys.COMPONENT_INSTANCES_RELEASING,
+ status.getReleasing());
+ resources.setComponentOpt(name,
+ StatusKeys.COMPONENT_INSTANCES_FAILED,
+ status.getFailed());
+ resources.setComponentOpt(name,
+ StatusKeys.COMPONENT_INSTANCES_COMPLETED,
+ status.getCompleted());
+ resources.setComponentOpt(name,
+ StatusKeys.COMPONENT_INSTANCES_STARTED,
+ status.getStarted());
+ }
+ return resources.getConfTree();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/LiveStatisticsRefresher.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/LiveStatisticsRefresher.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/LiveStatisticsRefresher.java
new file mode 100644
index 0000000..d31b455
--- /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/application/resources/LiveStatisticsRefresher.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.slider.server.appmaster.state.StateAccessForProviders;
+
+import java.util.Map;
+
+public class LiveStatisticsRefresher implements ResourceRefresher<Map<String,Integer>> {
+
+ private final StateAccessForProviders state;
+
+ public LiveStatisticsRefresher(StateAccessForProviders state) {
+ this.state = state;
+ }
+
+ @Override
+ public Map<String, Integer> refresh() throws Exception {
+
+ // snapshot resources
+ return state.getLiveStatistics();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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
new file mode 100644
index 0000000..35f0367
--- /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/application/resources/ResourceRefresher.java
@@ -0,0 +1,31 @@
+/*
+ * 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;
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/ResourceSnapshotRefresher.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/ResourceSnapshotRefresher.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/ResourceSnapshotRefresher.java
new file mode 100644
index 0000000..c16912a
--- /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/application/resources/ResourceSnapshotRefresher.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.apache.slider.core.conf.ConfTree;
+import org.apache.slider.core.conf.ConfTreeOperations;
+import org.apache.slider.server.appmaster.state.StateAccessForProviders;
+
+public class ResourceSnapshotRefresher implements ResourceRefresher<ConfTree> {
+
+ private final StateAccessForProviders state;
+
+ public ResourceSnapshotRefresher(StateAccessForProviders state) {
+ this.state = state;
+ }
+
+ @Override
+ public ConfTree refresh() throws Exception {
+
+ // snapshot resources
+ ConfTreeOperations resources = state.getResourcesSnapshot();
+ return resources.getConfTree();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/management/ManagementResource.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/management/ManagementResource.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/management/ManagementResource.java
new file mode 100644
index 0000000..f27711a
--- /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/management/ManagementResource.java
@@ -0,0 +1,93 @@
+/*
+ * 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.management;
+
+import org.apache.slider.core.conf.AggregateConf;
+import org.apache.slider.server.appmaster.web.WebAppApi;
+import org.apache.slider.server.appmaster.web.rest.AbstractSliderResource;
+import org.apache.slider.server.appmaster.web.rest.RestPaths;
+import org.apache.slider.server.appmaster.web.rest.management.resources.AggregateConfResource;
+import org.apache.slider.server.appmaster.web.rest.management.resources.ConfTreeResource;
+import org.apache.slider.server.appmaster.web.rest.management.resources.ResourceFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import java.net.URI;
+import java.net.URL;
+
+/**
+ *
+ */
+public class ManagementResource extends AbstractSliderResource {
+ protected static final Logger log =
+ LoggerFactory.getLogger(ManagementResource.class);
+ public static final String CONFIG = "config";
+ public static final String APP_UNDER_MANAGEMENT = "/app";
+
+ public ManagementResource(WebAppApi slider) {
+ super(slider);
+ }
+
+ private void init(HttpServletResponse res) {
+ res.setContentType(null);
+ }
+
+ @GET
+ public Response getWadl (@Context HttpServletRequest request) {
+ return redirectToAppWadl(request);
+ }
+
+ @GET
+ @Path("/app")
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public AggregateConfResource getAggregateConfiguration(@Context UriInfo uriInfo,
+ @Context HttpServletResponse res) {
+ init(res);
+ return ResourceFactory.createAggregateConfResource(getAggregateConf(),
+ uriInfo.getAbsolutePathBuilder());
+ }
+
+ @GET
+ @Path(APP_UNDER_MANAGEMENT+"/configurations/{config}")
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ConfTreeResource getConfTreeResource(@PathParam(CONFIG) String config,
+ @Context UriInfo uriInfo,
+ @Context HttpServletResponse res) {
+ init(res);
+ AggregateConfResource aggregateConf =
+ ResourceFactory.createAggregateConfResource(getAggregateConf(),
+ uriInfo.getBaseUriBuilder()
+ .path(RestPaths.SLIDER_CONTEXT_ROOT)
+ .path(RestPaths.MANAGEMENT + APP_UNDER_MANAGEMENT));
+ return aggregateConf.getConfTree(config);
+ }
+
+ protected AggregateConf getAggregateConf() {
+ return slider.getAppState().getInstanceDefinitionSnapshot();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/management/resources/ActionsResource.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/management/resources/ActionsResource.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/management/resources/ActionsResource.java
new file mode 100644
index 0000000..9b340fa
--- /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/management/resources/ActionsResource.java
@@ -0,0 +1,22 @@
+/*
+ * 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.management.resources;
+
+public class ActionsResource {
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/d8cab88d/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/management/resources/AggregateConfResource.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/management/resources/AggregateConfResource.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/management/resources/AggregateConfResource.java
new file mode 100644
index 0000000..794daf9
--- /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/management/resources/AggregateConfResource.java
@@ -0,0 +1,90 @@
+/*
+ * 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.management.resources;
+
+import org.apache.slider.core.conf.AggregateConf;
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+import javax.ws.rs.core.UriBuilder;
+import java.util.HashMap;
+import java.util.Map;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+public class AggregateConfResource {
+ private String href;
+ private final ConfTreeResource resources;
+ private final ConfTreeResource internal;
+ private final ConfTreeResource appConf;
+ @JsonIgnore
+ private Map<String, ConfTreeResource> confMap;
+
+ public AggregateConfResource(AggregateConf conf, UriBuilder uriBuilder) {
+ if (uriBuilder != null) {
+ this.href = uriBuilder.build().toASCIIString();
+ resources = ResourceFactory.createConfTreeResource(conf.getResources(),
+ uriBuilder.clone().path("configurations").path("resources"));
+ internal = ResourceFactory.createConfTreeResource(conf.getInternal(),
+ uriBuilder.clone().path("configurations").path("internal"));
+ appConf = ResourceFactory.createConfTreeResource(conf.getAppConf(),
+ uriBuilder.clone().path("configurations").path("appConf"));
+ initConfMap();
+ } else {
+ resources = null;
+ internal = null;
+ appConf = null;
+ }
+ }
+
+ private void initConfMap() {
+ confMap = new HashMap<>();
+ confMap.put("internal", internal);
+ confMap.put("resources", resources);
+ confMap.put("appConf", appConf);
+ }
+
+ public AggregateConfResource() {
+ this(null, null);
+ }
+
+ public ConfTreeResource getConfTree(String name) {
+ return confMap.get(name);
+ }
+
+ public String getHref() {
+ return href;
+ }
+
+ public void setHref(String href) {
+ this.href = href;
+ }
+
+ public ConfTreeResource getResources() {
+ return resources;
+ }
+
+ public ConfTreeResource getInternal() {
+ return internal;
+ }
+
+ public ConfTreeResource getAppConf() {
+ return appConf;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org