Browse Source

[DeploymentManager] Deploy test envs using Murano

 * deploy environement using custom object model
 * store openstack credentials
 * use object model from the config within application
 repository

Change-Id: I18f1eb590845acbd7a8287797b29cbd727b113da
Alexey Khivin 2 years ago
parent
commit
2110eec0e8
24 changed files with 1594 additions and 0 deletions
  1. 7
    0
      deployment-manager/.gitignore
  2. 0
    0
      deployment-manager/CONTRIBUTING.md
  3. 201
    0
      deployment-manager/LICENSE
  4. 29
    0
      deployment-manager/README.md
  5. 139
    0
      deployment-manager/pom.xml
  6. 28
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/AbstractMuranoDeploymentDescriptor.java
  7. 36
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/BuildStepDetailsProvider.java
  8. 77
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoDeployment.java
  9. 363
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoHelper.java
  10. 211
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerBuildWrapper.java
  11. 92
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerDeployer.java
  12. 101
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/RepositoryTemplatedDeployment.java
  13. 60
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/TemplatedDeployment.java
  14. 14
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentials.java
  15. 109
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl.java
  16. 12
    0
      deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsNameProvider.java
  17. 26
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/Messages.properties
  18. 6
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/Messages.properties
  19. 21
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerBuildWrapper/config.jelly
  20. 17
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/MuranoManagerDeployer/config.jelly
  21. 14
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/RepositoryTemplatedDeployment/config.jelly
  22. 15
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/TemplatedDeployment/config.jelly
  23. 12
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/TemplatedDeployment/global.jelly
  24. 4
    0
      deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/index.jelly

+ 7
- 0
deployment-manager/.gitignore View File

@@ -0,0 +1,7 @@
1
+*.classpath
2
+*.project
3
+*.iml
4
+*.settings
5
+.idea/
6
+work/
7
+target/

+ 0
- 0
deployment-manager/CONTRIBUTING.md View File


+ 201
- 0
deployment-manager/LICENSE View File

