Browse Source

[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.

Minor code reformatting.

Change-Id: Ibf011caa7d9dd36857391acd05ce3bfc4fd5582c
Alexey Khivin 2 years ago
parent
commit
a40f7fb476
13 changed files with 235 additions and 114 deletions
  1. 6
    12
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerBuildWrapper.java
  2. 0
    1
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerDeployer.java
  3. 0
    101
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/RepositoryTemplatedDeployment.java
  4. 20
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/model/EnvironmentDescription.java
  5. 28
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/model/MuranoYaml.java
  6. 45
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/MuranoCiConfig.java
  7. 86
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment.java
  8. 5
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/TemplatedDeployment/help-objectModel.html
  9. 1
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/Messages.properties
  10. 31
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl/config.jelly
  11. 8
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl/help-identityEndpoint.html
  12. 0
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment/config.jelly
  13. 5
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment/help-environment.html

+ 6
- 12
deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerBuildWrapper.java View File

@@ -5,13 +5,8 @@ import com.cloudbees.plugins.credentials.CredentialsProvider;
5 5
 import com.cloudbees.plugins.credentials.common.StandardCredentials;
6 6
 import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
7 7
 import com.cloudbees.plugins.credentials.domains.DomainRequirement;
8
-import com.fasterxml.jackson.core.JsonParser;
9
-import com.fasterxml.jackson.databind.ObjectMapper;
10
-import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
11
-import com.fasterxml.jackson.dataformat.yaml.YAMLParser;
12 8
 import hudson.EnvVars;
13 9
 import hudson.Extension;
14
-import hudson.FilePath;
15 10
 import hudson.Launcher;
16 11
 import hudson.model.*;
17 12
 import hudson.security.ACL;
@@ -19,19 +14,17 @@ import hudson.tasks.BuildWrapper;
19 14
 import hudson.tasks.BuildWrapperDescriptor;
20 15
 import hudson.util.ListBoxModel;
21 16
 import jenkins.model.Jenkins;
22
-import org.apache.http.impl.client.SystemDefaultCredentialsProvider;
23 17
 import org.kohsuke.stapler.AncestorInPath;
24 18
 import org.kohsuke.stapler.DataBoundConstructor;
25 19
 import org.kohsuke.stapler.QueryParameter;
26 20
 import org.kohsuke.stapler.export.Exported;
27 21
 import org.openstack.murano.jenkins_plugins.muranoci.deploy.credentials.OpenstackCredentials;
22
+import org.openstack.murano.jenkins_plugins.muranoci.deploy.repository.RepositoryTemplatedDeployment;
28 23
 
29 24
 import java.io.IOException;
30 25
 import java.io.Serializable;
31 26
 import java.math.BigInteger;
32
-import java.net.URL;
33 27
 import java.security.SecureRandom;
34
-import java.util.HashMap;
35 28
 import java.util.List;
36 29
 import java.util.Map;
37 30
 
@@ -74,7 +67,7 @@ public class MuranoManagerBuildWrapper extends BuildWrapper implements Serializa
74 67
                     credentials.getPassword().getPlainText(),
75 68
                     credentials.getTenant()
76 69
             );
77
-            if (env.containsKey("BUILD_ENVIRONMENT_TIMEOUT")) {
70
+            if (env.containsKey("BUILD_ENVIRONMENT_TIMEOUT")){
78 71
                 int timeout = Integer.parseInt(env.get("BUILD_ENVIRONMENT_TIMEOUT"));
79 72
                 helper.setTimeout(timeout);
80 73
             }
@@ -82,7 +75,8 @@ public class MuranoManagerBuildWrapper extends BuildWrapper implements Serializa
82 75
             //TODO: Remove
83 76
             try {
84 77
                 ((RepositoryTemplatedDeployment) deployment).readObjectModel(build.getWorkspace());
85
-            } catch (Exception io) {
78
+            } catch (Exception io){
79
+                io.printStackTrace();
86 80
             }
87 81
 
88 82
             String name = generateEnvName();
@@ -91,7 +85,7 @@ public class MuranoManagerBuildWrapper extends BuildWrapper implements Serializa
91 85
                     name, deployment.getObjectModel());
92 86
 
93 87
             boolean result = helper.waitDeploymentResult(envId);
94
-            if (!result) {
88
+            if (!result){
95 89
                 build.setResult(Result.FAILURE);
96 90
             }
97 91
         } catch (Exception e) {
@@ -122,7 +116,7 @@ public class MuranoManagerBuildWrapper extends BuildWrapper implements Serializa
122 116
 
123 117
         return openstackCredentials;
124 118
     }
