Removing jackson to mitigate cve-2017-4995
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / onap / direct / AAIExternalSystemInfoProvider.java
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 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;
29
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;
34
35 /**
36  * Responsible for providing information related to the VNFM from VF-C source
37  */
38 @Component
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;
43
44     @Autowired
45     AAIExternalSystemInfoProvider(Environment environment, AAIRestApiProvider aaiRestApiProvider) {
46         super(environment);
47         this.aaiRestApiProvider = aaiRestApiProvider;
48     }
49
50     @Override
51     public VnfmInfo queryVnfmInfoFromSource(String vnfmId) {
52         return convertEsrToVnfmInfo(getEsrVnfm(vnfmId));
53     }
54
55     private EsrVnfm getEsrVnfm(String vnfmId) {
56         try {
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);
60         }
61     }
62
63     @Override
64     public VimInfo getVimInfo(String vimId) {
65         return convertEsrToVim(getEsrSystemInfo(vimId), vimId);
66     }
67
68     /**
69      * @param vimId the identifier of the VIM
70      * @return the VIM details
71      */
72     public EsrSystemInfo getEsrSystemInfo(String vimId) {
73         try {
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);
77         }
78     }
79
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");
91         } else {
92             vimInfo.setSslInsecure("false");
93             vimInfo.setSslCacert(esrSystemInfo.getSslCacert());
94         }
95         vimInfo.setUserName(esrSystemInfo.getUserName());
96         vimInfo.setVendor(esrSystemInfo.getVendor());
97         vimInfo.setVimId(vimId);
98         return vimInfo;
99     }
100
101
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());
115         return vnfmInfo;
116     }
117 }