2 * Copyright 2016 Huawei Technologies Co., Ltd.
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.vnfm.svnfm.vnfmadapter.service.adapter.impl;
21 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VNFRestfulUtil;
22 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.adapter.inf.IDriver2MSBManager;
23 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
24 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.RestfulResponse;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import net.sf.json.JSONObject;
32 * Driver to MSB Manager Class.<br/>
37 * @version VFC 1.0 Aug 29, 2016
39 public class Driver2MSBManager implements IDriver2MSBManager {
41 private static final Logger LOG = LoggerFactory.getLogger(Driver2MSBManager.class);
44 public JSONObject registerDriver(Map<String, String> paramsMap, JSONObject driverInfo) {
45 JSONObject resultObj = new JSONObject();
47 RestfulResponse rsp = VNFRestfulUtil.getRemoteResponse(paramsMap, driverInfo.toString());
49 LOG.error("function=registerDriver, RestfulResponse is null");
50 resultObj.put("reason", "RestfulResponse is null.");
51 resultObj.put("retCode", Constant.REST_FAIL);
54 String resultCreate = rsp.getResponseContent();
56 if(rsp.getStatus() == Constant.HTTP_CREATED) {
57 LOG.warn("function=registerDriver, msg= status={}, result={}.", rsp.getStatus(), resultCreate);
58 resultObj = JSONObject.fromObject(resultCreate);
59 resultObj.put("retCode", Constant.HTTP_CREATED);
61 } else if(rsp.getStatus() == Constant.HTTP_INVALID_PARAMETERS) {
62 LOG.error("function=registerDriver, msg=MSB return fail,invalid parameters,status={}, result={}.",
63 rsp.getStatus(), resultCreate);
64 resultObj.put("reason", "MSB return fail,invalid parameters.");
65 } else if(rsp.getStatus() == Constant.HTTP_INNERERROR) {
66 LOG.error("function=registerDriver, msg=MSB return fail,internal system error,status={}, result={}.",
67 rsp.getStatus(), resultCreate);
68 resultObj.put("reason", "MSB return fail,internal system error.");
70 resultObj.put("retCode", Constant.REST_FAIL);
75 public JSONObject unregisterDriver(Map<String, String> paramsMap) {
76 JSONObject resultObj = new JSONObject();
78 RestfulResponse rsp = VNFRestfulUtil.getRemoteResponse(paramsMap, "");
80 LOG.error("function=unregisterDriver, RestfulResponse is null");
81 resultObj.put("reason", "RestfulResponse is null.");
82 resultObj.put("retCode", Constant.REST_FAIL);
85 String resultCreate = rsp.getResponseContent();
87 if(rsp.getStatus() == Constant.HTTP_NOCONTENT) {
88 LOG.warn("function=unregisterDriver, msg= status={}, result={}.", rsp.getStatus(), resultCreate);
89 resultObj = JSONObject.fromObject(resultCreate);
90 resultObj.put("retCode", Constant.HTTP_NOCONTENT);
92 } else if(rsp.getStatus() == Constant.HTTP_NOTFOUND) {
94 "function=unregisterDriver, msg=MSB return fail,can't find the service instance.status={}, result={}.",
95 rsp.getStatus(), resultCreate);
96 resultObj.put("reason", "MSB return fail,can't find the service instance.");
97 } else if(rsp.getStatus() == Constant.HTTP_INVALID_PARAMETERS) {
98 LOG.error("function=unregisterDriver, msg=MSB return fail,invalid parameters,status={}, result={}.",
99 rsp.getStatus(), resultCreate);
100 resultObj.put("reason", "MSB return fail,invalid parameters.");
101 } else if(rsp.getStatus() == Constant.HTTP_INNERERROR) {
102 LOG.error("function=unregisterDriver, msg=MSB return fail,internal system error,status={}, result={}.",
103 rsp.getStatus(), resultCreate);
104 resultObj.put("reason", "MSB return fail,internal system error.");
106 resultObj.put("retCode", Constant.REST_FAIL);