@@ -0,0 +1,201 @@
1
+Apache License
2
+                           Version 2.0, January 2004
3
+                        http://www.apache.org/licenses/
4
+
5
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+   1. Definitions.
8
+
9
+      "License" shall mean the terms and conditions for use, reproduction,
10
+      and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+      "Licensor" shall mean the copyright owner or entity authorized by
13
+      the copyright owner that is granting the License.
14
+
15
+      "Legal Entity" shall mean the union of the acting entity and all
16
+      other entities that control, are controlled by, or are under common
17
+      control with that entity. For the purposes of this definition,
18
+      "control" means (i) the power, direct or indirect, to cause the
19
+      direction or management of such entity, whether by contract or
20
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+      outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+      "You" (or "Your") shall mean an individual or Legal Entity
24
+      exercising permissions granted by this License.
25
+
26
+      "Source" form shall mean the preferred form for making modifications,
27
+      including but not limited to software source code, documentation
28
+      source, and configuration files.
29
+
30
+      "Object" form shall mean any form resulting from mechanical
31
+      transformation or translation of a Source form, including but
32
+      not limited to compiled object code, generated documentation,
33
+      and conversions to other media types.
34
+
35
+      "Work" shall mean the work of authorship, whether in Source or
36
+      Object form, made available under the License, as indicated by a
37
+      copyright notice that is included in or attached to the work
38
+      (an example is provided in the Appendix below).
39
+
40
+      "Derivative Works" shall mean any work, whether in Source or Object
41
+      form, that is based on (or derived from) the Work and for which the
42
+      editorial revisions, annotations, elaborations, or other modifications
43
+      represent, as a whole, an original work of authorship. For the purposes
44
+      of this License, Derivative Works shall not include works that remain
45
+      separable from, or merely link (or bind by name) to the interfaces of,
46
+      the Work and Derivative Works thereof.
47
+
48
+      "Contribution" shall mean any work of authorship, including
49
+      the original version of the Work and any modifications or additions
50
+      to that Work or Derivative Works thereof, that is intentionally
51
+      submitted to Licensor for inclusion in the Work by the copyright owner
52
+      or by an individual or Legal Entity authorized to submit on behalf of
53
+      the copyright owner. For the purposes of this definition, "submitted"
54
+      means any form of electronic, verbal, or written communication sent
55
+      to the Licensor or its representatives, including but not limited to
56
+      communication on electronic mailing lists, source code control systems,
57
+      and issue tracking systems that are managed by, or on behalf of, the
58
+      Licensor for the purpose of discussing and improving the Work, but
59
+      excluding communication that is conspicuously marked or otherwise
60
+      designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+      "Contributor" shall mean Licensor and any individual or Legal Entity
63
+      on behalf of whom a Contribution has been received by Licensor and
64
+      subsequently incorporated within the Work.
65
+
66
+   2. Grant of Copyright License. Subject to the terms and conditions of
67
+      this License, each Contributor hereby grants to You a perpetual,
68
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+      copyright license to reproduce, prepare Derivative Works of,
70
+      publicly display, publicly perform, sublicense, and distribute the
71
+      Work and such Derivative Works in Source or Object form.
72
+
73
+   3. Grant of Patent License. Subject to the terms and conditions of
74
+      this License, each Contributor hereby grants to You a perpetual,
75
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+      (except as stated in this section) patent license to make, have made,
77
+      use, offer to sell, sell, import, and otherwise transfer the Work,
78
+      where such license applies only to those patent claims licensable
79
+      by such Contributor that are necessarily infringed by their
80
+      Contribution(s) alone or by combination of their Contribution(s)
81
+      with the Work to which such Contribution(s) was submitted. If You
82
+      institute patent litigation against any entity (including a
83
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+      or a Contribution incorporated within the Work constitutes direct
85
+      or contributory patent infringement, then any patent licenses
86
+      granted to You under this License for that Work shall terminate
87
+      as of the date such litigation is filed.
88
+
89
+   4. Redistribution. You may reproduce and distribute copies of the
90
+      Work or Derivative Works thereof in any medium, with or without
91
+      modifications, and in Source or Object form, provided that You
92
+      meet the following conditions:
93
+
94
+      (a) You must give any other recipients of the Work or
95
+          Derivative Works a copy of this License; and
96
+
97
+      (b) You must cause any modified files to carry prominent notices
98
+          stating that You changed the files; and
99
+
100
+      (c) You must retain, in the Source form of any Derivative Works
101
+          that You distribute, all copyright, patent, trademark, and
102
+          attribution notices from the Source form of the Work,
103
+          excluding those notices that do not pertain to any part of
104
+          the Derivative Works; and
105
+
106
+      (d) If the Work includes a "NOTICE" text file as part of its
107
+          distribution, then any Derivative Works that You distribute must
108
+          include a readable copy of the attribution notices contained
109
+          within such NOTICE file, excluding those notices that do not
110
+          pertain to any part of the Derivative Works, in at least one
111
+          of the following places: within a NOTICE text file distributed
112
+          as part of the Derivative Works; within the Source form or
113
+          documentation, if provided along with the Derivative Works; or,
114
+          within a display generated by the Derivative Works, if and
115
+          wherever such third-party notices normally appear. The contents
116
+          of the NOTICE file are for informational purposes only and
117
+          do not modify the License. You may add Your own attribution
118
+          notices within Derivative Works that You distribute, alongside
119
+          or as an addendum to the NOTICE text from the Work, provided
120
+          that such additional attribution notices cannot be construed
121
+          as modifying the License.
122
+
123
+      You may add Your own copyright statement to Your modifications and
124
+      may provide additional or different license terms and conditions
125
+      for use, reproduction, or distribution of Your modifications, or
126
+      for any such Derivative Works as a whole, provided Your use,
127
+      reproduction, and distribution of the Work otherwise complies with
128
+      the conditions stated in this License.
129
+
130
+   5. Submission of Contributions. Unless You explicitly state otherwise,
131
+      any Contribution intentionally submitted for inclusion in the Work
132
+      by You to the Licensor shall be under the terms and conditions of
133
+      this License, without any additional terms or conditions.
134
+      Notwithstanding the above, nothing herein shall supersede or modify
135
+      the terms of any separate license agreement you may have executed
136
+      with Licensor regarding such Contributions.
137
+
138
+   6. Trademarks. This License does not grant permission to use the trade
139
+      names, trademarks, service marks, or product names of the Licensor,
140
+      except as required for reasonable and customary use in describing the
141
+      origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+   7. Disclaimer of Warranty. Unless required by applicable law or
144
+      agreed to in writing, Licensor provides the Work (and each
145
+      Contributor provides its Contributions) on an "AS IS" BASIS,
146
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+      implied, including, without limitation, any warranties or conditions
148
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+      PARTICULAR PURPOSE. You are solely responsible for determining the
150
+      appropriateness of using or redistributing the Work and assume any
151
+      risks associated with Your exercise of permissions under this License.
152
+
153
+   8. Limitation of Liability. In no event and under no legal theory,
154
+      whether in tort (including negligence), contract, or otherwise,
155
+      unless required by applicable law (such as deliberate and grossly
156
+      negligent acts) or agreed to in writing, shall any Contributor be
157
+      liable to You for damages, including any direct, indirect, special,
158
+      incidental, or consequential damages of any character arising as a
159
+      result of this License or out of the use or inability to use the
160
+      Work (including but not limited to damages for loss of goodwill,
161
+      work stoppage, computer failure or malfunction, or any and all
162
+      other commercial damages or losses), even if such Contributor
163
+      has been advised of the possibility of such damages.
164
+
165
+   9. Accepting Warranty or Additional Liability. While redistributing
166
+      the Work or Derivative Works thereof, You may choose to offer,
167
+      and charge a fee for, acceptance of support, warranty, indemnity,
168
+      or other liability obligations and/or rights consistent with this
169
+      License. However, in accepting such obligations, You may act only
170
+      on Your own behalf and on Your sole responsibility, not on behalf
171
+      of any other Contributor, and only if You agree to indemnify,
172
+      defend, and hold each Contributor harmless for any liability
173
+      incurred by, or claims asserted against, such Contributor by reason
174
+      of your accepting any such warranty or additional liability.
175
+
176
+   END OF TERMS AND CONDITIONS
177
+
178
+   APPENDIX: How to apply the Apache License to your work.
179
+
180
+      To apply the Apache License to your work, attach the following
181
+      boilerplate notice, with the fields enclosed by brackets "{}"
182
+      replaced with your own identifying information. (Don't include
183
+      the brackets!)  The text should be enclosed in the appropriate
184
+      comment syntax for the file format. We also recommend that a
185
+      file or class name and description of purpose be included on the
186
+      same "printed page" as the copyright notice for easier
187
+      identification within third-party archives.
188
+
189
+   Copyright {yyyy} {name of copyright owner}
190
+
191
+   Licensed under the Apache License, Version 2.0 (the "License");
192
+   you may not use this file except in compliance with the License.
193
+   You may obtain a copy of the License at
194
+
195
+       http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+   Unless required by applicable law or agreed to in writing, software
198
+   distributed under the License is distributed on an "AS IS" BASIS,
199
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+   See the License for the specific language governing permissions and
201
+   limitations under the License.

+ 29
- 0
deployment-manager/README.md View File

@@ -0,0 +1,29 @@
1
+# Openstack Murano Deployment Manager Plugin
2
+
3
+This plugin manages Openstack Murano environments
4
+
5
+# Build
6
+    mvn clean verify
7
+Creates the plugin HPI package for use with Jenkins.
8
+
9
+# Run by Maven
10
+    mvn hpi:run
11
+Runs Jenkins with the plugin installed
12
+
13
+# License
14
+
15
+	(The Apache v2 License)
16
+
17
+    Copyright 2016 Google Inc. All Rights Reserved.
18
+
19
+    Licensed under the Apache License, Version 2.0 (the "License");
20
+    you may not use this file except in compliance with the License.
21
+    You may obtain a copy of the License at
22
+
23
+        http://www.apache.org/licenses/LICENSE-2.0
24
+
25
+    Unless required by applicable law or agreed to in writing, software
26
+    distributed under the License is distributed on an "AS IS" BASIS,
27
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+    See the License for the specific language governing permissions and
29
+    limitations under the License.

+ 139
- 0
deployment-manager/pom.xml View File

@@ -0,0 +1,139 @@
1
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
+    <modelVersion>4.0.0</modelVersion>
4
+
5
+    <parent>
6
+        <groupId>org.jenkins-ci.plugins</groupId>
7
+        <artifactId>plugin</artifactId>
8
+        <version>2.15</version>
9
+    </parent>
10
+
11
+    <name>Murano Deployment Manager Jenkins Plugin</name>
12
+
13
+    <description>
14
+        This plugin provides integration with Openstack Murano
15
+    </description>
16
+
17
+    <url>https://wiki.jenkins-ci.org/display/JENKINS/Murano+Deployment+Manager+Plugin</url>
18
+    <artifactId>murano-deployment-manager</artifactId>
19
+    <packaging>hpi</packaging>
20
+    <version>0.1-SNAPSHOT</version>
21
+
22
+    <licenses>
23
+        <license>
24
+            <name>The Apache V2 License</name>
25
+            <url>http://www.apache.org/licenses/LICENSE-2.0</url>
26
+            <distribution>repo</distribution>
27
+        </license>
28
+    </licenses>
29
+
30
+    <developers>
31
+        <developer>
32
+            <name>Alexey Khivin</name>
33
+            <email>akhivin@gmail.com</email>
34
+        </developer>
35
+    </developers>
36
+
37
+    <properties>
38
+        <java.level>8</java.level>
39
+        <jenkins.version>2.23</jenkins.version>
40
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
41
+        <openstack4jversion>3.0.2</openstack4jversion>
42
+    </properties>
43
+
44
+    <repositories>
45
+        <repository>
46
+            <id>repo.jenkins-ci.org</id>
47
+            <name>Jenkins Repository</name>
48
+            <url>http://repo.jenkins-ci.org/public/</url>
49
+        </repository>
50
+        <repository>
51
+            <id>jgit-repository</id>
52
+            <name>Eclipse JGit Repository</name>
53
+            <url>http://download.eclipse.org/jgit/maven</url>
54
+        </repository>
55
+    </repositories>
56
+
57
+    <pluginRepositories>
58
+        <pluginRepository>
59
+            <id>repo.jenkins-ci.org</id>
60
+            <url>http://repo.jenkins-ci.org/public/</url>
61
+        </pluginRepository>
62
+    </pluginRepositories>
63
+
64
+    <build>
65
+        <plugins>
66
+            <plugin>
67
+                <groupId>org.apache.maven.plugins</groupId>
68
+                <artifactId>maven-deploy-plugin</artifactId>
69
+                <version>2.8.2</version>
70
+                <dependencies>
71
+                    <dependency>
72
+                        <groupId>org.apache.maven.wagon</groupId>
73
+                        <artifactId>wagon-http</artifactId>
74
+                        <version>1.0-beta-6</version>
75
+                        <type>jar</type>
76
+                    </dependency>
77
+                </dependencies>
78
+            </plugin>
79
+        </plugins>
80
+    </build>
81
+
82
+    <scm>
83
+        <connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
84
+        <developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
85
+        <url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
86
+        <tag>HEAD</tag>
87
+    </scm>
88
+
89
+    <dependencies>
90
+        <dependency>
91
+            <groupId>org.mockito</groupId>
92
+            <artifactId>mockito-all</artifactId>
93
+            <version>RELEASE</version>
94
+            <scope>test</scope>
95
+        </dependency>
96
+
97
+        <dependency>
98
+            <groupId>org.pacesys</groupId>
99
+            <artifactId>openstack4j-core</artifactId>
100
+            <version>${openstack4jversion}</version>
101
+        </dependency>
102
+
103
+        <dependency>
104
+            <groupId>org.pacesys.openstack4j.connectors</groupId>
105
+            <artifactId>openstack4j-httpclient</artifactId>
106
+            <version>${openstack4jversion}</version>
107
+        </dependency>
108
+
109
+        <dependency>
110
+            <groupId>com.googlecode.json-simple</groupId>
111
+            <artifactId>json-simple</artifactId>
112
+            <version>1.1.1</version>
113
+        </dependency>
114
+
115
+        <dependency>
116
+            <groupId>org.apache.httpcomponents</groupId>
117
+            <artifactId>httpclient</artifactId>
118
+            <version>4.5.1</version>
119
+        </dependency>
120
+
121
+        <dependency>
122
+            <groupId>com.fasterxml.jackson.core</groupId>
123
+            <artifactId>jackson-databind</artifactId>
124
+            <version>2.8.3</version>
125
+        </dependency>
126
+
127
+        <dependency>
128
+            <groupId>com.fasterxml.jackson.dataformat</groupId>
129
+            <artifactId>jackson-dataformat-yaml</artifactId>
130
+            <version>2.7.4</version>
131
+        </dependency>
132
+
133
+        <dependency>
134
+            <groupId>org.jenkins-ci.plugins</groupId>
135
+            <artifactId>credentials</artifactId>
136
+            <version>LATEST</version>
137
+        </dependency>
138
+    </dependencies>
139
+</project>

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

@@ -0,0 +1,28 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy;
2
+
3
+import hudson.model.Descriptor;
4
+import net.sf.json.JSONObject;
5
+import org.kohsuke.stapler.StaplerRequest;
6
+
7
+import static java.util.Objects.requireNonNull;
8
+
9
+public abstract class AbstractMuranoDeploymentDescriptor
10
+        extends Descriptor<MuranoDeployment> {
11
+
12
+    protected AbstractMuranoDeploymentDescriptor(Class<? extends MuranoDeployment> clazz) {
13
+        super(requireNonNull(clazz));
14
+        load();
15
+    }
16
+
17
+    /**
18
+     * {@inheritDoc}
19
+     */
20
+    @Override
21
+    public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
22
+        save();
23
+        return true;
24
+    }
25
+
26
+    public abstract boolean isApplicable(Descriptor descriptor);
27
+    public abstract String getDisplayName();
28
+}

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

