diff options
author | Piotr Borelowski <p.borelowski@partner.samsung.com> | 2020-06-05 16:11:18 +0200 |
---|---|---|
committer | Piotr Borelowski <p.borelowski@partner.samsung.com> | 2020-06-09 19:49:44 +0200 |
commit | 96d36b56071a4f8630512ffa0ff456e27cd7df32 (patch) | |
tree | 5d5f32f2acdec457f5ea153b7bcf1355208825f7 /plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src | |
parent | 3fdcd619e63905d6a47a13a345a243ac30d212ec (diff) |
SOL002-Adapter added to CSIT docker
ve-vnfm-adapter starting as part of the docker-compose config
Issue-ID: INT-1614
Signed-off-by: Piotr Borelowski <p.borelowski@partner.samsung.com>
Change-Id: I240c3bd5fe6fab397af8cff78ed50d755211e628
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src')
2 files changed, 61 insertions, 75 deletions
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 ce3ee8f7..e45665c9 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 @@ -20,13 +20,7 @@ package org.onap.so.svnfm.simulator.controller; -import java.util.UUID; -import javax.ws.rs.core.MediaType; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse2001; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.*; import org.onap.so.svnfm.simulator.constants.Constant; import org.onap.so.svnfm.simulator.repository.VnfmCacheRepository; import org.onap.so.svnfm.simulator.services.SvnfmService; @@ -36,17 +30,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -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.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import javax.ws.rs.core.MediaType; +import java.util.UUID; /** - * * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) * @author Ronan Kenny (ronan.kenny@est.tech) */ @@ -54,14 +42,12 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping(path = Constant.BASE_URL, produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON) public class SvnfmController { + private static final Logger LOGGER = LoggerFactory.getLogger(SvnfmController.class); @Autowired private SvnfmService svnfmService; - @Autowired private VnfmCacheRepository vnfmCacheRepository; - private static final Logger LOGGER = LoggerFactory.getLogger(SvnfmController.class); - /** * To create the Vnf and stores the response in cache * @@ -163,9 +149,19 @@ public class SvnfmController { LOGGER.info("Subscription request received: {}", lccnSubscriptionRequest); svnfmService.registerSubscription(lccnSubscriptionRequest); final InlineResponse2001 response = new InlineResponse2001(); - + response.setId(UUID.randomUUID().toString()); final HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); return new ResponseEntity<>(response, headers, HttpStatus.CREATED); } + + @GetMapping(value = "/subscriptions/{id}") + public ResponseEntity<InlineResponse2001> getSubscribeId(@PathVariable("id") final String id) { + LOGGER.info("Subscription/id request received with id: {}", id); + final InlineResponse2001 response = new InlineResponse2001(); + response.setId(id); + final HttpHeaders headers = new HttpHeaders(); + headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + return new ResponseEntity<>(response, headers, HttpStatus.OK); + } } diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/OperationProgressor.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/OperationProgressor.java index ba549009..5c27665e 100644 --- a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/OperationProgressor.java +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/OperationProgressor.java @@ -2,32 +2,11 @@ package org.onap.so.svnfm.simulator.services; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.KeyManager; -import javax.net.ssl.KeyManagerFactory; -import javax.ws.rs.core.MediaType; import org.apache.commons.codec.binary.Base64; import org.modelmapper.ModelMapper; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.ApiResponse; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantRequest; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsLinks; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsLinksVnfLcmOpOcc; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.*; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.ApiClient; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.ApiException; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.api.DefaultApi; @@ -40,41 +19,53 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperatio import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification.NotificationTypeEnum; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationEnum; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationStateEnum; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoVnfcResourceInfo; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsAuthenticationParamsBasic; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsAuthenticationParamsOauth2ClientCredentials; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.*; import org.onap.so.svnfm.simulator.api.VeVnfmApi; -import org.onap.so.svnfm.simulator.model.Vnfds; -import org.onap.so.svnfm.simulator.repository.VnfOperationRepository; import org.onap.so.svnfm.simulator.config.ApplicationConfig; import org.onap.so.svnfm.simulator.model.VnfOperation; +import org.onap.so.svnfm.simulator.model.Vnfds; +import org.onap.so.svnfm.simulator.repository.VnfOperationRepository; import org.onap.so.svnfm.simulator.util.PatternContainedChecker; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.ws.rs.core.MediaType; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import java.util.*; + public abstract class OperationProgressor implements Runnable { private static final Logger LOGGER = LoggerFactory.getLogger(OperationProgressor.class); private static final String CERTIFICATE_TO_TRUST = "so-vnfm-adapter.crt.pem"; - - private Resource keyStoreResource = new ClassPathResource("so-vnfm-simulator.p12"); - private String keyStorePassword = "7Em3&j4.19xYiMelhD5?xbQ."; - protected final VnfOperation operation; protected final SvnfmService svnfmService; + protected final Vnfds vnfds; private final VnfOperationRepository vnfOperationRepository; private final ApplicationConfig applicationConfig; - protected final Vnfds vnfds; private final SubscriptionService subscriptionService; private final DefaultApi notificationClient; private final org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.api.DefaultApi grantClient; + private final Resource keyStoreResource = new ClassPathResource("so-vnfm-simulator.p12"); + private final String keyStorePassword = "7Em3&j4.19xYiMelhD5?xbQ."; public OperationProgressor(final VnfOperation operation, final SvnfmService svnfmService, - final VnfOperationRepository vnfOperationRepository, final ApplicationConfig applicationConfig, - final Vnfds vnfds, final SubscriptionService subscriptionService) { + final VnfOperationRepository vnfOperationRepository, final ApplicationConfig applicationConfig, + final Vnfds vnfds, final SubscriptionService subscriptionService) { this.operation = operation; this.svnfmService = svnfmService; this.vnfOperationRepository = vnfOperationRepository; @@ -83,7 +74,7 @@ public abstract class OperationProgressor implements Runnable { this.subscriptionService = subscriptionService; final ApiClient apiClient = new ApiClient(); - String callBackUrl = subscriptionService.getSubscriptions().iterator().next().getCallbackUri(); + String callBackUrl = getLastLccnSubscriptionRequest().getCallbackUri(); final PatternContainedChecker checker = new PatternContainedChecker("/lcn/", callBackUrl); callBackUrl = checker.getText(); apiClient.setBasePath(callBackUrl); @@ -137,7 +128,6 @@ public abstract class OperationProgressor implements Runnable { buildNotification(NotificationStatusEnum.START, OperationStateEnum.PROCESSING); sendNotification(notificationOfProcessing); - final GrantRequest grantRequest = buildGrantRequest(); final InlineResponse201 grantResponse = sendGrantRequest(grantRequest); final List<InlineResponse201InstantiatedVnfInfoVnfcResourceInfo> vnfcs = handleGrantResponse(grantResponse); @@ -154,7 +144,6 @@ public abstract class OperationProgressor implements Runnable { } catch (final Exception exception) { LOGGER.error("Error in OperationProgressor ", exception); } - } private void sleep(final long milliSeconds) { @@ -174,7 +163,7 @@ public abstract class OperationProgressor implements Runnable { } private VnfLcmOperationOccurrenceNotification buildNotification(final NotificationStatusEnum status, - final OperationStateEnum operationState) { + final OperationStateEnum operationState) { final VnfLcmOperationOccurrenceNotification notification = new VnfLcmOperationOccurrenceNotification(); notification.setId(UUID.randomUUID().toString()); notification.setNotificationType(NotificationTypeEnum.VNFLCMOPERATIONOCCURRENCENOTIFICATION); @@ -190,7 +179,6 @@ public abstract class OperationProgressor implements Runnable { vnfInstanceLink.setHref(getVnfLink()); links.setVnfInstance(vnfInstanceLink); - final LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance operationLink = new LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance(); operationLink.setHref(getOperationLink()); @@ -222,23 +210,18 @@ public abstract class OperationProgressor implements Runnable { LOGGER.info("Sending notification: {}", notification); try { final SubscriptionsAuthenticationParamsBasic subscriptionAuthentication = - subscriptionService.getSubscriptions().iterator().next().getAuthentication().getParamsBasic(); - final String auth = - subscriptionAuthentication.getUserName() + ":" + subscriptionAuthentication.getPassword(); + getLastLccnSubscriptionRequest().getAuthentication().getParamsBasic(); + final String auth = subscriptionAuthentication.getUserName() + ":" + subscriptionAuthentication.getPassword(); final byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)); String authHeader = "Basic " + new String(encodedAuth); - - notificationClient.lcnVnfLcmOperationOccurrenceNotificationPostWithHttpInfo(notification, - MediaType.APPLICATION_JSON, authHeader); + notificationClient.lcnVnfLcmOperationOccurrenceNotificationPostWithHttpInfo(notification, MediaType.APPLICATION_JSON, authHeader); } catch (final ApiException exception) { LOGGER.error("Error sending notification: " + notification, exception); LOGGER.error("Response code: {}, body: {}, basePath: {}", exception.getCode(), exception.getResponseBody(), notificationClient.getApiClient().getBasePath()); - } } - public GrantRequest buildGrantRequest() { final GrantRequest grantRequest = new GrantRequest(); grantRequest.setVnfInstanceId(operation.getVnfInstanceId()); @@ -275,15 +258,11 @@ public abstract class OperationProgressor implements Runnable { private InlineResponse201 sendGrantRequest(final GrantRequest grantRequest) { LOGGER.info("Sending grant request: {}", grantRequest); try { - final SubscriptionsAuthenticationParamsOauth2ClientCredentials subscriptionAuthentication = - subscriptionService.getSubscriptions().iterator().next().getAuthentication() - .getParamsOauth2ClientCredentials(); - + getLastLccnSubscriptionRequest().getAuthentication().getParamsOauth2ClientCredentials(); final String authHeader = applicationConfig.getGrantAuth().equals("oauth") ? "Bearer " + getToken(notificationClient.getApiClient(), subscriptionAuthentication) : null; - final ApiResponse<InlineResponse201> response = grantClient.grantsPostWithHttpInfo(grantRequest, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, authHeader); LOGGER.info("Grant Response: {}", response); @@ -307,7 +286,7 @@ public abstract class OperationProgressor implements Runnable { } private String getToken(final ApiClient apiClient, - final SubscriptionsAuthenticationParamsOauth2ClientCredentials oauthClientCredentials) { + final SubscriptionsAuthenticationParamsOauth2ClientCredentials oauthClientCredentials) { final String basePath = apiClient.getBasePath().substring(0, apiClient.getBasePath().indexOf("/so/")); final String tokenUrl = basePath + "/oauth/token?grant_type=client_credentials"; @@ -321,7 +300,6 @@ public abstract class OperationProgressor implements Runnable { connection.connect(); return getResponse(connection).get("access_token").getAsString(); - } catch (IOException exception) { LOGGER.error("Error getting token", exception); return null; @@ -348,4 +326,16 @@ public abstract class OperationProgressor implements Runnable { return jsonObject; } + private LccnSubscriptionRequest getLastLccnSubscriptionRequest() { + final Collection<LccnSubscriptionRequest> subscriptions = subscriptionService.getSubscriptions(); + final Iterator<LccnSubscriptionRequest> iterator = subscriptions.iterator(); + + LccnSubscriptionRequest last = null; + + while (iterator.hasNext()) { + last = iterator.next(); + } + + return last; + } } |