diff options
author | MukeshKumar <mukeshsharma@est.tech> | 2020-08-31 16:28:26 +0100 |
---|---|---|
committer | Mukesh <mukeshsharma@est.tech> | 2020-09-05 22:44:31 +0100 |
commit | 89be2d744cabc60937176302038c1af766d30751 (patch) | |
tree | 58a5cc806a6432da5eea84b719ba08ea51e7db71 /adapters/etsi-sol003-adapter/etsi-sol003-lcm | |
parent | 27d773cb05051ccc7d967434421aba189a0ae8b5 (diff) |
Get SOl003 pkg from ETSI Catalog mgr
Issue-ID: SO-3207
Change-Id: Ib20176e1b0cd572933d45944cdd1e2ac3d036b6c
Signed-off-by: Mukesh <mukeshsharma@est.tech>
Diffstat (limited to 'adapters/etsi-sol003-adapter/etsi-sol003-lcm')
7 files changed, 96 insertions, 65 deletions
diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/pom.xml b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/pom.xml index 8359fd3829..6ed9afcc75 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/pom.xml +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/pom.xml @@ -105,5 +105,10 @@ <artifactId>junit</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.onap.so.adapters</groupId> + <artifactId>etsi-sol003-pkgm-adapter</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> </project> diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/SdcPackageProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/EtsiPackageProvider.java index 497de2874c..ac0e882414 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/SdcPackageProvider.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/EtsiPackageProvider.java @@ -24,38 +24,26 @@ package org.onap.so.adapters.etsisol003adapter.lcm.extclients; import static com.google.common.base.Splitter.on; import static com.google.common.collect.Iterables.filter; -import static com.google.common.io.ByteStreams.toByteArray; import static java.lang.String.format; -import static org.apache.http.HttpHeaders.ACCEPT; -import static org.apache.http.HttpHeaders.AUTHORIZATION; import static org.onap.so.adapters.etsisol003adapter.lcm.NvfmAdapterUtils.abortOperation; import static org.onap.so.adapters.etsisol003adapter.lcm.NvfmAdapterUtils.child; import static org.onap.so.adapters.etsisol003adapter.lcm.NvfmAdapterUtils.childElement; import static org.onap.so.adapters.etsisol003adapter.lcm.NvfmAdapterUtils.children; import static org.slf4j.LoggerFactory.getLogger; -import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.util.HashSet; -import java.util.Iterator; -import java.util.List; import java.util.NoSuchElementException; +import java.util.Optional; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import javax.net.ssl.SSLContext; -import org.apache.commons.codec.binary.Base64; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.onap.so.utils.CryptoUtils; +import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.EtsiCatalogServiceProviderImpl; +import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.EtsiCatalogManagerRequestFailureException; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.yaml.snakeyaml.Yaml; import com.google.common.io.ByteStreams; @@ -63,21 +51,13 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; @Component -public class SdcPackageProvider { - private static final String GET_PACKAGE_URL = "%s/sdc/v1/catalog/resources/%s/toscaModel"; - @Value("${sdc.toscametapath:TOSCA-Metadata/TOSCA.meta}") - private List<String> toscaMetaPaths; +public class EtsiPackageProvider { + private static final String TOCSA_METADATA_FILE_PATH = "TOSCA-Metadata/TOSCA.meta"; private static final String TOSCA_VNFD_KEY = "Entry-Definitions"; - private static Logger logger = getLogger(SdcPackageProvider.class); + private static Logger logger = getLogger(EtsiPackageProvider.class); - @Value("${sdc.username}") - private String sdcUsername; - @Value("${sdc.password}") - private String sdcPassword; - @Value("${sdc.key}") - private String sdcKey; - @Value("${sdc.endpoint}") - private String baseUrl; + @Autowired + private EtsiCatalogServiceProviderImpl etsiCatalogServiceProviderImpl; public String getVnfdId(final String csarId) { return getVnfNodeProperty(csarId, "descriptor_id"); @@ -133,35 +113,25 @@ public class SdcPackageProvider { } private byte[] getPackage(final String csarId) { - final String SERVICE_NAME = "vnfm-adapter"; - try (CloseableHttpClient client = HttpClients.custom().setSSLContext(SSLContext.getDefault()).build()) { - final HttpGet httpget = new HttpGet(format(GET_PACKAGE_URL, baseUrl, csarId)); - httpget.setHeader(ACCEPT, APPLICATION_OCTET_STREAM_VALUE); - httpget.setHeader("X-ECOMP-InstanceID", SERVICE_NAME); - httpget.setHeader("X-FromAppId", SERVICE_NAME); - final String auth = sdcUsername + ":" + CryptoUtils.decrypt(sdcPassword, sdcKey); - final byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)); - final String authHeader = "Basic " + new String(encodedAuth); - httpget.setHeader(AUTHORIZATION, authHeader); - logger.debug("Fetching from SDC: " + httpget); - final CloseableHttpResponse response = client.execute(httpget); - final HttpEntity entity = response.getEntity(); - final InputStream is = entity.getContent(); - return toByteArray(is); - } catch (final Exception e) { - throw abortOperation("Unable to download " + csarId + " package from SDC", e); + final Optional<byte[]> optional = etsiCatalogServiceProviderImpl.getVnfPackageContent(csarId); + try { + if (optional.isPresent()) { + return optional.get(); + } + } catch (final Exception exception) { + logger.error("Unable to retrieve package from ETSI Catalog Manager using pkgId: {}", csarId); + throw new EtsiCatalogManagerRequestFailureException("Value is not present", exception); } + logger.error("Unable to retrieve package from ETSI Catalog Manager using pkgId: {}", csarId); + throw new EtsiCatalogManagerRequestFailureException("Value is not present"); } private String getVnfdLocation(final InputStream stream) throws IOException { - final Iterator<String> pathIterator = toscaMetaPaths.iterator(); - while (pathIterator.hasNext()) { - final String toscaMetadata = new String(getFileInZip(stream, pathIterator.next()).toByteArray()); - if (!toscaMetadata.isEmpty()) { - final String toscaVnfdLine = - filter(on("\n").split(toscaMetadata), line -> line.contains(TOSCA_VNFD_KEY)).iterator().next(); - return toscaVnfdLine.replace(TOSCA_VNFD_KEY + ":", "").trim(); - } + final String toscaMetadata = new String(getFileInZip(stream, TOCSA_METADATA_FILE_PATH).toByteArray()); + if (!toscaMetadata.isEmpty()) { + final String toscaVnfdLine = + filter(on("\n").split(toscaMetadata), line -> line.contains(TOSCA_VNFD_KEY)).iterator().next(); + return toscaVnfdLine.replace(TOSCA_VNFD_KEY + ":", "").trim(); } throw abortOperation("Unable to find valid Tosca Path"); } diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmRestTemplateConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmRestTemplateConfiguration.java new file mode 100644 index 0000000000..2c7ddd1d49 --- /dev/null +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmRestTemplateConfiguration.java @@ -0,0 +1,56 @@ +/*- + * ============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.etsisol003adapter.lcm.extclients.vnfm; + +import org.onap.logging.filter.spring.SpringClientPayloadFilter; +import org.onap.so.configuration.rest.HttpComponentsClientConfiguration; +import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.BufferingClientHttpRequestFactory; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Configuration +public class VnfmRestTemplateConfiguration { + + public static final String SOL003_LCM_REST_TEMPLATE = "Sol003LcmRestTemplate"; + + @Autowired + private HttpComponentsClientConfiguration httpComponentsClientConfiguration; + + @Bean + @Qualifier(SOL003_LCM_REST_TEMPLATE) + public RestTemplate sol003LcmRestTemplate() { + final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = + httpComponentsClientConfiguration.httpComponentsClientHttpRequestFactory(); + final RestTemplate restTemplate = + new RestTemplate(new BufferingClientHttpRequestFactory(clientHttpRequestFactory)); + restTemplate.getInterceptors().add(new SOSpringClientFilter()); + restTemplate.getInterceptors().add((new SpringClientPayloadFilter())); + return restTemplate; + } +} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmServiceProviderConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmServiceProviderConfiguration.java index da727b395a..1ed3ec9ff2 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmServiceProviderConfiguration.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmServiceProviderConfiguration.java @@ -20,7 +20,6 @@ package org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; import java.io.IOException; import java.security.KeyManagementException; import java.security.KeyStore; @@ -83,7 +82,7 @@ public class VnfmServiceProviderConfiguration extends AbstractServiceProviderCon @Value("${vnfmadapter.temp.vnfm.oauth.endpoint:#{null}}") private String oauthEndpoint; - @Qualifier(CONFIGURABLE_REST_TEMPLATE) + @Qualifier(VnfmRestTemplateConfiguration.SOL003_LCM_REST_TEMPLATE) @Autowired private RestTemplate defaultRestTemplate; diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/lifecycle/LifecycleManager.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/lifecycle/LifecycleManager.java index 8ba56c5051..472b5176d5 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/lifecycle/LifecycleManager.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/lifecycle/LifecycleManager.java @@ -24,7 +24,7 @@ import java.util.Map; import org.onap.aai.domain.yang.EsrVnfm; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.Relationship; -import org.onap.so.adapters.etsisol003adapter.lcm.extclients.SdcPackageProvider; +import org.onap.so.adapters.etsisol003adapter.lcm.extclients.EtsiPackageProvider; import org.onap.so.adapters.etsisol003adapter.lcm.extclients.aai.AaiHelper; import org.onap.so.adapters.etsisol003adapter.lcm.extclients.aai.AaiServiceProvider; import org.onap.so.adapters.etsisol003adapter.lcm.extclients.aai.OamIpAddressSource; @@ -60,12 +60,12 @@ public class LifecycleManager { private final AaiHelper aaiHelper; private final VnfmHelper vnfmHelper; private final JobManager jobManager; - private final SdcPackageProvider packageProvider; + private final EtsiPackageProvider packageProvider; @Autowired LifecycleManager(final AaiServiceProvider aaiServiceProvider, final AaiHelper aaiHelper, final VnfmHelper vnfmHelper, final VnfmServiceProvider vnfmServiceProvider, final JobManager jobManager, - final SdcPackageProvider packageProvider) { + final EtsiPackageProvider packageProvider) { this.aaiServiceProvider = aaiServiceProvider; this.vnfmServiceProvider = vnfmServiceProvider; this.aaiHelper = aaiHelper; diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/EtsiSol003AdapterControllerTest.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/EtsiSol003AdapterControllerTest.java index eaf40b546f..9aed675324 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/EtsiSol003AdapterControllerTest.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/EtsiSol003AdapterControllerTest.java @@ -27,7 +27,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.VnfmRestTemplateConfiguration; import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest; @@ -54,7 +54,8 @@ import org.onap.aai.domain.yang.RelationshipList; import org.onap.aaiclient.client.aai.AAIResourcesClient; import org.onap.aaiclient.client.aai.AAIVersion; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; -import org.onap.so.adapters.etsisol003adapter.lcm.extclients.SdcPackageProvider; +import org.onap.so.adapters.etsisol003adapter.lcm.extclients.EtsiPackageProvider; +import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.VnfmRestTemplateConfiguration; import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse200; import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse2001; import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse201; @@ -106,7 +107,7 @@ public class EtsiSol003AdapterControllerTest { @LocalServerPort private int port; @Autowired - @Qualifier(CONFIGURABLE_REST_TEMPLATE) + @Qualifier(VnfmRestTemplateConfiguration.SOL003_LCM_REST_TEMPLATE) private RestTemplate testRestTemplate; private MockRestServiceServer mockRestServer; @@ -114,7 +115,7 @@ public class EtsiSol003AdapterControllerTest { AAIResourcesClient aaiResourcesClient; @MockBean - SdcPackageProvider sdcPackageProvider; + EtsiPackageProvider etsiPackageProvider; @Autowired EtsiSol003AdapterController controller; diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/Sol003LcnControllerTest.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/Sol003LcnControllerTest.java index ab6ae83896..86eda0abfa 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/Sol003LcnControllerTest.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/Sol003LcnControllerTest.java @@ -26,7 +26,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.VnfmRestTemplateConfiguration; 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; @@ -99,7 +99,7 @@ public class Sol003LcnControllerTest { @LocalServerPort private int port; @Autowired - @Qualifier(CONFIGURABLE_REST_TEMPLATE) + @Qualifier(VnfmRestTemplateConfiguration.SOL003_LCM_REST_TEMPLATE) private RestTemplate testRestTemplate; private MockRestServiceServer mockRestServer; |