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.rest;
19 import javax.servlet.http.HttpServletRequest;
20 import javax.ws.rs.Consumes;
21 import javax.ws.rs.DELETE;
22 import javax.ws.rs.POST;
23 import javax.ws.rs.PUT;
24 import javax.ws.rs.Path;
25 import javax.ws.rs.Produces;
26 import javax.ws.rs.QueryParam;
27 import javax.ws.rs.core.Context;
28 import javax.ws.rs.core.MediaType;
30 import org.onap.vfc.nfvo.resmanagement.common.VimUtil;
31 import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant;
32 import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant;
33 import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
34 import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
35 import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil;
36 import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil;
37 import org.onap.vfc.nfvo.resmanagement.service.group.inf.ResOperateService;
38 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 import net.sf.json.JSONObject;
45 * Resource Operate ROA Class.<br>
50 * @version NFVO 0.5 Sep 10, 2016
52 @Path(UrlConstant.RESOPERATE_URL)
53 @Consumes(MediaType.APPLICATION_JSON)
54 @Produces(MediaType.APPLICATION_JSON)
55 public class ResOperateRoa {
57 private static final Logger LOGGER = LoggerFactory.getLogger(ResOperateRoa.class);
59 private ResOperateService resOperateService;
62 * Update iResource pool.<br>
68 * @throws ServiceException
72 @Path(UrlConstant.MODRES_URL)
73 @Consumes(MediaType.APPLICATION_JSON)
74 @Produces(MediaType.APPLICATION_JSON)
75 public JSONObject updateIResPool(@Context HttpServletRequest context,
76 @QueryParam(ParamConstant.PARAM_VIMID) String vimId) throws ServiceException {
77 JSONObject json = RequestUtil.getAllJsonRequestBody(context);
78 LOGGER.warn("ResPoolRoa::modVimId :{}", vimId);
79 JSONObject vimInfo = VimUtil.getVimById(vimId);
80 String tenant = vimInfo.getString("tenant");
81 String tenantId = VimUtil.getTenantIdByName(tenant, vimId);
83 resOperateService.updateIRes(tenantId, vimId, json);
84 resOperateService.sendMsgMonitor("update", vimId);
85 return RoaResponseUtil.update(HttpConstant.OK_CODE);
86 } catch(ServiceException se) {
87 LOGGER.error("ResOperateRoa::updateIResPool error:{}" + se);
88 return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());
93 * Add all resource pool.<br>
99 * @throws ServiceException
103 @Path(UrlConstant.ADDRES_URL)
104 @Consumes(UrlConstant.APPLICATION_TYPE)
105 @Produces(MediaType.APPLICATION_JSON)
106 public JSONObject addAllResPool(@Context HttpServletRequest context,
107 @QueryParam(ParamConstant.PARAM_TENANTID) String tenantId,
108 @QueryParam(ParamConstant.PARAM_VIMID) String vimId) throws ServiceException {
109 JSONObject json = RequestUtil.getAllJsonRequestBody(context);
110 LOGGER.warn("ResOperateRoa::vimId :{}", vimId);
113 resOperateService.addIRes(tenantId, vimId, json);
114 resOperateService.sendMsgMonitor("create", vimId);
115 return RoaResponseUtil.add(HttpConstant.OK_CODE);
116 } catch(ServiceException se) {
117 LOGGER.error("ResOperateRoa::addAllResPool error:{}" + se);
118 return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());
123 * Delete iResource.<br>
128 * @throws ServiceException
132 @Consumes(MediaType.APPLICATION_JSON)
133 @Produces(MediaType.APPLICATION_JSON)
134 public JSONObject deleteIRes(@Context HttpServletRequest context,
135 @QueryParam(ParamConstant.PARAM_VIMID) String vimId) throws ServiceException {
136 LOGGER.warn("ResOperateRoa::deleteIResource vimId:{}", vimId);
139 resOperateService.sendMsgMonitor("delete", vimId);
140 int result = resOperateService.deleteIRes(vimId);
141 return RoaResponseUtil.delete(result);
142 } catch(ServiceException se) {
143 LOGGER.error("ResOperateRoa::deleteIRes error:{}" + se);
144 return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());
148 public void setResOperateService(ResOperateService resOperateService) {
149 this.resOperateService = resOperateService;