AT&T 1712 and 1802 release code
[so.git] / cloudify-client / src / main / java / org / openecomp / mso / cloudify / v3 / model / Deployment.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.cloudify.v3.model;
22
23 import java.io.IOException;
24 import java.io.Serializable;
25 import java.util.Date;
26 import java.util.List;
27 import java.util.Map;
28
29 import com.fasterxml.jackson.annotation.JsonIgnore;
30 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
31 import com.fasterxml.jackson.annotation.JsonProperty;
32 import com.fasterxml.jackson.databind.ObjectMapper;
33
34 @JsonIgnoreProperties(ignoreUnknown = true)
35 //@JsonRootName("deployment")
36 public class Deployment implements Serializable {
37
38         private static final long serialVersionUID = 1L;
39         
40     @JsonProperty("blueprint_id")
41     private String blueprintId;
42
43     @JsonProperty("created_at")
44     private Date createdAt;
45
46     @JsonProperty("created_by")
47     private String createdBy;
48
49     @JsonProperty("description")
50     private String description;
51
52     @JsonProperty("groups")
53     private Map<String, Group> groups = null;
54     
55     @JsonProperty("id")
56     private String id;
57     
58     @JsonProperty("inputs")
59     private Map<String, Object> inputs = null;
60     
61     // TODO: Expand the definition of a PolicyTrigger
62     @JsonProperty("policy_triggers")
63     private List<Object> policyTriggers;
64
65     // TODO: Expand the definition of a PolicyType
66     @JsonProperty("policy_types")
67     private List<Object> policyTypes;
68
69     @JsonProperty("scaling_groups")
70     private Map<String, ScalingGroup> scalingGroups = null;
71     
72     @JsonProperty("tenant_name")
73     private String tenantName;
74
75     @JsonProperty("updated_at")
76     private Date updatedAt;
77
78     @JsonProperty("workflows")
79     private List<Workflow> workflows;
80
81     // ObjectMapper instance to parse Json object outputs
82     @JsonIgnore
83         private static ObjectMapper mapper = new ObjectMapper();
84
85     public String getBlueprintId() {
86         return blueprintId;
87     }
88
89     public void setBlueprintId(String blueprintId) {
90         this.blueprintId = blueprintId;
91     }
92    
93     public Date getCreatedAt() {
94         return createdAt;
95     }
96
97     public void setCreatedAt(Date createdAt) {
98         this.createdAt = createdAt;
99     }
100
101     public String getCreatedBy() {
102         return createdBy;
103     }
104
105     public void setCreatedBy(String createdBy) {
106         this.createdBy = createdBy;
107     }
108
109     public String getDescription() {
110         return description;
111     }
112
113     public void setDescription(String description) {
114         this.description = description;
115     }
116     
117     public Map<String, Group> getGroups() {
118         return this.groups;
119     }
120     
121     public void setGroups(Map<String, Group> groups) {
122         this.groups = groups;
123     }
124
125     public String getId() {
126         return id;
127     }
128
129     public void setId(String id) {
130         this.id = id;
131     }
132
133     public Map<String, Object> getInputs() {
134         return this.inputs;
135     }
136     public void setInputs(Map<String, Object> inputs) {
137         this.inputs = inputs;
138     }
139
140     public String getTenantName() {
141         return tenantName;
142     }
143
144     public void setTenantName(String tenantName) {
145         this.tenantName = tenantName;
146     }
147
148     public Map<String, ScalingGroup> getScalingGroups() {
149                 return scalingGroups;
150         }
151
152         public void setScalingGroups(Map<String, ScalingGroup> scalingGroups) {
153                 this.scalingGroups = scalingGroups;
154         }
155
156         public Date getUpdatedAt() {
157         return updatedAt;
158     }
159
160     public void setUpdatedAt(Date updatedAt) {
161         this.updatedAt = updatedAt;
162     }
163
164     public List<Workflow> getWorkflows() {
165         return workflows;
166     }
167
168     public void setWorkflows(List<Workflow> workflows) {
169         this.workflows = workflows;
170     }
171
172     /*
173      * Nested subclasses for Group definitions
174      */
175     public static final class Group {
176         @JsonProperty ("policies")
177         Object policies;
178         
179         @JsonProperty("members")
180         List<String> members;
181
182                 public Object getPolicies() {
183                         return policies;
184                 }
185
186                 public void setPolicies(Object policies) {
187                         this.policies = policies;
188                 }
189
190                 public List<String> getMembers() {
191                         return members;
192                 }
193
194                 public void setMembers(List<String> members) {
195                         this.members = members;
196                 }
197     }
198
199     /*
200      * Nested subclasses for Scaling Group definitions
201      */
202     public static final class ScalingGroup {
203         @JsonProperty ("properties")
204         ScalingGroupProperties properties;
205         
206         @JsonProperty("members")
207         List<String> members;
208
209                 public ScalingGroupProperties getProperties() {
210                         return properties;
211                 }
212
213                 public void setProperties(ScalingGroupProperties properties) {
214                         this.properties = properties;
215                 }
216
217                 public List<String> getMembers() {
218                         return members;
219                 }
220
221                 public void setMembers(List<String> members) {
222                         this.members = members;
223                 }
224     }
225
226     public static final class ScalingGroupProperties {
227         @JsonProperty("current_instances")
228         int currentInstances;
229         
230         @JsonProperty("default_instances")
231         int defaultInstances;
232         
233         @JsonProperty("max_instances")
234         int maxInstances;
235         
236         @JsonProperty("min_instances")
237         int minInstances;
238         
239         @JsonProperty("planned_instances")
240         int plannedInstances;
241
242                 public int getCurrentInstances() {
243                         return currentInstances;
244                 }
245
246                 public void setCurrentInstances(int currentInstances) {
247                         this.currentInstances = currentInstances;
248                 }
249
250                 public int getDefaultInstances() {
251                         return defaultInstances;
252                 }
253
254                 public void setDefaultInstances(int defaultInstances) {
255                         this.defaultInstances = defaultInstances;
256                 }
257
258                 public int getMaxInstances() {
259                         return maxInstances;
260                 }
261
262                 public void setMaxInstances(int maxInstances) {
263                         this.maxInstances = maxInstances;
264                 }
265
266                 public int getMinInstances() {
267                         return minInstances;
268                 }
269
270                 public void setMinInstances(int minInstances) {
271                         this.minInstances = minInstances;
272                 }
273
274                 public int getPlannedInstances() {
275                         return plannedInstances;
276                 }
277
278                 public void setPlannedInstances(int plannedInstances) {
279                         this.plannedInstances = plannedInstances;
280                 }
281     }
282     
283     /*
284      * Nested subclass for Deployment Workflow entities.
285      * Note that Blueprint class also contains a slightly different Workflow structure.
286      */
287     public static final class Workflow {
288         @JsonProperty("name")
289         private String name;
290         @JsonProperty("created_at")
291         private Date createdAt;
292         @JsonProperty("parameters")
293         private Map<String,ParameterDefinition> parameters;
294         
295         public Workflow() {}
296         
297                 public String getName() {
298                         return name;
299                 }
300                 public void setName(String name) {
301                         this.name = name;
302                 }
303                 public Date getCreatedAt() {
304                         return createdAt;
305                 }
306                 public void setCreatedAt(Date createdAt) {
307                         this.createdAt = createdAt;
308                 }
309                 public Map<String, ParameterDefinition> getParameters() {
310                         return parameters;
311                 }
312                 public void setParameters(Map<String, ParameterDefinition> parameters) {
313                         this.parameters = parameters;
314                 }
315     }
316     
317         /*
318          * Return an  output as a Json-mapped Object of the provided type.
319          * This is useful for json-object outputs.
320          */
321         public <T> T getMapValue (Map<String,Object> map, String key, Class<T> type)
322         {
323                 if (map.containsKey(key)) {
324                         try {
325                                 String s = mapper.writeValueAsString(map.get(key));
326                                 return (mapper.readValue(s, type));
327                         }
328                         catch (IOException e) {
329                                 return null;
330                         }
331                 }
332                 return null;
333         }
334
335         @Override
336     public String toString() {
337         return "Deployment{" +
338                 "id='" + id + '\'' +
339                 ", description='" + description + '\'' +
340                 ", blueprintId='" + blueprintId + '\'' +
341                 ", createdBy='" + createdBy + '\'' +
342                 ", tenantName='" + tenantName + '\'' +
343                 ", createdAt=" + createdAt +
344                 ", updatedAt=" + updatedAt +
345                 ", inputs='" + inputs + '\'' +
346                 ", workflows=" + workflows +
347                 ", groups=" + groups +
348                 '}';
349     }
350
351 }