aboutsummaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
authorrope252 <gareth.roper@est.tech>2020-02-07 16:06:41 +0000
committerrope252 <gareth.roper@est.tech>2020-02-10 14:05:07 +0000
commit3341eca5cdef51891157f35320afed58a1aef711 (patch)
tree3fd0f40ea9cc80743db952c561bf7b42150fcc79 /adapters
parent6db24e72ecbf4f5c63085085c10dc656568b563b (diff)
SOL003 Adapter Package Management - Terminate Subscription
Change-Id: I11e73f166bdab1b69b40640394ca9abb304b5be5 Issue-ID: SO-2419 Signed-off-by: rope252 <gareth.roper@est.tech>
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java12
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java32
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/SubscriptionManager.java9
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProvider.java2
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionController.java22
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java36
6 files changed, 104 insertions, 9 deletions
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java
index 62b365745c..e0eed159c2 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java
@@ -23,7 +23,6 @@ package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
import java.util.Optional;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscription;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
-import org.springframework.http.ResponseEntity;
/**
* Provides methods for invoking REST calls to the ETSI Catalog Manager.
@@ -74,11 +73,18 @@ public interface EtsiCatalogServiceProvider {
Optional<byte[]> getVnfPackageArtifact(final String vnfPkgId, final String artifactPath);
/**
- * Post the SubscriptionRequest Object.
+ * POST the SubscriptionRequest Object.
*
- * @return The ResponseEntity containing the ETSI Catalog Manager's PkgmSubscription object.
+ * @return The ETSI Catalog Manager's PkgmSubscription object.
*/
Optional<PkgmSubscription> postSubscription(
final org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest);
+ /**
+ * DELETE the SubscriptionRequest Object.
+ *
+ * @return A Boolean representing if the delete was successful or not.
+ */
+ Boolean deleteSubscription(final String subscriptionId);
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java
index 1a48494e1a..573a798410 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java
@@ -21,11 +21,14 @@
package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
import java.util.Optional;
-import javax.swing.text.html.Option;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscription;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPkgInfo;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
-import org.onap.so.adapters.vnfmadapter.rest.exceptions.*;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerBadRequestException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerRequestFailureException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgBadRequestException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgConflictException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgNotFoundException;
import org.onap.so.rest.exceptions.HttpResouceNotFoundException;
import org.onap.so.rest.exceptions.InvalidRestRequestException;
import org.onap.so.rest.exceptions.RestProcessingException;
@@ -190,7 +193,8 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide
return Optional.empty();
} catch (final InvalidRestRequestException invalidRestRequestException) {
logger.error("Caught InvalidRestRequestException", invalidRestRequestException);
- throw new EtsiCatalogManagerBadRequestException("Bad Request Received on postSubscription call.");
+ throw new EtsiCatalogManagerBadRequestException(
+ "Bad Request Received on postSubscription call to ETSI Catalog Manager.");
} catch (final RestProcessingException restProcessingException) {
logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(),
restProcessingException);
@@ -200,6 +204,28 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide
}
}
+ public Boolean deleteSubscription(final String subscriptionId) {
+ try {
+ final ResponseEntity<Void> responseEntity = httpServiceProvider
+ .deleteHttpRequest(etsiCatalogUrlProvider.getSubscriptionUrl() + "/" + subscriptionId, Void.class);
+
+ if (responseEntity.getStatusCode() == HttpStatus.NO_CONTENT) {
+ logger.info("Subscription with ID: {} has been successfully deleted from the ETSI Catalog Manager",
+ subscriptionId);
+ return true;
+ }
+ logger.error("Unexpected Status Code Received on deleteSubscription: {}", responseEntity.getStatusCode());
+ return false;
+ } catch (final InvalidRestRequestException invalidRestRequestException) {
+ logger.error("Caught InvalidRestRequestException on deleteSubscription call to ETSI Catalog Manager.",
+ invalidRestRequestException);
+ throw new EtsiCatalogManagerBadRequestException(
+ "Bad Request Received on deleteSubscription call to ETSI Catalog Manager.");
+ }
+ }
+
+
+
private Optional<byte[]> requestVnfElement(final String vnfPkgId, final String vnfRequestUrl,
final String vnfRequestName) {
try {
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/SubscriptionManager.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/SubscriptionManager.java
index 30a16f70a8..bbf8b74952 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/SubscriptionManager.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/SubscriptionManager.java
@@ -143,6 +143,15 @@ public class SubscriptionManager {
return response;
}
+ public boolean deleteSubscription(final String subscriptionId) {
+ if (getSubscription(subscriptionId).isPresent()) {
+ if (etsiCatalogServiceProvider.deleteSubscription(subscriptionId)) {
+ return packageManagementCacheServiceProvider.deleteSubscription(subscriptionId);
+ }
+ }
+ return false;
+ }
+
public URI getSubscriptionUri(final String subscriptionId) {
return URI.create(
vnfmAdapterEndpoint + Constants.PACKAGE_MANAGEMENT_BASE_URL + "/subscriptions/" + subscriptionId);
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProvider.java
index 6042513a50..437d20e593 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProvider.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProvider.java
@@ -60,7 +60,7 @@ public interface PackageManagementCacheServiceProvider {
* Delete subscription from cache
*
* @param subscriptionId
- * @return true if subscription exists and able to be removed, otherwise returns false
+ * @return Boolean
*/
boolean deleteSubscription(final String subscriptionId);
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionController.java
index cbad564210..4be0838c08 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionController.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionController.java
@@ -23,14 +23,13 @@ package org.onap.so.adapters.vnfmadapter.rest;
import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL;
import static org.slf4j.LoggerFactory.getLogger;
import java.net.URI;
-import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
import java.util.List;
import java.util.Optional;
import javax.ws.rs.core.MediaType;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2002;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest;
-import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
import org.onap.so.adapters.vnfmadapter.packagemanagement.subscriptionmanagement.SubscriptionManager;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,6 +37,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
+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;
@@ -140,6 +140,24 @@ public class Sol003PackageManagementSubscriptionController {
}
/**
+ * DELETE a specific subscription, by subscriptionId. Section Number: 10.4.8.3.5
+ *
+ * @param subscriptionId The ID of the subscription that you wish to delete.
+ * @return Empty response if successful. Object: Void Response Code: 204 No Content
+ */
+ @DeleteMapping(value = "/subscriptions/{subscriptionId}")
+ public ResponseEntity<?> deleteSubscription(@PathVariable("subscriptionId") final String subscriptionId) {
+ if (subscriptionManager.deleteSubscription(subscriptionId)) {
+ logger.debug("Successfully deleted subscription with id {}", subscriptionId);
+ return ResponseEntity.noContent().build();
+ }
+ final String errorMessage =
+ "The requested subscription: " + subscriptionId + " was not found on call deleteSubscription";
+ logger.error(errorMessage);
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ProblemDetails().detail(errorMessage));
+ }
+
+ /**
* Method to set the Location in the header with the URI parameter
*
* @param subscriptionUri
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java
index f90978e0d5..3d26c33679 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java
@@ -68,6 +68,7 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.http.HttpMethod;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.hamcrest.Matchers.is;
+import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
/**
@@ -199,6 +200,41 @@ public class Sol003PackageManagementSubscriptionControllerTest {
assertEquals(HttpStatus.OK, response.getStatusCode());
}
+ @Test
+ public void testSuccessDeleteSubscriptionWithSubscriptionId() throws GeneralSecurityException {
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest = buildPkgmSubscriptionRequest();
+ final PkgmSubscription pkgmSubscription = buildPkgmSubscription();
+ final String subscriptionId = pkgmSubscription.getId();
+
+ mockRestServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
+ .andRespond(withSuccess(gson.toJson(pkgmSubscription), MediaType.APPLICATION_JSON));
+ mockRestServer.expect(requestTo(msbEndpoint + "/" + subscriptionId)).andExpect(method(HttpMethod.DELETE))
+ .andRespond(withStatus(HttpStatus.NO_CONTENT));
+
+ final ResponseEntity<InlineResponse2002> responsePost =
+ (ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController
+ .postSubscriptionRequest(pkgmSubscriptionRequest);
+
+
+ final ResponseEntity responseDelete =
+ sol003PackageManagementSubscriptionController.deleteSubscription(subscriptionId);
+
+ // Attempt to retrieve the subscription after delete
+ final ResponseEntity<InlineResponse2002> responseGetSubscription =
+ (ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController
+ .getSubscription(subscriptionId);
+
+ assertEquals(HttpStatus.NOT_FOUND, responseGetSubscription.getStatusCode());
+ assertEquals(HttpStatus.NO_CONTENT, responseDelete.getStatusCode());
+ }
+
+ @Test
+ public void testFailDeleteSubscriptionWithInvalidSubscriptionId() throws URISyntaxException, InterruptedException {
+ final ResponseEntity<Void> responseDelete = (ResponseEntity<Void>) sol003PackageManagementSubscriptionController
+ .deleteSubscription("invalidSubscriptionId");
+ assertEquals(HttpStatus.NOT_FOUND, responseDelete.getStatusCode());
+ }
+
private PkgmSubscriptionRequest buildPkgmSubscriptionRequest() {
final PkgmSubscriptionRequest pkgmSubscriptionRequest = new PkgmSubscriptionRequest();
final SubscriptionsFilter sub = buildSubscriptionsFilter();