SLIDER-711 Implement initial read-only view of REST resources.
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/47ca9e65 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/47ca9e65 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/47ca9e65 Branch: refs/heads/feature/SLIDER-151_REST_API Commit: 47ca9e656b186d054b2f2ef2506f6bfd4b564d0d Parents: fad1b97 Author: Steve Loughran <[email protected]> Authored: Tue Dec 16 20:23:03 2014 +0000 Committer: Steve Loughran <[email protected]> Committed: Tue Dec 16 20:25:40 2014 +0000 ---------------------------------------------------------------------- .../server/appmaster/web/rest/RestPaths.java | 8 ++++ .../rest/application/ApplicationResource.java | 10 ++--- .../resources/LiveResourcesRefresher.java | 19 +++++----- .../resources/ResourceSnapshotRefresher.java | 40 ++++++++++++++++++++ 4 files changed, 62 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/47ca9e65/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java index a264f77..bd569ef 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/RestPaths.java @@ -131,4 +131,12 @@ public class RestPaths { public static final String APPLICATION_WADL = "/application.wadl"; + public static final String LIVE_RESOURCES = "/live/resources"; + 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/desired"; + 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"; } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/47ca9e65/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java index 2d63269..2477464 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java @@ -22,6 +22,7 @@ import com.google.common.collect.Lists; import org.apache.slider.core.conf.ConfTree; 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.application.resources.CachedContent; import org.apache.slider.server.appmaster.web.rest.application.resources.ContentCache; import org.apache.slider.server.appmaster.web.rest.application.resources.LiveResourcesRefresher; @@ -37,14 +38,13 @@ import java.util.List; public class ApplicationResource extends AbstractSliderResource { private static final Logger log = LoggerFactory.getLogger(ApplicationResource.class); - public static final String LIVE_RESOURCES_JSON = "/live/resources.json"; - ContentCache cache = new ContentCache(); public static final int LIFESPAN = 1000; + private final ContentCache cache = new ContentCache(); public ApplicationResource(WebAppApi slider) { super(slider); - cache.put(LIVE_RESOURCES_JSON, + cache.put(RestPaths.LIVE_RESOURCES, new CachedContent<ConfTree>(LIFESPAN, new LiveResourcesRefresher(slider.getAppState()))); } @@ -99,10 +99,10 @@ public class ApplicationResource extends AbstractSliderResource { } @GET - @Path(LIVE_RESOURCES_JSON) + @Path(RestPaths.LIVE_RESOURCES) @Produces({MediaType.APPLICATION_JSON}) public Object getLiveResources() { - return cache.get(LIVE_RESOURCES_JSON).get(); + return cache.get(RestPaths.LIVE_RESOURCES).get(); } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/47ca9e65/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/LiveResourcesRefresher.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/LiveResourcesRefresher.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/LiveResourcesRefresher.java index 5c46a64..fd52528 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/LiveResourcesRefresher.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/LiveResourcesRefresher.java @@ -36,34 +36,33 @@ public class LiveResourcesRefresher implements ResourceRefresher<ConfTree> { @Override public ConfTree refresh() { - ConfTree resources = new ConfTree(); - ConfTreeOperations ops = new ConfTreeOperations(resources); + // snapshot resources - state.getResourcesSnapshot(); + ConfTreeOperations resources = state.getResourcesSnapshot(); // then add actual values Map<Integer, RoleStatus> roleStatusMap = state.getRoleStatusMap(); for (RoleStatus status : roleStatusMap.values()) { String name = status.getName(); - ops.setComponentOpt(name, + resources.setComponentOpt(name, StatusKeys.COMPONENT_INSTANCES_REQUESTED, status.getRequested()); - ops.setComponentOpt(name, + resources.setComponentOpt(name, StatusKeys.COMPONENT_INSTANCES_ACTUAL, status.getActual()); - ops.setComponentOpt(name, + resources.setComponentOpt(name, StatusKeys.COMPONENT_INSTANCES_RELEASING, status.getReleasing()); - ops.setComponentOpt(name, + resources.setComponentOpt(name, StatusKeys.COMPONENT_INSTANCES_FAILED, status.getFailed()); - ops.setComponentOpt(name, + resources.setComponentOpt(name, StatusKeys.COMPONENT_INSTANCES_COMPLETED, status.getCompleted()); - ops.setComponentOpt(name, + resources.setComponentOpt(name, StatusKeys.COMPONENT_INSTANCES_STARTED, status.getStarted()); } - return resources; + return resources.getConfTree(); } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/47ca9e65/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ResourceSnapshotRefresher.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ResourceSnapshotRefresher.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/resources/ResourceSnapshotRefresher.java new file mode 100644 index 0000000..0034d57 --- /dev/null +++ b/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() { + + // snapshot resources + ConfTreeOperations resources = state.getResourcesSnapshot(); + return resources.getConfTree(); + } +}
