2 * ============LICENSE_START======================================================= ONAP : SO
3 * ================================================================================ Copyright (C) 2018 Nokia.
4 * ============================================================================= Licensed under the Apache License,
5 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 * specific language governing permissions and limitations under the License.
13 * ============LICENSE_END=========================================================
15 package org.onap.so.cloudify.beans;
17 import java.util.HashMap;
19 import org.onap.so.cloudify.v3.model.Execution;
21 public final class DeploymentInfoBuilder {
23 private String id = "";
24 private DeploymentStatus deploymentStatus = DeploymentStatus.NOTFOUND;
25 private Map<String, Object> deploymentOutputs = new HashMap<>();
26 private Map<String, Object> deploymentInputs = new HashMap<>();
27 private String lastAction;
28 private String actionStatus;
29 private String errorMessage;
31 public DeploymentInfoBuilder withId(String id) {
36 public DeploymentInfoBuilder withStatus(DeploymentStatus deploymentStatus) {
37 this.deploymentStatus = deploymentStatus;
41 public DeploymentInfoBuilder withDeploymentOutputs(Map<String, Object> deploymentOutputs) {
42 if (deploymentOutputs != null) {
43 this.deploymentOutputs = deploymentOutputs;
48 public DeploymentInfoBuilder withDeploymentInputs(Map<String, Object> deploymentInputs) {
49 this.deploymentInputs = deploymentInputs;
53 public DeploymentInfoBuilder withLastAction(String lastAction) {
54 this.lastAction = lastAction;
58 public DeploymentInfoBuilder withActionStatus(String actionStatus) {
59 this.actionStatus = actionStatus;
63 public DeploymentInfoBuilder withErrorMessage(String errorMessage) {
64 this.errorMessage = errorMessage;
68 public DeploymentInfoBuilder fromExecution(Execution execution) {
69 if (execution != null) {
70 this.lastAction = execution.getWorkflowId();
71 this.actionStatus = execution.getStatus();
72 this.errorMessage = execution.getError();
74 // Compute the status based on the last workflow
75 if (lastAction.equals("install")) {
76 if (actionStatus.equals("terminated")) {
77 this.deploymentStatus = DeploymentStatus.INSTALLED;
78 } else if (actionStatus.equals("failed")) {
79 this.deploymentStatus = DeploymentStatus.FAILED;
80 } else if (actionStatus.equals("started") || actionStatus.equals("pending")) {
81 this.deploymentStatus = DeploymentStatus.INSTALLING;
83 this.deploymentStatus = DeploymentStatus.UNKNOWN;
85 } else if (lastAction.equals("uninstall")) {
86 if (actionStatus.equals("terminated")) {
87 this.deploymentStatus = DeploymentStatus.CREATED;
88 } else if (actionStatus.equals("failed")) {
89 this.deploymentStatus = DeploymentStatus.FAILED;
90 } else if (actionStatus.equals("started") || actionStatus.equals("pending")) {
91 this.deploymentStatus = DeploymentStatus.UNINSTALLING;
93 this.deploymentStatus = DeploymentStatus.UNKNOWN;
96 // Could have more cases in the future for different actions.
97 this.deploymentStatus = DeploymentStatus.UNKNOWN;
100 this.deploymentStatus = DeploymentStatus.CREATED;
106 public DeploymentInfo build() {
107 return new DeploymentInfo(id, deploymentStatus, deploymentOutputs, deploymentInputs, lastAction, actionStatus,