4a76a90a41a1f6f96cf6a27d4853bdc3ffa527d2
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / resource / VnfmManager.java
1 /**
2  * Copyright 2016-2017 ZTE Corporation.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.aai.esr.resource;
17
18 import com.codahale.metrics.annotation.Timed;
19 import io.swagger.annotations.Api;
20 import io.swagger.annotations.ApiOperation;
21 import io.swagger.annotations.ApiParam;
22 import io.swagger.annotations.ApiResponse;
23 import io.swagger.annotations.ApiResponses;
24 import org.eclipse.jetty.http.HttpStatus;
25 import org.onap.aai.esr.entity.rest.VnfmRegisterInfo;
26 import org.onap.aai.esr.util.ExtsysUtil;
27 import org.onap.aai.esr.wrapper.VnfmManagerWrapper;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 import javax.ws.rs.Consumes;
32 import javax.ws.rs.DELETE;
33 import javax.ws.rs.GET;
34 import javax.ws.rs.POST;
35 import javax.ws.rs.PUT;
36 import javax.ws.rs.Path;
37 import javax.ws.rs.PathParam;
38 import javax.ws.rs.Produces;
39 import javax.ws.rs.core.MediaType;
40 import javax.ws.rs.core.Response;
41
42 @Path("/vnfms")
43 @Api(tags = {" vnfm Management "})
44 public class VnfmManager {
45
46   private static final Logger LOGGER = LoggerFactory.getLogger(VnfmManager.class);
47
48   private static ExtsysUtil extsysUtil = new ExtsysUtil();
49   
50   /**
51    * query all vnfm.
52    */
53   @GET
54   @ApiOperation(value = "get  all vnfm ")
55   @Produces(MediaType.APPLICATION_JSON)
56   @ApiResponses(value = {
57       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
58           response = String.class),
59       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
60           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
61       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
62           response = String.class)})
63   @Timed
64   public Response queryVnfmList() {
65     LOGGER.info("start query all vnfm!");
66     return VnfmManagerWrapper.getInstance().queryVnfmList();
67   }
68   
69   /**
70    * query  vnfm by id.
71    */
72   @Path("/{vnfmId}")
73   @GET
74   @ApiOperation(value = "get vnfm by id")
75   @Produces(MediaType.APPLICATION_JSON)
76   @ApiResponses(value = {
77       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
78           response = String.class),
79       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
80           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
81       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
82           response = String.class)})
83   @Timed
84   public Response queryVnfmById(@ApiParam(value = "vnfm id") @PathParam("vnfmId") String vnfmId) {
85     LOGGER.info("start query  vnfm by id." + vnfmId);
86     return VnfmManagerWrapper.getInstance().queryVnfmById(vnfmId);
87   }
88   
89   /**
90    * delete  vnfm by id.
91    */
92   @Path("/{vnfmId}")
93   @DELETE
94   @ApiOperation(value = "delete a vnfm")
95   @ApiResponses(value = {
96       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
97           response = String.class),
98       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
99           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
100       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
101           response = String.class)})
102   @Timed
103   public Response delVnfm(@ApiParam(value = "vnfm id") @PathParam("vnfmId") String vnfmId) {
104     LOGGER.info("start delete vnfm .id:" + vnfmId);
105     return VnfmManagerWrapper.getInstance().delVnfm(vnfmId);
106   }
107   
108   /**
109    * update  vnfm by id.
110    */
111   @PUT
112   @Path("/{vnfmId}")
113   @Consumes(MediaType.APPLICATION_JSON)
114   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
115   @ApiOperation(value = "update a vnfm")
116   @ApiResponses(value = {
117       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
118           response = String.class),
119       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
120           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
121       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
122           response = String.class)})
123   @Timed
124   public Response updateVnfm(@ApiParam(value = "vnfm", required = true) VnfmRegisterInfo vnfm,
125       @ApiParam(value = "vnfm id", required = true) @PathParam("vnfmId") String vnfmId) {
126     LOGGER.info("start update vnfm .id:" + vnfmId + " info:" + extsysUtil.objectToString(vnfm));
127     return VnfmManagerWrapper.getInstance().updateVnfm(vnfm, vnfmId);
128   }
129   
130   /**
131    * add  vnfm .
132    */
133   @POST
134   @Consumes(MediaType.APPLICATION_JSON)
135   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
136   @ApiOperation(value = "create a vnfm")
137   @ApiResponses(value = {
138       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
139           response = String.class),
140       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
141           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
142       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
143           response = String.class)})
144   @Timed
145   public Response registerVnfm(@ApiParam(value = "vnfm", required = true) VnfmRegisterInfo vnfm) {
146     return VnfmManagerWrapper.getInstance().registerVnfm(vnfm);
147   }
148 }