4806652d32fda42923682ca768fa8d4ca4a60415
[sdnc/apps.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SDNC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdnc.apps.ms.gra.controllers;
22
23 import com.fasterxml.jackson.annotation.JsonInclude;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.JsonMappingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import com.google.gson.JsonParser;
28
29 import org.onap.ccsdk.apps.services.RestException;
30 import org.onap.ccsdk.apps.services.SvcLogicFactory;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceBase;
34 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadData;
35 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadDataRepository;
36 import org.onap.sdnc.apps.ms.gra.data.ConfigServices;
37 import org.onap.sdnc.apps.ms.gra.data.ConfigServicesRepository;
38 import org.onap.sdnc.apps.ms.gra.data.ConfigContrailRouteAllottedResources;
39 import org.onap.sdnc.apps.ms.gra.data.ConfigContrailRouteAllottedResourcesRepository;
40 import org.onap.sdnc.apps.ms.gra.data.ConfigPortMirrorConfigurations;
41 import org.onap.sdnc.apps.ms.gra.data.ConfigPortMirrorConfigurationsRepository;
42 import org.onap.sdnc.apps.ms.gra.data.OperationalPreloadData;
43 import org.onap.sdnc.apps.ms.gra.data.OperationalPreloadDataRepository;
44 import org.onap.sdnc.apps.ms.gra.data.OperationalServices;
45 import org.onap.sdnc.apps.ms.gra.data.OperationalServicesRepository;
46 import org.onap.sdnc.apps.ms.gra.data.OperationalContrailRouteAllottedResources;
47 import org.onap.sdnc.apps.ms.gra.data.OperationalContrailRouteAllottedResourcesRepository;
48 import org.onap.sdnc.apps.ms.gra.data.OperationalPortMirrorConfigurations;
49 import org.onap.sdnc.apps.ms.gra.data.OperationalPortMirrorConfigurationsRepository;
50 import org.onap.sdnc.apps.ms.gra.swagger.OperationsApi;
51 import org.onap.sdnc.apps.ms.gra.swagger.model.*;
52 import org.springframework.beans.factory.annotation.Autowired;
53 import org.springframework.boot.autoconfigure.domain.EntityScan;
54 import org.springframework.context.annotation.ComponentScan;
55 import org.springframework.context.annotation.Import;
56 import org.springframework.http.HttpStatus;
57 import org.springframework.http.ResponseEntity;
58 import org.springframework.stereotype.Controller;
59
60 import javax.servlet.http.HttpServletRequest;
61 import javax.validation.Valid;
62
63 import java.text.DateFormat;
64 import java.text.SimpleDateFormat;
65 import java.util.*;
66 import java.util.concurrent.atomic.AtomicBoolean;
67
68 @Controller
69 @ComponentScan(basePackages = { "org.onap.sdnc.apps.ms.gra.*", "org.onap.ccsdk.apps.services" })
70 @EntityScan("org.onap.sdnc.apps.ms.gra.*")
71 @Import(value = SvcLogicFactory.class)
72 public class OperationsApiController implements OperationsApi {
73
74     private static final String CALLED_STR = "{} called.";
75     private static final String MODULE_NAME = "GENERIC-RESOURCE-API";
76     private static final String SERVICE_OBJECT_PATH_PARAM = "service-object-path";
77     private static final String NETWORK_OBJECT_PATH_PARAM = "network-object-path";
78     private static final String VNF_OBJECT_PATH_PARAM = "vnf-object-path";
79     private static final String PNF_OBJECT_PATH_PARAM = "pnf-object-path";
80     private static final String VF_MODULE_OBJECT_PATH_PARAM = "vf-module-object-path";
81     private static final String PORT_MIRROR_OBJECT_PATH_PARAM = "port-mirror-object-path";
82     private static final String BACKGROUND_THREAD_STARTED_MESSAGE = "Start background thread";
83     private static final String BACKGROUND_THREAD_INFO = "Background thread: input conf_id is {}";
84     private static final String SKIP_MDSAL_UPDATE_PROP = "skip-mdsal-update";
85     private static final String ADDING_INPUT_DATA_LOG = "Adding INPUT data for {} [{}] input: {}";
86     private static final String ADDING_OPERATIONAL_DATA_LOG = "Adding OPERATIONAL data for {} [{}] operational-data: {}";
87
88     private final ObjectMapper objectMapper;
89
90     private final HttpServletRequest request;
91
92     @Autowired
93     protected SvcLogicServiceBase svc;
94
95     @Autowired
96     private ConfigPreloadDataRepository configPreloadDataRepository;
97
98     @Autowired
99     private OperationalPreloadDataRepository operationalPreloadDataRepository;
100
101     @Autowired
102     private ConfigServicesRepository configServicesRepository;
103
104     @Autowired
105     private OperationalServicesRepository operationalServicesRepository;
106
107     @Autowired
108     private ConfigContrailRouteAllottedResourcesRepository configContrailRouteAllottedResourcesRepository;
109
110     @Autowired
111     private OperationalContrailRouteAllottedResourcesRepository operationalContrailRouteAllottedResourcesRepository;
112
113     @Autowired
114     private ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository;
115
116     @Autowired
117     private OperationalPortMirrorConfigurationsRepository operationalPortMirrorConfigurationsRepository;
118
119     private static class Iso8601Util {
120
121         private static TimeZone timeZone = TimeZone.getTimeZone("UTC");
122         private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
123
124         private Iso8601Util() {
125         }
126
127         static {
128             dateFormat.setTimeZone(timeZone);
129         }
130
131         private static String now() {
132             return dateFormat.format(new Date());
133         }
134     }
135
136     @org.springframework.beans.factory.annotation.Autowired
137     public OperationsApiController(ObjectMapper objectMapper, HttpServletRequest request) {
138         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
139         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
140         this.objectMapper = objectMapper;
141         this.request = request;
142     }
143
144     @Override
145     public Optional<ObjectMapper> getObjectMapper() {
146         return Optional.ofNullable(objectMapper);
147     }
148
149     @Override
150     public Optional<HttpServletRequest> getRequest() {
151         return Optional.ofNullable(request);
152     }
153
154     @Override
155     public ResponseEntity<GenericResourceApiPreloadNetworkTopologyOperation> operationsGENERICRESOURCEAPIpreloadNetworkTopologyOperationPost(
156             @Valid GenericResourceApiPreloadnetworktopologyoperationInputBodyparam graInput) {
157         final String svcOperation = "preload-network-topology-operation";
158         GenericResourceApiPreloadNetworkTopologyOperation retval = new GenericResourceApiPreloadNetworkTopologyOperation();
159         GenericResourceApiPreloadTopologyResponseBody resp = new GenericResourceApiPreloadTopologyResponseBody();
160
161         log.info(CALLED_STR, svcOperation);
162         if (hasInvalidPreloadNetwork(graInput)) {
163             log.debug("exiting {} because of null or empty preload-network-topology-information", svcOperation);
164
165             resp.setResponseCode("403");
166             resp.setResponseMessage("invalid input, null or empty preload-network-topology-information");
167             resp.setAckFinalIndicator("Y");
168
169             retval.setOutput(resp);
170
171             return new ResponseEntity<>(retval, HttpStatus.FORBIDDEN);
172         }
173
174         String preloadId = graInput.getInput().getPreloadNetworkTopologyInformation()
175                 .getNetworkTopologyIdentifierStructure().getNetworkId();
176         String preloadType = "network";
177
178         resp.setSvcRequestId(graInput.getInput().getSdncRequestHeader().getSvcRequestId());
179
180         SvcLogicContext ctxIn = new SvcLogicContext();
181
182         GenericResourceApiPreloaddataPreloadData preloadData = null;
183
184         // Add input to SvcLogicContext
185         try {
186             ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(graInput.getInput()));
187         } catch (JsonProcessingException e) {
188             log.error("exiting {} due to parse error on input preload data", svcOperation);
189             resp.setResponseCode("500");
190             resp.setResponseMessage("internal error");
191             resp.setAckFinalIndicator("Y");
192             retval.setOutput(resp);
193             return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
194         }
195
196         // Add config tree data to SvcLogicContext
197         try {
198             preloadData = getConfigPreloadData(preloadId, preloadType);
199             ctxIn.mergeJson("preload-data", objectMapper.writeValueAsString(preloadData));
200         } catch (JsonProcessingException e) {
201             log.error("exiting {} due to parse error on saved config preload data", svcOperation);
202             resp.setResponseCode("500");
203             resp.setResponseMessage("internal error");
204             resp.setAckFinalIndicator("Y");
205             retval.setOutput(resp);
206             return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
207         }
208
209         // Add operational tree data to SvcLogicContext
210         try {
211             preloadData = getOperationalPreloadData(preloadId, preloadType);
212             ctxIn.mergeJson("operational-data", objectMapper.writeValueAsString(preloadData));
213         } catch (JsonProcessingException e) {
214             log.error("exiting {} due to parse error on saved operational preload data", svcOperation);
215             resp.setResponseCode("500");
216             resp.setResponseMessage("internal error");
217             resp.setAckFinalIndicator("Y");
218             retval.setOutput(resp);
219             return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
220         }
221
222         // Call DG
223         try {
224             // Any of these can throw a nullpointer exception
225             // execute should only throw a SvcLogicException
226             SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
227             Properties respProps = ctxOut.toProperties();
228
229             resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
230             resp.setResponseCode(respProps.getProperty("error-code", "200"));
231             resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
232
233             if ("200".equals(resp.getResponseCode())) {
234                 // If DG returns success, update database
235                 String ctxJson = ctxOut.toJsonString("preload-data");
236                 log.info("DG preload-data is {}", ctxJson);
237                 GenericResourceApiPreloaddataPreloadData preloadToLoad = objectMapper.readValue(ctxJson,
238                         GenericResourceApiPreloaddataPreloadData.class);
239                 saveConfigPreloadData(preloadId, preloadType, preloadToLoad);
240                 saveOperationalPreloadData(preloadId, preloadType, preloadToLoad);
241             }
242
243         } catch (NullPointerException npe) {
244             log.error("Caught NPE", npe);
245             resp.setAckFinalIndicator("true");
246             resp.setResponseCode("500");
247             resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
248         } catch (SvcLogicException e) {
249             log.error("Caught SvcLogicException", e);
250             resp.setAckFinalIndicator("true");
251             resp.setResponseCode("500");
252             resp.setResponseMessage(e.getMessage());
253         } catch (JsonMappingException e) {
254             log.error("Caught JsonMappingException", e);
255             resp.setAckFinalIndicator("true");
256             resp.setResponseCode("500");
257             resp.setResponseMessage(e.getMessage());
258         } catch (JsonProcessingException e) {
259             log.error("Caught JsonProcessingException", e);
260             resp.setAckFinalIndicator("true");
261             resp.setResponseCode("500");
262             resp.setResponseMessage(e.getMessage());
263         }
264
265         retval.setOutput(resp);
266         return (new ResponseEntity<>(retval, HttpStatus.valueOf(Integer.parseInt(resp.getResponseCode()))));
267     }
268
269     @Override
270     public ResponseEntity<GenericResourceApiPreloadVfModuleTopologyOperation> operationsGENERICRESOURCEAPIpreloadVfModuleTopologyOperationPost(
271             @Valid GenericResourceApiPreloadvfmoduletopologyoperationInputBodyparam graInput) {
272         final String svcOperation = "preload-vf-module-topology-operation";
273         GenericResourceApiPreloadVfModuleTopologyOperation retval = new GenericResourceApiPreloadVfModuleTopologyOperation();
274         GenericResourceApiPreloadTopologyResponseBody resp = new GenericResourceApiPreloadTopologyResponseBody();
275
276         log.info(CALLED_STR, svcOperation);
277         if (hasInvalidPreloadNetwork(graInput)) {
278             log.debug("exiting {} because of null or empty preload-network-topology-information", svcOperation);
279
280             resp.setResponseCode("403");
281             resp.setResponseMessage("invalid input, null or empty preload-network-topology-information");
282             resp.setAckFinalIndicator("Y");
283
284             retval.setOutput(resp);
285
286             return new ResponseEntity<>(retval, HttpStatus.FORBIDDEN);
287         }
288
289         String preloadId = graInput.getInput().getPreloadVfModuleTopologyInformation().getVfModuleTopology()
290                 .getVfModuleTopologyIdentifier().getVfModuleName();
291         String preloadType = "vf-module";
292
293         resp.setSvcRequestId(graInput.getInput().getSdncRequestHeader().getSvcRequestId());
294
295         SvcLogicContext ctxIn = new SvcLogicContext();
296
297         GenericResourceApiPreloaddataPreloadData preloadData = null;
298
299         // Add input to SvcLogicContext
300         try {
301             ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(graInput.getInput()));
302         } catch (JsonProcessingException e) {
303             log.error("exiting {} due to parse error on input preload data", svcOperation);
304             resp.setResponseCode("500");
305             resp.setResponseMessage("internal error");
306             resp.setAckFinalIndicator("Y");
307             retval.setOutput(resp);
308             return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
309         }
310
311         // Add config tree data to SvcLogicContext
312         try {
313             preloadData = getConfigPreloadData(preloadId, preloadType);
314             ctxIn.mergeJson("preload-data", objectMapper.writeValueAsString(preloadData));
315         } catch (JsonProcessingException e) {
316             log.error("exiting {} due to parse error on saved config preload data", svcOperation);
317             resp.setResponseCode("500");
318             resp.setResponseMessage("internal error");
319             resp.setAckFinalIndicator("Y");
320             retval.setOutput(resp);
321             return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
322         }
323
324         // Add operational tree data to SvcLogicContext
325         try {
326             preloadData = getOperationalPreloadData(preloadId, preloadType);
327             ctxIn.mergeJson("operational-data", objectMapper.writeValueAsString(preloadData));
328         } catch (JsonProcessingException e) {
329             log.error("exiting {} due to parse error on saved operational preload data", svcOperation);
330             resp.setResponseCode("500");
331             resp.setResponseMessage("internal error");
332             resp.setAckFinalIndicator("Y");
333             retval.setOutput(resp);
334             return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
335         }
336
337         // Call DG
338         try {
339             // Any of these can throw a nullpointer exception
340             // execute should only throw a SvcLogicException
341             SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
342             Properties respProps = ctxOut.toProperties();
343
344             resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
345             resp.setResponseCode(respProps.getProperty("error-code", "200"));
346             resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
347
348             if ("200".equals(resp.getResponseCode())) {
349                 // If DG returns success, update database
350                 String ctxJson = ctxOut.toJsonString("preload-data");
351                 GenericResourceApiPreloaddataPreloadData preloadToLoad = objectMapper.readValue(ctxJson,
352                         GenericResourceApiPreloaddataPreloadData.class);
353                 saveConfigPreloadData(preloadId, preloadType, preloadToLoad);
354                 saveOperationalPreloadData(preloadId, preloadType, preloadToLoad);
355             }
356
357         } catch (NullPointerException npe) {
358             resp.setAckFinalIndicator("true");
359             resp.setResponseCode("500");
360             resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
361         } catch (SvcLogicException e) {
362             resp.setAckFinalIndicator("true");
363             resp.setResponseCode("500");
364             resp.setResponseMessage(e.getMessage());
365         } catch (JsonMappingException e) {
366             resp.setAckFinalIndicator("true");
367             resp.setResponseCode("500");
368             resp.setResponseMessage(e.getMessage());
369         } catch (JsonProcessingException e) {
370             resp.setAckFinalIndicator("true");
371             resp.setResponseCode("500");
372             resp.setResponseMessage(e.getMessage());
373         }
374
375         retval.setOutput(resp);
376         return (new ResponseEntity<>(retval, HttpStatus.valueOf(Integer.parseInt(resp.getResponseCode()))));
377     }
378
379     private boolean hasInvalidPreloadNetwork(
380             GenericResourceApiPreloadnetworktopologyoperationInputBodyparam preloadData) {
381         return ((preloadData == null) || (preloadData.getInput() == null)
382                 || (preloadData.getInput().getPreloadNetworkTopologyInformation() == null));
383     }
384
385     private boolean hasInvalidPreloadNetwork(
386             GenericResourceApiPreloadvfmoduletopologyoperationInputBodyparam preloadData) {
387         return ((preloadData == null) || (preloadData.getInput() == null)
388                 || (preloadData.getInput().getPreloadVfModuleTopologyInformation() == null));
389     }
390
391     private boolean hasInvalidServiceId(GenericResourceApiServiceOperationInformation input) {
392
393         return input == null || input.getServiceInformation() == null
394                 || input.getServiceInformation().getServiceInstanceId() == null
395                 || input.getServiceInformation().getServiceInstanceId().length() == 0;
396     }
397
398     private boolean hasInvalidServiceId(GenericResourceApiNetworkOperationInformation input) {
399
400         return input == null || input.getServiceInformation() == null
401                 || input.getServiceInformation().getServiceInstanceId() == null
402                 || input.getServiceInformation().getServiceInstanceId().length() == 0;
403     }
404
405     private boolean hasInvalidServiceId(GenericResourceApiVnfOperationInformation input) {
406
407         return input == null || input.getServiceInformation() == null
408                 || input.getServiceInformation().getServiceInstanceId() == null
409                 || input.getServiceInformation().getServiceInstanceId().length() == 0;
410     }
411
412     private boolean hasInvalidServiceId(GenericResourceApiVfModuleOperationInformation input) {
413
414         return input == null || input.getServiceInformation() == null
415                 || input.getServiceInformation().getServiceInstanceId() == null
416                 || input.getServiceInformation().getServiceInstanceId().length() == 0;
417     }
418
419     private boolean hasInvalidServiceId(GenericResourceApiPortMirrorTopologyOperationInformation input) {
420
421         return input == null || input.getServiceInformation() == null
422                 || input.getServiceInformation().getServiceInstanceId() == null
423                 || input.getServiceInformation().getServiceInstanceId().length() == 0;
424     }
425
426     private boolean hasInvalidServiceId(GenericResourceApiVnfgetresourcerequestInput input) {
427
428         return input == null || input.getServiceInformation() == null
429                 || input.getServiceInformation().getServiceInstanceId() == null
430                 || input.getServiceInformation().getServiceInstanceId().length() == 0;
431     }
432
433     private boolean hasInvalidVnfId(GenericResourceApiVfModuleOperationInformation input) {
434
435         return input == null || input.getVnfInformation() == null
436                 || input.getVnfInformation().getVnfId() == null
437                 || input.getVnfInformation().getVnfId().length() == 0;
438     }
439
440     private boolean hasInvalidConfigurationId(GenericResourceApiPortMirrorTopologyOperationInformation input) {
441         return input.getConfigurationInformation() == null
442                 || input.getConfigurationInformation().getConfigurationId() == null
443                 || input.getConfigurationInformation().getConfigurationId().length() == 0;
444     }
445
446     private boolean hasInvalidPolicyUpdateInput(GenericResourceApiPolicyupdatenotifyoperationInput input) {
447         return (input.getPolicyName() == null) || (input.getUpdateType() == null) || (input.getVersionId() == null);
448     }
449
450     private GenericResourceApiPreloaddataPreloadData getConfigPreloadData(String preloadId, String preloadType)
451             throws JsonProcessingException {
452
453         List<ConfigPreloadData> configPreloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
454                 preloadType);
455
456         if (configPreloadData.isEmpty()) {
457             return (null);
458         } else {
459             return (objectMapper.readValue(configPreloadData.get(0).getPreloadData(),
460                     GenericResourceApiPreloaddataPreloadData.class));
461         }
462     }
463
464     private GenericResourceApiPreloaddataPreloadData getOperationalPreloadData(String preloadId, String preloadType)
465             throws JsonProcessingException {
466
467         List<OperationalPreloadData> configPreloadData = operationalPreloadDataRepository
468                 .findByPreloadIdAndPreloadType(preloadId, preloadType);
469
470         if (configPreloadData.isEmpty()) {
471             return (null);
472         } else {
473             return (objectMapper.readValue(configPreloadData.get(0).getPreloadData(),
474                     GenericResourceApiPreloaddataPreloadData.class));
475         }
476     }
477
478     private void saveConfigPreloadData(String preloadId, String preloadType,
479             GenericResourceApiPreloaddataPreloadData preloadData) throws JsonProcessingException {
480
481         configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
482         configPreloadDataRepository
483                 .save(new ConfigPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadData)));
484
485     }
486
487     private void saveOperationalPreloadData(String preloadId, String preloadType,
488             GenericResourceApiPreloaddataPreloadData preloadData) throws JsonProcessingException {
489
490         operationalPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
491         operationalPreloadDataRepository
492                 .save(new OperationalPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadData)));
493
494     }
495
496     private GenericResourceApiServicedataServiceData getConfigServiceData(String svcInstanceId)
497             throws JsonProcessingException {
498
499         List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
500
501         if (configServices.isEmpty()) {
502             return (null);
503         } else {
504             return (objectMapper.readValue(configServices.get(0).getSvcData(),
505                     GenericResourceApiServicedataServiceData.class));
506         }
507     }
508
509     @Override
510     public ResponseEntity<GenericResourceApiNetworkTopologyOperation> operationsGENERICRESOURCEAPInetworkTopologyOperationPost(
511             @Valid GenericResourceApiNetworkOperationInformationBodyparam input) throws RestException {
512         final String svcOperation = "network-topology-operation";
513         GenericResourceApiNetworkTopologyOperation retval = new GenericResourceApiNetworkTopologyOperation();
514         GenericResourceApiNetworktopologyoperationOutput resp = new GenericResourceApiNetworktopologyoperationOutput();
515
516         log.info(CALLED_STR, svcOperation);
517         // Verify input contains service instance id
518         if (hasInvalidServiceId(input.getInput())) {
519             log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
520
521             resp.setResponseCode("404");
522             resp.setResponseMessage("null or empty service-instance-id");
523             resp.setAckFinalIndicator("Y");
524
525             retval.setOutput(resp);
526
527             return new ResponseEntity<>(retval, HttpStatus.OK);
528         }
529
530         String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
531
532         SvcLogicContext ctxIn = new SvcLogicContext();
533
534         // Add input to SvcLogicContext
535         try {
536             ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
537         } catch (JsonProcessingException e) {
538             log.error("exiting {} due to parse error on input data", svcOperation);
539             resp.setResponseCode("500");
540             resp.setResponseMessage("internal error");
541             resp.setAckFinalIndicator("Y");
542             retval.setOutput(resp);
543             return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
544         }
545
546         // Add config tree data to SvcLogicContext
547         List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
548         ConfigServices configService = null;
549         String svcData = null;
550         if (configServices != null && !configServices.isEmpty()) {
551             configService = configServices.get(0);
552             svcData = configService.getSvcData();
553         }
554         if (svcData != null) {
555             ctxIn.mergeJson("service-data", configService.getSvcData());
556         } else {
557             log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
558
559             resp.setResponseCode("404");
560             resp.setResponseMessage("invalid input: the service-instance does not have any service data in SDNC");
561             resp.setAckFinalIndicator("Y");
562
563             retval.setOutput(resp);
564
565             return new ResponseEntity<>(retval, HttpStatus.OK);
566         }
567
568         // Add operational tree data to SvcLogicContext
569         List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
570         OperationalServices operService = null;
571         boolean saveOperationalData = false;
572
573         if (operServices != null && !operServices.isEmpty()) {
574             operService = operServices.get(0);
575             ctxIn.mergeJson("operational-data", operService.getSvcData());
576         } else {
577             operService = new OperationalServices(svcInstanceId, null, null);
578         }
579
580         // Update service status info in config entry from input
581         configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
582         configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
583         configService.setServiceStatusRpcName(svcOperation);
584
585         // Call DG
586         try {
587             // Any of these can throw a nullpointer exception
588             // execute should only throw a SvcLogicException
589             SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
590             Properties respProps = ctxOut.toProperties();
591
592             resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
593             resp.setResponseCode(respProps.getProperty("error-code", "200"));
594             resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
595
596
597
598             configService
599                     .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
600
601             if ("200".equals(resp.getResponseCode())) {
602
603                 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
604                 serviceReference.setInstanceId(svcInstanceId);
605                 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
606                 resp.setServiceResponseInformation(serviceReference);
607     
608                 GenericResourceApiInstanceReference networkReference = new GenericResourceApiInstanceReference();
609                 networkReference.setInstanceId(respProps.getProperty("networkId"));
610                 networkReference.setObjectPath(respProps.getProperty(NETWORK_OBJECT_PATH_PARAM));
611                 resp.setNetworkResponseInformation(networkReference);
612
613                 // If DG returns success, update svcData in config and operational trees
614                 // and remember to save operational data.
615                 String ctxJson = ctxOut.toJsonString("service-data");
616                 configService.setSvcData(ctxJson);
617                 operService.setSvcData(ctxJson);
618                 saveOperationalData = true;
619             }
620
621         } catch (NullPointerException npe) {
622             resp.setAckFinalIndicator("true");
623             resp.setResponseCode("500");
624             resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
625         } catch (SvcLogicException e) {
626             resp.setAckFinalIndicator("true");
627             resp.setResponseCode("500");
628             resp.setResponseMessage(e.getMessage());
629         }
630
631         // Update status in config services entry
632
633         configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
634         configService.setServiceStatusResponseCode(resp.getResponseCode());
635         configService.setServiceStatusResponseMessage(resp.getResponseMessage());
636         configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
637
638         // Update config tree
639         configServicesRepository.save(configService);
640
641         // If necessary, sync status to operation service entry and save
642         if (saveOperationalData) {
643             operService.setServiceStatus(configService.getServiceStatus());
644             operationalServicesRepository.save(operService);
645         }
646         retval.setOutput(resp);
647         
648         return (new ResponseEntity<>(retval, HttpStatus.OK));
649     }
650
651     @Override
652     public ResponseEntity<GenericResourceApiServiceTopologyOperation> operationsGENERICRESOURCEAPIserviceTopologyOperationPost(
653             @Valid GenericResourceApiServiceOperationInformationBodyparam input) throws RestException {
654         final String svcOperation = "service-topology-operation";
655         GenericResourceApiServiceTopologyOperation retval = new GenericResourceApiServiceTopologyOperation();
656         GenericResourceApiServicetopologyoperationOutput resp = new GenericResourceApiServicetopologyoperationOutput();
657
658         log.info(CALLED_STR, svcOperation);
659
660         // Verify input contains service instance id
661         if (hasInvalidServiceId(input.getInput())) {
662             log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
663
664             resp.setResponseCode("404");
665             resp.setResponseMessage("null or empty service-instance-id");
666             resp.setAckFinalIndicator("Y");
667
668             retval.setOutput(resp);
669
670             return new ResponseEntity<>(retval, HttpStatus.OK);
671         }
672
673         String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
674
675         SvcLogicContext ctxIn = new SvcLogicContext();
676
677         // Add input to SvcLogicContext
678         try {
679             ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
680         } catch (JsonProcessingException e) {
681             log.error("exiting {} due to parse error on input data", svcOperation);
682             resp.setResponseCode("500");
683             resp.setResponseMessage("internal error");
684             resp.setAckFinalIndicator("Y");
685             retval.setOutput(resp);
686             return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
687         }
688
689         // Add config tree data to SvcLogicContext
690         List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
691         ConfigServices configService = null;
692         if (configServices != null && !configServices.isEmpty()) {
693             configService = configServices.get(0);
694             if (configService.getSvcData() != null) {
695                 ctxIn.mergeJson("service-data", configService.getSvcData());
696             }
697         } else {
698             configService = new ConfigServices(svcInstanceId, null);
699         }
700
701         // Add operational tree data to SvcLogicContext
702         List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
703         OperationalServices operService = null;
704         boolean saveOperationalData = false;
705
706         if (operServices != null && !operServices.isEmpty()) {
707             operService = operServices.get(0);
708             ctxIn.mergeJson("operational-data", operService.getSvcData());
709         } else {
710             operService = new OperationalServices(svcInstanceId, null, null);
711         }
712
713         // Update service status info in config entry from input
714         configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
715         configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
716         configService.setServiceStatusRpcName(svcOperation);
717
718         // Call DG
719         try {
720             // Any of these can throw a nullpointer exception
721             // execute should only throw a SvcLogicException
722             SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
723             Properties respProps = ctxOut.toProperties();
724
725             resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
726             resp.setResponseCode(respProps.getProperty("error-code", "200"));
727             resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
728
729             configService
730                     .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
731
732             if ("200".equals(resp.getResponseCode())) {                 
733                 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
734                 serviceReference.setInstanceId(svcInstanceId);
735                 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
736                 resp.setServiceResponseInformation(serviceReference);
737
738                 // If DG returns success, update svcData in config and operational trees
739                 // and remember to save operational data.
740                 String ctxJson = ctxOut.toJsonString("service-data");
741                 configService.setSvcData(ctxJson);
742                 operService.setSvcData(ctxJson);
743                 saveOperationalData = true;
744             }
745
746         } catch (NullPointerException npe) {
747             resp.setAckFinalIndicator("true");
748             resp.setResponseCode("500");
749             resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
750         } catch (SvcLogicException e) {
751             resp.setAckFinalIndicator("true");
752             resp.setResponseCode("500");
753             resp.setResponseMessage(e.getMessage());
754         }
755
756         // Update status in config services entry
757
758         configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
759         configService.setServiceStatusResponseCode(resp.getResponseCode());
760         configService.setServiceStatusResponseMessage(resp.getResponseMessage());
761         configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
762
763         // Update config tree
764         configServicesRepository.save(configService);
765
766         // If necessary, sync status to operation service entry and save
767         if (saveOperationalData) {
768             operService.setServiceStatus(configService.getServiceStatus());
769             operationalServicesRepository.save(operService);
770         }
771         retval.setOutput(resp);
772         return (new ResponseEntity<>(retval, HttpStatus.OK));
773
774     }
775
776     @Override
777     public ResponseEntity<GenericResourceApiVnfTopologyOperation> operationsGENERICRESOURCEAPIvnfTopologyOperationPost(
778             @Valid GenericResourceApiVnfOperationInformationBodyparam input)
779             throws RestException {
780                 final String svcOperation = "vnf-topology-operation";
781                 GenericResourceApiVnfTopologyOperation retval = new GenericResourceApiVnfTopologyOperation();
782                 GenericResourceApiVnftopologyoperationOutput resp = new GenericResourceApiVnftopologyoperationOutput();
783         
784                 log.info(CALLED_STR, svcOperation);
785                 // Verify input contains service instance id
786                 if (hasInvalidServiceId(input.getInput())) {
787                     log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
788         
789                     resp.setResponseCode("404");
790                     resp.setResponseMessage("null or empty service-instance-id");
791                     resp.setAckFinalIndicator("Y");
792         
793                     retval.setOutput(resp);
794         
795                     return new ResponseEntity<>(retval, HttpStatus.OK);
796                 }
797         
798                 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
799                 String vnfId = null;
800                 
801                 if ((input.getInput() != null) && (input.getInput().getVnfInformation() != null)) {
802                     vnfId = input.getInput().getVnfInformation().getVnfId();
803                 }
804         
805                 SvcLogicContext ctxIn = new SvcLogicContext();
806         
807                 // Add input to SvcLogicContext
808                 try {
809                     ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
810                 } catch (JsonProcessingException e) {
811                     log.error("exiting {} due to parse error on input data", svcOperation);
812                     resp.setResponseCode("500");
813                     resp.setResponseMessage("internal error");
814                     resp.setAckFinalIndicator("Y");
815                     retval.setOutput(resp);
816                     return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
817                 }
818         
819                 // Add config tree data to SvcLogicContext
820                 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
821                 ConfigServices configService = null;
822                 if (configServices != null && !configServices.isEmpty()) {
823                     configService = configServices.get(0);
824                     ctxIn.mergeJson("service-data", configService.getSvcData());
825                 } else {
826                     log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
827         
828                     resp.setResponseCode("404");
829                     resp.setResponseMessage("invalid input: the service-instance does not have any service data in SDNC");
830                     resp.setAckFinalIndicator("Y");
831         
832                     retval.setOutput(resp);
833         
834                     return new ResponseEntity<>(retval, HttpStatus.OK);
835                 }
836         
837                 // Add operational tree data to SvcLogicContext
838                 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
839                 OperationalServices operService = null;
840                 boolean saveOperationalData = false;
841         
842                 if (operServices != null && !operServices.isEmpty()) {
843                     operService = operServices.get(0);
844                     ctxIn.mergeJson("operational-data", operService.getSvcData());
845                 } else {
846                     operService = new OperationalServices(svcInstanceId, null, null);
847                 }
848         
849                 // Update service status info in config entry from input
850                 configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
851                 configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
852                 configService.setServiceStatusRpcName(svcOperation);
853
854
855         
856                 // Call DG
857                 try {
858                     // Any of these can throw a nullpointer exception
859                     // execute should only throw a SvcLogicException
860                     SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
861                     Properties respProps = ctxOut.toProperties();
862         
863                     resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
864                     resp.setResponseCode(respProps.getProperty("error-code", "200"));
865                     resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
866
867                     configService
868                             .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
869         
870                     if ("200".equals(resp.getResponseCode())) {
871
872                         GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
873                         serviceReference.setInstanceId(svcInstanceId);
874                         serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
875                         resp.setServiceResponseInformation(serviceReference);
876                         
877                         if (vnfId == null) {
878                             vnfId = respProps.getProperty("vnfId");
879                         }
880                         GenericResourceApiInstanceReference vnfReference = new GenericResourceApiInstanceReference();
881                         vnfReference.setInstanceId(vnfId);
882                         vnfReference.setObjectPath(respProps.getProperty(VNF_OBJECT_PATH_PARAM));
883                         resp.setVnfResponseInformation(vnfReference);
884                         
885                         // If DG returns success, update svcData in config and operational trees
886                         // and remember to save operational data.
887                         String ctxJson = ctxOut.toJsonString("service-data");
888                         configService.setSvcData(ctxJson);
889                         operService.setSvcData(ctxJson);
890                         saveOperationalData = true;
891                     }
892         
893                 } catch (NullPointerException npe) {
894                     resp.setAckFinalIndicator("true");
895                     resp.setResponseCode("500");
896                     resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
897                 } catch (SvcLogicException e) {
898                     resp.setAckFinalIndicator("true");
899                     resp.setResponseCode("500");
900                     resp.setResponseMessage(e.getMessage());
901                 }
902         
903                 // Update status in config services entry
904         
905                 configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
906                 configService.setServiceStatusResponseCode(resp.getResponseCode());
907                 configService.setServiceStatusResponseMessage(resp.getResponseMessage());
908                 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
909         
910                 // Update config tree
911                 configServicesRepository.save(configService);
912         
913                 // If necessary, sync status to operation service entry and save
914                 if (saveOperationalData) {
915                     operService.setServiceStatus(configService.getServiceStatus());
916                     operationalServicesRepository.save(operService);
917                 }
918                 retval.setOutput(resp);
919                 return (new ResponseEntity<>(retval, HttpStatus.OK));
920     }
921
922     @Override
923     public ResponseEntity<GenericResourceApiVfModuleTopologyOperation> operationsGENERICRESOURCEAPIvfModuleTopologyOperationPost(
924             @Valid GenericResourceApiVfModuleOperationInformationBodyparam input)
925             throws RestException {
926         final String svcOperation = "vf-module-topology-operation";
927         GenericResourceApiVfModuleTopologyOperation retval = new GenericResourceApiVfModuleTopologyOperation();
928         GenericResourceApiVfmoduletopologyoperationOutput resp = new GenericResourceApiVfmoduletopologyoperationOutput();
929
930         log.info(CALLED_STR, svcOperation);
931         // Verify input contains service instance id
932         if (hasInvalidServiceId(input.getInput())) {
933             log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
934
935             resp.setResponseCode("404");
936             resp.setResponseMessage("null or empty service-instance-id");
937             resp.setAckFinalIndicator("Y");
938             retval.setOutput(resp);
939             return new ResponseEntity<>(retval, HttpStatus.OK);
940         }
941
942         // Verify input contains vnf-id
943         if (hasInvalidVnfId(input.getInput())) {
944             log.debug("exiting {} because of null or empty vnf-id", svcOperation);
945
946             resp.setResponseCode("404");
947             resp.setResponseMessage("null or empty vnf-id");
948             resp.setAckFinalIndicator("Y");
949             retval.setOutput(resp);
950             return new ResponseEntity<>(retval, HttpStatus.OK);
951         }
952
953         String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
954         String vnfId = input.getInput().getVnfInformation().getVnfId();
955         String vfModuleId = input.getInput().getVfModuleInformation().getVfModuleId();
956
957         SvcLogicContext ctxIn = new SvcLogicContext();
958
959         // Add input to SvcLogicContext
960         try {
961             ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
962         } catch (JsonProcessingException e) {
963             log.error("exiting {} due to parse error on input data", svcOperation);
964             resp.setResponseCode("500");
965             resp.setResponseMessage("internal error");
966             resp.setAckFinalIndicator("Y");
967             retval.setOutput(resp);
968             return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
969         }
970
971         // Add config tree data to SvcLogicContext
972         List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
973         ConfigServices configService = null;
974         if (configServices != null && !configServices.isEmpty()) {
975             configService = configServices.get(0);
976             log.info("Read ({}) data for [{}] service-data: {}",
977                     "CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS", svcInstanceId, configService.getSvcData().toString());
978             ctxIn.mergeJson("service-data", configService.getSvcData());
979         } else {
980             log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
981             resp.setResponseCode("404");
982             resp.setResponseMessage("invalid input: the service-instance does not have any service data in SDNC");
983             resp.setAckFinalIndicator("Y");
984             retval.setOutput(resp);
985             return new ResponseEntity<>(retval, HttpStatus.OK);
986         }
987
988         // Add operational tree data to SvcLogicContext
989         List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
990         OperationalServices operService = null;
991
992         if (operServices != null && !operServices.isEmpty()) {
993             operService = operServices.get(0);
994             log.info("Read ({}) data for [{}] operational-data: {}",
995                     "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", svcInstanceId, operService.getSvcData().toString());
996             //ctxIn.mergeJson("operational-data", operService.getSvcData());
997         } else {
998             log.info("No operational-data found in OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS for [{}]", svcInstanceId);
999             operService = new OperationalServices(svcInstanceId, null, null);
1000         }
1001
1002         // Update service status info in config entry from input
1003         configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1004         configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1005         configService.setServiceStatusRpcName(svcOperation);
1006
1007         String ackFinal = "Y";
1008         String skipMdsalUpdate;
1009
1010         // Call DG
1011         try {
1012             // Any of these can throw a nullpointer exception
1013             // execute should only throw a SvcLogicException
1014             SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1015             Properties respProps = ctxOut.toProperties();
1016
1017             ackFinal = respProps.getProperty("ack-final", "Y");
1018             skipMdsalUpdate = respProps.getProperty("skip-mdsal-update", "N");
1019             log.info("ackFinal [{}], skipMdsalUpdate [{}]", ackFinal, skipMdsalUpdate);
1020
1021             resp.setAckFinalIndicator(ackFinal);
1022             resp.setResponseCode(respProps.getProperty("error-code", "200"));
1023             resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
1024
1025             // Update status in config services entry
1026             configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
1027             configService.setServiceStatusResponseCode(resp.getResponseCode());
1028             configService.setServiceStatusResponseMessage(resp.getResponseMessage());
1029             configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
1030             configService
1031                     .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1032
1033             if ("200".equals(resp.getResponseCode())) {
1034
1035                 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
1036                 serviceReference.setInstanceId(svcInstanceId);
1037                 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
1038                 resp.setServiceResponseInformation(serviceReference);
1039
1040                 GenericResourceApiInstanceReference vnfReference = new GenericResourceApiInstanceReference();
1041                 vnfReference.setInstanceId(vnfId);
1042                 vnfReference.setObjectPath(respProps.getProperty(VNF_OBJECT_PATH_PARAM));
1043                 resp.setVnfResponseInformation(vnfReference);
1044
1045                 GenericResourceApiInstanceReference vfModuleReference = new GenericResourceApiInstanceReference();
1046                 vnfReference.setInstanceId(vfModuleId);
1047                 vnfReference.setObjectPath(respProps.getProperty(VF_MODULE_OBJECT_PATH_PARAM));
1048                 resp.setVnfResponseInformation(vfModuleReference);
1049
1050                 if (skipMdsalUpdate.equals("N")) {
1051                     // If DG returns success,
1052                     // ONLY update svcData in config and operational trees
1053                     // and remember to save operational data when skip-mdsal-update is Y in ctx.
1054                     String ctxJson = ctxOut.toJsonString("service-data");
1055                     log.info("Saving service-data in SDN because skiMdsalUpdate is {}", skipMdsalUpdate);
1056                     configService.setSvcData(ctxJson);
1057                     configServicesRepository.save(configService);
1058
1059                     log.info("Copying service-data to operational-data");
1060                     operService.setSvcData(ctxJson);
1061                     operService.setServiceStatus(configService.getServiceStatus());
1062                     operationalServicesRepository.save(operService);
1063                 }
1064             }
1065         } catch (NullPointerException npe) {
1066             resp.setAckFinalIndicator("Y");
1067             resp.setResponseCode("500");
1068             resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
1069         } catch (SvcLogicException e) {
1070             resp.setAckFinalIndicator("Y");
1071         }
1072
1073         if (ackFinal.equals("N")) {
1074             // Spawn background thread to invoke the Async DG
1075             Runnable backgroundThread = new Runnable() {
1076                 public void run() {
1077                     log.info(BACKGROUND_THREAD_STARTED_MESSAGE);
1078                     processAsyncVfModuleTopologyOperation(svcOperation, input);
1079                 }
1080             };
1081             new Thread(backgroundThread).start();
1082         }
1083         retval.setOutput(resp);
1084         return (new ResponseEntity<>(retval, HttpStatus.OK));
1085     }
1086
1087     public void processAsyncVfModuleTopologyOperation( String parentOperation,
1088             @Valid GenericResourceApiVfModuleOperationInformationBodyparam input) {
1089         log.info(BACKGROUND_THREAD_INFO, input.getInput().getVfModuleInformation().getVfModuleId());
1090         final String svcOperation = "vf-module-topology-operation-async";
1091
1092         log.info(CALLED_STR, svcOperation);
1093         String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1094         SvcLogicContext ctxIn = new SvcLogicContext();
1095
1096         // Add input to SvcLogicContext
1097         try {
1098             ctxIn.mergeJson(parentOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1099         } catch (JsonProcessingException e) {
1100             log.error("exiting {} due to parse error on input data", svcOperation);
1101             return;
1102         }
1103
1104         // Add config tree data to SvcLogicContext
1105         List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1106         ConfigServices configService = null;
1107         if (configServices != null && !configServices.isEmpty()) {
1108             configService = configServices.get(0);
1109             log.info("Read ({}) data for [{}] service-data: {}",
1110                     "CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS", svcInstanceId, configService.getSvcData().toString());
1111             ctxIn.mergeJson("service-data", configService.getSvcData());
1112         } else {
1113             log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
1114             return;
1115         }
1116
1117         // Add operational tree data to SvcLogicContext
1118         List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
1119         OperationalServices operService = null;
1120
1121         if (operServices != null && !operServices.isEmpty()) {
1122             operService = operServices.get(0);
1123             log.info("Read ({}) data for [{}] operational-data: {}",
1124                     "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", svcInstanceId, operService.getSvcData().toString());
1125             //ctxIn.mergeJson("operational-data", operService.getSvcData());
1126         } else {
1127             log.info("No operational-data found in OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS for [{}]", svcInstanceId);
1128             operService = new OperationalServices(svcInstanceId, null, null);
1129         }
1130
1131         // Update service status info in config entry from input
1132         configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1133         configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1134         configService.setServiceStatusRpcName(svcOperation);
1135
1136         String respStatus = "SUCCESS";
1137         String errorMessage = null;
1138
1139         log.info ("Adding INPUT data for {} [{}] input: {}", svcOperation, svcInstanceId, input.getInput().toString());
1140
1141         // Call DG
1142         try {
1143             // Any of these can throw a nullpointer exception
1144             // execute should only throw a SvcLogicException
1145             SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1146             Properties respProps = ctxOut.toProperties();
1147
1148             String ackFinal = respProps.getProperty("ack-final-indicator", "Y");
1149             String errorCode = respProps.getProperty("error-code", "200");
1150             errorMessage = respProps.getProperty("error-message", "SUCCESS");
1151
1152             if (! "200".equals(errorCode)) {
1153                 respStatus = "FAILED";
1154             }
1155
1156             // Update status in config services entry
1157             configService.setServiceStatusFinalIndicator(ackFinal);
1158             configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
1159             configService.setServiceStatusResponseCode(errorCode);
1160             configService.setServiceStatusResponseMessage(errorMessage);
1161             configService
1162                     .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1163
1164             String ctxJson = ctxOut.toJsonString("service-data");
1165             configServicesRepository.save(configService);
1166
1167             operService.setSvcData(ctxJson);
1168             operService.setServiceStatus(configService.getServiceStatus());
1169             operationalServicesRepository.save(operService);
1170
1171         } catch (Exception ex) {
1172             log.error("Caught Exception updating service status in SDN for {} [{}] \n", svcOperation, svcInstanceId);
1173         }
1174         log.info("Returned {} for {} [{}] {}.", respStatus, svcOperation, svcInstanceId, errorMessage);
1175     }
1176
1177     @Override
1178     public ResponseEntity<GenericResourceApiPortMirrorTopologyOperation> operationsGENERICRESOURCEAPIportMirrorTopologyOperationPost(
1179             @Valid GenericResourceApiPortMirrorTopologyOperationInformationBodyparam input)
1180             throws RestException {
1181         final String svcOperation = "port-mirror-topology-operation";
1182         GenericResourceApiPortMirrorTopologyOperation retval = new GenericResourceApiPortMirrorTopologyOperation();
1183         GenericResourceApiPortmirrortopologyoperationOutput resp = new GenericResourceApiPortmirrortopologyoperationOutput();
1184
1185         log.info(CALLED_STR, svcOperation);
1186
1187         // Verify input contains configuration-id
1188         if (hasInvalidConfigurationId(input.getInput())) {
1189             log.debug("exiting {} because of null or empty configuration-id", svcOperation);
1190
1191             resp.setResponseCode("404");
1192             resp.setResponseMessage("null or empty configuration-id");
1193             resp.setAckFinalIndicator("Y");
1194             retval.setOutput(resp);
1195             return new ResponseEntity<>(retval, HttpStatus.OK);
1196         }
1197
1198         // Verify input contains service instance id
1199         if (hasInvalidServiceId(input.getInput())) {
1200             log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
1201
1202             resp.setResponseCode("404");
1203             resp.setResponseMessage("null or empty service-instance-id");
1204             resp.setAckFinalIndicator("Y");
1205             retval.setOutput(resp);
1206             return new ResponseEntity<>(retval, HttpStatus.OK);
1207         }
1208
1209         String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1210         String configurationId = input.getInput().getConfigurationInformation().getConfigurationId();
1211
1212         SvcLogicContext ctxIn = new SvcLogicContext();
1213
1214         // Add input to SvcLogicContext
1215         try {
1216             ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1217         } catch (JsonProcessingException e) {
1218             log.error("exiting {} due to parse error on input data", svcOperation);
1219             resp.setResponseCode("500");
1220             resp.setResponseMessage("internal error");
1221             resp.setAckFinalIndicator("Y");
1222             retval.setOutput(resp);
1223             return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1224         }
1225
1226         // Add service instance config data to SvcLogicContext
1227         List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1228         ConfigServices configService = null;
1229         if (configServices != null && !configServices.isEmpty()) {
1230             configService = configServices.get(0);
1231             log.info("Read ({}) data for [{}] service-data: {}", "CONFIG_GRA_SERVICES", svcInstanceId, configService.getSvcData());
1232             ctxIn.mergeJson("service-data", configService.getSvcData());
1233
1234         } else {
1235             log.debug("exiting {} because there is no service data with id [{}] in SDN", svcOperation, svcInstanceId);
1236             resp.setResponseCode("404");
1237             resp.setResponseMessage("invalid input: there is no service-instance with id [{}] in SDNC");
1238             resp.setAckFinalIndicator("Y");
1239
1240             retval.setOutput(resp);
1241             return new ResponseEntity<>(retval, HttpStatus.OK);
1242         }
1243
1244         // Add configuration config data to SvcLogicContext
1245         List<ConfigPortMirrorConfigurations> configPortMirrorConfigurations =
1246                 configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1247         ConfigPortMirrorConfigurations configPortMirrorConfiguration;
1248         if (configPortMirrorConfigurations != null && !configPortMirrorConfigurations.isEmpty()) {
1249             configPortMirrorConfiguration = configPortMirrorConfigurations.get(0);
1250             log.info("Read ({}) data for [{}] configuration-data: {}",
1251                     "CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId, configPortMirrorConfiguration.getPmcData());
1252             ctxIn.mergeJson("configuration-data", configPortMirrorConfiguration.getPmcData());
1253
1254         } else {
1255             log.info("No configuration-data found ({}) for [{}]", "CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId);
1256             configPortMirrorConfiguration = new ConfigPortMirrorConfigurations(configurationId, null);
1257         }
1258
1259         /*
1260         // Add configuration operational data to SvcLogicContext
1261         List<OperationalPortMirrorConfigurations> operPortMirrorConfigurations =
1262                 operationalPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1263         OperationalPortMirrorConfigurations operPortMirrorConfiguration;
1264
1265         if (operPortMirrorConfigurations != null && !operPortMirrorConfigurations.isEmpty()) {
1266             operPortMirrorConfiguration = operPortMirrorConfigurations.get(0);
1267             log.info("Read ({}) data for [{}] operational-data: {}",
1268                     "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId, operPortMirrorConfiguration.getPmcData());
1269             ctxIn.mergeJson("operational-data", operPortMirrorConfiguration.getPmcData());
1270
1271         } else {
1272             log.info("No operational-data found ({}) for [{}]", "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId);
1273             operPortMirrorConfiguration = new OperationalPortMirrorConfigurations(configurationId, null, null);
1274         }
1275
1276         */
1277
1278         String ackFinal = "Y";
1279         String errorCode = "200";
1280         String errorMessage = "SUCCESS";
1281         String respStatus = "SUCCESS";
1282
1283         log.info(ADDING_INPUT_DATA_LOG, svcOperation, svcInstanceId, input.getInput().toString());
1284         //log.info(ADDING_INPUT_DATA_LOG, svcOperation, svcInstanceId, input.toString());
1285
1286         // Update service status info in config entry from input
1287         configPortMirrorConfiguration.setPortMirrorConfigurationStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1288         configPortMirrorConfiguration.setPortMirrorConfigurationStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1289         configPortMirrorConfiguration.setPortMirrorConfigurationStatusRpcName(svcOperation);
1290
1291         // Call DG
1292         try {
1293             // Any of these can throw a nullpointer exception
1294             // execute should only throw a SvcLogicException
1295             SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1296             Properties respProps = ctxOut.toProperties();
1297
1298             ackFinal = respProps.getProperty("ack-final", "Y");
1299             errorCode = respProps.getProperty("error-code", "200");
1300             errorMessage = respProps.getProperty("error-message", "SUCCESS");
1301             log.info("ackFinal [{}], error-code [{}], error-message [{}]", ackFinal, errorCode, errorMessage);
1302
1303             resp.setAckFinalIndicator(ackFinal);
1304             resp.setResponseCode(errorCode);
1305             resp.setResponseMessage(errorMessage);
1306
1307             // Update status in config services entry
1308             configPortMirrorConfiguration
1309                     .setPortMirrorConfigurationStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1310             configPortMirrorConfiguration.setPortMirrorConfigurationStatusFinalIndicator(resp.getAckFinalIndicator());
1311             configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseCode(resp.getResponseCode());
1312             configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseMessage(resp.getResponseMessage());
1313             configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseTimestamp(Iso8601Util.now());
1314
1315             GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
1316             serviceReference.setInstanceId(svcInstanceId);
1317             serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
1318             resp.setServiceResponseInformation(serviceReference);
1319
1320             GenericResourceApiInstanceReference pmcReference = new GenericResourceApiInstanceReference();
1321             serviceReference.setInstanceId(configurationId);
1322             serviceReference.setObjectPath(respProps.getProperty(PORT_MIRROR_OBJECT_PATH_PARAM));
1323             resp.setServiceResponseInformation(pmcReference);
1324
1325             retval.setOutput(resp);
1326
1327             // ONLY update pmcData in config and operational trees
1328             //String ctxJson = ctxOut.toJsonString("configuration-data");
1329             //configPortMirrorConfiguration.setPmcData(ctxJson);
1330             //operPortMirrorConfiguration.setPmcData(ctxJson);
1331             //configPortMirrorConfigurationsRepository.save(configPortMirrorConfiguration);
1332
1333             // If necessary, sync status to operation service entry and save
1334             //operPortMirrorConfiguration.setPortMirrorConfigurationStatus(configPortMirrorConfiguration.getPortMirrorConfigurationStatus());
1335             //operationalPortMirrorConfigurationsRepository.save(operPortMirrorConfiguration);
1336
1337             if (! "200".equals(errorCode)) {
1338                 respStatus = "FAILED";
1339             }
1340
1341         } catch (NullPointerException npe) {
1342             resp.setAckFinalIndicator("Y");
1343             resp.setResponseCode("500");
1344             resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
1345         } catch (SvcLogicException e) {
1346             resp.setAckFinalIndicator("Y");
1347         }
1348
1349         if (ackFinal.equals("N")) {
1350             // Spawn background thread to invoke the Async DG
1351             Runnable backgroundThread = new Runnable() {
1352                 public void run() {
1353                     log.info(BACKGROUND_THREAD_STARTED_MESSAGE);
1354                     processAsyncPortMirrorTopologyOperation(svcOperation, input);
1355                  }
1356             };
1357             new Thread(backgroundThread).start();
1358         }
1359         log.info("Returned {} for {} [{}] {}.", respStatus, svcOperation, configurationId, errorMessage);
1360         return (new ResponseEntity<>(retval, HttpStatus.OK));
1361     }
1362
1363     public void processAsyncPortMirrorTopologyOperation( String parentOperation,
1364              @Valid GenericResourceApiPortMirrorTopologyOperationInformationBodyparam input) {
1365         log.info(BACKGROUND_THREAD_INFO, input.getInput().getConfigurationInformation().getConfigurationId());
1366         final String svcOperation = "port-mirror-topology-operation-async";
1367
1368         log.info(CALLED_STR, svcOperation);
1369         String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1370         String configurationId = input.getInput().getConfigurationInformation().getConfigurationId();
1371         SvcLogicContext ctxIn = new SvcLogicContext();
1372
1373         String errorMessage;
1374
1375         // Add input to SvcLogicContext
1376         try {
1377             ctxIn.mergeJson(parentOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1378         } catch (JsonProcessingException e) {
1379             log.error("exiting {} due to parse error on input data", svcOperation);
1380             return;
1381         }
1382
1383         // Add service instance config data to SvcLogicContext
1384         List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1385         ConfigServices configService = null;
1386         if (configServices != null && !configServices.isEmpty()) {
1387             configService = configServices.get(0);
1388             ctxIn.mergeJson("service-data", configService.getSvcData());
1389         } else {
1390             log.error("exiting {} because there is no service data with id [{}] in SDN", svcOperation, svcInstanceId);
1391             return;
1392         }
1393
1394         // Add config tree data to SvcLogicContext
1395         List<ConfigPortMirrorConfigurations> configPortMirrorConfigurations = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1396         ConfigPortMirrorConfigurations configPortMirrorConfiguration;
1397         if (configPortMirrorConfigurations != null && !configPortMirrorConfigurations.isEmpty()) {
1398             configPortMirrorConfiguration = configPortMirrorConfigurations.get(0);
1399             ctxIn.mergeJson("configuration-data", configPortMirrorConfiguration.getPmcData());
1400         } else {
1401             configPortMirrorConfiguration = new ConfigPortMirrorConfigurations(configurationId, null);
1402         }
1403
1404         /*
1405         // Add operational tree data to SvcLogicContext
1406         List<OperationalPortMirrorConfigurations> operPortMirrorConfigurations = operationalPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1407         OperationalPortMirrorConfigurations operPortMirrorConfiguration = null;
1408
1409         if (operPortMirrorConfigurations != null && !operPortMirrorConfigurations.isEmpty()) {
1410             operPortMirrorConfiguration = operPortMirrorConfigurations.get(0);
1411             ctxIn.mergeJson("operational-data", operPortMirrorConfiguration.getPmcData());
1412         } else {
1413             operPortMirrorConfiguration = new OperationalPortMirrorConfigurations(configurationId, null, null);
1414         }
1415
1416         */
1417
1418         // Update service status info in config entry from input
1419         configPortMirrorConfiguration.setPortMirrorConfigurationStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1420         configPortMirrorConfiguration.setPortMirrorConfigurationStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1421         configPortMirrorConfiguration.setPortMirrorConfigurationStatusRpcName(parentOperation);
1422
1423         log.info("Adding INPUT data for {} [{}] input: {}", svcOperation, svcInstanceId, input.toString());
1424
1425         // Call DG
1426         try {
1427             // Any of these can throw a nullpointer exception
1428             // execute should only throw a SvcLogicException
1429             SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1430             Properties respProps = ctxOut.toProperties();
1431
1432             String ackFinalIndicator = respProps.getProperty("ack-final-indicator", "Y");
1433             String errorCode = respProps.getProperty("error-code", "200");
1434             errorMessage = respProps.getProperty("error-message", "SUCCESS");
1435
1436             // Update status in config services entry
1437             configPortMirrorConfiguration.setPortMirrorConfigurationStatusFinalIndicator(ackFinalIndicator);
1438             configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseTimestamp(Iso8601Util.now());
1439             configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseCode(errorCode);
1440             configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseMessage(errorMessage);
1441             configPortMirrorConfiguration
1442                     .setPortMirrorConfigurationStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1443
1444             // ONLY update status
1445             //String ctxJson = ctxOut.toJsonString("configuration-data");
1446             //configPortMirrorConfiguration.setPmcData(ctxJson);
1447             //configPortMirrorConfiguration.setPmcData(ctxJson);
1448
1449             // Update config tree
1450             configPortMirrorConfigurationsRepository.save(configPortMirrorConfiguration);
1451
1452             //update operational tree
1453             //operPortMirrorConfiguration.setPortMirrorConfigurationStatus(configPortMirrorConfiguration.getPortMirrorConfigurationStatus());
1454             //operationalPortMirrorConfigurationsRepository.save(operPortMirrorConfiguration);
1455
1456         } catch (Exception e) {
1457             log.error("Caught Exception updating configuration status in SDN for {} [{}] \n", svcOperation, configurationId);
1458         }
1459         log.info("Returned SUCCESS for {} [{}]", svcOperation, configurationId);
1460     }
1461
1462     @Override
1463     public ResponseEntity<GenericResourceApiVnfGetResourceRequest> operationsGENERICRESOURCEAPIvnfGetResourceRequestPost(
1464             @Valid GenericResourceApiVnfgetresourcerequestInputBodyparam input)
1465             throws RestException {
1466         final String svcOperation = "vnf-get-resource-request";
1467         GenericResourceApiVnfGetResourceRequest retval = new GenericResourceApiVnfGetResourceRequest();
1468
1469         log.info(CALLED_STR, svcOperation);
1470         // Verify input contains service instance id
1471         if (hasInvalidServiceId(input.getInput())) {
1472             log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
1473             //return new ResponseEntity<>(retval, HttpStatus.OK);
1474         }
1475
1476         String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1477         SvcLogicContext ctxIn = new SvcLogicContext();
1478
1479         // Add input to SvcLogicContext
1480         try {
1481             ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1482         } catch (JsonProcessingException e) {
1483             log.error("exiting {} due to parse error on input data", svcOperation);
1484             return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1485         }
1486
1487         // Add config tree data to SvcLogicContext
1488         List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1489         ConfigServices configService = null;
1490         if (configServices != null && !configServices.isEmpty()) {
1491             configService = configServices.get(0);
1492             ctxIn.mergeJson("service-data", configService.getSvcData());
1493         } else {
1494             log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
1495             return new ResponseEntity<>(retval, HttpStatus.OK);
1496         }
1497
1498         // Call DG
1499         try {
1500             // Any of these can throw a nullpointer exception
1501             // execute should only throw a SvcLogicException
1502             SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1503             Properties respProps = ctxOut.toProperties();
1504
1505             /* For debugging Only
1506             respProps.forEach((k,v) -> {
1507                 log.debug("prop: {} -> {}",k,v);
1508             });
1509             */
1510
1511             String ctxJson = ctxOut.toJsonString("vnf-get-resource-request-output");
1512             GenericResourceApiVnfgetresourcerequestOutput vnfgetresourcerequestOutput =
1513                     objectMapper.readValue(ctxJson, GenericResourceApiVnfgetresourcerequestOutput.class);
1514
1515             retval.setOutput(vnfgetresourcerequestOutput);
1516
1517         } catch (Exception e) {
1518             return (new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR));
1519         }
1520         return (new ResponseEntity<>(retval, HttpStatus.OK));
1521     }
1522
1523     @Override
1524     public ResponseEntity<GenericResourceApiPolicyUpdateNotifyOperation> operationsGENERICRESOURCEAPIpolicyUpdateNotifyOperationPost(
1525             @Valid GenericResourceApiPolicyupdatenotifyoperationInputBodyparam input)
1526             throws RestException {
1527         final String svcOperation = "policy-update-notify-operation";
1528         GenericResourceApiPolicyUpdateNotifyOperation retval = new GenericResourceApiPolicyUpdateNotifyOperation();
1529         GenericResourceApiPolicyupdatenotifyoperationOutput resp = new GenericResourceApiPolicyupdatenotifyoperationOutput();
1530
1531         log.info(CALLED_STR, svcOperation);
1532         // Verify required input elements
1533         if (hasInvalidPolicyUpdateInput(input.getInput())) {
1534             log.debug("exiting {} because policy name, update type, or version id was not provided", svcOperation);
1535             resp.setErrorCode("404");
1536             resp.setErrorMsg("policy-name, update-type, and/or version-id is null or empty");
1537             retval.setOutput(resp);
1538             return new ResponseEntity<>(retval, HttpStatus.OK);
1539         }
1540
1541         SvcLogicContext ctxIn = new SvcLogicContext();
1542
1543         // Add input to SvcLogicContext
1544         try {
1545             ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1546         } catch (JsonProcessingException e) {
1547             log.error("exiting {} due to parse error on input data", svcOperation);
1548             resp.setErrorCode("500");
1549             resp.setErrorMsg("internal error");
1550             retval.setOutput(resp);
1551             return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1552         }
1553
1554         // Call DG
1555         try {
1556             // Any of these can throw a nullpointer exception
1557             // execute should only throw a SvcLogicException
1558             SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1559             Properties respProps = ctxOut.toProperties();
1560             resp.setErrorCode(respProps.getProperty("error-code", "200"));
1561             resp.setErrorMsg(respProps.getProperty("error-message", "SUCCESS"));
1562
1563             /* For debugging Only
1564             respProps.forEach((k,v) -> {
1565                 log.debug("prop: {} -> {}",k,v);
1566             });
1567              */
1568
1569         } catch (NullPointerException npe) {
1570             resp.setErrorCode("500");
1571             resp.setErrorMsg("Check that you populated module, rpc and or mode correctly.");
1572         } catch (SvcLogicException e) {
1573             resp.setErrorCode("500");
1574             resp.setErrorMsg(e.getMessage());
1575         }
1576
1577         retval.setOutput(resp);
1578         return (new ResponseEntity<>(retval, HttpStatus.OK));
1579     }
1580
1581 }