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