diff options
Diffstat (limited to 'adapters/mso-ve-vnfm-adapter/src/main')
6 files changed, 119 insertions, 95 deletions
diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java index fd20a0f78e..70e4e1d88b 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java @@ -25,11 +25,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Optional; import org.apache.logging.log4j.util.Strings; -import org.onap.aai.domain.yang.EsrSystemInfo; -import org.onap.aai.domain.yang.EsrSystemInfoList; -import org.onap.aai.domain.yang.EsrVnfm; -import org.onap.aai.domain.yang.EsrVnfmList; -import org.onap.aai.domain.yang.v18.GenericVnf; +import org.onap.aai.domain.yang.*; import org.onap.so.adapters.vevnfm.exception.VeVnfmException; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.AAIResourcesClient; @@ -45,14 +41,25 @@ public class AaiConnection { private static final Logger logger = LoggerFactory.getLogger(AaiConnection.class); + private static final String SELFLINK = "selflink"; private static final int FIRST_INDEX = 0; + private AAIResourcesClient resourcesClient = null; + private static void isValid(final List<EsrSystemInfo> infos) throws VeVnfmException { if (infos == null || infos.isEmpty() || Strings.isBlank(infos.get(FIRST_INDEX).getServiceUrl())) { throw new VeVnfmException("No 'url' field in VNFM info"); } } + private AAIResourcesClient getResourcesClient() { + if (resourcesClient == null) { + resourcesClient = new AAIResourcesClient(); + } + + return resourcesClient; + } + public List<EsrSystemInfo> receiveVnfm() throws VeVnfmException { List<EsrSystemInfo> infos; @@ -68,9 +75,8 @@ public class AaiConnection { } private List<EsrSystemInfo> receiveVnfmInternal() { - final AAIResourcesClient resourcesClient = new AAIResourcesClient(); final AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.VNFM_LIST); - final Optional<EsrVnfmList> response = resourcesClient.get(EsrVnfmList.class, resourceUri); + final Optional<EsrVnfmList> response = getResourcesClient().get(EsrVnfmList.class, resourceUri); if (response.isPresent()) { final EsrVnfmList esrVnfmList = response.get(); @@ -81,7 +87,7 @@ public class AaiConnection { for (final EsrVnfm vnfm : esrVnfm) { final String vnfmId = vnfm.getVnfmId(); - infos.addAll(receiveVnfmServiceUrl(resourcesClient, vnfmId)); + infos.addAll(receiveVnfmServiceUrl(vnfmId)); } return infos; @@ -90,8 +96,8 @@ public class AaiConnection { return null; } - private List<EsrSystemInfo> receiveVnfmServiceUrl(final AAIResourcesClient resourcesClient, final String vnfmId) { - final Optional<EsrVnfm> response = resourcesClient.get(EsrVnfm.class, + private List<EsrSystemInfo> receiveVnfmServiceUrl(final String vnfmId) { + final Optional<EsrVnfm> response = getResourcesClient().get(EsrVnfm.class, AAIUriFactory.createResourceUri(AAIObjectType.VNFM, vnfmId).depth(Depth.ONE)); if (response.isPresent()) { @@ -107,17 +113,24 @@ public class AaiConnection { return Collections.emptyList(); } - public boolean checkGenericVnfId(final String vnfId) { - final AAIResourcesClient resourcesClient = new AAIResourcesClient(); - final AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId); - final Optional<GenericVnf> response = resourcesClient.get(GenericVnf.class, resourceUri); + public String receiveGenericVnfId(final String href) { + final AAIResourceUri resourceUri = + AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNFS).queryParam(SELFLINK, href); + final Optional<GenericVnfs> response = getResourcesClient().get(GenericVnfs.class, resourceUri); if (response.isPresent()) { - final GenericVnf vnf = response.get(); - logger.info("The AAI replied with: {}", vnf); - return vnfId.equals(vnf.getVnfId()); + final GenericVnfs vnfs = response.get(); + logger.info("The AAI replied with: {}", vnfs); + final List<GenericVnf> genericVnfList = vnfs.getGenericVnf(); + final int size = genericVnfList.size(); + + if (size == 1) { + return genericVnfList.get(FIRST_INDEX).getVnfId(); + } else if (size > 1) { + logger.warn("more generic vnfs available"); + } } - return false; + return null; } } diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java index 1560b3be4d..36bc23d1b5 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java @@ -20,14 +20,10 @@ package org.onap.so.adapters.vevnfm.controller; -import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; -import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType; -import org.onap.so.adapters.vevnfm.service.DmaapService; -import org.onap.so.adapters.vevnfm.service.VnfAaiChecker; import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification; +import org.onap.so.adapters.vevnfm.service.DmaapConditionalSender; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -38,29 +34,20 @@ public class NotificationController { private static final Logger logger = LoggerFactory.getLogger(NotificationController.class); - private final NotificationVnfFilterType notificationVnfFilterType; - private final VnfAaiChecker vnfAaiChecker; - private final DmaapService dmaapService; + private final DmaapConditionalSender dmaapConditionalSender; - @Autowired - public NotificationController(final ConfigProperties configProperties, final VnfAaiChecker vnfAaiChecker, - final DmaapService dmaapService) { - this.notificationVnfFilterType = configProperties.getNotificationVnfFilterType(); - this.vnfAaiChecker = vnfAaiChecker; - this.dmaapService = dmaapService; + public NotificationController(final DmaapConditionalSender dmaapConditionalSender) { + this.dmaapConditionalSender = dmaapConditionalSender; } @PostMapping("${vnfm.notification}") public ResponseEntity receiveNotification(@RequestBody final VnfLcmOperationOccurrenceNotification notification) { logger.info("Notification received {}", notification); - final String vnfInstanceId = notification.getVnfInstanceId(); - - if (vnfAaiChecker.vnfCheck(notificationVnfFilterType, vnfInstanceId)) { - logger.info("The info with the VNF id '{}' is sent to DMaaP", vnfInstanceId); - dmaapService.send(notification); - } else { - logger.info("This VNF id '{}' is not supported", vnfInstanceId); + try { + dmaapConditionalSender.send(notification); + } catch (NullPointerException e) { + logger.warn("NullPointerException caught while sending to DMaaP", e); } return ResponseEntity.ok().build(); diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java index 8ef3f24d2f..a3ff2dcd6d 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java @@ -47,7 +47,7 @@ public class DmaapEvent { private final VnfLcmOperationOccurrenceNotification etsiLcmEvent; public DmaapEvent(final String closedLoopControlName, final String version, - final VnfLcmOperationOccurrenceNotification etsiLcmEvent) { + final VnfLcmOperationOccurrenceNotification etsiLcmEvent, final String genericId) { this.closedLoopControlName = closedLoopControlName; this.closedLoopAlarmStart = Instant.now().getLong(INSTANT_SECONDS); this.closedLoopEventClient = MSERVICE; @@ -55,7 +55,7 @@ public class DmaapEvent { this.requestId = UUID.randomUUID().toString(); this.targetType = VNF; this.target = VNFID; - this.aaiEvent = new AaiEvent(false, etsiLcmEvent.getId()); + this.aaiEvent = (genericId == null) ? null : new AaiEvent(false, genericId); this.from = ETSI; this.version = version; this.etsiLcmEvent = etsiLcmEvent; diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSender.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSender.java new file mode 100644 index 0000000000..b96bffa58f --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSender.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * SO + * ================================================================================ + * Copyright (C) 2020 Samsung. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.vevnfm.service; + +import org.apache.logging.log4j.util.Strings; +import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification; +import org.onap.so.adapters.vevnfm.aai.AaiConnection; +import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; +import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +@Service +public class DmaapConditionalSender { + + private static final Logger logger = LoggerFactory.getLogger(DmaapConditionalSender.class); + + private final NotificationVnfFilterType notificationVnfFilterType; + private final AaiConnection aaiConnection; + private final DmaapService dmaapService; + + public DmaapConditionalSender(final ConfigProperties configProperties, final AaiConnection aaiConnection, + final DmaapService dmaapService) { + this.notificationVnfFilterType = configProperties.getNotificationVnfFilterType(); + this.aaiConnection = aaiConnection; + this.dmaapService = dmaapService; + } + + public void send(final VnfLcmOperationOccurrenceNotification notification) { + final String href = notification.getLinks().getVnfInstance().getHref(); + boolean logSent = false; + + switch (notificationVnfFilterType) { + case ALL: + dmaapService.send(notification, aaiConnection.receiveGenericVnfId(href)); + logSent = true; + break; + case AAI_CHECKED: + final String genericId = aaiConnection.receiveGenericVnfId(href); + if (Strings.isNotBlank(genericId)) { + dmaapService.send(notification, genericId); + logSent = true; + } + break; + case NONE: + break; + default: + throw new IllegalArgumentException( + "The value of VnfNotificationFilterType is not supported: " + notificationVnfFilterType); + } + + final String vnfInstanceId = notification.getVnfInstanceId(); + final String not = logSent ? "" : "not "; + logger.info("The info with the VNF id '{}' is " + not + "sent to DMaaP", vnfInstanceId); + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java index c13811d9d0..278f9dee95 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java @@ -20,9 +20,9 @@ package org.onap.so.adapters.vevnfm.service; +import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification; import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; import org.onap.so.adapters.vevnfm.event.DmaapEvent; -import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification; import org.onap.so.rest.service.HttpRestServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,9 +51,9 @@ public class DmaapService { this.restProvider = restProvider; } - public void send(final VnfLcmOperationOccurrenceNotification notification) { + public void send(final VnfLcmOperationOccurrenceNotification notification, final String genericId) { try { - final DmaapEvent event = new DmaapEvent(closedLoopControlName, version, notification); + final DmaapEvent event = new DmaapEvent(closedLoopControlName, version, notification, genericId); final ResponseEntity<String> response = restProvider.postHttpRequest(event, getUrl(), String.class); final HttpStatus statusCode = response.getStatusCode(); final String body = response.getBody(); diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/VnfAaiChecker.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/VnfAaiChecker.java deleted file mode 100644 index 1442fa2862..0000000000 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/VnfAaiChecker.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SO - * ================================================================================ - * Copyright (C) 2020 Samsung. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.vevnfm.service; - -import org.onap.so.adapters.vevnfm.aai.AaiConnection; -import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class VnfAaiChecker { - - private final AaiConnection aaiConnection; - - @Autowired - public VnfAaiChecker(final AaiConnection aaiConnection) { - this.aaiConnection = aaiConnection; - } - - public boolean vnfCheck(final NotificationVnfFilterType filterType, final String vnfId) { - switch (filterType) { - case ALL: - return true; - case AAI_CHECKED: - return aaiConnection.checkGenericVnfId(vnfId); - case NONE: - return false; - default: - throw new IllegalArgumentException( - "The value of VnfNotificationFilterType is not supported: " + filterType); - } - } -} |