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.onap.so.openstack.mappers;
23 import java.util.HashMap;
24 import java.util.List;
26 import java.util.Optional;
27 import org.onap.so.openstack.beans.HeatStatus;
28 import org.onap.so.openstack.beans.StackInfo;
29 import com.woorea.openstack.heat.model.Stack;
30 import com.woorea.openstack.heat.model.Stack.Output;
32 public class StackInfoMapper {
34 private final Stack stack;
35 private final Map<String, HeatStatus> heatStatusMap = new HashMap<>();
37 public StackInfoMapper(Stack stack) {
39 configureHeatStatusMap();
42 public StackInfo map() {
43 final StackInfo info = new StackInfo();
45 info.setStatus(HeatStatus.NOTFOUND);
47 info.setName(stack.getStackName());
48 info.setCanonicalName(stack.getStackName() + "/" + stack.getId());
49 info.setStatus(this.mapStatus(stack.getStackStatus()));
51 info.setStatusMessage(stack.getStackStatusReason());
53 Optional<Map<String, Object>> result = this.mapOutputToMap(stack.getOutputs());
54 if (result.isPresent()) {
55 info.setOutputs(result.get());
58 info.setParameters(stack.getParameters());
64 protected HeatStatus mapStatus(String status) {
65 final HeatStatus result;
67 result = HeatStatus.INIT;
69 result = heatStatusMap.getOrDefault(status, HeatStatus.UNKNOWN);
75 protected Optional<Map<String, Object>> mapOutputToMap(List<Output> outputs) {
76 Optional<Map<String, Object>> result = Optional.empty();
77 if (outputs != null) {
78 final HashMap<String, Object> map = new HashMap<>();
79 for (Output output : outputs) {
80 map.put(output.getOutputKey(), output.getOutputValue());
82 result = Optional.of(map);
88 private void configureHeatStatusMap() {
89 heatStatusMap.put("CREATE_IN_PROGRESS", HeatStatus.BUILDING);
90 heatStatusMap.put("CREATE_COMPLETE", HeatStatus.CREATED);
91 heatStatusMap.put("CREATE_FAILED", HeatStatus.FAILED);
92 heatStatusMap.put("DELETE_IN_PROGRESS", HeatStatus.DELETING);
93 heatStatusMap.put("DELETE_COMPLETE", HeatStatus.NOTFOUND);
94 heatStatusMap.put("DELETE_FAILED", HeatStatus.FAILED);
95 heatStatusMap.put("UPDATE_IN_PROGRESS", HeatStatus.UPDATING);
96 heatStatusMap.put("UPDATE_FAILED", HeatStatus.FAILED);
97 heatStatusMap.put("UPDATE_COMPLETE", HeatStatus.UPDATED);