@@ -0,0 +1,36 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy;
2
+
3
+import hudson.Extension;
4
+import hudson.ExtensionPoint;
5
+import hudson.model.Describable;
6
+import hudson.tasks.BuildStep;
7
+import hudson.tasks.Shell;
8
+
9
+
10
+public abstract class BuildStepDetailsProvider<T extends BuildStep> implements ExtensionPoint {
11
+
12
+    protected static String defaultName(BuildStep bs) {
13
+        return bs instanceof Describable<?> ? ((Describable<?>) bs).getDescriptor().getDisplayName()
14
+                : null;
15
+    }
16
+
17
+    /**
18
+     * @param bs A given {@link BuildStep}.
19
+     * @return the details of the build step.
20
+     */
21
+    public abstract String getDetails(T bs);
22
+
23
+    /**
24
+     * {@link BuildStepDetailsProvider} for {@link Shell}.
25
+     */
26
+    @Extension
27
+    public static class ShellBuildStepDetailsProvider extends BuildStepDetailsProvider<Shell> {
28
+        /**
29
+         * {@inheritDoc}
30
+         */
31
+        @Override
32
+        public String getDetails(Shell shell) {
33
+            return shell.getCommand();
34
+        }
35
+    }
36
+}

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

@@ -0,0 +1,77 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy;
2
+
3
+import hudson.DescriptorExtensionList;
4
+import hudson.ExtensionPoint;
5
+import hudson.model.Describable;
6
+import hudson.model.Descriptor;
7
+import jenkins.model.Jenkins;
8
+
9
+import java.util.LinkedList;
10
+import java.util.List;
11
+
12
+import static java.util.Objects.requireNonNull;
13
+
14
+public abstract class MuranoDeployment
15
+        implements Describable<MuranoDeployment>, ExtensionPoint {
16
+    /**
17
+     * Json data that describes Murano Environment applications
18
+     */
19
+    private String objectModel;
20
+
21
+
22
+    public MuranoDeployment() {
23
+        super();
24
+    }
25
+
26
+    /**
27
+     * Contains data that describes Environment within Openstack Cloud
28
+     * and connection credentials.
29
+     *
30
+     * @param objectModel description of environment to be deployed
31
+     */
32
+    public MuranoDeployment(String objectModel) {
33
+
34
+        this.objectModel = requireNonNull(objectModel, "Object Model should not be Null");
35
+    }
36
+
37
+    /**
38
+     * Boilerplate, see:
39
+     * https://wiki.jenkins-ci.org/display/JENKINS/Defining+a+new+extension+point
40
+     *
41
+     * @return all registered {@link MuranoDeployment}s
42
+     */
43
+    public static DescriptorExtensionList<MuranoDeployment, AbstractMuranoDeploymentDescriptor> all() {
44
+        return Jenkins.getInstance().getDescriptorList(MuranoDeployment.class);
45
+    }
46
+
47
+    public static List<AbstractMuranoDeploymentDescriptor> getCompatibleDeployments(Descriptor descriptor) {
48
+        LinkedList<AbstractMuranoDeploymentDescriptor> cloudDeployments =
49
+                new LinkedList<>();
50
+
51
+        for (AbstractMuranoDeploymentDescriptor deployment : all()) {
52
+            if (!deployment.isApplicable(descriptor)) {
53
+                continue;
54
+            }
55
+            cloudDeployments.add(deployment);
56
+        }
57
+
58
+        return cloudDeployments;
59
+    }
60
+
61
+    public String getObjectModel() {
62
+        return objectModel;
63
+    }
64
+
65
+    public void setObjectModel(String objectModel) {
66
+        this.objectModel = objectModel;
67
+    }
68
+
69
+    /**
70
+     * Boilerplate, see: https://wiki.jenkins-ci.org/display/JENKINS/Defining+a+new+extension+point
71
+     */
72
+    @Override
73
+    public Descriptor<MuranoDeployment> getDescriptor() {
74
+        return (Descriptor<MuranoDeployment>) Jenkins.getInstance().getDescriptor(getClass());
75
+    }
76
+
77
+}

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

