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 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;
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;
60 import javax.servlet.http.HttpServletRequest;
61 import javax.validation.Valid;
63 import java.text.DateFormat;
64 import java.text.SimpleDateFormat;
66 import java.util.concurrent.atomic.AtomicBoolean;
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 {
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: {}";
88 private final ObjectMapper objectMapper;
90 private final HttpServletRequest request;
93 protected SvcLogicServiceBase svc;
96 private ConfigPreloadDataRepository configPreloadDataRepository;
99 private OperationalPreloadDataRepository operationalPreloadDataRepository;
102 private ConfigServicesRepository configServicesRepository;
105 private OperationalServicesRepository operationalServicesRepository;
108 private ConfigContrailRouteAllottedResourcesRepository configContrailRouteAllottedResourcesRepository;
111 private OperationalContrailRouteAllottedResourcesRepository operationalContrailRouteAllottedResourcesRepository;
114 private ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository;
117 private OperationalPortMirrorConfigurationsRepository operationalPortMirrorConfigurationsRepository;
119 private static class Iso8601Util {
121 private static TimeZone timeZone = TimeZone.getTimeZone("UTC");
122 private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
124 private Iso8601Util() {
128 dateFormat.setTimeZone(timeZone);
131 private static String now() {
132 return dateFormat.format(new Date());
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;
145 public Optional<ObjectMapper> getObjectMapper() {
146 return Optional.ofNullable(objectMapper);
150 public Optional<HttpServletRequest> getRequest() {
151 return Optional.ofNullable(request);
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();
161 log.info(CALLED_STR, svcOperation);
162 if (hasInvalidPreloadNetwork(graInput)) {
163 log.debug("exiting {} because of null or empty preload-network-topology-information", svcOperation);
165 resp.setResponseCode("403");
166 resp.setResponseMessage("invalid input, null or empty preload-network-topology-information");
167 resp.setAckFinalIndicator("Y");
169 retval.setOutput(resp);
171 return new ResponseEntity<>(retval, HttpStatus.FORBIDDEN);
174 String preloadId = graInput.getInput().getPreloadNetworkTopologyInformation()
175 .getNetworkTopologyIdentifierStructure().getNetworkId();
176 String preloadType = "network";
178 resp.setSvcRequestId(graInput.getInput().getSdncRequestHeader().getSvcRequestId());
180 SvcLogicContext ctxIn = new SvcLogicContext();
182 GenericResourceApiPreloaddataPreloadData preloadData = null;
184 // Add input to SvcLogicContext
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);
196 // Add config tree data to SvcLogicContext
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);
209 // Add operational tree data to SvcLogicContext
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);
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();
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"));
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);
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());
265 retval.setOutput(resp);
266 return (new ResponseEntity<>(retval, HttpStatus.valueOf(Integer.parseInt(resp.getResponseCode()))));
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();
276 log.info(CALLED_STR, svcOperation);
277 if (hasInvalidPreloadNetwork(graInput)) {
278 log.debug("exiting {} because of null or empty preload-network-topology-information", svcOperation);
280 resp.setResponseCode("403");
281 resp.setResponseMessage("invalid input, null or empty preload-network-topology-information");
282 resp.setAckFinalIndicator("Y");
284 retval.setOutput(resp);
286 return new ResponseEntity<>(retval, HttpStatus.FORBIDDEN);
289 String preloadId = graInput.getInput().getPreloadVfModuleTopologyInformation().getVfModuleTopology()
290 .getVfModuleTopologyIdentifier().getVfModuleName();
291 String preloadType = "vf-module";
293 resp.setSvcRequestId(graInput.getInput().getSdncRequestHeader().getSvcRequestId());
295 SvcLogicContext ctxIn = new SvcLogicContext();
297 GenericResourceApiPreloaddataPreloadData preloadData = null;
299 // Add input to SvcLogicContext
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);
311 // Add config tree data to SvcLogicContext
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);
324 // Add operational tree data to SvcLogicContext
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);
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();
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"));
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);
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());
375 retval.setOutput(resp);
376 return (new ResponseEntity<>(retval, HttpStatus.valueOf(Integer.parseInt(resp.getResponseCode()))));
379 private boolean hasInvalidPreloadNetwork(
380 GenericResourceApiPreloadnetworktopologyoperationInputBodyparam preloadData) {
381 return ((preloadData == null) || (preloadData.getInput() == null)
382 || (preloadData.getInput().getPreloadNetworkTopologyInformation() == null));
385 private boolean hasInvalidPreloadNetwork(
386 GenericResourceApiPreloadvfmoduletopologyoperationInputBodyparam preloadData) {
387 return ((preloadData == null) || (preloadData.getInput() == null)
388 || (preloadData.getInput().getPreloadVfModuleTopologyInformation() == null));
391 private boolean hasInvalidServiceId(GenericResourceApiServiceOperationInformation input) {
393 return input == null || input.getServiceInformation() == null
394 || input.getServiceInformation().getServiceInstanceId() == null
395 || input.getServiceInformation().getServiceInstanceId().length() == 0;
398 private boolean hasInvalidServiceId(GenericResourceApiNetworkOperationInformation input) {
400 return input == null || input.getServiceInformation() == null
401 || input.getServiceInformation().getServiceInstanceId() == null
402 || input.getServiceInformation().getServiceInstanceId().length() == 0;
405 private boolean hasInvalidServiceId(GenericResourceApiVnfOperationInformation input) {
407 return input == null || input.getServiceInformation() == null
408 || input.getServiceInformation().getServiceInstanceId() == null
409 || input.getServiceInformation().getServiceInstanceId().length() == 0;
412 private boolean hasInvalidServiceId(GenericResourceApiVfModuleOperationInformation input) {
414 return input == null || input.getServiceInformation() == null
415 || input.getServiceInformation().getServiceInstanceId() == null
416 || input.getServiceInformation().getServiceInstanceId().length() == 0;
419 private boolean hasInvalidServiceId(GenericResourceApiPortMirrorTopologyOperationInformation input) {
421 return input == null || input.getServiceInformation() == null
422 || input.getServiceInformation().getServiceInstanceId() == null
423 || input.getServiceInformation().getServiceInstanceId().length() == 0;
426 private boolean hasInvalidServiceId(GenericResourceApiVnfgetresourcerequestInput input) {
428 return input == null || input.getServiceInformation() == null
429 || input.getServiceInformation().getServiceInstanceId() == null
430 || input.getServiceInformation().getServiceInstanceId().length() == 0;
433 private boolean hasInvalidVnfId(GenericResourceApiVfModuleOperationInformation input) {
435 return input == null || input.getVnfInformation() == null
436 || input.getVnfInformation().getVnfId() == null
437 || input.getVnfInformation().getVnfId().length() == 0;
440 private boolean hasInvalidConfigurationId(GenericResourceApiPortMirrorTopologyOperationInformation input) {
441 return input.getConfigurationInformation() == null
442 || input.getConfigurationInformation().getConfigurationId() == null
443 || input.getConfigurationInformation().getConfigurationId().length() == 0;
446 private boolean hasInvalidPolicyUpdateInput(GenericResourceApiPolicyupdatenotifyoperationInput input) {
447 return (input.getPolicyName() == null) || (input.getUpdateType() == null) || (input.getVersionId() == null);
450 private GenericResourceApiPreloaddataPreloadData getConfigPreloadData(String preloadId, String preloadType)
451 throws JsonProcessingException {
453 List<ConfigPreloadData> configPreloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
456 if (configPreloadData.isEmpty()) {
459 return (objectMapper.readValue(configPreloadData.get(0).getPreloadData(),
460 GenericResourceApiPreloaddataPreloadData.class));
464 private GenericResourceApiPreloaddataPreloadData getOperationalPreloadData(String preloadId, String preloadType)
465 throws JsonProcessingException {
467 List<OperationalPreloadData> configPreloadData = operationalPreloadDataRepository
468 .findByPreloadIdAndPreloadType(preloadId, preloadType);
470 if (configPreloadData.isEmpty()) {
473 return (objectMapper.readValue(configPreloadData.get(0).getPreloadData(),
474 GenericResourceApiPreloaddataPreloadData.class));
478 private void saveConfigPreloadData(String preloadId, String preloadType,
479 GenericResourceApiPreloaddataPreloadData preloadData) throws JsonProcessingException {
481 configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
482 configPreloadDataRepository
483 .save(new ConfigPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadData)));
487 private void saveOperationalPreloadData(String preloadId, String preloadType,
488 GenericResourceApiPreloaddataPreloadData preloadData) throws JsonProcessingException {
490 operationalPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
491 operationalPreloadDataRepository
492 .save(new OperationalPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadData)));
496 private GenericResourceApiServicedataServiceData getConfigServiceData(String svcInstanceId)
497 throws JsonProcessingException {
499 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
501 if (configServices.isEmpty()) {
504 return (objectMapper.readValue(configServices.get(0).getSvcData(),
505 GenericResourceApiServicedataServiceData.class));
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();
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);
521 resp.setResponseCode("404");
522 resp.setResponseMessage("null or empty service-instance-id");
523 resp.setAckFinalIndicator("Y");
525 retval.setOutput(resp);
527 return new ResponseEntity<>(retval, HttpStatus.OK);
530 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
532 SvcLogicContext ctxIn = new SvcLogicContext();
534 // Add input to SvcLogicContext
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);
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();
554 if (svcData != null) {
555 ctxIn.mergeJson("service-data", configService.getSvcData());
557 log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
559 resp.setResponseCode("404");
560 resp.setResponseMessage("invalid input: the service-instance does not have any service data in SDNC");
561 resp.setAckFinalIndicator("Y");
563 retval.setOutput(resp);
565 return new ResponseEntity<>(retval, HttpStatus.OK);
568 // Add operational tree data to SvcLogicContext
569 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
570 OperationalServices operService = null;
571 boolean saveOperationalData = false;
573 if (operServices != null && !operServices.isEmpty()) {
574 operService = operServices.get(0);
575 ctxIn.mergeJson("operational-data", operService.getSvcData());
577 operService = new OperationalServices(svcInstanceId, null, null);
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);
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();
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"));
599 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
601 if ("200".equals(resp.getResponseCode())) {
603 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
604 serviceReference.setInstanceId(svcInstanceId);
605 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
606 resp.setServiceResponseInformation(serviceReference);
608 GenericResourceApiInstanceReference networkReference = new GenericResourceApiInstanceReference();
609 networkReference.setInstanceId(respProps.getProperty("networkId"));
610 networkReference.setObjectPath(respProps.getProperty(NETWORK_OBJECT_PATH_PARAM));
611 resp.setNetworkResponseInformation(networkReference);
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;
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());
631 // Update status in config services entry
633 configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
634 configService.setServiceStatusResponseCode(resp.getResponseCode());
635 configService.setServiceStatusResponseMessage(resp.getResponseMessage());
636 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
638 // Update config tree
639 configServicesRepository.save(configService);
641 // If necessary, sync status to operation service entry and save
642 if (saveOperationalData) {
643 operService.setServiceStatus(configService.getServiceStatus());
644 operationalServicesRepository.save(operService);
646 retval.setOutput(resp);
648 return (new ResponseEntity<>(retval, HttpStatus.OK));
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();
658 log.info(CALLED_STR, svcOperation);
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);
664 resp.setResponseCode("404");
665 resp.setResponseMessage("null or empty service-instance-id");
666 resp.setAckFinalIndicator("Y");
668 retval.setOutput(resp);
670 return new ResponseEntity<>(retval, HttpStatus.OK);
673 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
675 SvcLogicContext ctxIn = new SvcLogicContext();
677 // Add input to SvcLogicContext
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);
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());
698 configService = new ConfigServices(svcInstanceId, null);
701 // Add operational tree data to SvcLogicContext
702 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
703 OperationalServices operService = null;
704 boolean saveOperationalData = false;
706 if (operServices != null && !operServices.isEmpty()) {
707 operService = operServices.get(0);
708 ctxIn.mergeJson("operational-data", operService.getSvcData());
710 operService = new OperationalServices(svcInstanceId, null, null);
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);
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();
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"));
730 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
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);
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;
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());
756 // Update status in config services entry
758 configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
759 configService.setServiceStatusResponseCode(resp.getResponseCode());
760 configService.setServiceStatusResponseMessage(resp.getResponseMessage());
761 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
763 // Update config tree
764 configServicesRepository.save(configService);
766 // If necessary, sync status to operation service entry and save
767 if (saveOperationalData) {
768 operService.setServiceStatus(configService.getServiceStatus());
769 operationalServicesRepository.save(operService);
771 retval.setOutput(resp);
772 return (new ResponseEntity<>(retval, HttpStatus.OK));
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();
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);
789 resp.setResponseCode("404");
790 resp.setResponseMessage("null or empty service-instance-id");
791 resp.setAckFinalIndicator("Y");
793 retval.setOutput(resp);
795 return new ResponseEntity<>(retval, HttpStatus.OK);
798 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
801 if((input.getInput() != null) && (input.getInput().getVnfInformation() != null)) {
802 vnfId = input.getInput().getVnfInformation().getVnfId();
805 SvcLogicContext ctxIn = new SvcLogicContext();
807 // Add input to SvcLogicContext
809 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
811 catch(JsonProcessingException e) {
812 log.error("exiting {} due to parse error on input data", svcOperation);
813 resp.setResponseCode("500");
814 resp.setResponseMessage("internal error");
815 resp.setAckFinalIndicator("Y");
816 retval.setOutput(resp);
817 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
820 // Add config tree data to SvcLogicContext
821 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
822 ConfigServices configService = null;
823 if(configServices != null && !configServices.isEmpty()) {
824 configService = configServices.get(0);
825 ctxIn.mergeJson("service-data", configService.getSvcData());
828 log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
830 resp.setResponseCode("404");
831 resp.setResponseMessage("invalid input: the service-instance does not have any service data in SDNC");
832 resp.setAckFinalIndicator("Y");
834 retval.setOutput(resp);
836 return new ResponseEntity<>(retval, HttpStatus.OK);
839 // Add operational tree data to SvcLogicContext
840 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
841 OperationalServices operService = null;
842 boolean saveOperationalData = false;
844 if(operServices != null && !operServices.isEmpty()) {
845 operService = operServices.get(0);
846 ctxIn.mergeJson("operational-data", operService.getSvcData());
849 operService = new OperationalServices(svcInstanceId, null, null);
852 // Update service status info in config entry from input
853 configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
854 configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
855 configService.setServiceStatusRpcName(svcOperation);
860 // Any of these can throw a nullpointer exception
861 // execute should only throw a SvcLogicException
862 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
863 Properties respProps = ctxOut.toProperties();
865 resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
866 resp.setResponseCode(respProps.getProperty("error-code", "200"));
867 resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
870 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
872 if("200".equals(resp.getResponseCode())) {
874 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
875 serviceReference.setInstanceId(svcInstanceId);
876 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
877 resp.setServiceResponseInformation(serviceReference);
880 vnfId = respProps.getProperty("vnfId");
882 GenericResourceApiInstanceReference vnfReference = new GenericResourceApiInstanceReference();
883 vnfReference.setInstanceId(vnfId);
884 vnfReference.setObjectPath(respProps.getProperty(VNF_OBJECT_PATH_PARAM));
885 resp.setVnfResponseInformation(vnfReference);
887 // If DG returns success, update svcData in config and operational trees
888 // and remember to save operational data.
889 String ctxJson = ctxOut.toJsonString("service-data");
890 configService.setSvcData(ctxJson);
891 operService.setSvcData(ctxJson);
892 saveOperationalData = true;
896 catch(NullPointerException npe) {
897 resp.setAckFinalIndicator("Y");
898 resp.setResponseCode("500");
899 resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
901 catch(SvcLogicException e) {
902 resp.setAckFinalIndicator("Y");
903 resp.setResponseCode("500");
904 resp.setResponseMessage(e.getMessage());
907 // Update status in config services entry
909 configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
910 configService.setServiceStatusResponseCode(resp.getResponseCode());
911 configService.setServiceStatusResponseMessage(resp.getResponseMessage());
912 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
914 // Update config tree
915 configServicesRepository.save(configService);
917 // If necessary, sync status to operation service entry and save
918 if(saveOperationalData) {
919 operService.setServiceStatus(configService.getServiceStatus());
920 operationalServicesRepository.save(operService);
923 if(resp.getAckFinalIndicator().equals("N")) {
924 // Spawn background thread to invoke the Async DG
925 Runnable backgroundThread = () -> {
926 log.info(BACKGROUND_THREAD_STARTED_MESSAGE);
927 processAsyncVnfTopologyOperation(svcOperation, input);
929 new Thread(backgroundThread).start();
932 log.info("Returned {} for {} [{}] {}.", resp.getResponseCode(), svcOperation, vnfId, resp.getResponseMessage());
933 retval.setOutput(resp);
934 return (new ResponseEntity<>(retval, HttpStatus.OK));
937 public void processAsyncVnfTopologyOperation(String parentOperation, @Valid GenericResourceApiVnfOperationInformationBodyparam input) {
938 final String svcOperation = "vnf-topology-operation-async";
939 GenericResourceApiVnftopologyoperationOutput resp = new GenericResourceApiVnftopologyoperationOutput();
941 log.info(CALLED_STR, svcOperation);
942 // Verify input contains service instance id
943 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
944 String vnfId = input.getInput().getVnfInformation().getVnfId();
946 SvcLogicContext ctxIn = new SvcLogicContext();
948 // Add input to SvcLogicContext
950 ctxIn.mergeJson(parentOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
951 } catch (JsonProcessingException e) {
952 log.error("exiting {} due to parse error on input data", svcOperation);
956 // Add config tree data to SvcLogicContext
957 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
958 ConfigServices configService = null;
959 if(configServices != null && !configServices.isEmpty()) {
960 configService = configServices.get(0);
961 ctxIn.mergeJson("service-data", configService.getSvcData());
964 log.error("exiting {} because there is no service data with id [{}] in SDN", svcOperation, svcInstanceId);
968 // Add operational tree data to SvcLogicContext
969 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
970 OperationalServices operService = null;
972 if(operServices != null && !operServices.isEmpty()) {
973 operService = operServices.get(0);
974 ctxIn.mergeJson("operational-data", operService.getSvcData());
977 operService = new OperationalServices(svcInstanceId, null, null);
980 // Update service status info in config entry from input
981 configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
982 configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
983 configService.setServiceStatusRpcName(svcOperation);
988 // Any of these can throw a nullpointer exception
989 // execute should only throw a SvcLogicException
990 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
991 Properties respProps = ctxOut.toProperties();
993 resp.setAckFinalIndicator(respProps.getProperty("ack-final-indicator", "Y"));
994 resp.setResponseCode(respProps.getProperty("error-code", "200"));
995 resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
998 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1000 if("200".equals(resp.getResponseCode())) {
1001 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
1002 serviceReference.setInstanceId(svcInstanceId);
1003 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
1004 resp.setServiceResponseInformation(serviceReference);
1007 vnfId = respProps.getProperty("vnfId");
1009 GenericResourceApiInstanceReference vnfReference = new GenericResourceApiInstanceReference();
1010 vnfReference.setInstanceId(vnfId);
1011 vnfReference.setObjectPath(respProps.getProperty(VNF_OBJECT_PATH_PARAM));
1012 resp.setVnfResponseInformation(vnfReference);
1014 // If DG returns success, update svcData in config and operational trees
1015 // and remember to save operational data.
1016 String ctxJson = ctxOut.toJsonString("service-data");
1017 configService.setSvcData(ctxJson);
1018 operService.setSvcData(ctxJson);
1020 // Update status in config services entry
1022 configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
1023 configService.setServiceStatusResponseCode(resp.getResponseCode());
1024 configService.setServiceStatusResponseMessage(resp.getResponseMessage());
1025 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
1027 // Update config and operational tree
1028 configServicesRepository.save(configService);
1029 operService.setServiceStatus(configService.getServiceStatus());
1030 operationalServicesRepository.save(operService);
1031 log.info("Returned SUCCESS for {} [{}]", svcOperation, vnfId);
1034 catch(Exception e) {
1035 log.error("Caught Exception updating configuration status in SDN for {} [{}] \n", svcOperation, vnfId);
1040 public ResponseEntity<GenericResourceApiVfModuleTopologyOperation> operationsGENERICRESOURCEAPIvfModuleTopologyOperationPost(
1041 @Valid GenericResourceApiVfModuleOperationInformationBodyparam input)
1042 throws RestException {
1043 final String svcOperation = "vf-module-topology-operation";
1044 GenericResourceApiVfModuleTopologyOperation retval = new GenericResourceApiVfModuleTopologyOperation();
1045 GenericResourceApiVfmoduletopologyoperationOutput resp = new GenericResourceApiVfmoduletopologyoperationOutput();
1047 log.info(CALLED_STR, svcOperation);
1048 // Verify input contains service instance id
1049 if (hasInvalidServiceId(input.getInput())) {
1050 log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
1052 resp.setResponseCode("404");
1053 resp.setResponseMessage("null or empty service-instance-id");
1054 resp.setAckFinalIndicator("Y");
1055 retval.setOutput(resp);
1056 return new ResponseEntity<>(retval, HttpStatus.OK);
1059 // Verify input contains vnf-id
1060 if (hasInvalidVnfId(input.getInput())) {
1061 log.debug("exiting {} because of null or empty vnf-id", svcOperation);
1063 resp.setResponseCode("404");
1064 resp.setResponseMessage("null or empty vnf-id");
1065 resp.setAckFinalIndicator("Y");
1066 retval.setOutput(resp);
1067 return new ResponseEntity<>(retval, HttpStatus.OK);
1070 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1071 String vnfId = input.getInput().getVnfInformation().getVnfId();
1072 String vfModuleId = input.getInput().getVfModuleInformation().getVfModuleId();
1074 SvcLogicContext ctxIn = new SvcLogicContext();
1076 // Add input to SvcLogicContext
1078 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1079 } catch (JsonProcessingException e) {
1080 log.error("exiting {} due to parse error on input data", svcOperation);
1081 resp.setResponseCode("500");
1082 resp.setResponseMessage("internal error");
1083 resp.setAckFinalIndicator("Y");
1084 retval.setOutput(resp);
1085 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1088 // Add config tree data to SvcLogicContext
1089 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1090 ConfigServices configService = null;
1091 if (configServices != null && !configServices.isEmpty()) {
1092 configService = configServices.get(0);
1093 log.info("Read ({}) data for [{}] service-data: {}",
1094 "CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS", svcInstanceId, configService.getSvcData().toString());
1095 ctxIn.mergeJson("service-data", configService.getSvcData());
1097 log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
1098 resp.setResponseCode("404");
1099 resp.setResponseMessage("invalid input: the service-instance does not have any service data in SDNC");
1100 resp.setAckFinalIndicator("Y");
1101 retval.setOutput(resp);
1102 return new ResponseEntity<>(retval, HttpStatus.OK);
1105 // Add operational tree data to SvcLogicContext
1106 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
1107 OperationalServices operService = null;
1109 if (operServices != null && !operServices.isEmpty()) {
1110 operService = operServices.get(0);
1111 log.info("Read ({}) data for [{}] operational-data: {}",
1112 "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", svcInstanceId, operService.getSvcData().toString());
1113 //ctxIn.mergeJson("operational-data", operService.getSvcData());
1115 log.info("No operational-data found in OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS for [{}]", svcInstanceId);
1116 operService = new OperationalServices(svcInstanceId, null, null);
1119 // Update service status info in config entry from input
1120 configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1121 configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1122 configService.setServiceStatusRpcName(svcOperation);
1124 String ackFinal = "Y";
1125 String skipMdsalUpdate;
1129 // Any of these can throw a nullpointer exception
1130 // execute should only throw a SvcLogicException
1131 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1132 Properties respProps = ctxOut.toProperties();
1134 ackFinal = respProps.getProperty("ack-final", "Y");
1135 skipMdsalUpdate = respProps.getProperty("skip-mdsal-update", "N");
1136 log.info("ackFinal [{}], skipMdsalUpdate [{}]", ackFinal, skipMdsalUpdate);
1138 resp.setAckFinalIndicator(ackFinal);
1139 resp.setResponseCode(respProps.getProperty("error-code", "200"));
1140 resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
1142 // Update status in config services entry
1143 configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
1144 configService.setServiceStatusResponseCode(resp.getResponseCode());
1145 configService.setServiceStatusResponseMessage(resp.getResponseMessage());
1146 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
1148 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1150 if ("200".equals(resp.getResponseCode())) {
1152 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
1153 serviceReference.setInstanceId(svcInstanceId);
1154 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
1155 resp.setServiceResponseInformation(serviceReference);
1157 GenericResourceApiInstanceReference vnfReference = new GenericResourceApiInstanceReference();
1158 vnfReference.setInstanceId(vnfId);
1159 vnfReference.setObjectPath(respProps.getProperty(VNF_OBJECT_PATH_PARAM));
1160 resp.setVnfResponseInformation(vnfReference);
1162 GenericResourceApiInstanceReference vfModuleReference = new GenericResourceApiInstanceReference();
1163 vnfReference.setInstanceId(vfModuleId);
1164 vnfReference.setObjectPath(respProps.getProperty(VF_MODULE_OBJECT_PATH_PARAM));
1165 resp.setVnfResponseInformation(vfModuleReference);
1167 if (skipMdsalUpdate.equals("N")) {
1168 // If DG returns success,
1169 // ONLY update svcData in config and operational trees
1170 // and remember to save operational data when skip-mdsal-update is Y in ctx.
1171 String ctxJson = ctxOut.toJsonString("service-data");
1172 log.info("Saving service-data in SDN because skiMdsalUpdate is {}", skipMdsalUpdate);
1173 configService.setSvcData(ctxJson);
1174 configServicesRepository.save(configService);
1176 log.info("Copying service-data to operational-data");
1177 operService.setSvcData(ctxJson);
1178 operService.setServiceStatus(configService.getServiceStatus());
1179 operationalServicesRepository.save(operService);
1182 } catch (NullPointerException npe) {
1183 resp.setAckFinalIndicator("Y");
1184 resp.setResponseCode("500");
1185 resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
1186 } catch (SvcLogicException e) {
1187 resp.setAckFinalIndicator("Y");
1190 if (ackFinal.equals("N")) {
1191 // Spawn background thread to invoke the Async DG
1192 Runnable backgroundThread = new Runnable() {
1194 log.info(BACKGROUND_THREAD_STARTED_MESSAGE);
1195 processAsyncVfModuleTopologyOperation(svcOperation, input);
1198 new Thread(backgroundThread).start();
1200 retval.setOutput(resp);
1201 return (new ResponseEntity<>(retval, HttpStatus.OK));
1204 public void processAsyncVfModuleTopologyOperation( String parentOperation,
1205 @Valid GenericResourceApiVfModuleOperationInformationBodyparam input) {
1206 log.info(BACKGROUND_THREAD_INFO, input.getInput().getVfModuleInformation().getVfModuleId());
1207 final String svcOperation = "vf-module-topology-operation-async";
1209 log.info(CALLED_STR, svcOperation);
1210 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1211 SvcLogicContext ctxIn = new SvcLogicContext();
1213 // Add input to SvcLogicContext
1215 ctxIn.mergeJson(parentOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1216 } catch (JsonProcessingException e) {
1217 log.error("exiting {} due to parse error on input data", svcOperation);
1221 // Add config tree data to SvcLogicContext
1222 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1223 ConfigServices configService = null;
1224 if (configServices != null && !configServices.isEmpty()) {
1225 configService = configServices.get(0);
1226 log.info("Read ({}) data for [{}] service-data: {}",
1227 "CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS", svcInstanceId, configService.getSvcData().toString());
1228 ctxIn.mergeJson("service-data", configService.getSvcData());
1230 log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
1234 // Add operational tree data to SvcLogicContext
1235 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
1236 OperationalServices operService = null;
1238 if (operServices != null && !operServices.isEmpty()) {
1239 operService = operServices.get(0);
1240 log.info("Read ({}) data for [{}] operational-data: {}",
1241 "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", svcInstanceId, operService.getSvcData().toString());
1242 //ctxIn.mergeJson("operational-data", operService.getSvcData());
1244 log.info("No operational-data found in OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS for [{}]", svcInstanceId);
1245 operService = new OperationalServices(svcInstanceId, null, null);
1248 // Update service status info in config entry from input
1249 configService.setServiceStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1250 configService.setServiceStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1251 configService.setServiceStatusRpcName(svcOperation);
1253 String respStatus = "SUCCESS";
1254 String errorMessage = null;
1256 log.info ("Adding INPUT data for {} [{}] input: {}", svcOperation, svcInstanceId, input.getInput().toString());
1260 // Any of these can throw a nullpointer exception
1261 // execute should only throw a SvcLogicException
1262 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1263 Properties respProps = ctxOut.toProperties();
1265 String ackFinal = respProps.getProperty("ack-final-indicator", "Y");
1266 String errorCode = respProps.getProperty("error-code", "200");
1267 errorMessage = respProps.getProperty("error-message", "SUCCESS");
1269 if (! "200".equals(errorCode)) {
1270 respStatus = "FAILED";
1273 // Update status in config services entry
1274 configService.setServiceStatusFinalIndicator(ackFinal);
1275 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
1276 configService.setServiceStatusResponseCode(errorCode);
1277 configService.setServiceStatusResponseMessage(errorMessage);
1279 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1281 String ctxJson = ctxOut.toJsonString("service-data");
1282 configServicesRepository.save(configService);
1284 operService.setSvcData(ctxJson);
1285 operService.setServiceStatus(configService.getServiceStatus());
1286 operationalServicesRepository.save(operService);
1288 } catch (Exception ex) {
1289 log.error("Caught Exception updating service status in SDN for {} [{}] \n", svcOperation, svcInstanceId);
1291 log.info("Returned {} for {} [{}] {}.", respStatus, svcOperation, svcInstanceId, errorMessage);
1295 public ResponseEntity<GenericResourceApiPortMirrorTopologyOperation> operationsGENERICRESOURCEAPIportMirrorTopologyOperationPost(
1296 @Valid GenericResourceApiPortMirrorTopologyOperationInformationBodyparam input)
1297 throws RestException {
1298 final String svcOperation = "port-mirror-topology-operation";
1299 GenericResourceApiPortMirrorTopologyOperation retval = new GenericResourceApiPortMirrorTopologyOperation();
1300 GenericResourceApiPortmirrortopologyoperationOutput resp = new GenericResourceApiPortmirrortopologyoperationOutput();
1302 log.info(CALLED_STR, svcOperation);
1304 // Verify input contains configuration-id
1305 if (hasInvalidConfigurationId(input.getInput())) {
1306 log.debug("exiting {} because of null or empty configuration-id", svcOperation);
1308 resp.setResponseCode("404");
1309 resp.setResponseMessage("null or empty configuration-id");
1310 resp.setAckFinalIndicator("Y");
1311 retval.setOutput(resp);
1312 return new ResponseEntity<>(retval, HttpStatus.OK);
1315 // Verify input contains service instance id
1316 if (hasInvalidServiceId(input.getInput())) {
1317 log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
1319 resp.setResponseCode("404");
1320 resp.setResponseMessage("null or empty service-instance-id");
1321 resp.setAckFinalIndicator("Y");
1322 retval.setOutput(resp);
1323 return new ResponseEntity<>(retval, HttpStatus.OK);
1326 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1327 String configurationId = input.getInput().getConfigurationInformation().getConfigurationId();
1329 SvcLogicContext ctxIn = new SvcLogicContext();
1331 // Add input to SvcLogicContext
1333 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1334 } catch (JsonProcessingException e) {
1335 log.error("exiting {} due to parse error on input data", svcOperation);
1336 resp.setResponseCode("500");
1337 resp.setResponseMessage("internal error");
1338 resp.setAckFinalIndicator("Y");
1339 retval.setOutput(resp);
1340 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1343 // Add service instance config data to SvcLogicContext
1344 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1345 ConfigServices configService = null;
1346 if (configServices != null && !configServices.isEmpty()) {
1347 configService = configServices.get(0);
1348 log.info("Read ({}) data for [{}] service-data: {}", "CONFIG_GRA_SERVICES", svcInstanceId, configService.getSvcData());
1349 ctxIn.mergeJson("service-data", configService.getSvcData());
1352 log.debug("exiting {} because there is no service data with id [{}] in SDN", svcOperation, svcInstanceId);
1353 resp.setResponseCode("404");
1354 resp.setResponseMessage("invalid input: there is no service-instance with id [{}] in SDNC");
1355 resp.setAckFinalIndicator("Y");
1357 retval.setOutput(resp);
1358 return new ResponseEntity<>(retval, HttpStatus.OK);
1361 // Add configuration config data to SvcLogicContext
1362 List<ConfigPortMirrorConfigurations> configPortMirrorConfigurations =
1363 configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1364 ConfigPortMirrorConfigurations configPortMirrorConfiguration;
1365 if (configPortMirrorConfigurations != null && !configPortMirrorConfigurations.isEmpty()) {
1366 configPortMirrorConfiguration = configPortMirrorConfigurations.get(0);
1367 log.info("Read ({}) data for [{}] configuration-data: {}",
1368 "CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId, configPortMirrorConfiguration.getPmcData());
1369 ctxIn.mergeJson("configuration-data", configPortMirrorConfiguration.getPmcData());
1372 log.info("No configuration-data found ({}) for [{}]", "CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId);
1373 configPortMirrorConfiguration = new ConfigPortMirrorConfigurations(configurationId, null);
1377 // Add configuration operational data to SvcLogicContext
1378 List<OperationalPortMirrorConfigurations> operPortMirrorConfigurations =
1379 operationalPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1380 OperationalPortMirrorConfigurations operPortMirrorConfiguration;
1382 if (operPortMirrorConfigurations != null && !operPortMirrorConfigurations.isEmpty()) {
1383 operPortMirrorConfiguration = operPortMirrorConfigurations.get(0);
1384 log.info("Read ({}) data for [{}] operational-data: {}",
1385 "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId, operPortMirrorConfiguration.getPmcData());
1386 ctxIn.mergeJson("operational-data", operPortMirrorConfiguration.getPmcData());
1389 log.info("No operational-data found ({}) for [{}]", "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId);
1390 operPortMirrorConfiguration = new OperationalPortMirrorConfigurations(configurationId, null, null);
1395 String ackFinal = "Y";
1396 String errorCode = "200";
1397 String errorMessage = "SUCCESS";
1398 String respStatus = "SUCCESS";
1400 log.info(ADDING_INPUT_DATA_LOG, svcOperation, svcInstanceId, input.getInput().toString());
1401 //log.info(ADDING_INPUT_DATA_LOG, svcOperation, svcInstanceId, input.toString());
1403 // Update service status info in config entry from input
1404 configPortMirrorConfiguration.setPortMirrorConfigurationStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1405 configPortMirrorConfiguration.setPortMirrorConfigurationStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1406 configPortMirrorConfiguration.setPortMirrorConfigurationStatusRpcName(svcOperation);
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 errorCode = respProps.getProperty("error-code", "200");
1417 errorMessage = respProps.getProperty("error-message", "SUCCESS");
1418 log.info("ackFinal [{}], error-code [{}], error-message [{}]", ackFinal, errorCode, errorMessage);
1420 resp.setAckFinalIndicator(ackFinal);
1421 resp.setResponseCode(errorCode);
1422 resp.setResponseMessage(errorMessage);
1424 // Update status in config services entry
1425 configPortMirrorConfiguration
1426 .setPortMirrorConfigurationStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1427 configPortMirrorConfiguration.setPortMirrorConfigurationStatusFinalIndicator(resp.getAckFinalIndicator());
1428 configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseCode(resp.getResponseCode());
1429 configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseMessage(resp.getResponseMessage());
1430 configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseTimestamp(Iso8601Util.now());
1432 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
1433 serviceReference.setInstanceId(svcInstanceId);
1434 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
1435 resp.setServiceResponseInformation(serviceReference);
1437 GenericResourceApiInstanceReference pmcReference = new GenericResourceApiInstanceReference();
1438 serviceReference.setInstanceId(configurationId);
1439 serviceReference.setObjectPath(respProps.getProperty(PORT_MIRROR_OBJECT_PATH_PARAM));
1440 resp.setServiceResponseInformation(pmcReference);
1442 retval.setOutput(resp);
1444 // ONLY update pmcData in config and operational trees
1445 //String ctxJson = ctxOut.toJsonString("configuration-data");
1446 //configPortMirrorConfiguration.setPmcData(ctxJson);
1447 //operPortMirrorConfiguration.setPmcData(ctxJson);
1448 //configPortMirrorConfigurationsRepository.save(configPortMirrorConfiguration);
1450 // If necessary, sync status to operation service entry and save
1451 //operPortMirrorConfiguration.setPortMirrorConfigurationStatus(configPortMirrorConfiguration.getPortMirrorConfigurationStatus());
1452 //operationalPortMirrorConfigurationsRepository.save(operPortMirrorConfiguration);
1454 if (! "200".equals(errorCode)) {
1455 respStatus = "FAILED";
1458 } catch (NullPointerException npe) {
1459 resp.setAckFinalIndicator("Y");
1460 resp.setResponseCode("500");
1461 resp.setResponseMessage("Check that you populated module, rpc and or mode correctly.");
1462 } catch (SvcLogicException e) {
1463 resp.setAckFinalIndicator("Y");
1466 if (ackFinal.equals("N")) {
1467 // Spawn background thread to invoke the Async DG
1468 Runnable backgroundThread = new Runnable() {
1470 log.info(BACKGROUND_THREAD_STARTED_MESSAGE);
1471 processAsyncPortMirrorTopologyOperation(svcOperation, input);
1474 new Thread(backgroundThread).start();
1476 log.info("Returned {} for {} [{}] {}.", respStatus, svcOperation, configurationId, errorMessage);
1477 return (new ResponseEntity<>(retval, HttpStatus.OK));
1480 public void processAsyncPortMirrorTopologyOperation( String parentOperation,
1481 @Valid GenericResourceApiPortMirrorTopologyOperationInformationBodyparam input) {
1482 log.info(BACKGROUND_THREAD_INFO, input.getInput().getConfigurationInformation().getConfigurationId());
1483 final String svcOperation = "port-mirror-topology-operation-async";
1485 log.info(CALLED_STR, svcOperation);
1486 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1487 String configurationId = input.getInput().getConfigurationInformation().getConfigurationId();
1488 SvcLogicContext ctxIn = new SvcLogicContext();
1490 String errorMessage;
1492 // Add input to SvcLogicContext
1494 ctxIn.mergeJson(parentOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1495 } catch (JsonProcessingException e) {
1496 log.error("exiting {} due to parse error on input data", svcOperation);
1500 // Add service instance config data to SvcLogicContext
1501 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1502 ConfigServices configService = null;
1503 if (configServices != null && !configServices.isEmpty()) {
1504 configService = configServices.get(0);
1505 ctxIn.mergeJson("service-data", configService.getSvcData());
1507 log.error("exiting {} because there is no service data with id [{}] in SDN", svcOperation, svcInstanceId);
1511 // Add config tree data to SvcLogicContext
1512 List<ConfigPortMirrorConfigurations> configPortMirrorConfigurations = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1513 ConfigPortMirrorConfigurations configPortMirrorConfiguration;
1514 if (configPortMirrorConfigurations != null && !configPortMirrorConfigurations.isEmpty()) {
1515 configPortMirrorConfiguration = configPortMirrorConfigurations.get(0);
1516 ctxIn.mergeJson("configuration-data", configPortMirrorConfiguration.getPmcData());
1518 configPortMirrorConfiguration = new ConfigPortMirrorConfigurations(configurationId, null);
1522 // Add operational tree data to SvcLogicContext
1523 List<OperationalPortMirrorConfigurations> operPortMirrorConfigurations = operationalPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1524 OperationalPortMirrorConfigurations operPortMirrorConfiguration = null;
1526 if (operPortMirrorConfigurations != null && !operPortMirrorConfigurations.isEmpty()) {
1527 operPortMirrorConfiguration = operPortMirrorConfigurations.get(0);
1528 ctxIn.mergeJson("operational-data", operPortMirrorConfiguration.getPmcData());
1530 operPortMirrorConfiguration = new OperationalPortMirrorConfigurations(configurationId, null, null);
1535 // Update service status info in config entry from input
1536 configPortMirrorConfiguration.setPortMirrorConfigurationStatusAction(input.getInput().getRequestInformation().getRequestAction().toString());
1537 configPortMirrorConfiguration.setPortMirrorConfigurationStatusRpcAction(input.getInput().getSdncRequestHeader().getSvcAction().toString());
1538 configPortMirrorConfiguration.setPortMirrorConfigurationStatusRpcName(parentOperation);
1540 log.info("Adding INPUT data for {} [{}] input: {}", svcOperation, svcInstanceId, input.toString());
1544 // Any of these can throw a nullpointer exception
1545 // execute should only throw a SvcLogicException
1546 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1547 Properties respProps = ctxOut.toProperties();
1549 String ackFinalIndicator = respProps.getProperty("ack-final-indicator", "Y");
1550 String errorCode = respProps.getProperty("error-code", "200");
1551 errorMessage = respProps.getProperty("error-message", "SUCCESS");
1553 // Update status in config services entry
1554 configPortMirrorConfiguration.setPortMirrorConfigurationStatusFinalIndicator(ackFinalIndicator);
1555 configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseTimestamp(Iso8601Util.now());
1556 configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseCode(errorCode);
1557 configPortMirrorConfiguration.setPortMirrorConfigurationStatusResponseMessage(errorMessage);
1558 configPortMirrorConfiguration
1559 .setPortMirrorConfigurationStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1561 // ONLY update status
1562 //String ctxJson = ctxOut.toJsonString("configuration-data");
1563 //configPortMirrorConfiguration.setPmcData(ctxJson);
1564 //configPortMirrorConfiguration.setPmcData(ctxJson);
1566 // Update config tree
1567 configPortMirrorConfigurationsRepository.save(configPortMirrorConfiguration);
1569 //update operational tree
1570 //operPortMirrorConfiguration.setPortMirrorConfigurationStatus(configPortMirrorConfiguration.getPortMirrorConfigurationStatus());
1571 //operationalPortMirrorConfigurationsRepository.save(operPortMirrorConfiguration);
1573 } catch (Exception e) {
1574 log.error("Caught Exception updating configuration status in SDN for {} [{}] \n", svcOperation, configurationId);
1576 log.info("Returned SUCCESS for {} [{}]", svcOperation, configurationId);
1580 public ResponseEntity<GenericResourceApiVnfGetResourceRequest> operationsGENERICRESOURCEAPIvnfGetResourceRequestPost(
1581 @Valid GenericResourceApiVnfgetresourcerequestInputBodyparam input)
1582 throws RestException {
1583 final String svcOperation = "vnf-get-resource-request";
1584 GenericResourceApiVnfGetResourceRequest retval = new GenericResourceApiVnfGetResourceRequest();
1586 log.info(CALLED_STR, svcOperation);
1587 // Verify input contains service instance id
1588 if (hasInvalidServiceId(input.getInput())) {
1589 log.debug("exiting {} because of null or empty service-instance-id", svcOperation);
1590 //return new ResponseEntity<>(retval, HttpStatus.OK);
1593 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1594 SvcLogicContext ctxIn = new SvcLogicContext();
1596 // Add input to SvcLogicContext
1598 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1599 } catch (JsonProcessingException e) {
1600 log.error("exiting {} due to parse error on input data", svcOperation);
1601 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1604 // Add config tree data to SvcLogicContext
1605 List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId);
1606 ConfigServices configService = null;
1607 if (configServices != null && !configServices.isEmpty()) {
1608 configService = configServices.get(0);
1609 ctxIn.mergeJson("service-data", configService.getSvcData());
1611 log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
1612 return new ResponseEntity<>(retval, HttpStatus.OK);
1617 // Any of these can throw a nullpointer exception
1618 // execute should only throw a SvcLogicException
1619 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1620 Properties respProps = ctxOut.toProperties();
1622 /* For debugging Only
1623 respProps.forEach((k,v) -> {
1624 log.debug("prop: {} -> {}",k,v);
1628 String ctxJson = ctxOut.toJsonString("vnf-get-resource-request-output");
1629 GenericResourceApiVnfgetresourcerequestOutput vnfgetresourcerequestOutput =
1630 objectMapper.readValue(ctxJson, GenericResourceApiVnfgetresourcerequestOutput.class);
1632 retval.setOutput(vnfgetresourcerequestOutput);
1634 } catch (Exception e) {
1635 return (new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR));
1637 return (new ResponseEntity<>(retval, HttpStatus.OK));
1641 public ResponseEntity<GenericResourceApiPolicyUpdateNotifyOperation> operationsGENERICRESOURCEAPIpolicyUpdateNotifyOperationPost(
1642 @Valid GenericResourceApiPolicyupdatenotifyoperationInputBodyparam input)
1643 throws RestException {
1644 final String svcOperation = "policy-update-notify-operation";
1645 GenericResourceApiPolicyUpdateNotifyOperation retval = new GenericResourceApiPolicyUpdateNotifyOperation();
1646 GenericResourceApiPolicyupdatenotifyoperationOutput resp = new GenericResourceApiPolicyupdatenotifyoperationOutput();
1648 log.info(CALLED_STR, svcOperation);
1649 // Verify required input elements
1650 if (hasInvalidPolicyUpdateInput(input.getInput())) {
1651 log.debug("exiting {} because policy name, update type, or version id was not provided", svcOperation);
1652 resp.setErrorCode("404");
1653 resp.setErrorMsg("policy-name, update-type, and/or version-id is null or empty");
1654 retval.setOutput(resp);
1655 return new ResponseEntity<>(retval, HttpStatus.OK);
1658 SvcLogicContext ctxIn = new SvcLogicContext();
1660 // Add input to SvcLogicContext
1662 ctxIn.mergeJson(svcOperation + "-input", objectMapper.writeValueAsString(input.getInput()));
1663 } catch (JsonProcessingException e) {
1664 log.error("exiting {} due to parse error on input data", svcOperation);
1665 resp.setErrorCode("500");
1666 resp.setErrorMsg("internal error");
1667 retval.setOutput(resp);
1668 return new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR);
1673 // Any of these can throw a nullpointer exception
1674 // execute should only throw a SvcLogicException
1675 SvcLogicContext ctxOut = svc.execute(MODULE_NAME, svcOperation, null, "sync", ctxIn);
1676 Properties respProps = ctxOut.toProperties();
1677 resp.setErrorCode(respProps.getProperty("error-code", "200"));
1678 resp.setErrorMsg(respProps.getProperty("error-message", "SUCCESS"));
1680 /* For debugging Only
1681 respProps.forEach((k,v) -> {
1682 log.debug("prop: {} -> {}",k,v);
1686 } catch (NullPointerException npe) {
1687 resp.setErrorCode("500");
1688 resp.setErrorMsg("Check that you populated module, rpc and or mode correctly.");
1689 } catch (SvcLogicException e) {
1690 resp.setErrorCode("500");
1691 resp.setErrorMsg(e.getMessage());
1694 retval.setOutput(resp);
1695 return (new ResponseEntity<>(retval, HttpStatus.OK));