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.gvnfm.jujuvnfmadapter.service.adapter.impl;
21 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.servicetoken.JujuVnfmRestfulUtil;
22 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.adapter.inf.IJujuAdapter2MSBManager;
23 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.constant.Constant;
24 import org.openo.baseservice.roa.util.restclient.RestfulResponse;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import net.sf.json.JSONObject;
32 * Juju adapter to msb manager class.<br>
37 * @version NFVO 0.5 Sep 12, 2016
39 public class JujuAdapter2MSBManager implements IJujuAdapter2MSBManager {
41 private static final Logger LOG = LoggerFactory.getLogger(JujuAdapter2MSBManager.class);
44 public JSONObject registerJujuAdapter(Map<String, String> paramsMap, JSONObject adapterInfo) {
45 JSONObject resultObj = new JSONObject();
48 RestfulResponse rsp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap,adapterInfo.toString());
50 LOG.error("function=registerJujuAdapter, RestfulResponse is null");
51 resultObj.put(Constant.REASON, "RestfulResponse is null.");
52 resultObj.put(Constant.RETURN_CODE, Constant.ERROR_STATUS_CODE);
55 String resultCreate = rsp.getResponseContent();
57 if(rsp.getStatus() == Constant.HTTP_CREATED) {
58 LOG.warn("function=registerJujuAdapter, msg= status={}, result={}.", rsp.getStatus(), resultCreate);
59 resultObj = JSONObject.fromObject(resultCreate);
60 resultObj.put(Constant.RETURN_CODE, Constant.HTTP_CREATED);
62 } else if(rsp.getStatus() == Constant.INVALID_PARAMETERS){
63 LOG.error("function=registerJujuAdapter, msg=MSB return fail,invalid parameters,status={}, result={}.", rsp.getStatus(),
65 resultObj.put(Constant.REASON, "MSB return fail,invalid parameters.");
66 } else if(rsp.getStatus() == Constant.HTTP_INNERERROR){
67 LOG.error("function=registerJujuAdapter, msg=MSB return fail,internal system error,status={}, result={}.", rsp.getStatus(),
69 resultObj.put(Constant.REASON, "MSB return fail,internal system error.");
71 resultObj.put(Constant.RETURN_CODE, Constant.ERROR_STATUS_CODE);
76 public JSONObject unregisterJujuAdapter(Map<String, String> paramsMap) {
77 JSONObject resultObj = new JSONObject();
80 RestfulResponse rsp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap,"");
82 LOG.error("function=unregisterJujuAdapter, RestfulResponse is null");
83 resultObj.put(Constant.REASON, "RestfulResponse is null.");
84 resultObj.put(Constant.RETURN_CODE, Constant.ERROR_STATUS_CODE);
87 String resultCreate = rsp.getResponseContent();
89 if(rsp.getStatus() == Constant.UNREG_SUCCESS) {
90 LOG.warn("function=unregisterJujuAdapter, msg= status={}, result={}.", rsp.getStatus(), resultCreate);
91 resultObj = JSONObject.fromObject(resultCreate);
92 resultObj.put(Constant.RETURN_CODE, Constant.UNREG_SUCCESS);
94 } else if(rsp.getStatus() == Constant.HTTP_NOTFOUND){
95 LOG.error("function=unregisterJujuAdapter, msg=MSB return fail,can't find the service instance.status={}, result={}.", rsp.getStatus(),
97 resultObj.put(Constant.REASON, "MSB return fail,can't find the service instance.");
98 } else if(rsp.getStatus() == Constant.INVALID_PARAMETERS){
99 LOG.error("function=unregisterJujuAdapter, msg=MSB return fail,invalid parameters,status={}, result={}.", rsp.getStatus(),
101 resultObj.put(Constant.REASON, "MSB return fail,invalid parameters.");
102 } else if(rsp.getStatus() == Constant.HTTP_INNERERROR){
103 LOG.error("function=unregisterJujuAdapter, msg=MSB return fail,internal system error,status={}, result={}.", rsp.getStatus(),
105 resultObj.put(Constant.REASON, "MSB return fail,internal system error.");
107 resultObj.put(Constant.RETURN_CODE, Constant.ERROR_STATUS_CODE);