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