2 * Copyright 2016-2017 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.resmanagement.service.adapter.impl;
21 import org.onap.vfc.nfvo.resmanagement.common.constant.Constant;
22 import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant;
23 import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
24 import org.onap.vfc.nfvo.resmanagement.service.adapter.inf.IResmgrAdapter2MSBManager;
25 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulResponse;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import net.sf.json.JSONObject;
37 * @version VFC 1.0 Sep 22, 2016
39 public class ResmgrAdapter2MSBManager implements IResmgrAdapter2MSBManager {
41 private static final Logger LOG = LoggerFactory.getLogger(ResmgrAdapter2MSBManager.class);
44 public JSONObject registerResmgr(Map<String, String> paramsMap, JSONObject driverInfo) {
45 JSONObject resultObj = new JSONObject();
47 RestfulResponse rsp = RestfulUtil.getRemoteResponse(paramsMap, driverInfo.toString());
49 LOG.error("function=registerResmgr, RestfulResponse is null");
50 resultObj.put("reason", "RestfulResponse is null.");
51 resultObj.put("retCode", Constant.ERROR_CODE);
54 LOG.warn("function=registerResmgr, status={}, content={}.", rsp.getStatus(), rsp.getResponseContent());
55 String resultCreate = rsp.getResponseContent();
57 if(rsp.getStatus() == HttpConstant.HTTP_CREATED) {
58 LOG.warn("function=registerResmgr, msg= status={}, result={}.", rsp.getStatus(), resultCreate);
59 resultObj = JSONObject.fromObject(resultCreate);
60 resultObj.put("retCode", HttpConstant.HTTP_CREATED);
62 } else if(rsp.getStatus() == HttpConstant.HTTP_INVALID_PARAMETERS) {
63 LOG.error("function=registerResmgr, msg=MSB return fail,invalid parameters,status={}, result={}.",
64 rsp.getStatus(), resultCreate);
65 resultObj.put("reason", "MSB return fail,invalid parameters.");
66 } else if(rsp.getStatus() == HttpConstant.HTTP_INNERERROR_CODE) {
67 LOG.error("function=registerResmgr, msg=MSB return fail,internal system error,status={}, result={}.",
68 rsp.getStatus(), resultCreate);
69 resultObj.put("reason", "MSB return fail,internal system error.");
71 resultObj.put("retCode", Constant.ERROR_CODE);
76 public JSONObject unregisterResmgr(Map<String, String> paramsMap) {
77 JSONObject resultObj = new JSONObject();
79 RestfulResponse rsp = RestfulUtil.getRemoteResponse(paramsMap, "");
81 LOG.error("function=unregisterResmgr, RestfulResponse is null");
82 resultObj.put("reason", "RestfulResponse is null.");
83 resultObj.put("retCode", Constant.ERROR_CODE);
86 String resultCreate = rsp.getResponseContent();
88 if(rsp.getStatus() == HttpConstant.HTTP_NOCONTENT) {
89 LOG.warn("function=unregisterResmgr, msg= status={}, result={}.", rsp.getStatus(), resultCreate);
90 resultObj = JSONObject.fromObject(resultCreate);
91 resultObj.put("retCode", HttpConstant.HTTP_NOCONTENT);
93 } else if(rsp.getStatus() == HttpConstant.HTTP_NOTFOUND_CODE) {
95 "function=unregisterResmgr, msg=MSB return fail,can't find the service instance.status={}, result={}.",
96 rsp.getStatus(), resultCreate);
97 resultObj.put("reason", "MSB return fail,can't find the service instance.");
98 } else if(rsp.getStatus() == HttpConstant.HTTP_INVALID_PARAMETERS) {
99 LOG.error("function=unregisterResmgr, msg=MSB return fail,invalid parameters,status={}, result={}.",
100 rsp.getStatus(), resultCreate);
101 resultObj.put("reason", "MSB return fail,invalid parameters.");
102 } else if(rsp.getStatus() == HttpConstant.HTTP_INNERERROR_CODE) {
103 LOG.error("function=unregisterResmgr, msg=MSB return fail,internal system error,status={}, result={}.",
104 rsp.getStatus(), resultCreate);
105 resultObj.put("reason", "MSB return fail,internal system error.");
107 resultObj.put("retCode", Constant.ERROR_CODE);