From 7da243ebe05be27ade86feac83a6243eebba619c Mon Sep 17 00:00:00 2001 From: Jian He Date: Fri, 14 Oct 2016 13:47:38 -0700 Subject: [PATCH] YARN-5729. Bug fixes for the service Rest API. Contributed by Gour Saha --- .../services/api/impl/ApplicationApiService.java | 16 ++++++++++++++-- .../yarn/services/resource/Application.java | 6 +++--- .../hadoop/yarn/services/resource/Artifact.java | 4 +++- .../hadoop/yarn/services/resource/Component.java | 4 +++- .../yarn/services/resource/ConfigFile.java | 4 +++- .../yarn/services/resource/Configuration.java | 4 +++- .../hadoop/yarn/services/resource/Container.java | 6 +++--- .../yarn/services/resource/PlacementPolicy.java | 4 +++- .../yarn/services/resource/ReadinessCheck.java | 4 +++- .../hadoop/yarn/services/resource/Resource.java | 2 +- 10 files changed, 39 insertions(+), 15 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/api/impl/ApplicationApiService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/api/impl/ApplicationApiService.java index 0a62629c9a4..21cf1136ec8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/api/impl/ApplicationApiService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/api/impl/ApplicationApiService.java @@ -276,7 +276,7 @@ public class ApplicationApiService implements ApplicationApi { // If it is a simple app with no components, then create a default component if (application.getComponents() == null) { - application.setComponents(getDefaultComponentAsList()); + application.setComponents(getDefaultComponentAsList(application)); } // Application lifetime if not specified, is set to unlimited lifetime @@ -1029,7 +1029,8 @@ public class ApplicationApiService implements ApplicationApi { // end-users point of view, is out of scope of the REST API. Also, this // readiness has nothing to do with readiness-check defined at the component // level (which is used for dependency resolution of component DAG). - if (totalNumberOfIpAssignedContainers == totalExpectedNumberOfRunningContainers) { + if (totalNumberOfIpAssignedContainers + .longValue() == totalExpectedNumberOfRunningContainers.longValue()) { app.setState(ApplicationState.READY); } logger.info("Application = {}", app); @@ -1389,6 +1390,17 @@ public class ApplicationApiService implements ApplicationApi { return Response.status(Status.NO_CONTENT).build(); } + // create default component and initialize with app level global values + private List getDefaultComponentAsList(Application app) { + List comps = getDefaultComponentAsList(); + Component comp = comps.get(0); + comp.setArtifact(app.getArtifact()); + comp.setResource(app.getResource()); + comp.setNumberOfContainers(app.getNumberOfContainers()); + comp.setLaunchCommand(app.getLaunchCommand()); + return comps; + } + private List getDefaultComponentAsList() { Component comp = new Component(); comp.setName(DEFAULT_COMPONENT_NAME); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Application.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Application.java index 719bf95e9f5..ed65ad2b228 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Application.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Application.java @@ -168,19 +168,19 @@ public class Application extends BaseResource { * The time when the application was created, e.g. 2016-03-16T01:01:49.000Z. **/ public Application launchTime(Date launchTime) { - this.launchTime = launchTime; + this.launchTime = launchTime == null ? null : (Date) launchTime.clone(); return this; } @ApiModelProperty(example = "null", value = "The time when the application was created, e.g. 2016-03-16T01:01:49.000Z.") @JsonProperty("launch_time") public String getLaunchTime() { - return launchTime.toString(); + return launchTime == null ? null : launchTime.toString(); } @XmlElement(name = "launch_time") public void setLaunchTime(Date launchTime) { - this.launchTime = launchTime; + this.launchTime = launchTime == null ? null : (Date) launchTime.clone(); } /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Artifact.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Artifact.java index af0ad12848c..9ac2bc799f6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Artifact.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Artifact.java @@ -20,6 +20,7 @@ package org.apache.hadoop.yarn.services.resource; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import java.io.Serializable; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonInclude; @@ -33,7 +34,8 @@ import com.fasterxml.jackson.annotation.JsonValue; @ApiModel(description = "Artifact of an application component") @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-02T08:15:05.615-07:00") @JsonInclude(JsonInclude.Include.NON_NULL) -public class Artifact { +public class Artifact implements Serializable { + private static final long serialVersionUID = 3608929500111099035L; private String id = null; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Component.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Component.java index 1246aa81c9d..75f579aced9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Component.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Component.java @@ -20,6 +20,7 @@ package org.apache.hadoop.yarn.services.resource; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -42,7 +43,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-02T08:15:05.615-07:00") @XmlRootElement @JsonInclude(JsonInclude.Include.NON_NULL) -public class Component { +public class Component implements Serializable { + private static final long serialVersionUID = -8430058381509087805L; private String name = null; private List dependencies = new ArrayList(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/ConfigFile.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/ConfigFile.java index d06c1b8fe4d..3ced153bd6c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/ConfigFile.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/ConfigFile.java @@ -20,6 +20,7 @@ package org.apache.hadoop.yarn.services.resource; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import java.io.Serializable; import java.util.Objects; import javax.xml.bind.annotation.XmlElement; @@ -38,7 +39,8 @@ import com.fasterxml.jackson.annotation.JsonValue; @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-02T08:15:05.615-07:00") @XmlRootElement @JsonInclude(JsonInclude.Include.NON_NULL) -public class ConfigFile { +public class ConfigFile implements Serializable { + private static final long serialVersionUID = -7009402089417704612L; public enum TypeEnum { XML("xml"), PROPERTIES("properties"), JSON("json"), YAML("yaml"), TEMPLATE( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Configuration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Configuration.java index 05983db8d05..908220a5936 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Configuration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Configuration.java @@ -20,6 +20,7 @@ package org.apache.hadoop.yarn.services.resource; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -39,7 +40,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; @ApiModel(description = "Set of configuration properties that can be injected into the application components via envs, files and custom pluggable helper docker containers. Files of several standard formats like xml, properties, json, yaml and templates will be supported.") @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-02T08:15:05.615-07:00") @JsonInclude(JsonInclude.Include.NON_NULL) -public class Configuration { +public class Configuration implements Serializable { + private static final long serialVersionUID = -4330788704981074466L; private Map properties = new HashMap(); private Map env = new HashMap(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Container.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Container.java index 4e40102632e..a4efdf3c08f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Container.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Container.java @@ -73,19 +73,19 @@ public class Container extends BaseResource { * This will most likely be different from cluster launch time. **/ public Container launchTime(Date launchTime) { - this.launchTime = launchTime; + this.launchTime = launchTime == null ? null : (Date) launchTime.clone(); return this; } @ApiModelProperty(example = "null", value = "The time when the container was created, e.g. 2016-03-16T01:01:49.000Z. This will most likely be different from cluster launch time.") @JsonProperty("launch_time") public String getLaunchTime() { - return launchTime.toString(); + return launchTime == null ? null : launchTime.toString(); } @XmlElement(name = "launch_time") public void setLaunchTime(Date launchTime) { - this.launchTime = launchTime; + this.launchTime = launchTime == null ? null : (Date) launchTime.clone(); } /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/PlacementPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/PlacementPolicy.java index 7541e2f9749..5df00a00a9e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/PlacementPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/PlacementPolicy.java @@ -20,6 +20,7 @@ package org.apache.hadoop.yarn.services.resource; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import java.io.Serializable; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; @@ -31,7 +32,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; @ApiModel(description = "Placement policy of an instance of an application. This feature is in the works in YARN-4902.") @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-02T08:15:05.615-07:00") -public class PlacementPolicy { +public class PlacementPolicy implements Serializable { + private static final long serialVersionUID = 4341110649551172231L; private String label = null; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/ReadinessCheck.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/ReadinessCheck.java index 10c951a192f..f5497466168 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/ReadinessCheck.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/ReadinessCheck.java @@ -20,6 +20,7 @@ package org.apache.hadoop.yarn.services.resource; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import java.io.Serializable; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; @@ -34,7 +35,8 @@ import com.fasterxml.jackson.annotation.JsonValue; @ApiModel(description = "A custom command or a pluggable helper container to determine the readiness of a container of a component. Readiness for every application is different. Hence the need for a simple interface, with scope to support advanced usecases.") @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-02T08:15:05.615-07:00") -public class ReadinessCheck { +public class ReadinessCheck implements Serializable { + private static final long serialVersionUID = -3836839816887186801L; public enum TypeEnum { HTTP("http"); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Resource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Resource.java index a3780cc15c4..234ccb38978 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Resource.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/services/resource/Resource.java @@ -35,7 +35,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; @ApiModel(description = "Resource determines the amount of resources (vcores, memory, network, etc.) usable by a container. This field determines the resource to be applied for all the containers of a component or application. The resource specified at the app (or global) level can be overriden at the component level. Only one of profile OR cpu & memory are exepected. It raises a validation exception otherwise.") @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-02T08:15:05.615-07:00") -public class Resource extends BaseResource { +public class Resource extends BaseResource implements Cloneable { private static final long serialVersionUID = -6431667797380250037L; private String profile = null;