2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.cloudify.beans;
24 import java.util.HashMap;
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;
31 * This Java bean class relays Heat stack status information to ActiveVOS processes.
33 * This bean is returned by all Heat-specific adapter operations (create, query, delete)
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;
46 public DeploymentInfo () {
49 public DeploymentInfo (String id, Map<String,Object> outputs) {
51 if (outputs != null) this.outputs = outputs;
54 public DeploymentInfo (String id) {
58 public DeploymentInfo (String id, DeploymentStatus status) {
63 public DeploymentInfo (Deployment deployment) {
64 this(deployment, null, null);
68 * Construct a DeploymentInfo object from a deployment and the latest Execution action
72 public DeploymentInfo (Deployment deployment, DeploymentOutputs outputs, Execution execution)
74 if (deployment == null) {
79 this.id = deployment.getId();
82 this.outputs = outputs.getOutputs();
84 if (deployment.getInputs() != null)
85 this.inputs = deployment.getInputs();
87 if (execution != null) {
88 this.lastAction = execution.getWorkflowId();
89 this.actionStatus = execution.getStatus();
90 this.errorMessage = execution.getError();
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;
101 this.status = DeploymentStatus.UNKNOWN;
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;
111 this.status = DeploymentStatus.UNKNOWN;
114 // Could have more cases in the future for different actions.
115 this.status = DeploymentStatus.UNKNOWN;
119 this.status = DeploymentStatus.CREATED;
123 public String getId() {
127 public void setId (String id) {
131 public DeploymentStatus getStatus() {
135 public void setStatus (DeploymentStatus status) {
136 this.status = status;
139 public Map<String,Object> getOutputs () {
143 public void setOutputs (Map<String,Object> outputs) {
144 this.outputs = outputs;
147 public Map<String,Object> getInputs () {
151 public void setInputs (Map<String,Object> inputs) {
152 this.inputs = inputs;
155 public String getLastAction() {
159 public String getActionStatus() {
163 public String getErrorMessage() {
167 public void saveExecutionStatus (Execution execution) {
168 this.lastAction = execution.getWorkflowId();
169 this.actionStatus = execution.getStatus();
170 this.errorMessage = execution.getError();
174 public String toString() {
175 return "DeploymentInfo {" +
177 ", inputs='" + inputs + '\'' +
178 ", outputs='" + outputs + '\'' +
179 ", lastAction='" + lastAction + '\'' +
180 ", status='" + status + '\'' +
181 ", errorMessage='" + errorMessage + '\'' +