@@ -0,0 +1,363 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy;
2
+
3
+
4
+import org.apache.http.client.methods.CloseableHttpResponse;
5
+import org.json.simple.JSONArray;
6
+import org.json.simple.JSONObject;
7
+import org.json.simple.parser.JSONParser;
8
+import org.json.simple.parser.ParseException;
9
+import org.kohsuke.stapler.DataBoundConstructor;
10
+import org.openstack4j.api.OSClient;
11
+import org.openstack4j.api.exceptions.AuthenticationException;
12
+import org.openstack4j.connectors.httpclient.HttpCommand;
13
+import org.openstack4j.core.transport.HttpMethod;
14
+import org.openstack4j.core.transport.HttpRequest;
15
+import org.openstack4j.openstack.OSFactory;
16
+
17
+import java.io.BufferedReader;
18
+import java.io.InputStreamReader;
19
+import java.time.Instant;
20
+import java.util.concurrent.TimeoutException;
21
+import java.util.logging.Level;
22
+import java.util.logging.LogRecord;
23
+import java.util.logging.Logger;
24
+
25
+public class MuranoHelper {
26
+    public static final int MURANO_DEFAULT_PORT = 8082;
27
+
28
+    private final static Logger LOG = Logger.getLogger(MuranoHelper.class.getName());
29
+
30
+    private OSClient.OSClientV2 os = null;
31
+
32
+    /**
33
+     * Suppose this is keystone Url
34
+     */
35
+    private String serverUrl;
36
+    private String username;
37
+    private String password;
38
+    private String tenantName;
39
+    /**
40
+     * Default timeout for waiting deployment success
41
+     */
42
+    private int timeout = 3600*1000;
43
+
44
+    @DataBoundConstructor
45
+    public MuranoHelper(String serverUrl,
46
+                        String username,
47
+                        String password,
48
+                        String tenantName) {
49
+        this.serverUrl = serverUrl;
50
+        this.username = username;
51
+        this.password = password;
52
+        this.tenantName = tenantName;
53
+    }
54
+
55
+    public String getServerUrl() {
56
+        return serverUrl;
57
+    }
58
+
59
+    public String getUsername() {
60
+        return username;
61
+    }
62
+
63
+    public String getPassword() {
64
+        return password;
65
+    }
66
+
67
+    public String getTenantName() {
68
+        return tenantName;
69
+    }
70
+
71
+
72
+    /**
73
+     *
74
+     * @param name New environment name
75
+     * @param objectModel object model describing new environment
76
+     * @return new environment id
77
+     * @throws AuthenticationException in case credentials
78
+     */
79
+    public String deployNewFromObjectModel(String name, String objectModel)
80
+            throws AuthenticationException {
81
+
82
+        this.authenticate();
83
+
84
+        String token = getOSClient().getAccess().getToken().getId();
85
+
86
+        String envId = checkIfDeploymentExists(token, name);
87
+        if (envId == null) {
88
+            // Create Env
89
+            envId = this.createEnvironment(token, name);
90
+
91
+            // Create Session
92
+            String sessionId = this.createEnvironmentSession(token, envId);
93
+
94
+            // Add App to Environment
95
+            addApplicationToEnvironment(token, envId, sessionId, objectModel);
96
+
97
+            // Deploy
98
+            deployEnvironment(token, envId, sessionId);
99
+        }
100
+
101
+        return envId;
102
+    }
103
+
104
+
105
+    /**
106
+     * Loop around to see if the deployment is a success. This waits for about 10 secs 300 times hoping that
107
+     * it finishes. This all depends on teh number of nodes and the speed of the boxes. But seems sufficient.
108
+     *
109
+     * @param envId Environemnt Id
110
+     * @return whether the deployment is a success
111
+     * @throws TimeoutException if deployment process still in progress after deadline
112
+     */
113
+    public boolean waitDeploymentResult(String envId) throws TimeoutException {
114
+        String token = getOSClient().getAccess().getToken().getId();
115
+
116
+        boolean status = false;
117
+        Instant deadline = Instant.now().plusMillis(timeout);
118
+
119
+        while(true) {
120
+            try {
121
+                Thread.sleep(10000);
122
+                String payload = getResponseForJson(
123
+                        getMuranoEnpoint(),
124
+                        MURANO_DEFAULT_PORT,
125
+                        "/v1/environments/" + envId + "/deployments",
126
+                        HttpMethod.GET,
127
+                        token,
128
+                        null,
129
+                        null);
130
+                JSONParser parser = new JSONParser();
131
+                try {
132
+                    JSONObject deployments = (JSONObject) parser.parse(payload);
133
+                    JSONArray deploymentList = (JSONArray) deployments.get("deployments");
134
+                    JSONObject thisDeployment = (JSONObject) deploymentList.get(0);
135
+                    if ("success".equals(thisDeployment.get("state"))) {
136
+                        status = true;
137
+                        break;
138
+                    }
139
+                } catch (ParseException pe) {
140
+                }
141
+            } catch (Exception ex) {
142
+                status = false;
143
+                break;
144
+            }
145
+            if (Instant.now().isAfter(deadline)){
146
+                throw new TimeoutException("Environment was not ready in time.");
147
+            }
148
+
149
+        }
150
+        return status;
151
+    }
152
+
153
+    /**
154
+     * Return the Environment id if it exists
155
+     *
156
+     * @param token
157
+     * @param name
158
+     * @return
159
+     */
160
+    private String checkIfDeploymentExists(String token, String name) {
161
+        // TODO: remove string manipulation
162
+        String payload = getResponseForJson(
163
+                getMuranoEnpoint(),
164
+                MURANO_DEFAULT_PORT,
165
+                "/v1/environments",
166
+                HttpMethod.GET,
167
+                token,
168
+                null,
169
+                null);
170
+        String envId = null;
171
+        JSONParser parser = new JSONParser();
172
+        try{
173
+            Object obj = parser.parse(payload);
174
+            JSONObject response = (JSONObject)obj;
175
+            JSONArray environmentArray =  (JSONArray) response.get("environments");
176
+            for (Object env: environmentArray) {
177
+                JSONObject thisEnv = (JSONObject) env;
178
+                String envName = (String) thisEnv.get("name");
179
+                if (envName.equals(name)) {
180
+                    envId = (String) thisEnv.get("id");
181
+                    break;
182
+                }
183
+            }
184
+        }catch(ParseException pe){
185
+            LogRecord logRecord = new LogRecord(Level.WARNING, "Parse exception: position: " + pe.getPosition());
186
+            logRecord.setThrown(pe);
187
+            LOG.log(logRecord);
188
+        }
189
+        return envId;
190
+    }
191
+
192
+    /**
193
+     * Deploy the environment given the environment id and Session Token
194
+     */
195
+    private void deployEnvironment(String token, String envId, String sessionId) {
196
+        String response = getResponseForJson(
197
+                getMuranoEnpoint(),
198
+                MURANO_DEFAULT_PORT,
199
+                "/v1/environments/" + envId + "/sessions/" + sessionId + "/deploy",
200
+                HttpMethod.POST,
201
+                token,
202
+                null,
203
+                null);
204
+    }
205
+
206
+
207
+    public String getMuranoEnpoint() {
208
+        /*
209
+         * TODO: This is temporary decision. Murano URL should be obtained from Keystone
210
+         */
211
+        String string[] = this.serverUrl.split(":");
212
+
213
+        return string[0] + ":" + string[1];
214
+    }
215
+
216
+    /**
217
+     * Add the app(K8S) to the environment
218
+     * @param token
219
+     * @param envId
220
+     * @param sessionId
221
+     * @param jsonReq
222
+     */
223
+    private void addApplicationToEnvironment(String token, String envId, String sessionId, String jsonReq) {
224
+        String response = getResponseForJson(this.getMuranoEnpoint(),
225
+                MURANO_DEFAULT_PORT,
226
+                "/v1/environments/" + envId + "/services",
227
+                HttpMethod.POST,
228
+                token,
229
+                jsonReq,
230
+                sessionId);
231
+    }
232
+
233
+    private String createEnvironmentSession(String token, String envId) {
234
+        String payload = getResponseForJson(this.getMuranoEnpoint(),
235
+                MURANO_DEFAULT_PORT,
236
+                "/v1/environments/" + envId + "/configure",
237
+                HttpMethod.POST,
238
+                token,
239
+                null,
240
+                null);
241
+
242
+        String sessionId = "";
243
+        JSONParser parser = new JSONParser();
244
+        try{
245
+            Object obj = parser.parse(payload);
246
+            JSONObject response = (JSONObject)obj;
247
+            sessionId = (String)response.get("id");
248
+        }catch(ParseException pe){
249
+            System.out.println("position: " + pe.getPosition());
250
+            System.out.println(pe);
251
+        }
252
+        return sessionId;
253
+    }
254
+
255
+    private String createEnvironment(String token, String envname) {
256
+        String reqPayload = "{\"name\":\"" + envname + "\"}";
257
+        String payload = getResponseForJson(
258
+                getMuranoEnpoint(),
259
+                MURANO_DEFAULT_PORT,
260
+                "/v1/environments",
261
+                HttpMethod.POST, token, reqPayload, null);
262
+
263
+        String envId = "";
264
+        JSONParser parser = new JSONParser();
265
+        try{
266
+            Object obj = parser.parse(payload);
267
+            JSONObject response = (JSONObject)obj;
268
+            envId = (String)response.get("id");
269
+        }catch(ParseException pe){
270
+            System.out.println("position: " + pe.getPosition());
271
+            System.out.println(pe);
272
+        }
273
+
274
+        return envId;
275
+    }
276
+
277
+    /**
278
+     * Main helper method to call the Murano API and return the response. Accepts both GET and POST.
279
+     *
280
+     * @param url Base URL to connect
281
+     * @param port Which port is murano listening on
282
+     * @param requestPath Path on Murano URL
283
+     * @param method GET or POST
284
+     * @param token Auth Token
285
+     * @param jsonPayload Payload for the message
286
+     * @param muranoSessionId Optional Session Id
287
+     * @return Response from the Call
288
+     */
289
+    private  String getResponseForJson(String url,
290
+                                       int port,
291
+                                       String requestPath,
292
+                                       HttpMethod method,
293
+                                       String token,
294
+                                       String jsonPayload,
295
+                                       String muranoSessionId) {
296
+        HttpRequest request = HttpRequest.builder().method(method)
297
+                .endpoint(url + ":" + port)
298
+                .path(requestPath)
299
+                .header("X-Auth-Token", token)
300
+                .json(jsonPayload)
301
+                .build();
302
+        if (muranoSessionId != null) {
303
+            request.getHeaders().put("X-Configuration-Session", muranoSessionId);
304
+        }
305
+        if (jsonPayload != null) {
306
+            request = request.toBuilder().json(jsonPayload).build();
307
+        }
308
+
309
+        HttpCommand command = HttpCommand.create(request);
310
+        CloseableHttpResponse response = null;
311
+        try {
312
+            response = command.execute();
313
+        } catch(Exception ex) {
314
+            ex.printStackTrace();
315
+            return null;
316
+        }
317
+
318
+        StringBuffer jsonString = new StringBuffer();
319
+        try {
320
+            BufferedReader br = new BufferedReader(new InputStreamReader(
321
+                    response.getEntity().getContent()));
322
+
323
+            //Print the raw output of murano api from the server
324
+            String output;
325
+
326
+            while ((output = br.readLine()) != null) {
327
+                jsonString.append(output + "\n");
328
+            }
329
+        } catch(Exception ex) {
330
+            return null;
331
+        }
332
+
333
+        return jsonString.toString();
334
+    }
335
+
336
+
337
+    /**
338
+     * Authenticate to the Openstack instance given the credentials in constructor
339
+     *
340
+     * @throws AuthenticationException in case of authentication failure.
341
+     */
342
+    public void authenticate() throws AuthenticationException {
343
+        this.os = OSFactory.builderV2()
344
+                .endpoint(this.serverUrl)
345
+                .credentials(this.username, this.password)
346
+                .tenantName(this.tenantName)
347
+                .authenticate();
348
+    }
349
+
350
+
351
+    /**
352
+     * Helper object to return the OSClient
353
+     * @return OSClient V2
354
+     */
355
+    public OSClient.OSClientV2 getOSClient() {
356
+       return this.os;
357
+    }
358
+
359
+    public void setTimeout(int timeout) {
360
+        this.timeout = timeout;
361
+    }
362
+}
363
+

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

