blob: cfe0badf81c568ce3e4995a85f0192d48980be9a [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
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
22package org.onap.osam.mso;
23
24import com.fasterxml.jackson.annotation.JsonCreator;
25import com.fasterxml.jackson.annotation.JsonValue;
26import com.fasterxml.jackson.databind.DeserializationFeature;
27import com.fasterxml.jackson.databind.ObjectMapper;
28import com.google.common.collect.ImmutableList;
29import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
30import org.onap.portalsdk.core.util.SystemProperties;
31import org.onap.osam.exceptions.GenericUncheckedException;
32import org.onap.osam.mso.rest.Request;
33import org.onap.osam.mso.rest.RequestDetails;
34import org.onap.osam.mso.rest.RequestDetailsWrapper;
35import org.onap.osam.mso.rest.RequestList;
36import org.onap.osam.mso.rest.RequestWrapper;
37import org.onap.osam.mso.rest.Task;
38import org.onap.osam.mso.rest.TaskList;
39import org.springframework.beans.factory.annotation.Autowired;
40import org.togglz.core.manager.FeatureManager;
41
42import javax.ws.rs.BadRequestException;
43import java.io.IOException;
44import java.text.DateFormat;
45import java.text.SimpleDateFormat;
46import java.util.ArrayList;
47import java.util.Date;
48import java.util.HashMap;
49import java.util.List;
50import java.util.Map;
51import java.util.regex.Pattern;
52
53import static org.apache.commons.lang.StringUtils.upperCase;
54import static org.onap.osam.controllers.MsoController.*;
55import static org.onap.osam.mso.MsoProperties.*;
56import static org.onap.osam.properties.Features.FLAG_UNASSIGN_SERVICE;
57
58public class MsoBusinessLogicImpl implements MsoBusinessLogic {
59
60 public static final String START = " start";
61 public static final String RESOURCE_TYPE = "resourceType";
62 FeatureManager featureManager;
63
64 private static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
65 private static final Pattern SOFTWARE_VERSION_PATTERN = Pattern.compile("^[A-Za-z0-9.\\-]+$");
66 private static final Pattern NUMBER_PATTERN = Pattern.compile("^[0-9]+$");
67 private static final String ACTIVATE = "/activate";
68 private static final String DEACTIVATE = "/deactivate";
69 private static final String ENABLE_PORT = "/enablePort";
70 private static final String DISABLE_PORT = "/disablePort";
71 private static final String RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT = "operationalEnvironment";
72 private static final String SOURCE_OPERATIONAL_ENVIRONMENT = "VID";
73 private static final ObjectMapper objectMapper = new ObjectMapper();
74 private final MsoInterface msoClientInterface;
75
76 /**
77 * The logger.
78 */
79 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoBusinessLogicImpl.class);
80
81 @Autowired
82 public MsoBusinessLogicImpl(MsoInterface msoClientInterface, FeatureManager featureManager) {
83 this.msoClientInterface = msoClientInterface;
84 this.featureManager = featureManager;
85 }
86
87 public static String validateEndpointPath(String endpointEnvVariable) {
88 String endpoint = SystemProperties.getProperty(endpointEnvVariable);
89 if (endpoint == null || endpoint.isEmpty()) {
90 throw new GenericUncheckedException(endpointEnvVariable + " env variable is not defined");
91 }
92 return endpoint;
93 }
94
95 // this function should get params from tosca and send them to instance at mso, then return success response.
96 @Override
97 public MsoResponseWrapper createSvcInstance(RequestDetails msoRequest) {
98 String methodName = "createSvcInstance ";
99 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
100
101 String endpoint;
102 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE);
103
104 return msoClientInterface.createSvcInstance(msoRequest, endpoint);
105 }
106
107 @Override
108 public MsoResponseWrapper createE2eSvcInstance(Object msoRequest){
109 String methodName = "createE2eSvcInstance ";
110 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
111
112 String endpoint;
113 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE);
114
115
116 return msoClientInterface.createE2eSvcInstance(msoRequest, endpoint);
117 }
118
119 @Override
120 public MsoResponseWrapper createVnf(RequestDetails requestDetails, String serviceInstanceId) {
121 String methodName = "createVnf";
122 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
123
124 String endpoint;
125 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
126
127 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
128 return msoClientInterface.createVnf(requestDetails, vnf_endpoint);
129 }
130
131 @Override
132 public MsoResponseWrapper createNwInstance(RequestDetails requestDetails, String serviceInstanceId) {
133 String methodName = "createNwInstance";
134 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
135
136 String endpoint;
137 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
138
139 String nw_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
140 return msoClientInterface.createNwInstance(requestDetails, nw_endpoint);
141 }
142
143 @Override
144 public MsoResponseWrapper createVolumeGroupInstance(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
145 String methodName = "createVolumeGroupInstance";
146 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
147
148 String endpoint;
149 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
150
151 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
152 vnf_endpoint = vnf_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
153
154 return msoClientInterface.createVolumeGroupInstance(requestDetails, vnf_endpoint);
155 }
156
157 @Override
158 public MsoResponseWrapper createVfModuleInstance(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
159 String methodName = "createVfModuleInstance";
160 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
161
162 String endpoint;
163 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
164
165 String partial_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
166 String vf_module_endpoint = partial_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
167
168 return msoClientInterface.createVfModuleInstance(requestDetails, vf_module_endpoint);
169 }
170
171 @Override
172 public MsoResponseWrapper scaleOutVfModuleInstance(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
173 String methodName = "scaleOutVfModuleInstance";
174 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
175
176 String endpoint;
177 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_SCALE_OUT);
178
179 String partial_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
180 String vf_module_endpoint = partial_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
181 RequestDetailsWrapper wrapper = new RequestDetailsWrapper();
182 //requestDetails.setVnfName(null);
183 //requestDetails.setVnfInstanceId(null);
184 wrapper.requestDetails = requestDetails;
185
186 return msoClientInterface.scaleOutVFModuleInstance(wrapper, vf_module_endpoint);
187 }
188 @Override
189 public MsoResponseWrapper createConfigurationInstance(org.onap.osam.mso.rest.RequestDetailsWrapper requestDetailsWrapper, String serviceInstanceId) {
190 String methodName = "createConfigurationInstance";
191 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
192
193 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATIONS);
194 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
195
196 return msoClientInterface.createConfigurationInstance(requestDetailsWrapper, endpoint);
197 }
198
199 @Override
200 public MsoResponseWrapper deleteE2eSvcInstance(Object requestDetails, String serviceInstanceId) {
201 String methodName = "deleteE2eSvcInstance";
202 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
203
204 String endpoint;
205 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE) + "/" + serviceInstanceId;
206
207 return msoClientInterface.deleteE2eSvcInstance(requestDetails, endpoint);
208 }
209
210 @Override
211 public MsoResponseWrapper deleteSvcInstance(RequestDetails requestDetails, String serviceInstanceId, String serviceStatus) {
212 String methodName = "deleteSvcInstance";
213 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
214 String endpoint;
215
216 if (featureManager.isActive(FLAG_UNASSIGN_SERVICE)){
217 endpoint = validateEndpointPath(MsoProperties.MSO_DELETE_OR_UNASSIGN_REST_API_SVC_INSTANCE);
218 if (shouldUnassignService(serviceStatus)){
219 logger.debug(EELFLoggerDelegate.debugLogger, "unassign service");
220 String svc_endpoint = endpoint + "/" + serviceInstanceId + "/unassign";
221 return msoClientInterface.unassignSvcInstance(requestDetails, svc_endpoint);
222 }
223 } else {
224 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE);
225 }
226
227 String svc_endpoint = endpoint + "/" + serviceInstanceId;
228 return msoClientInterface.deleteSvcInstance(requestDetails, svc_endpoint);
229 }
230
231 private boolean shouldUnassignService(String serviceStatus) {
232 return ImmutableList.of("created","pendingdelete","pending-delete", "assigned").contains(serviceStatus.toLowerCase());
233 }
234
235 @Override
236 public MsoResponseWrapper deleteVnf(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
237 String methodName = "deleteVnf";
238 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
239
240 String endpoint;
241 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
242 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
243 vnf_endpoint = vnf_endpoint + '/' + vnfInstanceId;
244
245 return msoClientInterface.deleteVnf(requestDetails, vnf_endpoint);
246 }
247
248 @Override
249 public MsoResponseWrapper deleteVfModule(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId, String vfModuleId) {
250 String methodName = "deleteVfModule";
251 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
252
253 String endpoint;
254 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
255
256 String vf__modules_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId).replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
257
258 String delete_vf_endpoint = vf__modules_endpoint + '/' + vfModuleId;
259
260 return msoClientInterface.deleteVfModule(requestDetails, delete_vf_endpoint);
261 }
262
263 @Override
264 public MsoResponseWrapper deleteVolumeGroupInstance(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId, String volumeGroupId) {
265 String methodName = "deleteVolumeGroupInstance";
266 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
267
268 String endpoint;
269 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
270
271 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
272 String vnf_endpoint = svc_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
273 String delete_volume_group_endpoint = vnf_endpoint + "/" + volumeGroupId;
274
275 return msoClientInterface.deleteVolumeGroupInstance(requestDetails, delete_volume_group_endpoint);
276 }
277
278 @Override
279 public MsoResponseWrapper deleteNwInstance(RequestDetails requestDetails, String serviceInstanceId, String networkInstanceId) {
280 String methodName = "deleteNwInstance";
281 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
282
283 String endpoint;
284 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
285
286 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
287 String delete_nw_endpoint = svc_endpoint + "/" + networkInstanceId;
288
289 return msoClientInterface.deleteNwInstance(requestDetails, delete_nw_endpoint);
290 }
291
292 @Override
293 public MsoResponseWrapper getOrchestrationRequest(String requestId) {
294 String methodName = "getOrchestrationRequest";
295 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
296 try {
297 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
298 String path = p + "/" + requestId;
299
300 return msoClientInterface.getOrchestrationRequest(path);
301
302 } catch (Exception e) {
303 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
304 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
305 throw e;
306 }
307 }
308
309 @Override
310 public MsoResponseWrapper getOrchestrationRequests(String filterString) {
311 String methodName = "getOrchestrationRequest";
312 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
313 try {
314 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
315 String path = p + filterString;
316
317 return msoClientInterface.getOrchestrationRequest(path);
318
319 } catch (Exception e) {
320 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
321 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
322 throw e;
323 }
324 }
325
326 @Override
327 public List<Request> getOrchestrationRequestsForDashboard() {
328 String methodName = "getOrchestrationRequestsForDashboard";
329 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
330 List<Request> filteredOrchestrationRequests = new ArrayList<>();
331 try {
332 String path = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
333 path += "filter=modelType:EQUALS:vnf";
334 RestObject<String> restObjStr = new RestObject<>();
335 String str = new String();
336 restObjStr.set(str);
337
338 MsoResponseWrapper msoResponseWrapper = msoClientInterface.getOrchestrationRequestsForDashboard(str, "", path, restObjStr);
339 List<RequestWrapper> allOrchestrationRequests = deserializeOrchestrationRequestsJson(msoResponseWrapper.getEntity());
340
341 final ImmutableList<String> suppoertedRequestTypes = ImmutableList.of(
342 RequestType.REPLACE_INSTANCE.toString().toUpperCase(),
343 RequestType.UPDATE_INSTANCE.toString().toUpperCase(),
344 RequestType.APPLY_UPDATED_CONFIG.toString().toUpperCase(),
345 RequestType.IN_PLACE_SOFTWARE_UPDATE.toString().toUpperCase()
346 );
347
348 for (RequestWrapper currentRequest : allOrchestrationRequests) {
349 if (currentRequest.getRequest() != null
350 && "vnf".equalsIgnoreCase(currentRequest.getRequest().getRequestScope())
351 && suppoertedRequestTypes.contains(upperCase(currentRequest.getRequest().getRequestType()))
352 ) {
353 filteredOrchestrationRequests.add(currentRequest.getRequest());
354 }
355 }
356 } catch (Exception e) {
357 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
358 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
359 }
360 return filteredOrchestrationRequests;
361 }
362
363 private List<RequestWrapper> deserializeOrchestrationRequestsJson(String orchestrationRequestsJson) {
364 String methodName = "deserializeOrchestrationRequestsJson";
365 logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START);
366
367 ObjectMapper mapper = new ObjectMapper();
368 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
369 mapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true);
370 RequestList requestList = null;
371 try {
372 requestList = mapper.readValue(orchestrationRequestsJson, RequestList.class);
373 } catch (IOException e) {
374 throw new GenericUncheckedException(e);
375 }
376 return requestList.getRequestList();
377 }
378
379
380 @Override
381 public List<Task> getManualTasksByRequestId(String originalRequestId) {
382 String methodName = "getManualTasksByRequestId";
383 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
384
385 try {
386 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
387 String path = p + "?originalRequestId=" + originalRequestId;
388
389 RestObject<String> restObjStr = new RestObject<>();
390 String str = new String();
391 restObjStr.set(str);
392
393 MsoResponseWrapper msoResponseWrapper = msoClientInterface.getManualTasksByRequestId(str, "", path, restObjStr);
394 return deserializeManualTasksJson(msoResponseWrapper.getEntity());
395
396 } catch (Exception e) {
397 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
398 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
399 throw e;
400 }
401 }
402
403 private List<Task> deserializeManualTasksJson(String manualTasksJson) {
404 String methodName = "deserializeManualTasksJson";
405 logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START);
406
407 ObjectMapper mapper = new ObjectMapper();
408 try {
409 TaskList taskList = mapper.readValue(manualTasksJson, TaskList.class);
410 return taskList.getTaskList();
411 } catch (IOException e) {
412 throw new GenericUncheckedException(e);
413 }
414 }
415
416
417 @Override
418 public MsoResponseWrapper completeManualTask(RequestDetails requestDetails, String taskId) {
419 String methodName = "completeManualTask";
420 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
421 try {
422 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
423 String path = p + "/" + taskId + "/complete";
424
425 RestObject<String> restObjStr = new RestObject<>();
426 String str = new String();
427 restObjStr.set(str);
428
429 msoClientInterface.completeManualTask(requestDetails, str, "", path, restObjStr);
430
431 return MsoUtil.wrapResponse(restObjStr);
432
433 } catch (Exception e) {
434 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
435 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
436 throw e;
437 }
438 }
439
440 @Override
441 public MsoResponseWrapper activateServiceInstance(RequestDetails requestDetails, String serviceInstanceId) {
442 String methodName = "activateServiceInstance";
443 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
444 try {
445 String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
446 String activateServicePath = serviceEndpoint + "/" + serviceInstanceId + ACTIVATE;
447
448 RestObject<String> restObjStr = new RestObject<>();
449 String str = "";
450 restObjStr.set(str);
451
452 msoClientInterface.setServiceInstanceStatus(requestDetails, str, "", activateServicePath, restObjStr);
453
454 return MsoUtil.wrapResponse(restObjStr);
455
456 } catch (Exception e) {
457 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
458 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
459 throw e;
460 }
461 }
462
463 public RequestDetailsWrapper generateInPlaceMsoRequest(RequestDetails requestDetails) {
464 validateUpdateVnfSoftwarePayload(requestDetails);
465 RequestDetails inPlaceSoftwareUpdateRequest = new RequestDetails();
466 inPlaceSoftwareUpdateRequest.setCloudConfiguration(requestDetails.getCloudConfiguration());
467 inPlaceSoftwareUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
468 inPlaceSoftwareUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
469 RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper();
470 requestDetailsWrapper.requestDetails = inPlaceSoftwareUpdateRequest;
471 return requestDetailsWrapper;
472 }
473
474 @Override
475 public RequestDetailsWrapper generateConfigMsoRequest(RequestDetails requestDetails) {
476 validateUpdateVnfConfig(requestDetails);
477 RequestDetails ConfigUpdateRequest = new RequestDetails();
478 ConfigUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
479 ConfigUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
480 RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper();
481 requestDetailsWrapper.requestDetails = ConfigUpdateRequest;
482 return requestDetailsWrapper;
483 }
484
485
486 @Override
487 public MsoResponseWrapperInterface updateVnfSoftware(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
488 String methodName = "updateVnfSoftware";
489 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
490 //String vnf_endpoint = getChangeManagementEndpoint(serviceInstanceId, vnfInstanceId, MsoChangeManagementRequest.SOFTWARE_UPDATE); //workflow name in mso is different than workflow name in vid UI
491 String vnf_endpoint = "";
492
493 RequestDetailsWrapper finalRequestDetails = generateInPlaceMsoRequest(requestDetails);
494 return msoClientInterface.changeManagementUpdate(finalRequestDetails, vnf_endpoint);
495 }
496
497 @Override
498 public MsoResponseWrapperInterface updateVnfConfig(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
499 String methodName = "updateVnfConfig";
500 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
501 RequestDetailsWrapper finalRequestDetails = generateConfigMsoRequest(requestDetails);
502 //String vnf_endpoint = getChangeManagementEndpoint(serviceInstanceId, vnfInstanceId, MsoChangeManagementRequest.CONFIG_UPDATE);
503 String vnf_endpoint = "";
504
505
506 return msoClientInterface.changeManagementUpdate(finalRequestDetails, vnf_endpoint);
507 }
508
509 private String getChangeManagementEndpoint(String serviceInstanceId, String vnfInstanceId, String vnfRequestType) {
510 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
511 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
512 vnf_endpoint = vnf_endpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
513 vnf_endpoint = vnf_endpoint.replace(REQUEST_TYPE, vnfRequestType);
514 return vnf_endpoint;
515 }
516
517 private Map getChangeManagementPayload(RequestDetails requestDetails, String message){
518 if(requestDetails.getRequestParameters()==null||requestDetails.getRequestParameters().getAdditionalProperties()==null){
519 throw new BadRequestException(message);
520 }
521 Object payloadRaw=requestDetails.getRequestParameters().getAdditionalProperties().get("payload");
522 try{
523 return objectMapper.readValue((String)payloadRaw,Map.class);
524 }
525 catch(Exception exception){
526 throw new BadRequestException(message);
527 }
528 }
529
530 private void validateUpdateVnfSoftwarePayload(RequestDetails requestDetails) {
531 //final String noValidPayloadMsg = "No valid payload in " + ChangeManagementRequest.VNF_IN_PLACE_SOFTWARE_UPDATE + " request";
532 final String noValidPayloadMsg = "";
533
534 Map payload = getChangeManagementPayload(requestDetails, noValidPayloadMsg);
535 validateUpdateVnfSoftwarePayloadProperty(payload, noValidPayloadMsg, "existing_software_version", SOFTWARE_VERSION_PATTERN);
536 validateUpdateVnfSoftwarePayloadProperty(payload, noValidPayloadMsg, "new_software_version", SOFTWARE_VERSION_PATTERN);
537
538 //if "operations_timeout" is not integer, trying to read it as String that represent a number
539 if (!(payload.get("operations_timeout") instanceof Integer)) {
540 validateUpdateVnfSoftwarePayloadProperty(payload, noValidPayloadMsg, "operations_timeout", NUMBER_PATTERN);
541 }
542 }
543
544 private void validateUpdateVnfSoftwarePayloadProperty(Map payload, String noValidPayloadMsg, String propertyName, Pattern pattern) {
545 Object forValidation = payload.get(propertyName);
546 final String noValidPayloadPropertyMsg = noValidPayloadMsg + ", " + propertyName + " property is not valid";
547 if (!(forValidation instanceof String)) {
548 throw new BadRequestException(noValidPayloadPropertyMsg);
549 }
550 if (!pattern.matcher((String) forValidation).matches()) {
551 throw new BadRequestException(noValidPayloadPropertyMsg);
552 }
553 }
554
555 private void validateUpdateVnfConfig(RequestDetails requestDetails) {
556 //final String noValidPayloadMsg = "No valid payload in " + ChangeManagementRequest.CONFIG_UPDATE + " request";
557 final String noValidPayloadMsg = "";
558
559 Map payload = getChangeManagementPayload(requestDetails, noValidPayloadMsg);
560 validateConfigUpdateVnfPayloadProperty(payload, noValidPayloadMsg, "request-parameters");
561 validateConfigUpdateVnfPayloadProperty(payload, noValidPayloadMsg, "configuration-parameters");
562 }
563
564 private void validateConfigUpdateVnfPayloadProperty(Map payload, String noValidPayloadMsg, String propertyName) {
565 final String noValidPayloadPropertyMsg = noValidPayloadMsg+ ", "+ propertyName + " property is not valid";
566 if(!payload.containsKey(propertyName)) {
567 throw new BadRequestException( noValidPayloadPropertyMsg);
568 }
569 }
570
571 @Override
572 public MsoResponseWrapper deleteConfiguration(
573 org.onap.osam.mso.rest.RequestDetailsWrapper requestDetailsWrapper,
574 String serviceInstanceId,
575 String configurationId) {
576
577 String methodName = "deleteConfiguration";
578 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
579
580 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE);
581 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
582 endpoint = endpoint.replace(CONFIGURATION_ID, configurationId);
583
584 return msoClientInterface.deleteConfiguration(requestDetailsWrapper, endpoint);
585 }
586
587 @Override
588 public MsoResponseWrapper setConfigurationActiveStatus(
589 RequestDetails requestDetails,
590 String serviceInstanceId,
591 String configurationId,
592 boolean isActivate) {
593
594 String methodName = "setConfigurationActiveStatus";
595 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
596
597 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE);
598 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
599 endpoint = endpoint.replace(CONFIGURATION_ID, configurationId);
600
601 String isActivateState = (isActivate ? ACTIVATE : DEACTIVATE);
602 endpoint = endpoint + isActivateState;
603
604 return msoClientInterface.setConfigurationActiveStatus(requestDetails, endpoint);
605 }
606
607 @Override
608 public MsoResponseWrapper setServiceInstanceStatus(RequestDetails requestDetails , String serviceInstanceId, boolean isActivate) {
609 String methodName = "setServiceInstanceStatus";
610 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
611 try {
612 String serviceEndpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE);
613 String endpoint = serviceEndpoint + "/" + serviceInstanceId;
614
615 String isActivateState = (isActivate ? ACTIVATE : DEACTIVATE);
616 endpoint = endpoint + isActivateState;
617
618
619 RestObject<String> restObjStr = new RestObject<>();
620 String str = "";
621 restObjStr.set(str);
622
623 msoClientInterface.setServiceInstanceStatus(requestDetails , str, "", endpoint, restObjStr);
624
625 return MsoUtil.wrapResponse(restObjStr);
626
627 } catch (Exception e) {
628 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
629 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
630 throw e;
631 }
632 }
633
634 @Override
635 public MsoResponseWrapper setPortOnConfigurationStatus(
636 RequestDetails requestDetails,
637 String serviceInstanceId,
638 String configurationId,
639 boolean isEnable) {
640 String methodName = "setPortOnConfigurationStatus";
641 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
642
643 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE);
644 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
645 endpoint = endpoint.replace(CONFIGURATION_ID, configurationId);
646
647 String isEnablePortStatus = (isEnable ? ENABLE_PORT : DISABLE_PORT);
648 endpoint = endpoint + isEnablePortStatus;
649
650 return msoClientInterface.setPortOnConfigurationStatus(requestDetails, endpoint);
651 }
652
653
654 /* @Override
655 public RequestDetailsWrapper<RequestDetails> createOperationalEnvironmentActivationRequestDetails(OperationalEnvironmentActivateInfo details) {
656 RequestDetails requestDetails = new RequestDetails();
657 RequestInfo requestInfo = new RequestInfo();
658 requestInfo.setAdditionalProperty(RESOURCE_TYPE, RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT);
659 requestInfo.setSource(SOURCE_OPERATIONAL_ENVIRONMENT);
660 requestInfo.setRequestorId(details.getUserId());
661 requestDetails.setRequestInfo(requestInfo);
662
663 org.onap.vid.domain.mso.RelatedInstance relatedInstance = new org.onap.vid.domain.mso.RelatedInstance();
664 relatedInstance.setAdditionalProperty(RESOURCE_TYPE, RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT);
665 relatedInstance.setInstanceId(details.getRelatedInstanceId());
666 relatedInstance.setInstanceName(details.getRelatedInstanceName());
667 requestDetails.setAdditionalProperty("relatedInstanceList", Collections.singletonList(ImmutableMap.of("relatedInstance", relatedInstance)));
668
669 org.onap.vid.domain.mso.RequestParameters requestParameters = new org.onap.vid.domain.mso.RequestParameters();
670 requestParameters.setUserParams(null);
671 requestParameters.setAdditionalProperty("operationalEnvironmentType", "VNF");
672 requestParameters.setAdditionalProperty("workloadContext", details.getWorkloadContext());
673 requestParameters.setAdditionalProperty("manifest", details.getManifest());
674 requestDetails.setRequestParameters(requestParameters);
675
676 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
677
678 debugRequestDetails(requestDetailsWrapper, logger);
679
680 return requestDetailsWrapper;
681 }*/
682
683 /* @Override
684 public RequestDetailsWrapper<RequestDetails> createOperationalEnvironmentDeactivationRequestDetails(OperationalEnvironmentDeactivateInfo details) {
685 RequestDetails requestDetails = new RequestDetails();
686
687 RequestInfo requestInfo = new RequestInfo();
688 requestInfo.setAdditionalProperty(RESOURCE_TYPE, RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT);
689 requestInfo.setSource(SOURCE_OPERATIONAL_ENVIRONMENT);
690 requestInfo.setRequestorId(details.getUserId());
691 requestDetails.setRequestInfo(requestInfo);
692
693 org.onap.vid.domain.mso.RequestParameters requestParameters = new org.onap.vid.domain.mso.RequestParameters();
694 requestParameters.setUserParams(null);
695 requestParameters.setAdditionalProperty("operationalEnvironmentType", "VNF");
696 requestDetails.setRequestParameters(requestParameters);
697 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
698 debugRequestDetails(requestDetailsWrapper, logger);
699 return requestDetailsWrapper;
700 }*/
701
702 @Override
703 public String getCloudResourcesRequestsStatusPath(String requestId) {
704 String path = validateEndpointPath(MSO_REST_API_CLOUD_RESOURCES_REQUEST_STATUS);
705 path = path.replace("<request_id>", requestId);
706 return path;
707 }
708
709 /*@Override
710 public RequestDetailsWrapper<OperationEnvironmentRequestDetails> convertParametersToRequestDetails(OperationalEnvironmentController.OperationalEnvironmentCreateBody input, String userId) {
711 OperationEnvironmentRequestDetails.RequestInfo requestInfo = new OperationEnvironmentRequestDetails.RequestInfo(
712 RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT,
713 input.getInstanceName(),
714 SOURCE_OPERATIONAL_ENVIRONMENT,
715 userId);
716
717 OperationEnvironmentRequestDetails.RelatedInstance relatedInstance = new OperationEnvironmentRequestDetails.RelatedInstance(
718 RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT,
719 input.getEcompInstanceId(),
720 input.getEcompInstanceName());
721
722 List<OperationEnvironmentRequestDetails.RelatedInstance> relatedInstanceList = Collections.singletonList((relatedInstance));
723
724 OperationEnvironmentRequestDetails.RequestParameters requestParameters = new OperationEnvironmentRequestDetails.RequestParameters(
725 input.getOperationalEnvironmentType(),
726 input.getTenantContext(),
727 input.getWorkloadContext());
728
729 OperationEnvironmentRequestDetails requestDetails = new OperationEnvironmentRequestDetails(requestInfo, relatedInstanceList, requestParameters);
730 RequestDetailsWrapper<OperationEnvironmentRequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
731 debugRequestDetails(requestDetailsWrapper, logger);
732 return requestDetailsWrapper;
733 }*/
734
735 @Override
736 public MsoResponseWrapper removeRelationshipFromServiceInstance(RequestDetails requestDetails, String serviceInstanceId) {
737 String methodName = "removeRelationshipFromServiceInstance";
738 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
739
740 String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
741 String removeRelationshipsPath = serviceEndpoint + "/" + serviceInstanceId + "/removeRelationships";
742
743 return msoClientInterface.removeRelationshipFromServiceInstance(requestDetails, removeRelationshipsPath);
744 }
745
746 @Override
747 public MsoResponseWrapper addRelationshipToServiceInstance(RequestDetails requestDetails, String serviceInstanceId) {
748 String methodName = "addRelationshipToServiceInstance";
749 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
750
751 String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
752 String addRelationshipsPath = serviceEndpoint + "/" + serviceInstanceId + "/addRelationships";
753
754 return msoClientInterface.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath);
755 }
756
757
758 public enum RequestType {
759
760 CREATE_INSTANCE("createInstance"),
761 DELETE_INSTANCE("deleteInstance"),
762 REPLACE_INSTANCE("replaceInstance"),
763 UPDATE_INSTANCE("updateInstance"),
764 ACTIVATE_INSTANCE("activateInstance"),
765 DEACTIVATE_INSTANCE("deactivateInstance"),
766 APPLY_UPDATED_CONFIG("applyUpdatedConfig"),
767 IN_PLACE_SOFTWARE_UPDATE("inPlaceSoftwareUpdate"),
768 UNKNOWN("unknown"),
769 NOT_PROVIDED("not provided");
770 private final String value;
771 private static final Map<String, RequestType> CONSTANTS = new HashMap<>();
772
773 static {
774 for (RequestType c: values()) {
775 CONSTANTS.put(c.value, c);
776 }
777 }
778
779 RequestType(String value) {
780 this.value = value;
781 }
782
783 @JsonValue
784 @Override
785 public String toString() {
786 return this.value;
787 }
788
789 @JsonCreator
790 public static RequestType fromValue(String value) {
791 RequestType constant = CONSTANTS.get(value);
792 if (constant == null) {
793 throw new IllegalArgumentException(value);
794 } else {
795 return constant;
796 }
797 }
798 }
799}