Initial OpenECOMP MSO commit
[so.git] / adapters / mso-adapter-utils / src / main / java / org / openecomp / mso / openstack / beans / StackInfo.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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
24 import java.util.Map;
25 import java.util.HashMap;
26
27 import com.woorea.openstack.heat.model.Stack;
28
29 /*
30  * This Java bean class relays Heat stack status information to ActiveVOS processes.
31  * 
32  * This bean is returned by all Heat-specific adapter operations (create, query, delete)
33  */
34
35 public class StackInfo {
36         // Set defaults for everything
37         private String name = "";
38         private String canonicalName = "";
39         private HeatStatus status = HeatStatus.UNKNOWN;
40         private String statusMessage = "";
41         private Map<String,Object> outputs = new HashMap<String,Object>();
42         private Map<String,Object> parameters = new HashMap<String,Object>();
43         
44         static Map<String,HeatStatus> HeatStatusMap;
45         static {
46                 HeatStatusMap = new HashMap<String,HeatStatus>();
47                 HeatStatusMap.put("CREATE_IN_PROGRESS", HeatStatus.BUILDING);
48                 HeatStatusMap.put("CREATE_COMPLETE", HeatStatus.CREATED);
49                 HeatStatusMap.put("CREATE_FAILED", HeatStatus.FAILED);
50                 HeatStatusMap.put("DELETE_IN_PROGRESS", HeatStatus.DELETING);
51                 HeatStatusMap.put("DELETE_COMPLETE", HeatStatus.NOTFOUND);
52                 HeatStatusMap.put("DELETE_FAILED", HeatStatus.FAILED);
53                 HeatStatusMap.put("UPDATE_IN_PROGRESS", HeatStatus.UPDATING);
54                 HeatStatusMap.put("UPDATE_FAILED", HeatStatus.FAILED);
55                 HeatStatusMap.put("UPDATE_COMPLETE", HeatStatus.UPDATED);
56         }
57
58         public StackInfo () {
59         }
60         
61         public StackInfo (String name, HeatStatus status, String statusMessage, Map<String,Object> outputs) {
62                 this.name = name;
63                 this.canonicalName = name;      // Don't have an ID, so just use name
64
65                 this.status = status;
66                 if (statusMessage != null)  this.statusMessage = statusMessage;
67                 if (outputs != null)  this.outputs = outputs;
68         }
69         
70         public StackInfo (String name, HeatStatus status) {
71                 this.name = name;
72                 this.canonicalName = name;      // Don't have an ID, so just use name
73                 this.status = status;
74         }
75         
76         public StackInfo (Stack stack)
77         {
78                 if (stack == null) {
79                         this.status = HeatStatus.NOTFOUND;
80                         return;
81                 }
82         
83                 this.name = stack.getStackName();
84                 this.canonicalName = stack.getStackName() + "/" + stack.getId();
85
86                 if (stack.getStackStatus() == null) {
87                         this.status = HeatStatus.INIT;
88                 } else if (HeatStatusMap.containsKey(stack.getStackStatus())) {
89                         this.status = HeatStatusMap.get(stack.getStackStatus());
90                 } else {
91                         this.status = HeatStatus.UNKNOWN;
92                 }
93                 
94                 this.statusMessage = stack.getStackStatusReason();
95                 
96                 if (stack.getOutputs() != null) {
97                         this.outputs = new HashMap<String,Object>();
98                         for (Stack.Output output : stack.getOutputs()) {
99                                 this.outputs.put(output.getOutputKey(), output.getOutputValue());
100                         }
101                 }
102                 
103                 this.parameters = stack.getParameters();
104         }
105         
106         public String getName() {
107                 return name;
108         }
109         
110         public void setName (String name) {
111                 this.name = name;
112         }
113         
114         public String getCanonicalName() {
115                 return canonicalName;
116         }
117         
118         public void setCanonicalName (String name) {
119                 this.canonicalName = name;
120         }
121         
122         public HeatStatus getStatus() {
123                 return status;
124         }
125         
126         public void setStatus (HeatStatus status) {
127                 this.status = status;
128         }
129         
130         public String getStatusMessage() {
131                 return statusMessage;
132         }
133         
134         public void setStatusMessage (String statusMessage) {
135                 this.statusMessage = statusMessage;
136         }
137         
138         public Map<String,Object> getOutputs () {
139                 return outputs;
140         }
141         
142         public void setOutputs (Map<String,Object> outputs) {
143                 this.outputs = outputs;
144         }
145         
146         public Map<String,Object> getParameters () {
147                 return parameters;
148         }
149         
150         public void setParameters (Map<String,Object> parameters) {
151                 this.parameters = parameters;
152         }
153         
154 }
155