Update docker image to fix CSIT failure
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / aai / impl / AaiMgmrInfImpl.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
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.impl;
18
19 import java.io.IOException;
20 import java.util.HashMap;
21
22 import org.apache.commons.codec.binary.Base64;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.AaiVnfmInfo;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.inf.AaiMgmrInf;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Component;
32 import org.springframework.web.bind.annotation.RequestMethod;
33
34 import com.google.gson.Gson;
35
36 @Component
37 public class AaiMgmrInfImpl implements AaiMgmrInf{
38         private static final Logger logger = LoggerFactory.getLogger(AaiMgmrInfImpl.class);
39         
40         @Autowired 
41         private AdaptorEnv adaptorEnv;
42         
43         @Autowired
44         HttpClientProcessorInf httpClientProcessor;
45         
46         private Gson gson = new Gson();
47         @Override
48         public AaiVnfmInfo queryVnfm(String vnfmId) throws IOException {
49                 String httpPath = String.format(CommonConstants.RetrieveVnfmListPath, vnfmId);
50                 RequestMethod method = RequestMethod.GET;
51                 
52                 String responseStr = operateHttpTask(null, httpPath, method);
53                 
54                 logger.info("AaiMgmrInfImpl->queryVnfm, the vnfmInfo is {}", responseStr);
55                 
56                 return gson.fromJson(responseStr, AaiVnfmInfo.class);
57         }
58         
59         private String operateHttpTask(Object httpBodyObj, String httpPath, RequestMethod method) throws IOException {
60                 String url=adaptorEnv.getAaiApiUriFront() + httpPath;
61                 
62                 HashMap<String, String> headerMap = new HashMap<>();
63                 headerMap.put("Content-Type", "application/json");
64         headerMap.put("Accept", "application/json");
65         headerMap.put("X-TransactionId", "9999");
66         headerMap.put("X-FromAppId", "esr-server");
67
68         Base64 token = new Base64();
69         String authen = new String(token.encode(("AAI:AAI").getBytes()));
70         headerMap.put("Authorization", "Basic " + authen);
71         logger.info("getVimById headerMap: {}", headerMap.toString());
72                 
73                 return httpClientProcessor.process(url, method, headerMap, gson.toJson(httpBodyObj)).getContent();
74         }
75
76         public void setAdaptorEnv(AdaptorEnv env) {
77                 this.adaptorEnv = env;
78         }
79 }