diff options
33 files changed, 1329 insertions, 401 deletions
diff --git a/adapters/mso-ve-vnfm-adapter/pom.xml b/adapters/mso-ve-vnfm-adapter/pom.xml index 02abd600f8..3518445b45 100644 --- a/adapters/mso-ve-vnfm-adapter/pom.xml +++ b/adapters/mso-ve-vnfm-adapter/pom.xml @@ -30,15 +30,27 @@ <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> - <dependency> <groupId>org.onap.so.adapters</groupId> <artifactId>mso-vnfm-adapter-ext-clients</artifactId> <version>${project.version}</version> </dependency> - + <dependency> + <groupId>org.onap.so</groupId> + <artifactId>common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.glassfish.jersey.core</groupId> + <artifactId>jersey-common</artifactId> + </dependency> + <dependency> + <groupId>org.glassfish.jersey.core</groupId> + <artifactId>jersey-client</artifactId> + </dependency> + <dependency> + <groupId>org.glassfish.jersey.inject</groupId> + <artifactId>jersey-hk2</artifactId> + </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/Application.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/Application.java index c4ca5f1fe1..e4a6bed300 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/Application.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/Application.java @@ -23,10 +23,10 @@ package org.onap.so.adapters.vevnfm; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication +@SpringBootApplication(scanBasePackages = {"org.onap.so"}) public class Application { - public static void main(String... args) { + public static void main(final String... args) { SpringApplication.run(Application.class, args); } } 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 new file mode 100644 index 0000000000..91a79b29bf --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java @@ -0,0 +1,82 @@ +/*- + * ============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.aai; + +import java.util.List; +import java.util.Optional; +import org.onap.aai.domain.yang.EsrSystemInfo; +import org.onap.aai.domain.yang.EsrVnfm; +import org.onap.aai.domain.yang.EsrVnfmList; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.graphinventory.entities.uri.Depth; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +@Service +public class AaiConnection { + + private static final Logger logger = LoggerFactory.getLogger(AaiConnection.class); + + private static final int FIRST_INDEX = 0; + + public String receiveVnfm() { + final AAIResourcesClient resourcesClient = new AAIResourcesClient(); + final Optional<EsrVnfmList> response = + resourcesClient.get(EsrVnfmList.class, AAIUriFactory.createResourceUri(AAIObjectType.VNFM_LIST)); + + if (response.isPresent()) { + final EsrVnfmList esrVnfmList = response.get(); + logger.info("The VNFM replied with: {}", esrVnfmList); + final List<EsrVnfm> esrVnfm = esrVnfmList.getEsrVnfm(); + + if (esrVnfm.isEmpty()) { + return null; + } + + final String vnfmId = esrVnfm.get(FIRST_INDEX).getVnfmId(); + return receiveVnfmServiceUrl(resourcesClient, vnfmId); + } + + return null; + } + + private String receiveVnfmServiceUrl(final AAIResourcesClient resourcesClient, final String vnfmId) { + final Optional<EsrVnfm> response = resourcesClient.get(EsrVnfm.class, + AAIUriFactory.createResourceUri(AAIObjectType.VNFM, vnfmId).depth(Depth.ONE)); + + if (response.isPresent()) { + final EsrVnfm esrVnfm = response.get(); + logger.info("The VNFM replied with: {}", esrVnfm); + final List<EsrSystemInfo> esrSystemInfo = esrVnfm.getEsrSystemInfoList().getEsrSystemInfo(); + + if (esrSystemInfo.isEmpty()) { + return null; + } + + return esrSystemInfo.get(FIRST_INDEX).getServiceUrl(); + } + + return null; + } +} 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 new file mode 100644 index 0000000000..aa8c7f68c9 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiPropertiesExt.java @@ -0,0 +1,67 @@ +/*- + * ============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.aai; + +import java.net.MalformedURLException; +import java.net.URL; +import org.onap.so.client.aai.AAIProperties; +import org.onap.so.client.aai.AAIVersion; +import org.onap.so.spring.SpringContextHelper; +import org.springframework.context.ApplicationContext; + +public class AaiPropertiesExt implements AAIProperties { + + 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"); + } + + @Override + public URL getEndpoint() throws MalformedURLException { + return new URL(endpoint); + } + + @Override + public String getSystemName() { + return "MSO"; + } + + @Override + public AAIVersion getDefaultVersion() { + return AAIVersion.V15; + } + + @Override + public String getAuth() { + return encryptedBasicAuth; + } + + @Override + public String getKey() { + return encryptionKey; + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/ApplicationConfiguration.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/ApplicationConfiguration.java new file mode 100644 index 0000000000..108b2ee896 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/ApplicationConfiguration.java @@ -0,0 +1,36 @@ +/*- + * ============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.rest.service.HttpRestServiceProvider; +import org.onap.so.rest.service.HttpRestServiceProviderImpl; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class ApplicationConfiguration { + + @Bean + public HttpRestServiceProvider restProvider(final RestTemplate restTemplate) { + return new HttpRestServiceProviderImpl(restTemplate); + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/SecurityConfiguration.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/SecurityConfiguration.java new file mode 100644 index 0000000000..32c2559d7b --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/SecurityConfiguration.java @@ -0,0 +1,35 @@ +/*- + * ============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.security.SoBasicWebSecurityConfigurerAdapter; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; + +@Configuration +public class SecurityConfiguration extends SoBasicWebSecurityConfigurerAdapter { + + @Override + protected void configure(final HttpSecurity http) throws Exception { + http.authorizeRequests().antMatchers().permitAll().and().requestMatchers().antMatchers("/").and() + .authorizeRequests().anyRequest().authenticated(); + } +} 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 new file mode 100644 index 0000000000..f7b7283c59 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/StartupConfiguration.java @@ -0,0 +1,48 @@ +/*- + * ============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.service.StartupService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.event.EventListener; +import org.springframework.core.env.Environment; +import org.springframework.core.env.Profiles; + +@Configuration +public class StartupConfiguration { + + public static final String TEST_PROFILE = "test"; + + @Autowired + private Environment environment; + + @Autowired + private StartupService startupService; + + @EventListener(ApplicationReadyEvent.class) + public void onApplicationReadyEvent() throws Exception { + if (!environment.acceptsProfiles(Profiles.of(TEST_PROFILE))) { + startupService.run(); + } + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/exception/VeVnfmException.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/exception/VeVnfmException.java new file mode 100644 index 0000000000..abd9ff9d33 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/exception/VeVnfmException.java @@ -0,0 +1,28 @@ +/*- + * ============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.exception; + +public class VeVnfmException extends Exception { + + public VeVnfmException(final String message) { + super(message); + } +} 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 new file mode 100644 index 0000000000..7a9ec9659e --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/StartupService.java @@ -0,0 +1,53 @@ +/*- + * ============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.vevnfm.aai.AaiConnection; +import org.onap.so.adapters.vevnfm.exception.VeVnfmException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class StartupService { + + @Autowired + private AaiConnection aaiConnection; + + @Autowired + private SubscriberService subscriberService; + + private static void isValid(final String endpoint) throws VeVnfmException { + if (Strings.isBlank(endpoint)) { + throw new VeVnfmException("No 'url' field in VNFM info"); + } + } + + public void run() throws Exception { + final String endpoint = aaiConnection.receiveVnfm(); + isValid(endpoint); + final boolean done = subscriberService.subscribe(endpoint); + + if (!done) { + throw new VeVnfmException("Could not subscribe to VNFM"); + } + } +} 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 new file mode 100644 index 0000000000..e413124b4b --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriberService.java @@ -0,0 +1,67 @@ +/*- + * ============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.subscription.SubscribeSender; +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +public class SubscriberService { + + private static final char COLON = ':'; + + @Value("${notification.url}") + private String notificationUrl; + + @Value("${server.port}") + private String serverPort; + + @Value("${system.url}") + private String systemUrl; + + @Autowired + private SubscribeSender sender; + + public boolean subscribe(final String endpoint) { + final LccnSubscriptionRequest request = createRequest(); + return sender.send(endpoint, request); + } + + private LccnSubscriptionRequest createRequest() { + final LccnSubscriptionRequest request = new LccnSubscriptionRequest(); + request.callbackUri(getCallbackUri()); + final SubscriptionsAuthenticationParamsBasic paramsBasic = new SubscriptionsAuthenticationParamsBasic(); + final SubscriptionsAuthentication authentication = new SubscriptionsAuthentication(); + authentication.setParamsBasic(paramsBasic); + request.authentication(authentication); + + return request; + } + + private String getCallbackUri() { + return systemUrl + COLON + serverPort + notificationUrl; + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/subscription/SubscribeSender.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/subscription/SubscribeSender.java new file mode 100644 index 0000000000..1b3a049bcf --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/subscription/SubscribeSender.java @@ -0,0 +1,58 @@ +/*- + * ============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.subscription; + +import org.onap.so.adapters.vnfmadapter.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.Component; + +@Component +public class SubscribeSender { + + private static final Logger logger = LoggerFactory.getLogger(SubscribeSender.class); + + @Value("${vnfm.subscription}") + private String vnfmSubscription; + + @Autowired + private HttpRestServiceProvider restProvider; + + public boolean send(final String endpoint, final LccnSubscriptionRequest request) { + final ResponseEntity<String> response = restProvider.postHttpRequest(request, getUrl(endpoint), String.class); + + final HttpStatus statusCode = response.getStatusCode(); + final String body = response.getBody(); + + logger.info("The VNFM replied with the code {} and the body {}", statusCode, body); + + return HttpStatus.CREATED == statusCode; + } + + private String getUrl(final String endpoint) { + return endpoint + vnfmSubscription; + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/main/resources/META-INF/services/org.onap.so.client.RestProperties b/adapters/mso-ve-vnfm-adapter/src/main/resources/META-INF/services/org.onap.so.client.RestProperties new file mode 100644 index 0000000000..9fc8e62cf5 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/resources/META-INF/services/org.onap.so.client.RestProperties @@ -0,0 +1 @@ +org.onap.so.adapters.vevnfm.aai.AaiPropertiesExt 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 30b3955821..12197d737d 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml +++ b/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml @@ -1,5 +1,5 @@ # -# Copyright © 2019 Samsung. +# Copyright © 2019, 2020 Samsung. # All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,8 +14,24 @@ # See the License for the specific language governing permissions and # limitations under the License. +server: + port: 8080 + +system: + url: http://localhost + notification: - url: /lcm/v1/vnf/instances/notifications + url: /lcm/v1/vnf/instances/notifications + +mso: + key: 07a7159d3bf51a0e53be7a8f89699be7 + +aai: + endpoint: https://aai.onap:30233 + auth: 75C4483F9C05E2C33A8602635FA532397EC44AB667A2B64DED4FEE08DD932F2E3C1FEE + +vnfm: + subscription: /vnflcm/v1/subscriptions spring: http: 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 c8d2a6bf90..418c2e2201 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 @@ -20,20 +20,59 @@ package org.onap.so.adapters.vevnfm.controller; +import static org.junit.Assert.assertEquals; +import org.junit.Before; import org.junit.Test; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification; +import org.junit.runner.RunWith; +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.ResponseEntity; -import static org.junit.Assert.assertEquals; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; +@SpringBootTest +@RunWith(SpringRunner.class) +@ActiveProfiles(StartupConfiguration.TEST_PROFILE) public class NotificationControllerTest { - private final NotificationController controller = new NotificationController(); + private static final String MINIMAL_JSON_CONTENT = "{}"; + private static final int ZERO = 0; + + @Value("${notification.url}") + private String notificationUrl; + + @Autowired + private WebApplicationContext webApplicationContext; + + private MockMvc mvc; + + @Before + public void init() { + mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); + } @Test - public void testReceiveNotification() { - final VnfLcmOperationOccurrenceNotification notification = new VnfLcmOperationOccurrenceNotification(); - final ResponseEntity response = controller.receiveNotification(notification); - assertEquals(HttpStatus.OK, response.getStatusCode()); + public void testReceiveNotification() throws Exception { + // given + final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(notificationUrl) + .contentType(MediaType.APPLICATION_JSON).content(MINIMAL_JSON_CONTENT); + + // when + final MvcResult mvcResult = mvc.perform(request).andReturn(); + + // then + final MockHttpServletResponse response = mvcResult.getResponse(); + assertEquals(HttpStatus.OK.value(), response.getStatus()); + assertEquals(ZERO, response.getContentLength()); } } 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 new file mode 100644 index 0000000000..8c480d0415 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/StartupServiceTest.java @@ -0,0 +1,80 @@ +/*- + * ============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.mockito.Mockito.*; +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.exception.VeVnfmException; + +@RunWith(MockitoJUnitRunner.class) +public class StartupServiceTest { + + @Mock + private AaiConnection aaiConnection; + + @Mock + private SubscriberService subscriberService; + + @InjectMocks + private StartupService startupService; + + @Test + public void testSuccess() throws Exception { + // given + final String endpoint = "lh"; + + when(aaiConnection.receiveVnfm()).thenReturn(endpoint); + when(subscriberService.subscribe(endpoint)).thenReturn(true); + + // when + startupService.run(); + + // then + verify(aaiConnection, times(1)).receiveVnfm(); + verify(subscriberService, times(1)).subscribe(endpoint); + } + + @Test(expected = VeVnfmException.class) + public void testFailureAai() throws Exception { + // given + when(aaiConnection.receiveVnfm()).thenReturn(null); + + // when + startupService.run(); + } + + @Test(expected = VeVnfmException.class) + public void testFailureSubscriber() throws Exception { + // given + final String endpoint = "lh"; + + when(aaiConnection.receiveVnfm()).thenReturn(endpoint); + when(subscriberService.subscribe(endpoint)).thenReturn(false); + + // when + startupService.run(); + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/subscription/SubscribeSenderTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/subscription/SubscribeSenderTest.java new file mode 100644 index 0000000000..62a624a983 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/subscription/SubscribeSenderTest.java @@ -0,0 +1,97 @@ +/*- + * ============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.subscription; + +import static org.junit.Assert.assertTrue; +import static org.springframework.http.HttpHeaders.CONTENT_TYPE; +import static org.springframework.test.web.client.ExpectedCount.once; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.*; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.hamcrest.CoreMatchers; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration; +import org.onap.so.adapters.vnfmadapter.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; +import org.springframework.http.MediaType; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.client.MockRestServiceServer; +import org.springframework.web.client.RestTemplate; + +@SpringBootTest +@RunWith(SpringRunner.class) +@ActiveProfiles(StartupConfiguration.TEST_PROFILE) +public class SubscribeSenderTest { + + private static final String SLASH = "/"; + private static final String MINIMAL_JSON_CONTENT = "{}"; + + private static final Gson GSON; + + static { + final GsonBuilder builder = new GsonBuilder(); + builder.serializeNulls(); + GSON = builder.create(); + } + + @Value("${vnfm.subscription}") + private String vnfmSubscription; + + @Autowired + private SubscribeSender sender; + + @Autowired + private RestTemplate restTemplate; + + private MockRestServiceServer mockRestServer; + + @Before + public void init() { + mockRestServer = MockRestServiceServer.bindTo(restTemplate).build(); + } + + @Test + public void testSuccess() { + // given + final String endpoint = "lh"; + final LccnSubscriptionRequest request = new LccnSubscriptionRequest(); + + mockRestServer.expect(once(), requestTo(SLASH + endpoint + vnfmSubscription)) + .andExpect(header(CONTENT_TYPE, CoreMatchers.containsString(MediaType.APPLICATION_JSON_VALUE))) + .andExpect(method(HttpMethod.POST)).andExpect(content().json(GSON.toJson(request))) + .andRespond(withStatus(HttpStatus.CREATED).body(MINIMAL_JSON_CONTENT)); + + // when + final boolean done = sender.send(endpoint, request); + + // then + assertTrue(done); + mockRestServer.verify(); + } +} diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn index 930f666bf0..c8600586ce 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn @@ -1,68 +1,40 @@ <?xml version="1.0" encoding="UTF-8"?> -<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1a52v2f" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0"> +<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1a52v2f" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="2.0.3"> <bpmn:collaboration id="Collaboration_0go8wi3"> <bpmn:participant id="Participant_1dwc5st" name="SO Assign PNF" processRef="AssignPnfBB" /> <bpmn:participant id="Participant_0gycee4" name="AAI" /> <bpmn:messageFlow id="MessageFlow_0xh6bkn" sourceRef="CreatePnfEntryInAai" targetRef="Participant_0gycee4" /> - <bpmn:messageFlow id="MessageFlow_0cnehf5" sourceRef="Participant_0gycee4" targetRef="CheckAaiForPnfCorrelationId" /> - <bpmn:messageFlow id="MessageFlow_1e1pjve" sourceRef="CheckAaiForPnfCorrelationId" targetRef="Participant_0gycee4" /> </bpmn:collaboration> <bpmn:process id="AssignPnfBB" name="AssignPnfBB" isExecutable="true"> - <bpmn:startEvent id="AssignPnf_StartEvent"> - <bpmn:outgoing>SequenceFlow_1fu9o4x</bpmn:outgoing> - </bpmn:startEvent> - <bpmn:serviceTask id="CheckAaiForPnfCorrelationId" name="Check AAI for pnf_correlation_id" camunda:expression="${CheckAaiForPnfCorrelationId.execute(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))}"> - <bpmn:incoming>SequenceFlow_1fu9o4x</bpmn:incoming> - <bpmn:outgoing>SequenceFlow_081rs5d</bpmn:outgoing> - </bpmn:serviceTask> - <bpmn:exclusiveGateway id="DoesAaiContainInfoAboutPnf" name="Does AAI contain info about pnf?"> - <bpmn:incoming>SequenceFlow_081rs5d</bpmn:incoming> - <bpmn:outgoing>SequenceFlow_0fn5kgz</bpmn:outgoing> - <bpmn:outgoing>SequenceFlow_1ewfz8r</bpmn:outgoing> - </bpmn:exclusiveGateway> - <bpmn:serviceTask id="CreatePnfEntryInAai" name="Create Pnf entry in AAI" camunda:expression="${CreatePnfEntryInAai.execute(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))}"> - <bpmn:incoming>SequenceFlow_0fn5kgz</bpmn:incoming> - <bpmn:outgoing>SequenceFlow_0l6rtzy</bpmn:outgoing> - </bpmn:serviceTask> + <bpmn:sequenceFlow id="SequenceFlow_0l6rtzy" sourceRef="CreatePnfEntryInAai" targetRef="AaiEntryExists" /> + <bpmn:sequenceFlow id="SequenceFlow_1fu9o4x" sourceRef="AssignPnf_StartEvent" targetRef="CreatePnfEntryInAai" /> <bpmn:endEvent id="AaiEntryExists" name="AAI entry exists"> - <bpmn:incoming>SequenceFlow_1ewfz8r</bpmn:incoming> <bpmn:incoming>SequenceFlow_0l6rtzy</bpmn:incoming> </bpmn:endEvent> - <bpmn:sequenceFlow id="SequenceFlow_081rs5d" sourceRef="CheckAaiForPnfCorrelationId" targetRef="DoesAaiContainInfoAboutPnf" /> - <bpmn:sequenceFlow id="SequenceFlow_0fn5kgz" name="No" sourceRef="DoesAaiContainInfoAboutPnf" targetRef="CreatePnfEntryInAai"> - <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{!aaiContainsInfoAboutPnf}</bpmn:conditionExpression> - </bpmn:sequenceFlow> - <bpmn:sequenceFlow id="SequenceFlow_1ewfz8r" name="Yes " sourceRef="DoesAaiContainInfoAboutPnf" targetRef="AaiEntryExists"> - <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{aaiContainsInfoAboutPnf}</bpmn:conditionExpression> - </bpmn:sequenceFlow> - <bpmn:sequenceFlow id="SequenceFlow_0l6rtzy" sourceRef="CreatePnfEntryInAai" targetRef="AaiEntryExists" /> - <bpmn:sequenceFlow id="SequenceFlow_1fu9o4x" sourceRef="AssignPnf_StartEvent" targetRef="CheckAaiForPnfCorrelationId" /> + <bpmn:serviceTask id="CreatePnfEntryInAai" name="Create Pnf entry in AAI" camunda:expression="${AAICreateTasks.createPnf(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))}"> + <bpmn:incoming>SequenceFlow_1fu9o4x</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0l6rtzy</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:startEvent id="AssignPnf_StartEvent"> + <bpmn:outgoing>SequenceFlow_1fu9o4x</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:association id="Association_1le3nwi" sourceRef="AssignPnf_StartEvent" targetRef="TextAnnotation_184cxp4" /> <bpmn:textAnnotation id="TextAnnotation_184cxp4"> <bpmn:text>Inputs: - - pnfCorrelationId - String - - uuid - String</bpmn:text> + - pnfName - String +</bpmn:text> </bpmn:textAnnotation> - <bpmn:association id="Association_1le3nwi" sourceRef="AssignPnf_StartEvent" targetRef="TextAnnotation_184cxp4" /> </bpmn:process> <bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_0go8wi3"> <bpmndi:BPMNShape id="Participant_1dwc5st_di" bpmnElement="Participant_1dwc5st" isHorizontal="true"> - <dc:Bounds x="160" y="80" width="1100" height="390" /> + <dc:Bounds x="160" y="80" width="646" height="391" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="Participant_0gycee4_di" bpmnElement="Participant_0gycee4" isHorizontal="true"> - <dc:Bounds x="590" y="570" width="502" height="60" /> + <dc:Bounds x="260" y="567" width="502" height="60" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="ServiceTask_1ix8822_di" bpmnElement="CreatePnfEntryInAai"> - <dc:Bounds x="920" y="247" width="100" height="80" /> - </bpmndi:BPMNShape> - <bpmndi:BPMNShape id="ExclusiveGateway_1l92fkt_di" bpmnElement="DoesAaiContainInfoAboutPnf" isMarkerVisible="true"> - <dc:Bounds x="795" y="262" width="50" height="50" /> - <bpmndi:BPMNLabel> - <dc:Bounds x="777" y="322" width="85" height="27" /> - </bpmndi:BPMNLabel> - </bpmndi:BPMNShape> - <bpmndi:BPMNShape id="ServiceTask_0ebur3y_di" bpmnElement="CheckAaiForPnfCorrelationId"> - <dc:Bounds x="640" y="247" width="100" height="80" /> + <dc:Bounds x="461" y="247" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="StartEvent_1g3euow_di" bpmnElement="AssignPnf_StartEvent"> <dc:Bounds x="219" y="269" width="36" height="36" /> @@ -70,55 +42,27 @@ <bpmndi:BPMNShape id="TextAnnotation_184cxp4_di" bpmnElement="TextAnnotation_184cxp4"> <dc:Bounds x="236" y="150" width="243" height="53" /> </bpmndi:BPMNShape> - <bpmndi:BPMNEdge id="SequenceFlow_081rs5d_di" bpmnElement="SequenceFlow_081rs5d"> - <di:waypoint x="740" y="287" /> - <di:waypoint x="795" y="287" /> - </bpmndi:BPMNEdge> - <bpmndi:BPMNEdge id="SequenceFlow_0fn5kgz_di" bpmnElement="SequenceFlow_0fn5kgz"> - <di:waypoint x="845" y="287" /> - <di:waypoint x="920" y="287" /> - <bpmndi:BPMNLabel> - <dc:Bounds x="854" y="290" width="15" height="14" /> - </bpmndi:BPMNLabel> - </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="MessageFlow_0xh6bkn_di" bpmnElement="MessageFlow_0xh6bkn"> - <di:waypoint x="970" y="327" /> - <di:waypoint x="970" y="570" /> - </bpmndi:BPMNEdge> - <bpmndi:BPMNEdge id="MessageFlow_0cnehf5_di" bpmnElement="MessageFlow_0cnehf5"> - <di:waypoint x="710" y="570" /> - <di:waypoint x="710" y="327" /> - </bpmndi:BPMNEdge> - <bpmndi:BPMNEdge id="MessageFlow_1e1pjve_di" bpmnElement="MessageFlow_1e1pjve"> - <di:waypoint x="671" y="327" /> - <di:waypoint x="671" y="570" /> + <di:waypoint x="511" y="327" /> + <di:waypoint x="511" y="567" /> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="Association_1le3nwi_di" bpmnElement="Association_1le3nwi"> <di:waypoint x="237" y="269" /> <di:waypoint x="237" y="203" /> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="EndEvent_1wfgsdz_di" bpmnElement="AaiEntryExists"> - <dc:Bounds x="1152" y="269" width="36" height="36" /> + <dc:Bounds x="722" y="269" width="36" height="36" /> <bpmndi:BPMNLabel> - <dc:Bounds x="1133" y="312" width="77" height="14" /> + <dc:Bounds x="703" y="312" width="77" height="14" /> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> - <bpmndi:BPMNEdge id="SequenceFlow_1ewfz8r_di" bpmnElement="SequenceFlow_1ewfz8r"> - <di:waypoint x="820" y="262" /> - <di:waypoint x="820" y="170" /> - <di:waypoint x="1170" y="170" /> - <di:waypoint x="1170" y="269" /> - <bpmndi:BPMNLabel> - <dc:Bounds x="822" y="240" width="19" height="40" /> - </bpmndi:BPMNLabel> - </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="SequenceFlow_0l6rtzy_di" bpmnElement="SequenceFlow_0l6rtzy"> - <di:waypoint x="1020" y="287" /> - <di:waypoint x="1152" y="287" /> + <di:waypoint x="561" y="287" /> + <di:waypoint x="722" y="287" /> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="SequenceFlow_1fu9o4x_di" bpmnElement="SequenceFlow_1fu9o4x"> <di:waypoint x="255" y="287" /> - <di:waypoint x="640" y="287" /> + <di:waypoint x="461" y="287" /> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WaitForPnfReadyBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WaitForPnfReadyBB.bpmn new file mode 100644 index 0000000000..b38ec69ba5 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WaitForPnfReadyBB.bpmn @@ -0,0 +1,156 @@ +<?xml version="1.0" encoding="UTF-8"?> +<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0"> + <bpmn:collaboration id="Collaboration_1d0w8lf"> + <bpmn:participant id="WaitForPnfReadyBB_ID" name="SO Wait For Pnf Ready" processRef="WaitForPnfReadyBB" /> + <bpmn:participant id="WorkflowMessageServiceForDmaap" name="Workflow Message Service (communication with DMAAP) " /> + <bpmn:messageFlow id="MessageFlow_1vrcp2d" sourceRef="WorkflowMessageServiceForDmaap" targetRef="WaitForDmaapPnfReadyNotification" /> + <bpmn:messageFlow id="MessageFlow_0tg4hw9" sourceRef="RegisterForPnfReadyEvent" targetRef="WorkflowMessageServiceForDmaap" /> + <bpmn:messageFlow id="MessageFlow_1py54jr" sourceRef="UnregisterfromPnfReadyEvent" targetRef="WorkflowMessageServiceForDmaap" /> + </bpmn:collaboration> + <bpmn:process id="WaitForPnfReadyBB" name="WaitForPnfReadyBB" isExecutable="true"> + <bpmn:startEvent id="WaitForPnfReady_StartEvent"> + <bpmn:outgoing>SequenceFlow_1jzs6dp</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:serviceTask id="RegisterForPnfReadyEvent" name="Register for Pnf Ready Event" camunda:delegateExpression="${RegisterForPnfReadyEvent}"> + <bpmn:incoming>SequenceFlow_1jzs6dp</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_1o8od8e</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="SequenceFlow_1miyzfe" sourceRef="UnregisterfromPnfReadyEvent" targetRef="ThrowTimeoutException" /> + <bpmn:sequenceFlow id="SequenceFlow_0p09qgm" sourceRef="WaitForDmaapPnfReadyNotification" targetRef="AaiEntryUpdated" /> + <bpmn:sequenceFlow id="SequenceFlow_1o8od8e" sourceRef="RegisterForPnfReadyEvent" targetRef="WaitForDmaapPnfReadyNotification" /> + <bpmn:sequenceFlow id="SequenceFlow_1kc34bc" sourceRef="WaitForDmaapTimeout" targetRef="UnregisterfromPnfReadyEvent" /> + <bpmn:sequenceFlow id="SequenceFlow_1jzs6dp" sourceRef="WaitForPnfReady_StartEvent" targetRef="RegisterForPnfReadyEvent" /> + <bpmn:receiveTask id="WaitForDmaapPnfReadyNotification" name="Wait for DMAAP pnf-ready notification" messageRef="Message_13h1tlo"> + <bpmn:incoming>SequenceFlow_1o8od8e</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0p09qgm</bpmn:outgoing> + </bpmn:receiveTask> + <bpmn:boundaryEvent id="WaitForDmaapTimeout" name="Timeout" attachedToRef="WaitForDmaapPnfReadyNotification"> + <bpmn:outgoing>SequenceFlow_1kc34bc</bpmn:outgoing> + <bpmn:timerEventDefinition> + <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">#{timeoutForPnfEntryNotification}</bpmn:timeDuration> + </bpmn:timerEventDefinition> + </bpmn:boundaryEvent> + <bpmn:serviceTask id="UnregisterfromPnfReadyEvent" name="Unregister from Pnf Ready Event" camunda:delegateExpression="${CancelDmaapSubscription}"> + <bpmn:incoming>SequenceFlow_1kc34bc</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_1miyzfe</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:endEvent id="ThrowTimeoutException" name="Throw timeout exception"> + <bpmn:incoming>SequenceFlow_1miyzfe</bpmn:incoming> + <bpmn:errorEventDefinition errorRef="Error_1" /> + </bpmn:endEvent> + <bpmn:endEvent id="AaiEntryUpdated" name="AAI entry updated"> + <bpmn:incoming>SequenceFlow_0p09qgm</bpmn:incoming> + </bpmn:endEvent> + <bpmn:textAnnotation id="TextAnnotation_1eyzes8"> + <bpmn:text>Inputs: + - pnf name - String</bpmn:text> + </bpmn:textAnnotation> + <bpmn:association id="Association_0d7oxnz" sourceRef="WaitForPnfReady_StartEvent" targetRef="TextAnnotation_1eyzes8" /> + </bpmn:process> + <bpmn:error id="Error_1" name="MSO Workflow Exception" errorCode="MSOWorkflowException" /> + <bpmn:message id="Message_13h1tlo" name="WorkflowMessage" /> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1d0w8lf"> + <bpmndi:BPMNShape id="Participant_1egg397_di" bpmnElement="WaitForPnfReadyBB_ID" isHorizontal="true"> + <dc:Bounds x="160" y="50" width="810" height="400" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="EndEvent_0k52gr7_di" bpmnElement="AaiEntryUpdated"> + <dc:Bounds x="882" y="189" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="858" y="230" width="88" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="StartEvent_0j5ok9h_di" bpmnElement="WaitForPnfReady_StartEvent"> + <dc:Bounds x="219" y="189" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="-80" y="228" width="90" height="20" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Participant_0vmrrhf_di" bpmnElement="WorkflowMessageServiceForDmaap" isHorizontal="true"> + <dc:Bounds x="340" y="490" width="463" height="60" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="EndEvent_0wbx6tt_di" bpmnElement="ThrowTimeoutException"> + <dc:Bounds x="882" y="322" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="875" y="359" width="70" height="27" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="TextAnnotation_1eyzes8_di" bpmnElement="TextAnnotation_1eyzes8"> + <dc:Bounds x="236" y="70" width="243" height="39" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="Association_0d7oxnz_di" bpmnElement="Association_0d7oxnz"> + <di:waypoint x="237" y="189" /> + <di:waypoint x="237" y="109" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="MessageFlow_1vrcp2d_di" bpmnElement="MessageFlow_1vrcp2d"> + <di:waypoint x="582" y="490" /> + <di:waypoint x="582" y="247" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="996" y="380" width="90" height="10" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="BoundaryEvent_15eo1k9_di" bpmnElement="WaitForDmaapTimeout"> + <dc:Bounds x="596" y="229" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="639" y="240" width="40" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1kc34bc_di" bpmnElement="SequenceFlow_1kc34bc"> + <di:waypoint x="614" y="265" /> + <di:waypoint x="614" y="340" /> + <di:waypoint x="710" y="340" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1028" y="309" width="90" height="10" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ReceiveTask_1sfysua_di" bpmnElement="WaitForDmaapPnfReadyNotification"> + <dc:Bounds x="530" y="167" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_0p09qgm_di" bpmnElement="SequenceFlow_0p09qgm"> + <di:waypoint x="630" y="207" /> + <di:waypoint x="882" y="207" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1106.5" y="187" width="90" height="10" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_1o8od8e_di" bpmnElement="SequenceFlow_1o8od8e"> + <di:waypoint x="440" y="207" /> + <di:waypoint x="530" y="207" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="893.5" y="187" width="90" height="10" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="MessageFlow_0tg4hw9_di" bpmnElement="MessageFlow_0tg4hw9"> + <di:waypoint x="390" y="247" /> + <di:waypoint x="390" y="490" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="823" y="380" width="90" height="10" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ServiceTask_1iax11n_di" bpmnElement="RegisterForPnfReadyEvent"> + <dc:Bounds x="340" y="167" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1miyzfe_di" bpmnElement="SequenceFlow_1miyzfe"> + <di:waypoint x="810" y="340" /> + <di:waypoint x="882" y="340" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1233.5" y="343" width="90" height="10" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="MessageFlow_1py54jr_di" bpmnElement="MessageFlow_1py54jr"> + <di:waypoint x="760" y="380" /> + <di:waypoint x="760" y="490" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1165" y="458" width="90" height="10" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ServiceTask_12j7hox_di" bpmnElement="UnregisterfromPnfReadyEvent"> + <dc:Bounds x="710" y="300" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1jzs6dp_di" bpmnElement="SequenceFlow_1jzs6dp"> + <di:waypoint x="255" y="207" /> + <di:waypoint x="340" y="207" /> + </bpmndi:BPMNEdge> + </bpmndi:BPMNPlane> + </bpmndi:BPMNDiagram> +</bpmn:definitions> diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/RegisterForPnfReadyEvent.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/RegisterForPnfReadyEvent.java new file mode 100644 index 0000000000..f0eadbbf78 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/RegisterForPnfReadyEvent.java @@ -0,0 +1,99 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Nokia. + * ================================================================================ + * 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.bpmn.infrastructure.pnf.delegate; + +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION; +import com.google.common.base.Strings; +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.infrastructure.pnf.dmaap.DmaapClient; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.ExceptionBuilder; +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.stereotype.Component; + +/** + * This class is designed to be used within WaitForPnfReadyBB + */ +@Component +public class RegisterForPnfReadyEvent implements JavaDelegate { + + private static final String ERROR_MESSAGE_PNF_NOT_FOUND = + "pnf resource not found in buildingBlockExecution while registering to dmaap listener"; + private static final Logger LOGGER = LoggerFactory.getLogger(RegisterForPnfReadyEvent.class); + + private DmaapClient dmaapClient; + private ExtractPojosForBB extractPojosForBB; + private ExceptionBuilder exceptionBuilder; + private String pnfEntryNotificationTimeout; + + @Autowired + public RegisterForPnfReadyEvent(DmaapClient dmaapClient, ExtractPojosForBB extractPojosForBB, + ExceptionBuilder exceptionBuilder, + @Value("${aai.pnfEntryNotificationTimeout}") String pnfEntryNotificationTimeout) { + this.dmaapClient = dmaapClient; + this.extractPojosForBB = extractPojosForBB; + this.exceptionBuilder = exceptionBuilder; + this.pnfEntryNotificationTimeout = pnfEntryNotificationTimeout; + } + + @Override + public void execute(DelegateExecution execution) { + try { + String pnfName = getPnfName(execution); + fillExecution(execution, pnfName); + RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService(); + dmaapClient.registerForUpdate(pnfName, () -> runtimeService.createMessageCorrelation("WorkflowMessage") + .processInstanceBusinessKey(execution.getProcessBusinessKey()).correlateWithResult()); + } catch (BBObjectNotFoundException e) { + LOGGER.error(ERROR_MESSAGE_PNF_NOT_FOUND); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ERROR_MESSAGE_PNF_NOT_FOUND); + } + } + + private void fillExecution(DelegateExecution execution, String pnfName) { + execution.setVariable(ExecutionVariableNames.PNF_CORRELATION_ID, pnfName); + if (Strings.isNullOrEmpty(pnfEntryNotificationTimeout)) { + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, + "pnfEntryNotificationTimeout value not defined"); + } + execution.setVariable(TIMEOUT_FOR_NOTIFICATION, pnfEntryNotificationTimeout); + } + + private String getPnfName(DelegateExecution execution) throws BBObjectNotFoundException { + BuildingBlockExecution buildingBlockExecution = + (BuildingBlockExecution) execution.getVariable("gBuildingBlockExecution"); + Pnf pnf = extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.PNF); + String pnfName = pnf.getPnfName(); + if (Strings.isNullOrEmpty(pnfName)) { + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "pnf name is not set"); + } + return pnfName; + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java deleted file mode 100644 index 29914252d8..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.tasks; - -import joptsimple.internal.Strings; -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.client.exception.BBObjectNotFoundException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; -import java.io.IOException; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID; - -@Component -public class CheckAaiForPnfCorrelationId extends PnfBaseTasks { - private static final Logger logger = LoggerFactory.getLogger(CheckAaiForPnfCorrelationId.class); - - @Override - public void execute(BuildingBlockExecution execution) { - try { - String pnfCorrelationId = extractPnf(execution).getPnfName(); - checkIfPnfCorrelationIdPresent(execution, pnfCorrelationId); - checkIfPnfExistsInAai(execution, pnfCorrelationId); - } catch (BBObjectNotFoundException e) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); - } - - } - - private void checkIfPnfCorrelationIdPresent(BuildingBlockExecution execution, String pnfCorrelationId) { - if (Strings.isNullOrEmpty(pnfCorrelationId)) { - exceptionUtil.buildAndThrowWorkflowException(execution, 500, PNF_CORRELATION_ID + " is not set"); - } - } - - private void checkIfPnfExistsInAai(BuildingBlockExecution execution, String pnfCorrelationId) { - try { - boolean isEntry = pnfManagement.getEntryFor(pnfCorrelationId).isPresent(); - logger.debug("AAI entry is found for pnf correlation id {}: {}", PNF_CORRELATION_ID, isEntry); - execution.setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, isEntry); - } catch (IOException e) { - logger.error("Exception in check AAI for pnf_correlation_id execution", e); - exceptionUtil.buildAndThrowWorkflowException(execution, 9999, e); - } - } -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java deleted file mode 100644 index 6e86ad619e..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.tasks; - -import org.onap.aai.domain.yang.Pnf; -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.client.exception.BBObjectNotFoundException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -@Component -public class CreatePnfEntryInAai extends PnfBaseTasks { - private static final Logger logger = LoggerFactory.getLogger(CreatePnfEntryInAai.class); - - @Override - public void execute(BuildingBlockExecution execution) throws Exception { - try { - org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf = extractPnf(execution); - String pnfCorrelationId = pnf.getPnfName(); - pnfManagement.createEntry(pnfCorrelationId, preparePnfForAai(pnf)); - logger.debug("AAI entry is created for pnf correlation id: {}, pnf uuid: {}", pnfCorrelationId, - pnf.getPnfId()); - } catch (BBObjectNotFoundException e) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); - } - } - - private Pnf preparePnfForAai(org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf) { - Pnf pnfAai = new Pnf(); - pnfAai.setPnfId(pnf.getPnfId()); - pnfAai.setPnfName(pnf.getPnfName()); - return pnfAai; - } - -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java deleted file mode 100644 index d8e3379afb..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.tasks; - -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; -import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; -import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; -import org.onap.so.client.exception.BBObjectNotFoundException; -import org.onap.so.client.exception.ExceptionBuilder; -import org.springframework.beans.factory.annotation.Autowired; - -public abstract class PnfBaseTasks { - protected PnfManagement pnfManagement; - @Autowired - protected ExceptionBuilder exceptionUtil; - @Autowired - protected ExtractPojosForBB extractPojosForBB; - - @Autowired - public void setPnfManagement(PnfManagement pnfManagement) { - this.pnfManagement = pnfManagement; - } - - public abstract void execute(BuildingBlockExecution execution) throws Exception; - - protected Pnf extractPnf(BuildingBlockExecution execution) throws BBObjectNotFoundException { - return extractPojosForBB.extractByKey(execution, ResourceKey.PNF); - } -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/RegisterForPnfReadyEventTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/RegisterForPnfReadyEventTest.java new file mode 100644 index 0000000000..a82fb5d823 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/RegisterForPnfReadyEventTest.java @@ -0,0 +1,125 @@ +package org.onap.so.bpmn.infrastructure.pnf.delegate; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import java.util.HashMap; +import org.camunda.bpm.engine.ProcessEngineServices; +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.runtime.MessageCorrelationBuilder; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InOrder; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.ExceptionBuilder; + +public class RegisterForPnfReadyEventTest { + + private static final String PNF_NAME = "pnfNameTest"; + + private DelegateExecution delegateExecution; + private ExtractPojosForBB extractPojosForBBMock; + private DmaapClientTestImpl dmaapClientTest; + private MessageCorrelationBuilder messageCorrelationBuilder; + private ExceptionBuilder exceptionBuilderMock; + private BuildingBlockExecution buildingBlockExecution; + private static final String PNF_ENTRY_NOTIFICATION_TIMEOUT = "P14D"; + + private RegisterForPnfReadyEvent testedObject; + + @Before + public void init() { + delegateExecution = prepareExecution(); + dmaapClientTest = new DmaapClientTestImpl(); + exceptionBuilderMock = mock(ExceptionBuilder.class); + extractPojosForBBMock = mock(ExtractPojosForBB.class); + buildingBlockExecution = new DelegateExecutionImpl(new HashMap<>()); + when(delegateExecution.getVariable("gBuildingBlockExecution")).thenReturn(buildingBlockExecution); + } + + @Test + public void shouldRegisterForDmaapClient() throws BBObjectNotFoundException { + // given + testedObject = new RegisterForPnfReadyEvent(dmaapClientTest, extractPojosForBBMock, exceptionBuilderMock, + PNF_ENTRY_NOTIFICATION_TIMEOUT); + Pnf pnf = new Pnf(); + pnf.setPnfName(PNF_NAME); + when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.PNF)).thenReturn(pnf); + // when + testedObject.execute(delegateExecution); + // then + verify(delegateExecution).setVariable(ExecutionVariableNames.PNF_CORRELATION_ID, PNF_NAME); + verify(delegateExecution).setVariable(ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION, + PNF_ENTRY_NOTIFICATION_TIMEOUT); + checkIfInformConsumerThreadIsRunProperly(dmaapClientTest); + } + + @Test + public void pnfNotFoundInBBexecution_WorkflowExIsThrown() throws BBObjectNotFoundException { + // given + testedObject = new RegisterForPnfReadyEvent(dmaapClientTest, extractPojosForBBMock, exceptionBuilderMock, + PNF_ENTRY_NOTIFICATION_TIMEOUT); + when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.PNF)) + .thenThrow(BBObjectNotFoundException.class); + // when + testedObject.execute(delegateExecution); + // then + verify(exceptionBuilderMock).buildAndThrowWorkflowException(delegateExecution, 7000, + "pnf resource not found in buildingBlockExecution while registering to dmaap listener"); + } + + @Test + public void pnfNameIsNull_WorkflowExIsThrown() throws BBObjectNotFoundException { + // given + testedObject = new RegisterForPnfReadyEvent(dmaapClientTest, extractPojosForBBMock, exceptionBuilderMock, + PNF_ENTRY_NOTIFICATION_TIMEOUT); + when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.PNF)).thenReturn(new Pnf()); + // when + testedObject.execute(delegateExecution); + // then + verify(exceptionBuilderMock).buildAndThrowWorkflowException(delegateExecution, 7000, "pnf name is not set"); + } + + @Test + public void pnfEventNotificationTimeoutNotSet_WorkflowExIsThrown() throws BBObjectNotFoundException { + // given + testedObject = new RegisterForPnfReadyEvent(dmaapClientTest, extractPojosForBBMock, exceptionBuilderMock, null); + when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.PNF)).thenReturn(new Pnf()); + // when + testedObject.execute(delegateExecution); + // then + verify(exceptionBuilderMock).buildAndThrowWorkflowException(delegateExecution, 7000, + "pnfEntryNotificationTimeout value not defined"); + } + + private void checkIfInformConsumerThreadIsRunProperly(DmaapClientTestImpl dmaapClientTest) { + dmaapClientTest.getInformConsumer().run(); + InOrder inOrder = inOrder(messageCorrelationBuilder); + inOrder.verify(messageCorrelationBuilder).processInstanceBusinessKey("testBusinessKey"); + inOrder.verify(messageCorrelationBuilder).correlateWithResult(); + } + + private DelegateExecution prepareExecution() { + DelegateExecution delegateExecution = mock(DelegateExecution.class); + when(delegateExecution.getProcessBusinessKey()).thenReturn("testBusinessKey"); + ProcessEngineServices processEngineServices = mock(ProcessEngineServices.class); + when(delegateExecution.getProcessEngineServices()).thenReturn(processEngineServices); + RuntimeService runtimeService = mock(RuntimeService.class); + when(processEngineServices.getRuntimeService()).thenReturn(runtimeService); + + messageCorrelationBuilder = mock(MessageCorrelationBuilder.class); + when(runtimeService.createMessageCorrelation(any())).thenReturn(messageCorrelationBuilder); + when(messageCorrelationBuilder.processInstanceBusinessKey(any())).thenReturn(messageCorrelationBuilder); + + return delegateExecution; + } + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java deleted file mode 100644 index 3fa9fbf3b5..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.tasks; - -import org.camunda.bpm.engine.delegate.BpmnError; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.runners.Enclosed; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl; -import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementThrowingException; -import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement; -import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; -import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; -import org.onap.so.client.exception.ExceptionBuilder; -import java.io.IOException; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.anyInt; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITHOUT_ENTRY; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITH_ENTRY; -import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_UUID; -import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.preparePnf; - -@RunWith(Enclosed.class) -public class CheckAaiForPnfCorrelationIdTest { - - @RunWith(MockitoJUnitRunner.class) - public static class ConnectionOkTests { - - @Mock - private ExtractPojosForBB extractPojosForBB; - @Mock - private ExceptionBuilder exceptionUtil; - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @InjectMocks - private CheckAaiForPnfCorrelationId task = new CheckAaiForPnfCorrelationId(); - private PnfManagement pnfManagementTest = new PnfManagementTestImpl(); - - @Before - public void setUp() { - task.setPnfManagement(pnfManagementTest); - } - - @Test - public void shouldThrowExceptionWhenPnfCorrelationIdIsNotSet() throws Exception { - // given - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))).thenReturn(preparePnf(null, PNF_UUID)); - BuildingBlockExecution execution = mock(BuildingBlockExecution.class); - doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(eq(execution), - anyInt(), anyString()); - // when, then - expectedException.expect(BpmnError.class); - task.execute(execution); - verify(exceptionUtil).buildAndThrowWorkflowException(eq(execution), anyInt(), anyString()); - } - - @Test - public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception { - // given - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))) - .thenReturn(preparePnf(ID_WITHOUT_ENTRY, PNF_UUID)); - BuildingBlockExecution execution = mock(BuildingBlockExecution.class); - // when - task.execute(execution); - // then - verify(execution).setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, false); - } - - @Test - public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception { - // given - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))) - .thenReturn(preparePnf(ID_WITH_ENTRY, PNF_UUID)); - BuildingBlockExecution execution = mock(BuildingBlockExecution.class); - // when - task.execute(execution); - // then - verify(execution).setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, true); - } - } - - @RunWith(MockitoJUnitRunner.class) - public static class NoConnectionTests { - - @Mock - private ExtractPojosForBB extractPojosForBB; - @Mock - private ExceptionBuilder exceptionUtil; - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @InjectMocks - private CheckAaiForPnfCorrelationId task = new CheckAaiForPnfCorrelationId(); - private PnfManagement pnfManagementTest = new PnfManagementThrowingException(); - - @Before - public void setUp() throws Exception { - task.setPnfManagement(pnfManagementTest); - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))) - .thenReturn(preparePnf(PNF_CORRELATION_ID, PNF_UUID)); - } - - @Test - public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() { - // given - BuildingBlockExecution execution = mock(BuildingBlockExecution.class); - doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(eq(execution), - anyInt(), any(IOException.class)); - // when, then - expectedException.expect(BpmnError.class); - task.execute(execution); - verify(exceptionUtil).buildAndThrowWorkflowException(eq(execution), anyInt(), any(IOException.class)); - } - } -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java deleted file mode 100644 index ed8dd82efb..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.tasks; - -import org.junit.Before; -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.aai.domain.yang.Pnf; -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl; -import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; -import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_CORRELATION_ID; -import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_UUID; -import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.preparePnf; - -@RunWith(MockitoJUnitRunner.class) -public class CreatePnfEntryInAaiTest { - - @Mock - private ExtractPojosForBB extractPojosForBB; - @InjectMocks - private CreatePnfEntryInAai task = new CreatePnfEntryInAai(); - private PnfManagementTestImpl pnfManagementTest = new PnfManagementTestImpl(); - - @Before - public void setUp() throws Exception { - task.setPnfManagement(pnfManagementTest); - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))) - .thenReturn(preparePnf(PNF_CORRELATION_ID, PNF_UUID)); - } - - @Test - public void shouldSetPnfIdAndPnfName() throws Exception { - // when - task.execute(mock(BuildingBlockExecution.class)); - // then - Pnf createdEntry = pnfManagementTest.getCreated().get(PNF_CORRELATION_ID); - assertThat(createdEntry.getPnfId()).isEqualTo(PNF_UUID); - assertThat(createdEntry.getPnfName()).isEqualTo(PNF_CORRELATION_ID); - assertThat(createdEntry.isInMaint()).isNull(); - } - -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java deleted file mode 100644 index 49fe96c3d9..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.tasks; - -import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; -import java.util.UUID; - -public class PnfTasksUtils { - static final String PNF_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString(); - static final String PNF_CORRELATION_ID = "testPnfCorrelationId"; - - public static Pnf preparePnf(String pnfName, String pnfUuid) { - Pnf pnf = new Pnf(); - pnf.setPnfName(pnfName); - pnf.setPnfId(pnfUuid); - return pnf; - } - -} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java index b9f73f3f0e..22089dae1f 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java @@ -6,6 +6,8 @@ * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 @@ -29,6 +31,7 @@ import java.util.TreeSet; import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.onap.so.client.orchestration.AAIPnfResources; import org.onap.so.logger.LoggingAnchor; import org.camunda.bpm.engine.delegate.BpmnError; import org.onap.so.bpmn.common.BuildingBlockExecution; @@ -43,6 +46,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness; import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy; import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity; import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.Project; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; @@ -50,7 +54,6 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; -import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException; import org.onap.so.client.aai.AAIObjectPlurals; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; @@ -87,6 +90,8 @@ public class AAICreateTasks { @Autowired private AAIVnfResources aaiVnfResources; @Autowired + private AAIPnfResources aaiPnfResources; + @Autowired private ExceptionBuilder exceptionUtil; @Autowired private ExtractPojosForBB extractPojosForBB; @@ -252,6 +257,17 @@ public class AAICreateTasks { } } + public void createPnf(BuildingBlockExecution execution) { + try { + Pnf pnf = extractPojosForBB.extractByKey(execution, ResourceKey.PNF); + ServiceInstance serviceInstance = + extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + aaiPnfResources.createPnfAndConnectServiceInstance(pnf, serviceInstance); + } catch (BBObjectNotFoundException e) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); + } + } + /** * This method is used for separating (,) from the string. * diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java index 06f6550d51..11a7b83259 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 @@ -87,6 +89,10 @@ public class AAIObjectMapper { return modelMapper.map(vnf, org.onap.aai.domain.yang.GenericVnf.class); } + public org.onap.aai.domain.yang.Pnf mapPnf(Pnf pnf) { + return modelMapper.map(pnf, org.onap.aai.domain.yang.Pnf.class); + } + public org.onap.aai.domain.yang.VfModule mapVfModule(VfModule vfModule) { if (modelMapper.getTypeMap(VfModule.class, org.onap.aai.domain.yang.VfModule.class) == null) { modelMapper.addMappings(new PropertyMap<VfModule, org.onap.aai.domain.yang.VfModule>() { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java new file mode 100644 index 0000000000..9dd44c43e9 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Nokia Intellectual Property. 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.client.orchestration; + +import java.util.Optional; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.aai.mapper.AAIObjectMapper; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class AAIPnfResources { + + @Autowired + private InjectionHelper injectionHelper; + + @Autowired + private AAIObjectMapper aaiObjectMapper; + + public void createPnfAndConnectServiceInstance(Pnf pnf, ServiceInstance serviceInstance) { + AAIResourceUri pnfURI = AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnf.getPnfName()); + pnf.setOrchestrationStatus(OrchestrationStatus.INVENTORIED); + AAIResourceUri serviceInstanceURI = + AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId()); + injectionHelper.getAaiClient().createIfNotExists(pnfURI, Optional.of(aaiObjectMapper.mapPnf(pnf))) + .connect(pnfURI, serviceInstanceURI); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java index 39efa6dc76..73896d7d6d 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 @@ -40,6 +42,7 @@ import org.onap.so.client.orchestration.AAICollectionResources; import org.onap.so.client.orchestration.AAIConfigurationResources; import org.onap.so.client.orchestration.AAIInstanceGroupResources; import org.onap.so.client.orchestration.AAINetworkResources; +import org.onap.so.client.orchestration.AAIPnfResources; import org.onap.so.client.orchestration.AAIServiceInstanceResources; import org.onap.so.client.orchestration.AAIVfModuleResources; import org.onap.so.client.orchestration.AAIVnfResources; @@ -69,6 +72,9 @@ public abstract class BaseTaskTest extends TestDataSetup { protected AAIVnfResources aaiVnfResources; @Mock + protected AAIPnfResources aaiPnfResources; + + @Mock protected AAIVfModuleResources aaiVfModuleResources; @Mock diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java index a8550d8df9..a8f47fc763 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 @@ -55,6 +57,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness; import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy; import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; @@ -74,6 +77,7 @@ public class AAICreateTasksTest extends BaseTaskTest { private ServiceInstance serviceInstance; private L3Network network; private GenericVnf genericVnf; + private Pnf pnf; private VolumeGroup volumeGroup; private CloudRegion cloudRegion; private VfModule vfModule; @@ -93,6 +97,7 @@ public class AAICreateTasksTest extends BaseTaskTest { serviceInstance = setServiceInstance(); network = setL3Network(); genericVnf = setGenericVnf(); + pnf = buildPnf(); volumeGroup = setVolumeGroup(); cloudRegion = setCloudRegion(); vfModule = setVfModule(); @@ -324,6 +329,19 @@ public class AAICreateTasksTest extends BaseTaskTest { verify(aaiVnfResources, times(1)).createVnfandConnectServiceInstance(genericVnf, serviceInstance); } + @Test + public void createPnfShouldCallCreatePnfAndConnectServiceInstance() throws BBObjectNotFoundException { + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf); + aaiCreateTasks.createPnf(execution); + verify(aaiPnfResources, times(1)).createPnfAndConnectServiceInstance(pnf, serviceInstance); + } + + @Test + public void createPnfShouldThrowBpmnErrorWhenPnfIsNotFound() throws BBObjectNotFoundException { + expectedException.expect(BpmnError.class); + doThrow(BBObjectNotFoundException.class).when(extractPojosForBB).extractByKey(execution, ResourceKey.PNF); + aaiCreateTasks.createPnf(execution); + } @Test public void createVfModuleTest() throws Exception { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java new file mode 100644 index 0000000000..a929f256ac --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Nokia Intellectual Property. 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.client.orchestration; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import java.util.Optional; +import org.junit.Before; +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.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.mapper.AAIObjectMapper; +import org.onap.so.db.catalog.beans.OrchestrationStatus; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class AAIPnfResourcesTest extends TestDataSetup { + + private Pnf pnf; + private ServiceInstance serviceInstance; + + @Mock + protected AAIObjectMapper aaiObjectMapperMock; + + @Mock + protected InjectionHelper injectionHelperMock; + + @Mock + protected AAIResourcesClient aaiResourcesClientMock; + + @InjectMocks + AAIPnfResources aaiPnfResources = new AAIPnfResources(); + + @Before + public void setUp() { + pnf = buildPnf(); + pnf.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + serviceInstance = buildServiceInstance(); + + doReturn(aaiResourcesClientMock).when(injectionHelperMock).getAaiClient(); + } + + @Test + public void createPnfAndConnectServiceInstanceShouldSetInventoriedStatusAndCallConnectMethod() { + org.onap.aai.domain.yang.Pnf pnfYang = new org.onap.aai.domain.yang.Pnf(); + + doReturn(pnfYang).when(aaiObjectMapperMock).mapPnf(pnf); + doReturn(aaiResourcesClientMock).when(aaiResourcesClientMock).createIfNotExists(any(AAIResourceUri.class), + eq(Optional.of(pnfYang))); + + aaiPnfResources.createPnfAndConnectServiceInstance(pnf, serviceInstance); + + assertEquals(OrchestrationStatus.INVENTORIED, pnf.getOrchestrationStatus()); + verify(aaiResourcesClientMock, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + +} diff --git a/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java b/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java index 5b302f663e..a89bea6975 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java @@ -44,6 +44,11 @@ public class AAIResourcesClient extends aaiClient = (AAIClient) super.client; } + public AAIResourcesClient(AAIClient client) { + super(client); + aaiClient = (AAIClient) super.client; + } + @Override public AAIResultWrapper createWrapper(String json) { return new AAIResultWrapper(json); |