2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia.
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=========================================================
20 package org.onap.so.cloudify.beans;
22 import java.util.HashMap;
24 import org.onap.so.cloudify.v3.model.Execution;
26 public final class DeploymentInfoBuilder {
28 private String id = "";
29 private DeploymentStatus deploymentStatus = DeploymentStatus.NOTFOUND;
30 private Map<String, Object> deploymentOutputs = new HashMap<>();
31 private Map<String, Object> deploymentInputs = new HashMap<>();
32 private String lastAction;
33 private String actionStatus;
34 private String errorMessage;
36 public DeploymentInfoBuilder withId(String id) {
41 public DeploymentInfoBuilder withStatus(DeploymentStatus deploymentStatus) {
42 this.deploymentStatus = deploymentStatus;
46 public DeploymentInfoBuilder withDeploymentOutputs(Map<String, Object> deploymentOutputs) {
47 if (deploymentOutputs != null) {
48 this.deploymentOutputs = deploymentOutputs;
53 public DeploymentInfoBuilder withDeploymentInputs(Map<String, Object> deploymentInputs) {
54 this.deploymentInputs = deploymentInputs;
58 public DeploymentInfoBuilder withLastAction(String lastAction) {
59 this.lastAction = lastAction;
63 public DeploymentInfoBuilder withActionStatus(String actionStatus) {
64 this.actionStatus = actionStatus;
68 public DeploymentInfoBuilder withErrorMessage(String errorMessage) {
69 this.errorMessage = errorMessage;
73 public DeploymentInfoBuilder fromExecution(Execution execution) {
74 if (execution != null) {
75 this.lastAction = execution.getWorkflowId();
76 this.actionStatus = execution.getStatus();
77 this.errorMessage = execution.getError();
79 // Compute the status based on the last workflow
80 if (lastAction.equals("install")) {
81 if (actionStatus.equals("terminated")) {
82 this.deploymentStatus = DeploymentStatus.INSTALLED;
83 } else if (actionStatus.equals("failed")) {
84 this.deploymentStatus = DeploymentStatus.FAILED;
85 } else if (actionStatus.equals("started") || actionStatus.equals("pending")) {
86 this.deploymentStatus = DeploymentStatus.INSTALLING;
88 this.deploymentStatus = DeploymentStatus.UNKNOWN;
90 } else if (lastAction.equals("uninstall")) {
91 if (actionStatus.equals("terminated")) {
92 this.deploymentStatus = DeploymentStatus.CREATED;
93 } else if (actionStatus.equals("failed")) {
94 this.deploymentStatus = DeploymentStatus.FAILED;
95 } else if (actionStatus.equals("started") || actionStatus.equals("pending")) {
96 this.deploymentStatus = DeploymentStatus.UNINSTALLING;
98 this.deploymentStatus = DeploymentStatus.UNKNOWN;
101 // Could have more cases in the future for different actions.
102 this.deploymentStatus = DeploymentStatus.UNKNOWN;
105 this.deploymentStatus = DeploymentStatus.CREATED;
111 public DeploymentInfo build() {
112 return new DeploymentInfo(id,