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.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.impl;
19 import java.io.IOException;
20 import java.util.HashMap;
22 import org.apache.http.client.ClientProtocolException;
23 import org.apache.http.impl.client.HttpClientBuilder;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor;
30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest;
31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse;
32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmNotifyLCMEventsRequest;
33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.VnfmInfo;
34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.http.MediaType;
37 import org.springframework.stereotype.Component;
38 import org.springframework.web.bind.annotation.RequestMethod;
40 import com.google.gson.Gson;
43 public class NslcmMgmrImpl implements NslcmMgmrInf{
44 private static final Logger logger = LoggerFactory.getLogger(NslcmMgmrImpl.class);
47 private AdaptorEnv adaptorEnv;
50 HttpClientProcessorInf httpClientProcessor;
52 private Gson gson = new Gson();
55 // public VnfmInfo queryVnfm(String vnfmId) throws ClientProtocolException, IOException
57 // String httpPath = String.format(CommonConstants.RetrieveVnfmListPath, vnfmId);
58 // RequestMethod method = RequestMethod.GET;
60 // String responseStr = operateNslcmHttpTask(null, httpPath, method);
62 // logger.info("NslcmMgmrImpl->queryVnfm, the vnfmInfo is {}", responseStr);
64 // VnfmInfo response = gson.fromJson(responseStr, VnfmInfo.class);
69 public NslcmGrantVnfResponse grantVnf(NslcmGrantVnfRequest driverRequest) throws ClientProtocolException, IOException {
70 String httpPath = CommonConstants.NslcmGrantPath;
71 RequestMethod method = RequestMethod.POST;
73 String responseStr = operateNslcmHttpTask(driverRequest, httpPath, method);
75 logger.info("NslcmMgmrImpl->grantVnf, the NslcmGrantVnfResponse is {}", responseStr);
77 NslcmGrantVnfResponse response = gson.fromJson(responseStr, NslcmGrantVnfResponse.class);
82 public void notifyVnf(NslcmNotifyLCMEventsRequest driverRequest, String vnfInstanceId) throws ClientProtocolException, IOException {
83 String httpPath = String.format(CommonConstants.NslcmNotifyPath, vnfInstanceId);
84 RequestMethod method = RequestMethod.POST;
86 operateNslcmHttpTask(driverRequest, httpPath, method);
89 private String operateNslcmHttpTask(Object httpBodyObj, String httpPath, RequestMethod method) throws ClientProtocolException, IOException {
90 String url=adaptorEnv.getLcmApiUriFront() + httpPath;
92 HashMap<String, String> map = new HashMap<String, String>();
93 map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
95 String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj));
100 public void setAdaptorEnv(AdaptorEnv env) {
101 this.adaptorEnv = env;