Repository: incubator-slider Updated Branches: refs/heads/feature/packaging_improvements f3cab4445 -> 5b1826e1b
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/Export.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/Export.java b/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/Export.java deleted file mode 100644 index 7331144..0000000 --- a/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/Export.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.providers.agent.application.metadata.json; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Represents package description. - */ -public class Export { - protected static final Logger - log = LoggerFactory.getLogger(Export.class); - - - private String name; - private String value; - - /** - * Creator. - */ - public Export() { - } - - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setValue(String value) { - this.value = value; - } - - public String getValue() { - return value; - } -} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/ExportGroup.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/ExportGroup.java b/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/ExportGroup.java deleted file mode 100644 index e95497d..0000000 --- a/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/ExportGroup.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.providers.agent.application.metadata.json; - -import org.codehaus.jackson.annotate.JsonProperty; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -/** - * Represents package description. - */ -public class ExportGroup { - protected static final Logger - log = LoggerFactory.getLogger(ExportGroup.class); - - - private String name; - private List<Export> exports = new ArrayList<Export>(); - - /** - * Creator. - */ - public ExportGroup() { - } - - @JsonProperty("exports") - public List<Export> getExports() { - return this.exports; - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/MetaInfo.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/MetaInfo.java b/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/MetaInfo.java deleted file mode 100644 index ff81fb9..0000000 --- a/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/MetaInfo.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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.providers.agent.application.metadata.json; - -import org.apache.slider.core.exceptions.BadConfigException; -import org.apache.slider.providers.agent.application.metadata.Metainfo; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.map.annotate.JsonSerialize; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Represents the metadata associated with the application. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) -public class MetaInfo { - protected static final Logger - log = LoggerFactory.getLogger(MetaInfo.class); - - private static final String UTF_8 = "UTF-8"; - - /** - * version - */ - private String schemaVersion = "2.1"; - - private Application application; - - - /** - * Creator. - */ - public MetaInfo() { - } - - public void setApplication(Application application) { - this.application = application; - } - - public Application getApplication() { - return application; - } - - public void setSchemaVersion(String version) { - schemaVersion = version; - } - - public String getSchemaVersion() { - return schemaVersion; - } - - public static MetaInfo upConverted(Metainfo fromVersion2dot0) throws BadConfigException { - if (fromVersion2dot0 == null) { - return null; - } - - MetaInfo metaInfo = new MetaInfo(); - - if (fromVersion2dot0.getApplication() != null) { - Application app = new Application(); - metaInfo.setApplication(app); - - app.setComment(fromVersion2dot0.getApplication().getComment()); - app.setExportedConfigs(fromVersion2dot0.getApplication().getExportedConfigs()); - app.setName(fromVersion2dot0.getApplication().getName()); - app.setVersion(fromVersion2dot0.getApplication().getVersion()); - - // command order - if (fromVersion2dot0.getApplication().getCommandOrder() != null) { - for (org.apache.slider.providers.agent.application.metadata.CommandOrder xmlCo : - fromVersion2dot0.getApplication().getCommandOrder()) { - CommandOrder co = new CommandOrder(); - co.setCommand(xmlCo.getCommand()); - co.setRequires(xmlCo.getRequires()); - app.getCommandOrders().add(co); - } - } - - // packages - if (fromVersion2dot0.getApplication().getOSSpecifics() != null) { - for (org.apache.slider.providers.agent.application.metadata.OSSpecific xmlOSS : - fromVersion2dot0.getApplication().getOSSpecifics()) { - for (org.apache.slider.providers.agent.application.metadata.OSPackage xmlOSP : xmlOSS.getPackages()) { - Package pkg = new Package(); - pkg.setName(xmlOSP.getName()); - pkg.setType(xmlOSP.getType()); - app.getPackages().add(pkg); - } - } - } - - // export - if (fromVersion2dot0.getApplication().getExportGroups() != null) { - for (org.apache.slider.providers.agent.application.metadata.ExportGroup xmlEg : - fromVersion2dot0.getApplication().getExportGroups()) { - ExportGroup eg = new ExportGroup(); - eg.setName(xmlEg.getName()); - app.getExportGroups().add(eg); - for (org.apache.slider.providers.agent.application.metadata.Export xmlEx : - xmlEg.getExports()) { - Export exp = new Export(); - exp.setName(xmlEx.getName()); - exp.setValue(xmlEx.getValue()); - eg.getExports().add(exp); - } - } - } - - // config file - if (fromVersion2dot0.getApplication().getConfigFiles() != null) { - for (org.apache.slider.providers.agent.application.metadata.ConfigFile xmlConf : - fromVersion2dot0.getApplication().getConfigFiles()) { - ConfigFile conf = new ConfigFile(); - conf.setDictionaryName(xmlConf.getDictionaryName()); - conf.setFileName(xmlConf.getFileName()); - conf.setType(xmlConf.getType()); - app.getConfigFiles().add(conf); - } - } - - // component - if (fromVersion2dot0.getApplication().getComponents() != null) { - for (org.apache.slider.providers.agent.application.metadata.Component xmlComp : - fromVersion2dot0.getApplication().getComponents()) { - Component comp = new Component(); - comp.setAppExports(xmlComp.getAppExports()); - comp.setAutoStartOnFailure(xmlComp.getRequiresAutoRestart()); - comp.setCategory(xmlComp.getCategory()); - comp.setCompExports(xmlComp.getCompExports()); - comp.setMaxInstanceCount(xmlComp.getMaxInstanceCountInt()); - comp.setMinInstanceCount(xmlComp.getMinInstanceCountInt()); - comp.setName(xmlComp.getName()); - comp.setPublishConfig(xmlComp.getPublishConfig()); - if(xmlComp.getCommandScript() != null) { - CommandScript commandScript = new CommandScript(); - commandScript.setScript(xmlComp.getCommandScript().getScript()); - commandScript.setScriptType(xmlComp.getCommandScript().getScriptType()); - commandScript.setTimeout(xmlComp.getCommandScript().getTimeout()); - comp.setCommandScript(commandScript); - } - app.getComponents().add(comp); - } - } - - } - return metaInfo; - } - - public Component getApplicationComponent(String roleName) { - if (application == null) { - log.error("Malformed app definition: Expect application as the top level element for metainfo"); - } else { - for (Component component : application.getComponents()) { - if (component.getName().equals(roleName)) { - return component; - } - } - } - return null; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/MetaInfoParser.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/MetaInfoParser.java b/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/MetaInfoParser.java deleted file mode 100644 index f821b82..0000000 --- a/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/MetaInfoParser.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.providers.agent.application.metadata.json; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; - -/** - * Represents the metadata associated with the application. - */ -public class MetaInfoParser { - protected static final Logger - log = LoggerFactory.getLogger(MetaInfoParser.class); - - private final GsonBuilder gsonBuilder = new GsonBuilder(); - private Gson gson; - - /** - * Creator. - */ - public MetaInfoParser() { - gson = gsonBuilder.create(); - } - - - /** - * Convert to a JSON string - * - * @return a JSON string description - * - * @throws IOException Problems mapping/writing the object - */ - public String toJsonString(MetaInfo metaInfo) throws IOException { - return gson.toJson(metaInfo); - } - - /** - * Convert from JSON - * - * @param json input - * - * @return the parsed JSON - * - * @throws IOException IO - */ - public MetaInfo fromJsonString(String json) - throws IOException { - return gson.fromJson(json, MetaInfo.class); - } - - /** - * Parse metainfo from an IOStream - * @param is - * @return - * @throws IOException - */ - public MetaInfo fromInputStream(InputStream is) throws IOException { - StringWriter writer = new StringWriter(); - IOUtils.copy(is, writer); - return fromJsonString(writer.toString()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/Package.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/Package.java b/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/Package.java deleted file mode 100644 index b9bddd6..0000000 --- a/slider-core/src/main/java/org/apache/slider/providers/agent/application/metadata/json/Package.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.providers.agent.application.metadata.json; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Represents package description. - */ -public class Package { - protected static final Logger - log = LoggerFactory.getLogger(Package.class); - - - private String name; - private String type; - - public Package() { - } - - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } -} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/Container.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/Container.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/Container.java deleted file mode 100644 index ef58920..0000000 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/Container.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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 org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -/** - * Represents a docker container - */ -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) -public class Container { - protected static final Logger - log = LoggerFactory.getLogger(Container.class); - - private String name; - private String image; - private String options; - private List<ContainerMount> mounts = new ArrayList<>(); - private List<ContainerPort> ports = new ArrayList<>(); - - - public Container() { - } - - @JsonProperty("mounts") - public List<ContainerMount> getMounts() { - return this.mounts; - } - - @JsonProperty("ports") - public List<ContainerPort> getPorts() { - return this.ports; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getImage() { - return image; - } - - public void setImage(String image) { - this.image = image; - } - - public String getOptions() { - return options; - } - - public void setOptions(String options) { - this.options = options; - } -} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ContainerMount.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ContainerMount.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ContainerMount.java deleted file mode 100644 index c2670c7..0000000 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ContainerMount.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.map.annotate.JsonSerialize; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Represents a docker container mount - */ -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) -public class ContainerMount { - protected static final Logger - log = LoggerFactory.getLogger(ContainerMount.class); - - - // TODO: Rename - private String containerMount; - private String hostMount; - - public ContainerMount() { - } - - public String getContainerMount() { - return containerMount; - } - - public void setContainerMount(String containerMount) { - this.containerMount = containerMount; - } - - public String getHostMount() { - return hostMount; - } - - public void setHostMount(String hostMount) { - this.hostMount = hostMount; - } -} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ContainerPort.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ContainerPort.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ContainerPort.java deleted file mode 100644 index a36194c..0000000 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ContainerPort.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.map.annotate.JsonSerialize; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Represents a docker container port - */ -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) -public class ContainerPort { - protected static final Logger - log = LoggerFactory.getLogger(ContainerPort.class); - - - private String containerPort; - private String hostPort; - - public ContainerPort() { - } - - public String getContainerPort() { - return containerPort; - } - - public void setContainerPort(String containerPort) { - this.containerPort = containerPort; - } - - public String getHostPort() { - return hostPort; - } - - public void setHostPort(String hostPort) { - this.hostPort = hostPort; - } -} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ExecutionCommand.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ExecutionCommand.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ExecutionCommand.java index 054bc46..9208707 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ExecutionCommand.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/agent/ExecutionCommand.java @@ -18,8 +18,11 @@ package org.apache.slider.server.appmaster.web.rest.agent; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.slider.providers.agent.application.metadata.json.Component; -import org.apache.slider.providers.agent.application.metadata.json.MetaInfo; +import org.apache.slider.providers.agent.application.metadata.Component; +import org.apache.slider.providers.agent.application.metadata.DockerContainer; +import org.apache.slider.providers.agent.application.metadata.DockerContainerMount; +import org.apache.slider.providers.agent.application.metadata.DockerContainerPort; +import org.apache.slider.providers.agent.application.metadata.Metainfo; import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.annotate.JsonProperty; import org.codehaus.jackson.map.annotate.JsonSerialize; @@ -54,14 +57,14 @@ public class ExecutionCommand { private String serviceName; private String componentName; private String componentType; - private List<Container> containers = new ArrayList<>(); + private List<DockerContainer> containers = new ArrayList<>(); public ExecutionCommand(AgentCommandType commandType) { this.commandType = commandType; } @JsonProperty("containers") - public List<Container> getContainers() { + public List<DockerContainer> getContainers() { return containers; } @@ -220,26 +223,26 @@ public class ExecutionCommand { return builder.toString(); } - public void addContainerDetails(String componentName, MetaInfo metaInfo) { + public void addContainerDetails(String componentName, Metainfo metaInfo) { Component component = metaInfo.getApplicationComponent(componentName); this.setComponentType(component.getType()); log.info("Adding container details for {}", componentName); - for(org.apache.slider.providers.agent.application.metadata.json.Container metaContainer: component.getContainers()) { - Container container = new Container(); + for(DockerContainer metaContainer: component.getDockerContainers()) { + DockerContainer container = new DockerContainer(); container.setImage(metaContainer.getImage()); container.setName(metaContainer.getName()); container.setOptions(metaContainer.getOptions()); if(metaContainer.getMounts().size() > 0) { - for(org.apache.slider.providers.agent.application.metadata.json.ContainerMount metaContMount : metaContainer.getMounts()) { - ContainerMount contMnt = new ContainerMount(); + for(DockerContainerMount metaContMount : metaContainer.getMounts()) { + DockerContainerMount contMnt = new DockerContainerMount(); contMnt.setContainerMount(metaContMount.getContainerMount()); contMnt.setHostMount(metaContMount.getHostMount()); container.getMounts().add(contMnt); } } if(metaContainer.getPorts().size() > 0) { - for(org.apache.slider.providers.agent.application.metadata.json.ContainerPort metaCntPort : metaContainer.getPorts()) { - ContainerPort cntPort = new ContainerPort(); + for(DockerContainerPort metaCntPort : metaContainer.getPorts()) { + DockerContainerPort cntPort = new DockerContainerPort(); cntPort.setContainerPort(metaCntPort.getContainerPort()); cntPort.setHostPort(metaCntPort.getHostPort()); container.getPorts().add(cntPort); http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy b/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy index c3f52e7..d96886a 100644 --- a/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy @@ -97,7 +97,7 @@ class TestWindowsSupport extends YarnMiniClusterTestBase { assumeWindows() SliderFileSystem sfs = new SliderFileSystem(new Configuration()) try { - def metainfo = AgentUtils.getApplicationMetaInfo(sfs, windowsFile) + def metainfo = AgentUtils.getApplicationMetainfo(sfs, windowsFile) } catch (FileNotFoundException fnfe) { // expected } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentClientProvider2.java ---------------------------------------------------------------------- diff --git a/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentClientProvider2.java b/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentClientProvider2.java index 466b300..92efafd 100644 --- a/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentClientProvider2.java +++ b/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentClientProvider2.java @@ -30,9 +30,9 @@ import org.apache.slider.core.conf.ConfTree; import org.apache.slider.core.exceptions.BadCommandArgumentsException; import org.apache.slider.core.exceptions.SliderException; import org.apache.slider.providers.ProviderUtils; -import org.apache.slider.providers.agent.application.metadata.json.Application; -import org.apache.slider.providers.agent.application.metadata.json.MetaInfo; -import org.apache.slider.providers.agent.application.metadata.json.Package; +import org.apache.slider.providers.agent.application.metadata.Application; +import org.apache.slider.providers.agent.application.metadata.Metainfo; +import org.apache.slider.providers.agent.application.metadata.Package; import org.codehaus.jettison.json.JSONObject; import org.junit.Assert; import org.junit.BeforeClass; @@ -120,7 +120,7 @@ public class TestAgentClientProvider2 { global.put("d", "{app_install_dir}/d"); inputConfig.put("global", global); - MetaInfo metainfo = new MetaInfo(); + Metainfo metainfo = new Metainfo(); Application app = new Application(); metainfo.setApplication(app); Package pkg = new Package(); http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentProviderService.java ---------------------------------------------------------------------- diff --git a/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentProviderService.java b/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentProviderService.java index 7746867..95b7d56 100644 --- a/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentProviderService.java +++ b/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentProviderService.java @@ -48,17 +48,16 @@ import org.apache.slider.core.registry.docstore.ExportEntry; import org.apache.slider.core.registry.docstore.PublishedExports; import org.apache.slider.core.registry.docstore.PublishedExportsSet; import org.apache.slider.providers.ProviderRole; -import org.apache.slider.providers.agent.application.metadata.json.Application; -import org.apache.slider.providers.agent.application.metadata.json.CommandOrder; -import org.apache.slider.providers.agent.application.metadata.json.CommandScript; -import org.apache.slider.providers.agent.application.metadata.json.Component; +import org.apache.slider.providers.agent.application.metadata.Application; +import org.apache.slider.providers.agent.application.metadata.CommandOrder; +import org.apache.slider.providers.agent.application.metadata.CommandScript; +import org.apache.slider.providers.agent.application.metadata.Component; import org.apache.slider.providers.agent.application.metadata.ComponentExport; -import org.apache.slider.providers.agent.application.metadata.json.ConfigFile; +import org.apache.slider.providers.agent.application.metadata.ConfigFile; import org.apache.slider.providers.agent.application.metadata.DefaultConfig; -import org.apache.slider.providers.agent.application.metadata.json.Export; -import org.apache.slider.providers.agent.application.metadata.json.ExportGroup; -import org.apache.slider.providers.agent.application.metadata.json.MetaInfo; -import org.apache.slider.providers.agent.application.metadata.json.MetaInfoParser; +import org.apache.slider.providers.agent.application.metadata.Export; +import org.apache.slider.providers.agent.application.metadata.ExportGroup; +import org.apache.slider.providers.agent.application.metadata.Metainfo; import org.apache.slider.providers.agent.application.metadata.MetainfoParser; import org.apache.slider.providers.agent.application.metadata.PropertyInfo; import org.apache.slider.server.appmaster.model.mock.MockRegistryOperations; @@ -304,8 +303,13 @@ public class TestAgentProviderService { CommandScript cs = new CommandScript(); cs.setScript("scripts/hbase_master.py"); doReturn(cs).when(mockAps).getScriptPathFromMetainfo(anyString()); - MetaInfo metainfo = new MetaInfo(); + Metainfo metainfo = new Metainfo(); metainfo.setApplication(new Application()); + + Component hm = new Component(); + hm.setName("HBASE_MASTER"); + metainfo.getApplication().addComponent(hm); + doReturn(metainfo).when(mockAps).getApplicationMetainfo(any(SliderFileSystem.class), anyString()); Configuration conf = new Configuration(); @@ -451,7 +455,7 @@ public class TestAgentProviderService { cs.setScript("scripts/hbase_master.py"); doReturn(cs).when(mockAps) .getScriptPathFromMetainfo(anyString()); - MetaInfo metainfo = new MetaInfo(); + Metainfo metainfo = new Metainfo(); Application application = new Application(); metainfo.setApplication(application); doReturn(metainfo).when(mockAps).getApplicationMetainfo( @@ -470,7 +474,7 @@ public class TestAgentProviderService { } doNothing().when(mockAps).processAllocatedPorts(anyString(), anyString(), - anyString(), anyMap()); + anyString(), anyMap()); expect(access.isApplicationLive()).andReturn(true).anyTimes(); ClusterDescription desc = new ClusterDescription(); desc.setOption(OptionKeys.ZOOKEEPER_QUORUM, "host1:2181"); @@ -496,14 +500,14 @@ public class TestAgentProviderService { ProviderRole providerRole = new ProviderRole(role, 1); providerRoleMap.put(1, providerRole); mockAps.rebuildContainerDetails(containers, "mockcontainer_1", - providerRoleMap); + providerRoleMap); return mockAps; } @Test public void testThreeInstallFailures() throws IOException, SliderException { InputStream metainfo_1 = new ByteArrayInputStream(metainfo_1_str.getBytes()); - MetaInfo metainfo = MetaInfo.upConverted(new MetainfoParser().parse(metainfo_1)); + Metainfo metainfo = new MetainfoParser().fromXmlStream(metainfo_1); ConfTree tree = new ConfTree(); tree.global.put(InternalKeys.INTERNAL_APPLICATION_IMAGE_PATH, "."); @@ -544,7 +548,7 @@ public class TestAgentProviderService { doReturn(access).when(mockAps).getAmState(); doReturn(metainfo).when(mockAps).getApplicationMetainfo(any(SliderFileSystem.class), anyString()); doReturn(new HashMap<String, DefaultConfig>()).when(mockAps). - initializeDefaultConfigs(any(SliderFileSystem.class), anyString(), any(MetaInfo.class)); + initializeDefaultConfigs(any(SliderFileSystem.class), anyString(), any(Metainfo.class)); try { @@ -631,14 +635,23 @@ public class TestAgentProviderService { } @Test - public void testAgentStateStarted() throws Exception, SliderException { + public void testAgentStateStarted() throws Exception { AggregateConf instanceDefinition = prepareConfForAgentStateTests(); AgentProviderService mockAps = prepareProviderServiceForAgentStateTests(); + + Metainfo metainfo = new Metainfo(); + Application application = new Application(); + Component hbaseMaster = new Component(); + hbaseMaster.setName("HBASE_MASTER"); + application.addComponent(hbaseMaster); + metainfo.setApplication(application); + doReturn(metainfo).when(mockAps).getMetaInfo(); + Register reg = new Register(); reg.setResponseId(0); reg.setLabel("mockcontainer_1___HBASE_MASTER"); Map<String,String> ports = new HashMap<String,String>(); - ports.put("a","100"); + ports.put("a", "100"); reg.setAllocatedPorts(ports); // Simulating agent in STARTED state @@ -688,12 +701,15 @@ public class TestAgentProviderService { AggregateConf instanceDefinition = prepareConfForAgentStateTests(); AgentProviderService mockAps = prepareProviderServiceForAgentStateTests(); - MetaInfo metainfo = new MetaInfo(); + Metainfo metainfo = new Metainfo(); Application application = new Application(); CommandOrder cmdOrder = new CommandOrder(); cmdOrder.setCommand("HBASE_MASTER-START"); cmdOrder.setRequires("HBASE_MASTER-INSTALLED"); application.getCommandOrders().add(cmdOrder); + Component hbaseMaster = new Component(); + hbaseMaster.setName("HBASE_MASTER"); + application.addComponent(hbaseMaster); metainfo.setApplication(application); doReturn(metainfo).when(mockAps).getApplicationMetainfo( any(SliderFileSystem.class), anyString()); @@ -808,11 +824,49 @@ public class TestAgentProviderService { aps.close(); } + @Test + public void testComponentSpecificPublishes() throws Exception { + InputStream metainfo_1 = new ByteArrayInputStream(metainfo_1_str.getBytes()); + Metainfo metainfo = new MetainfoParser().fromXmlStream(metainfo_1); + AgentProviderService aps = createAgentProviderService(new Configuration()); + AgentProviderService mockAps = Mockito.spy(aps); + doNothing().when(mockAps).publishApplicationInstanceData(anyString(), anyString(), anyCollection()); + doReturn(metainfo).when(mockAps).getMetaInfo(); + + Map<String, String> ports = new HashMap<String, String>(); + ports.put("global.listen_port", "10010"); + mockAps.processAndPublishComponentSpecificData(ports, + "cid1", + "host1", + "HBASE_REGIONSERVER"); + ArgumentCaptor<Collection> entriesCaptor = ArgumentCaptor. + forClass(Collection.class); + ArgumentCaptor<String> publishNameCaptor = ArgumentCaptor. + forClass(String.class); + Mockito.verify(mockAps, Mockito.times(1)).publishApplicationInstanceData( + anyString(), + publishNameCaptor.capture(), + entriesCaptor.capture()); + assert entriesCaptor.getAllValues().size() == 1; + for (Collection coll : entriesCaptor.getAllValues()) { + Set<Map.Entry<String, String>> entrySet = (Set<Map.Entry<String, String>>) coll; + for (Map.Entry entry : entrySet) { + log.info("{}:{}", entry.getKey(), entry.getValue().toString()); + if (entry.getKey().equals("PropertyA")) { + assert entry.getValue().toString().equals("host1:10010"); + } + } + } + assert publishNameCaptor.getAllValues().size() == 1; + for (String coll : publishNameCaptor.getAllValues()) { + assert coll.equals("ComponentInstanceData"); + } + } @Test public void testComponentSpecificPublishes2() throws Exception { InputStream metainfo_1 = new ByteArrayInputStream(metainfo_1_str.getBytes()); - MetaInfo metainfo = MetaInfo.upConverted(new MetainfoParser().parse(metainfo_1)); + Metainfo metainfo = new MetainfoParser().fromXmlStream(metainfo_1); AgentProviderService aps = createAgentProviderService(new Configuration()); AgentProviderService mockAps = Mockito.spy(aps); doNothing().when(mockAps).publishApplicationInstanceData(anyString(), anyString(), anyCollection()); @@ -897,7 +951,7 @@ public class TestAgentProviderService { @Test public void testProcessConfig() throws Exception { InputStream metainfo_1 = new ByteArrayInputStream(metainfo_1_str.getBytes()); - MetaInfo metainfo = MetaInfo.upConverted(new MetainfoParser().parse(metainfo_1)); + Metainfo metainfo = new MetainfoParser().fromXmlStream(metainfo_1); Assert.assertNotNull(metainfo.getApplication()); AgentProviderService aps = createAgentProviderService(new Configuration()); HeartBeat hb = new HeartBeat(); @@ -982,7 +1036,7 @@ public class TestAgentProviderService { @Test public void testMetaInfoParsing() throws Exception { InputStream metainfo_1 = new ByteArrayInputStream(metainfo_1_str.getBytes()); - MetaInfo metainfo = MetaInfo.upConverted(new MetainfoParser().parse(metainfo_1)); + Metainfo metainfo = new MetainfoParser().fromXmlStream(metainfo_1); Assert.assertNotNull(metainfo.getApplication()); Application application = metainfo.getApplication(); log.info("Service: " + application.toString()); @@ -993,10 +1047,10 @@ public class TestAgentProviderService { int found = 0; for (Component component : components) { if (component.getName().equals("HBASE_MASTER")) { - Assert.assertEquals(component.getAutoStartOnFailure(), Boolean.TRUE); - Assert.assertEquals(component.getAutoStartOnFailure(), Boolean.TRUE); - Assert.assertEquals(component.getMinInstanceCount(), 1); - Assert.assertEquals(component.getMaxInstanceCount(), 2); + Assert.assertEquals("true", component.getAutoStartOnFailure()); + Assert.assertEquals(Boolean.TRUE, component.getAutoStartOnFailureBoolean()); + Assert.assertEquals(component.getMinInstanceCountInt(), 1); + Assert.assertEquals(component.getMaxInstanceCountInt(), 2); Assert.assertEquals(component.getCommandScript().getScript(), "scripts/hbase_master.py"); Assert.assertEquals(component.getCategory(), "MASTER"); Assert.assertEquals(component.getAppExports(), "QuickLinks-JMX_Endpoint,QuickLinks-Master_Status"); @@ -1004,8 +1058,8 @@ public class TestAgentProviderService { found++; } if (component.getName().equals("HBASE_REGIONSERVER")) { - Assert.assertEquals(component.getAutoStartOnFailure(), "Falsee"); - Assert.assertEquals(component.getAutoStartOnFailure(), Boolean.FALSE); + Assert.assertEquals("Falsee", component.getAutoStartOnFailure()); + Assert.assertEquals(Boolean.FALSE, component.getAutoStartOnFailureBoolean()); Assert.assertEquals(component.getMinInstanceCount(), "1"); Assert.assertNull(component.getMaxInstanceCount()); Assert.assertEquals(component.getCommandScript().getScript(), "scripts/hbase_regionserver.py"); @@ -1084,16 +1138,16 @@ public class TestAgentProviderService { + " </comment>\n"; metainfo_1 = new ByteArrayInputStream(metainfo_1_str_bad.getBytes()); - metainfo = MetaInfo.upConverted(new MetainfoParser().parse(metainfo_1)); + metainfo = new MetainfoParser().fromXmlStream(metainfo_1); Assert.assertNull(metainfo); } @Test public void testMetaInfoRelatedOperations() throws Exception { InputStream metainfo_1 = new ByteArrayInputStream(metainfo_1_str.getBytes()); - MetaInfo metainfo = MetaInfo.upConverted(new MetainfoParser().parse(metainfo_1)); + Metainfo metainfo = new MetainfoParser().fromXmlStream(metainfo_1); InputStream metainfo_2 = new ByteArrayInputStream(metainfo_2_str.getBytes()); - MetaInfo metainfo2 = MetaInfo.upConverted(new MetainfoParser().parse(metainfo_2)); + Metainfo metainfo2 = new MetainfoParser().fromXmlStream(metainfo_2); String role_hm = "HBASE_MASTER"; String role_hrs = "HBASE_REGIONSERVER"; @@ -1122,7 +1176,7 @@ public class TestAgentProviderService { // App has two components HBASE_MASTER and HBASE_REGIONSERVER // Start of HBASE_RS depends on the start of HBASE_MASTER InputStream metainfo_1 = new ByteArrayInputStream(metainfo_1_str.getBytes()); - MetaInfo metainfo = MetaInfo.upConverted(new MetainfoParser().parse(metainfo_1)); + Metainfo metainfo = new MetainfoParser().fromXmlStream(metainfo_1); ConfTree tree = new ConfTree(); tree.global.put(InternalKeys.INTERNAL_APPLICATION_IMAGE_PATH, "."); @@ -1165,7 +1219,7 @@ public class TestAgentProviderService { doReturn(access).when(mockAps).getAmState(); doReturn(metainfo).when(mockAps).getApplicationMetainfo(any(SliderFileSystem.class), anyString()); doReturn(new HashMap<String, DefaultConfig>()).when(mockAps). - initializeDefaultConfigs(any(SliderFileSystem.class), anyString(), any(MetaInfo.class)); + initializeDefaultConfigs(any(SliderFileSystem.class), anyString(), any(Metainfo.class)); try { @@ -1495,7 +1549,7 @@ public class TestAgentProviderService { @Test public void testAddInstallCommand() throws Exception { InputStream metainfo_1 = new ByteArrayInputStream(metainfo_1_str.getBytes()); - MetaInfo metainfo = MetaInfo.upConverted(new MetainfoParser().parse(metainfo_1)); + Metainfo metainfo = new MetainfoParser().fromXmlStream(metainfo_1); AgentProviderService aps = createAgentProviderService(new Configuration()); HeartBeatResponse hbr = new HeartBeatResponse(); http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/test/java/org/apache/slider/providers/agent/TestComponentCommandOrder.java ---------------------------------------------------------------------- diff --git a/slider-core/src/test/java/org/apache/slider/providers/agent/TestComponentCommandOrder.java b/slider-core/src/test/java/org/apache/slider/providers/agent/TestComponentCommandOrder.java index bac1158..c123fbb 100644 --- a/slider-core/src/test/java/org/apache/slider/providers/agent/TestComponentCommandOrder.java +++ b/slider-core/src/test/java/org/apache/slider/providers/agent/TestComponentCommandOrder.java @@ -18,7 +18,7 @@ package org.apache.slider.providers.agent; -import org.apache.slider.providers.agent.application.metadata.json.CommandOrder; +import org.apache.slider.providers.agent.application.metadata.CommandOrder; import org.apache.slider.server.appmaster.model.mock.MockContainerId; import org.junit.Assert; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/test/java/org/apache/slider/providers/agent/application/metadata/TestMetainfoParser.java ---------------------------------------------------------------------- diff --git a/slider-core/src/test/java/org/apache/slider/providers/agent/application/metadata/TestMetainfoParser.java b/slider-core/src/test/java/org/apache/slider/providers/agent/application/metadata/TestMetainfoParser.java index 1177e9d..7930c8b 100644 --- a/slider-core/src/test/java/org/apache/slider/providers/agent/application/metadata/TestMetainfoParser.java +++ b/slider-core/src/test/java/org/apache/slider/providers/agent/application/metadata/TestMetainfoParser.java @@ -45,7 +45,7 @@ public class TestMetainfoParser { InputStream resStream = this.getClass().getResourceAsStream( METAINFO_XML); MetainfoParser parser = new MetainfoParser(); - Metainfo metainfo = parser.parse(resStream); + Metainfo metainfo = parser.fromXmlStream(resStream); Assert.assertNotNull(metainfo); Assert.assertNotNull(metainfo.getApplication()); Application application = metainfo.getApplication(); @@ -67,4 +67,106 @@ public class TestMetainfoParser { assert found; Assert.assertEquals(0, application.getConfigFiles().size()); } + + @Test + public void testJsonParse() throws IOException { + String metaInfo1_json = "{\n" + + "\"schemaVersion\":\"2.2\",\n" + + "\"application\":{\n" + + "\"name\": \"MEMCACHED\"," + + "\"exportGroups\": [" + + "{" + + "\"name\": \"Servers\"," + + "\"exports\": [" + + "{" + + "\"name\": \"host_port\"," + + "\"value\": \"${MEMCACHED_HOST}:${site.global.port}\"" + + "}" + + "]" + + "}" + + "]," + + "\"components\": [" + + "{" + + "\"name\": \"MEMCACHED\"," + + "\"compExports\": \"Servers-host_port\"," + + "\"commands\": [" + + "{" + + "\"exec\": \"java -classpath /usr/myapps/memcached/*:/usr/lib/hadoop/lib/* com.thimbleware.jmemcached.Main\"" + + "}" + + "]" + + "}," + + "{" + + "\"name\": \"MEMCACHED2\"," + + "\"commands\": [" + + "{" + + "\"exec\": \"scripts/config.py\"," + + "\"type\": \"PYTHON\"," + + "\"name\": \"CONFIGURE\"" + + "}" + + "]," + + "\"dockerContainers\": [" + + "{" + + "\"name\": \"redis\"," + + "\"image\": \"dockerhub/redis\"," + + "\"options\": \"-net=bridge\"," + + "\"mounts\": [" + + "{" + + "\"containerMount\": \"/tmp/conf\"," + + "\"hostMount\": \"{$conf:@//site/global/app_root}/conf\"" + + "}" + + "]" + + "}" + + "]" + + "}" + + "]" + + "}" + + "}"; + + MetainfoParser parser = new MetainfoParser(); + Metainfo mInfo = parser.fromJsonString(metaInfo1_json); + Assert.assertEquals("2.2", mInfo.getSchemaVersion()); + + Application app = mInfo.getApplication(); + Assert.assertNotNull(app); + + Assert.assertEquals("MEMCACHED", app.getName()); + List<ExportGroup> egs = app.getExportGroups(); + Assert.assertEquals(1, egs.size()); + ExportGroup eg = egs.get(0); + Assert.assertEquals("Servers", eg.getName()); + List<Export> exports = eg.getExports(); + Assert.assertEquals(1, exports.size()); + Export export = exports.get(0); + Assert.assertEquals("host_port", export.getName()); + Assert.assertEquals("${MEMCACHED_HOST}:${site.global.port}", export.getValue()); + + List<Component> components = app.getComponents(); + Assert.assertEquals(2, components.size()); + + Component c1 = mInfo.getApplicationComponent("MEMCACHED"); + Assert.assertNotNull(c1); + Assert.assertEquals("MEMCACHED", c1.getName()); + Assert.assertEquals("Servers-host_port", c1.getCompExports()); + Assert.assertEquals(1, c1.getCommands().size()); + ComponentCommand cmd = c1.getCommands().get(0); + Assert.assertEquals("START", cmd.getName()); + Assert.assertEquals("SHELL", cmd.getType()); + Assert.assertEquals("java -classpath /usr/myapps/memcached/*:/usr/lib/hadoop/lib/* com.thimbleware.jmemcached.Main", + cmd.getExec()); + + Component c2 = mInfo.getApplicationComponent("MEMCACHED2"); + Assert.assertNotNull(c2); + Assert.assertEquals("MEMCACHED2", c2.getName()); + Assert.assertEquals(1, c2.getCommands().size()); + cmd = c2.getCommands().get(0); + Assert.assertEquals("CONFIGURE", cmd.getName()); + Assert.assertEquals("PYTHON", cmd.getType()); + Assert.assertEquals("scripts/config.py", cmd.getExec()); + Assert.assertEquals(1, c2.getDockerContainers().size()); + DockerContainer cont = c2.getDockerContainers().get(0); + Assert.assertEquals("redis", cont.getName()); + Assert.assertEquals(1, cont.getMounts().size()); + DockerContainerMount mount = cont.getMounts().get(0); + Assert.assertEquals("{$conf:@//site/global/app_root}/conf", mount.getHostMount()); + } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5b1826e1/slider-core/src/test/java/org/apache/slider/providers/agent/application/metadata/json/TestMetaInfoParser.java ---------------------------------------------------------------------- diff --git a/slider-core/src/test/java/org/apache/slider/providers/agent/application/metadata/json/TestMetaInfoParser.java b/slider-core/src/test/java/org/apache/slider/providers/agent/application/metadata/json/TestMetaInfoParser.java deleted file mode 100644 index 83a87a4..0000000 --- a/slider-core/src/test/java/org/apache/slider/providers/agent/application/metadata/json/TestMetaInfoParser.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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.providers.agent.application.metadata.json; - -import org.junit.Assert; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.List; - -/** - * - */ -public class TestMetaInfoParser { - protected static final Logger log = - LoggerFactory.getLogger(TestMetaInfoParser.class); - - @Test - public void testParse() throws IOException { - String metaInfo1_json = "{\n" - + "\"schemaVersion\":\"2.2\",\n" - + "\"application\":{\n" - + "\"name\": \"MEMCACHED\"," - + "\"exportGroups\": [" - + "{" - + "\"name\": \"Servers\"," - + "\"exports\": [" - + "{" - + "\"name\": \"host_port\"," - + "\"value\": \"${MEMCACHED_HOST}:${site.global.port}\"" - + "}" - + "]" - + "}" - + "]," - + "\"components\": [" - + "{" - + "\"name\": \"MEMCACHED\"," - + "\"compExports\": \"Servers-host_port\"," - + "\"commands\": [" - + "{" - + "\"exec\": \"java -classpath /usr/myapps/memcached/*:/usr/lib/hadoop/lib/* com.thimbleware.jmemcached.Main\"" - + "}" - + "]" - + "}," - + "{" - + "\"name\": \"MEMCACHED2\"," - + "\"commands\": [" - + "{" - + "\"exec\": \"scripts/config.py\"," - + "\"type\": \"PYTHON\"," - + "\"name\": \"CONFIGURE\"" - + "}" - + "]," - + "\"containers\": [" - + "{" - + "\"name\": \"redis\"," - + "\"image\": \"dockerhub/redis\"," - + "\"options\": \"-net=bridge\"," - + "\"mounts\": [" - + "{" - + "\"containerMount\": \"/tmp/conf\"," - + "\"hostMount\": \"{$conf:@//site/global/app_root}/conf\"" - + "}" - + "]" - + "}" - + "]" - + "}" - + "]" - + "}" - + "}"; - - MetaInfoParser parser = new MetaInfoParser(); - MetaInfo mInfo = parser.fromJsonString(metaInfo1_json); - Assert.assertEquals("2.2", mInfo.getSchemaVersion()); - - Application app = mInfo.getApplication(); - Assert.assertNotNull(app); - - Assert.assertEquals("MEMCACHED", app.getName()); - List<ExportGroup> egs = app.getExportGroups(); - Assert.assertEquals(1, egs.size()); - ExportGroup eg = egs.get(0); - Assert.assertEquals("Servers", eg.getName()); - List<Export> exports = eg.getExports(); - Assert.assertEquals(1, exports.size()); - Export export = exports.get(0); - Assert.assertEquals("host_port", export.getName()); - Assert.assertEquals("${MEMCACHED_HOST}:${site.global.port}", export.getValue()); - - List<Component> components = app.getComponents(); - Assert.assertEquals(2, components.size()); - - Component c1 = app.getApplicationComponent("MEMCACHED"); - Assert.assertNotNull(c1); - Assert.assertEquals("MEMCACHED", c1.getName()); - Assert.assertEquals("Servers-host_port", c1.getCompExports()); - Assert.assertEquals(1, c1.getCommands().size()); - ComponentCommand cmd = c1.getCommands().get(0); - Assert.assertEquals("START", cmd.getName()); - Assert.assertEquals("SHELL", cmd.getType()); - Assert.assertEquals("java -classpath /usr/myapps/memcached/*:/usr/lib/hadoop/lib/* com.thimbleware.jmemcached.Main", cmd.getExec()); - - Component c2 = app.getApplicationComponent("MEMCACHED2"); - Assert.assertNotNull(c2); - Assert.assertEquals("MEMCACHED2", c2.getName()); - Assert.assertEquals(1, c2.getCommands().size()); - cmd = c2.getCommands().get(0); - Assert.assertEquals("CONFIGURE", cmd.getName()); - Assert.assertEquals("PYTHON", cmd.getType()); - Assert.assertEquals("scripts/config.py", cmd.getExec()); - Assert.assertEquals(1, c2.getContainers().size()); - Container cont = c2.getContainers().get(0); - Assert.assertEquals("redis", cont.getName()); - Assert.assertEquals(1, cont.getMounts().size()); - ContainerMount mount = cont.getMounts().get(0); - Assert.assertEquals("{$conf:@//site/global/app_root}/conf", mount.getHostMount()); - } -}
