Merge "Change the copyright to 2018"
[so.git] / adapters / mso-adapter-utils / src / main / java / org / openecomp / mso / openstack / beans / StackInfo.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.openstack.beans;
22
23 import com.woorea.openstack.heat.model.Stack;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 /*
28  * This Java bean class relays Heat stack status information to ActiveVOS processes.
29  *
30  * This bean is returned by all Heat-specific adapter operations (create, query, delete)
31  */
32 public class StackInfo {
33         private String name = "";
34         private String canonicalName = "";
35         private HeatStatus status;
36         private Map<String, Object> outputs = new HashMap<>();
37         private Map<String,Object> parameters = new HashMap<>();
38         static private Map<String, HeatStatus> heatStatusMap;
39
40         static {
41                 heatStatusMap = new HashMap<>();
42                 heatStatusMap.put("CREATE_IN_PROGRESS", HeatStatus.BUILDING);
43                 heatStatusMap.put("CREATE_COMPLETE", HeatStatus.CREATED);
44                 heatStatusMap.put("CREATE_FAILED", HeatStatus.FAILED);
45                 heatStatusMap.put("DELETE_IN_PROGRESS", HeatStatus.DELETING);
46                 heatStatusMap.put("DELETE_COMPLETE", HeatStatus.NOTFOUND);
47                 heatStatusMap.put("DELETE_FAILED", HeatStatus.FAILED);
48                 heatStatusMap.put("UPDATE_IN_PROGRESS", HeatStatus.UPDATING);
49                 heatStatusMap.put("UPDATE_FAILED", HeatStatus.FAILED);
50                 heatStatusMap.put("UPDATE_COMPLETE", HeatStatus.UPDATED);
51         }
52
53         public StackInfo (String name, HeatStatus status) {
54                 this.name = name;
55                 this.canonicalName = name;      // Don't have an ID, so just use name
56                 this.status = status;
57         }
58
59         public StackInfo (Stack stack)
60         {
61                 if (stack == null) {
62                         this.status = HeatStatus.NOTFOUND;
63                         return;
64                 }
65                 this.name = stack.getStackName();
66                 this.canonicalName = stack.getStackName() + "/" + stack.getId();
67
68                 if (stack.getStackStatus() == null) {
69                         this.status = HeatStatus.INIT;
70                 } else {
71                         this.status = heatStatusMap.getOrDefault(stack.getStackStatus(), HeatStatus.UNKNOWN);
72                 }
73                 if (stack.getOutputs() != null) {
74                         this.outputs = new HashMap<>();
75                         stack.getOutputs().forEach(output -> outputs.put(output.getOutputKey(), output.getOutputValue()));
76                 }
77
78                 this.parameters = stack.getParameters();
79         }
80
81         public String getName() {
82                 return name;
83         }
84
85         public void setName (String name) {
86                 this.name = name;
87         }
88
89         public String getCanonicalName() {
90                 return canonicalName;
91         }
92
93         public HeatStatus getStatus() {
94                 return status;
95         }
96
97         public Map<String, Object> getOutputs() {
98                 return outputs;
99         }
100
101         public Map<String,Object> getParameters () {
102                 return parameters;
103         }
104
105 }
106