diff options
author | AndrewLamb <andrew.a.lamb@est.tech> | 2020-05-06 14:58:58 +0100 |
---|---|---|
committer | AndrewLamb <andrew.a.lamb@est.tech> | 2020-05-07 11:45:01 +0100 |
commit | 73364832c77469f73a7926a727888d904109023b (patch) | |
tree | 5ea43b0cdc0d4adb4e1b0d989d8e4dd54729c31e /plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service | |
parent | 8a477f14b199f96b29e7f99216f39f7ee8273edb (diff) |
Update vnfm simulator - subscribe and notify
Change-Id: Iced3da9cbedabba7df9defb4933ec69dfaf75823
Issue-ID: SO-2420
Signed-off-by: AndrewLamb <andrew.a.lamb@est.tech>
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service')
17 files changed, 837 insertions, 50 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/pom.xml b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/pom.xml index aefea959..00fd81f1 100644 --- a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/pom.xml +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/pom.xml @@ -18,6 +18,16 @@ <groupId>org.onap.so.adapters</groupId> <artifactId>mso-vnfm-adapter-ext-clients</artifactId> <version>1.4.3</version> + <exclusions> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </exclusion> + <exclusion> + <groupId>com.github.tomakehurst</groupId> + <artifactId>wiremock-standalone</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> @@ -109,6 +119,22 @@ <groupId>org.onap.so</groupId> <artifactId>common</artifactId> <version>1.4.3</version> + <exclusions> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.onap.so.simulators.vnfm</groupId> + <artifactId>vnfm-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>4.5.8</version> </dependency> </dependencies> <build> diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/config/SslBasedRestTemplateConfiguration.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/config/SslBasedRestTemplateConfiguration.java new file mode 100644 index 00000000..47e189dc --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/config/SslBasedRestTemplateConfiguration.java @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.svnfm.simulator.config; + +import com.google.gson.Gson; +import org.apache.http.client.HttpClient; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContextBuilder; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.JSON; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.GsonHttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.client.RestTemplate; +import java.security.KeyStore; +import java.util.Iterator; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * @author Andrew Lamb (andrew.a.lamb@est.tech) + */ +@Configuration public class SslBasedRestTemplateConfiguration { + + private static final Logger logger = LoggerFactory.getLogger(SslBasedRestTemplateConfiguration.class); + + public static final String SSL_BASED_CONFIGURABLE_REST_TEMPLATE = "sslBasedConfigurableRestTemplate"; + + @Value("${http.client.ssl.trust-store:#{null}}") + private Resource trustStore; + @Value("${http.client.ssl.trust-store-password:#{null}}") + private String trustStorePassword; + + @Value("${server.ssl.key-store:#{null}}") + private Resource keyStoreResource; + @Value("${server.ssl.key--store-password:#{null}}") + private String keyStorePassword; + + @Bean + @Qualifier(SSL_BASED_CONFIGURABLE_REST_TEMPLATE) + public RestTemplate sslBasedrestTemplate() throws Exception { + logger.info("Configuring {} ...", this.getClass().getCanonicalName()); + final RestTemplate restTemplate = new RestTemplate(); + final HttpClientBuilder builder = HttpClients.custom(); + + if (keyStoreResource != null && trustStore != null) { + logger.info("Setting key-store: {}", keyStoreResource.getURL()); + logger.info("Setting key-store-password: {}", keyStorePassword); + final KeyStore keystore = KeyStore.getInstance("pkcs12"); + keystore.load(keyStoreResource.getInputStream(), keyStorePassword.toCharArray()); + + logger.info("Setting client trust-store: {}", trustStore.getURL()); + logger.info("Setting client trust-store-password: {}", trustStorePassword); + final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( + new SSLContextBuilder().loadTrustMaterial(trustStore.getURL(), trustStorePassword.toCharArray()) + .loadKeyMaterial(keystore, keyStorePassword.toCharArray()).build()); + builder.setSSLSocketFactory(socketFactory); + } + + final HttpClient httpClient = builder.build(); + final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient); + restTemplate.setRequestFactory(factory); + setGsonMessageConverter(restTemplate); + return restTemplate; + } + + public void setGsonMessageConverter(final RestTemplate restTemplate) { + logger.info("Setting GsonMessageConverter ..."); + final Iterator<HttpMessageConverter<?>> iterator = restTemplate.getMessageConverters().iterator(); + while (iterator.hasNext()) { + if (iterator.next() instanceof MappingJackson2HttpMessageConverter) { + iterator.remove(); + } + } + final Gson gson = new JSON().getGson(); + restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); + logger.info("Finished setting GsonMessageConverter ..."); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/constants/Constant.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/constants/Constant.java index 02a319a2..ceb5be5a 100644 --- a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/constants/Constant.java +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/constants/Constant.java @@ -24,6 +24,7 @@ package org.onap.so.svnfm.simulator.constants; * * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) * @author ronan.kenny@est.tech + * @author Eoin Hanan (eoin.hanan@est.tech) */ public class Constant { @@ -36,4 +37,9 @@ public class Constant { public static final String VNF_CONFIG_PROPERTIES = "{\"isAutoScaleEnabled\": \"true\",\"isAutoHealingEnabled\": \"true\"}"; public static final String IN_LINE_RESPONSE_201_CACHE = "inlineResponse201"; + public static final String PACKAGE_MANAGEMENT_BASE_URL = "/vnfpkgm/v1"; + public static final String SUBSCRIPTION_ENDPOINT = "/subscribe"; + public static final String NOTIFICATION_ENDPOINT = "/notification"; + public static final String VNFM_ADAPTER_ENDPOINT = "https://so-vnfm-adapter.onap:9092/so/vnfm-adapter/v1/"; + public static final String VNFM_ADAPTER_SUBSCRIPTION_ENDPOINT = VNFM_ADAPTER_ENDPOINT + "vnfpkgm/v1/subscriptions"; } diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/controller/SubscriptionNotificationController.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/controller/SubscriptionNotificationController.java new file mode 100644 index 00000000..2c6b8f24 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/controller/SubscriptionNotificationController.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.svnfm.simulator.controller; + +import javax.ws.rs.core.MediaType; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse201; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthentication; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthentication.AuthTypeEnum; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthenticationParamsBasic; +import org.onap.so.svnfm.simulator.constants.Constant; +import org.onap.so.svnfm.simulator.services.SubscriptionManager; +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.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author Eoin Hanan (eoin.hanan@est.tech) + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * + */ +@RestController +@RequestMapping(path = Constant.PACKAGE_MANAGEMENT_BASE_URL, produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON) +public class SubscriptionNotificationController { + @Autowired + private SubscriptionManager subscriptionManager; + + private static final Logger logger = LoggerFactory.getLogger(SubscriptionNotificationController.class); + + @Value("${spring.security.usercredentials[0].username}") + private String username; + @Value("${spring.security.usercredentials[0].password}") + private String password; + + @GetMapping(produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<Void> testEndpoint() { + logger.info("Testing SubscriptionNotification Endpoint"); + return ResponseEntity.noContent().build(); + } + + /** + * Send subscription request + * + * @param pkgmSubscriptionRequest The subscription request + * @return + */ + @PostMapping(value = Constant.SUBSCRIPTION_ENDPOINT, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> subscribeForNotifications(@RequestBody final PkgmSubscriptionRequest pkgmSubscriptionRequest){ + logger.info("Vnf Package Subscription Request received:\n{}", pkgmSubscriptionRequest); + + if(pkgmSubscriptionRequest.getCallbackUri()==null){ + logger.info("Subscription Request does not include call back URI "); + pkgmSubscriptionRequest.setCallbackUri(Constant.PACKAGE_MANAGEMENT_BASE_URL + Constant.NOTIFICATION_ENDPOINT); + } + + if(pkgmSubscriptionRequest.getAuthentication()==null) { + pkgmSubscriptionRequest.setAuthentication(new SubscriptionsAuthentication() + .addAuthTypeItem(AuthTypeEnum.BASIC) + .paramsBasic(new SubscriptionsAuthenticationParamsBasic().userName(username).password(password))); + + } + logger.info("Final Request being sent:\n{}", pkgmSubscriptionRequest); + + final InlineResponse201 response = subscriptionManager.createSubscription(pkgmSubscriptionRequest); + logger.info("Response is:\n{}", response); + + return ResponseEntity.ok().body(response); + } + + /** + * Endpoint to receive VNF package notifications + * + * @param notification The notification received + * @return + */ + @PostMapping(value = Constant.NOTIFICATION_ENDPOINT, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> postVnfPackageNotification(@RequestBody Object notification){ + logger.info("Vnf Notification received:\n{}", notification); + return ResponseEntity.noContent().build(); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/controller/SvnfmController.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/controller/SvnfmController.java index 6683b696..ce3ee8f7 100644 --- a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/controller/SvnfmController.java +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/controller/SvnfmController.java @@ -65,7 +65,7 @@ public class SvnfmController { /** * To create the Vnf and stores the response in cache * - * @param CreateVnfRequest + * @param createVNFRequest * @return InlineResponse201 */ @PostMapping(value = "/vnf_instances") diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/oauth/AuthorizationServerConfig.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/oauth/AuthorizationServerConfig.java index 500c85be..a97c41fa 100644 --- a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/oauth/AuthorizationServerConfig.java +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/oauth/AuthorizationServerConfig.java @@ -20,7 +20,7 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap @Override public void configure(final ClientDetailsServiceConfigurer clients) throws Exception { clients.inMemory().withClient("vnfmadapter") - .secret("$2a$10$dHzTlqSBcm8hdO52LBvnX./zNTvUzzJy.lZrc4bCBL5gkln0wX6T6") + .secret("$2a$10$dHzTlqSBcm8hdO52LBvnX./zNTvUzzJy.lZrc4bCBL5gkln0wX6T6") //123456 .authorizedGrantTypes("client_credentials").scopes("write").accessTokenValiditySeconds(ONE_DAY) .refreshTokenValiditySeconds(ONE_DAY); } diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/SubscriptionManager.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/SubscriptionManager.java new file mode 100644 index 00000000..2050ab0d --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/SubscriptionManager.java @@ -0,0 +1,70 @@ +package org.onap.so.svnfm.simulator.services; + +import static org.onap.so.svnfm.simulator.config.SslBasedRestTemplateConfiguration.SSL_BASED_CONFIGURABLE_REST_TEMPLATE; + +import java.nio.charset.StandardCharsets; +import javax.ws.rs.core.MediaType; +import org.apache.commons.codec.binary.Base64; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse201; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest; +import org.onap.so.svnfm.simulator.constants.Constant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +/** + * + * @author Eoin Hanan (eoin.hanan@est.tech) + * @author Gareth Roper (gareth.roper@est.tech) + */ +@Service +public class SubscriptionManager { + + private static final Logger LOGGER = LoggerFactory.getLogger(SubscriptionManager.class); + + private final RestTemplate restTemplate; + + @Value("${vnfm-adapter.auth.name}") + private String username; + + @Value("${vnfm-adapter.auth.password}") + private String password; + + @Autowired + public SubscriptionManager( + @Qualifier(SSL_BASED_CONFIGURABLE_REST_TEMPLATE) final RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } + + /** + * Send subscription request to the vnfm adapter + * + * @param pkgmSubscriptionRequest The subscription request to send + * @return + */ + public InlineResponse201 createSubscription(final PkgmSubscriptionRequest pkgmSubscriptionRequest) { + final byte[] encodedAuth = getBasicAuth(username, password); + final String authHeader = "Basic " + new String(encodedAuth); + final String uri = Constant.VNFM_ADAPTER_SUBSCRIPTION_ENDPOINT; + final HttpHeaders headers = new HttpHeaders(); + headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + headers.add(HttpHeaders.AUTHORIZATION, authHeader); + headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); + final HttpEntity<?> request = new HttpEntity<>(pkgmSubscriptionRequest, headers); + LOGGER.info("Creating Subscription using request: {}", pkgmSubscriptionRequest); + return restTemplate.exchange(uri, HttpMethod.POST, request, InlineResponse201.class).getBody(); + } + + private byte[] getBasicAuth(final String username, final String password) { + final String auth = username + ":" + password; + return Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/resources/application.yaml b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/resources/application.yaml index 33d865c1..ffae8eb2 100644 --- a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/resources/application.yaml +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/resources/application.yaml @@ -11,54 +11,64 @@ # 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. - spring: - h2: - console: - enabled: true - path: console - datasource: - url: jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE - username: admin - password: admin - http: - converters: - preferred-json-mapper: gson - security: - usercredentials: - - username: vnfm - password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke' - role: BPEL-Client - + h2: + console: null + enabled: true + path: console + datasource: + url: jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE + username: admin + password: admin + http: + converters: + preferred-json-mapper: gson + security: + usercredentials: + - username: vnfm + password: $2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke + role: BPEL-Client + main: + allow-bean-definition-overriding: true server: - port: 9093 - tomcat: - max-threads: 50 - ssl: - key-alias: so@so.onap.org - key--store-password: '7Em3&j4.19xYiMelhD5?xbQ.' - key-store: classpath:so-vnfm-simulator.p12 - key-store-type: PKCS12 - + port: 9093 + tomcat: + max-threads: 50 + ssl: + key-alias: so@so.onap.org + key--store-password: 7Em3&j4.19xYiMelhD5?xbQ. + key-store: classpath:so-vnfm-simulator.p12 + key-store-type: PKCS12 +http: + client: + ssl: + trust-store: classpath:so-vnfm-adapter.p12 + trust-store-password: ywsqCy:EEo#j}HJHM7z^Rk[L +endpoint: + callbackUri: https://so-vnfm-simulator.onap:9093/vnfpkgm/v1/notification +vnfm-adapter: + auth: + name: vnfm + password: password1$ vnfds: - vnfdlist: - - vnfdid: 1 - vnfclist: - - vnfcid: VNFC1 - resourceTemplateId: vnfd1_vnfc1 - vduId: vnfd1_vduForVnfc1 - type: COMPUTE - - vnfcid: VNFC2 - resourceTemplateId: vnfd1_vnfc2 - vduId: vnfd1_vduForVnfc2 - type: COMPUTE - - vnfdid: 2 - vnfclist: - - vnfcid: VNFC3 - resourceTemplateId: vnfd2_vnfc3 - vduId: vnfd2_vduForVnfc3 - type: COMPUTE - - vnfcid: VNFC4 - resourceTemplateId: vnfd2_vnfc4 - vduId: vnfd2_vduForVnfc4 - type: COMPUTE + vnfdlist: + - vnfdid: 1 + vnfclist: + - vnfcid: VNFC1 + resourceTemplateId: vnfd1_vnfc1 + vduId: vnfd1_vduForVnfc1 + type: COMPUTE + - vnfcid: VNFC2 + resourceTemplateId: vnfd1_vnfc2 + vduId: vnfd1_vduForVnfc2 + type: COMPUTE + - vnfdid: 2 + vnfclist: + - vnfcid: VNFC3 + resourceTemplateId: vnfd2_vnfc3 + vduId: vnfd2_vduForVnfc3 + type: COMPUTE + - vnfcid: VNFC4 + resourceTemplateId: vnfd2_vnfc4 + vduId: vnfd2_vduForVnfc4 + type: COMPUTE diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/resources/so-vnfm-adapter.jks b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/resources/so-vnfm-adapter.jks Binary files differnew file mode 100644 index 00000000..ac3113f8 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/resources/so-vnfm-adapter.jks diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/resources/so-vnfm-adapter.p12 b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/resources/so-vnfm-adapter.p12 Binary files differnew file mode 100644 index 00000000..ae4fddc6 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/resources/so-vnfm-adapter.p12 diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/controllers/TestSubscriptionNotificationController.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/controllers/TestSubscriptionNotificationController.java new file mode 100644 index 00000000..743e2c04 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/controllers/TestSubscriptionNotificationController.java @@ -0,0 +1,194 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.svnfm.simulator.controllers; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse201; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter1; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.notification.model.VnfPackageOnboardingNotification; +import org.onap.so.svnfm.simulator.config.SvnfmApplication; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +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; +import java.time.LocalDateTime; + +import static org.junit.Assert.assertEquals; +import static org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter.NotificationTypesEnum.VNFPACKAGECHANGENOTIFICATION; +import static org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter.NotificationTypesEnum.VNFPACKAGEONBOARDINGNOTIFICATION; +import static org.onap.so.svnfm.simulator.config.SslBasedRestTemplateConfiguration.SSL_BASED_CONFIGURABLE_REST_TEMPLATE; +import static org.onap.so.svnfm.simulator.constants.Constant.NOTIFICATION_ENDPOINT; +import static org.onap.so.svnfm.simulator.constants.Constant.PACKAGE_MANAGEMENT_BASE_URL; +import static org.onap.so.svnfm.simulator.constants.Constant.SUBSCRIPTION_ENDPOINT; +import static org.onap.so.svnfm.simulator.constants.Constant.VNFM_ADAPTER_SUBSCRIPTION_ENDPOINT; +import static org.onap.so.svnfm.simulator.utils.TestUtils.getBaseUrl; +import static org.onap.so.svnfm.simulator.utils.TestUtils.getBasicAuth; +import static org.onap.so.svnfm.simulator.utils.TestUtils.getHttpHeaders; +import static org.onap.so.svnfm.simulator.utils.TestUtils.getNotification; +import static org.onap.so.svnfm.simulator.utils.TestUtils.getSubscriptionRequest; +import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; + +/** + * @author Andrew Lamb (andrew.a.lamb@est.tech) + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SvnfmApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class TestSubscriptionNotificationController { + + private static final Logger LOGGER = getLogger(TestSubscriptionNotificationController.class); + + @LocalServerPort + private int port; + + @Autowired @Qualifier(SSL_BASED_CONFIGURABLE_REST_TEMPLATE) + private RestTemplate restTemplate; + private MockRestServiceServer mockRestServiceServer; + + @Autowired + private TestRestTemplate testRestTemplate; + + private Gson gson; + private String vnfmSimulatorCallbackUrl; + + @Before + public void setup() { + mockRestServiceServer = MockRestServiceServer.bindTo(restTemplate).build(); + gson = new GsonBuilder().create(); + vnfmSimulatorCallbackUrl = getBaseUrl(port) + PACKAGE_MANAGEMENT_BASE_URL + NOTIFICATION_ENDPOINT; + } + + @After + public void teardown() { + mockRestServiceServer.reset(); + } + + @Test + public void testGetFromEndpoint_Success() { + final ResponseEntity<?> responseEntity = checkGetFromTestEndpoint(); + assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + } + + @Test + public void testPostOnboardingSubscriptionRequest_Success() throws Exception { + final PkgmSubscriptionRequest pkgmSubscriptionRequest = + gson.fromJson(getSubscriptionRequest(VNFPACKAGEONBOARDINGNOTIFICATION), PkgmSubscriptionRequest.class); + pkgmSubscriptionRequest.setCallbackUri(vnfmSimulatorCallbackUrl); + final InlineResponse201 inlineResponse = + new InlineResponse201().id("subscriptionId").filter(new SubscriptionsFilter1()) + .callbackUri("callbackUri"); + + mockRestServiceServer.expect(requestTo(VNFM_ADAPTER_SUBSCRIPTION_ENDPOINT)).andExpect(method(HttpMethod.POST)) + .andExpect(content().json(gson.toJson(pkgmSubscriptionRequest))) + .andRespond(withSuccess(gson.toJson(inlineResponse), APPLICATION_JSON)); + + final ResponseEntity<?> responseEntity = postSubscriptionRequest(pkgmSubscriptionRequest); + final InlineResponse201 responseEntityBody = (InlineResponse201) responseEntity.getBody(); + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertEquals(inlineResponse, responseEntityBody); + } + + @Test + public void testPostChangeSubscriptionRequest_Success() throws Exception { + final PkgmSubscriptionRequest pkgmSubscriptionRequest = + gson.fromJson(getSubscriptionRequest(VNFPACKAGECHANGENOTIFICATION), PkgmSubscriptionRequest.class); + pkgmSubscriptionRequest.setCallbackUri(vnfmSimulatorCallbackUrl); + final InlineResponse201 inlineResponse = + new InlineResponse201().id("subscriptionId").filter(new SubscriptionsFilter1()) + .callbackUri("callbackUri"); + + mockRestServiceServer.expect(requestTo(VNFM_ADAPTER_SUBSCRIPTION_ENDPOINT)).andExpect(method(HttpMethod.POST)) + .andExpect(content().json(gson.toJson(pkgmSubscriptionRequest))) + .andRespond(withSuccess(gson.toJson(inlineResponse), APPLICATION_JSON)); + + final ResponseEntity<?> responseEntity = postSubscriptionRequest(pkgmSubscriptionRequest); + final InlineResponse201 responseEntityBody = (InlineResponse201) responseEntity.getBody(); + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertEquals(inlineResponse, responseEntityBody); + } + + @Test + public void testNotificationEndpoint_Success() throws Exception { + final VnfPackageOnboardingNotification vnfPackageOnboardingNotification = + gson.fromJson(getNotification(VNFPACKAGEONBOARDINGNOTIFICATION), + VnfPackageOnboardingNotification.class); + final LocalDateTime timestamp = LocalDateTime.of(2020, 1, 1, 1, 1, 1, 1); + vnfPackageOnboardingNotification.setTimeStamp(timestamp); + final ResponseEntity<?> responseEntity = postNotification(vnfPackageOnboardingNotification); + assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + } + + private ResponseEntity<Void> checkGetFromTestEndpoint() { + LOGGER.info("checkGetFromTestEndpoint() method..."); + final String vnfmSimulatorTestEndpoint = getBaseUrl(port) + PACKAGE_MANAGEMENT_BASE_URL; + final String authHeader = getBasicAuth("vnfm", "password1$"); + final HttpHeaders headers = getHttpHeaders(authHeader); + final HttpEntity<?> request = new HttpEntity<>(headers); + + LOGGER.info("sending request {} to: {}", request, vnfmSimulatorTestEndpoint); + return testRestTemplate.exchange(vnfmSimulatorTestEndpoint, HttpMethod.GET, request, Void.class); + } + + private ResponseEntity<?> postSubscriptionRequest(final PkgmSubscriptionRequest subscriptionRequest) { + LOGGER.info("postSubscriptionRequest() method..."); + final String vnfmSimulatorSubscribeEndpoint = + getBaseUrl(port) + PACKAGE_MANAGEMENT_BASE_URL + SUBSCRIPTION_ENDPOINT; + final String authHeader = getBasicAuth("vnfm", "password1$"); + final HttpHeaders headers = getHttpHeaders(authHeader); + final HttpEntity<?> request = new HttpEntity<>(subscriptionRequest, headers); + + LOGGER.info("sending request {} to: {}", request, vnfmSimulatorSubscribeEndpoint); + return testRestTemplate + .exchange(vnfmSimulatorSubscribeEndpoint, HttpMethod.POST, request, InlineResponse201.class); + } + + private ResponseEntity<?> postNotification(final Object notification) { + LOGGER.info("postNotification method..."); + final String authHeader = getBasicAuth("vnfm", "password1$"); + final HttpHeaders headers = getHttpHeaders(authHeader); + final HttpEntity<?> request = new HttpEntity<>(notification, headers); + + LOGGER.info("sending request {} to: {}", request, vnfmSimulatorCallbackUrl); + return testRestTemplate.exchange(vnfmSimulatorCallbackUrl, HttpMethod.POST, request, Void.class); + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/utils/TestUtils.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/utils/TestUtils.java new file mode 100644 index 00000000..e03f945c --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/utils/TestUtils.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.svnfm.simulator.utils; + +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import org.apache.commons.codec.binary.Base64; + +/** + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * + */ +public class TestUtils { + + public static String getBasicAuth(final String username, final String password) { + final String auth = username + ":" + password; + return "Basic " + new String(Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1))); + } + + public static HttpHeaders getHttpHeaders(final String authHeader) { + final HttpHeaders headers = new HttpHeaders(); + headers.add(HttpHeaders.AUTHORIZATION, authHeader); + headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); + return headers; + } + + public static File getFile(final String file) throws IOException { + return new ClassPathResource(file).getFile(); + } + + public static String getJsonString(final String file) throws IOException { + return new String(Files.readAllBytes(getFile(file).toPath())); + } + + public static String getBaseUrl(final int port) { + return "http://localhost:" + port; + } + + public static String getSubscriptionRequest(final SubscriptionsFilter.NotificationTypesEnum notificationType) throws Exception { + switch (notificationType) { + case VNFPACKAGECHANGENOTIFICATION: + return getJsonString("test-data/pkg-subscription-request-change.json"); + case VNFPACKAGEONBOARDINGNOTIFICATION: + return getJsonString("test-data/pkg-subscription-request-onboarding.json"); + default: + return null; + } + } + + public static String getNotification(final SubscriptionsFilter.NotificationTypesEnum notificationType) throws Exception { + switch (notificationType) { + case VNFPACKAGECHANGENOTIFICATION: + return getJsonString("test-data/vnf-package-change-notification.json"); + case VNFPACKAGEONBOARDINGNOTIFICATION: + return getJsonString("test-data/vnf-package-onboarding-notification.json"); + default: + return null; + } + } + + private TestUtils() {} + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/application.yaml b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/application.yaml new file mode 100644 index 00000000..3a2268cb --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/application.yaml @@ -0,0 +1,64 @@ +# Copyright © 2019 Nordix Foundation +# +# 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. +spring: + h2: + console: null + enabled: true + path: console + datasource: + url: jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE + username: admin + password: admin + http: + converters: + preferred-json-mapper: gson + security: + usercredentials: + - username: vnfm + password: $2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke + role: BPEL-Client + main: + allow-bean-definition-overriding: true +server: + port: 9093 + tomcat: + max-threads: 50 +endpoint: + callbackUri: https://so-vnfm-simulator.onap:9093/vnfpkgm/v1/notification +vnfm-adapter: + auth: + name: vnfm + password: password1$ +vnfds: + vnfdlist: + - vnfdid: 1 + vnfclist: + - vnfcid: VNFC1 + resourceTemplateId: vnfd1_vnfc1 + vduId: vnfd1_vduForVnfc1 + type: COMPUTE + - vnfcid: VNFC2 + resourceTemplateId: vnfd1_vnfc2 + vduId: vnfd1_vduForVnfc2 + type: COMPUTE + - vnfdid: 2 + vnfclist: + - vnfcid: VNFC3 + resourceTemplateId: vnfd2_vnfc3 + vduId: vnfd2_vduForVnfc3 + type: COMPUTE + - vnfcid: VNFC4 + resourceTemplateId: vnfd2_vnfc4 + vduId: vnfd2_vduForVnfc4 + type: COMPUTE diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/test-data/pkg-subscription-request-change.json b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/test-data/pkg-subscription-request-change.json new file mode 100644 index 00000000..862ed598 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/test-data/pkg-subscription-request-change.json @@ -0,0 +1,43 @@ +{ + "filter": { + "notificationTypes": [ + "VnfPackageChangeNotification" + ], + "vnfProductsFromProviders": [ + { + "vnfProvider": "Ericsson", + "vnfProducts": [ + { + "vnfProductName": "VnfProducts", + "versions": [ + { + "vnfSoftwareVersion": "vnfSoftwareVersion", + "vnfdVersions": [ + "version1" + ] + } + ] + } + ] + } + ], + "vnfdId": [ + "VNFDID" + ], + "vnfPkgId": [ + "VNFPKGID" + ], + "operationalState": ["ENABLED"], + "usageState": [] + }, + "callbackUri": "https://so-vnfm-simulator.onap:9093/vnfpkgm/v1/notification", + "authentication": { + "authType": [ + "BASIC" + ], + "paramsBasic": { + "userName": "vnfm", + "password": "password1$" + } + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/test-data/pkg-subscription-request-onboarding.json b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/test-data/pkg-subscription-request-onboarding.json new file mode 100644 index 00000000..3aa192ed --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/test-data/pkg-subscription-request-onboarding.json @@ -0,0 +1,43 @@ +{ + "filter": { + "notificationTypes": [ + "VnfPackageOnboardingNotification" + ], + "vnfProductsFromProviders": [ + { + "vnfProvider": "Ericsson", + "vnfProducts": [ + { + "vnfProductName": "VnfProducts", + "versions": [ + { + "vnfSoftwareVersion": "vnfSoftwareVersion", + "vnfdVersions": [ + "version1" + ] + } + ] + } + ] + } + ], + "vnfdId": [ + "VNFDID" + ], + "vnfPkgId": [ + "VNFPKGID" + ], + "operationalState": ["ENABLED"], + "usageState": [] + }, + "callbackUri": "https://so-vnfm-simulator.onap:9093/vnfpkgm/v1/notification", + "authentication": { + "authType": [ + "BASIC" + ], + "paramsBasic": { + "userName": "vnfm", + "password": "password1$" + } + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/test-data/vnf-package-change-notification.json b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/test-data/vnf-package-change-notification.json new file mode 100644 index 00000000..0022ecf9 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/test-data/vnf-package-change-notification.json @@ -0,0 +1,17 @@ +{ + "id": "string", + "notificationType": "VnfPackageChangeNotification", + "subscriptionId": "string", + "vnfPkgId": "string", + "vnfdId": "string", + "changeType": "OP_STATE_CHANGE", + "operationalState": ["ENABLED"], + "_links": { + "vnfPackage": { + "href": "string" + }, + "subscription": { + "href": "string" + } + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/test-data/vnf-package-onboarding-notification.json b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/test-data/vnf-package-onboarding-notification.json new file mode 100644 index 00000000..40b565be --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/resources/test-data/vnf-package-onboarding-notification.json @@ -0,0 +1,15 @@ +{ + "id": "string", + "notificationType": "VnfPackageOnboardingNotification", + "subscriptionId": "string", + "vnfPkgId": "string", + "vnfdId": "string", + "_links": { + "vnfPackage": { + "href": "string" + }, + "subscription": { + "href": "string" + } + } +} |