2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.etsicatalog;
22 import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.etsicatalog.EtsiCatalogServiceProviderConfiguration.ETSI_CATALOG_SERVICE_PROVIDER_BEAN;
23 import java.util.Optional;
24 import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdInfo;
25 import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPkgInfo;
26 import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.EtsiCatalogManagerRequestFailureException;
27 import org.onap.so.rest.service.HttpRestServiceProvider;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.beans.factory.annotation.Qualifier;
32 import org.springframework.http.ResponseEntity;
33 import org.springframework.stereotype.Service;
36 * @author Waqas Ikram (waqas.ikram@est.tech)
40 public class EtsiCatalogPackageManagementServiceProviderImpl implements EtsiCatalogPackageManagementServiceProvider {
42 private static final Logger logger = LoggerFactory.getLogger(EtsiCatalogPackageManagementServiceProviderImpl.class);
44 private final HttpRestServiceProvider httpServiceProvider;
45 private final EtsiCatalogUrlProvider etsiCatalogUrlProvider;
48 public EtsiCatalogPackageManagementServiceProviderImpl(final EtsiCatalogUrlProvider etsiCatalogUrlProvider,
49 @Qualifier(ETSI_CATALOG_SERVICE_PROVIDER_BEAN) final HttpRestServiceProvider httpServiceProvider) {
50 this.etsiCatalogUrlProvider = etsiCatalogUrlProvider;
51 this.httpServiceProvider = httpServiceProvider;
55 public Optional<NsdInfo> getNSPackageModel(final String nsdId) {
57 final ResponseEntity<NsdInfo> response =
58 httpServiceProvider.getHttpResponse(etsiCatalogUrlProvider.getNsPackageUrl(nsdId), NsdInfo.class);
59 if (response.getStatusCode().is2xxSuccessful()) {
60 return Optional.ofNullable(response.getBody());
62 return Optional.empty();
63 } catch (final Exception restProcessingException) {
64 logger.error("Caught exception while getting NS package model for: {}", nsdId, restProcessingException);
65 throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.",
66 restProcessingException);
71 public Optional<VnfPkgInfo> getVnfPkgInfo(final String vnfPkgId) {
73 final ResponseEntity<VnfPkgInfo> response = httpServiceProvider
74 .getHttpResponse(etsiCatalogUrlProvider.getVnfPackageUrl(vnfPkgId), VnfPkgInfo.class);
75 if (response.getStatusCode().is2xxSuccessful()) {
76 return Optional.ofNullable(response.getBody());
78 return Optional.empty();
79 } catch (final Exception restProcessingException) {
80 logger.error("Caught exception while getting VNF package model for: {}", vnfPkgId, restProcessingException);
81 throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.",
82 restProcessingException);