1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
/**
* Copyright (c) 2018 Orange
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.onap.nbi.apis.serviceorder.workflow;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.onap.nbi.apis.serviceorder.SoClient;
import org.onap.nbi.apis.serviceorder.model.ServiceCharacteristic;
import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
import org.onap.nbi.apis.serviceorder.model.StateType;
import org.onap.nbi.apis.serviceorder.model.consumer.CloudConfiguration;
import org.onap.nbi.apis.serviceorder.model.consumer.CreateE2EServiceInstanceResponse;
import org.onap.nbi.apis.serviceorder.model.consumer.CreateServiceInstanceResponse;
import org.onap.nbi.apis.serviceorder.model.consumer.MSOE2EPayload;
import org.onap.nbi.apis.serviceorder.model.consumer.MSOPayload;
import org.onap.nbi.apis.serviceorder.model.consumer.ModelInfo;
import org.onap.nbi.apis.serviceorder.model.consumer.OwningEntity;
import org.onap.nbi.apis.serviceorder.model.consumer.ParametersModel;
import org.onap.nbi.apis.serviceorder.model.consumer.Project;
import org.onap.nbi.apis.serviceorder.model.consumer.RequestDetails;
import org.onap.nbi.apis.serviceorder.model.consumer.RequestInfo;
import org.onap.nbi.apis.serviceorder.model.consumer.RequestParameters;
import org.onap.nbi.apis.serviceorder.model.consumer.ResourceModel;
import org.onap.nbi.apis.serviceorder.model.consumer.ServiceModel;
import org.onap.nbi.apis.serviceorder.model.consumer.SubscriberInfo;
import org.onap.nbi.apis.serviceorder.model.consumer.UserParams;
import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo;
import org.onap.nbi.apis.serviceorder.service.ServiceOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@Service
public class PostSoProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(PostSoProcessor.class);
@Value("${onap.lcpCloudRegionId}")
private String lcpCloudRegionId;
@Value("${onap.tenantId}")
private String tenantId;
@Value("${so.owning.entity.id}")
private String soOwningEntityId;
@Value("${so.owning.entity.name}")
private String soOwningEntityName;
@Value("${so.project.name}")
private String soProjectName;
@Autowired
private ServiceOrderService serviceOrderService;
@Autowired
private SoClient soClient;
public ResponseEntity<CreateServiceInstanceResponse> postServiceOrderItem(ServiceOrderInfo serviceOrderInfo,
ServiceOrderItem serviceOrderItem) {
ResponseEntity<CreateServiceInstanceResponse> response = null;
try {
response = postSORequest(serviceOrderItem,serviceOrderInfo);
} catch (NullPointerException e) {
LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e);
response = null;
}
return response;
}
public ResponseEntity<CreateE2EServiceInstanceResponse> postE2EServiceOrderItem(ServiceOrderInfo serviceOrderInfo,
ServiceOrderItem serviceOrderItem, ServiceOrder serviceOrder) {
ResponseEntity<CreateE2EServiceInstanceResponse> response;
try {
response = postE2ESORequest(serviceOrderItem, serviceOrderInfo, serviceOrder);
} catch (NullPointerException e) {
LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e);
response = null;
}
return response;
}
private ResponseEntity<CreateServiceInstanceResponse> postSORequest(ServiceOrderItem serviceOrderItem,
ServiceOrderInfo serviceOrderInfo) {
RequestDetails requestDetails = buildSoRequest(serviceOrderItem,
serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()).getCatalogResponse(),
serviceOrderInfo.getSubscriberInfo());
MSOPayload msoPayload = new MSOPayload(requestDetails);
ResponseEntity<CreateServiceInstanceResponse> response = null;
switch (serviceOrderItem.getAction()) {
case ADD:
response = soClient.callCreateServiceInstance(msoPayload);
break;
case DELETE:
response = soClient.callDeleteServiceInstance(msoPayload,serviceOrderItem.getService().getId());
break;
case MODIFY:
if(StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE ==serviceOrderItem.getState()) {
response = soClient.callCreateServiceInstance(msoPayload);
}
if(StateType.ACKNOWLEDGED==serviceOrderItem.getState()) {
response = soClient.callDeleteServiceInstance(msoPayload,serviceOrderItem.getService().getId());
}
break;
default:
break;
}
return response;
}
private ResponseEntity<CreateE2EServiceInstanceResponse> postE2ESORequest(ServiceOrderItem serviceOrderItem,
ServiceOrderInfo serviceOrderInfo, ServiceOrder serviceOrder) {
ServiceModel service = buildE2ESoRequest(serviceOrderItem, serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()).getCatalogResponse(), serviceOrderInfo.getSubscriberInfo(), serviceOrder);
MSOE2EPayload msoE2EPayload = new MSOE2EPayload(service);
ResponseEntity<CreateE2EServiceInstanceResponse> response = null;
switch (serviceOrderItem.getAction()) {
case ADD:
response = soClient.callE2ECreateServiceInstance(msoE2EPayload);
break;
case DELETE:
response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(), service.getServiceType(),serviceOrderItem.getService().getId());
break;
case MODIFY:
if(StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE ==serviceOrderItem.getState()) {
response = soClient.callE2ECreateServiceInstance(msoE2EPayload);
}
if(StateType.ACKNOWLEDGED==serviceOrderItem.getState()) {
response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(), service.getServiceType(),serviceOrderItem.getService().getId());
}
break;
default:
break;
}
return response;
}
/**
* Build SO CREATE request from the ServiceOrder and catalog informations from SDC
*
* @param orderItem
* @param sdcInfos
* @param subscriberInfo
* @return
*/
private RequestDetails buildSoRequest(ServiceOrderItem orderItem, Map<String, Object> sdcInfos,
SubscriberInfo subscriberInfo) {
RequestDetails requestDetails = new RequestDetails();
requestDetails.setSubscriberInfo(subscriberInfo);
ModelInfo modelInfo = new ModelInfo();
modelInfo.setModelType("service");
modelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID"));
modelInfo.setModelNameVersionId(orderItem.getService().getServiceSpecification().getId());
modelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId());
modelInfo.setModelName((String) sdcInfos.get("name"));
modelInfo.setModelVersion((String) sdcInfos.get("version"));
requestDetails.setModelInfo(modelInfo);
RequestInfo requestInfo = new RequestInfo();
requestInfo.setInstanceName(orderItem.getService().getName());
requestInfo.setSource("VID");
requestInfo.setSuppressRollback(false);
requestInfo.setRequestorId("NBI");
requestDetails.setRequestInfo(requestInfo);
RequestParameters requestParameters = new RequestParameters();
requestParameters.setSubscriptionServiceType((String) sdcInfos.get("name"));
requestParameters.setUserParams(
retrieveUserParamsFromServiceCharacteristics(orderItem.getService().getServiceCharacteristic()));
requestParameters.setaLaCarte(true);
requestDetails.setRequestParameters(requestParameters);
CloudConfiguration cloudConfiguration = new CloudConfiguration(lcpCloudRegionId, tenantId);
requestDetails.setCloudConfiguration(cloudConfiguration);
OwningEntity owningEntity = new OwningEntity();
owningEntity.setOwningEntityId(soOwningEntityId);
owningEntity.setOwningEntityName(soOwningEntityName);
requestDetails.setOwningEntity(owningEntity);
Project project = new Project();
project.setProjectName(soProjectName);
requestDetails.setProject(project);
return requestDetails;
}
/**
* Build E2E SO CREATE request from the ServiceOrder and catalog informations from SDC
*
* @param serviceOrderItem
* @param serviceOrder
* @param sdcInfos
* @return
*/
//ServiceOrderItem serviceOrderItem --> orderItem?
private ServiceModel buildE2ESoRequest(ServiceOrderItem serviceOrderItem, Map<String, Object> sdcInfos,
SubscriberInfo subscriberInfo, ServiceOrder serviceOrder) {
subscriberInfo.getGlobalSubscriberId();
ServiceModel service = new ServiceModel();
service.setName(serviceOrderItem.getService().getName());
service.setDescription(serviceOrder.getDescription());
service.setServiceUuid(serviceOrderItem.getService().getServiceSpecification().getId());
service.setServiceInvariantUuid((String) sdcInfos.get("invariantUUID"));
service.setGlobalSubscriberId(subscriberInfo.getGlobalSubscriberId());
service.setServiceType((String) sdcInfos.get("name"));
ParametersModel parameters = new ParametersModel();
ArrayList<ResourceModel> resources = new ArrayList();
ArrayList<Object> resourceObjects = (ArrayList<Object>)sdcInfos.get("resourceSpecification");
for(int i = 0; i < resourceObjects.size(); i++) {
ResourceModel resourceModel = new ResourceModel((Map<String, Object>)resourceObjects.get(i));
ParametersModel resourceParameters = new ParametersModel();
resourceModel.setParameters(resourceParameters);
resources.add(resourceModel);
}
parameters.setResources(resources);
List<UserParams> userParams = retrieveUserParamsFromServiceCharacteristics(serviceOrderItem.getService().getServiceCharacteristic());
// If there are ServiceCharacteristics add them to requestInputs
if (!userParams.isEmpty()){
Map<String, String> requestInputs = new HashMap<String, String>();
for (int i = 0; i < userParams.size(); i++) {
requestInputs.put(userParams.get(i).getName(), userParams.get(i).getValue());
}
parameters.setRequestInputs(requestInputs);
}
service.setParameters(parameters);
return service;
}
/**
* Build a list of UserParams for the SO request by browsing a list of ServiceCharacteristics from SDC
*/
private List<UserParams> retrieveUserParamsFromServiceCharacteristics(List<ServiceCharacteristic> characteristics) {
List<UserParams> userParams = new ArrayList<>();
if (!CollectionUtils.isEmpty(characteristics)) {
for (ServiceCharacteristic characteristic : characteristics) {
UserParams userParam = new UserParams(characteristic.getName(),
characteristic.getValue().getServiceCharacteristicValue());
userParams.add(userParam);
}
}
return userParams;
}
}
|