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 com.nokia.vfcadaptor.nslcm.impl;
19 import java.io.IOException;
21 import org.apache.http.client.ClientProtocolException;
22 import org.apache.http.impl.client.HttpClientBuilder;
23 import org.apache.log4j.Logger;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.http.MediaType;
26 import org.springframework.stereotype.Component;
27 import org.springframework.web.bind.annotation.RequestMethod;
29 import com.google.gson.Gson;
30 import com.nokia.vfcadaptor.common.bo.AdaptorEnv;
31 import com.nokia.vfcadaptor.constant.CommonConstants;
32 import com.nokia.vfcadaptor.http.client.HttpRequestProcessor;
33 import com.nokia.vfcadaptor.nslcm.bo.NslcmGrantVnfRequest;
34 import com.nokia.vfcadaptor.nslcm.bo.NslcmGrantVnfResponse;
35 import com.nokia.vfcadaptor.nslcm.bo.NslcmNotifyLCMEventsRequest;
36 import com.nokia.vfcadaptor.nslcm.bo.VnfmInfo;
37 import com.nokia.vfcadaptor.nslcm.inf.NslcmMgmrInf;
40 public class NslcmMgmrImpl implements NslcmMgmrInf{
41 private Logger logger = Logger.getLogger(NslcmMgmrImpl.class);
44 private AdaptorEnv adaptorEnv;
47 private HttpClientBuilder httpClientBuilder;
49 private Gson gson = new Gson();
51 public VnfmInfo queryVnfm(String vnfmId) throws ClientProtocolException, IOException
53 String httpPath = String.format(CommonConstants.RetrieveNvfmListPath, vnfmId);
54 RequestMethod method = RequestMethod.GET;
56 String responseStr = operateNslcmHttpTask(null, httpPath, method);
58 logger.info("NslcmMgmrImpl->queryVnfm, the vnfmInfo is " + responseStr);
60 VnfmInfo response = gson.fromJson(responseStr, VnfmInfo.class);
65 public NslcmGrantVnfResponse grantVnf(NslcmGrantVnfRequest driverRequest) throws ClientProtocolException, IOException {
66 String httpPath = CommonConstants.NslcmGrantPath;
67 RequestMethod method = RequestMethod.POST;
69 String responseStr = operateNslcmHttpTask(driverRequest, httpPath, method);
71 logger.info("NslcmMgmrImpl->grantVnf, the NslcmGrantVnfResponse is " + responseStr);
73 NslcmGrantVnfResponse response = gson.fromJson(responseStr, NslcmGrantVnfResponse.class);
78 public void notifyVnf(NslcmNotifyLCMEventsRequest driverRequest, String vnfInstanceId) throws ClientProtocolException, IOException {
79 String httpPath = String.format(CommonConstants.NslcmNotifyPath, vnfInstanceId);
80 RequestMethod method = RequestMethod.POST;
82 operateNslcmHttpTask(driverRequest, httpPath, method);
85 public String operateNslcmHttpTask(Object httpBodyObj, String httpPath, RequestMethod method) throws ClientProtocolException, IOException {
86 String url="http://" + adaptorEnv.getNslcmIp() + ":" + adaptorEnv.getNslcmPort() + httpPath;
87 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, method);
88 processor.addHdeader(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
90 processor.addPostEntity(gson.toJson(httpBodyObj));
92 String responseStr = processor.process(url);