125
-
119
+    
126 120
     @Exported
127 121
     public MuranoDeployment getDeployment() {
128 122
         return deployment;

+ 0
- 1
deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerDeployer.java View File

@@ -1,6 +1,5 @@
1 1
 package org.openstack.murano.jenkins_plugins.muranoci.deploy;
2 2
 
3
-import hudson.EnvVars;
4 3
 import hudson.Extension;
5 4
 import hudson.Launcher;
6 5
 import hudson.model.AbstractBuild;

+ 0
- 101
deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/RepositoryTemplatedDeployment.java View File

@@ -1,101 +0,0 @@
1
-package org.openstack.murano.jenkins_plugins.muranoci.deploy;
2
-
3
-import com.fasterxml.jackson.core.JsonFactory;
4
-import com.fasterxml.jackson.core.JsonProcessingException;
5
-import com.fasterxml.jackson.core.type.TypeReference;
6
-import com.fasterxml.jackson.databind.ObjectMapper;
7
-import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
8
-import com.fasterxml.jackson.dataformat.yaml.YAMLParser;
9
-import hudson.Extension;
10
-import hudson.FilePath;
11
-import hudson.model.Descriptor;
12
-import org.kohsuke.stapler.DataBoundConstructor;
13
-
14
-import java.io.IOException;
15
-import java.nio.file.Files;
16
-import java.nio.file.Paths;
17
-import java.util.ArrayList;
18
-import java.util.HashMap;
19
-import java.util.List;
20
-import java.util.Map;
21
-
22
-public class RepositoryTemplatedDeployment extends MuranoDeployment {
23
-    /**
24
-     * The file in the repository that contains muranoci configuration.
25
-     */
26
-    public static final String CI_CONFG_FILENAME = ".murano.yml";
27
-
28
-    /**
29
-     *
30
-     */
31
-    private final String environment;
32
-
33
-    /**
34
-     * The specific Implemenation of <code>MuranoDeployment</code> that
35
-     * gets object model from the file within the repo.
36
-     *
37
-     * @param environment The name of the environment within the .murano.yml config
38
-     */
39
-    @DataBoundConstructor
40
-    public RepositoryTemplatedDeployment(
41
-            String environment) {
42
-
43
-        this.environment = environment;
44
-    }
45
-
46
-    public String getEnvironment() {
47
-        return environment;
48
-    }
49
-
50
-    /**
51
-     * Denotes that this is a cloud deployment plugin.
52
-     */
53
-    @Extension
54
-    public static class DescriptorImpl extends AbstractMuranoDeploymentDescriptor {
55
-        public DescriptorImpl() {
56
-            this(RepositoryTemplatedDeployment.class);
57
-        }
58
-
59
-        public DescriptorImpl(Class<? extends RepositoryTemplatedDeployment> clazz) {
60
-            super(clazz);
61
-        }
62
-
63
-        /**
64
-         * {@inheritDoc}
65
-         */
66
-        @Override
67
-        public String getDisplayName() {
68
-            return Messages.RepositoryTemplatedMuranoDeployment_DisplayName();
69
-        }
70
-
71
-        /**
72
-         * {@inheritDoc}
73
-         */
74
-        @Override
75
-        public boolean isApplicable(Descriptor descriptor) {
76
-            return true;
77
-        }
78
-    }
79
-
80
-
81
-    public void readObjectModel(FilePath workspace) throws IOException {
82
-        String config = null;
83
-        try {
84
-            config = new FilePath(workspace, ".murano.yml").readToString();
85
-        } catch (IOException e) {
86
-            e.printStackTrace();
87
-        } catch (InterruptedException e) {
88
-            e.printStackTrace();
89
-        }
90
-        YAMLFactory factory = new YAMLFactory();
91
-        ObjectMapper mapper = new ObjectMapper(factory);
92
-        HashMap<String, Object> map = mapper.readValue(config, HashMap.class);
93
-        Object model = ((Map<String,Object>)((Map<String,Object>)map).get("environments")).get(this.environment);
94
-
95
-        JsonFactory jsonFactory = new JsonFactory();
96
-        ObjectMapper mapperModel = new ObjectMapper(jsonFactory);
97
-        String string = mapperModel.writeValueAsString(model);
98
-        System.out.println(string);
99
-        this.setObjectModel(string);
100
-    }
101
-}

+ 20
- 0
deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/model/EnvironmentDescription.java View File

@@ -0,0 +1,20 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy.model;
2
+
3
+public class EnvironmentDescription {
4
+    private String modelFile = null;
5
+
6
+    public EnvironmentDescription() {
7
+    }
8
+
9
+    public EnvironmentDescription(String modelPath) {
10
+        this.modelFile = modelPath;
11
+    }
12
+
13
+    public String getModelFile() {
14
+        return modelFile;
15
+    }
16
+
17
+    public void setModelFile(String modelFile) {
18
+        this.modelFile = modelFile;
19
+    }
20
+}

+ 28
- 0
deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/model/MuranoYaml.java View File

@@ -0,0 +1,28 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy.model;
2
+
3
+
4
+import com.fasterxml.jackson.annotation.JsonProperty;
5
+
6
+import java.util.HashMap;
7
+import java.util.Map;
8
+
9
+public class MuranoYaml {
10
+
11
+    @JsonProperty
12
+    private Map<String, EnvironmentDescription> environments = null;
13
+
14
+    public MuranoYaml() {
15
+    }
16
+
17
+    public MuranoYaml(Map<String, EnvironmentDescription> environments) {
18
+        this.environments = environments;
19
+    }
20
+
21
+    public Map<String, EnvironmentDescription> getEnvironments() {
22
+        return environments;
23
+    }
24
+
25
+    public void setEnvironments(HashMap<String, EnvironmentDescription> environments) {
26
+        this.environments = environments;
27
+    }
28
+}

+ 45
- 0
deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/MuranoCiConfig.java View File

@@ -0,0 +1,45 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy.repository;
2
+
3
+import com.fasterxml.jackson.databind.ObjectMapper;
4
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
5
+import hudson.FilePath;
6
+import org.openstack.murano.jenkins_plugins.muranoci.deploy.model.MuranoYaml;
7
+
8
+import java.io.IOException;
9
+
10
+/**
11
+ * Class for getting information from a CI-config.
12
+ */
13
+public class MuranoCiConfig {
14
+    /**
15
+     * The file in the repository that contains muranoci configuration.
16
+     */
17
+    public static final String CI_CONFG_FILENAME = ".murano.yml";
18
+
19
+    private final MuranoYaml data;
20
+
21
+    public MuranoCiConfig(MuranoYaml data) {
22
+        this.data = data;
23
+    }
24
+
25
+    public MuranoYaml getData() {
26
+        return data;
27
+    }
28
+
29
+    public static MuranoCiConfig read(FilePath workspace) throws IOException {
30
+        String configYaml = null;
31
+        try {
32
+            configYaml = new FilePath(workspace, CI_CONFG_FILENAME).readToString();
33
+        } catch (IOException e) {
34
+            e.printStackTrace();
35
+        } catch (InterruptedException e) {
36
+            e.printStackTrace();
37
+        }
38
+
39
+        final YAMLFactory factory = new YAMLFactory();
40
+        ObjectMapper mapper = new ObjectMapper(factory);
41
+        MuranoYaml data = mapper.readValue(configYaml, MuranoYaml.class);
42
+
43
+        return new MuranoCiConfig(data);
44
+    }
45
+}

+ 86
- 0
deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment.java View File

@@ -0,0 +1,86 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy.repository;
2
+
3
+import hudson.Extension;
4
+import hudson.FilePath;
5
+import hudson.model.Descriptor;
6
+import org.kohsuke.stapler.DataBoundConstructor;
7
+import org.openstack.murano.jenkins_plugins.muranoci.deploy.AbstractMuranoDeploymentDescriptor;
8
+import org.openstack.murano.jenkins_plugins.muranoci.deploy.Messages;
9
+import org.openstack.murano.jenkins_plugins.muranoci.deploy.MuranoDeployment;
10
+import org.openstack.murano.jenkins_plugins.muranoci.deploy.model.EnvironmentDescription;
11
+
12
+import java.io.IOException;
13
+
14
+public class RepositoryTemplatedDeployment extends MuranoDeployment {
15
+
16
+    /**
17
+     * An environment description name in a config
18
+     */
19
+    private final String environment;
20
+
21
+    /**
22
+     * The specific Implemenation of <code>MuranoDeployment</code> that
23
+     * gets object model from the file within the repo.
24
+     *
25
+     * @param environment The name of the environment within the .murano.yml config
26
+     */
27
+    @DataBoundConstructor
28
+    public RepositoryTemplatedDeployment(String environment) {
29
+
30
+        this.environment = environment;
31
+    }
32
+
33
+    public String getEnvironment() {
34
+        return environment;
35
+    }
36
+
37
+    /**
38
+     * Denotes that this is a cloud deployment plugin.
39
+     */
40
+    @Extension
41
+    public static class DescriptorImpl extends AbstractMuranoDeploymentDescriptor {
42
+        public DescriptorImpl() {
43
+            this(RepositoryTemplatedDeployment.class);
44
+        }
45
+
46
+        public DescriptorImpl(Class<? extends RepositoryTemplatedDeployment> clazz) {
47
+            super(clazz);
48
+        }
49
+
50
+        /**
51
+         * {@inheritDoc}
52
+         */
53
+        @Override
54
+        public String getDisplayName() {
55
+            return Messages.RepositoryTemplatedMuranoDeployment_DisplayName();
56
+        }
57
+
58
+        /**
59
+         * {@inheritDoc}
60
+         */
61
+        @Override
62
+        public boolean isApplicable(Descriptor descriptor) {
63
+            return true;
64
+        }
65
+    }
66
+
67
+    /**
68
+     * Read object model from a file pointed at current job param.
69
+     * The file should be placed at the repo and th3e repo should be
70
+     * fetched before this stage
71
+     *
72
+     * @param workspace working dir for a current Jenkins-job
73
+     * @throws IOException file reading error
74
+     * @throws InterruptedException file reading error
75
+     */
76
+    public void readObjectModel(FilePath workspace) throws IOException, InterruptedException {
77
+        MuranoCiConfig config = MuranoCiConfig.read(workspace);
78
+
79
+        EnvironmentDescription description = config.getData().getEnvironments().get(this.environment);
80
+
81
+        String modelPath = description.getModelFile();
82
+        String objectModel = new FilePath(workspace, modelPath).readToString();
83
+
84
+        this.setObjectModel( objectModel);
85
+    }
86
+}

+ 5
- 0
deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/TemplatedDeployment/help-objectModel.html View File

@@ -0,0 +1,5 @@
1
+<div>
2
+    <p>
3
+        <a href="http://docs.openstack.org/developer/murano/draft/appdev-guide/murano_pl.html#object-model">Object Model</a> for your environment
4
+    </p>
5
+</div>

+ 1
- 0
deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/Messages.properties View File

@@ -0,0 +1 @@
1
+CertificateCredentialsImpl.DisplayName=Openstack Cloud

+ 31
- 0
deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl/config.jelly View File

@@ -0,0 +1,31 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler">
3
+    <f:entry title="Name" field="name">
4
+        <f:textbox/>
5
+    </f:entry>
6
+
7
+    <f:entry title="Description" field="description">
8
+        <f:textbox/>
9
+    </f:entry>
10
+
11
+    <f:entry title="${%Identity service endpoint}" field="identityServiceEndpoint">
12
+        <f:textbox/>
13
+    </f:entry>
14
+
15
+    <f:entry title="${%Tenant}" field="tenant">
16
+        <f:textbox/>
17
+    </f:entry>
18
+
19
+    <f:entry title="${%Username}" field="username">
20
+        <f:textbox/>
21
+    </f:entry>
22
+
23
+    <f:entry title="${%Password}" field="password">
24
+        <f:password/>
25
+    </f:entry>
26
+
27
+    <f:validateButton
28
+            title="${%Test Connection}" progress="${%Testing...}"
29
+            method="testConnection" with="identityServiceEndpoint,tenant,username,password"/>
30
+
31
+</j:jelly>

+ 8
- 0
deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl/help-identityEndpoint.html View File

@@ -0,0 +1,8 @@
1
+<div>
2
+    <p>
3
+        Keystone is an OpenStack service that provides API client authentication,
4
+        service discovery, and distributed multi-tenant authorization by
5
+        implementing OpenStack’s Identity API.
6
+        <a href="http://docs.openstack.org/developer/keystone/"/>
7
+    </p>
8
+</div>

deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/RepositoryTemplatedDeployment/config.jelly → deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment/config.jelly View File


+ 5
- 0
deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/repository/RepositoryTemplatedDeployment/help-environment.html View File

@@ -0,0 +1,5 @@
1
+<div>
2
+    <p>
3
+        Choose one from environments described in .murano.yml file at the root of your repository.
4
+    </p>
5
+</div>

Loading…
Cancel
Save