@@ -0,0 +1,211 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy;
2
+
3
+import com.cloudbees.plugins.credentials.CredentialsMatchers;
4
+import com.cloudbees.plugins.credentials.CredentialsProvider;
5
+import com.cloudbees.plugins.credentials.common.StandardCredentials;
6
+import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
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
+import hudson.EnvVars;
13
+import hudson.Extension;
14
+import hudson.FilePath;
15
+import hudson.Launcher;
16
+import hudson.model.*;
17
+import hudson.security.ACL;
18
+import hudson.tasks.BuildWrapper;
19
+import hudson.tasks.BuildWrapperDescriptor;
20
+import hudson.util.ListBoxModel;
21
+import jenkins.model.Jenkins;
22
+import org.apache.http.impl.client.SystemDefaultCredentialsProvider;
23
+import org.kohsuke.stapler.AncestorInPath;
24
+import org.kohsuke.stapler.DataBoundConstructor;
25
+import org.kohsuke.stapler.QueryParameter;
26
+import org.kohsuke.stapler.export.Exported;
27
+import org.openstack.murano.jenkins_plugins.muranoci.deploy.credentials.OpenstackCredentials;
28
+
29
+import java.io.IOException;
30
+import java.io.Serializable;
31
+import java.math.BigInteger;
32
+import java.net.URL;
33
+import java.security.SecureRandom;
34
+import java.util.HashMap;
35
+import java.util.List;
36
+import java.util.Map;
37
+
38
+import static com.google.common.collect.Lists.newArrayList;
39
+import static java.util.Objects.requireNonNull;
40
+
41
+
42
+public class MuranoManagerBuildWrapper extends BuildWrapper implements Serializable {
43
+    private static String MURANO_ENV_NAME = "MuranoCI-";
44
+
45
+
46
+    private final MuranoDeployment deployment;
47
+    private String credentialsId;
48
+
49
+    @DataBoundConstructor
50
+    public MuranoManagerBuildWrapper(MuranoDeployment deployment,
51
+                                     String credentialsId) {
52
+
53
+        this.deployment = requireNonNull(deployment);
54
+        this.credentialsId = requireNonNull(credentialsId);
55
+    }
56
+
57
+    public String getCredentialsId() {
58
+        return credentialsId;
59
+    }
60
+
61
+    /**
62
+     * {@inheritDoc}
63
+     */
64
+    @Override
65
+    public BuildWrapper.Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener)
66
+            throws IOException, InterruptedException {
67
+        EnvVars env = build.getEnvironment(listener);
68
+        OpenstackCredentials credentials = getOpenstackCredentials(getCredentialsId());
69
+
70
+        try {
71
+            MuranoHelper helper = new MuranoHelper(
72
+                    credentials.getIdentityServiceEndpoint(),
73
+                    credentials.getUsername(),
74
+                    credentials.getPassword().getPlainText(),
75
+                    credentials.getTenant()
76
+            );
77
+            if (env.containsKey("BUILD_ENVIRONMENT_TIMEOUT")) {
78
+                int timeout = Integer.parseInt(env.get("BUILD_ENVIRONMENT_TIMEOUT"));
79
+                helper.setTimeout(timeout);
80
+            }
81
+
82
+            //TODO: Remove
83
+            try {
84
+                ((RepositoryTemplatedDeployment) deployment).readObjectModel(build.getWorkspace());
85
+            } catch (Exception io) {
86
+            }
87
+
88
+            String name = generateEnvName();
89
+
90
+            String envId = helper.deployNewFromObjectModel(
91
+                    name, deployment.getObjectModel());
92
+
93
+            boolean result = helper.waitDeploymentResult(envId);
94
+            if (!result) {
95
+                build.setResult(Result.FAILURE);
96
+            }
97
+        } catch (Exception e) {
98
+            e.printStackTrace();
99
+            build.setResult(Result.FAILURE);
100
+        }
101
+
102
+        return new JenkinsEnvironmentImpl(env);
103
+    }
104
+
105
+    private String generateEnvName() {
106
+        return MURANO_ENV_NAME + new BigInteger(
107
+                32,
108
+                new SecureRandom())
109
+                .toString(16);
110
+    }
111
+
112
+    private OpenstackCredentials getOpenstackCredentials(String credentialsId) {
113
+        List<OpenstackCredentials> openstackCredentialsList =
114
+                CredentialsProvider.lookupCredentials(
115
+                        OpenstackCredentials.class,
116
+                        Jenkins.getInstance(),
117
+                        ACL.SYSTEM);
118
+        OpenstackCredentials openstackCredentials = CredentialsMatchers.firstOrNull(
119
+                openstackCredentialsList,
120
+                CredentialsMatchers.allOf(
121
+                        CredentialsMatchers.withId(credentialsId)));
122
+
123
+        return openstackCredentials;
124
+    }
125
+
126
+    @Exported
127
+    public MuranoDeployment getDeployment() {
128
+        return deployment;
129
+    }
130
+
131
+    /**
132
+     * {@inheritDoc}
133
+     */
134
+    @Override
135
+    public DescriptorImpl getDescriptor() {
136
+        return (DescriptorImpl) super.getDescriptor();
137
+    }
138
+
139
+    /**
140
+     * The descriptor for our {@code MuranoManagerBuildWrapper} plugin.
141
+     */
142
+    @Extension
143
+    public static final class DescriptorImpl extends BuildWrapperDescriptor {
144
+        /**
145
+         * {@inheritDoc}
146
+         */
147
+        @Override
148
+        public boolean isApplicable(AbstractProject<?, ?> project) {
149
+            return true;
150
+        }
151
+
152
+        /**
153
+         * {@inheritDoc}
154
+         */
155
+        @Override
156
+        public String getDisplayName() {
157
+            return Messages.MuranoManagerBuildWrapper_DisplayName();
158
+        }
159
+
160
+
161
+        @SuppressWarnings("unused") // used by stapler
162
+        public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Jenkins context,
163
+                                                     @QueryParameter String remoteBase) {
164
+            if (context == null || !context.hasPermission(Item.CONFIGURE)) {
165
+                return new StandardListBoxModel();
166
+            }
167
+
168
+            List<DomainRequirement> domainRequirements = newArrayList();
169
+            return new StandardListBoxModel()
170
+                    .withEmptySelection()
171
+                    .withMatching(
172
+                            CredentialsMatchers.anyOf(
173
+                                    CredentialsMatchers.instanceOf(OpenstackCredentials.class)),
174
+                            CredentialsProvider.lookupCredentials(
175
+                                    StandardCredentials.class,
176
+                                    context,
177
+                                    ACL.SYSTEM,
178
+                                    domainRequirements));
179
+        }
180
+
181
+    }
182
+
183
+    private final class JenkinsEnvironmentImpl extends Environment {
184
+        private final EnvVars envVars;
185
+
186
+        /**
187
+         * Construct the instance with a snapshot of the environment within which it was created in case
188
+         * values that were used to configure it at the start of the build change before the end.
189
+         *
190
+         * @param envVars The set of environment variables used to spin up the ephemeral deployment, so
191
+         *                we can tear it down with the same.
192
+         */
193
+        public JenkinsEnvironmentImpl(EnvVars envVars) {
194
+            this.envVars = requireNonNull(envVars);
195
+        }
196
+
197
+        @Override
198
+        public void buildEnvVars(Map<String, String> env) {
199
+            super.buildEnvVars(env);
200
+        }
201
+
202
+        /**
203
+         * {@inheritDoc}
204
+         */
205
+        @Override
206
+        public boolean tearDown(AbstractBuild build, BuildListener listener)
207
+                throws IOException, InterruptedException {
208
+            return true;
209
+        }
210
+    }
211
+}

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

