2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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.sdnc.apps.ms.gra.controllers;
23 import java.text.DateFormat;
24 import java.text.SimpleDateFormat;
25 import java.util.Date;
26 import java.util.List;
27 import java.util.Optional;
28 import java.util.Properties;
29 import java.util.TimeZone;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.validation.Valid;
34 import com.fasterxml.jackson.annotation.JsonInclude;
35 import com.fasterxml.jackson.core.JsonProcessingException;
36 import com.fasterxml.jackson.databind.JsonMappingException;
37 import com.fasterxml.jackson.databind.ObjectMapper;
39 import org.onap.ccsdk.apps.services.RestException;
40 import org.onap.ccsdk.apps.services.SvcLogicFactory;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
42 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
43 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceBase;
44 import org.onap.sdnc.apps.ms.gra.data.ConfigContrailRouteAllottedResourcesRepository;
45 import org.onap.sdnc.apps.ms.gra.data.ConfigNetworks;
46 import org.onap.sdnc.apps.ms.gra.data.ConfigNetworksRepository;
47 import org.onap.sdnc.apps.ms.gra.data.ConfigPortMirrorConfigurations;
48 import org.onap.sdnc.apps.ms.gra.data.ConfigPortMirrorConfigurationsRepository;
49 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadData;
50 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadDataRepository;
51 import org.onap.sdnc.apps.ms.gra.data.ConfigServices;
52 import org.onap.sdnc.apps.ms.gra.data.ConfigServicesRepository;
53 import org.onap.sdnc.apps.ms.gra.data.ConfigVfModules;
54 import org.onap.sdnc.apps.ms.gra.data.ConfigVfModulesRepository;
55 import org.onap.sdnc.apps.ms.gra.data.ConfigVnfs;
56 import org.onap.sdnc.apps.ms.gra.data.ConfigVnfsRepository;
57 import org.onap.sdnc.apps.ms.gra.data.OperationalContrailRouteAllottedResourcesRepository;
58 import org.onap.sdnc.apps.ms.gra.data.OperationalPortMirrorConfigurationsRepository;
59 import org.onap.sdnc.apps.ms.gra.data.OperationalPreloadData;
60 import org.onap.sdnc.apps.ms.gra.data.OperationalPreloadDataRepository;
61 import org.onap.sdnc.apps.ms.gra.data.OperationalServices;
62 import org.onap.sdnc.apps.ms.gra.data.OperationalServicesRepository;
63 import org.onap.sdnc.apps.ms.gra.swagger.OperationsApi;
64 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiInstanceReference;
65 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiNetworkOperationInformation;
66 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiNetworkOperationInformationBodyparam;
67 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiNetworkTopologyOperation;
68 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiNetworktopologyoperationOutput;
69 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPolicyUpdateNotifyOperation;
70 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPolicyupdatenotifyoperationInput;
71 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPolicyupdatenotifyoperationInputBodyparam;
72 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPolicyupdatenotifyoperationOutput;
73 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPortMirrorTopologyOperation;
74 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPortMirrorTopologyOperationInformation;
75 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPortMirrorTopologyOperationInformationBodyparam;
76 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPortmirrortopologyoperationOutput;
77 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloadNetworkTopologyOperation;
78 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloadTopologyResponseBody;
79 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloadVfModuleTopologyOperation;
80 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloaddataPreloadData;
81 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloadnetworktopologyoperationInputBodyparam;
82 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloadvfmoduletopologyoperationInputBodyparam;
83 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiRequestStatusEnumeration;
84 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServiceOperationInformation;
85 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServiceOperationInformationBodyparam;
86 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServiceTopologyOperation;
87 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServiceData;
88 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataNetworks;
89 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataNetworksNetwork;
90 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataNetworksNetworkNetworkData;
91 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataVnfs;
92 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataVnfsVnf;
93 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataVnfsVnfVnfData;
94 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules;
95 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule;
96 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData;
97 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicetopologyoperationOutput;
98 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVfModuleOperationInformation;
99 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVfModuleOperationInformationBodyparam;
100 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVfModuleTopologyOperation;
101 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVfmoduletopologyoperationOutput;
102 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfGetResourceRequest;
103 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfOperationInformation;
104 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfOperationInformationBodyparam;
105 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfTopologyOperation;
106 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfgetresourcerequestInput;
107 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfgetresourcerequestInputBodyparam;
108 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfgetresourcerequestOutput;
109 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnftopologyoperationOutput;
110 import org.springframework.beans.factory.annotation.Autowired;
111 import org.springframework.boot.autoconfigure.domain.EntityScan;
112 import org.springframework.context.annotation.ComponentScan;
113 import org.springframework.context.annotation.Import;
114 import org.springframework.http.HttpStatus;
115 import org.springframework.http.ResponseEntity;
116 import org.springframework.stereotype.Controller;
119 @ComponentScan(basePackages = { "org.onap.sdnc.apps.ms.gra.*", "org.onap.ccsdk.apps.services" })
120 @EntityScan("org.onap.sdnc.apps.ms.gra.*")
121 @Import(value = SvcLogicFactory.class)
122 public class OperationsApiController implements OperationsApi {
124 private static final String CALLED_STR = "{} called.";
125 private static final String MODULE_NAME = "GENERIC-RESOURCE-API";
126 private static final String SERVICE_OBJECT_PATH_PARAM = "service-object-path";
127 private static final String NETWORK_OBJECT_PATH_PARAM = "network-object-path";
128 private static final String VNF_OBJECT_PATH_PARAM = "vnf-object-path";
129 private static final String PNF_OBJECT_PATH_PARAM = "pnf-object-path";
130 private static final String VF_MODULE_OBJECT_PATH_PARAM = "vf-module-object-path";
131 private static final String PORT_MIRROR_OBJECT_PATH_PARAM = "port-mirror-object-path";
132 private static final String BACKGROUND_THREAD_STARTED_MESSAGE = "Start background thread";
133 private static final String BACKGROUND_THREAD_INFO = "Background thread: input conf_id is {}";
134 private static final String SKIP_MDSAL_UPDATE_PROP = "skip-mdsal-update";
135 private static final String ADDING_INPUT_DATA_LOG = "Adding INPUT data for {} [{}] input: {}";
136 private static final String ADDING_OPERATIONAL_DATA_LOG = "Adding OPERATIONAL data for {} [{}] operational-data: {}";
138 private final ObjectMapper objectMapper;
140 private final HttpServletRequest request;
143 protected SvcLogicServiceBase svc;
146 private ConfigPreloadDataRepository configPreloadDataRepository;
149 private OperationalPreloadDataRepository operationalPreloadDataRepository;
152 private ConfigServicesRepository configServicesRepository;
155 private OperationalServicesRepository operationalServicesRepository;
158 private ConfigNetworksRepository configNetworksRepository;
161 private ConfigVnfsRepository configVnfsRepository;
164 private ConfigVfModulesRepository configVfModulesRepository;
167 private ConfigContrailRouteAllottedResourcesRepository configContrailRouteAllottedResourcesRepository;
170 private OperationalContrailRouteAllottedResourcesRepository operationalContrailRouteAllottedResourcesRepository;
173 private ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository;
176 private OperationalPortMirrorConfigurationsRepository operationalPortMirrorConfigurationsRepository;
178 private static class Iso8601Util {
180 private static TimeZone timeZone = TimeZone.getTimeZone("UTC");
181 private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
183 private Iso8601Util() {
187 dateFormat.setTimeZone(timeZone);
190 private static String now() {
191 return dateFormat.format(new Date());
195 @org.springframework.beans.factory.annotation.Autowired
196 public OperationsApiController(ObjectMapper objectMapper, HttpServletRequest request) {
197 objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
198 objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
199 this.objectMapper = objectMapper;
200 this.request = request;
204 public Optional<ObjectMapper> getObjectMapper() {
205 return Optional.ofNullable(objectMapper);
209 public Optional<HttpServletRequest> getRequest() {
210 return Optional.ofNullable(request);
214 public ResponseEntity<GenericResourceApiPreloadNetworkTopologyOperation> operationsGENERICRESOURCEAPIpreloadNetworkTopologyOperationPost(
215 @Valid GenericResourceApiPreloadnetworktopologyoperationInputBodyparam graInput) {
216 final String svcOperation = "preload-network-topology-operation";
217 GenericResourceApiPreloadNetworkTopologyOperation retval = new GenericResourceApiPreloadNetworkTopologyOperation();
218 GenericResourceApiPreloadTopologyResponseBody resp = new GenericResourceApiPreloadTopologyResponseBody();
220 log.info(CALLED_STR, svcOperation);
221 if (hasInvalidPreloadNetwork(graInput)) {
222 log.debug("exiting {} because of null or empty preload-network-topology-information", svcOperation);
224 resp.setResponseCode("403");
225 resp.setResponseMessage("invalid input, null or empty preload-network-topology-information");
226 resp.setAckFinalIndicator("Y");
228 retval.setOutput(resp);
230 return new ResponseEntity<>(retval, HttpStatus.FORBIDDEN);
233 String preloadId = graInput.getInput().getPreloadNetworkTopologyInformation()
234 .getNetworkTopologyIdentifierStructure().getNetworkId();
235 String preloadType = "network";
237 resp.setSvcRequestId(graInput.getInput().getSdncRequestHeader().getSvcRequestId());
239 SvcLogicContext ctxIn = new SvcLogicContext();
241 GenericResourceApiPreloaddataPreloadData preloadData = null;
243 // Add input to SvcLogicContext
245 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(graInput.getInput()));
246 } catch (JsonProcessingException e) {
247 log.error("exiting {} due to parse error on input preload data", svcOperation);
248 resp.setResponseCode("500");
249 resp.setResponseMessage("internal error");
250 resp.setAckFinalIndicator("Y");
251 retval.setOutput(resp);
252 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
255 // Add config tree data to SvcLogicContext
257 preloadData = getConfigPreloadData(preloadId, preloadType);
258 ctxIn.mergeJson("preload-data", objectMapper.writeValueAsString(preloadData));
259 } catch (JsonProcessingException e) {
260 log.error("exiting {} due to parse error on saved config preload data", svcOperation);
261 resp.setResponseCode("500");
262 resp.setResponseMessage("internal error");
263 resp.setAckFinalIndicator("Y");
264 retval.setOutput(resp);
265 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
268 // Add operational tree data to SvcLogicContext
270 preloadData = getOperationalPreloadData(preloadId, preloadType);
271 ctxIn.mergeJson("operational-data", objectMapper.writeValueAsString(preloadData));
272 } catch (JsonProcessingException e) {
273 log.error("exiting {} due to parse error on saved operational preload data", svcOperation);
274 resp.setResponseCode("500");
275 resp.setResponseMessage("internal error");
276 resp.setAckFinalIndicator("Y");
277 retval.setOutput(resp);
278 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
283 // Any of these can throw a nullpointer exception
284 // execute should only throw a SvcLogicException
285 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
286 Properties respProps = ctxOut.toProperties();
288 resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
289 resp.setResponseCode(respProps.getProperty("error-code", "200"));
290 resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
292 if ("200".equals(resp.getResponseCode())) {
293 // If DG returns success, update database
294 String ctxJson = ctxOut.toJsonString("preload-data");
295 log.info("DG preload-data is {}", ctxJson);
296 GenericResourceApiPreloaddataPreloadData preloadToLoad = objectMapper.readValue(ctxJson,
297 GenericResourceApiPreloaddataPreloadData.class);
298 saveConfigPreloadData(preloadId, preloadType, preloadToLoad);
299 saveOperationalPreloadData(preloadId, preloadType, preloadToLoad);
302 } catch (NullPointerException npe) {
303 log.error("Caught NPE", npe);
304 resp.setAckFinalIndicator("true");
305 resp.setResponseCode("500");
306 resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
307 } catch (SvcLogicException e) {
308 log.error("Caught SvcLogicException", e);
309 resp.setAckFinalIndicator("true");
310 resp.setResponseCode("500");
311 resp.setResponseMessage(e.getMessage());
312 } catch (JsonMappingException e) {
313 log.error("Caught JsonMappingException", e);
314 resp.setAckFinalIndicator("true");
315 resp.setResponseCode("500");
316 resp.setResponseMessage(e.getMessage());
317 } catch (JsonProcessingException e) {
318 log.error("Caught JsonProcessingException", e);
319 resp.setAckFinalIndicator("true");
320 resp.setResponseCode("500");
321 resp.setResponseMessage(e.getMessage());
324 retval.setOutput(resp);
325 return (new ResponseEntity<>(retval, HttpStatus.valueOf(Integer.parseInt(resp.getResponseCode()))));
329 public ResponseEntity<GenericResourceApiPreloadVfModuleTopologyOperation> operationsGENERICRESOURCEAPIpreloadVfModuleTopologyOperationPost(
330 @Valid GenericResourceApiPreloadvfmoduletopologyoperationInputBodyparam graInput) {
331 final String svcOperation = "preload-vf-module-topology-operation";
332 GenericResourceApiPreloadVfModuleTopologyOperation retval = new GenericResourceApiPreloadVfModuleTopologyOperation();
333 GenericResourceApiPreloadTopologyResponseBody resp = new GenericResourceApiPreloadTopologyResponseBody();
335 log.info(CALLED_STR, svcOperation);
336 if (hasInvalidPreloadNetwork(graInput)) {
337 log.debug("exiting {} because of null or empty preload-network-topology-information", svcOperation);
339 resp.setResponseCode("403");
340 resp.setResponseMessage("invalid input, null or empty preload-network-topology-information");
341 resp.setAckFinalIndicator("Y");
343 retval.setOutput(resp);
345 return new ResponseEntity<>(retval, HttpStatus.FORBIDDEN);
348 String preloadId = graInput.getInput().getPreloadVfModuleTopologyInformation().getVfModuleTopology()
349 .getVfModuleTopologyIdentifier().getVfModuleName();
350 String preloadType = "vf-module";
352 resp.setSvcRequestId(graInput.getInput().getSdncRequestHeader().getSvcRequestId());
354 SvcLogicContext ctxIn = new SvcLogicContext();
356 GenericResourceApiPreloaddataPreloadData preloadData = null;
358 // Add input to SvcLogicContext
360 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(graInput.getInput()));
361 } catch (JsonProcessingException e) {
362 log.error("exiting {} due to parse error on input preload data", svcOperation);
363 resp.setResponseCode("500");
364 resp.setResponseMessage("internal error");
365 resp.setAckFinalIndicator("Y");
366 retval.setOutput(resp);
367 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
370 // Add config tree data to SvcLogicContext
372 preloadData = getConfigPreloadData(preloadId, preloadType);
373 ctxIn.mergeJson("preload-data", objectMapper.writeValueAsString(preloadData));
374 } catch (JsonProcessingException e) {
375 log.error("exiting {} due to parse error on saved config preload data", svcOperation);
376 resp.setResponseCode("500");
377 resp.setResponseMessage("internal error");
378 resp.setAckFinalIndicator("Y");
379 retval.setOutput(resp);
380 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
383 // Add operational tree data to SvcLogicContext
385 preloadData = getOperationalPreloadData(preloadId, preloadType);
386 ctxIn.mergeJson("operational-data", objectMapper.writeValueAsString(preloadData));
387 } catch (JsonProcessingException e) {
388 log.error("exiting {} due to parse error on saved operational preload data", svcOperation);
389 resp.setResponseCode("500");
390 resp.setResponseMessage("internal error");
391 resp.setAckFinalIndicator("Y");
392 retval.setOutput(resp);
393 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
398 // Any of these can throw a nullpointer exception
399 // execute should only throw a SvcLogicException
400 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
401 Properties respProps = ctxOut.toProperties();
403 resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
404 resp.setResponseCode(respProps.getProperty("error-code", "200"));
405 resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
407 if ("200".equals(resp.getResponseCode())) {
408 // If DG returns success, update database
409 String ctxJson = ctxOut.toJsonString("preload-data");
410 GenericResourceApiPreloaddataPreloadData preloadToLoad = objectMapper.readValue(ctxJson,
411 GenericResourceApiPreloaddataPreloadData.class);
412 saveConfigPreloadData(preloadId, preloadType, preloadToLoad);
413 saveOperationalPreloadData(preloadId, preloadType, preloadToLoad);
416 } catch (NullPointerException npe) {
417 resp.setAckFinalIndicator("true");
418 resp.setResponseCode("500");
419 resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
420 } catch (SvcLogicException e) {
421 resp.setAckFinalIndicator("true");
422 resp.setResponseCode("500");
423 resp.setResponseMessage(e.getMessage());
424 } catch (JsonMappingException e) {
425 resp.setAckFinalIndicator("true");
426 resp.setResponseCode("500");
427 resp.setResponseMessage(e.getMessage());
428 } catch (JsonProcessingException e) {
429 resp.setAckFinalIndicator("true");
430 resp.setResponseCode("500");
431 resp.setResponseMessage(e.getMessage());
434 retval.setOutput(resp);
435 return (new ResponseEntity<>(retval, HttpStatus.valueOf(Integer.parseInt(resp.getResponseCode()))));
438 private boolean hasInvalidPreloadNetwork(
439 GenericResourceApiPreloadnetworktopologyoperationInputBodyparam preloadData) {
440 return ((preloadData == null) || (preloadData.getInput() == null)
441 || (preloadData.getInput().getPreloadNetworkTopologyInformation() == null));
444 private boolean hasInvalidPreloadNetwork(
445 GenericResourceApiPreloadvfmoduletopologyoperationInputBodyparam preloadData) {
446 return ((preloadData == null) || (preloadData.getInput() == null)
447 || (preloadData.getInput().getPreloadVfModuleTopologyInformation() == null));
450 private boolean hasInvalidServiceId(GenericResourceApiServiceOperationInformation input) {
452 return input == null || input.getServiceInformation() == null
453 || input.getServiceInformation().getServiceInstanceId() == null
454 || input.getServiceInformation().getServiceInstanceId().length() == 0;
457 private boolean hasInvalidServiceId(GenericResourceApiNetworkOperationInformation input) {
459 return input == null || input.getServiceInformation() == null
460 || input.getServiceInformation().getServiceInstanceId() == null
461 || input.getServiceInformation().getServiceInstanceId().length() == 0;
464 private boolean hasInvalidServiceId(GenericResourceApiVnfOperationInformation input) {
466 return input == null || input.getServiceInformation() == null
467 || input.getServiceInformation().getServiceInstanceId() == null
468 || input.getServiceInformation().getServiceInstanceId().length() == 0;
471 private boolean hasInvalidServiceId(GenericResourceApiVfModuleOperationInformation input) {
473 return input == null || input.getServiceInformation() == null
474 || input.getServiceInformation().getServiceInstanceId() == null
475 || input.getServiceInformation().getServiceInstanceId().length() == 0;
478 private boolean hasInvalidServiceId(GenericResourceApiPortMirrorTopologyOperationInformation input) {
480 return input == null || input.getServiceInformation() == null
481 || input.getServiceInformation().getServiceInstanceId() == null
482 || input.getServiceInformation().getServiceInstanceId().length() == 0;
485 private boolean hasInvalidServiceId(GenericResourceApiVnfgetresourcerequestInput input) {
487 return input == null || input.getServiceInformation() == null
488 || input.getServiceInformation().getServiceInstanceId() == null
489 || input.getServiceInformation().getServiceInstanceId().length() == 0;
492 private boolean hasInvalidVnfId(GenericResourceApiVfModuleOperationInformation input) {
494 return input == null || input.getVnfInformation() == null
495 || input.getVnfInformation().getVnfId() == null
496 || input.getVnfInformation().getVnfId().length() == 0;
499 private boolean hasInvalidConfigurationId(GenericResourceApiPortMirrorTopologyOperationInformation input) {
500 return input.getConfigurationInformation() == null
501 || input.getConfigurationInformation().getConfigurationId() == null
502 || input.getConfigurationInformation().getConfigurationId().length() == 0;
505 private boolean hasInvalidPolicyUpdateInput(GenericResourceApiPolicyupdatenotifyoperationInput input) {
506 return (input.getPolicyName() == null) || (input.getUpdateType() == null) || (input.getVersionId() == null);
509 private GenericResourceApiPreloaddataPreloadData getConfigPreloadData(String preloadId, String preloadType)
510 throws JsonProcessingException {
512 List<ConfigPreloadData> configPreloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
515 if (configPreloadData.isEmpty()) {
518 return (objectMapper.readValue(configPreloadData.get(0).getPreloadData(),
519 GenericResourceApiPreloaddataPreloadData.class));
523 private GenericResourceApiPreloaddataPreloadData getOperationalPreloadData(String preloadId, String preloadType)
524 throws JsonProcessingException {
526 List<OperationalPreloadData> configPreloadData = operationalPreloadDataRepository
527 .findByPreloadIdAndPreloadType(preloadId, preloadType);
529 if (configPreloadData.isEmpty()) {
532 return (objectMapper.readValue(configPreloadData.get(0).getPreloadData(),
533 GenericResourceApiPreloaddataPreloadData.class));
537 private void saveConfigPreloadData(String preloadId, String preloadType,
538 GenericResourceApiPreloaddataPreloadData preloadData) throws JsonProcessingException {
540 configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
541 configPreloadDataRepository
542 .save(new ConfigPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadData)));
546 private void saveOperationalPreloadData(String preloadId, String preloadType,
547 GenericResourceApiPreloaddataPreloadData preloadData) throws JsonProcessingException {
549 operationalPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
550 operationalPreloadDataRepository
551 .save(new OperationalPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadData)));
555 private String getConfigServiceDataAsString(String svcInstanceId) throws JsonProcessingException {
556 return(objectMapper.writeValueAsString(getConfigServiceData(svcInstanceId)));
559 private GenericResourceApiServicedataServiceData getConfigServiceData(String svcInstanceId)
560 throws JsonProcessingException {
562 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
564 if (configServices.isEmpty()) {
568 GenericResourceApiServicedataServiceData svcData = (objectMapper.readValue(configServices.get(0).getSvcData(), GenericResourceApiServicedataServiceData.class));
571 List<ConfigNetworks> configNetworks = configNetworksRepository.findBySvcInstanceId(svcInstanceId);
572 GenericResourceApiServicedataServicedataNetworks networks = new GenericResourceApiServicedataServicedataNetworks();
573 for (ConfigNetworks configNetwork : configNetworks) {
574 GenericResourceApiServicedataServicedataNetworksNetwork network = new GenericResourceApiServicedataServicedataNetworksNetwork();
575 network.setNetworkId(configNetwork.getNetworkId());
576 network.setNetworkData(objectMapper.readValue(configNetwork.getNetworkData(), GenericResourceApiServicedataServicedataNetworksNetworkNetworkData.class));
577 networks.addNetworkItem(network);
579 svcData.setNetworks(networks);
582 List<ConfigVnfs> configVnfs = configVnfsRepository.findBySvcInstanceId(svcInstanceId);
583 GenericResourceApiServicedataServicedataVnfs vnfs = new GenericResourceApiServicedataServicedataVnfs();
584 for (ConfigVnfs configVnf : configVnfs) {
585 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
586 vnf.setVnfId(configVnf.getVnfId());
587 GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = objectMapper.readValue(configVnf.getVnfData(), GenericResourceApiServicedataServicedataVnfsVnfVnfData.class);
589 // Get vf modules for this vnf
590 List<ConfigVfModules> configVfModules = configVfModulesRepository.findBySvcInstanceIdAndVnfId(svcInstanceId, configVnf.getVnfId());
591 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules vfModules = new GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules();
592 for (ConfigVfModules configVfModule : configVfModules) {
593 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule vfModule = new GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule();
594 vfModule.setVfModuleId(configVfModule.getVfModuleId());
595 vfModule.setVfModuleData(objectMapper.readValue(configVfModule.getVfModuleData(), GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData.class));
596 vfModules.addVfModuleItem(vfModule);
598 vnfData.setVfModules(vfModules);
599 vnf.setVnfData(vnfData);
600 vnfs.addVnfItem(vnf);
602 svcData.setVnfs(vnfs);
606 private void saveSvcData(ConfigServices configService, String svcDataAsString) throws JsonProcessingException {
607 if (svcDataAsString == null) {
608 configServicesRepository.save(configService);
611 saveSvcData(configService, objectMapper.readValue(svcDataAsString, GenericResourceApiServicedataServiceData.class));
614 private void saveSvcData(ConfigServices configService, GenericResourceApiServicedataServiceData svcData) throws JsonProcessingException {
615 if (svcData == null) {
616 configServicesRepository.save(configService);
620 String svcInstanceId = configService.getSvcInstanceId();
623 GenericResourceApiServicedataServicedataNetworks networks = svcData.getNetworks();
624 if (networks != null) {
625 List<GenericResourceApiServicedataServicedataNetworksNetwork> networkItems = networks.getNetwork();
626 if ((networkItems != null) && !networkItems.isEmpty()) {
627 for (GenericResourceApiServicedataServicedataNetworksNetwork networkItem : networkItems) {
628 List<ConfigNetworks> configNetworks = configNetworksRepository
629 .findBySvcInstanceIdAndNetworkId(svcInstanceId, networkItem.getNetworkId());
630 ConfigNetworks configNetwork;
631 if ((configNetworks == null) || (configNetworks.isEmpty())) {
632 configNetwork = new ConfigNetworks(svcInstanceId, networkItem.getNetworkId());
634 configNetwork = configNetworks.get(0);
636 configNetwork.setNetworkData(objectMapper.writeValueAsString(networkItem.getNetworkData()));
637 configNetworksRepository.save(configNetwork);
640 svcData.setNetworks(null);
644 GenericResourceApiServicedataServicedataVnfs vnfs = svcData.getVnfs();
646 List<GenericResourceApiServicedataServicedataVnfsVnf> vnfItems = vnfs.getVnf();
647 if ((vnfItems != null) && !vnfItems.isEmpty()) {
648 for (GenericResourceApiServicedataServicedataVnfsVnf vnfItem : vnfItems) {
649 String vnfId = vnfItem.getVnfId();
650 List<ConfigVnfs> configVnfs = configVnfsRepository.findBySvcInstanceIdAndVnfId(svcInstanceId,
652 ConfigVnfs configVnf;
653 if ((configVnfs == null) || (configVnfs.isEmpty())) {
654 configVnf = new ConfigVnfs(svcInstanceId, vnfId);
656 configVnf = configVnfs.get(0);
659 GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnfItem.getVnfData();
662 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules vfModules = vnfData.getVfModules();
663 if (vfModules != null) {
664 List<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule> vfModuleItems = vfModules
666 if ((vfModuleItems != null) && !vfModuleItems.isEmpty()) {
667 for (GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule vfModuleItem : vfModuleItems) {
668 List<ConfigVfModules> configVfModules = configVfModulesRepository
669 .findBySvcInstanceIdAndVnfIdAndVfModuleId(svcInstanceId, vnfId,
670 vfModuleItem.getVfModuleId());
671 ConfigVfModules configVfModule;
672 if ((configVfModules == null) || (configVfModules.isEmpty())) {
673 configVfModule = new ConfigVfModules(svcInstanceId, vnfId,
674 vfModuleItem.getVfModuleId());
676 configVfModule = configVfModules.get(0);
678 configVfModule.setVfModuleData(
679 objectMapper.writeValueAsString(vfModuleItem.getVfModuleData()));
680 configVfModulesRepository.save(configVfModule);
682 vnfData.setVfModules(null);
684 configVnf.setVnfData(objectMapper.writeValueAsString(vnfData));
685 configVnfsRepository.save(configVnf);
690 svcData.setVnfs(null);
693 configService.setSvcData(objectMapper.writeValueAsString(svcData));
694 configServicesRepository.save(configService);
698 public ResponseEntity<GenericResourceApiNetworkTopologyOperation> operationsGENERICRESOURCEAPInetworkTopologyOperationPost(
699 @Valid GenericResourceApiNetworkOperationInformationBodyparam input) throws RestException {
700 final String svcOperation = "network-topology-operation";
701 GenericResourceApiNetworkTopologyOperation retval = new GenericResourceApiNetworkTopologyOperation();
702 GenericResourceApiNetworktopologyoperationOutput resp = new GenericResourceApiNetworktopologyoperationOutput();
704 log.info(CALLED_STR, svcOperation);
705 // Verify input contains service instance id
706 if (hasInvalidServiceId(input.getInput())) {
707 log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
709 resp.setResponseCode("404");
710 resp.setResponseMessage("null or empty service-instance-id");
711 resp.setAckFinalIndicator("Y");
713 retval.setOutput(resp);
715 return new ResponseEntity<>(retval, HttpStatus.OK);
718 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
720 SvcLogicContext ctxIn = new SvcLogicContext();
722 // Add input to SvcLogicContext
724 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
725 } catch (JsonProcessingException e) {
726 log.error("exiting {} due to parse error on input data", svcOperation);
727 resp.setResponseCode("500");
728 resp.setResponseMessage("internal error");
729 resp.setAckFinalIndicator("Y");
730 retval.setOutput(resp);
731 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
734 // Add config tree data to SvcLogicContext
735 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
736 ConfigServices configService = null;
737 String svcData = null;
738 if (configServices != null && !configServices.isEmpty()) {
739 configService = configServices.get(0);
741 svcData = getConfigServiceDataAsString(svcInstanceId);
742 } catch (JsonProcessingException e) {
743 log.error("exiting {} due to parse error on service data", svcOperation);
744 resp.setResponseCode("500");
745 resp.setResponseMessage("internal error");
746 resp.setAckFinalIndicator("Y");
747 retval.setOutput(resp);
748 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
751 if (svcData != null) {
752 ctxIn.mergeJson("service-data", svcData);
754 log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
756 resp.setResponseCode("404");
757 resp.setResponseMessage("invalid input: the service-instance does not have any service data in SDNC");
758 resp.setAckFinalIndicator("Y");
760 retval.setOutput(resp);
762 return new ResponseEntity<>(retval, HttpStatus.OK);
765 // Add operational tree data to SvcLogicContext
766 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
767 OperationalServices operService = null;
768 boolean saveOperationalData = false;
770 if (operServices != null && !operServices.isEmpty()) {
771 operService = operServices.get(0);
772 ctxIn.mergeJson("operational-data", operService.getSvcData());
774 operService = new OperationalServices(svcInstanceId, null, null);
777 // Update service status info in config entry from input
778 configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
779 configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
780 configService.setServiceStatusRpcName(svcOperation);
782 String ctxSvcDataJson = svcData;
786 // Any of these can throw a nullpointer exception
787 // execute should only throw a SvcLogicException
788 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
789 Properties respProps = ctxOut.toProperties();
791 resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
792 resp.setResponseCode(respProps.getProperty("error-code", "200"));
793 resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
798 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
800 if ("200".equals(resp.getResponseCode())) {
802 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
803 serviceReference.setInstanceId(svcInstanceId);
804 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
805 resp.setServiceResponseInformation(serviceReference);
807 GenericResourceApiInstanceReference networkReference = new GenericResourceApiInstanceReference();
808 networkReference.setInstanceId(respProps.getProperty("networkId"));
809 networkReference.setObjectPath(respProps.getProperty(NETWORK_OBJECT_PATH_PARAM));
810 resp.setNetworkResponseInformation(networkReference);
812 // If DG returns success, update svcData in config and operational trees
813 // and remember to save operational data.
814 ctxSvcDataJson = ctxOut.toJsonString("service-data");
815 operService.setSvcData(ctxSvcDataJson);
816 saveOperationalData = true;
819 } catch (NullPointerException npe) {
820 resp.setAckFinalIndicator("true");
821 resp.setResponseCode("500");
822 resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
823 } catch (SvcLogicException e) {
824 resp.setAckFinalIndicator("true");
825 resp.setResponseCode("500");
826 resp.setResponseMessage(e.getMessage());
829 // Update status in config services entry
831 configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
832 configService.setServiceStatusResponseCode(resp.getResponseCode());
833 configService.setServiceStatusResponseMessage(resp.getResponseMessage());
834 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
839 saveSvcData(configService, ctxSvcDataJson);
840 } catch (JsonProcessingException e) {
841 log.error("exiting {} due to error saving service data", svcOperation);
842 resp.setResponseCode("500");
843 resp.setResponseMessage("internal error");
844 resp.setAckFinalIndicator("Y");
845 retval.setOutput(resp);
846 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
849 // If necessary, sync status to operation service entry and save
850 if (saveOperationalData) {
851 operService.setServiceStatus(configService.getServiceStatus());
852 operationalServicesRepository.save(operService);
854 retval.setOutput(resp);
856 return (new ResponseEntity<>(retval, HttpStatus.OK));
860 public ResponseEntity<GenericResourceApiServiceTopologyOperation> operationsGENERICRESOURCEAPIserviceTopologyOperationPost(
861 @Valid GenericResourceApiServiceOperationInformationBodyparam input) throws RestException {
862 final String svcOperation = "service-topology-operation";
863 GenericResourceApiServiceTopologyOperation retval = new GenericResourceApiServiceTopologyOperation();
864 GenericResourceApiServicetopologyoperationOutput resp = new GenericResourceApiServicetopologyoperationOutput();
866 log.info(CALLED_STR, svcOperation);
868 // Verify input contains service instance id
869 if (hasInvalidServiceId(input.getInput())) {
870 log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
872 resp.setResponseCode("404");
873 resp.setResponseMessage("null or empty service-instance-id");
874 resp.setAckFinalIndicator("Y");
876 retval.setOutput(resp);
878 return new ResponseEntity<>(retval, HttpStatus.OK);
881 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
883 SvcLogicContext ctxIn = new SvcLogicContext();
885 // Add input to SvcLogicContext
887 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
888 } catch (JsonProcessingException e) {
889 log.error("exiting {} due to parse error on input data", svcOperation);
890 resp.setResponseCode("500");
891 resp.setResponseMessage("internal error");
892 resp.setAckFinalIndicator("Y");
893 retval.setOutput(resp);
894 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
897 // Add config tree data to SvcLogicContext
898 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
899 ConfigServices configService = null;
900 String svcData = null;
901 if (configServices != null && !configServices.isEmpty()) {
902 configService = configServices.get(0);
904 svcData = getConfigServiceDataAsString(svcInstanceId);
905 ctxIn.mergeJson("service-data", svcData);
906 } catch (JsonProcessingException e) {
907 log.error("exiting {} due to parse error on service data", svcOperation);
908 resp.setResponseCode("500");
909 resp.setResponseMessage("internal error");
910 resp.setAckFinalIndicator("Y");
911 retval.setOutput(resp);
912 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
915 configService = new ConfigServices(svcInstanceId, null);
919 // Add operational tree data to SvcLogicContext
920 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
921 OperationalServices operService = null;
922 boolean saveOperationalData = false;
924 if (operServices != null && !operServices.isEmpty()) {
925 operService = operServices.get(0);
926 ctxIn.mergeJson("operational-data", operService.getSvcData());
928 operService = new OperationalServices(svcInstanceId, null, null);
931 // Update service status info in config entry from input
932 configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
933 configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
934 configService.setServiceStatusRpcName(svcOperation);
936 String ctxSvcDataJson = svcData;
939 // Any of these can throw a nullpointer exception
940 // execute should only throw a SvcLogicException
941 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
942 Properties respProps = ctxOut.toProperties();
944 resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
945 resp.setResponseCode(respProps.getProperty("error-code", "200"));
946 resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
949 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
951 if ("200".equals(resp.getResponseCode())) {
952 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
953 serviceReference.setInstanceId(svcInstanceId);
954 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
955 resp.setServiceResponseInformation(serviceReference);
957 // If DG returns success, update svcData in config and operational trees
958 // and remember to save operational data.
959 ctxSvcDataJson= ctxOut.toJsonString("service-data");
961 operService.setSvcData(ctxSvcDataJson);
962 saveOperationalData = true;
965 } catch (NullPointerException npe) {
966 resp.setAckFinalIndicator("true");
967 resp.setResponseCode("500");
968 resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
969 } catch (SvcLogicException e) {
970 resp.setAckFinalIndicator("true");
971 resp.setResponseCode("500");
972 resp.setResponseMessage(e.getMessage());
975 // Update status in config services entry
977 configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
978 configService.setServiceStatusResponseCode(resp.getResponseCode());
979 configService.setServiceStatusResponseMessage(resp.getResponseMessage());
980 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
984 saveSvcData(configService, ctxSvcDataJson);
985 } catch (JsonProcessingException e) {
986 log.error("exiting {} due to error saving service data", svcOperation);
987 resp.setResponseCode("500");
988 resp.setResponseMessage("internal error");
989 resp.setAckFinalIndicator("Y");
990 retval.setOutput(resp);
991 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
994 // If necessary, sync status to operation service entry and save
995 if (saveOperationalData) {
996 operService.setServiceStatus(configService.getServiceStatus());
997 operationalServicesRepository.save(operService);
999 retval.setOutput(resp);
1000 return (new ResponseEntity<>(retval, HttpStatus.OK));
1005 public ResponseEntity<GenericResourceApiVnfTopologyOperation> operationsGENERICRESOURCEAPIvnfTopologyOperationPost(
1006 @Valid GenericResourceApiVnfOperationInformationBodyparam input)
1007 throws RestException {
1008 final String svcOperation = "vnf-topology-operation";
1009 GenericResourceApiVnfTopologyOperation retval = new GenericResourceApiVnfTopologyOperation();
1010 GenericResourceApiVnftopologyoperationOutput resp = new GenericResourceApiVnftopologyoperationOutput();
1012 log.info(CALLED_STR, svcOperation);
1013 // Verify input contains service instance id
1014 if(hasInvalidServiceId(input.getInput())) {
1015 log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
1017 resp.setResponseCode("404");
1018 resp.setResponseMessage("null or empty service-instance-id");
1019 resp.setAckFinalIndicator("Y");
1021 retval.setOutput(resp);
1023 return new ResponseEntity<>(retval, HttpStatus.OK);
1026 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1027 String vnfId = null;
1029 if((input.getInput() != null) && (input.getInput().getVnfInformation() != null)) {
1030 vnfId = input.getInput().getVnfInformation().getVnfId();
1033 SvcLogicContext ctxIn = new SvcLogicContext();
1035 // Add input to SvcLogicContext
1037 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1039 catch(JsonProcessingException e) {
1040 log.error("exiting {} due to parse error on input data", svcOperation);
1041 resp.setResponseCode("500");
1042 resp.setResponseMessage("internal error");
1043 resp.setAckFinalIndicator("Y");
1044 retval.setOutput(resp);
1045 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1048 // Add config tree data to SvcLogicContext
1049 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1050 ConfigServices configService = null;
1051 String svcData = null;
1052 if (configServices != null && !configServices.isEmpty()) {
1053 configService = configServices.get(0);
1055 svcData = getConfigServiceDataAsString(svcInstanceId);
1056 } catch (JsonProcessingException e) {
1057 log.error("exiting {} due to parse error on service data", svcOperation);
1058 resp.setResponseCode("500");
1059 resp.setResponseMessage("internal error");
1060 resp.setAckFinalIndicator("Y");
1061 retval.setOutput(resp);
1062 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1065 if (svcData != null) {
1066 ctxIn.mergeJson("service-data", svcData);
1068 log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
1070 resp.setResponseCode("404");
1071 resp.setResponseMessage("invalid input: the service-instance does not have any service data in SDNC");
1072 resp.setAckFinalIndicator("Y");
1074 retval.setOutput(resp);
1076 return new ResponseEntity<>(retval, HttpStatus.OK);
1079 // Add operational tree data to SvcLogicContext
1080 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
1081 OperationalServices operService = null;
1082 boolean saveOperationalData = false;
1084 if(operServices != null && !operServices.isEmpty()) {
1085 operService = operServices.get(0);
1086 ctxIn.mergeJson("operational-data", operService.getSvcData());
1089 operService = new OperationalServices(svcInstanceId, null, null);
1092 // Update service status info in config entry from input
1093 configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1094 configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1095 configService.setServiceStatusRpcName(svcOperation);
1097 String ctxSvcDataJson = svcData;
1101 // Any of these can throw a nullpointer exception
1102 // execute should only throw a SvcLogicException
1103 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1104 Properties respProps = ctxOut.toProperties();
1106 resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
1107 resp.setResponseCode(respProps.getProperty("error-code", "200"));
1108 resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
1111 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1113 if("200".equals(resp.getResponseCode())) {
1115 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
1116 serviceReference.setInstanceId(svcInstanceId);
1117 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
1118 resp.setServiceResponseInformation(serviceReference);
1121 vnfId = respProps.getProperty("vnfId");
1123 GenericResourceApiInstanceReference vnfReference = new GenericResourceApiInstanceReference();
1124 vnfReference.setInstanceId(vnfId);
1125 vnfReference.setObjectPath(respProps.getProperty(VNF_OBJECT_PATH_PARAM));
1126 resp.setVnfResponseInformation(vnfReference);
1128 // If DG returns success, update svcData in config and operational trees
1129 // and remember to save operational data.
1130 ctxSvcDataJson = ctxOut.toJsonString("service-data");
1131 operService.setSvcData(ctxSvcDataJson);
1132 saveOperationalData = true;
1136 catch(NullPointerException npe) {
1137 resp.setAckFinalIndicator("Y");
1138 resp.setResponseCode("500");
1139 resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
1141 catch(SvcLogicException e) {
1142 resp.setAckFinalIndicator("Y");
1143 resp.setResponseCode("500");
1144 resp.setResponseMessage(e.getMessage());
1147 // Update status in config services entry
1149 configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
1150 configService.setServiceStatusResponseCode(resp.getResponseCode());
1151 configService.setServiceStatusResponseMessage(resp.getResponseMessage());
1152 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
1154 // Save service data
1156 saveSvcData(configService, ctxSvcDataJson);
1157 } catch (JsonProcessingException e) {
1158 log.error("exiting {} due to error saving service data", svcOperation);
1159 resp.setResponseCode("500");
1160 resp.setResponseMessage("internal error");
1161 resp.setAckFinalIndicator("Y");
1162 retval.setOutput(resp);
1163 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1167 // If necessary, sync status to operation service entry and save
1168 if(saveOperationalData) {
1169 operService.setServiceStatus(configService.getServiceStatus());
1170 operationalServicesRepository.save(operService);
1173 if(resp.getAckFinalIndicator().equals("N")) {
1174 // Spawn background thread to invoke the Async DG
1175 Runnable backgroundThread = () -> {
1176 log.info(BACKGROUND_THREAD_STARTED_MESSAGE);
1177 processAsyncVnfTopologyOperation(svcOperation, input);
1179 new Thread(backgroundThread).start();
1182 log.info("Returned {} for {} [{}] {}.", resp.getResponseCode(), svcOperation, vnfId, resp.getResponseMessage());
1183 retval.setOutput(resp);
1184 return (new ResponseEntity<>(retval, HttpStatus.OK));
1187 public void processAsyncVnfTopologyOperation(String parentOperation, @Valid GenericResourceApiVnfOperationInformationBodyparam input) {
1188 final String svcOperation = "vnf-topology-operation-async";
1189 GenericResourceApiVnftopologyoperationOutput resp = new GenericResourceApiVnftopologyoperationOutput();
1191 log.info(CALLED_STR, svcOperation);
1192 // Verify input contains service instance id
1193 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1194 String vnfId = input.getInput().getVnfInformation().getVnfId();
1196 SvcLogicContext ctxIn = new SvcLogicContext();
1198 // Add input to SvcLogicContext
1200 ctxIn.mergeJson(parentOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1201 } catch (JsonProcessingException e) {
1202 log.error("exiting {} due to parse error on input data", svcOperation);
1206 // Add config tree data to SvcLogicContext
1207 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1208 ConfigServices configService = null;
1209 String svcData = null;
1210 if (configServices != null && !configServices.isEmpty()) {
1211 configService = configServices.get(0);
1213 svcData = getConfigServiceDataAsString(svcInstanceId);
1214 } catch (JsonProcessingException e) {
1215 log.error("exiting {} due to parse error on service data", svcOperation);
1219 if (svcData != null) {
1220 ctxIn.mergeJson("service-data", svcData);
1222 log.error("exiting {} because there is no service data with id [{}] in SDN", svcOperation, svcInstanceId);
1227 // Add operational tree data to SvcLogicContext
1228 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
1229 OperationalServices operService = null;
1231 if(operServices != null && !operServices.isEmpty()) {
1232 operService = operServices.get(0);
1233 ctxIn.mergeJson("operational-data", operService.getSvcData());
1236 operService = new OperationalServices(svcInstanceId, null, null);
1239 // Update service status info in config entry from input
1240 configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1241 configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1242 configService.setServiceStatusRpcName(svcOperation);
1244 String ctxSvcDataJson = svcData;
1248 // Any of these can throw a nullpointer exception
1249 // execute should only throw a SvcLogicException
1250 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1251 Properties respProps = ctxOut.toProperties();
1253 resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
1254 resp.setResponseCode(respProps.getProperty("error-code", "200"));
1255 resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
1258 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1260 if("200".equals(resp.getResponseCode())) {
1261 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
1262 serviceReference.setInstanceId(svcInstanceId);
1263 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
1264 resp.setServiceResponseInformation(serviceReference);
1267 vnfId = respProps.getProperty("vnfId");
1269 GenericResourceApiInstanceReference vnfReference = new GenericResourceApiInstanceReference();
1270 vnfReference.setInstanceId(vnfId);
1271 vnfReference.setObjectPath(respProps.getProperty(VNF_OBJECT_PATH_PARAM));
1272 resp.setVnfResponseInformation(vnfReference);
1274 // If DG returns success, update svcData in config and operational trees
1275 // and remember to save operational data.
1276 ctxSvcDataJson = ctxOut.toJsonString("service-data");
1277 operService.setSvcData(ctxSvcDataJson);
1279 // Update status in config services entry
1281 configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
1282 configService.setServiceStatusResponseCode(resp.getResponseCode());
1283 configService.setServiceStatusResponseMessage(resp.getResponseMessage());
1284 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
1286 // Save service data
1288 saveSvcData(configService, ctxSvcDataJson);
1289 } catch (JsonProcessingException e) {
1290 log.error("exiting {} due to error saving service data", svcOperation);
1294 // Update operational tree
1295 operService.setServiceStatus(configService.getServiceStatus());
1296 operationalServicesRepository.save(operService);
1297 log.info("Returned SUCCESS for {} [{}]", svcOperation, vnfId);
1300 catch(Exception e) {
1301 log.error("Caught Exception updating configuration status in SDN for {} [{}] \n", svcOperation, vnfId);
1306 public ResponseEntity<GenericResourceApiVfModuleTopologyOperation> operationsGENERICRESOURCEAPIvfModuleTopologyOperationPost(
1307 @Valid GenericResourceApiVfModuleOperationInformationBodyparam input)
1308 throws RestException {
1309 final String svcOperation = "vf-module-topology-operation";
1310 GenericResourceApiVfModuleTopologyOperation retval = new GenericResourceApiVfModuleTopologyOperation();
1311 GenericResourceApiVfmoduletopologyoperationOutput resp = new GenericResourceApiVfmoduletopologyoperationOutput();
1313 log.info(CALLED_STR, svcOperation);
1314 // Verify input contains service instance id
1315 if (hasInvalidServiceId(input.getInput())) {
1316 log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
1318 resp.setResponseCode("404");
1319 resp.setResponseMessage("null or empty service-instance-id");
1320 resp.setAckFinalIndicator("Y");
1321 retval.setOutput(resp);
1322 return new ResponseEntity<>(retval, HttpStatus.OK);
1325 // Verify input contains vnf-id
1326 if (hasInvalidVnfId(input.getInput())) {
1327 log.debug("exiting {} because of null or empty vnf-id", svcOperation);
1329 resp.setResponseCode("404");
1330 resp.setResponseMessage("null or empty vnf-id");
1331 resp.setAckFinalIndicator("Y");
1332 retval.setOutput(resp);
1333 return new ResponseEntity<>(retval, HttpStatus.OK);
1336 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1337 String vnfId = input.getInput().getVnfInformation().getVnfId();
1338 String vfModuleId = input.getInput().getVfModuleInformation().getVfModuleId();
1340 SvcLogicContext ctxIn = new SvcLogicContext();
1342 // Add input to SvcLogicContext
1344 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1345 } catch (JsonProcessingException e) {
1346 log.error("exiting {} due to parse error on input data", svcOperation);
1347 resp.setResponseCode("500");
1348 resp.setResponseMessage("internal error");
1349 resp.setAckFinalIndicator("Y");
1350 retval.setOutput(resp);
1351 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1354 // Add config tree data to SvcLogicContext
1355 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1356 ConfigServices configService = null;
1357 String svcData = null;
1358 if (configServices != null && !configServices.isEmpty()) {
1359 configService = configServices.get(0);
1361 svcData = getConfigServiceDataAsString(svcInstanceId);
1362 } catch (JsonProcessingException e) {
1363 log.error("exiting {} due to parse error on service data", svcOperation);
1364 resp.setResponseCode("500");
1365 resp.setResponseMessage("internal error");
1366 resp.setAckFinalIndicator("Y");
1367 retval.setOutput(resp);
1368 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1371 if (svcData != null) {
1372 ctxIn.mergeJson("service-data", svcData);
1374 log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
1376 resp.setResponseCode("404");
1377 resp.setResponseMessage("invalid input: the service-instance does not have any service data in SDNC");
1378 resp.setAckFinalIndicator("Y");
1380 retval.setOutput(resp);
1382 return new ResponseEntity<>(retval, HttpStatus.OK);
1385 // Add operational tree data to SvcLogicContext
1386 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
1387 OperationalServices operService = null;
1389 if (operServices != null && !operServices.isEmpty()) {
1390 operService = operServices.get(0);
1391 log.info("Read ({}) data for [{}] operational-data: {}",
1392 "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", svcInstanceId, operService.getSvcData().toString());
1393 //ctxIn.mergeJson("operational-data", operService.getSvcData());
1395 log.info("No operational-data found in OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS for [{}]", svcInstanceId);
1396 operService = new OperationalServices(svcInstanceId, null, null);
1399 // Update service status info in config entry from input
1400 configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1401 configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1402 configService.setServiceStatusRpcName(svcOperation);
1404 String ackFinal = "Y";
1405 String skipMdsalUpdate;
1407 String ctxSvcDataJson = svcData;
1410 // Any of these can throw a nullpointer exception
1411 // execute should only throw a SvcLogicException
1412 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1413 Properties respProps = ctxOut.toProperties();
1415 ackFinal = respProps.getProperty("ack-final", "Y");
1416 skipMdsalUpdate = respProps.getProperty("skip-mdsal-update", "N");
1417 log.info("ackFinal [{}], skipMdsalUpdate [{}]", ackFinal, skipMdsalUpdate);
1419 resp.setAckFinalIndicator(ackFinal);
1420 resp.setResponseCode(respProps.getProperty("error-code", "200"));
1421 resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
1423 // Update status in config services entry
1424 configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
1425 configService.setServiceStatusResponseCode(resp.getResponseCode());
1426 configService.setServiceStatusResponseMessage(resp.getResponseMessage());
1427 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
1429 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1431 if ("200".equals(resp.getResponseCode())) {
1433 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
1434 serviceReference.setInstanceId(svcInstanceId);
1435 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
1436 resp.setServiceResponseInformation(serviceReference);
1438 GenericResourceApiInstanceReference vnfReference = new GenericResourceApiInstanceReference();
1439 vnfReference.setInstanceId(vnfId);
1440 vnfReference.setObjectPath(respProps.getProperty(VNF_OBJECT_PATH_PARAM));
1441 resp.setVnfResponseInformation(vnfReference);
1443 GenericResourceApiInstanceReference vfModuleReference = new GenericResourceApiInstanceReference();
1444 vnfReference.setInstanceId(vfModuleId);
1445 vnfReference.setObjectPath(respProps.getProperty(VF_MODULE_OBJECT_PATH_PARAM));
1446 resp.setVnfResponseInformation(vfModuleReference);
1448 if (skipMdsalUpdate.equals("N")) {
1449 // If DG returns success,
1450 // ONLY update svcData in config and operational trees
1451 // and remember to save operational data when skip-mdsal-update is Y in ctx.
1452 String ctxJson = ctxOut.toJsonString("service-data");
1453 log.info("Saving service-data in SDN because skiMdsalUpdate is {}", skipMdsalUpdate);
1454 saveSvcData(configService, ctxJson);
1456 log.info("Copying service-data to operational-data");
1457 operService.setSvcData(ctxJson);
1458 operService.setServiceStatus(configService.getServiceStatus());
1459 operationalServicesRepository.save(operService);
1462 } catch (NullPointerException npe) {
1463 resp.setAckFinalIndicator("Y");
1464 resp.setResponseCode("500");
1465 resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
1466 } catch (SvcLogicException e) {
1467 resp.setAckFinalIndicator("Y");
1468 } catch (JsonProcessingException e) {
1469 resp.setAckFinalIndicator("Y");
1470 resp.setResponseCode("500");
1471 resp.setResponseMessage("Internal error");
1472 log.error("exiting {} due to error updating service data", svcOperation, e);
1475 if (ackFinal.equals("N")) {
1476 // Spawn background thread to invoke the Async DG
1477 Runnable backgroundThread = new Runnable() {
1479 log.info(BACKGROUND_THREAD_STARTED_MESSAGE);
1480 processAsyncVfModuleTopologyOperation(svcOperation, input);
1483 new Thread(backgroundThread).start();
1485 retval.setOutput(resp);
1486 return (new ResponseEntity<>(retval, HttpStatus.OK));
1489 public void processAsyncVfModuleTopologyOperation( String parentOperation,
1490 @Valid GenericResourceApiVfModuleOperationInformationBodyparam input) {
1491 log.info(BACKGROUND_THREAD_INFO, input.getInput().getVfModuleInformation().getVfModuleId());
1492 final String svcOperation = "vf-module-topology-operation-async";
1494 log.info(CALLED_STR, svcOperation);
1495 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1496 SvcLogicContext ctxIn = new SvcLogicContext();
1498 // Add input to SvcLogicContext
1500 ctxIn.mergeJson(parentOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1501 } catch (JsonProcessingException e) {
1502 log.error("exiting {} due to parse error on input data", svcOperation);
1506 // Add config tree data to SvcLogicContext
1507 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1508 ConfigServices configService = null;
1509 String svcData = null;
1510 if (configServices != null && !configServices.isEmpty()) {
1511 configService = configServices.get(0);
1513 svcData = getConfigServiceDataAsString(svcInstanceId);
1514 } catch (JsonProcessingException e) {
1515 log.error("exiting {} due to parse error on service data", svcOperation);
1519 if (svcData != null) {
1520 ctxIn.mergeJson("service-data", svcData);
1522 log.error("exiting {} because there is no service data with id [{}] in SDN", svcOperation, svcInstanceId);
1527 // Add operational tree data to SvcLogicContext
1528 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
1529 OperationalServices operService = null;
1531 if (operServices != null && !operServices.isEmpty()) {
1532 operService = operServices.get(0);
1533 log.info("Read ({}) data for [{}] operational-data: {}",
1534 "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", svcInstanceId, operService.getSvcData().toString());
1535 //ctxIn.mergeJson("operational-data", operService.getSvcData());
1537 log.info("No operational-data found in OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS for [{}]", svcInstanceId);
1538 operService = new OperationalServices(svcInstanceId, null, null);
1541 // Update service status info in config entry from input
1542 configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1543 configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1544 configService.setServiceStatusRpcName(svcOperation);
1546 String respStatus = "SUCCESS";
1547 String errorMessage = null;
1549 String ctxSvcDataJson = svcData;
1551 log.info ("Adding INPUT data for {} [{}] input: {}", svcOperation, svcInstanceId, input.getInput().toString());
1555 // Any of these can throw a nullpointer exception
1556 // execute should only throw a SvcLogicException
1557 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1558 Properties respProps = ctxOut.toProperties();
1560 String ackFinal = respProps.getProperty("ack-final-indicator", "Y");
1561 String errorCode = respProps.getProperty("error-code", "200");
1562 errorMessage = respProps.getProperty("error-message", "SUCCESS");
1564 if (! "200".equals(errorCode)) {
1565 respStatus = "FAILED";
1568 // Update status in config services entry
1569 configService.setServiceStatusFinalIndicator(ackFinal);
1570 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
1571 configService.setServiceStatusResponseCode(errorCode);
1572 configService.setServiceStatusResponseMessage(errorMessage);
1574 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1576 ctxSvcDataJson = ctxOut.toJsonString("service-data");
1577 configServicesRepository.save(configService);
1579 // Save service data
1581 saveSvcData(configService, ctxSvcDataJson);
1582 } catch (JsonProcessingException e) {
1583 log.error("exiting {} due to error saving service data", svcOperation);
1587 operService.setSvcData(ctxSvcDataJson);
1588 operService.setServiceStatus(configService.getServiceStatus());
1589 operationalServicesRepository.save(operService);
1591 } catch (Exception ex) {
1592 log.error("Caught Exception updating service status in SDN for {} [{}] \n", svcOperation, svcInstanceId);
1594 log.info("Returned {} for {} [{}] {}.", respStatus, svcOperation, svcInstanceId, errorMessage);
1598 public ResponseEntity<GenericResourceApiPortMirrorTopologyOperation> operationsGENERICRESOURCEAPIportMirrorTopologyOperationPost(
1599 @Valid GenericResourceApiPortMirrorTopologyOperationInformationBodyparam input)
1600 throws RestException {
1601 final String svcOperation = "port-mirror-topology-operation";
1602 GenericResourceApiPortMirrorTopologyOperation retval = new GenericResourceApiPortMirrorTopologyOperation();
1603 GenericResourceApiPortmirrortopologyoperationOutput resp = new GenericResourceApiPortmirrortopologyoperationOutput();
1605 log.info(CALLED_STR, svcOperation);
1607 // Verify input contains configuration-id
1608 if (hasInvalidConfigurationId(input.getInput())) {
1609 log.debug("exiting {} because of null or empty configuration-id", svcOperation);
1611 resp.setResponseCode("404");
1612 resp.setResponseMessage("null or empty configuration-id");
1613 resp.setAckFinalIndicator("Y");
1614 retval.setOutput(resp);
1615 return new ResponseEntity<>(retval, HttpStatus.OK);
1618 // Verify input contains service instance id
1619 if (hasInvalidServiceId(input.getInput())) {
1620 log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
1622 resp.setResponseCode("404");
1623 resp.setResponseMessage("null or empty service-instance-id");
1624 resp.setAckFinalIndicator("Y");
1625 retval.setOutput(resp);
1626 return new ResponseEntity<>(retval, HttpStatus.OK);
1629 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1630 String configurationId = input.getInput().getConfigurationInformation().getConfigurationId();
1632 SvcLogicContext ctxIn = new SvcLogicContext();
1634 // Add input to SvcLogicContext
1636 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1637 } catch (JsonProcessingException e) {
1638 log.error("exiting {} due to parse error on input data", svcOperation);
1639 resp.setResponseCode("500");
1640 resp.setResponseMessage("internal error");
1641 resp.setAckFinalIndicator("Y");
1642 retval.setOutput(resp);
1643 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1646 // Add service instance config data to SvcLogicContext
1647 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1648 ConfigServices configService = null;
1649 if (configServices != null && !configServices.isEmpty()) {
1650 configService = configServices.get(0);
1651 log.info("Read ({}) data for [{}] service-data: {}", "CONFIG_GRA_SERVICES", svcInstanceId, configService.getSvcData());
1652 ctxIn.mergeJson("service-data", configService.getSvcData());
1655 log.debug("exiting {} because there is no service data with id [{}] in SDN", svcOperation, svcInstanceId);
1656 resp.setResponseCode("404");
1657 resp.setResponseMessage("invalid input: there is no service-instance with id [{}] in SDNC");
1658 resp.setAckFinalIndicator("Y");
1660 retval.setOutput(resp);
1661 return new ResponseEntity<>(retval, HttpStatus.OK);
1664 // Add configuration config data to SvcLogicContext
1665 List<ConfigPortMirrorConfigurations> configPortMirrorConfigurations =
1666 configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1667 ConfigPortMirrorConfigurations configPortMirrorConfiguration;
1668 if (configPortMirrorConfigurations != null && !configPortMirrorConfigurations.isEmpty()) {
1669 configPortMirrorConfiguration = configPortMirrorConfigurations.get(0);
1670 log.info("Read ({}) data for [{}] configuration-data: {}",
1671 "CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId, configPortMirrorConfiguration.getPmcData());
1672 ctxIn.mergeJson("configuration-data", configPortMirrorConfiguration.getPmcData());
1675 log.info("No configuration-data found ({}) for [{}]", "CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId);
1676 configPortMirrorConfiguration = new ConfigPortMirrorConfigurations(configurationId, null);
1680 // Add configuration operational data to SvcLogicContext
1681 List<OperationalPortMirrorConfigurations> operPortMirrorConfigurations =
1682 operationalPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1683 OperationalPortMirrorConfigurations operPortMirrorConfiguration;
1685 if (operPortMirrorConfigurations != null && !operPortMirrorConfigurations.isEmpty()) {
1686 operPortMirrorConfiguration = operPortMirrorConfigurations.get(0);
1687 log.info("Read ({}) data for [{}] operational-data: {}",
1688 "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId, operPortMirrorConfiguration.getPmcData());
1689 ctxIn.mergeJson("operational-data", operPortMirrorConfiguration.getPmcData());
1692 log.info("No operational-data found ({}) for [{}]", "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId);
1693 operPortMirrorConfiguration = new OperationalPortMirrorConfigurations(configurationId, null, null);
1698 String ackFinal = "Y";
1699 String errorCode = "200";
1700 String errorMessage = "SUCCESS";
1701 String respStatus = "SUCCESS";
1703 log.info(ADDING_INPUT_DATA_LOG, svcOperation, svcInstanceId, input.getInput().toString());
1704 //log.info(ADDING_INPUT_DATA_LOG, svcOperation, svcInstanceId, input.toString());
1706 // Update service status info in config entry from input
1707 configPortMirrorConfiguration.setPortMirrorConfigurationStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1708 configPortMirrorConfiguration.setPortMirrorConfigurationStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1709 configPortMirrorConfiguration.setPortMirrorConfigurationStatusRpcName(svcOperation);
1713 // Any of these can throw a nullpointer exception
1714 // execute should only throw a SvcLogicException
1715 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1716 Properties respProps = ctxOut.toProperties();
1718 ackFinal = respProps.getProperty("ack-final", "Y");
1719 errorCode = respProps.getProperty("error-code", "200");
1720 errorMessage = respProps.getProperty("error-message", "SUCCESS");
1721 log.info("ackFinal [{}], error-code [{}], error-message [{}]", ackFinal, errorCode, errorMessage);
1723 resp.setAckFinalIndicator(ackFinal);
1724 resp.setResponseCode(errorCode);
1725 resp.setResponseMessage(errorMessage);
1727 // Update status in config services entry
1728 configPortMirrorConfiguration
1729 .setPortMirrorConfigurationStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1730 configPortMirrorConfiguration.setPortMirrorConfigurationStatusFinalIndicator(resp.getAckFinalIndicator());
1731 configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseCode(resp.getResponseCode());
1732 configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseMessage(resp.getResponseMessage());
1733 configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseTimestamp(Iso8601Util.now());
1735 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
1736 serviceReference.setInstanceId(svcInstanceId);
1737 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
1738 resp.setServiceResponseInformation(serviceReference);
1740 GenericResourceApiInstanceReference pmcReference = new GenericResourceApiInstanceReference();
1741 serviceReference.setInstanceId(configurationId);
1742 serviceReference.setObjectPath(respProps.getProperty(PORT_MIRROR_OBJECT_PATH_PARAM));
1743 resp.setServiceResponseInformation(pmcReference);
1745 retval.setOutput(resp);
1747 // ONLY update pmcData in config and operational trees
1748 //String ctxJson = ctxOut.toJsonString("configuration-data");
1749 //configPortMirrorConfiguration.setPmcData(ctxJson);
1750 //operPortMirrorConfiguration.setPmcData(ctxJson);
1751 //configPortMirrorConfigurationsRepository.save(configPortMirrorConfiguration);
1753 // If necessary, sync status to operation service entry and save
1754 //operPortMirrorConfiguration.setPortMirrorConfigurationStatus(configPortMirrorConfiguration.getPortMirrorConfigurationStatus());
1755 //operationalPortMirrorConfigurationsRepository.save(operPortMirrorConfiguration);
1757 if (! "200".equals(errorCode)) {
1758 respStatus = "FAILED";
1761 } catch (NullPointerException npe) {
1762 resp.setAckFinalIndicator("Y");
1763 resp.setResponseCode("500");
1764 resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
1765 } catch (SvcLogicException e) {
1766 resp.setAckFinalIndicator("Y");
1769 if (ackFinal.equals("N")) {
1770 // Spawn background thread to invoke the Async DG
1771 Runnable backgroundThread = new Runnable() {
1773 log.info(BACKGROUND_THREAD_STARTED_MESSAGE);
1774 processAsyncPortMirrorTopologyOperation(svcOperation, input);
1777 new Thread(backgroundThread).start();
1779 log.info("Returned {} for {} [{}] {}.", respStatus, svcOperation, configurationId, errorMessage);
1780 return (new ResponseEntity<>(retval, HttpStatus.OK));
1783 public void processAsyncPortMirrorTopologyOperation( String parentOperation,
1784 @Valid GenericResourceApiPortMirrorTopologyOperationInformationBodyparam input) {
1785 log.info(BACKGROUND_THREAD_INFO, input.getInput().getConfigurationInformation().getConfigurationId());
1786 final String svcOperation = "port-mirror-topology-operation-async";
1788 log.info(CALLED_STR, svcOperation);
1789 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1790 String configurationId = input.getInput().getConfigurationInformation().getConfigurationId();
1791 SvcLogicContext ctxIn = new SvcLogicContext();
1793 String errorMessage;
1795 // Add input to SvcLogicContext
1797 ctxIn.mergeJson(parentOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1798 } catch (JsonProcessingException e) {
1799 log.error("exiting {} due to parse error on input data", svcOperation);
1803 // Add service instance config data to SvcLogicContext
1804 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1805 ConfigServices configService = null;
1806 if (configServices != null && !configServices.isEmpty()) {
1807 configService = configServices.get(0);
1808 ctxIn.mergeJson("service-data", configService.getSvcData());
1810 log.error("exiting {} because there is no service data with id [{}] in SDN", svcOperation, svcInstanceId);
1814 // Add config tree data to SvcLogicContext
1815 List<ConfigPortMirrorConfigurations> configPortMirrorConfigurations = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1816 ConfigPortMirrorConfigurations configPortMirrorConfiguration;
1817 if (configPortMirrorConfigurations != null && !configPortMirrorConfigurations.isEmpty()) {
1818 configPortMirrorConfiguration = configPortMirrorConfigurations.get(0);
1819 ctxIn.mergeJson("configuration-data", configPortMirrorConfiguration.getPmcData());
1821 configPortMirrorConfiguration = new ConfigPortMirrorConfigurations(configurationId, null);
1825 // Add operational tree data to SvcLogicContext
1826 List<OperationalPortMirrorConfigurations> operPortMirrorConfigurations = operationalPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1827 OperationalPortMirrorConfigurations operPortMirrorConfiguration = null;
1829 if (operPortMirrorConfigurations != null && !operPortMirrorConfigurations.isEmpty()) {
1830 operPortMirrorConfiguration = operPortMirrorConfigurations.get(0);
1831 ctxIn.mergeJson("operational-data", operPortMirrorConfiguration.getPmcData());
1833 operPortMirrorConfiguration = new OperationalPortMirrorConfigurations(configurationId, null, null);
1838 // Update service status info in config entry from input
1839 configPortMirrorConfiguration.setPortMirrorConfigurationStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1840 configPortMirrorConfiguration.setPortMirrorConfigurationStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1841 configPortMirrorConfiguration.setPortMirrorConfigurationStatusRpcName(parentOperation);
1843 log.info("Adding INPUT data for {} [{}] input: {}", svcOperation, svcInstanceId, input.toString());
1847 // Any of these can throw a nullpointer exception
1848 // execute should only throw a SvcLogicException
1849 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1850 Properties respProps = ctxOut.toProperties();
1852 String ackFinalIndicator = respProps.getProperty("ack-final-indicator", "Y");
1853 String errorCode = respProps.getProperty("error-code", "200");
1854 errorMessage = respProps.getProperty("error-message", "SUCCESS");
1856 // Update status in config services entry
1857 configPortMirrorConfiguration.setPortMirrorConfigurationStatusFinalIndicator(ackFinalIndicator);
1858 configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseTimestamp(Iso8601Util.now());
1859 configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseCode(errorCode);
1860 configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseMessage(errorMessage);
1861 configPortMirrorConfiguration
1862 .setPortMirrorConfigurationStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1864 // ONLY update status
1865 //String ctxJson = ctxOut.toJsonString("configuration-data");
1866 //configPortMirrorConfiguration.setPmcData(ctxJson);
1867 //configPortMirrorConfiguration.setPmcData(ctxJson);
1869 // Update config tree
1870 configPortMirrorConfigurationsRepository.save(configPortMirrorConfiguration);
1872 //update operational tree
1873 //operPortMirrorConfiguration.setPortMirrorConfigurationStatus(configPortMirrorConfiguration.getPortMirrorConfigurationStatus());
1874 //operationalPortMirrorConfigurationsRepository.save(operPortMirrorConfiguration);
1876 } catch (Exception e) {
1877 log.error("Caught Exception updating configuration status in SDN for {} [{}] \n", svcOperation, configurationId);
1879 log.info("Returned SUCCESS for {} [{}]", svcOperation, configurationId);
1883 public ResponseEntity<GenericResourceApiVnfGetResourceRequest> operationsGENERICRESOURCEAPIvnfGetResourceRequestPost(
1884 @Valid GenericResourceApiVnfgetresourcerequestInputBodyparam input)
1885 throws RestException {
1886 final String svcOperation = "vnf-get-resource-request";
1887 GenericResourceApiVnfGetResourceRequest retval = new GenericResourceApiVnfGetResourceRequest();
1889 log.info(CALLED_STR, svcOperation);
1890 // Verify input contains service instance id
1891 if (hasInvalidServiceId(input.getInput())) {
1892 log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
1893 //return new ResponseEntity<>(retval, HttpStatus.OK);
1896 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1897 SvcLogicContext ctxIn = new SvcLogicContext();
1899 // Add input to SvcLogicContext
1901 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1902 } catch (JsonProcessingException e) {
1903 log.error("exiting {} due to parse error on input data", svcOperation);
1904 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1907 // Add config tree data to SvcLogicContext
1908 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1909 ConfigServices configService = null;
1910 if (configServices != null && !configServices.isEmpty()) {
1911 configService = configServices.get(0);
1912 ctxIn.mergeJson("service-data", configService.getSvcData());
1914 log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
1915 return new ResponseEntity<>(retval, HttpStatus.OK);
1920 // Any of these can throw a nullpointer exception
1921 // execute should only throw a SvcLogicException
1922 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1923 Properties respProps = ctxOut.toProperties();
1925 /* For debugging Only
1926 respProps.forEach((k,v) -> {
1927 log.debug("prop: {} -> {}",k,v);
1931 String ctxJson = ctxOut.toJsonString("vnf-get-resource-request-output");
1932 GenericResourceApiVnfgetresourcerequestOutput vnfgetresourcerequestOutput =
1933 objectMapper.readValue(ctxJson, GenericResourceApiVnfgetresourcerequestOutput.class);
1935 retval.setOutput(vnfgetresourcerequestOutput);
1937 } catch (Exception e) {
1938 return (new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR));
1940 return (new ResponseEntity<>(retval, HttpStatus.OK));
1944 public ResponseEntity<GenericResourceApiPolicyUpdateNotifyOperation> operationsGENERICRESOURCEAPIpolicyUpdateNotifyOperationPost(
1945 @Valid GenericResourceApiPolicyupdatenotifyoperationInputBodyparam input)
1946 throws RestException {
1947 final String svcOperation = "policy-update-notify-operation";
1948 GenericResourceApiPolicyUpdateNotifyOperation retval = new GenericResourceApiPolicyUpdateNotifyOperation();
1949 GenericResourceApiPolicyupdatenotifyoperationOutput resp = new GenericResourceApiPolicyupdatenotifyoperationOutput();
1951 log.info(CALLED_STR, svcOperation);
1952 // Verify required input elements
1953 if (hasInvalidPolicyUpdateInput(input.getInput())) {
1954 log.debug("exiting {} because policy name, update type, or version id was not provided", svcOperation);
1955 resp.setErrorCode("404");
1956 resp.setErrorMsg("policy-name, update-type, and/or version-id is null or empty");
1957 retval.setOutput(resp);
1958 return new ResponseEntity<>(retval, HttpStatus.OK);
1961 SvcLogicContext ctxIn = new SvcLogicContext();
1963 // Add input to SvcLogicContext
1965 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1966 } catch (JsonProcessingException e) {
1967 log.error("exiting {} due to parse error on input data", svcOperation);
1968 resp.setErrorCode("500");
1969 resp.setErrorMsg("internal error");
1970 retval.setOutput(resp);
1971 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1976 // Any of these can throw a nullpointer exception
1977 // execute should only throw a SvcLogicException
1978 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1979 Properties respProps = ctxOut.toProperties();
1980 resp.setErrorCode(respProps.getProperty("error-code", "200"));
1981 resp.setErrorMsg(respProps.getProperty("error-message", "SUCCESS"));
1983 /* For debugging Only
1984 respProps.forEach((k,v) -> {
1985 log.debug("prop: {} -> {}",k,v);
1989 } catch (NullPointerException npe) {
1990 resp.setErrorCode("500");
1991 resp.setErrorMsg("Check that you populated module, rpc and or mode correctly.");
1992 } catch (SvcLogicException e) {
1993 resp.setErrorCode("500");
1994 resp.setErrorMsg(e.getMessage());
1997 retval.setOutput(resp);
1998 return (new ResponseEntity<>(retval, HttpStatus.OK));