Move pauseInstantiation from VfModule to BaseResource
[vid.git] / vid-app-common / src / main / java / org / onap / vid / model / serviceInstantiation / ServiceInstantiation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.vid.model.serviceInstantiation;
22
23 import com.fasterxml.jackson.annotation.JsonProperty;
24 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.stream.Collectors;
30 import java.util.stream.Stream;
31 import org.apache.commons.lang3.ObjectUtils;
32 import org.onap.vid.job.JobAdapter;
33 import org.onap.vid.job.JobType;
34 import org.onap.vid.model.VidNotions;
35 import org.onap.vid.mso.model.ModelInfo;
36 import org.onap.vid.utils.jackson.BooleanAsStringSerializer;
37
38 public class ServiceInstantiation extends BaseResource implements JobAdapter.AsyncJobRequest {
39
40     private final String owningEntityId;
41
42     private final String owningEntityName;
43
44     private final String projectName;
45
46     private final String subscriberName;
47
48     private final String globalSubscriberId;
49
50     private final String productFamilyId;
51
52     private final String subscriptionServiceType;
53
54     private final String tenantName;
55
56     private final String aicZoneId;
57
58     private final String aicZoneName;
59
60     private final Map<String, Vnf> vnfs;
61
62     private final Map<String, Network> networks;
63
64     private final Map<String, InstanceGroup> vnfGroups;
65
66     private final boolean isPause;
67
68     private int bulkSize;
69
70     private final String testApi;
71
72     private final boolean isALaCarte;
73
74     private final VidNotions vidNotions;
75     private Map<String, VrfEntry> vrfs;
76
77     public ServiceInstantiation(@JsonProperty("modelInfo") ModelInfo modelInfo,
78                                 @JsonProperty("owningEntityId") String owningEntityId,
79                                 @JsonProperty("owningEntityName") String owningEntityName,
80                                 @JsonProperty("projectName") String projectName,
81                                 @JsonProperty("globalSubscriberId") String globalSubscriberId,
82                                 @JsonProperty("subscriberName") String subscriberName,
83                                 @JsonProperty("productFamilyId") String productFamilyId,
84                                 @JsonProperty("instanceName") String instanceName,
85                                 @JsonProperty("subscriptionServiceType") String subscriptionServiceType,
86                                 @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId,
87                                 @JsonProperty("legacyRegion") String legacyRegion,
88                                 @JsonProperty("tenantId") String tenantId,
89                                 @JsonProperty("tenantName") String tenantName,
90                                 @JsonProperty("aicZoneId") String aicZoneId,
91                                 @JsonProperty("aicZoneName") String aicZoneName,
92                                 @JsonProperty("vnfs") Map<String, Vnf> vnfs,
93                                 @JsonProperty("networks") Map<String, Network> networks,
94                                 @JsonProperty("vnfGroups") Map<String, InstanceGroup> vnfGroups,
95                                 @JsonProperty("vrfs") Map<String, VrfEntry> vrfs,
96                                 @JsonProperty("instanceParams") List<Map<String, String>> instanceParams,
97                                 @JsonProperty("pause") boolean isPause,
98                                 @JsonProperty("bulkSize") int bulkSize,
99                                 @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure,
100                                 @JsonProperty("isALaCarte") boolean isALaCarte,
101                                 @JsonProperty("testApi") String testApi,
102                                 @JsonProperty("instanceId") String instanceId,
103                                 @JsonProperty("action") String action,
104                                 @JsonProperty("trackById") String trackById,
105                                 @JsonProperty("isFailed") Boolean isFailed,
106                                 @JsonProperty("statusMessage") String statusMessage,
107                                 @JsonProperty("vidNotions") VidNotions vidNotions,
108                                 @JsonProperty("originalName") String originalName) {
109         super(modelInfo, instanceName, action, lcpCloudRegionId, legacyRegion, tenantId, instanceParams, rollbackOnFailure, instanceId, trackById, isFailed, statusMessage,
110             null, null, originalName);
111         this.owningEntityId = owningEntityId;
112         this.owningEntityName = owningEntityName;
113         this.projectName = projectName;
114         this.globalSubscriberId = globalSubscriberId;
115         this.subscriberName = subscriberName;
116         this.productFamilyId = productFamilyId;
117         this.subscriptionServiceType = subscriptionServiceType;
118         this.tenantName = tenantName;
119         this.aicZoneId = aicZoneId;
120         this.aicZoneName = aicZoneName;
121         this.vnfs = vnfs;
122         this.networks = networks;
123         this.vnfGroups = vnfGroups;
124         this.vrfs = vrfs;
125         this.isPause = isPause;
126         this.bulkSize = bulkSize;
127         this.isALaCarte = isALaCarte;
128         this.testApi = isALaCarte ? testApi : null;
129         this.vidNotions = vidNotions;
130     }
131
132     @Override
133     @JsonSerialize(using=BooleanAsStringSerializer.class)
134     public boolean isRollbackOnFailure() {
135         // this override is for the BooleanAsStringSerializer annotation,
136         // but for Service-Instance level only
137         return super.isRollbackOnFailure();
138     }
139
140     public String getOwningEntityId() {
141         return owningEntityId;
142     }
143
144     public String getOwningEntityName() {
145         return owningEntityName;
146     }
147
148     public String getProjectName() {
149         return projectName;
150     }
151
152     public String getGlobalSubscriberId() {
153         return globalSubscriberId;
154     }
155
156     public String getSubscriberName() {
157         return subscriberName;
158     }
159
160     public String getProductFamilyId() {
161         return productFamilyId;
162     }
163
164     public String getSubscriptionServiceType() {
165         return subscriptionServiceType;
166     }
167
168     public String getTenantName() {
169         return tenantName;
170     }
171
172     public String getAicZoneId() {
173         return aicZoneId;
174     }
175
176     public String getAicZoneName() {
177         return aicZoneName;
178     }
179
180     public Map<String, Vnf> getVnfs() {
181         return emptyMapIfNull(vnfs);
182     }
183
184     public Map<String, Network> getNetworks() {
185         return emptyMapIfNull(networks);
186     }
187
188     public Map<String, InstanceGroup> getVnfGroups() {
189         return emptyMapIfNull(vnfGroups);
190     }
191
192     public Map<String, VrfEntry> getVrfs() {
193         return emptyMapIfNull(vrfs);
194     }
195
196     public boolean isPause() {
197         return isPause;
198     }
199
200     public int getBulkSize() { return bulkSize; }
201
202     public void setBulkSize(int bulkSize) {
203         this.bulkSize = bulkSize;
204     }
205
206     public VidNotions getVidNotions() {
207         return vidNotions;
208     }
209
210     @Override
211     protected String getModelType() {
212         return "service";
213     }
214
215     @Override
216     public Collection<BaseResource> getChildren() {
217         return Stream.of(getNetworks().values(), getVnfs().values(), getVnfGroups().values()).flatMap(Collection::stream).collect(Collectors.toList());
218     }
219
220     @JsonProperty("isALaCarte")
221     public boolean isALaCarte() {
222         return isALaCarte;
223     }
224
225     public String getTestApi() {
226         return this.testApi;
227     }
228
229     @Override
230     public JobType getJobType() {
231         return JobType.ALaCarteService;
232     }
233
234     private <T> Map<String, T> emptyMapIfNull(Map<String, T> map) {
235         return ObjectUtils.defaultIfNull(map, Collections.emptyMap());
236     }
237
238 }