@@ -0,0 +1,92 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy;
2
+
3
+import hudson.EnvVars;
4
+import hudson.Extension;
5
+import hudson.Launcher;
6
+import hudson.model.AbstractBuild;
7
+import hudson.model.AbstractProject;
8
+import hudson.model.BuildListener;
9
+import hudson.model.Result;
10
+import hudson.tasks.BuildStepDescriptor;
11
+import hudson.tasks.BuildStepMonitor;
12
+import hudson.tasks.Publisher;
13
+import hudson.tasks.Recorder;
14
+import org.kohsuke.stapler.DataBoundConstructor;
15
+
16
+import java.io.IOException;
17
+
18
+/**
19
+ * After a successful build, this plugin deploys to Murano Environment via the
20
+ * Deployment Manager API.
21
+ */
22
+public class MuranoManagerDeployer extends Recorder {
23
+
24
+    @DataBoundConstructor
25
+    public MuranoManagerDeployer() {
26
+    }
27
+
28
+    /**
29
+     * {@inheritDoc}
30
+     */
31
+    @Override
32
+    public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener)
33
+            throws IOException, InterruptedException {
34
+        if (build.getResult() != Result.SUCCESS) {
35
+            return true;
36
+        }
37
+
38
+        try {
39
+            build.getEnvironment(listener);
40
+        } catch (IOException e) {
41
+            e.printStackTrace(listener.error(Messages.MuranoManagerDeployer_EnvironmentException()));
42
+            build.setResult(Result.FAILURE);
43
+            return false;
44
+        }
45
+
46
+        return true;
47
+    }
48
+
49
+    /**
50
+     * {@inheritDoc}
51
+     */
52
+    @Override
53
+    public BuildStepMonitor getRequiredMonitorService() {
54
+        return BuildStepMonitor.NONE;
55
+    }
56
+
57
+
58
+    @Extension
59
+    public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
60
+        /**
61
+         * {@inheritDoc}
62
+         */
63
+        @Override
64
+        public boolean isApplicable(Class<? extends AbstractProject> aClass) {
65
+            // Indicates that this builder can be used with all kinds of project types
66
+            return true;
67
+        }
68
+
69
+
70
+        /**
71
+         * {@inheritDoc}
72
+         */
73
+        @Override
74
+        public String getDisplayName() {
75
+            return Messages.MuranoManagerDeployer_DisplayName();
76
+        }
77
+    }
78
+
79
+    /**
80
+     * {@link BuildStepDetailsProvider} for the Cloud Manager Deployer.
81
+     */
82
+    @Extension
83
+    public static class DetailsProvider extends BuildStepDetailsProvider<MuranoManagerDeployer> {
84
+        /**
85
+         * {@inheritDoc}
86
+         */
87
+        @Override
88
+        public String getDetails(MuranoManagerDeployer deployer) {
89
+            return "MuranoManagerDeployer";
90
+        }
91
+    }
92
+}

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

