From 891c4a1b3a6942b1f643e3119d0669d7e03553d2 Mon Sep 17 00:00:00 2001 From: Alexey Khivin Date: Wed, 5 Oct 2016 21:36:08 +0300 Subject: [PATCH] [DeploymentManager] Multi-env configuration support User can put several configurations for different types of Murano-environment. Object model for each environment placed to a separate file. Change-Id: Ibf011caa7d9dd36857391acd05ce3bfc4fd5582c --- .../muranoci/deploy/MuranoDeployment.java | 6 +- .../deploy/MuranoManagerBuildWrapper.java | 18 ++-- .../deploy/MuranoManagerDeployer.java | 3 +- .../deploy/RepositoryTemplatedDeployment.java | 101 ------------------ .../deploy/model/EnvironmentDescription.java | 20 ++++ .../muranoci/deploy/model/MuranoYaml.java | 28 +++++ .../deploy/repository/MuranoCiConfig.java | 56 ++++++++++ .../RepositoryTemplatedDeployment.java | 78 ++++++++++++++ .../TemplatedDeployment/help-objectModel.html | 5 + .../deploy/credentials/Messages.properties | 1 + .../OpenstackCredentialsImpl/config.jelly | 31 ++++++ .../help-identityEndpoint.html | 8 ++ .../config.jelly | 0 .../help-environment.html | 5 + 14 files changed, 243 insertions(+), 117 deletions(-) delete mode 100644 deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/RepositoryTemplatedDeployment.java create mode 100644 deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/model/EnvironmentDescription.java create mode 100644 deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/model/MuranoYaml.java create mode 100644 deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/MuranoCiConfig.java create mode 100644 deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment.java create mode 100644 deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/TemplatedDeployment/help-objectModel.html create mode 100644 deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/Messages.properties create mode 100644 deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl/config.jelly create mode 100644 deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl/help-identityEndpoint.html rename deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/{ => repository}/RepositoryTemplatedDeployment/config.jelly (100%) create mode 100644 deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment/help-environment.html diff --git a/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoDeployment.java b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoDeployment.java index 2182796..1370e6a 100644 --- a/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoDeployment.java +++ b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoDeployment.java @@ -29,7 +29,8 @@ public abstract class MuranoDeployment * * @param objectModel description of environment to be deployed */ - public MuranoDeployment(String objectModel) { + public MuranoDeployment( + String objectModel) { this.objectModel = requireNonNull(objectModel, "Object Model should not be Null"); } @@ -44,7 +45,8 @@ public abstract class MuranoDeployment return Jenkins.getInstance().getDescriptorList(MuranoDeployment.class); } - public static List getCompatibleDeployments(Descriptor descriptor) { + public static List getCompatibleDeployments( + Descriptor descriptor) { LinkedList cloudDeployments = new LinkedList<>(); diff --git a/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerBuildWrapper.java b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerBuildWrapper.java index ff625cf..18c7625 100644 --- a/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerBuildWrapper.java +++ b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerBuildWrapper.java @@ -5,13 +5,8 @@ import com.cloudbees.plugins.credentials.CredentialsProvider; import com.cloudbees.plugins.credentials.common.StandardCredentials; import com.cloudbees.plugins.credentials.common.StandardListBoxModel; import com.cloudbees.plugins.credentials.domains.DomainRequirement; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLParser; import hudson.EnvVars; import hudson.Extension; -import hudson.FilePath; import hudson.Launcher; import hudson.model.*; import hudson.security.ACL; @@ -19,19 +14,17 @@ import hudson.tasks.BuildWrapper; import hudson.tasks.BuildWrapperDescriptor; import hudson.util.ListBoxModel; import jenkins.model.Jenkins; -import org.apache.http.impl.client.SystemDefaultCredentialsProvider; import org.kohsuke.stapler.AncestorInPath; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.export.Exported; import org.openstack.murano.jenkins_plugins.muranoci.deploy.credentials.OpenstackCredentials; +import org.openstack.murano.jenkins_plugins.muranoci.deploy.repository.RepositoryTemplatedDeployment; import java.io.IOException; import java.io.Serializable; import java.math.BigInteger; -import java.net.URL; import java.security.SecureRandom; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -74,7 +67,7 @@ public class MuranoManagerBuildWrapper extends BuildWrapper implements Serializa credentials.getPassword().getPlainText(), credentials.getTenant() ); - if (env.containsKey("BUILD_ENVIRONMENT_TIMEOUT")) { + if (env.containsKey("BUILD_ENVIRONMENT_TIMEOUT")){ int timeout = Integer.parseInt(env.get("BUILD_ENVIRONMENT_TIMEOUT")); helper.setTimeout(timeout); } @@ -82,7 +75,8 @@ public class MuranoManagerBuildWrapper extends BuildWrapper implements Serializa //TODO: Remove try { ((RepositoryTemplatedDeployment) deployment).readObjectModel(build.getWorkspace()); - } catch (Exception io) { + } catch (Exception io){ + io.printStackTrace(); } String name = generateEnvName(); @@ -91,7 +85,7 @@ public class MuranoManagerBuildWrapper extends BuildWrapper implements Serializa name, deployment.getObjectModel()); boolean result = helper.waitDeploymentResult(envId); - if (!result) { + if (!result){ build.setResult(Result.FAILURE); } } catch (Exception e) { @@ -122,7 +116,7 @@ public class MuranoManagerBuildWrapper extends BuildWrapper implements Serializa return openstackCredentials; } - + @Exported public MuranoDeployment getDeployment() { return deployment; diff --git a/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerDeployer.java b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerDeployer.java index 2ba9ec4..496ec27 100644 --- a/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerDeployer.java +++ b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerDeployer.java @@ -1,6 +1,5 @@ package org.openstack.murano.jenkins_plugins.muranoci.deploy; -import hudson.EnvVars; import hudson.Extension; import hudson.Launcher; import hudson.model.AbstractBuild; @@ -55,7 +54,7 @@ public class MuranoManagerDeployer extends Recorder { } - @Extension + @Extension(ordinal = -1.0) public static class DescriptorImpl extends BuildStepDescriptor { /** * {@inheritDoc} diff --git a/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/RepositoryTemplatedDeployment.java b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/RepositoryTemplatedDeployment.java deleted file mode 100644 index 7111111..0000000 --- a/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/RepositoryTemplatedDeployment.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.openstack.murano.jenkins_plugins.muranoci.deploy; - -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLParser; -import hudson.Extension; -import hudson.FilePath; -import hudson.model.Descriptor; -import org.kohsuke.stapler.DataBoundConstructor; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class RepositoryTemplatedDeployment extends MuranoDeployment { - /** - * The file in the repository that contains muranoci configuration. - */ - public static final String CI_CONFG_FILENAME = ".murano.yml"; - - /** - * - */ - private final String environment; - - /** - * The specific Implemenation of MuranoDeployment that - * gets object model from the file within the repo. - * - * @param environment The name of the environment within the .murano.yml config - */ - @DataBoundConstructor - public RepositoryTemplatedDeployment( - String environment) { - - this.environment = environment; - } - - public String getEnvironment() { - return environment; - } - - /** - * Denotes that this is a cloud deployment plugin. - */ - @Extension - public static class DescriptorImpl extends AbstractMuranoDeploymentDescriptor { - public DescriptorImpl() { - this(RepositoryTemplatedDeployment.class); - } - - public DescriptorImpl(Class clazz) { - super(clazz); - } - - /** - * {@inheritDoc} - */ - @Override - public String getDisplayName() { - return Messages.RepositoryTemplatedMuranoDeployment_DisplayName(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isApplicable(Descriptor descriptor) { - return true; - } - } - - - public void readObjectModel(FilePath workspace) throws IOException { - String config = null; - try { - config = new FilePath(workspace, ".murano.yml").readToString(); - } catch (IOException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - YAMLFactory factory = new YAMLFactory(); - ObjectMapper mapper = new ObjectMapper(factory); - HashMap map = mapper.readValue(config, HashMap.class); - Object model = ((Map)((Map)map).get("environments")).get(this.environment); - - JsonFactory jsonFactory = new JsonFactory(); - ObjectMapper mapperModel = new ObjectMapper(jsonFactory); - String string = mapperModel.writeValueAsString(model); - System.out.println(string); - this.setObjectModel(string); - } -} diff --git a/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/model/EnvironmentDescription.java b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/model/EnvironmentDescription.java new file mode 100644 index 0000000..2dfc21b --- /dev/null +++ b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/model/EnvironmentDescription.java @@ -0,0 +1,20 @@ +package org.openstack.murano.jenkins_plugins.muranoci.deploy.model; + +public class EnvironmentDescription { + private String modelFile = null; + + public EnvironmentDescription() { + } + + public EnvironmentDescription(String modelPath) { + this.modelFile = modelPath; + } + + public String getModelFile() { + return modelFile; + } + + public void setModelFile(String modelFile) { + this.modelFile = modelFile; + } +} diff --git a/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/model/MuranoYaml.java b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/model/MuranoYaml.java new file mode 100644 index 0000000..3682303 --- /dev/null +++ b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/model/MuranoYaml.java @@ -0,0 +1,28 @@ +package org.openstack.murano.jenkins_plugins.muranoci.deploy.model; + + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.HashMap; +import java.util.Map; + +public class MuranoYaml { + + @JsonProperty + private Map environments = null; + + public MuranoYaml() { + } + + public MuranoYaml(Map environments) { + this.environments = environments; + } + + public Map getEnvironments() { + return environments; + } + + public void setEnvironments(HashMap environments) { + this.environments = environments; + } +} diff --git a/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/MuranoCiConfig.java b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/MuranoCiConfig.java new file mode 100644 index 0000000..6ac3ee8 --- /dev/null +++ b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/MuranoCiConfig.java @@ -0,0 +1,56 @@ +package org.openstack.murano.jenkins_plugins.muranoci.deploy.repository; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import hudson.FilePath; +import org.openstack.murano.jenkins_plugins.muranoci.deploy.model.MuranoYaml; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by kh on 10/3/16. + */ +public class MuranoCiConfig { + /** + * The file in the repository that contains muranoci configuration. + */ + public static final String CI_CONFG_FILENAME = ".murano.yml"; + + private final MuranoYaml data; + + public MuranoCiConfig(MuranoYaml data) { + this.data = data; + } + + public MuranoYaml getData() { + return data; + } + + public static MuranoCiConfig read(FilePath workspace) throws IOException { + String configYaml = null; + try { + configYaml = new FilePath(workspace, CI_CONFG_FILENAME).readToString(); + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + final YAMLFactory factory = new YAMLFactory(); + ObjectMapper mapper = new ObjectMapper(factory); + MuranoYaml data = mapper.readValue(configYaml, MuranoYaml.class); + + return new MuranoCiConfig(data); + } +} diff --git a/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment.java b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment.java new file mode 100644 index 0000000..ec151ab --- /dev/null +++ b/deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment.java @@ -0,0 +1,78 @@ +package org.openstack.murano.jenkins_plugins.muranoci.deploy.repository; + +import hudson.Extension; +import hudson.FilePath; +import hudson.model.Descriptor; +import org.kohsuke.stapler.DataBoundConstructor; +import org.openstack.murano.jenkins_plugins.muranoci.deploy.AbstractMuranoDeploymentDescriptor; +import org.openstack.murano.jenkins_plugins.muranoci.deploy.Messages; +import org.openstack.murano.jenkins_plugins.muranoci.deploy.MuranoDeployment; +import org.openstack.murano.jenkins_plugins.muranoci.deploy.model.EnvironmentDescription; + +import java.io.IOException; + +public class RepositoryTemplatedDeployment extends MuranoDeployment { + + /** + * + */ + private final String environment; + + /** + * The specific Implemenation of MuranoDeployment that + * gets object model from the file within the repo. + * + * @param environment The name of the environment within the .murano.yml config + */ + @DataBoundConstructor + public RepositoryTemplatedDeployment(String environment) { + + this.environment = environment; + } + + public String getEnvironment() { + return environment; + } + + /** + * Denotes that this is a cloud deployment plugin. + */ + @Extension + public static class DescriptorImpl extends AbstractMuranoDeploymentDescriptor { + public DescriptorImpl() { + this(RepositoryTemplatedDeployment.class); + } + + public DescriptorImpl(Class clazz) { + super(clazz); + } + + /** + * {@inheritDoc} + */ + @Override + public String getDisplayName() { + return Messages.RepositoryTemplatedMuranoDeployment_DisplayName(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isApplicable(Descriptor descriptor) { + return true; + } + } + + + public void readObjectModel(FilePath workspace) throws IOException, InterruptedException { + MuranoCiConfig config = MuranoCiConfig.read(workspace); + + EnvironmentDescription description = config.getData().getEnvironments().get(this.environment); + + String modelPath = description.getModelFile(); + String objectModel = new FilePath(workspace, modelPath).readToString(); + + this.setObjectModel( objectModel); + } +} diff --git a/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/TemplatedDeployment/help-objectModel.html b/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/TemplatedDeployment/help-objectModel.html new file mode 100644 index 0000000..692b53c --- /dev/null +++ b/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/TemplatedDeployment/help-objectModel.html @@ -0,0 +1,5 @@ +
+

+ Object Model for your environment +

+
\ No newline at end of file diff --git a/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/Messages.properties b/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/Messages.properties new file mode 100644 index 0000000..5a63f1b --- /dev/null +++ b/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/Messages.properties @@ -0,0 +1 @@ +CertificateCredentialsImpl.DisplayName=Openstack Cloud \ No newline at end of file diff --git a/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl/config.jelly b/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl/config.jelly new file mode 100644 index 0000000..70e4921 --- /dev/null +++ b/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl/config.jelly @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl/help-identityEndpoint.html b/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl/help-identityEndpoint.html new file mode 100644 index 0000000..04b5085 --- /dev/null +++ b/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl/help-identityEndpoint.html @@ -0,0 +1,8 @@ +
+

+ Keystone is an OpenStack service that provides API client authentication, + service discovery, and distributed multi-tenant authorization by + implementing OpenStack’s Identity API. + +

+
\ No newline at end of file diff --git a/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/RepositoryTemplatedDeployment/config.jelly b/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment/config.jelly similarity index 100% rename from deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/RepositoryTemplatedDeployment/config.jelly rename to deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment/config.jelly diff --git a/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment/help-environment.html b/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment/help-environment.html new file mode 100644 index 0000000..c04f055 --- /dev/null +++ b/deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment/help-environment.html @@ -0,0 +1,5 @@ +
+

+ Choose one from environments described in .murano.yml file at the root of your repository. +

+
\ No newline at end of file