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()));
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);
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());
826 log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
828 resp.setResponseCode("404");
829 resp.setResponseMessage("invalid input: the service-instance does not have any service data in SDNC");
830 resp.setAckFinalIndicator("Y");
832 retval.setOutput(resp);
834 return new ResponseEntity<>(retval, HttpStatus.OK);
837 // Add operational tree data to SvcLogicContext
838 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
839 OperationalServices operService = null;
840 boolean saveOperationalData = false;
842 if (operServices != null && !operServices.isEmpty()) {
843 operService = operServices.get(0);
844 ctxIn.mergeJson("operational-data", operService.getSvcData());
846 operService = new OperationalServices(svcInstanceId, null, null);
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);
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();
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"));
868 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
870 if ("200".equals(resp.getResponseCode())) {
872 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
873 serviceReference.setInstanceId(svcInstanceId);
874 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
875 resp.setServiceResponseInformation(serviceReference);
878 vnfId = respProps.getProperty("vnfId");
880 GenericResourceApiInstanceReference vnfReference = new GenericResourceApiInstanceReference();
881 vnfReference.setInstanceId(vnfId);
882 vnfReference.setObjectPath(respProps.getProperty(VNF_OBJECT_PATH_PARAM));
883 resp.setVnfResponseInformation(vnfReference);
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;
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());
903 // Update status in config services entry
905 configService.setServiceStatusFinalIndicator(resp.getAckFinalIndicator());
906 configService.setServiceStatusResponseCode(resp.getResponseCode());
907 configService.setServiceStatusResponseMessage(resp.getResponseMessage());
908 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
910 // Update config tree
911 configServicesRepository.save(configService);
913 // If necessary, sync status to operation service entry and save
914 if (saveOperationalData) {
915 operService.setServiceStatus(configService.getServiceStatus());
916 operationalServicesRepository.save(operService);
918 retval.setOutput(resp);
919 return (new ResponseEntity<>(retval, HttpStatus.OK));
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();
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);
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);
942 // Verify input contains vnf-id
943 if (hasInvalidVnfId(input.getInput())) {
944 log.debug("exiting {} because of null or empty vnf-id", svcOperation);
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);
953 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
954 String vnfId = input.getInput().getVnfInformation().getVnfId();
955 String vfModuleId = input.getInput().getVfModuleInformation().getVfModuleId();
957 SvcLogicContext ctxIn = new SvcLogicContext();
959 // Add input to SvcLogicContext
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);
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());
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);
988 // Add operational tree data to SvcLogicContext
989 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
990 OperationalServices operService = null;
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());
998 log.info("No operational-data found in OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS for [{}]", svcInstanceId);
999 operService = new OperationalServices(svcInstanceId, null, null);
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);
1007 String ackFinal = "Y";
1008 String skipMdsalUpdate;
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();
1017 ackFinal = respProps.getProperty("ack-final", "Y");
1018 skipMdsalUpdate = respProps.getProperty("skip-mdsal-update", "N");
1019 log.info("ackFinal [{}], skipMdsalUpdate [{}]", ackFinal, skipMdsalUpdate);
1021 resp.setAckFinalIndicator(ackFinal);
1022 resp.setResponseCode(respProps.getProperty("error-code", "200"));
1023 resp.setResponseMessage(respProps.getProperty("error-message", "SUCCESS"));
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());
1031 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1033 if ("200".equals(resp.getResponseCode())) {
1035 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
1036 serviceReference.setInstanceId(svcInstanceId);
1037 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
1038 resp.setServiceResponseInformation(serviceReference);
1040 GenericResourceApiInstanceReference vnfReference = new GenericResourceApiInstanceReference();
1041 vnfReference.setInstanceId(vnfId);
1042 vnfReference.setObjectPath(respProps.getProperty(VNF_OBJECT_PATH_PARAM));
1043 resp.setVnfResponseInformation(vnfReference);
1045 GenericResourceApiInstanceReference vfModuleReference = new GenericResourceApiInstanceReference();
1046 vnfReference.setInstanceId(vfModuleId);
1047 vnfReference.setObjectPath(respProps.getProperty(VF_MODULE_OBJECT_PATH_PARAM));
1048 resp.setVnfResponseInformation(vfModuleReference);
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);
1059 log.info("Copying service-data to operational-data");
1060 operService.setSvcData(ctxJson);
1061 operService.setServiceStatus(configService.getServiceStatus());
1062 operationalServicesRepository.save(operService);
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");
1073 if (ackFinal.equals("N")) {
1074 // Spawn background thread to invoke the Async DG
1075 Runnable backgroundThread = new Runnable() {
1077 log.info(BACKGROUND_THREAD_STARTED_MESSAGE);
1078 processAsyncVfModuleTopologyOperation(svcOperation, input);
1081 new Thread(backgroundThread).start();
1083 retval.setOutput(resp);
1084 return (new ResponseEntity<>(retval, HttpStatus.OK));
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";
1092 log.info(CALLED_STR, svcOperation);
1093 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1094 SvcLogicContext ctxIn = new SvcLogicContext();
1096 // Add input to SvcLogicContext
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);
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());
1113 log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
1117 // Add operational tree data to SvcLogicContext
1118 List<OperationalServices> operServices = operationalServicesRepository.findBySvcInstanceId(svcInstanceId);
1119 OperationalServices operService = null;
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());
1127 log.info("No operational-data found in OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS for [{}]", svcInstanceId);
1128 operService = new OperationalServices(svcInstanceId, null, null);
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);
1136 String respStatus = "SUCCESS";
1137 String errorMessage = null;
1139 log.info ("Adding INPUT data for {} [{}] input: {}", svcOperation, svcInstanceId, input.getInput().toString());
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();
1148 String ackFinal = respProps.getProperty("ack-final-indicator", "Y");
1149 String errorCode = respProps.getProperty("error-code", "200");
1150 errorMessage = respProps.getProperty("error-message", "SUCCESS");
1152 if (! "200".equals(errorCode)) {
1153 respStatus = "FAILED";
1156 // Update status in config services entry
1157 configService.setServiceStatusFinalIndicator(ackFinal);
1158 configService.setServiceStatusResponseTimestamp(Iso8601Util.now());
1159 configService.setServiceStatusResponseCode(errorCode);
1160 configService.setServiceStatusResponseMessage(errorMessage);
1162 .setServiceStatusRequestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE.toString());
1164 String ctxJson = ctxOut.toJsonString("service-data");
1165 configServicesRepository.save(configService);
1167 operService.setSvcData(ctxJson);
1168 operService.setServiceStatus(configService.getServiceStatus());
1169 operationalServicesRepository.save(operService);
1171 } catch (Exception ex) {
1172 log.error("Caught Exception updating service status in SDN for {} [{}] \n", svcOperation, svcInstanceId);
1174 log.info("Returned {} for {} [{}] {}.", respStatus, svcOperation, svcInstanceId, errorMessage);
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();
1185 log.info(CALLED_STR, svcOperation);
1187 // Verify input contains configuration-id
1188 if (hasInvalidConfigurationId(input.getInput())) {
1189 log.debug("exiting {} because of null or empty configuration-id", svcOperation);
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);
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);
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);
1209 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1210 String configurationId = input.getInput().getConfigurationInformation().getConfigurationId();
1212 SvcLogicContext ctxIn = new SvcLogicContext();
1214 // Add input to SvcLogicContext
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);
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());
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");
1240 retval.setOutput(resp);
1241 return new ResponseEntity<>(retval, HttpStatus.OK);
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());
1255 log.info("No configuration-data found ({}) for [{}]", "CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId);
1256 configPortMirrorConfiguration = new ConfigPortMirrorConfigurations(configurationId, null);
1260 // Add configuration operational data to SvcLogicContext
1261 List<OperationalPortMirrorConfigurations> operPortMirrorConfigurations =
1262 operationalPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1263 OperationalPortMirrorConfigurations operPortMirrorConfiguration;
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());
1272 log.info("No operational-data found ({}) for [{}]", "OPERATIONAL_GRA_PORT_MIRROR_CONFIGURATIONS", configurationId);
1273 operPortMirrorConfiguration = new OperationalPortMirrorConfigurations(configurationId, null, null);
1278 String ackFinal = "Y";
1279 String errorCode = "200";
1280 String errorMessage = "SUCCESS";
1281 String respStatus = "SUCCESS";
1283 log.info(ADDING_INPUT_DATA_LOG, svcOperation, svcInstanceId, input.getInput().toString());
1284 //log.info(ADDING_INPUT_DATA_LOG, svcOperation, svcInstanceId, input.toString());
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);
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();
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);
1303 resp.setAckFinalIndicator(ackFinal);
1304 resp.setResponseCode(errorCode);
1305 resp.setResponseMessage(errorMessage);
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());
1315 GenericResourceApiInstanceReference serviceReference = new GenericResourceApiInstanceReference();
1316 serviceReference.setInstanceId(svcInstanceId);
1317 serviceReference.setObjectPath(respProps.getProperty(SERVICE_OBJECT_PATH_PARAM));
1318 resp.setServiceResponseInformation(serviceReference);
1320 GenericResourceApiInstanceReference pmcReference = new GenericResourceApiInstanceReference();
1321 serviceReference.setInstanceId(configurationId);
1322 serviceReference.setObjectPath(respProps.getProperty(PORT_MIRROR_OBJECT_PATH_PARAM));
1323 resp.setServiceResponseInformation(pmcReference);
1325 retval.setOutput(resp);
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);
1333 // If necessary, sync status to operation service entry and save
1334 //operPortMirrorConfiguration.setPortMirrorConfigurationStatus(configPortMirrorConfiguration.getPortMirrorConfigurationStatus());
1335 //operationalPortMirrorConfigurationsRepository.save(operPortMirrorConfiguration);
1337 if (! "200".equals(errorCode)) {
1338 respStatus = "FAILED";
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");
1349 if (ackFinal.equals("N")) {
1350 // Spawn background thread to invoke the Async DG
1351 Runnable backgroundThread = new Runnable() {
1353 log.info(BACKGROUND_THREAD_STARTED_MESSAGE);
1354 processAsyncPortMirrorTopologyOperation(svcOperation, input);
1357 new Thread(backgroundThread).start();
1359 log.info("Returned {} for {} [{}] {}.", respStatus, svcOperation, configurationId, errorMessage);
1360 return (new ResponseEntity<>(retval, HttpStatus.OK));
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";
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();
1373 String errorMessage;
1375 // Add input to SvcLogicContext
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);
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());
1390 log.error("exiting {} because there is no service data with id [{}] in SDN", svcOperation, svcInstanceId);
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());
1401 configPortMirrorConfiguration = new ConfigPortMirrorConfigurations(configurationId, null);
1405 // Add operational tree data to SvcLogicContext
1406 List<OperationalPortMirrorConfigurations> operPortMirrorConfigurations = operationalPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
1407 OperationalPortMirrorConfigurations operPortMirrorConfiguration = null;
1409 if (operPortMirrorConfigurations != null && !operPortMirrorConfigurations.isEmpty()) {
1410 operPortMirrorConfiguration = operPortMirrorConfigurations.get(0);
1411 ctxIn.mergeJson("operational-data", operPortMirrorConfiguration.getPmcData());
1413 operPortMirrorConfiguration = new OperationalPortMirrorConfigurations(configurationId, null, null);
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);
1423 log.info("Adding INPUT data for {} [{}] input: {}", svcOperation, svcInstanceId, input.toString());
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();
1432 String ackFinalIndicator = respProps.getProperty("ack-final-indicator", "Y");
1433 String errorCode = respProps.getProperty("error-code", "200");
1434 errorMessage = respProps.getProperty("error-message", "SUCCESS");
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());
1444 // ONLY update status
1445 //String ctxJson = ctxOut.toJsonString("configuration-data");
1446 //configPortMirrorConfiguration.setPmcData(ctxJson);
1447 //configPortMirrorConfiguration.setPmcData(ctxJson);
1449 // Update config tree
1450 configPortMirrorConfigurationsRepository.save(configPortMirrorConfiguration);
1452 //update operational tree
1453 //operPortMirrorConfiguration.setPortMirrorConfigurationStatus(configPortMirrorConfiguration.getPortMirrorConfigurationStatus());
1454 //operationalPortMirrorConfigurationsRepository.save(operPortMirrorConfiguration);
1456 } catch (Exception e) {
1457 log.error("Caught Exception updating configuration status in SDN for {} [{}] \n", svcOperation, configurationId);
1459 log.info("Returned SUCCESS for {} [{}]", svcOperation, configurationId);
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();
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);
1476 String svcInstanceId = input.getInput().getServiceInformation().getServiceInstanceId();
1477 SvcLogicContext ctxIn = new SvcLogicContext();
1479 // Add input to SvcLogicContext
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);
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());
1494 log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation);
1495 return new ResponseEntity<>(retval, HttpStatus.OK);
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();
1505 /* For debugging Only
1506 respProps.forEach((k,v) -> {
1507 log.debug("prop: {} -> {}",k,v);
1511 String ctxJson = ctxOut.toJsonString("vnf-get-resource-request-output");
1512 GenericResourceApiVnfgetresourcerequestOutput vnfgetresourcerequestOutput =
1513 objectMapper.readValue(ctxJson, GenericResourceApiVnfgetresourcerequestOutput.class);
1515 retval.setOutput(vnfgetresourcerequestOutput);
1517 } catch (Exception e) {
1518 return (new ResponseEntity<>(retval, HttpStatus.INTERNAL_SERVER_ERROR));
1520 return (new ResponseEntity<>(retval, HttpStatus.OK));
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();
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);
1541 SvcLogicContext ctxIn = new SvcLogicContext();
1543 // Add input to SvcLogicContext
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);
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"));
1563 /* For debugging Only
1564 respProps.forEach((k,v) -> {
1565 log.debug("prop: {} -> {}",k,v);
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());
1577 retval.setOutput(resp);
1578 return (new ResponseEntity<>(retval, HttpStatus.OK));