@@ -0,0 +1,101 @@
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
+}

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

@@ -0,0 +1,60 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy;
2
+
3
+import hudson.Extension;
4
+import hudson.model.Descriptor;
5
+
6
+import hudson.util.FormValidation;
7
+import org.kohsuke.stapler.DataBoundConstructor;
8
+import org.kohsuke.stapler.QueryParameter;
9
+import org.openstack4j.api.exceptions.AuthenticationException;
10
+
11
+import javax.servlet.ServletException;
12
+import java.io.IOException;
13
+
14
+import static java.util.Objects.requireNonNull;
15
+
16
+public class TemplatedDeployment extends MuranoDeployment {
17
+
18
+    /**
19
+     * The specific Implemenation of <code>MuranoDeployment</code> that
20
+     * gets object model from the contructor parameter
21
+     * (the direct textarea on Jenkins form)
22
+     *
23
+     * @param objectModel Object model for Murano environment to be deployed
24
+     */
25
+    @DataBoundConstructor
26
+    public TemplatedDeployment(
27
+            String objectModel) {
28
+        super(requireNonNull(objectModel));
29
+    }
30
+
31
+    /**
32
+     * Denotes that this is a cloud deployment plugin.
33
+     */
34
+    @Extension
35
+    public static class DescriptorImpl extends AbstractMuranoDeploymentDescriptor {
36
+        public DescriptorImpl() {
37
+            this(TemplatedDeployment.class);
38
+        }
39
+
40
+        public DescriptorImpl(Class<? extends TemplatedDeployment> clazz) {
41
+            super(clazz);
42
+        }
43
+
44
+        /**
45
+         * {@inheritDoc}
46
+         */
47
+        @Override
48
+        public String getDisplayName() {
49
+            return Messages.TemplatedMuranoDeployment_DisplayName();
50
+        }
51
+
52
+        /**
53
+         * {@inheritDoc}
54
+         */
55
+        @Override
56
+        public boolean isApplicable(Descriptor descriptor) {
57
+            return true;
58
+        }
59
+    }
60
+}

+ 14
- 0
deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentials.java View File

@@ -0,0 +1,14 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy.credentials;
2
+
3
+
4
+import com.cloudbees.plugins.credentials.Credentials;
5
+import hudson.util.Secret;
6
+
7
+public interface OpenstackCredentials extends Credentials {
8
+    String getName();
9
+    String getDescription();
10
+    String getUsername();
11
+    Secret getPassword();
12
+    String getTenant();
13
+    String getIdentityServiceEndpoint();
14
+}

+ 109
- 0
deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsImpl.java View File

@@ -0,0 +1,109 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy.credentials;
2
+
3
+
4
+import com.cloudbees.plugins.credentials.CredentialsDescriptor;
5
+import com.cloudbees.plugins.credentials.NameWith;
6
+import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;
7
+import com.cloudbees.plugins.credentials.impl.Messages;
8
+import hudson.Extension;
9
+import hudson.util.FormValidation;
10
+import hudson.util.Secret;
11
+import org.kohsuke.stapler.DataBoundConstructor;
12
+import org.kohsuke.stapler.QueryParameter;
13
+import org.openstack.murano.jenkins_plugins.muranoci.deploy.MuranoHelper;
14
+import org.openstack4j.api.exceptions.AuthenticationException;
15
+
16
+import javax.servlet.ServletException;
17
+import java.io.IOException;
18
+
19
+import static java.util.Objects.requireNonNull;
20
+
21
+@NameWith(value = OpenstackCredentialsNameProvider.class, priority = 50)
22
+public class OpenstackCredentialsImpl extends BaseStandardCredentials implements OpenstackCredentials {
23
+    private final String name;
24
+
25
+    private final String identityServiceEndpoint;
26
+    private final String username;
27
+    private final Secret password;
28
+    private final String tenant;
29
+
30
+    @DataBoundConstructor
31
+    public OpenstackCredentialsImpl(
32
+            String id,
33
+            String name,
34
+            String description,
35
+            String identityServiceEndpoint,
36
+            String tenant,
37
+            String username,
38
+            String password) {
39
+        super(id, description);
40
+
41
+        this.name = name;
42
+        this.identityServiceEndpoint = identityServiceEndpoint;
43
+        this.username = username;
44
+        this.password = Secret.fromString(requireNonNull(password));
45
+        this.tenant = tenant;
46
+    }
47
+
48
+    public String getName() {
49
+        return this.name;
50
+    }
51
+
52
+    @Override
53
+    public String getUsername() {
54
+        return this.username;
55
+    }
56
+
57
+    @Override
58
+    public Secret getPassword() {
59
+        return this.password;
60
+    }
61
+
62
+    @Override
63
+    public String getTenant() {
64
+        return this.tenant;
65
+    }
66
+
67
+    @Override
68
+    public String getIdentityServiceEndpoint() {
69
+        return this.identityServiceEndpoint;
70
+    }
71
+
72
+    @Extension
73
+    public static class Descriptor
74
+            extends CredentialsDescriptor {
75
+
76
+        public FormValidation doTestConnection(@QueryParameter("identityServiceEndpoint") final String identityServiceEndpoint,
77
+                                               @QueryParameter("tenant") final String tenant,
78
+                                               @QueryParameter("username") final String username,
79
+                                               @QueryParameter("password") final String password)
80
+                throws IOException, ServletException {
81
+
82
+            MuranoHelper client = new MuranoHelper(
83
+                    identityServiceEndpoint,
84
+                    username,
85
+                    password,
86
+                    tenant);
87
+
88
+            try {
89
+                client.authenticate();
90
+            } catch (AuthenticationException ae) {
91
+                return FormValidation.error(
92
+                        "Unable to connect to server. Please check credentials");
93
+            } catch (Exception e) {
94
+                return FormValidation.error("Error: " + e.getMessage());
95
+            }
96
+
97
+            return FormValidation.ok("Success");
98
+        }
99
+
100
+        /**
101
+         * {@inheritDoc}
102
+         */
103
+        @Override
104
+        public String getDisplayName() {
105
+//            return Messages.CertificateCredentialsImpl_DisplayName();
106
+            return "Openstack Cloud";
107
+        }
108
+    }
109
+}

