summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@est.tech>2020-02-18 18:09:40 +0000
committerwaqas.ikram <waqas.ikram@est.tech>2020-02-19 10:29:10 +0000
commit08fdefa42dbfd664abe4675713a9e635e6fa24a2 (patch)
treefc2c5577f89b6173e2253c8f32494cc017d94a90
parenta71813fd697298b9a9bddea6eacc9de5fada2de0 (diff)
Adding sync mechanism
Change-Id: I81dc737c27092d32bac6457ba015f0b093cb1176 Issue-ID: SO-2418 Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java11
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java29
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/SubscriptionManager.java41
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationController.java1
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java2
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java6
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java85
-rw-r--r--common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java12
8 files changed, 152 insertions, 35 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 e0eed159c2..0dcc49eeac 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
@@ -21,6 +21,7 @@
package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
import java.util.Optional;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.NsdmSubscription;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscription;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
@@ -81,10 +82,18 @@ public interface EtsiCatalogServiceProvider {
final org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest);
/**
+ * Get the Subscription from ETSI Catalog.
+ *
+ * @param subscriptionId Subscription ID
+ * @return The Subscription {@link NsdmSubscription} from ETSI Catalog
+ */
+ Optional<NsdmSubscription> getSubscription(final String subscriptionId);
+
+ /**
* DELETE the SubscriptionRequest Object.
*
* @return A Boolean representing if the delete was successful or not.
*/
- Boolean deleteSubscription(final String subscriptionId);
+ 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 73ec7053a7..30d084629c 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,13 @@
package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
import java.util.Optional;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.NsdmSubscription;
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.EtsiCatalogManagerBadRequestException;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerRequestFailureException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.SubscriptionNotFoundException;
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;
@@ -204,7 +206,8 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide
}
}
- public Boolean deleteSubscription(final String subscriptionId) {
+ @Override
+ public boolean deleteSubscription(final String subscriptionId) {
try {
final ResponseEntity<Void> responseEntity = httpServiceProvider
.deleteHttpRequest(etsiCatalogUrlProvider.getSubscriptionUrl() + "/" + subscriptionId, Void.class);
@@ -216,6 +219,10 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide
}
logger.error("Unexpected Status Code Received on deleteSubscription: {}", responseEntity.getStatusCode());
return false;
+ } catch (final HttpResouceNotFoundException resouceNotFoundException) {
+ final String message = "Unable to find subscription in ETSI Catalog Manager using id: " + subscriptionId;
+ logger.error(message);
+ throw new SubscriptionNotFoundException(message);
} catch (final InvalidRestRequestException invalidRestRequestException) {
logger.error("Caught InvalidRestRequestException on deleteSubscription call to ETSI Catalog Manager.",
invalidRestRequestException);
@@ -224,7 +231,27 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide
}
}
+ @Override
+ public Optional<NsdmSubscription> getSubscription(final String subscriptionId) {
+ try {
+ final ResponseEntity<NsdmSubscription> responseEntity = httpServiceProvider.getHttpResponse(
+ etsiCatalogUrlProvider.getSubscriptionUrl() + "/" + subscriptionId, NsdmSubscription.class);
+ if (responseEntity.getStatusCode().is2xxSuccessful()) {
+ logger.debug("Found subscription with ID: {} in ETSI Catalog Manager", subscriptionId);
+ return Optional.ofNullable(responseEntity.getBody());
+ }
+ logger.error("Unexpected Status Code Received on getting subscription from ETSI Catalog Manager: {}",
+ responseEntity.getStatusCode());
+ } catch (final HttpResouceNotFoundException resouceNotFoundException) {
+ logger.error("Unable to find subscription in ETSI Catalog Manager using id: {}", subscriptionId);
+ return Optional.empty();
+ } catch (final RestProcessingException | InvalidRestRequestException exception) {
+ logger.error("Unable to query ETSI Catalog Manager for subscription using id: {}", subscriptionId,
+ exception);
+ }
+ throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.");
+ }
private Optional<byte[]> requestVnfElement(final String vnfPkgId, final String vnfRequestUrl,
final String vnfRequestName) {
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 efe747deae..d02bd9a345 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
@@ -32,6 +32,7 @@ import java.util.Optional;
import org.onap.so.adapters.vnfmadapter.Constants;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.EtsiCatalogServiceProvider;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.BasicAuth;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.NsdmSubscription;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscription;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2002;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest;
@@ -39,6 +40,7 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.VnfPackagesLinksSelf;
import org.onap.so.adapters.vnfmadapter.packagemanagement.subscriptionmanagement.cache.PackageManagementCacheServiceProvider;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.InternalServerErrorException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.SubscriptionNotFoundException;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.SubscriptionRequestConversionException;
import org.onap.so.utils.CryptoUtils;
import org.slf4j.Logger;
@@ -90,7 +92,7 @@ public class SubscriptionManager {
etsiCatalogServiceProvider.postSubscription(etsiCatalogManagerSubscriptionRequest);
if (optionalEtsiCatalogManagerSubscription.isPresent()) {
- PkgmSubscription etsiCatalogManagerSubscription = optionalEtsiCatalogManagerSubscription.get();
+ final PkgmSubscription etsiCatalogManagerSubscription = optionalEtsiCatalogManagerSubscription.get();
logger.debug("postPkgmSubscriptionRequest Response SubscriptionId: {}",
Objects.requireNonNull(etsiCatalogManagerSubscription.getId()));
final String subscriptionId = etsiCatalogManagerSubscription.getId();
@@ -116,6 +118,19 @@ public class SubscriptionManager {
}
public Optional<InlineResponse2002> getSubscription(final String subscriptionId) {
+
+ logger.debug("Checking if subscrition with id: {} exists in ETSI Catalog Manager", subscriptionId);
+ final Optional<NsdmSubscription> etsiCatalogSubscriptionOption =
+ etsiCatalogServiceProvider.getSubscription(subscriptionId);
+
+ if (!etsiCatalogSubscriptionOption.isPresent()) {
+ logger.debug("Unable to find subscription in ETSI Catalog Manager using id: {}", subscriptionId);
+ if (packageManagementCacheServiceProvider.getSubscription(subscriptionId).isPresent()) {
+ logger.debug("will remove subcription with id: {} from local cache", subscriptionId);
+ packageManagementCacheServiceProvider.deleteSubscription(subscriptionId);
+ }
+ }
+
final Optional<PkgmSubscriptionRequest> optional =
packageManagementCacheServiceProvider.getSubscription(subscriptionId);
if (optional.isPresent()) {
@@ -129,13 +144,25 @@ public class SubscriptionManager {
final Map<String, PkgmSubscriptionRequest> subscriptions =
packageManagementCacheServiceProvider.getSubscriptions();
final List<InlineResponse2002> response = new ArrayList<>();
- subscriptions.forEach((key, value) -> response.add(getInlineResponse2002(key, value)));
+ subscriptions.forEach((key, value) -> {
+ final Optional<InlineResponse2002> optional = getSubscription(key);
+ if (optional.isPresent()) {
+ response.add(optional.get());
+ }
+ });
return response;
}
public boolean deleteSubscription(final String subscriptionId) {
- if (getSubscription(subscriptionId).isPresent()) {
- if (etsiCatalogServiceProvider.deleteSubscription(subscriptionId)) {
+ if (packageManagementCacheServiceProvider.getSubscription(subscriptionId).isPresent()) {
+ try {
+ if (etsiCatalogServiceProvider.deleteSubscription(subscriptionId)) {
+ return packageManagementCacheServiceProvider.deleteSubscription(subscriptionId);
+ }
+ } catch (final SubscriptionNotFoundException subscriptionNotFoundException) {
+ logger.error(
+ "Unable to find subscription in ETSI Catalog Manager using id: {} will delete it from local cache",
+ subscriptionId);
return packageManagementCacheServiceProvider.deleteSubscription(subscriptionId);
}
}
@@ -153,17 +180,17 @@ public class SubscriptionManager {
}
private org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest buildEtsiCatalogManagerPkgmSubscriptionRequest(
- PkgmSubscriptionRequest pkgmSubscriptionRequest) throws GeneralSecurityException {
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest) throws GeneralSecurityException {
final org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest;
try {
etsiCatalogManagerSubscriptionRequest = conversionService.convert(pkgmSubscriptionRequest,
org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest.class);
- } catch (ConversionException conversionException) {
+ } catch (final ConversionException conversionException) {
logger.error(conversionException.getMessage());
throw new SubscriptionRequestConversionException(
"Could not convert Sol003 PkgmSubscriptionRequest to ETSI-Catalog Manager PkgmSubscriptionRequest");
- } catch (Exception exception) {
+ } catch (final Exception exception) {
logger.error(exception.getMessage());
throw new InternalServerErrorException(
"Could not convert Sol003 PkgmSubscriptionRequest to ETSI-Catalog Manager PkgmSubscriptionRequest");
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationController.java
index b4004b083d..a2f44f9deb 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationController.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationController.java
@@ -22,7 +22,6 @@ package org.onap.so.adapters.vnfmadapter.rest;
import static org.onap.so.adapters.vnfmadapter.Constants.ETSI_SUBSCRIPTION_NOTIFICATION_CONTROLLER_BASE_URL;
import static org.slf4j.LoggerFactory.getLogger;
-import javax.ws.rs.core.MediaType;
import org.slf4j.Logger;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java
index 3ead98fce2..21b20b0134 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java
@@ -50,8 +50,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping(value = BASE_URL, produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
public class Sol003GrantController {
- private static final String SEPARATOR = "_";
- private static final String VIM_TYPE = "OPENSTACK";
private static final Logger logger = LoggerFactory.getLogger(Sol003GrantController.class);
public final AaiServiceProvider aaiServiceProvider;
public final AaiHelper aaiHelper;
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java
index cce7241757..f1d20c65ef 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java
@@ -109,19 +109,19 @@ public class Sol003PackageManagementController {
*/
@GetMapping(value = "/vnf_packages/{vnfPkgId}/vnfd",
produces = {MediaType.TEXT_PLAIN, APPLICATION_ZIP, MediaType.APPLICATION_JSON})
- public ResponseEntity<byte[]> getVnfPackageVnfd(@PathVariable("vnfPkgId") final String vnfPkgId) {
+ public ResponseEntity<?> getVnfPackageVnfd(@PathVariable("vnfPkgId") final String vnfPkgId) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageVnfd Endpoint Invoked with VNF Package ID: ", vnfPkgId);
final Optional<byte[]> response = etsiCatalogServiceProvider.getVnfPackageVnfd(vnfPkgId);
if (response.isPresent()) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageVnfd Response: ", HttpStatus.OK);
- return new ResponseEntity(response.get(), HttpStatus.OK);
+ return new ResponseEntity<>(response.get(), HttpStatus.OK);
}
final String errorMessage = "An error occurred, a null response was received by the\n"
+ " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnfd\" \n"
+ "endpoint.";
logger.error(errorMessage);
- return new ResponseEntity(new ProblemDetails().detail(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(new ProblemDetails().detail(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR);
}
/**
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 c776e55ff0..ba1bf71936 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
@@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL;
import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
@@ -31,7 +32,6 @@ import static org.springframework.test.web.client.match.MockRestRequestMatchers.
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
-import com.google.gson.Gson;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
@@ -45,6 +45,7 @@ import org.junit.runner.RunWith;
import org.onap.so.adapters.vnfmadapter.Constants;
import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.LinkSelf;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.NsdmSubscription;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscription;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2002;
@@ -69,6 +70,7 @@ 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 com.google.gson.Gson;
/**
* @author Ronan Kenny (ronan.kenny@est.tech)
@@ -83,16 +85,18 @@ public class Sol003PackageManagementSubscriptionControllerTest {
private final URI msbEndpoint = URI.create("http://msb-iag.onap:80/api/vnfpkgm/v1/subscriptions");
@Autowired
@Qualifier(CONFIGURABLE_REST_TEMPLATE)
- private RestTemplate testRestTemplate;
- private MockRestServiceServer mockRestServer;
+ private RestTemplate restTemplate;
+ private MockRestServiceServer mockRestServiceServer;
@Autowired
private CacheManager cacheServiceProvider;
@Autowired
private Sol003PackageManagementSubscriptionController sol003PackageManagementSubscriptionController;
+ private static final String ID = UUID.randomUUID().toString();
+
@Before
public void setUp() {
- mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build();
+ mockRestServiceServer = MockRestServiceServer.bindTo(restTemplate).build();
final Cache cache = cacheServiceProvider.getCache(Constants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE);
cache.clear();
}
@@ -106,8 +110,8 @@ public class Sol003PackageManagementSubscriptionControllerTest {
final HttpHeaders headers = buildHttpHeaders(Objects.requireNonNull(response.getBody()).getCallbackUri());
- SubscriptionsLinks subscriptionsLinks = new SubscriptionsLinks();
- VnfPackagesLinksSelf vnfPackagesLinksSelf = new VnfPackagesLinksSelf();
+ final SubscriptionsLinks subscriptionsLinks = new SubscriptionsLinks();
+ final VnfPackagesLinksSelf vnfPackagesLinksSelf = new VnfPackagesLinksSelf();
vnfPackagesLinksSelf.setHref("https://so-vnfm-adapter.onap:30406" + PACKAGE_MANAGEMENT_BASE_URL
+ "/subscriptions/" + response.getBody().getId());
subscriptionsLinks.setSelf(vnfPackagesLinksSelf);
@@ -140,13 +144,19 @@ public class Sol003PackageManagementSubscriptionControllerTest {
@Test
public void testSuccessGetSubscriptionWithSubscriptionId() throws GeneralSecurityException, URISyntaxException {
+
final PkgmSubscriptionRequest pkgmSubscriptionRequest = postSubscriptionForTest();
+ mockRestServiceServer.expect(requestTo(msbEndpoint + "/" + ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(gson.toJson(new NsdmSubscription().id(ID)), MediaType.APPLICATION_JSON));
+
final ResponseEntity<InlineResponse2002> response =
(ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController
.postSubscriptionRequest(pkgmSubscriptionRequest);
final String subscriptionId = response.getBody().getId();
+
+
final ResponseEntity<InlineResponse2002> response2002 =
(ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController
.getSubscription(subscriptionId);
@@ -163,9 +173,12 @@ public class Sol003PackageManagementSubscriptionControllerTest {
@Test
public void testFailGetSubscriptionWithInvalidSubscriptionId() {
+ final String invalidId = "invalidSubscriptionId";
+ mockRestServiceServer.expect(requestTo(msbEndpoint + "/" + invalidId)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.NOT_FOUND));
final ResponseEntity<InlineResponse2002> response =
(ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController
- .getSubscription("invalidSubscriptionId");
+ .getSubscription(invalidId);
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
}
@@ -174,14 +187,16 @@ public class Sol003PackageManagementSubscriptionControllerTest {
final PkgmSubscription pkgmSubscription = buildPkgmSubscription();
final PkgmSubscriptionRequest pkgmSubscriptionRequest = buildPkgmSubscriptionRequest();
- mockRestServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
+ mockRestServiceServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
.andRespond(withSuccess(gson.toJson(pkgmSubscription), MediaType.APPLICATION_JSON));
+ mockRestServiceServer.expect(requestTo(msbEndpoint + "/" + ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(gson.toJson(new NsdmSubscription().id(ID)), MediaType.APPLICATION_JSON));
sol003PackageManagementSubscriptionController.postSubscriptionRequest(pkgmSubscriptionRequest);
- ResponseEntity<List<InlineResponse2002>> response =
+ final ResponseEntity<List<InlineResponse2002>> response =
sol003PackageManagementSubscriptionController.getSubscriptions();
- List<InlineResponse2002> subscriptionsList = response.getBody();
+ final List<InlineResponse2002> subscriptionsList = response.getBody();
assertEquals(Objects.requireNonNull(response.getBody()).get(0).getFilter(),
pkgmSubscriptionRequest.getFilter());
@@ -196,10 +211,14 @@ public class Sol003PackageManagementSubscriptionControllerTest {
final PkgmSubscription pkgmSubscription = buildPkgmSubscription();
final String subscriptionId = pkgmSubscription.getId();
- mockRestServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
+ mockRestServiceServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
.andRespond(withSuccess(gson.toJson(pkgmSubscription), MediaType.APPLICATION_JSON));
- mockRestServer.expect(requestTo(msbEndpoint + "/" + subscriptionId)).andExpect(method(HttpMethod.DELETE))
+
+ mockRestServiceServer.expect(requestTo(msbEndpoint + "/" + subscriptionId)).andExpect(method(HttpMethod.DELETE))
.andRespond(withStatus(HttpStatus.NO_CONTENT));
+ mockRestServiceServer.expect(requestTo(msbEndpoint + "/" + subscriptionId)).andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(gson.toJson(new NsdmSubscription().id(subscriptionId)),
+ MediaType.APPLICATION_JSON));
final ResponseEntity<InlineResponse2002> responsePost =
(ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController
@@ -218,6 +237,32 @@ public class Sol003PackageManagementSubscriptionControllerTest {
}
@Test
+ public void testDeleteSubscription_SubscripitonNotFoundInEtsiCatalogManager_SubscriptionDeletedFromLocalCache()
+ throws GeneralSecurityException {
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest = buildPkgmSubscriptionRequest();
+ final PkgmSubscription pkgmSubscription = buildPkgmSubscription();
+
+ mockRestServiceServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
+ .andRespond(withSuccess(gson.toJson(pkgmSubscription), MediaType.APPLICATION_JSON));
+
+ mockRestServiceServer.expect(requestTo(msbEndpoint + "/" + ID)).andExpect(method(HttpMethod.DELETE))
+ .andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<InlineResponse2002> responsePost =
+ (ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController
+ .postSubscriptionRequest(pkgmSubscriptionRequest);
+
+ final Cache cache = cacheServiceProvider.getCache(Constants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE);
+ assertNotNull(cache.get(ID));
+
+ final ResponseEntity responseDelete = sol003PackageManagementSubscriptionController.deleteSubscription(ID);
+
+ assertEquals(HttpStatus.NO_CONTENT, responseDelete.getStatusCode());
+ assertNull(cache.get(ID));
+
+ }
+
+ @Test
public void testFailDeleteSubscriptionWithInvalidSubscriptionId() throws URISyntaxException, InterruptedException {
final ResponseEntity<Void> responseDelete = (ResponseEntity<Void>) sol003PackageManagementSubscriptionController
.deleteSubscription("invalidSubscriptionId");
@@ -252,11 +297,11 @@ public class Sol003PackageManagementSubscriptionControllerTest {
}
private PkgmSubscription buildPkgmSubscription() {
- PkgmSubscription pkgmSubscription = new PkgmSubscription();
- PkgmNotificationsFilter pkgmNotificationsFilter = new PkgmNotificationsFilter();
- LinkSelf linkSelf = new LinkSelf();
- String id = UUID.randomUUID().toString();
- pkgmSubscription.setId(id);
+ final PkgmSubscription pkgmSubscription = new PkgmSubscription();
+ final PkgmNotificationsFilter pkgmNotificationsFilter = new PkgmNotificationsFilter();
+ final LinkSelf linkSelf = new LinkSelf();
+
+ pkgmSubscription.setId(ID);
pkgmSubscription.setCallbackUri(msbEndpoint + "/" + pkgmSubscription.getId().toString());
pkgmSubscription.setFilter(pkgmNotificationsFilter);
pkgmSubscription.setLinks(linkSelf);
@@ -267,14 +312,14 @@ public class Sol003PackageManagementSubscriptionControllerTest {
final PkgmSubscriptionRequest pkgmSubscriptionRequest = buildPkgmSubscriptionRequest();
final PkgmSubscription pkgmSubscription = buildPkgmSubscription();
- mockRestServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
+ mockRestServiceServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
.andRespond(withSuccess(gson.toJson(pkgmSubscription), MediaType.APPLICATION_JSON));
return pkgmSubscriptionRequest;
}
- private HttpHeaders buildHttpHeaders(String uri) throws URISyntaxException {
+ private HttpHeaders buildHttpHeaders(final String uri) throws URISyntaxException {
final HttpHeaders headers = new HttpHeaders();
- URI myUri = new URI(uri);
+ final URI myUri = new URI(uri);
headers.setLocation(myUri);
return headers;
}
diff --git a/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java b/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java
index b82d73bbbf..6211b76561 100644
--- a/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java
+++ b/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java
@@ -143,6 +143,18 @@ public class HttpRestServiceProviderImpl implements HttpRestServiceProvider {
final HttpEntity<?> request = new HttpEntity<>(getHttpHeaders());
return restTemplate.exchange(url, HttpMethod.DELETE, request, clazz);
+ } catch (final HttpStatusCodeException httpStatusCodeException) {
+ final String message = "Unable to invoke HTTP " + HttpMethod.DELETE + " using url: " + url + ", Response: "
+ + httpStatusCodeException.getRawStatusCode();
+ LOGGER.error(message, httpStatusCodeException);
+ final int rawStatusCode = httpStatusCodeException.getRawStatusCode();
+ if (rawStatusCode == HttpStatus.BAD_REQUEST.value()) {
+ throw new InvalidRestRequestException("No result found for given url: " + url);
+ } else if (rawStatusCode == HttpStatus.NOT_FOUND.value()) {
+ throw new HttpResouceNotFoundException("No result found for given url: " + url);
+ }
+ throw new RestProcessingException("Unable to invoke HTTP " + HttpMethod.DELETE + " using URL: " + url,
+ httpStatusCodeException, rawStatusCode);
} catch (final RestClientException restClientException) {
LOGGER.error("Unable to invoke HTTP DELETE using url: " + url, restClientException);
throw new InvalidRestRequestException("Unable to invoke HTTP DELETE using URL: " + url,