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 com.fasterxml.jackson.annotation.JsonIgnore;
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import com.google.common.collect.ImmutableMap;
26 import org.apache.commons.lang3.StringUtils;
27 import org.onap.vid.job.JobAdapter;
28 import org.onap.vid.job.JobType;
29 import org.onap.vid.model.Action;
30 import org.onap.vid.mso.model.ModelInfo;
32 import java.util.Collection;
33 import java.util.Collections;
34 import java.util.List;
37 public abstract class BaseResource implements JobAdapter.AsyncJobRequest {
39 protected String instanceId;
41 protected ModelInfo modelInfo;
43 protected String instanceName;
45 protected Action action;
47 protected String lcpCloudRegionId;
49 protected String tenantId;
51 protected List<Map<String, String>> instanceParams;
53 protected boolean rollbackOnFailure;
55 protected String trackById;
57 protected Boolean isFailed;
59 protected String statusMessage;
61 private static final Map<String, Action> actionStingToEnumMap = ImmutableMap.<String, Action>builder()
62 .put("Delete", Action.Delete)
63 .put("Create", Action.Create)
64 .put("None", Action.None)
65 .put("Update_Delete", Action.Delete)
66 .put("None_Delete", Action.Delete)
67 .put("Resume", Action.Resume)
68 .put("Replace", Action.Replace)
72 protected BaseResource(@JsonProperty("modelInfo") ModelInfo modelInfo,
73 @JsonProperty("instanceName") String instanceName,
74 @JsonProperty("action") String action,
75 @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId,
76 @JsonProperty("legacyRegion") String legacyRegion,
77 @JsonProperty("tenantId") String tenantId,
78 @JsonProperty("instanceParams") List<Map<String, String>> instanceParams,
79 @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure,
80 @JsonProperty("instanceId") String instanceId,
81 @JsonProperty("trackById") String trackById,
82 @JsonProperty("isFailed") Boolean isFailed,
83 @JsonProperty("statusMessage") String statusMessage) {
84 this.modelInfo = modelInfo;
85 this.modelInfo.setModelType(getModelType());
86 this.rollbackOnFailure = rollbackOnFailure;
87 this.instanceName = StringUtils.defaultString(instanceName, "");
88 this.action = actionStringToEnum(action);
89 this.lcpCloudRegionId = StringUtils.isNotEmpty(legacyRegion) ? legacyRegion : lcpCloudRegionId;
90 this.tenantId = tenantId;
91 this.instanceParams = instanceParams;
92 this.instanceId = instanceId;
93 this.trackById = trackById;
94 this.isFailed = isFailed!= null ? isFailed: false;
95 this.statusMessage = statusMessage;
98 private Action actionStringToEnum(String actionAsString) {
99 return actionStingToEnumMap.get(actionAsString);
102 public ModelInfo getModelInfo() {
106 public String getInstanceName() {
110 public Action getAction() {
111 return (action == null ? Action.Create : action);
114 public String getLcpCloudRegionId() {
115 return lcpCloudRegionId;
118 public String getTenantId() {
122 public List<Map<String, String>> getInstanceParams() {
123 return instanceParams == null ? Collections.emptyList() : instanceParams;
126 public boolean isRollbackOnFailure() { return rollbackOnFailure; }
128 public String getInstanceId() {
132 protected abstract String getModelType();
134 public String getTrackById() {
138 public void setTrackById(String trackById) {
139 this.trackById = trackById;
142 public Boolean getIsFailed() {
146 public void setIsFailed(Boolean isFailed) {
147 this.isFailed = isFailed;
150 public void setInstanceId(String instanceId) {
151 this.instanceId = instanceId;
154 public void setAction(Action action) {
155 this.action = action;
158 public String getStatusMessage() {
159 return statusMessage;
162 public void setStatusMessage(String statusMessage) {
163 this.statusMessage = statusMessage;
167 public abstract Collection<? extends BaseResource> getChildren();
170 public abstract JobType getJobType();