diff options
Diffstat (limited to 'adapters/mso-ve-vnfm-adapter')
20 files changed, 525 insertions, 71 deletions
diff --git a/adapters/mso-ve-vnfm-adapter/pom.xml b/adapters/mso-ve-vnfm-adapter/pom.xml index 3d054d9eca..42d20dc021 100644 --- a/adapters/mso-ve-vnfm-adapter/pom.xml +++ b/adapters/mso-ve-vnfm-adapter/pom.xml @@ -35,7 +35,12 @@ </dependency> <dependency> <groupId>org.onap.so.adapters</groupId> - <artifactId>mso-vnfm-adapter-ext-clients</artifactId> + <artifactId>etsi-sol003-lcm-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.so.adapters</groupId> + <artifactId>etsi-sol003-lcm-ext-clients</artifactId> <version>${project.version}</version> </dependency> <dependency> 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 9b2a8c3d62..fd20a0f78e 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 @@ -26,8 +26,10 @@ 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.so.adapters.vevnfm.exception.VeVnfmException; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.AAIResourcesClient; @@ -72,7 +74,7 @@ public class AaiConnection { if (response.isPresent()) { final EsrVnfmList esrVnfmList = response.get(); - logger.info("The VNFM replied with: {}", esrVnfmList); + logger.info("The AAI ESR replied with: {}", esrVnfmList); final List<EsrVnfm> esrVnfm = esrVnfmList.getEsrVnfm(); final List<EsrSystemInfo> infos = new LinkedList<>(); @@ -94,10 +96,28 @@ public class AaiConnection { if (response.isPresent()) { final EsrVnfm esrVnfm = response.get(); - logger.info("The VNFM replied with: {}", esrVnfm); - return esrVnfm.getEsrSystemInfoList().getEsrSystemInfo(); + logger.info("The AAI ESR replied with: {}", esrVnfm); + final EsrSystemInfoList esrSystemInfoList = esrVnfm.getEsrSystemInfoList(); + + if (esrSystemInfoList != null) { + return esrSystemInfoList.getEsrSystemInfo(); + } } 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); + + if (response.isPresent()) { + final GenericVnf vnf = response.get(); + logger.info("The AAI replied with: {}", vnf); + return vnfId.equals(vnf.getVnfId()); + } + + return false; + } } diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiPropertiesExt.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiPropertiesExt.java index aa8c7f68c9..e8660086c0 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiPropertiesExt.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiPropertiesExt.java @@ -22,6 +22,7 @@ package org.onap.so.adapters.vevnfm.aai; import java.net.MalformedURLException; import java.net.URL; +import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; import org.onap.so.client.aai.AAIProperties; import org.onap.so.client.aai.AAIVersion; import org.onap.so.spring.SpringContextHelper; @@ -29,15 +30,18 @@ import org.springframework.context.ApplicationContext; public class AaiPropertiesExt implements AAIProperties { + private static final String MSO = "MSO"; + private final String endpoint; private final String encryptedBasicAuth; private final String encryptionKey; public AaiPropertiesExt() { final ApplicationContext context = SpringContextHelper.getAppContext(); - this.endpoint = context.getEnvironment().getProperty("aai.endpoint"); - this.encryptedBasicAuth = context.getEnvironment().getProperty("aai.auth"); - this.encryptionKey = context.getEnvironment().getProperty("mso.key"); + final ConfigProperties configProperties = context.getBean(ConfigProperties.class); + this.endpoint = configProperties.getAaiEndpoint(); + this.encryptedBasicAuth = configProperties.getAaiAuth(); + this.encryptionKey = configProperties.getMsoKey(); } @Override @@ -47,7 +51,7 @@ public class AaiPropertiesExt implements AAIProperties { @Override public String getSystemName() { - return "MSO"; + return MSO; } @Override diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/ConfigProperties.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/ConfigProperties.java new file mode 100644 index 0000000000..d4ca5af0f2 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/ConfigProperties.java @@ -0,0 +1,134 @@ +/*- + * ============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.configuration; + +import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class ConfigProperties { + + @Value("${vevnfmadapter.vnf-filter-json}") + private String vevnfmadapterVnfFilterJson; + + @Value("${vevnfmadapter.endpoint}") + private String vevnfmadapterEndpoint; + + @Value("${mso.key}") + private String msoKey; + + @Value("${aai.endpoint}") + private String aaiEndpoint; + + @Value("${aai.auth}") + private String aaiAuth; + + @Value("${vnfm.default-endpoint}") + private String vnfmDefaultEndpoint; + + @Value("${vnfm.subscription}") + private String vnfmSubscription; + + @Value("${vnfm.notification}") + private String vnfmNotification; + + @Value("${notification.vnf-filter-type}") + private NotificationVnfFilterType notificationVnfFilterType; + + @Value("${dmaap.endpoint}") + private String dmaapEndpoint; + + @Value("${dmaap.topic}") + private String dmaapTopic; + + @Value("${dmaap.closed-loop.control.name}") + private String dmaapClosedLoopControlName; + + @Value("${dmaap.version}") + private String dmaapVersion; + + @Value("${spring.security.usercredentials[0].username}") + private String springSecurityUsername; + + @Value("${spring.security.usercredentials[0].openpass}") + private String springSecurityOpenpass; + + public String getVevnfmadapterVnfFilterJson() { + return vevnfmadapterVnfFilterJson; + } + + public String getVevnfmadapterEndpoint() { + return vevnfmadapterEndpoint; + } + + public String getMsoKey() { + return msoKey; + } + + public String getAaiEndpoint() { + return aaiEndpoint; + } + + public String getAaiAuth() { + return aaiAuth; + } + + public String getVnfmDefaultEndpoint() { + return vnfmDefaultEndpoint; + } + + public String getVnfmSubscription() { + return vnfmSubscription; + } + + public String getVnfmNotification() { + return vnfmNotification; + } + + public NotificationVnfFilterType getNotificationVnfFilterType() { + return notificationVnfFilterType; + } + + public String getDmaapEndpoint() { + return dmaapEndpoint; + } + + public String getDmaapTopic() { + return dmaapTopic; + } + + public String getDmaapClosedLoopControlName() { + return dmaapClosedLoopControlName; + } + + public String getDmaapVersion() { + return dmaapVersion; + } + + public String getSpringSecurityUsername() { + return springSecurityUsername; + } + + public String getSpringSecurityOpenpass() { + return springSecurityOpenpass; + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/StartupConfiguration.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/StartupConfiguration.java index c033fc3f96..8b5afbf6a1 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/StartupConfiguration.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/StartupConfiguration.java @@ -36,14 +36,17 @@ public class StartupConfiguration { public static final String TEST_PROFILE = "test"; - @Autowired - private Environment environment; - - @Autowired - private StartupService startupService; + private final Environment environment; + private final StartupService startupService; + private final SubscriptionScheduler subscriptionScheduler; @Autowired - private SubscriptionScheduler subscriptionScheduler; + public StartupConfiguration(final Environment environment, final StartupService startupService, + final SubscriptionScheduler subscriptionScheduler) { + this.environment = environment; + this.startupService = startupService; + this.subscriptionScheduler = subscriptionScheduler; + } @EventListener(ApplicationReadyEvent.class) public void onApplicationReadyEvent() throws Exception { diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/constant/NotificationVnfFilterType.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/constant/NotificationVnfFilterType.java new file mode 100644 index 0000000000..57935a9fda --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/constant/NotificationVnfFilterType.java @@ -0,0 +1,41 @@ +/*- + * ============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.constant; + +/** + * Select which incoming Notification with particular VNF id should be supported + */ +public enum NotificationVnfFilterType { + /** + * None + */ + NONE, + + /** + * Only those which are valid in AAI + */ + AAI_CHECKED, + + /** + * All + */ + ALL +} 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 cb324c32a9..1560b3be4d 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,8 +20,11 @@ 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.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification; +import org.onap.so.adapters.vevnfm.service.VnfAaiChecker; +import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,13 +38,31 @@ public class NotificationController { private static final Logger logger = LoggerFactory.getLogger(NotificationController.class); + private final NotificationVnfFilterType notificationVnfFilterType; + private final VnfAaiChecker vnfAaiChecker; + private final DmaapService dmaapService; + @Autowired - private DmaapService dmaapService; + public NotificationController(final ConfigProperties configProperties, final VnfAaiChecker vnfAaiChecker, + final DmaapService dmaapService) { + this.notificationVnfFilterType = configProperties.getNotificationVnfFilterType(); + this.vnfAaiChecker = vnfAaiChecker; + this.dmaapService = dmaapService; + } @PostMapping("${vnfm.notification}") public ResponseEntity receiveNotification(@RequestBody final VnfLcmOperationOccurrenceNotification notification) { logger.info("Notification received {}", notification); - dmaapService.send(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); + } + 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 dc0c5502dd..8ef3f24d2f 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 @@ -24,7 +24,7 @@ import static java.time.temporal.ChronoField.INSTANT_SECONDS; import com.fasterxml.jackson.annotation.JsonProperty; import java.time.Instant; import java.util.UUID; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification; +import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification; public class DmaapEvent { 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 c685ae815a..c13811d9d0 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,13 +20,13 @@ package org.onap.so.adapters.vevnfm.service; +import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; import org.onap.so.adapters.vevnfm.event.DmaapEvent; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification; +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; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -36,20 +36,20 @@ public class DmaapService { private static final Logger logger = LoggerFactory.getLogger(DmaapService.class); - @Value("${dmaap.endpoint}") - private String endpoint; - - @Value("${dmaap.topic}") - private String topic; - - @Value("${dmaap.closed-loop.control.name}") - private String closedLoopControlName; - - @Value("${dmaap.version}") - private String version; + private final String endpoint; + private final String topic; + private final String closedLoopControlName; + private final String version; + private final HttpRestServiceProvider restProvider; @Autowired - private HttpRestServiceProvider restProvider; + public DmaapService(final ConfigProperties configProperties, final HttpRestServiceProvider restProvider) { + this.endpoint = configProperties.getDmaapEndpoint(); + this.topic = configProperties.getDmaapTopic(); + this.closedLoopControlName = configProperties.getDmaapClosedLoopControlName(); + this.version = configProperties.getDmaapVersion(); + this.restProvider = restProvider; + } public void send(final VnfLcmOperationOccurrenceNotification notification) { try { diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/StartupService.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/StartupService.java index 92906ef35c..c128275e43 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/StartupService.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/StartupService.java @@ -24,11 +24,11 @@ import java.util.Collections; import java.util.List; import org.onap.aai.domain.yang.EsrSystemInfo; import org.onap.so.adapters.vevnfm.aai.AaiConnection; +import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; import org.onap.so.adapters.vevnfm.exception.VeVnfmException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.EnableRetry; import org.springframework.retry.annotation.Recover; @@ -41,11 +41,14 @@ public class StartupService { private static final Logger logger = LoggerFactory.getLogger(StartupService.class); - @Value("${vnfm.default-endpoint}") - private String vnfmDefaultEndpoint; + private final String vnfmDefaultEndpoint; + private final AaiConnection aaiConnection; @Autowired - private AaiConnection aaiConnection; + public StartupService(final ConfigProperties configProperties, final AaiConnection aaiConnection) { + this.vnfmDefaultEndpoint = configProperties.getVnfmDefaultEndpoint(); + this.aaiConnection = aaiConnection; + } @Retryable(value = {Exception.class}, maxAttempts = 5, backoff = @Backoff(delay = 5000, multiplier = 2)) public List<EsrSystemInfo> receiveVnfm() throws VeVnfmException { diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscribeSender.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscribeSender.java index d01c3c8f66..be71c04c89 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscribeSender.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscribeSender.java @@ -22,13 +22,13 @@ package org.onap.so.adapters.vevnfm.service; import com.fasterxml.jackson.annotation.JsonProperty; import org.onap.aai.domain.yang.EsrSystemInfo; +import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; import org.onap.so.adapters.vevnfm.exception.VeVnfmException; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest; +import org.onap.so.adapters.etsi.sol003.adapter.lcm.extclients.vnfm.model.LccnSubscriptionRequest; import org.onap.so.rest.service.HttpRestServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -41,11 +41,14 @@ public class SubscribeSender { private static final Logger logger = LoggerFactory.getLogger(SubscribeSender.class); - @Value("${vnfm.subscription}") - private String vnfmSubscription; + private final String vnfmSubscription; + private final HttpRestServiceProvider restProvider; @Autowired - private HttpRestServiceProvider restProvider; + public SubscribeSender(final ConfigProperties configProperties, final HttpRestServiceProvider restProvider) { + this.vnfmSubscription = configProperties.getVnfmSubscription(); + this.restProvider = restProvider; + } public String send(final EsrSystemInfo info, final LccnSubscriptionRequest request) throws VeVnfmException { final ResponseEntity<SubscribeToManoResponse> response = diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriberService.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriberService.java index 9760584d7a..32cd6ae22f 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriberService.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriberService.java @@ -20,39 +20,45 @@ package org.onap.so.adapters.vevnfm.service; +import com.google.gson.Gson; import com.squareup.okhttp.Credentials; import java.util.Collections; import org.apache.logging.log4j.util.Strings; import org.onap.aai.domain.yang.EsrSystemInfo; +import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; import org.onap.so.adapters.vevnfm.exception.VeVnfmException; import org.onap.so.adapters.vevnfm.provider.AuthorizationHeadersProvider; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsAuthentication; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsAuthenticationParamsBasic; +import org.onap.so.adapters.etsi.sol003.adapter.lcm.extclients.vnfm.model.LccnSubscriptionRequest; +import org.onap.so.adapters.etsi.sol003.adapter.lcm.extclients.vnfm.model.SubscriptionsAuthentication; +import org.onap.so.adapters.etsi.sol003.adapter.lcm.extclients.vnfm.model.SubscriptionsAuthenticationParamsBasic; +import org.onap.so.adapters.etsi.sol003.adapter.lcm.extclients.vnfm.model.SubscriptionsFilter; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @Service public class SubscriberService { - @Value("${vevnfmadapter.endpoint}") - private String endpoint; + private static final Gson gson = new Gson(); - @Value("${vnfm.notification}") - private String notification; - - @Value("${spring.security.usercredentials[0].username}") - private String username; - - @Value("${spring.security.usercredentials[0].openpass}") - private String openpass; - - @Autowired - private AuthorizationHeadersProvider headersProvider; + private final String vnfFilter; + private final String endpoint; + private final String notification; + private final String username; + private final String openpass; + private final AuthorizationHeadersProvider headersProvider; + private final SubscribeSender sender; @Autowired - private SubscribeSender sender; + public SubscriberService(final ConfigProperties configProperties, + final AuthorizationHeadersProvider headersProvider, final SubscribeSender sender) { + this.vnfFilter = configProperties.getVevnfmadapterVnfFilterJson(); + this.endpoint = configProperties.getVevnfmadapterEndpoint(); + this.notification = configProperties.getVnfmNotification(); + this.username = configProperties.getSpringSecurityUsername(); + this.openpass = configProperties.getSpringSecurityOpenpass(); + this.headersProvider = headersProvider; + this.sender = sender; + } private static String getAuthorization(final EsrSystemInfo info) { if (info == null) { @@ -91,6 +97,7 @@ public class SubscriberService { private LccnSubscriptionRequest createRequest() { final LccnSubscriptionRequest request = new LccnSubscriptionRequest(); + request.filter(getFilter()); request.callbackUri(getCallbackUri()); final SubscriptionsAuthenticationParamsBasic paramsBasic = new SubscriptionsAuthenticationParamsBasic(); final SubscriptionsAuthentication authentication = new SubscriptionsAuthentication(); @@ -103,6 +110,10 @@ public class SubscriberService { return request; } + private SubscriptionsFilter getFilter() { + return gson.fromJson(vnfFilter, SubscriptionsFilter.class); + } + private String getCallbackUri() { return endpoint + notification; } diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriptionScheduler.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriptionScheduler.java index d9f3acc3df..a696336011 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriptionScheduler.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriptionScheduler.java @@ -38,11 +38,14 @@ public class SubscriptionScheduler { private static final Logger logger = LoggerFactory.getLogger(SubscriptionScheduler.class); - @Autowired - private SubscriberService subscriberService; - + private final SubscriberService subscriberService; private List<EsrId> esrIds; + @Autowired + public SubscriptionScheduler(final SubscriberService subscriberService) { + this.subscriberService = subscriberService; + } + public void setInfos(final List<EsrSystemInfo> infos) { esrIds = new LinkedList<>(); 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 new file mode 100644 index 0000000000..1442fa2862 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/VnfAaiChecker.java @@ -0,0 +1,51 @@ +/*- + * ============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); + } + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml b/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml index a2a33bfb5c..c69c95187a 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml +++ b/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml @@ -18,6 +18,7 @@ server: port: 9098 vevnfmadapter: + vnf-filter-json: '{notificationTypes:[VnfLcmOperationOccurrenceNotification],operationStates:[COMPLETED]}' endpoint: http://so-ve-vnfm-adapter.onap:9098 mso: @@ -32,6 +33,9 @@ vnfm: subscription: /vnflcm/v1/subscriptions notification: /lcm/v1/vnf/instances/notifications +notification: + vnf-filter-type: NONE + dmaap: endpoint: http://message-router.onap:30227 topic: /events/unauthenticated.DCAE_CL_OUTPUT diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java index 974e6ec544..27def126ef 100644 --- a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java @@ -21,15 +21,14 @@ package org.onap.so.adapters.vevnfm.controller; import static org.junit.Assert.assertEquals; -import static org.springframework.test.web.client.ExpectedCount.once; import static org.springframework.test.web.client.match.MockRestRequestMatchers.anything; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -53,8 +52,8 @@ public class NotificationControllerTest { private static final String MINIMAL_JSON_CONTENT = "{}"; private static final int ZERO = 0; - @Value("${vnfm.notification}") - private String notification; + @Autowired + private ConfigProperties configProperties; @Autowired private WebApplicationContext webApplicationContext; @@ -62,11 +61,13 @@ public class NotificationControllerTest { @Autowired private RestTemplate restTemplate; + private String notification; private MockMvc mvc; private MockRestServiceServer mockRestServer; @Before public void init() { + notification = configProperties.getVnfmNotification(); mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); mockRestServer = MockRestServiceServer.bindTo(restTemplate).build(); } @@ -77,7 +78,7 @@ public class NotificationControllerTest { final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(notification) .contentType(MediaType.APPLICATION_JSON).content(MINIMAL_JSON_CONTENT); - mockRestServer.expect(once(), anything()).andRespond(withSuccess()); + mockRestServer.expect(anything()).andRespond(withSuccess()); // when final MvcResult mvcResult = mvc.perform(request).andReturn(); diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java index 9b18cf96dc..5d5ffa6555 100644 --- a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java @@ -34,16 +34,21 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.EsrSystemInfo; import org.onap.so.adapters.vevnfm.aai.AaiConnection; +import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; @RunWith(MockitoJUnitRunner.class) public class StartupServiceTest { private static final String URL = "rt"; + private static final String ENDPOINT = "localhost"; @Rule public ExpectedException thrown = ExpectedException.none(); @Mock + private ConfigProperties configProperties; + + @Mock private AaiConnection aaiConnection; @InjectMocks diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscribeSenderTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscribeSenderTest.java index b7f1f982a2..e67e19fd8d 100644 --- a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscribeSenderTest.java +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/SubscribeSenderTest.java @@ -33,11 +33,11 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.aai.domain.yang.EsrSystemInfo; +import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration; import org.onap.so.adapters.vevnfm.exception.VeVnfmException; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest; +import org.onap.so.adapters.etsi.sol003.adapter.lcm.extclients.vnfm.model.LccnSubscriptionRequest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; @@ -64,8 +64,8 @@ public class SubscribeSenderTest { GSON = builder.create(); } - @Value("${vnfm.subscription}") - private String vnfmSubscription; + @Autowired + private ConfigProperties configProperties; @Autowired private SubscribeSender sender; @@ -73,10 +73,12 @@ public class SubscribeSenderTest { @Autowired private RestTemplate restTemplate; + private String vnfmSubscription; private MockRestServiceServer mockRestServer; @Before public void init() { + vnfmSubscription = configProperties.getVnfmSubscription(); mockRestServer = MockRestServiceServer.bindTo(restTemplate).build(); } diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/VnfAaiCheckerTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/VnfAaiCheckerTest.java new file mode 100644 index 0000000000..da5992ee42 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/VnfAaiCheckerTest.java @@ -0,0 +1,87 @@ +/*- + * ============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 static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.adapters.vevnfm.aai.AaiConnection; +import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType; + +@RunWith(MockitoJUnitRunner.class) +public class VnfAaiCheckerTest { + + private static final String VNF_ID = "t5h78w"; + + @Mock + private AaiConnection aaiConnection; + + @InjectMocks + private VnfAaiChecker checker; + + @Test + public void testAll() { + // when + final boolean response = checker.vnfCheck(NotificationVnfFilterType.ALL, VNF_ID); + + // then + assertTrue(response); + } + + @Test + public void testAaiCheckedPresent() { + // given + when(aaiConnection.checkGenericVnfId(eq(VNF_ID))).thenReturn(true); + + // when + final boolean response = checker.vnfCheck(NotificationVnfFilterType.AAI_CHECKED, VNF_ID); + + // then + assertTrue(response); + } + + @Test + public void testAaiCheckedAbsent() { + // given + when(aaiConnection.checkGenericVnfId(eq(VNF_ID))).thenReturn(false); + + // when + final boolean response = checker.vnfCheck(NotificationVnfFilterType.AAI_CHECKED, VNF_ID); + + // then + assertFalse(response); + } + + @Test + public void testNone() { + // when + final boolean response = checker.vnfCheck(NotificationVnfFilterType.NONE, VNF_ID); + + // then + assertFalse(response); + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/test/resources/application.yaml b/adapters/mso-ve-vnfm-adapter/src/test/resources/application.yaml new file mode 100644 index 0000000000..2c7f67e459 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/test/resources/application.yaml @@ -0,0 +1,56 @@ +# +# Copyright © 2019, 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. + +server: + port: 9098 + +vevnfmadapter: + vnf-filter-json: '{notificationTypes:[VnfLcmOperationOccurrenceNotification],operationStates:[COMPLETED]}' + endpoint: http://so-ve-vnfm-adapter.onap:9098 + +mso: + key: 07a7159d3bf51a0e53be7a8f89699be7 + +aai: + endpoint: https://aai.onap:30233 + auth: 75C4483F9C05E2C33A8602635FA532397EC44AB667A2B64DED4FEE08DD932F2E3C1FEE + +vnfm: + default-endpoint: https://so-vnfm-simulator.onap:9093 + subscription: /vnflcm/v1/subscriptions + notification: /lcm/v1/vnf/instances/notifications + +notification: + vnf-filter-type: ALL + +dmaap: + endpoint: http://message-router.onap:30227 + topic: /events/unauthenticated.DCAE_CL_OUTPUT + closed-loop: + control: + name: ClosedLoopControlName + version: 1.0.2 + +spring: + security: + usercredentials: + - username: admin + openpass: a4b3c2d1 + password: '$2a$10$vU.mWyNTsikAxXIA5c269ewCpAbYTiyMS0m1N.kn4F2CSGEnrKN7K' + role: USER + http: + converters: + preferred-json-mapper: gson |