2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 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.vid.model.serviceInstantiation;
23 import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
25 import com.fasterxml.jackson.annotation.JsonIgnore;
26 import com.fasterxml.jackson.annotation.JsonInclude;
27 import com.fasterxml.jackson.annotation.JsonProperty;
28 import com.google.common.collect.ImmutableMap;
29 import java.util.Collection;
30 import java.util.Collections;
31 import java.util.List;
33 import org.apache.commons.lang3.StringUtils;
34 import org.onap.vid.job.JobAdapter;
35 import org.onap.vid.job.JobType;
36 import org.onap.vid.model.Action;
37 import org.onap.vid.mso.model.ModelInfo;
39 public abstract class BaseResource implements JobAdapter.AsyncJobRequest {
41 protected String instanceId;
43 protected ModelInfo modelInfo;
45 protected String instanceName;
47 protected Action action;
49 protected String lcpCloudRegionId;
51 protected String tenantId;
53 protected List<Map<String, String>> instanceParams;
55 protected boolean rollbackOnFailure;
57 protected String trackById;
59 protected Boolean isFailed;
61 protected String statusMessage;
63 protected Integer position;
65 @JsonInclude(NON_NULL)
66 protected String originalName; //not used at backend, but stored for fronted
69 private static final Map<String, Action> actionStingToEnumMap = ImmutableMap.<String, Action>builder()
70 .put("Delete", Action.Delete)
71 .put("Create", Action.Create)
72 .put("None", Action.None)
73 .put("Update_Delete", Action.Delete)
74 .put("None_Delete", Action.Delete)
75 .put("Resume", Action.Resume)
76 .put("Upgrade", Action.Upgrade)
77 .put("None_Upgrade", Action.Upgrade)
81 protected BaseResource(@JsonProperty("modelInfo") ModelInfo modelInfo,
82 @JsonProperty("instanceName") String instanceName,
83 @JsonProperty("action") String action,
84 @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId,
85 @JsonProperty("legacyRegion") String legacyRegion,
86 @JsonProperty("tenantId") String tenantId,
87 @JsonProperty("instanceParams") List<Map<String, String>> instanceParams,
88 @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure,
89 @JsonProperty("instanceId") String instanceId,
90 @JsonProperty("trackById") String trackById,
91 @JsonProperty("isFailed") Boolean isFailed,
92 @JsonProperty("statusMessage") String statusMessage,
93 @JsonProperty("position") Integer position,
94 @JsonProperty("originalName") String originalName) {
95 this.modelInfo = modelInfo;
96 this.modelInfo.setModelType(getModelType());
97 this.rollbackOnFailure = rollbackOnFailure;
98 this.instanceName = StringUtils.defaultString(instanceName, "");
99 this.action = actionStringToEnum(action);
100 this.lcpCloudRegionId = StringUtils.isNotEmpty(legacyRegion) ? legacyRegion : lcpCloudRegionId;
101 this.tenantId = tenantId;
102 this.instanceParams = instanceParams;
103 this.instanceId = instanceId;
104 this.trackById = trackById;
105 this.isFailed = isFailed!= null ? isFailed: false;
106 this.statusMessage = statusMessage;
107 this.position = position;
108 this.originalName = originalName;
111 private Action actionStringToEnum(String actionAsString) {
112 return actionStingToEnumMap.get(actionAsString);
115 public ModelInfo getModelInfo() {
119 public String getInstanceName() {
123 public Action getAction() {
124 return (action == null ? Action.Create : action);
127 public String getLcpCloudRegionId() {
128 return lcpCloudRegionId;
131 public String getTenantId() {
135 public List<Map<String, String>> getInstanceParams() {
136 return instanceParams == null ? Collections.emptyList() : instanceParams;
139 public boolean isRollbackOnFailure() { return rollbackOnFailure; }
141 public String getInstanceId() {
145 protected abstract String getModelType();
147 public String getTrackById() {
151 public void setTrackById(String trackById) {
152 this.trackById = trackById;
155 public Boolean getIsFailed() {
159 public void setIsFailed(Boolean isFailed) {
160 this.isFailed = isFailed;
163 public void setInstanceId(String instanceId) {
164 this.instanceId = instanceId;
167 public void setAction(Action action) {
168 this.action = action;
171 public String getStatusMessage() {
172 return statusMessage;
175 public void setStatusMessage(String statusMessage) {
176 this.statusMessage = statusMessage;
179 public Integer getPosition() {
183 public void setPosition(Integer position) {
184 this.position = position;
187 public String getOriginalName() {
192 public abstract Collection<? extends BaseResource> getChildren();
195 public abstract JobType getJobType();