+ 12
- 0
deployment-manager/src/main/java/org/openstack/murano/jenkins_plugins/muranoci/deploy/credentials/OpenstackCredentialsNameProvider.java View File

@@ -0,0 +1,12 @@
1
+package org.openstack.murano.jenkins_plugins.muranoci.deploy.credentials;
2
+
3
+
4
+import com.cloudbees.plugins.credentials.CredentialsNameProvider;
5
+
6
+public class OpenstackCredentialsNameProvider extends CredentialsNameProvider<OpenstackCredentialsImpl> {
7
+
8
+    @Override
9
+    public String getName(OpenstackCredentialsImpl openstackCredentials) {
10
+        return openstackCredentials.getName();
11
+    }
12
+}

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

@@ -0,0 +1,26 @@
1
+MuranoDeployment.InvalidDeploySpec=Invalid deployment specification.
2
+MuranoDeployment.DeployComplete=Deployment complete!
3
+MuranoDeployment.InsertRollback=Failure deploying, attempting rollback.
4
+MuranoDeployment.RollbackSuccess=Rollback successful.
5
+MuranoDeployment.DeleteComplete=Deletion complete!
6
+MuranoDeployment.CreatedDeploy=Created new deployment: {0}
7
+MuranoDeployment.CreatedDeployVerbose=Created new deployment: {0} with spec: {1}
8
+MuranoDeployment.DeletedDeploy=Deleted deployment: {0}
9
+MuranoDeployment.CreateDeployException=Exception creating deployment
10
+MuranoDeployment.GetDeployException=Exception getting deployment
11
+MuranoDeployment.DeleteDeployException=Exception deleting deployment
12
+MuranoDeployment.WaitDeploy=Waiting for deployment...
13
+MuranoDeployment.WaitDelete=Waiting for deletion...
14
+MuranoDeployment.WaitTimeoutDeploy=Timed out waiting for deployment.
15
+MuranoDeployment.WaitTimeoutDelete=Timed out waiting for deletion.
16
+MuranoDeployment.DeployFailed=Deployment failed for: {0}
17
+MuranoDeployment.ExecutorExceptionWhileDeploying=Bad state: RPC execution exception while deploying.
18
+MuranoDeployment.IOExceptionWhileDeploying=IO exception while deploying.
19
+MuranoDeployment.LogInsert=Inserting deployment: {0}
20
+MuranoDeployment.LogDelete=Deleting deployment: {0}
21
+MuranoDeploymentDescriptor.BadComponent=Components must match: {0}
22
+MuranoDeploymentDescriptor.NotEmpty=Components cannot be empty
23
+MuranoDeploymentDescriptor.SampleResolution={0}\nSample variable resolution: {1}
24
+MuranoDeploymentModule.AppName=Jenkins Cloud Deployer
25
+MuranoDeploymentModule.ConnectionError=Exception connecting to Deployment Manager
26
+MuranoEnvironmentDeleter_DisplayName=Deployment Turndown

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

@@ -0,0 +1,6 @@
1
+MuranoManagerDeployer.DisplayName=Openstack Murano Deployer
2
+MuranoManagerDeployer.EnvironmentException=Exception accessing build environment
3
+MuranoManagerBuildWrapper.DisplayName=Murano Deployer
4
+BuildStepDetailsProvider.MavenName=Maven
5
+TemplatedMuranoDeployment.DisplayName=Deploy using ready-made template
6
+RepositoryTemplatedMuranoDeployment.DisplayName=Deploy using configuration from project repository

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

@@ -0,0 +1,21 @@
1
+<?jelly escape-by-default='true'?>
2
+<j:jelly xmlns:j="jelly:core"
3
+         xmlns:f="/lib/form"
4
+         xmlns:c="/lib/credentials">
5
+
6
+    <f:entry title="${%Openstack Credentials}" field="credentialsId">
7
+        <c:select/>
8
+    </f:entry>
9
+
10
+    <j:invokeStatic var="descriptors"
11
+                    method="getCompatibleDeployments"
12
+                    className="org.openstack.murano.jenkins_plugins.muranoci.deploy.MuranoDeployment">
13
+
14
+        <j:arg type="hudson.model.Descriptor" value="${descriptor}"/>
15
+
16
+    </j:invokeStatic>
17
+
18
+    <f:dropdownDescriptorSelector field="deployment"
19
+                                  title="${%Deployment Form}"
20
+                                  descriptors="${descriptors}"/>
21
+</j:jelly>

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

@@ -0,0 +1,17 @@
1
+<?jelly escape-by-default='true'?>
2
+<j:jelly xmlns:j="jelly:core"
3
+         xmlns:st="jelly:stapler"
4
+         xmlns:d="jelly:define"
5
+         xmlns:l="/lib/layout"
6
+         xmlns:t="/lib/hudson"
7
+         xmlns:f="/lib/form"
8
+         xmlns:a="/lib/auth">
9
+
10
+    <f:entry name="action" title="${%Action}" field="action">
11
+        <select name="action">
12
+            <option value="teardownAction">${%Tear Down}</option>
13
+            <option value="doNothingAction">${%Do Nothing}</option>
14
+        </select>
15
+    </f:entry>
16
+
17
+</j:jelly>

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

@@ -0,0 +1,14 @@
1
+<?jelly escape-by-default='true'?>
2
+<j:jelly xmlns:j="jelly:core"
3
+         xmlns:st="jelly:stapler"
4
+         xmlns:d="jelly:define"
5
+         xmlns:l="/lib/layout"
6
+         xmlns:t="/lib/hudson"
7
+         xmlns:f="/lib/form"
8
+         xmlns:a="/lib/auth">
9
+
10
+    <f:entry title="${%Environment name}" field="environment" >
11
+        <f:textbox />
12
+    </f:entry>
13
+
14
+</j:jelly>

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

@@ -0,0 +1,15 @@
1
+<?jelly escape-by-default='true'?>
2
+<j:jelly xmlns:j="jelly:core"
3
+         xmlns:st="jelly:stapler"
4
+         xmlns:d="jelly:define"
5
+         xmlns:l="/lib/layout"
6
+         xmlns:t="/lib/hudson"
7
+         xmlns:f="/lib/form"
8
+         xmlns:a="/lib/auth">
9
+
10
+    <f:entry title="${%Application Object Model}" field="objectModel">
11
+        <f:textarea>
12
+        </f:textarea>
13
+    </f:entry>
14
+
15
+</j:jelly>

+ 12
- 0
deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/deploy/TemplatedDeployment/global.jelly View File

@@ -0,0 +1,12 @@
1
+<?jelly escape-by-default='true'?>
2
+<j:jelly xmlns:j="jelly:core"
3
+         xmlns:st="jelly:stapler"
4
+         xmlns:d="jelly:define"
5
+         xmlns:l="/lib/layout"
6
+         xmlns:t="/lib/hudson"
7
+         xmlns:f="/lib/form"
8
+         xmlns:a="/lib/auth">
9
+
10
+
11
+
12
+</j:jelly>

+ 4
- 0
deployment-manager/src/main/resources/org/openstack/murano/jenkins_plugins/muranoci/index.jelly View File

@@ -0,0 +1,4 @@
1
+<?jelly escape-by-default='true'?>
2
+<div>
3
+    This plugin integrates Openstack Murano to Jenkins.
4
+</div>

Loading…
Cancel
Save