Repository: incubator-slider Updated Branches: refs/heads/develop 2037ac4ae -> de41cb5bd
SLIDER-787 App Upgrade/Reconfig support in Slider Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/315a8953 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/315a8953 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/315a8953 Branch: refs/heads/develop Commit: 315a89532bd35b48e2de113424f4f19f522c3e23 Parents: 057a8c8 Author: Gour Saha <[email protected]> Authored: Fri Feb 27 18:12:11 2015 -0800 Committer: Gour Saha <[email protected]> Committed: Fri Feb 27 18:12:11 2015 -0800 ---------------------------------------------------------------------- .../slider/api/proto/RestTypeMarshalling.java | 14 ++++++++-- .../org/apache/slider/client/SliderClient.java | 27 +++++++++++++++++++- .../client/ipc/SliderClusterOperations.java | 8 +++++- .../slider/common/params/ActionListArgs.java | 4 +++ .../apache/slider/common/params/Arguments.java | 1 + .../apache/slider/common/tools/SliderUtils.java | 22 ++++++++++++++-- 6 files changed, 70 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/315a8953/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java b/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java index fcd8582..f5dff8f 100644 --- a/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java +++ b/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java @@ -26,12 +26,11 @@ import org.apache.slider.core.conf.ConfTree; import org.apache.slider.core.conf.ConfTreeOperations; import org.apache.slider.core.persist.AggregateConfSerDeser; import org.apache.slider.core.persist.ConfTreeSerDeser; -import org.codehaus.jackson.JsonParseException; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; +import java.util.List; /** * Class to handle marshalling of REST @@ -138,6 +137,17 @@ public class RestTypeMarshalling { return info; } + public static List<ContainerInformation> unmarshall( + Messages.GetLiveContainersResponseProto wire) { + List<ContainerInformation> infoList = new ArrayList<ContainerInformation>( + wire.getContainersList().size()); + for (Messages.ContainerInformationProto container : wire + .getContainersList()) { + infoList.add(unmarshall(container)); + } + return infoList; + } + public static Messages.ContainerInformationProto marshall(ContainerInformation info) { http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/315a8953/slider-core/src/main/java/org/apache/slider/client/SliderClient.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java index 77b5e96..ed343d2 100644 --- a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java +++ b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java @@ -70,6 +70,7 @@ import org.apache.slider.api.ResourceKeys; import org.apache.slider.api.SliderClusterProtocol; import org.apache.slider.api.StateValues; import org.apache.slider.api.proto.Messages; +import org.apache.slider.api.types.ContainerInformation; import org.apache.slider.api.types.SliderInstanceDescription; import org.apache.slider.client.ipc.SliderClusterOperations; import org.apache.slider.common.Constants; @@ -2095,12 +2096,18 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe boolean live = args.live; String state = args.state; + boolean listContainers = args.containers; boolean verbose = args.verbose; if (live && !state.isEmpty()) { throw new BadCommandArgumentsException( Arguments.ARG_LIVE + " and " + Arguments.ARG_STATE + " are exclusive"); } + if (listContainers && isUnset(clustername)) { + throw new BadCommandArgumentsException( + "Should specify an application instance with " + + Arguments.ARG_CONTAINERS); + } // flag to indicate only services in a specific state are to be listed boolean listOnlyInState = live || !state.isEmpty(); @@ -2135,6 +2142,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe min, max, reportMap.size() ); + List<ContainerInformation> containers = null; if (isSet(clustername)) { // only one instance is expected // resolve the persistent value @@ -2145,7 +2153,10 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe // create a new map with only that instance in it. // this restricts the output of results to this instance persistentInstances = new HashMap<String, Path>(); - persistentInstances.put(clustername, persistent); + persistentInstances.put(clustername, persistent); + if (listContainers) { + containers = getContainers(clustername); + } } // at this point there is either the entire list or a stripped down instance @@ -2157,8 +2168,10 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe // list the details if all were requested, or the filtering contained // a report listed++; + // containers will be non-null when only one instance is requested String details = SliderUtils.instanceDetailsToString(name, report, + containers, verbose); print(details); } @@ -2167,6 +2180,18 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe return listed > 0 ? EXIT_SUCCESS: EXIT_FALSE; } + public List<ContainerInformation> getContainers(String name) + throws YarnException, IOException { + SliderClusterOperations clusterOps = new SliderClusterOperations( + bondToCluster(name)); + try { + return clusterOps.getContainers(); + } catch (NoSuchNodeException e) { + throw new BadClusterStateException( + "Containers not found for application instance %s", name); + } + } + /** * Enumerate slider instances for the current user, and the * most recent app report, where available. http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/315a8953/slider-core/src/main/java/org/apache/slider/client/ipc/SliderClusterOperations.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/ipc/SliderClusterOperations.java b/slider-core/src/main/java/org/apache/slider/client/ipc/SliderClusterOperations.java index faaf619..bcabf64 100644 --- a/slider-core/src/main/java/org/apache/slider/client/ipc/SliderClusterOperations.java +++ b/slider-core/src/main/java/org/apache/slider/client/ipc/SliderClusterOperations.java @@ -432,7 +432,13 @@ public class SliderClusterOperations { return unmarshall(response); } - + public List<ContainerInformation> getContainers() throws IOException { + Messages.GetLiveContainersResponseProto response = appMaster + .getLiveContainers(Messages.GetLiveContainersRequestProto.newBuilder() + .build()); + return unmarshall(response); + } + public Map<String, ComponentInformation> enumComponents() throws IOException { Messages.GetLiveComponentsResponseProto response = appMaster.getLiveComponents( http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/315a8953/slider-core/src/main/java/org/apache/slider/common/params/ActionListArgs.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/common/params/ActionListArgs.java b/slider-core/src/main/java/org/apache/slider/common/params/ActionListArgs.java index 30cc93e..00767e7 100644 --- a/slider-core/src/main/java/org/apache/slider/common/params/ActionListArgs.java +++ b/slider-core/src/main/java/org/apache/slider/common/params/ActionListArgs.java @@ -42,6 +42,10 @@ public class ActionListArgs extends AbstractActionArgs { description = "print out information in details") public boolean verbose = false; + @Parameter(names = {ARG_CONTAINERS}, + description = "List containers of an application instance") + public boolean containers; + /** * Get the min #of params expected * @return the min number of params in the {@link #parameters} field http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/315a8953/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java b/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java index 789b285..b8414e3 100644 --- a/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java +++ b/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java @@ -69,6 +69,7 @@ public interface Arguments { String ARG_LISTEXP = "--listexp"; String ARG_LISTFILES = "--listfiles"; String ARG_LIVE = "--live"; + String ARG_CONTAINERS = "--containers"; String ARG_MANAGER = "--manager"; String ARG_MANAGER_SHORT = "--m"; String ARG_MESSAGE = "--message"; http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/315a8953/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java b/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java index 1e3379c..1474ad3 100644 --- a/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java +++ b/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java @@ -50,6 +50,7 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.slider.Slider; import org.apache.slider.api.InternalKeys; import org.apache.slider.api.RoleKeys; +import org.apache.slider.api.types.ContainerInformation; import org.apache.slider.common.SliderKeys; import org.apache.slider.common.SliderXmlConfKeys; import org.apache.slider.core.conf.MapOperations; @@ -661,11 +662,12 @@ public final class SliderUtils { */ public static String instanceDetailsToString(String name, ApplicationReport report, + List<ContainerInformation> containers, boolean verbose) { // format strings String staticf = "%-30s"; - String reportedf = staticf + " %10s %-40s"; - String livef = reportedf + " %s"; + String reportedf = staticf + " %10s %-42s"; + String livef = reportedf + " %s"; StringBuilder builder = new StringBuilder(200); if (report == null) { builder.append(String.format(staticf, name)); @@ -684,12 +686,28 @@ public final class SliderUtils { builder.append('\n'); builder.append(SliderUtils.appReportToString(report, "\n ")); } + if (containers != null) { + builder.append('\n'); + builder.append(SliderUtils.addContainersToString(containers)); + } } builder.append('\n'); return builder.toString(); } + public static String addContainersToString( + List<ContainerInformation> containers) { + String containerf = " %-40s %40s %-30s\n"; + StringBuilder builder = new StringBuilder(512); + builder.append("Containers:\n"); + for (ContainerInformation container : containers) { + builder.append(String.format(containerf, container.component, + container.containerId, container.host)); + } + return builder.toString(); + } + /** * Sorts the given list of application reports, most recently started * or finished instance first.
