fb4de3f2fccfbb7bae89f28a7fbab1ae1c7c2d66
[vfc/nfvo/driver/vnfm/svnfm.git] /
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
17
18 import java.util.Set;
19 import org.onap.aai.model.EsrSystemInfo;
20 import org.onap.aai.model.EsrVnfm;
21 import org.onap.aai.model.EsrVnfmList;
22 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.GenericExternalSystemInfoProvider;
23 import org.onap.vnfmdriver.model.VimInfo;
24 import org.onap.vnfmdriver.model.VnfmInfo;
25 import org.slf4j.Logger;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.beans.factory.annotation.Qualifier;
28 import org.springframework.core.env.Environment;
29 import org.springframework.stereotype.Component;
30
31 import static com.google.common.collect.Iterables.transform;
32 import static com.google.common.collect.Sets.newHashSet;
33 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
34 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
35 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
36 import static org.slf4j.LoggerFactory.getLogger;
37
38 /**
39  * Responsible for providing information related to the VNFM from VF-C source
40  */
41 @Component
42 @Qualifier("so")
43 public class AAIExternalSystemInfoProvider extends GenericExternalSystemInfoProvider {
44     private static Logger logger = getLogger(AAIExternalSystemInfoProvider.class);
45     private final AAIRestApiProvider aaiRestApiProvider;
46
47     @Autowired
48     AAIExternalSystemInfoProvider(Environment environment, AAIRestApiProvider aaiRestApiProvider) {
49         super(environment);
50         this.aaiRestApiProvider = aaiRestApiProvider;
51     }
52
53     @Override
54     public VnfmInfo queryVnfmInfoFromSource(String vnfmId) {
55         return convertEsrToVnfmInfo(getEsrVnfm(vnfmId));
56     }
57
58     private EsrVnfm getEsrVnfm(String vnfmId) {
59         try {
60             return aaiRestApiProvider.getExternalSystemApi().getExternalSystemEsrVnfmListEsrVnfm(vnfmId).blockingFirst();
61         } catch (Exception e) {
62             throw buildFatalFailure(logger, "Unable to query VNFM with " + vnfmId + " identifier from AAI", e);
63         }
64     }
65
66     @Override
67     public VimInfo getVimInfo(String vimId) {
68         return convertEsrToVim(getEsrSystemInfo(vimId), vimId);
69     }
70
71     /**
72      * @param vimId the identifier of the VIM
73      * @return the VIM details
74      */
75     public EsrSystemInfo getEsrSystemInfo(String vimId) {
76         try {
77             return aaiRestApiProvider.getCloudInfrastructureApi().getCloudInfrastructureCloudRegionsCloudRegion(getCloudOwner(vimId), getRegionName(vimId), null, null).blockingFirst().getEsrSystemInfoList().get(0);
78         } catch (Exception e) {
79             throw buildFatalFailure(logger, "Unable to query VIM with " + vimId + " identifier from AAI", e);
80         }
81     }
82
83     private VimInfo convertEsrToVim(EsrSystemInfo esrSystemInfo, String vimId) {
84         VimInfo vimInfo = new VimInfo();
85         vimInfo.setDescription(esrSystemInfo.getSystemName());
86         vimInfo.setName(esrSystemInfo.getSystemName());
87         vimInfo.setPassword(esrSystemInfo.getPassword());
88         vimInfo.setStatus(esrSystemInfo.getSystemStatus());
89         vimInfo.setType(esrSystemInfo.getType());
90         vimInfo.setUrl(esrSystemInfo.getServiceUrl());
91         vimInfo.setVersion(esrSystemInfo.getVersion());
92         if (esrSystemInfo.getSslCacert() == null) {
93             vimInfo.setSslInsecure("true");
94         } else {
95             vimInfo.setSslInsecure("false");
96             vimInfo.setSslCacert(esrSystemInfo.getSslCacert());
97         }
98         vimInfo.setUserName(esrSystemInfo.getUserName());
99         vimInfo.setVendor(esrSystemInfo.getVendor());
100         vimInfo.setVimId(vimId);
101         return vimInfo;
102     }
103
104
105     private VnfmInfo convertEsrToVnfmInfo(EsrVnfm vnfmInAai) {
106         EsrSystemInfo esrSystemInfo = vnfmInAai.getEsrSystemInfoList().get(0);
107         VnfmInfo vnfmInfo = new VnfmInfo();
108         vnfmInfo.setPassword(esrSystemInfo.getPassword());
109         vnfmInfo.setDescription(esrSystemInfo.getEsrSystemInfoId());
110         vnfmInfo.setName(esrSystemInfo.getSystemName());
111         vnfmInfo.setType(esrSystemInfo.getType());
112         vnfmInfo.setUrl(esrSystemInfo.getServiceUrl());
113         vnfmInfo.setVersion(esrSystemInfo.getVersion());
114         vnfmInfo.setVimId(vnfmInAai.getVimId());
115         vnfmInfo.setVendor(esrSystemInfo.getVendor());
116         vnfmInfo.setUserName(esrSystemInfo.getUserName());
117         vnfmInfo.setVnfmId(vnfmInAai.getVnfmId());
118         return vnfmInfo;
119     }
120
121     @Override
122     public Set<String> getVnfms() {
123         EsrVnfmList esrVnfmList = aaiRestApiProvider.getExternalSystemApi().getExternalSystemEsrVnfmList().blockingFirst();
124         return newHashSet(transform(esrVnfmList.getEsrVnfm(), esr -> esr.getVnfmId()));
125     }
126 }