2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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=========================================================
21 package org.onap.so.adapters.vnfmadapter.extclients.aai;
23 import org.onap.aai.domain.yang.*;
24 import org.onap.so.client.aai.AAIObjectType;
25 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
26 import org.onap.vnfmadapter.v1.model.Tenant;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Service;
31 import java.util.List;
34 public class AaiServiceProviderImpl implements AaiServiceProvider {
36 private static final Logger logger = LoggerFactory.getLogger(AaiServiceProviderImpl.class);
37 private final AaiClientProvider aaiClientProvider;
40 public AaiServiceProviderImpl(final AaiClientProvider aaiClientProvider) {
41 this.aaiClientProvider = aaiClientProvider;
45 public GenericVnf invokeGetGenericVnf(final String vnfId) {
46 return aaiClientProvider.getAaiClient()
47 .get(GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId))
49 logger.debug("No vnf found in AAI with ID: {}", vnfId);
55 public List<GenericVnf> invokeQueryGenericVnf(final String selfLink) {
56 return aaiClientProvider.getAaiClient()
58 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNFS).queryParam("selflink", selfLink))
60 logger.debug("No vnf found in AAI with selflink: {}", selfLink);
66 public EsrVnfmList invokeGetVnfms() {
67 return aaiClientProvider.getAaiClient()
68 .get(EsrVnfmList.class, AAIUriFactory.createResourceUri(AAIObjectType.VNFM_LIST)).orElseGet(() -> {
69 logger.debug("No VNFMs in AAI");
75 public EsrVnfm invokeGetVnfm(final String vnfmId) {
76 return aaiClientProvider.getAaiClient()
77 .get(EsrVnfm.class, AAIUriFactory.createResourceUri(AAIObjectType.VNFM, vnfmId)).orElseGet(() -> {
78 logger.debug("VNFM not found in AAI");
84 public EsrSystemInfoList invokeGetVnfmEsrSystemInfoList(final String vnfmId) {
85 return aaiClientProvider.getAaiClient()
86 .get(EsrSystemInfoList.class,
87 AAIUriFactory.createResourceUri(AAIObjectType.VNFM_ESR_SYSTEM_INFO_LIST, vnfmId))
89 logger.debug("VNFM ESR system info list not found in AAI");
95 public void invokePutGenericVnf(final GenericVnf vnf) {
96 aaiClientProvider.getAaiClient()
97 .update(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId()), vnf);
101 public void invokePutVserver(final String cloudOwner, final String cloudRegion, final String tenant,
102 final Vserver vserver) {
103 aaiClientProvider.getAaiClient().update(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner,
104 cloudRegion, tenant, vserver.getVserverId()), vserver);
108 public void invokeDeleteVserver(final String cloudOwner, final String cloudRegion, final String tenant,
109 final String vserverId) {
110 aaiClientProvider.getAaiClient().delete(
111 AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion, tenant, vserverId));
115 public Tenant invokeGetTenant(final String cloudOwner, final String cloudRegion, final String tenantId) {
116 return aaiClientProvider.getAaiClient()
118 AAIUriFactory.createResourceUri(AAIObjectType.TENANT, cloudOwner, cloudRegion, tenantId))
120 logger.debug("Tenant not found in AAI");
126 public EsrSystemInfoList invokeGetCloudRegionEsrSystemInfoList(final String cloudOwner, final String cloudRegion) {
127 return aaiClientProvider
128 .getAaiClient().get(EsrSystemInfoList.class, AAIUriFactory
129 .createResourceUri(AAIObjectType.CLOUD_ESR_SYSTEM_INFO_LIST, cloudOwner, cloudRegion))
131 logger.debug("Cloud esr system info list not found in AAI");