019a08af78be5b99f3d3d282fddfc89e5f4bb2de
[so.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.vnfmadapter.extclients.aai;
22
23 import org.onap.aai.domain.yang.EsrSystemInfoList;
24 import org.onap.aai.domain.yang.EsrVnfm;
25 import org.onap.aai.domain.yang.EsrVnfmList;
26 import org.onap.aai.domain.yang.GenericVnf;
27 import org.onap.aai.domain.yang.GenericVnfs;
28 import org.onap.aai.domain.yang.Vserver;
29 import org.onap.so.client.aai.AAIObjectType;
30 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
31 import org.onap.so.client.graphinventory.entities.uri.Depth;
32 import org.onap.vnfmadapter.v1.model.Tenant;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Service;
37
38 @Service
39 public class AaiServiceProviderImpl implements AaiServiceProvider {
40
41     private static final Logger logger = LoggerFactory.getLogger(AaiServiceProviderImpl.class);
42     private final AaiClientProvider aaiClientProvider;
43
44     @Autowired
45     public AaiServiceProviderImpl(final AaiClientProvider aaiClientProvider) {
46         this.aaiClientProvider = aaiClientProvider;
47     }
48
49     @Override
50     public GenericVnf invokeGetGenericVnf(final String vnfId) {
51         return aaiClientProvider.getAaiClient()
52                 .get(GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId))
53                 .orElseGet(() -> {
54                     logger.debug("No vnf found in AAI with ID: {}", vnfId);
55                     return null;
56                 });
57     }
58
59     @Override
60     public GenericVnfs invokeQueryGenericVnf(final String selfLink) {
61         return aaiClientProvider.getAaiClient()
62                 .get(GenericVnfs.class,
63                         AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNFS).queryParam("selflink", selfLink))
64                 .orElseGet(() -> {
65                     logger.debug("No vnf found in AAI with selflink: {}", selfLink);
66                     return null;
67                 });
68     }
69
70     @Override
71     public EsrVnfmList invokeGetVnfms() {
72         return aaiClientProvider.getAaiClient()
73                 .get(EsrVnfmList.class, AAIUriFactory.createResourceUri(AAIObjectType.VNFM_LIST)).orElseGet(() -> {
74                     logger.debug("No VNFMs in AAI");
75                     return null;
76                 });
77     }
78
79     @Override
80     public EsrVnfm invokeGetVnfm(final String vnfmId) {
81         return aaiClientProvider.getAaiClient()
82                 .get(EsrVnfm.class, AAIUriFactory.createResourceUri(AAIObjectType.VNFM, vnfmId).depth(Depth.ONE))
83                 .orElseGet(() -> {
84                     logger.debug("VNFM not found in AAI");
85                     return null;
86                 });
87     }
88
89     @Override
90     public EsrSystemInfoList invokeGetVnfmEsrSystemInfoList(final String vnfmId) {
91         return aaiClientProvider.getAaiClient()
92                 .get(EsrSystemInfoList.class,
93                         AAIUriFactory.createResourceUri(AAIObjectType.VNFM_ESR_SYSTEM_INFO_LIST, vnfmId))
94                 .orElseGet(() -> {
95                     logger.debug("VNFM ESR system info list not found in AAI");
96                     return null;
97                 });
98     }
99
100     @Override
101     public void invokePutGenericVnf(final GenericVnf vnf) {
102         aaiClientProvider.getAaiClient()
103                 .update(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId()), vnf);
104     }
105
106     @Override
107     public void invokePutVserver(final String cloudOwner, final String cloudRegion, final String tenant,
108             final Vserver vserver) {
109         aaiClientProvider.getAaiClient().create(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner,
110                 cloudRegion, tenant, vserver.getVserverId()), vserver);
111     }
112
113     @Override
114     public void invokeDeleteVserver(final String cloudOwner, final String cloudRegion, final String tenant,
115             final String vserverId) {
116         aaiClientProvider.getAaiClient().delete(
117                 AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion, tenant, vserverId));
118     }
119
120     @Override
121     public Tenant invokeGetTenant(final String cloudOwner, final String cloudRegion, final String tenantId) {
122         return aaiClientProvider.getAaiClient()
123                 .get(Tenant.class,
124                         AAIUriFactory.createResourceUri(AAIObjectType.TENANT, cloudOwner, cloudRegion, tenantId))
125                 .orElseGet(() -> {
126                     logger.debug("Tenant not found in AAI");
127                     return null;
128                 });
129     }
130
131     @Override
132     public EsrSystemInfoList invokeGetCloudRegionEsrSystemInfoList(final String cloudOwner, final String cloudRegion) {
133         return aaiClientProvider
134                 .getAaiClient().get(EsrSystemInfoList.class, AAIUriFactory
135                         .createResourceUri(AAIObjectType.CLOUD_ESR_SYSTEM_INFO_LIST, cloudOwner, cloudRegion))
136                 .orElseGet(() -> {
137                     logger.debug("Cloud esr system info list not found in AAI");
138                     return null;
139                 });
140     }
141
142 }