AT&T 1712 and 1802 release code
[so.git] / adapters / mso-adapter-utils / src / main / java / org / openecomp / mso / cloudify / beans / DeploymentInfo.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.beans;
22
23 import java.util.Map;
24 import java.util.HashMap;
25
26 import org.openecomp.mso.cloudify.v3.model.Deployment;
27 import org.openecomp.mso.cloudify.v3.model.DeploymentOutputs;
28 import org.openecomp.mso.cloudify.v3.model.Execution;
29
30 /*
31  * This Java bean class relays Heat stack status information to ActiveVOS processes.
32  * 
33  * This bean is returned by all Heat-specific adapter operations (create, query, delete)
34  */
35
36 public class DeploymentInfo {
37         // Set defaults for everything
38         private String id = "";
39         private DeploymentStatus status = DeploymentStatus.NOTFOUND;
40         private Map<String,Object> outputs = new HashMap<String,Object>();
41         private Map<String,Object> inputs = new HashMap<String,Object>();
42         private String lastAction;
43         private String actionStatus;
44         private String errorMessage;
45         
46         public DeploymentInfo () {
47         }
48         
49         public DeploymentInfo (String id, Map<String,Object> outputs) {
50                 this.id = id;
51                 if (outputs != null)  this.outputs = outputs;
52         }
53         
54         public DeploymentInfo (String id) {
55                 this.id = id;
56         }
57         
58         public DeploymentInfo (String id, DeploymentStatus status) {
59                 this.id = id;
60                 this.status = status;
61         }
62
63         public DeploymentInfo (Deployment deployment) {
64                 this(deployment, null, null);
65         }
66
67         /**
68          * Construct a DeploymentInfo object from a deployment and the latest Execution action
69          * @param deployment
70          * @param execution
71          */
72         public DeploymentInfo (Deployment deployment, DeploymentOutputs outputs, Execution execution)
73         {
74                 if (deployment == null) {
75                         this.id = null;
76                         return;
77                 }
78         
79                 this.id = deployment.getId();
80
81                 if (outputs != null)
82                         this.outputs = outputs.getOutputs();
83                 
84                 if (deployment.getInputs() != null)
85                         this.inputs = deployment.getInputs();
86                 
87                 if (execution != null) {
88                         this.lastAction = execution.getWorkflowId();
89                         this.actionStatus = execution.getStatus();
90                         this.errorMessage = execution.getError();
91                         
92                         // Compute the status based on the last workflow
93                         if (lastAction.equals("install")) {
94                                 if (actionStatus.equals("terminated"))
95                                         this.status = DeploymentStatus.INSTALLED;
96                                 else if (actionStatus.equals("failed"))
97                                         this.status = DeploymentStatus.FAILED;
98                                 else if (actionStatus.equals("started") || actionStatus.equals("pending"))
99                                         this.status = DeploymentStatus.INSTALLING;
100                                 else
101                                         this.status = DeploymentStatus.UNKNOWN;
102                         }
103                         else if (lastAction.equals("uninstall")) {
104                                 if (actionStatus.equals("terminated"))
105                                         this.status = DeploymentStatus.CREATED;
106                                 else if (actionStatus.equals("failed"))
107                                         this.status = DeploymentStatus.FAILED;
108                                 else if (actionStatus.equals("started") || actionStatus.equals("pending"))
109                                         this.status = DeploymentStatus.UNINSTALLING;
110                                 else
111                                         this.status = DeploymentStatus.UNKNOWN;
112                         }
113                         else {
114                                 // Could have more cases in the future for different actions.
115                                 this.status = DeploymentStatus.UNKNOWN;
116                         }
117                 }
118                 else {
119                         this.status = DeploymentStatus.CREATED;
120                 }
121         }
122         
123         public String getId() {
124                 return id;
125         }
126         
127         public void setId (String id) {
128                 this.id = id;
129         }
130         
131         public DeploymentStatus getStatus() {
132                 return status;
133         }
134         
135         public void setStatus (DeploymentStatus status) {
136                 this.status = status;
137         }
138         
139         public Map<String,Object> getOutputs () {
140                 return outputs;
141         }
142         
143         public void setOutputs (Map<String,Object> outputs) {
144                 this.outputs = outputs;
145         }
146         
147         public Map<String,Object> getInputs () {
148                 return inputs;
149         }
150         
151         public void setInputs (Map<String,Object> inputs) {
152                 this.inputs = inputs;
153         }
154
155         public String getLastAction() {
156                 return lastAction;
157         }
158
159         public String getActionStatus() {
160                 return actionStatus;
161         }
162
163         public String getErrorMessage() {
164                 return errorMessage;
165         }
166
167         public void saveExecutionStatus (Execution execution) {
168                 this.lastAction = execution.getWorkflowId();
169                 this.actionStatus = execution.getStatus();
170                 this.errorMessage = execution.getError();
171         }
172         
173         @Override
174     public String toString() {
175         return "DeploymentInfo {" +
176                 "id='" + id + '\'' +
177                 ", inputs='" + inputs + '\'' +
178                 ", outputs='" + outputs + '\'' +
179                 ", lastAction='" + lastAction + '\'' +
180                 ", status='" + status + '\'' +
181                 ", errorMessage='" + errorMessage + '\'' +
182                 '}';
183     }
184
185 }
186