2 * Copyright 2016-2017, Nokia Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
18 import org.onap.aai.model.EsrSystemInfo;
19 import org.onap.aai.model.EsrVnfm;
20 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.GenericExternalSystemInfoProvider;
21 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
22 import org.onap.vnfmdriver.model.VimInfo;
23 import org.onap.vnfmdriver.model.VnfmInfo;
24 import org.slf4j.Logger;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.context.annotation.Conditional;
27 import org.springframework.core.env.Environment;
28 import org.springframework.stereotype.Component;
30 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
31 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
32 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
33 import static org.slf4j.LoggerFactory.getLogger;
36 * Responsible for providing information related to the VNFM from VF-C source
39 @Conditional(value = Conditions.UseForDirect.class)
40 public class AAIExternalSystemInfoProvider extends GenericExternalSystemInfoProvider {
41 private static Logger logger = getLogger(AAIExternalSystemInfoProvider.class);
42 private final AAIRestApiProvider aaiRestApiProvider;
45 AAIExternalSystemInfoProvider(Environment environment, AAIRestApiProvider aaiRestApiProvider) {
47 this.aaiRestApiProvider = aaiRestApiProvider;
51 public VnfmInfo queryVnfmInfoFromSource(String vnfmId) {
52 return convertEsrToVnfmInfo(getEsrVnfm(vnfmId));
55 private EsrVnfm getEsrVnfm(String vnfmId) {
57 return aaiRestApiProvider.getExternalSystemApi().getExternalSystemEsrVnfmListEsrVnfm(vnfmId).blockingFirst();
58 } catch (Exception e) {
59 throw buildFatalFailure(logger, "Unable to query VNFM with " + vnfmId + " identifier from AAI", e);
64 public VimInfo getVimInfo(String vimId) {
65 return convertEsrToVim(getEsrSystemInfo(vimId), vimId);
69 * @param vimId the identifier of the VIM
70 * @return the VIM details
72 public EsrSystemInfo getEsrSystemInfo(String vimId) {
74 return aaiRestApiProvider.getCloudInfrastructureApi().getCloudInfrastructureCloudRegionsCloudRegion(getCloudOwner(vimId), getRegionName(vimId), null, null).blockingFirst().getEsrSystemInfoList().get(0);
75 } catch (Exception e) {
76 throw buildFatalFailure(logger, "Unable to query VIM with " + vimId + " identifier from AAI", e);
80 private VimInfo convertEsrToVim(EsrSystemInfo esrSystemInfo, String vimId) {
81 VimInfo vimInfo = new VimInfo();
82 vimInfo.setDescription(esrSystemInfo.getSystemName());
83 vimInfo.setName(esrSystemInfo.getSystemName());
84 vimInfo.setPassword(esrSystemInfo.getPassword());
85 vimInfo.setStatus(esrSystemInfo.getSystemStatus());
86 vimInfo.setType(esrSystemInfo.getType());
87 vimInfo.setUrl(esrSystemInfo.getServiceUrl());
88 vimInfo.setVersion(esrSystemInfo.getVersion());
89 if (esrSystemInfo.getSslCacert() == null) {
90 vimInfo.setSslInsecure("true");
92 vimInfo.setSslInsecure("false");
93 vimInfo.setSslCacert(esrSystemInfo.getSslCacert());
95 vimInfo.setUserName(esrSystemInfo.getUserName());
96 vimInfo.setVendor(esrSystemInfo.getVendor());
97 vimInfo.setVimId(vimId);
102 private VnfmInfo convertEsrToVnfmInfo(EsrVnfm vnfmInAai) {
103 EsrSystemInfo esrSystemInfo = vnfmInAai.getEsrSystemInfoList().get(0);
104 VnfmInfo vnfmInfo = new VnfmInfo();
105 vnfmInfo.setPassword(esrSystemInfo.getPassword());
106 vnfmInfo.setDescription(esrSystemInfo.getEsrSystemInfoId());
107 vnfmInfo.setName(esrSystemInfo.getSystemName());
108 vnfmInfo.setType(esrSystemInfo.getType());
109 vnfmInfo.setUrl(esrSystemInfo.getServiceUrl());
110 vnfmInfo.setVersion(esrSystemInfo.getVersion());
111 vnfmInfo.setVimId(vnfmInAai.getVimId());
112 vnfmInfo.setVendor(esrSystemInfo.getVendor());
113 vnfmInfo.setUserName(esrSystemInfo.getUserName());
114 vnfmInfo.setVnfmId(vnfmInAai.getVnfmId());