diff options
author | rope252 <gareth.roper@est.tech> | 2020-01-21 11:49:16 +0000 |
---|---|---|
committer | rope252 <gareth.roper@est.tech> | 2020-02-05 23:48:29 +0000 |
commit | c8af80f639d91024468c9d0fc1e4f2f0437f8608 (patch) | |
tree | bd510a2004c76e1e24b8db0ae91cb6c6e845c30e /adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main | |
parent | e9c0b88ed9b0e9a538ee87f25f3ea4c99f853702 (diff) |
ETSI Package Management - Subscribe
Change-Id: I6a01f97a5ec441fb72b3d506d5d7355e4d868e11
Issue-ID: SO-2417
Signed-off-by: rope252 <gareth.roper@est.tech>
Diffstat (limited to 'adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main')
24 files changed, 1204 insertions, 140 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 40be4411c8..fb32fb9605 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 @@ -21,7 +21,10 @@ package org.onap.so.adapters.vnfmadapter; /** - * Adapter constants + * VNFM Adapter constants + * + * @author Ronan Kenny (ronan.kenny@est.tech) + * @author Gareth Roper (gareth.roper@est.tech) */ public class Constants { @@ -29,8 +32,15 @@ public class Constants { public static final String SERVICE_VERSION = "v1"; public static final String BASE_URL = "/so/" + SERVICE_NAME + "/" + SERVICE_VERSION; public static final String PACKAGE_MANAGEMENT_BASE_URL = BASE_URL + "/vnfpkgm/v1"; + public static final String ETSI_SUBSCRIPTION_NOTIFICATION_BASE_URL = BASE_URL + "/etsicatalogmanager/notification"; + public static final String ETSI_SUBSCRIPTION_NOTIFICATION_CONTROLLER_BASE_URL = BASE_URL + "/etsicatalogmanager"; public static final String APPLICATION_ZIP = "application/zip"; public static final String OPERATION_NOTIFICATION_ENDPOINT = "/lcn/VnfLcmOperationOccurrenceNotification"; + /** + * Name of the subscription cache + */ + public static final String PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE = "PackageManagementSubscriptionCache"; + private Constants() {} } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java index 84282e0c7f..61d5adf9d8 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java @@ -23,7 +23,8 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.util.ArrayList; import java.util.Collection; -import org.onap.so.adapters.vnfmadapter.converters.Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter; +import org.onap.so.adapters.vnfmadapter.converters.etsicatalog.sol003.VnfPkgInfoConverter; +import org.onap.so.adapters.vnfmadapter.converters.sol003.etsicatalog.PkgmSubscriptionRequestConverter; import org.onap.so.adapters.vnfmadapter.oauth.OAuth2AccessTokenAdapter; import org.springframework.boot.autoconfigure.http.HttpMessageConverters; import org.springframework.context.annotation.Bean; @@ -43,7 +44,8 @@ public class MessageConverterConfiguration { @Bean public ConversionService conversionService() { final DefaultConversionService service = new DefaultConversionService(); - service.addConverter(new Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter()); + service.addConverter(new VnfPkgInfoConverter()); + service.addConverter(new PkgmSubscriptionRequestConverter()); return service; } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java index 62d2f7e2a9..405bf896ef 100755 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java @@ -27,6 +27,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; +import org.springframework.cache.annotation.EnableCaching; /** * The spring boot application for the VNFM (Virtual Network Function Manager) Adapter. @@ -37,6 +38,7 @@ import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; * @see <a href= "https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/003/02.05.01_60/gs_nfv-sol003v020501p.pdf">ETSI * SOL003 v2.5.1</a> */ +@EnableCaching @SpringBootApplication(scanBasePackages = {"org.onap.so"}) @EnableAutoConfiguration(exclude = {JacksonAutoConfiguration.class}) public class VnfmAdapterApplication { diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmBasicWebSecurityConfigurerAdapter.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmBasicWebSecurityConfigurerAdapter.java index 4f3bbe6c5b..a5404607b4 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmBasicWebSecurityConfigurerAdapter.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmBasicWebSecurityConfigurerAdapter.java @@ -23,14 +23,16 @@ package org.onap.so.adapters.vnfmadapter; import org.onap.so.security.SoBasicWebSecurityConfigurerAdapter; +import org.onap.so.security.SoUserCredentialConfiguration; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; - /** * @author Waqas Ikram (waqas.ikram@est.tech) + * @author Gareth Roper (gareth.roper@est.tech) * */ @EnableWebSecurity @@ -39,6 +41,7 @@ public class VnfmBasicWebSecurityConfigurerAdapter extends SoBasicWebSecurityCon @Value("${server.ssl.client-auth:none}") private String clientAuth; + SoUserCredentialConfiguration soUserCredentialConfiguration; @Override protected void configure(final HttpSecurity http) throws Exception { @@ -46,8 +49,8 @@ public class VnfmBasicWebSecurityConfigurerAdapter extends SoBasicWebSecurityCon http.csrf().disable().authorizeRequests().anyRequest().permitAll(); } else { super.configure(http); + http.authorizeRequests().antMatchers(HttpMethod.GET, "/etsi/subscription/notification").permitAll(); } } - } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/VnfPkgInfoConverter.java index de18ecc43e..160b875374 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/VnfPkgInfoConverter.java @@ -18,28 +18,36 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.vnfmadapter.converters; +package org.onap.so.adapters.vnfmadapter.converters.etsicatalog.sol003; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.*; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.*; +import java.util.ArrayList; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.convert.converter.Converter; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.List; +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.extclients.vnfm.packagemanagement.model.VnfPackagesChecksum; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.VnfPackagesSoftwareImages; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPackageSoftwareImageInfo; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.VnfPackagesAdditionalArtifacts; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPackageArtifactInfo; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.VnfPackagesLinks; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.VnfPackagesLinksSelf; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VNFPKGMLinkSerializer; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.Checksum; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.UriLink; /** - * Converter to convert from an Etsi Catalog Model {@link VnfPkgInfo} Object to a PackageManagement Model + * Converter to convert from an Etsi Catalog Manager {@link VnfPkgInfo} Object to its equivalent SOL003 Object * {@link InlineResponse2001} Object * * @author andrew.a.lamb@est.tech */ @Service -public class Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter - implements Converter<VnfPkgInfo, InlineResponse2001> { - private static final Logger logger = - LoggerFactory.getLogger(Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.class); +public class VnfPkgInfoConverter implements Converter<VnfPkgInfo, InlineResponse2001> { + private static final Logger logger = LoggerFactory.getLogger(VnfPkgInfoConverter.class); /** * Convert a {@link VnfPkgInfo} Object to an {@link InlineResponse2001} Object diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/sol003/etsicatalog/PkgmSubscriptionRequestConverter.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/sol003/etsicatalog/PkgmSubscriptionRequestConverter.java new file mode 100644 index 0000000000..c6d51c99aa --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/sol003/etsicatalog/PkgmSubscriptionRequestConverter.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.vnfmadapter.converters.sol003.etsicatalog; + +import static org.slf4j.LoggerFactory.getLogger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import javax.swing.text.html.Option; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.Version; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfProducts; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfProductsProviders; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter.NotificationTypesEnum; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter.OperationalStateEnum; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilterVersions; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilterVnfProducts; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilterVnfProductsFromProviders; +import org.slf4j.Logger; +import org.springframework.core.convert.converter.Converter; +import org.springframework.stereotype.Service; + +/** + * Converter to convert from an Etsi Catalog Manager {@link PkgmSubscriptionRequest} Object to its equivalent ETSI + * Catalog Manager Object + * + * @author Ronan Kenny (ronan.kenny@est.tech) + * @author Gareth Roper (gareth.roper@est.tech) + * + */ +@Service +public class PkgmSubscriptionRequestConverter implements + Converter<PkgmSubscriptionRequest, org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest> { + + private static final Logger logger = getLogger(PkgmSubscriptionRequestConverter.class); + + @Override + public org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest convert( + PkgmSubscriptionRequest pkgmSubscriptionRequest) { + final org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest = + new org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest(); + + etsiCatalogManagerSubscriptionRequest + .setFilters(getPkgmNotificationsFilter(pkgmSubscriptionRequest.getFilter())); + + return etsiCatalogManagerSubscriptionRequest; + } + + + private org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter getPkgmNotificationsFilter( + final SubscriptionsFilter sol003SubscriptionsFilter) { + final org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter etsiCatalogManagerFilters = + new org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter(); + + if (sol003SubscriptionsFilter.getNotificationTypes() != null) { + etsiCatalogManagerFilters.setNotificationTypes( + getPkgmNotificationsFilterNotificationTypes(sol003SubscriptionsFilter.getNotificationTypes())); + } + + etsiCatalogManagerFilters.setVnfProductsFromProviders( + getVnfProductsProviders(sol003SubscriptionsFilter.getVnfProductsFromProviders())); + + etsiCatalogManagerFilters.setVnfdId(getVnfdIds(sol003SubscriptionsFilter.getVnfdId())); + + etsiCatalogManagerFilters.setVnfPkgId(getVnfPkgIds(sol003SubscriptionsFilter.getVnfPkgId())); + + etsiCatalogManagerFilters + .setOperationalState(getOperationalState(sol003SubscriptionsFilter.getOperationalState())); + + etsiCatalogManagerFilters.setUsageState(null); + + return etsiCatalogManagerFilters; + } + + // TODO 'operationalState' in the Sol003 Swagger is type 'OperationalStateEnum'. The ETSI Catalog Manager Swagger + // 'operationalState' is type 'List<OperationalStateEnum>'. This method needs to be updated once swagger is updated. + private List<org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter.OperationalStateEnum> getOperationalState( + final OperationalStateEnum operationalState) { + if (operationalState != null) { + return Arrays.asList( + org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter.OperationalStateEnum + .fromValue(operationalState.getValue())); + } + return Collections.emptyList(); + } + + private List<String> getVnfPkgIds(final List<String> vnfPkgId) { + if (vnfPkgId != null) { + final List<String> etsiCatalogManagerVnfPkgId = new ArrayList<>(); + vnfPkgId.forEach(type -> { + etsiCatalogManagerVnfPkgId.add(type); + }); + } + return Collections.emptyList(); + } + + private List<String> getVnfdIds(final List<String> vnfdId) { + if (vnfdId != null) { + final List<String> etsiCatalogManagerVnfdId = new ArrayList<>(); + vnfdId.forEach(type -> { + etsiCatalogManagerVnfdId.add(type); + }); + } + return Collections.emptyList(); + } + + private List<VnfProductsProviders> getVnfProductsProviders( + final List<SubscriptionsFilterVnfProductsFromProviders> filterProductsFromProvider) { + + if (filterProductsFromProvider != null && !filterProductsFromProvider.isEmpty()) { + final List<VnfProductsProviders> etsiCatalogManagerVnfProductsProviders = new ArrayList<>(); + filterProductsFromProvider.forEach(vnfProduct -> { + etsiCatalogManagerVnfProductsProviders + .add(new VnfProductsProviders().vnfProducts(getVnfProducts(vnfProduct.getVnfProducts()))); + }); + return etsiCatalogManagerVnfProductsProviders; + } + return Collections.emptyList(); + } + + private List<VnfProducts> getVnfProducts(final List<SubscriptionsFilterVnfProducts> sol003VnfProducts) { + if (sol003VnfProducts != null) { + final List<VnfProducts> etsiCatalogManagerVnfProductsList = new ArrayList<>(); + sol003VnfProducts.forEach(vnfProduct -> { + etsiCatalogManagerVnfProductsList.add(new VnfProducts().vnfProductName(vnfProduct.getVnfProductName()) + .versions(getVersion(vnfProduct.getVersions()))); + }); + return etsiCatalogManagerVnfProductsList; + } + return Collections.emptyList(); + } + + private List<Version> getVersion(final List<SubscriptionsFilterVersions> sol003FilterVersions) { + if (sol003FilterVersions != null && !sol003FilterVersions.isEmpty()) { + List<Version> etsiCatalogVersionList = new ArrayList<>(); + sol003FilterVersions.forEach(vnfFilterVersion -> { + etsiCatalogVersionList.add(new Version().vnfSoftwareVersion(vnfFilterVersion.getVnfSoftwareVersion()) + .vnfdVersions(vnfFilterVersion.getVnfdVersions())); + }); + return etsiCatalogVersionList; + } + return Collections.emptyList(); + } + + private List<org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter.NotificationTypesEnum> getPkgmNotificationsFilterNotificationTypes( + final List<NotificationTypesEnum> notificationTypes) { + + if (notificationTypes != null && !notificationTypes.isEmpty()) { + final List<org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter.NotificationTypesEnum> etsiCatalogManagerNotificationTypes = + new ArrayList<>(); + notificationTypes.forEach(type -> etsiCatalogManagerNotificationTypes.add( + org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter.NotificationTypesEnum + .fromValue(type.getValue()))); + } + return Collections.emptyList(); + } + + +} 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 34fc2645a2..62b365745c 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,7 +21,9 @@ 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. @@ -71,4 +73,12 @@ public interface EtsiCatalogServiceProvider { */ Optional<byte[]> getVnfPackageArtifact(final String vnfPkgId, final String artifactPath); + /** + * Post the SubscriptionRequest Object. + * + * @return The ResponseEntity containing the ETSI Catalog Manager's PkgmSubscription object. + */ + Optional<PkgmSubscription> postSubscription( + final org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest); + } 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 779cb2a7a6..1a48494e1a 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,6 +21,8 @@ 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.*; @@ -102,6 +104,7 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide if (response.getStatusCode() == HttpStatus.OK) { if (response.hasBody()) { final VnfPkgInfo[] vnfPackages = response.getBody(); + assert (vnfPackages != null); final InlineResponse2001[] responses = new InlineResponse2001[vnfPackages.length]; for (int index = 0; index < vnfPackages.length; index++) { if (conversionService.canConvert(vnfPackages[index].getClass(), InlineResponse2001.class)) { @@ -113,7 +116,7 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide } logger.error("Unable to find Converter for response class: {}", vnfPackages[index].getClass()); } - return Optional.ofNullable(responses); + return Optional.of(responses); } logger.error("Received response without body ..."); } @@ -170,6 +173,33 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide return requestVnfElement(vnfPkgId, vnfRequestUrl, vnfRequestName); } + @Override + public Optional<PkgmSubscription> postSubscription( + final org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest) { + try { + final ResponseEntity<PkgmSubscription> responseEntity = + httpServiceProvider.postHttpRequest(etsiCatalogManagerSubscriptionRequest, + etsiCatalogUrlProvider.getSubscriptionUrl(), PkgmSubscription.class); + if (responseEntity.getStatusCode() == HttpStatus.OK) { + if (responseEntity.hasBody()) { + return Optional.of(responseEntity.getBody()); + } + logger.error("Received response without body on postSubscription"); + } + logger.error("Unexpected Status Code Received on postSubscription: {}", responseEntity.getStatusCode()); + return Optional.empty(); + } catch (final InvalidRestRequestException invalidRestRequestException) { + logger.error("Caught InvalidRestRequestException", invalidRestRequestException); + throw new EtsiCatalogManagerBadRequestException("Bad Request Received on postSubscription call."); + } catch (final RestProcessingException restProcessingException) { + logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(), + restProcessingException); + throw new EtsiCatalogManagerRequestFailureException( + "Internal Server Error Occurred. On postSubscription with StatusCode: " + + restProcessingException.getStatusCode()); + } + } + 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/extclients/etsicatalog/EtsiCatalogUrlProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java index 8382212d51..3b4c4c3066 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java @@ -99,4 +99,15 @@ public class EtsiCatalogUrlProvider { logger.info("getEtsiCatalogVnfPackageVnfd: {}", url); return url; } + + /** + * Get the URL for posting/retrieving a Subscription + * + * @return the URL for the operation + */ + public String getSubscriptionUrl() { + final String url = etsiCatalogManagerEndpoint + "/subscriptions"; + logger.info("getSubscriptionNotificationUrl: {}", url); + return url; + } } 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 new file mode 100644 index 0000000000..30a16f70a8 --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/SubscriptionManager.java @@ -0,0 +1,196 @@ +/*- + * ============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.adapters.vnfmadapter.packagemanagement.subscriptionmanagement; + +import static org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.SubscriptionAuthentication.AuthTypeEnum.BASIC; +import static org.slf4j.LoggerFactory.getLogger; +import java.net.URI; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +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.EtsiCatalogUrlProvider; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.BasicAuth; +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; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsLinks; +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.SubscriptionRequestConversionException; +import org.onap.so.rest.service.HttpRestServiceProvider; +import org.onap.so.utils.CryptoUtils; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.convert.ConversionException; +import org.springframework.core.convert.ConversionService; +import org.springframework.stereotype.Service; + +/** + * Manages package management subscriptions from the VNFMs + * + * @author Ronan Kenny (ronan.kenny@est.tech) + * @author Gareth Roper (gareth.roper@est.tech) + * + */ +@Service +public class SubscriptionManager { + + private static final Logger logger = getLogger(SubscriptionManager.class); + private final PackageManagementCacheServiceProvider packageManagementCacheServiceProvider; + private final EtsiCatalogUrlProvider etsiCatalogUrlProvider; + private final HttpRestServiceProvider httpServiceProvider; + private final ConversionService conversionService; + private final EtsiCatalogServiceProvider etsiCatalogServiceProvider; + private final String vnfmAdapterEndpoint; + private final String msoKeyString; + private final String vnfmAdapterAuth; + + + @Autowired + public SubscriptionManager(final PackageManagementCacheServiceProvider packageManagementCacheServiceProvider, + final ConversionService conversionService, final HttpRestServiceProvider httpServiceProvider, + final EtsiCatalogUrlProvider etsiCatalogUrlProvider, + final EtsiCatalogServiceProvider etsiCatalogServiceProvider, + @Value("${vnfmadapter.endpoint}") final String vnfmAdapterEndpoint, + @Value("${mso.key}") final String msoKeyString, + @Value("${vnfmadapter.auth:D6CFE56451508B75536C5E8A1E7AE06D0346006A693BF29293A6E1C762EFD59C671911DB6E9294E4FE15E4C1C5524B}") final String vnfmAdapterAuth) { + this.packageManagementCacheServiceProvider = packageManagementCacheServiceProvider; + this.etsiCatalogUrlProvider = etsiCatalogUrlProvider; + this.conversionService = conversionService; + this.httpServiceProvider = httpServiceProvider; + this.etsiCatalogServiceProvider = etsiCatalogServiceProvider; + this.vnfmAdapterEndpoint = vnfmAdapterEndpoint; + this.vnfmAdapterAuth = vnfmAdapterAuth; + this.msoKeyString = msoKeyString; + } + + public Optional<InlineResponse2002> createSubscription(final PkgmSubscriptionRequest pkgmSubscriptionRequest) + throws GeneralSecurityException { + + final org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest = + buildEtsiCatalogManagerPkgmSubscriptionRequest(pkgmSubscriptionRequest); + + final Optional<PkgmSubscription> optionalEtsiCatalogManagerSubscription = + etsiCatalogServiceProvider.postSubscription(etsiCatalogManagerSubscriptionRequest); + + if (optionalEtsiCatalogManagerSubscription.isPresent()) { + PkgmSubscription etsiCatalogManagerSubscription = optionalEtsiCatalogManagerSubscription.get(); + logger.debug("postPkgmSubscriptionRequest Response SubscriptionId: {}", + Objects.requireNonNull(etsiCatalogManagerSubscription.getId().toString())); + final String subscriptionId = etsiCatalogManagerSubscription.getId().toString(); + + packageManagementCacheServiceProvider.addSubscription(subscriptionId, pkgmSubscriptionRequest); + + final InlineResponse2002 response2002 = new InlineResponse2002(); + response2002.setId(subscriptionId); + response2002.setFilter(pkgmSubscriptionRequest.getFilter()); + response2002.setCallbackUri(getSubscriptionUri(subscriptionId).toString()); + response2002.setLinks(new SubscriptionsLinks() + .self(new VnfPackagesLinksSelf().href(getSubscriptionUri(subscriptionId).toString()))); + + return Optional.of(response2002); + } + throw new InternalServerErrorException( + "Received empty response from POST to ETSI Catalog Manager Subscription Endpoint."); + } + + + + public Optional<String> getSubscriptionId(final PkgmSubscriptionRequest pkgmSubscriptionRequest) { + return packageManagementCacheServiceProvider.getSubscriptionId(pkgmSubscriptionRequest); + } + + public Optional<InlineResponse2002> getSubscription(final String subscriptionId) { + final Optional<PkgmSubscriptionRequest> optional = + packageManagementCacheServiceProvider.getSubscription(subscriptionId); + if (optional.isPresent()) { + final PkgmSubscriptionRequest subscription = optional.get(); + return Optional.of(getInlineResponse2002(subscriptionId, subscription)); + } + return Optional.empty(); + } + + public List<InlineResponse2002> getSubscriptions() { + final Map<String, PkgmSubscriptionRequest> subscriptions = + packageManagementCacheServiceProvider.getSubscriptions(); + final List<InlineResponse2002> response = new ArrayList<>(); + subscriptions.forEach((key, value) -> response.add(getInlineResponse2002(key, value))); + return response; + } + + public URI getSubscriptionUri(final String subscriptionId) { + return URI.create( + vnfmAdapterEndpoint + Constants.PACKAGE_MANAGEMENT_BASE_URL + "/subscriptions/" + subscriptionId); + } + + private InlineResponse2002 getInlineResponse2002(final String id, final PkgmSubscriptionRequest subscription) { + return new InlineResponse2002().id(id).filter(subscription.getFilter()) + .callbackUri(subscription.getCallbackUri()); + } + + private org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest buildEtsiCatalogManagerPkgmSubscriptionRequest( + 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) { + logger.error(conversionException.getMessage()); + throw new SubscriptionRequestConversionException( + "Could not convert Sol003 PkgmSubscriptionRequest to ETSI-Catalog Manager PkgmSubscriptionRequest"); + } catch (Exception exception) { + logger.error(exception.getMessage()); + throw new InternalServerErrorException( + "Could not convert Sol003 PkgmSubscriptionRequest to ETSI-Catalog Manager PkgmSubscriptionRequest"); + } + + if (etsiCatalogManagerSubscriptionRequest != null) { + etsiCatalogManagerSubscriptionRequest + .setCallbackUri(vnfmAdapterEndpoint + Constants.ETSI_SUBSCRIPTION_NOTIFICATION_BASE_URL); + + final String[] auth = decryptAuth(); + final String username = auth[0]; + final String password = auth[1]; + + etsiCatalogManagerSubscriptionRequest.setAuthentication( + new org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.SubscriptionAuthentication() + .addAuthTypeItem(BASIC).paramsBasic(new BasicAuth().userName(username).password(password))); + return etsiCatalogManagerSubscriptionRequest; + } + throw new SubscriptionRequestConversionException( + "Failed to convert Sol003 PkgmSubscriptionRequest to ETSI-Catalog Manager PkgmSubscriptionRequest"); + } + + private String[] decryptAuth() throws GeneralSecurityException { + final String decryptedAuth = CryptoUtils.decrypt(vnfmAdapterAuth, msoKeyString); + final String[] auth = decryptedAuth.split(":"); + return auth; + } + +} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/AbstractCacheServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/AbstractCacheServiceProvider.java new file mode 100644 index 0000000000..e1e9b2307e --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/AbstractCacheServiceProvider.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.vnfmadapter.packagemanagement.subscriptionmanagement.cache; + +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; + +/** + * @author Ronan Kenny (ronan.kenny@est.tech) + * @author Gareth Roper (gareth.roper@est.tech) + */ +public abstract class AbstractCacheServiceProvider { + + private final CacheManager cacheManager; + private final String cacheName; + + public AbstractCacheServiceProvider(final String cacheName, final CacheManager cacheManager) { + this.cacheName = cacheName; + this.cacheManager = cacheManager; + } + + public Cache getCache() { + final Cache cache = cacheManager.getCache(cacheName); + if (cache == null) { + throw new CacheNotFoundException("Unable to find " + cacheName + " cache"); + } + return cache; + } +} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/CacheManagerConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/CacheManagerConfiguration.java new file mode 100644 index 0000000000..830db39888 --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/CacheManagerConfiguration.java @@ -0,0 +1,50 @@ +/*- + * ============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.adapters.vnfmadapter.packagemanagement.subscriptionmanagement.cache; + +import java.util.Arrays; +import org.onap.so.adapters.vnfmadapter.Constants; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.cache.concurrent.ConcurrentMapCache; +import org.springframework.cache.support.SimpleCacheManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author Ronan Kenny (ronan.kenny@est.tech) + * @author Gareth Roper (gareth.roper@est.tech) + */ +@Configuration +public class CacheManagerConfiguration { + + @Bean + public CacheManager cacheManager() { + final SimpleCacheManager manager = new SimpleCacheManager(); + manager.setCaches(Arrays.asList(getCache(Constants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE))); + + return manager; + } + + private Cache getCache(final String name) { + return new ConcurrentMapCache(name); + } +} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/CacheNotFoundException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/CacheNotFoundException.java new file mode 100644 index 0000000000..edd5982ab1 --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/CacheNotFoundException.java @@ -0,0 +1,37 @@ +/*- + * ============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.adapters.vnfmadapter.packagemanagement.subscriptionmanagement.cache; + +/** + * Exception for failure to find the cache. + * + * @author Ronan Kenny (ronan.kenny@est.tech) + * @author Gareth Roper (gareth.roper@est.tech) + * + */ +public class CacheNotFoundException extends RuntimeException { + + private static final long serialVersionUID = -372361485260755367L; + + public CacheNotFoundException(final String message) { + super(message); + } +} 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 new file mode 100644 index 0000000000..6042513a50 --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProvider.java @@ -0,0 +1,74 @@ +/*- + * ============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.adapters.vnfmadapter.packagemanagement.subscriptionmanagement.cache; + +import java.util.Map; +import java.util.Optional; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest; + +/** + * Interface which provides methods for communicating with the cache + * + * @author Ronan Kenny (ronan.kenny@est.tech) + * @author Gareth Roper (gareth.roper@est.tech) + * + */ +public interface PackageManagementCacheServiceProvider { + + /** + * Checks cache if subscription request Id is already present. If not, it adds the subscription to the cache. + * + * @param subscriptionId + * @param pkgmSubscriptionRequest + */ + void addSubscription(final String subscriptionId, final PkgmSubscriptionRequest pkgmSubscriptionRequest); + + /** + * Gets individual subscription from cache + * + * @param subscriptionId + * @return <AbstractMap.SimpleImmutableEntry<String, PkgmSubscriptionRequest>> + */ + Optional<PkgmSubscriptionRequest> getSubscription(final String subscriptionId); + + /** + * Gets Map of subscriptions from cache + * + * @return Map<String, PkgmSubscriptionRequest>> + */ + Map<String, PkgmSubscriptionRequest> getSubscriptions(); + + /** + * Delete subscription from cache + * + * @param subscriptionId + * @return true if subscription exists and able to be removed, otherwise returns false + */ + boolean deleteSubscription(final String subscriptionId); + + /** + * Checks if subscription exists in cache and return its subscriptionId + * + * @param pkgmSubscriptionRequest + * @return Subscription Id + */ + Optional<String> getSubscriptionId(final PkgmSubscriptionRequest pkgmSubscriptionRequest); +} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProviderImpl.java new file mode 100644 index 0000000000..ba57eb5e05 --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProviderImpl.java @@ -0,0 +1,119 @@ +/*- + * ============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.adapters.vnfmadapter.packagemanagement.subscriptionmanagement.cache; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import org.onap.so.adapters.vnfmadapter.Constants; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.stereotype.Service; + +/** + * Implementation which provides methods for communicating with the cache + * + * @author Ronan Kenny (ronan.kenny@est.tech) + * @author Gareth Roper (gareth.roper@est.tech) + */ +@Service +public class PackageManagementCacheServiceProviderImpl extends AbstractCacheServiceProvider + implements PackageManagementCacheServiceProvider { + + private static final Logger LOGGER = LoggerFactory.getLogger(PackageManagementCacheServiceProviderImpl.class); + + @Autowired + public PackageManagementCacheServiceProviderImpl(final CacheManager cacheManager) { + super(Constants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE, cacheManager); + } + + @Override + public void addSubscription(final String subscriptionId, final PkgmSubscriptionRequest pkgmSubscriptionRequest) { + LOGGER.debug("Adding {} to cache with subscription id: {}", pkgmSubscriptionRequest, subscriptionId); + getCache().put(subscriptionId, pkgmSubscriptionRequest); + } + + @Override + public Optional<PkgmSubscriptionRequest> getSubscription(final String subscriptionId) { + LOGGER.debug("Getting subscription from cache using Id: {}", subscriptionId); + final Cache cache = getCache(); + final PkgmSubscriptionRequest cacheValue = cache.get(subscriptionId, PkgmSubscriptionRequest.class); + if (cacheValue != null) { + return Optional.of(cacheValue); + } + LOGGER.error("Unable to find Subscription in cache using Id: {}", subscriptionId); + return Optional.empty(); + } + + @Override + public Map<String, PkgmSubscriptionRequest> getSubscriptions() { + LOGGER.info("Getting all subscriptions from cache"); + final Cache cache = getCache(); + + final Object nativeCache = cache.getNativeCache(); + if (nativeCache instanceof ConcurrentHashMap) { + @SuppressWarnings("unchecked") + final ConcurrentHashMap<Object, Object> concurrentHashMap = (ConcurrentHashMap<Object, Object>) nativeCache; + final Map<String, PkgmSubscriptionRequest> result = new HashMap<>(); + concurrentHashMap.keySet().forEach(key -> { + final Optional<PkgmSubscriptionRequest> optional = getSubscription(key.toString()); + optional.ifPresent(pkgmSubscriptionRequest -> result.put(key.toString(), pkgmSubscriptionRequest)); + }); + return result; + } + LOGGER.error("Unable to find Subscriptions in cache"); + return Collections.emptyMap(); + } + + @Override + public boolean deleteSubscription(final String subscriptionId) { + final Cache cache = getCache(); + final Optional<PkgmSubscriptionRequest> optional = getSubscription(subscriptionId); + if (optional.isPresent()) { + cache.evict(subscriptionId); + return true; + } + return false; + } + + @Override + public Optional<String> getSubscriptionId(final PkgmSubscriptionRequest pkgmSubscriptionRequest) { + final Cache cache = getCache(); + final Object nativeCache = cache.getNativeCache(); + if (nativeCache instanceof ConcurrentHashMap) { + @SuppressWarnings("unchecked") + final ConcurrentHashMap<Object, Object> concurrentHashMap = (ConcurrentHashMap<Object, Object>) nativeCache; + final Optional<Entry<Object, Object>> optional = concurrentHashMap.entrySet().stream() + .filter(entry -> entry.getValue().equals(pkgmSubscriptionRequest)).findAny(); + if (optional.isPresent()) { + return Optional.of(optional.get().getKey().toString()); + } + } + return Optional.empty(); + } +} 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 new file mode 100644 index 0000000000..c5bd5bc14e --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationController.java @@ -0,0 +1,51 @@ +/*- + * ============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.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; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * This controller handles the ETSI Subscription Notification Endpoints. + * + * @author Ronan Kenny (ronan.kenny@est.tech) + * @author Gareth Roper (gareth.roper@est.tech) + */ +@Controller +@RequestMapping(value = ETSI_SUBSCRIPTION_NOTIFICATION_CONTROLLER_BASE_URL, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) +public class EtsiSubscriptionNotificationController { + + private static final Logger logger = getLogger(EtsiSubscriptionNotificationController.class); + + @GetMapping(value = "/notification") + public ResponseEntity<Void> testSubscriptionNotificationEndPoint() { + logger.debug("Testing Notification Endpoint"); + return ResponseEntity.noContent().build(); + } +} 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 9d8e29b3f9..cce7241757 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 @@ -75,7 +75,7 @@ public class Sol003PackageManagementController { + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" \n" + "endpoint."; logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(buildProblemDetails(errorMessage)); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); } /** @@ -97,7 +97,7 @@ public class Sol003PackageManagementController { + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" by vnfPkgId: \"" + vnfPkgId + "\" \n" + "endpoint."; logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(buildProblemDetails(errorMessage)); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); } /** @@ -121,7 +121,7 @@ public class Sol003PackageManagementController { + "endpoint."; logger.error(errorMessage); - return new ResponseEntity(buildProblemDetails(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity(new ProblemDetails().detail(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR); } /** @@ -144,7 +144,7 @@ public class Sol003PackageManagementController { + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"package_content\" \n" + "endpoint."; logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(buildProblemDetails(errorMessage)); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); } /** @@ -170,19 +170,9 @@ public class Sol003PackageManagementController { + " Sol003PackageManagementController from the EtsiCatalogManager using the\n GET \"vnf_packages\" by vnfPkgId: \"" + vnfPkgId + "\" for artifactPath: \"" + artifactPath + "\"\n" + "endpoint."; logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(buildProblemDetails(errorMessage)); - } - - /** - * Builds the ProblemDetails Object, using the provided error message. - * - * @param detail The error message retrieved from the exception thrown. - * @return ProblemDetails Object, containing error information. - */ - private ProblemDetails buildProblemDetails(final String detail) { - final ProblemDetails problemDetails = new ProblemDetails(); - problemDetails.setDetail(detail); - return problemDetails; + // return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new + // ProblemDetails().detail(errorMessage)); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); } } 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 new file mode 100644 index 0000000000..cbad564210 --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionController.java @@ -0,0 +1,154 @@ +/*- + * ============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.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.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; +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.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; + +/** + * Controller for handling the Subscription Management. The client can use this resource to subscribe to notifications + * related to the VNF package management, and to query its subscriptions. For further information please read: + * https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/003/02.05.01_60/gs_nfv-sol003v020501p.pdf Use the section number + * above each endpoint to find the corresponding section in the above document. + * + * @author Ronan Kenny (ronan.kenny@est.tech) + * @author Gareth Roper (gareth.roper@est.tech) + */ +@Controller +@RequestMapping(value = PACKAGE_MANAGEMENT_BASE_URL, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) +public class Sol003PackageManagementSubscriptionController { + + private static final String LOG_REQUEST_RECEIVED = "Subscription Management Controller: {} {}"; + private static final Logger logger = getLogger(Sol003PackageManagementSubscriptionController.class); + private final SubscriptionManager subscriptionManager; + + @Autowired + public Sol003PackageManagementSubscriptionController(final SubscriptionManager subscriptionManager) { + this.subscriptionManager = subscriptionManager; + } + + /** + * POST Subscribe request. Will send request and respond with the subscription that you subscribed to, if + * successful. Section Number: 10.4.7 + * + * @param pkgmSubscriptionRequest This includes the details of the subscription to be created. + * @return The subscription requested, if successful. Object: InlineRespone2002 Response Code: 201 Created Response + * Code: 303 Duplicate Subscription + * @throws GeneralSecurityException + */ + @PostMapping(value = "/subscriptions") + public ResponseEntity<?> postSubscriptionRequest(@RequestBody final PkgmSubscriptionRequest pkgmSubscriptionRequest) + throws GeneralSecurityException { + logger.info(LOG_REQUEST_RECEIVED, " postSubscriptionRequest Endpoint Called"); + + // Check if subscription exists already. + final Optional<String> exists = subscriptionManager.getSubscriptionId(pkgmSubscriptionRequest); + + if (exists.isPresent()) { + final URI subscriptionUri = subscriptionManager.getSubscriptionUri(exists.get()); + final HttpHeaders headers = createLocationHeader(subscriptionUri); + logger.info("PkgmSubscriptionRequest already exists with uri {} ", subscriptionUri); + return new ResponseEntity<>(headers, HttpStatus.SEE_OTHER); + } + + logger.debug("No duplicate Subscription exists, continuing with POST."); + final Optional<InlineResponse2002> optionalInlineResponse2002 = + subscriptionManager.createSubscription(pkgmSubscriptionRequest); + + if (optionalInlineResponse2002.isPresent()) { + InlineResponse2002 inlineResponse2002 = optionalInlineResponse2002.get(); + final URI subscriptionUri = subscriptionManager.getSubscriptionUri(inlineResponse2002.getId()); + final HttpHeaders headers = createLocationHeader(subscriptionUri); + logger.debug("Sending response with uri {} ", subscriptionUri); + return new ResponseEntity<>(inlineResponse2002, headers, HttpStatus.CREATED); + } + final String errorMessage = "A null response was received during the postSubscriptionRequest call."; + logger.error(errorMessage); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); + } + + /** + * GET all subscriptions. Will return a list of all subscriptions currently active. Section Number: 10.4.7 + * + * @return All of the current active subscriptions. Object: List<InlineResponse2002> Response Code: 200 OK + */ + @GetMapping(value = "/subscriptions") + public ResponseEntity<List<InlineResponse2002>> getSubscriptions() { + logger.info(LOG_REQUEST_RECEIVED, " getSubscriptions."); + List<InlineResponse2002> subscriptionsList = subscriptionManager.getSubscriptions(); + return new ResponseEntity<>(subscriptionsList, HttpStatus.OK); + } + + /** + * GET a specific subscription, by subscriptionId. Section Number: 10.4.8 + * + * @param subscriptionId The ID of the subscription that you wish to retrieve. + * @return A subscription based on subscriptionId. Object: InlineResponse2002 Response Code: 200 OK + */ + @GetMapping(value = "/subscriptions/{subscriptionId}") + public ResponseEntity<?> getSubscription(@PathVariable("subscriptionId") final String subscriptionId) { + logger.info(LOG_REQUEST_RECEIVED, " Getting Subscription: ", subscriptionId); + final Optional<InlineResponse2002> optional = subscriptionManager.getSubscription(subscriptionId); + if (optional.isPresent()) { + logger.debug("Return subscription with id {} and body {}", subscriptionId, optional); + return new ResponseEntity<>(optional.get(), HttpStatus.OK); + } + final String errorMessage = + "The requested subscription: " + subscriptionId + " was not found on call getSubscription"; + 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 + * @return header with callbackUri in Location + */ + private HttpHeaders createLocationHeader(final URI subscriptionUri) { + final HttpHeaders headers = new HttpHeaders(); + headers.setLocation(subscriptionUri); + return headers; + } + +} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementController.java deleted file mode 100644 index 16650d4a3d..0000000000 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementController.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -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.util.List; -import javax.ws.rs.core.MediaType; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2002; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest; -import org.slf4j.Logger; -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; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * Controller for handling the Subscription Management. For further information please read: - * https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/003/02.05.01_60/gs_nfv-sol003v020501p.pdf Use the section number - * above each endpoint to find the corresponding section in the above document. - * - * @author gareth.roper@est.tech - */ -@Controller -@RequestMapping(value = PACKAGE_MANAGEMENT_BASE_URL, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) -public class Sol003SubscriptionManagementController { - - private static final String LOG_REQUEST_RECEIVED = "Subscription Management Controller: {} {}"; - private static final Logger logger = getLogger(Sol003SubscriptionManagementController.class); - - /** - * POST Subscribe request. Will send request and respond with the subscription that you subscribed to, if - * successful. Section Number: 10.4.7 - * - * @param pkgmSubscriptionRequest This includes the details of the subscription to be created. - * @return The subscription requested, if successful. Object: InlineRespone2002 Response Code: 201 Created Response - * Code: 303 Duplicate Subscription - */ - @PostMapping(value = "/subscriptions") - public ResponseEntity<InlineResponse2002> postSubscriptionRequest( - @RequestBody final PkgmSubscriptionRequest pkgmSubscriptionRequest) { - logger.info(LOG_REQUEST_RECEIVED, " postSubscriptionRequest: ", pkgmSubscriptionRequest); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } - - /** - * GET all subscriptions. Will return a list of all subscriptions currently active. Section Number: 10.4.7 - * - * @return All of the current active subscriptions. Object: List<InlineResponse2002> Response Code: 200 OK - */ - @GetMapping(value = "/subscriptions") - public ResponseEntity<List<InlineResponse2002>> getSubscriptions() { - logger.info(LOG_REQUEST_RECEIVED, " getSubscriptions."); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } - - /** - * GET a specific subscription, by subscriptionId. Section Number: 10.4.8 - * - * @param subscriptionId The ID of the subscription that you wish to retrieve. - * @return A subscription based on subscriptionId. Object: InlineResponse2002 Response Code: 200 OK - */ - @GetMapping(value = "/subscriptions/{subscriptionId}") - public ResponseEntity<InlineResponse2002> getSubscription( - @PathVariable("subscriptionId") final String subscriptionId) { - logger.info(LOG_REQUEST_RECEIVED, " Getting Subscription: ", subscriptionId); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } - - /** - * DELETE a specific subscription, by subscriptionId. Section Number: 10.4.7 - * - * @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<Void> deleteSubscription(@PathVariable("subscriptionId") final String subscriptionId) { - logger.info(LOG_REQUEST_RECEIVED, " Deleting Subscription: ", subscriptionId); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } - - -} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/EtsiCatalogManagerBadRequestException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/EtsiCatalogManagerBadRequestException.java new file mode 100644 index 0000000000..dbd098f7cd --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/EtsiCatalogManagerBadRequestException.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.adapters.vnfmadapter.rest.exceptions; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +/** + * Exception for an ETSI Catalog Manager Bad Request Exception. + * + * @author Gareth Roper (gareth.roper@est.tech + */ +@ResponseStatus(code = HttpStatus.BAD_REQUEST) +public class EtsiCatalogManagerBadRequestException extends RuntimeException { + + private static final long serialVersionUID = 6571317418914258768L; + + public EtsiCatalogManagerBadRequestException(final String message) { + super(message); + } + + @Override + public synchronized Throwable fillInStackTrace() { + return this; + } +} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/InternalServerErrorException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/InternalServerErrorException.java new file mode 100644 index 0000000000..9b547d3c5a --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/InternalServerErrorException.java @@ -0,0 +1,43 @@ +/*- + * ============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.adapters.vnfmadapter.rest.exceptions; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +/** + * Exception for an ETSI Catalog Manager Request Failure + * + * @author gareth.roper@est.tech + */ +@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR) +public class InternalServerErrorException extends RuntimeException { + + private static final long serialVersionUID = 66864561537194516L; + + public InternalServerErrorException(final String message) { + super(message); + } + + @Override + public synchronized Throwable fillInStackTrace() { + return this; + } +} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/Sol003PackageManagementControllerExceptionHandler.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/Sol003PackageManagementControllerExceptionHandler.java index a49063a72f..da8b0cbff2 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/Sol003PackageManagementControllerExceptionHandler.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/Sol003PackageManagementControllerExceptionHandler.java @@ -48,6 +48,30 @@ public class Sol003PackageManagementControllerExceptionHandler { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails); } + @ExceptionHandler(EtsiCatalogManagerBadRequestException.class) + public ResponseEntity<ProblemDetails> handleEtsiCatalogManagerBadRequestFailureException( + final EtsiCatalogManagerBadRequestException etsiCatalogManagerBadRequestException) { + final ProblemDetails problemDetails = new ProblemDetails(); + problemDetails.setDetail(etsiCatalogManagerBadRequestException.getMessage()); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(problemDetails); + } + + @ExceptionHandler(SubscriptionNotFoundException.class) + public ResponseEntity<ProblemDetails> handleSubscriptionNotFoundException( + final SubscriptionNotFoundException subscriptionNotFoundException) { + final ProblemDetails problemDetails = new ProblemDetails(); + problemDetails.setDetail(subscriptionNotFoundException.getMessage()); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails); + } + + @ExceptionHandler(SubscriptionRequestConversionException.class) + public ResponseEntity<ProblemDetails> handleSubscriptionRequestConversionException( + final SubscriptionRequestConversionException subscriptionRequestConversionException) { + final ProblemDetails problemDetails = new ProblemDetails(); + problemDetails.setDetail(subscriptionRequestConversionException.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails); + } + @ExceptionHandler(VnfPkgConflictException.class) public ResponseEntity<ProblemDetails> handleVnfPkgConflictException( final VnfPkgConflictException vnfPkgConflictException) { diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/SubscriptionNotFoundException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/SubscriptionNotFoundException.java new file mode 100644 index 0000000000..58c2ef050d --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/SubscriptionNotFoundException.java @@ -0,0 +1,43 @@ +/*- + * ============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.adapters.vnfmadapter.rest.exceptions; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +/** + * Exception for an ETSI Catalog Manager Request Failure + * + * @author gareth.roper@est.tech + */ +@ResponseStatus(code = HttpStatus.NOT_FOUND) +public class SubscriptionNotFoundException extends RuntimeException { + + private static final long serialVersionUID = 85268561453194516L; + + public SubscriptionNotFoundException(final String message) { + super(message); + } + + @Override + public synchronized Throwable fillInStackTrace() { + return this; + } +} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/SubscriptionRequestConversionException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/SubscriptionRequestConversionException.java new file mode 100644 index 0000000000..daa544f928 --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/SubscriptionRequestConversionException.java @@ -0,0 +1,43 @@ +/*- + * ============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.adapters.vnfmadapter.rest.exceptions; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +/** + * Exception for an ETSI Catalog Manager Request Failure + * + * @author gareth.roper@est.tech + */ +@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR) +public class SubscriptionRequestConversionException extends RuntimeException { + + private static final long serialVersionUID = 45898561453196895L; + + public SubscriptionRequestConversionException(final String message) { + super(message); + } + + @Override + public synchronized Throwable fillInStackTrace() { + return this; + } +} |