summaryrefslogtreecommitdiffstats
path: root/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2019-04-08 13:59:09 +0000
committerMichaelMorris <michael.morris@est.tech>2019-04-08 13:59:09 +0000
commit67e46b382de7ae15bdb2062e62bbc8725d3d113e (patch)
treec5a37d360b012b5920b02f59558772c9f77cb2f1 /adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java
parente757e801c665a1758cf4c976b24df13adda38b2b (diff)
Add subscription for notifications
Issue-ID: SO-1628 Change-Id: I302e5c65f9b01a8608053b6f83696d0161cd2bf2 Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java')
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Constants.java1
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java53
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java12
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java24
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java14
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java13
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnContoller.java3
7 files changed, 118 insertions, 2 deletions
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Constants.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Constants.java
index cdf7de869e..1695b39c85 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Constants.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Constants.java
@@ -28,6 +28,7 @@ public class Constants {
public static final String SERVICE_NAME = "vnfm-adapter";
public static final String SERVICE_VERSION = "v1";
public static final String BASE_URL = "/so/" + SERVICE_NAME + "/" + SERVICE_VERSION;
+ public static final String OPERATION_NOTIFICATION_ENDPOINT = "/lcn/VnfLcmOperationOccurrenceNotification";
private Constants() {}
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java
index 3b2b87f661..2e233180bb 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java
@@ -20,6 +20,8 @@
package org.onap.so.adapters.vnfmadapter.extclients.vnfm;
+import static org.onap.so.adapters.vnfmadapter.Constants.BASE_URL;
+import static org.onap.so.adapters.vnfmadapter.Constants.OPERATION_NOTIFICATION_ENDPOINT;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
@@ -33,14 +35,23 @@ import org.onap.so.adapters.vnfmadapter.extclients.vim.model.AccessInfo;
import org.onap.so.adapters.vnfmadapter.extclients.vim.model.InterfaceInfo;
import org.onap.so.adapters.vnfmadapter.extclients.vim.model.VimCredentials;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest;
+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.SubscriptionsAuthentication.AuthTypeEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsAuthenticationParamsBasic;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsFilter;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsFilter.NotificationTypesEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsFilterVnfInstanceSubscriptionFilter;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.VnfInstancesvnfInstanceIdinstantiateExtVirtualLinks;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.VnfInstancesvnfInstanceIdinstantiateVimConnectionInfo;
+import org.onap.so.security.WebSecurityConfig;
import org.onap.vnfmadapter.v1.model.CreateVnfRequest;
import org.onap.vnfmadapter.v1.model.ExternalVirtualLink;
import org.onap.vnfmadapter.v1.model.Tenant;
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.Service;
/**
@@ -52,10 +63,15 @@ public class VnfmHelper {
private static final Logger logger = LoggerFactory.getLogger(VnfmHelper.class);
private static final String SEPARATOR = "_";
private final AaiServiceProvider aaiServiceProvider;
+ private final WebSecurityConfig webSecurityConfig;
+
+ @Value("${vnfmadapter.endpoint}")
+ private String vnfmAdapterEndoint;
@Autowired
- public VnfmHelper(final AaiServiceProvider aaiServiceProvider) {
+ public VnfmHelper(final AaiServiceProvider aaiServiceProvider, final WebSecurityConfig webSecurityConfig) {
this.aaiServiceProvider = aaiServiceProvider;
+ this.webSecurityConfig = webSecurityConfig;
}
/**
@@ -149,4 +165,39 @@ public class VnfmHelper {
return null;
}
+ /**
+ * Create a {@link LccnSubscriptionRequest} to send in an notification subscription request to a
+ * VNFM.
+ *
+ * @param the ID of the VNF notifications are required for
+ *
+ * @return the request
+ */
+ public LccnSubscriptionRequest createNotificationSubscriptionRequest(final String vnfId) {
+ final LccnSubscriptionRequest lccnSubscriptionRequest = new LccnSubscriptionRequest();
+ lccnSubscriptionRequest.setAuthentication(getSubscriptionsAuthentication());
+ lccnSubscriptionRequest.setCallbackUri(vnfmAdapterEndoint + BASE_URL + OPERATION_NOTIFICATION_ENDPOINT);
+ final SubscriptionsFilter filter = new SubscriptionsFilter();
+ filter.addNotificationTypesItem(NotificationTypesEnum.VNFLCMOPERATIONOCCURRENCENOTIFICATION);
+ final SubscriptionsFilterVnfInstanceSubscriptionFilter vnfInstanceSubscriptionFilter =
+ new SubscriptionsFilterVnfInstanceSubscriptionFilter();
+ vnfInstanceSubscriptionFilter.addVnfInstanceIdsItem(vnfId);
+ filter.setVnfInstanceSubscriptionFilter(vnfInstanceSubscriptionFilter);
+ lccnSubscriptionRequest.setFilter(filter);
+ return lccnSubscriptionRequest;
+ }
+
+ private SubscriptionsAuthentication getSubscriptionsAuthentication() {
+ final SubscriptionsAuthenticationParamsBasic basicAuthParams = new SubscriptionsAuthenticationParamsBasic();
+ basicAuthParams.setUserName("vnfm");
+ basicAuthParams.setPassword(webSecurityConfig.getUsercredentials().stream()
+ .filter(userCredentials -> "vnfm".equals(userCredentials.getUsername())).findFirst().get()
+ .getPassword());
+
+ final SubscriptionsAuthentication authentication = new SubscriptionsAuthentication();
+ authentication.addAuthTypeItem(AuthTypeEnum.BASIC);
+ authentication.paramsBasic(basicAuthParams);
+ return authentication;
+ }
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java
index 320715dd33..472a8b8680 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java
@@ -22,8 +22,10 @@ package org.onap.so.adapters.vnfmadapter.extclients.vnfm;
import com.google.common.base.Optional;
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.InstantiateVnfRequest;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.TerminateVnfRequest;
/**
@@ -49,6 +51,16 @@ public interface VnfmServiceProvider {
String instantiateVnf(final String vnfSelfLink, final InstantiateVnfRequest instantiateVnfRequest);
/**
+ * Invoke a notification subscription request to a VNFM.
+ *
+ * @param vnfmId the ID of the VNFM
+ * @param subscriptionRequest
+ * @return the response to the subscription request
+ */
+ InlineResponse2001 subscribeForNotifications(final String vnfmId,
+ final LccnSubscriptionRequest subscriptionRequest);
+
+ /**
* Invoke a terminate request for a VNF.
*
* @param vnfSelfLink the link to he VNF on the VNFM
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java
index 246444fa8c..711069bc15 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java
@@ -22,8 +22,10 @@ package org.onap.so.adapters.vnfmadapter.extclients.vnfm;
import com.google.common.base.Optional;
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.InstantiateVnfRequest;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.TerminateVnfRequest;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmRequestFailureException;
import org.onap.so.rest.service.HttpRestServiceProvider;
@@ -76,7 +78,29 @@ public class VnfmServiceProviderImpl implements VnfmServiceProvider {
}
final String locationHeader = response.getHeaders().get("Location").iterator().next();
return locationHeader.substring(locationHeader.lastIndexOf("/") + 1);
+ }
+
+ @Override
+ public InlineResponse2001 subscribeForNotifications(final String vnfmId,
+ final LccnSubscriptionRequest subscriptionRequest) {
+ final String url = urlProvider.getSubscriptionsUrl(vnfmId);
+ ResponseEntity<InlineResponse2001> response = null;
+ try {
+ response = httpServiceProvider.postHttpRequest(subscriptionRequest, url, InlineResponse2001.class);
+ } catch (final Exception exception) {
+ final String errorMessage =
+ "Subscription to VNFM " + vnfmId + " resulted in exception" + subscriptionRequest;
+ logger.error(errorMessage, exception);
+ throw new VnfmRequestFailureException(errorMessage, exception);
+ }
+ if (response.getStatusCode() != HttpStatus.OK) {
+ final String errorMessage = "Subscription to VNFM " + vnfmId + " returned status code: "
+ + response.getStatusCode() + ", request: " + subscriptionRequest;
+ logger.error(errorMessage);
+ throw new VnfmRequestFailureException(errorMessage);
+ }
+ return response.getBody();
}
@Override
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java
index f0280d6a71..2eaaa8113f 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java
@@ -59,6 +59,20 @@ public class VnfmUrlProvider {
return url;
}
+ /**
+ * Get the URL for the subscriptions on a VNFM.
+ *
+ * @param vnfmId The ID of the VNFM
+ * @return the URL of the subscriptions
+ */
+ public String getSubscriptionsUrl(final String vnfmId) {
+ final String url =
+ UriComponentsBuilder.fromUri(getBaseUri(vnfmId)).pathSegment("/subscriptions").build().toString();
+ logger.debug("getOperationUrl:" + url);
+
+ return url;
+ }
+
private URI getBaseUri(final String vnfmId) {
final EsrSystemInfoList vnfmEsrSystemInfoList = aaiServiceProvider.invokeGetVnfmEsrSystemInfoList(vnfmId);
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java
index 9249b9e620..7f0f9e3b37 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java
@@ -29,6 +29,7 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmHelper;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmServiceProvider;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.TerminateVnfRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.TerminateVnfRequest.TerminationTypeEnum;
import org.onap.so.adapters.vnfmadapter.jobmanagement.JobManager;
@@ -82,6 +83,7 @@ public class LifecycleManager {
}
final String vnfIdInVnfm = sendCreateRequestToVnfm(genericVnf);
+ createNotificationSubscription(vnfm.getVnfmId(), vnfIdInVnfm);
final String operationId = sendInstantiateRequestToVnfm(vnfm, genericVnf, request, vnfIdInAai, vnfIdInVnfm);
final String jobId = jobManager.createJob(vnfm.getVnfmId(), operationId, false);
@@ -111,6 +113,17 @@ public class LifecycleManager {
return "vnfId";
}
+ private void createNotificationSubscription(final String vnfmId, final String vnfId) {
+ try {
+ final LccnSubscriptionRequest subscriptionRequest = vnfmHelper.createNotificationSubscriptionRequest(vnfId);
+ vnfmServiceProvider.subscribeForNotifications(vnfmId, subscriptionRequest);
+ } catch (final Exception exception) {
+ logger.warn("Subscription for notifications to VNFM: " + vnfmId + " for VNF " + vnfId
+ + " failed. AAI will not be updated unless the VNFM is configured by other means to send notifications relating to this VNF",
+ exception);
+ }
+ }
+
private String sendInstantiateRequestToVnfm(final EsrVnfm vnfm, final GenericVnf genericVnf,
final CreateVnfRequest createVnfRequest, final String vnfIdInAai, final String vnfIdInVnfm) {
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnContoller.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnContoller.java
index f0958cbe7d..0441342b79 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnContoller.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnContoller.java
@@ -21,6 +21,7 @@
package org.onap.so.adapters.vnfmadapter.rest;
import static org.onap.so.adapters.vnfmadapter.Constants.BASE_URL;
+import static org.onap.so.adapters.vnfmadapter.Constants.OPERATION_NOTIFICATION_ENDPOINT;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -83,7 +84,7 @@ public class Sol003LcnContoller {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
- @PostMapping(value = "/lcn/VnfLcmOperationOccurrenceNotification")
+ @PostMapping(value = OPERATION_NOTIFICATION_ENDPOINT)
public ResponseEntity<Void> lcnVnfLcmOperationOccurrenceNotificationPost(
@RequestBody final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification) {
logger.info(LOG_LCN_RECEIVED + vnfLcmOperationOccurrenceNotification);