Display ESR API with swagger
[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 import javax.ws.rs.Consumes;
31 import javax.ws.rs.DELETE;
32 import javax.ws.rs.GET;
33 import javax.ws.rs.POST;
34 import javax.ws.rs.PUT;
35 import javax.ws.rs.Path;
36 import javax.ws.rs.PathParam;
37 import javax.ws.rs.Produces;
38 import javax.ws.rs.core.MediaType;
39 import javax.ws.rs.core.Response;
40
41 @Path("/vnfms")
42 @Api(tags = {" vnfm Management "})
43 public class VnfmManager {
44
45     private static final Logger LOGGER = LoggerFactory.getLogger(VnfmManager.class);
46
47     private static ExtsysUtil extsysUtil = new ExtsysUtil();
48
49     /**
50      * query all vnfm.
51      */
52     @GET
53     @ApiOperation(value = "get  all vnfm ")
54     @Produces(MediaType.APPLICATION_JSON)
55     @ApiResponses(value = {
56             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
57             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
58                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
59             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
60                     response = String.class)})
61     @Timed
62     public Response queryVnfmList() {
63         LOGGER.info("start query all vnfm!");
64         return VnfmManagerWrapper.getInstance().queryVnfmList();
65     }
66
67     /**
68      * query vnfm by id.
69      */
70     @Path("/{vnfmId}")
71     @GET
72     @ApiOperation(value = "get vnfm by id")
73     @Produces(MediaType.APPLICATION_JSON)
74     @ApiResponses(value = {
75             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
76             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
77                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
78             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
79                     response = String.class)})
80     @Timed
81     public Response queryVnfmById(@ApiParam(value = "vnfm id") @PathParam("vnfmId") String vnfmId) {
82         LOGGER.info("start query  vnfm by id." + vnfmId);
83         return VnfmManagerWrapper.getInstance().queryVnfmById(vnfmId);
84     }
85
86     /**
87      * delete vnfm by id.
88      */
89     @Path("/{vnfmId}")
90     @DELETE
91     @ApiOperation(value = "delete a vnfm")
92     @ApiResponses(value = {
93             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
94             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
95                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
96             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
97                     response = String.class)})
98     @Timed
99     public Response delVnfm(@ApiParam(value = "vnfm id") @PathParam("vnfmId") String vnfmId) {
100         LOGGER.info("start delete vnfm .id:" + vnfmId);
101         return VnfmManagerWrapper.getInstance().delVnfm(vnfmId);
102     }
103
104     /**
105      * update vnfm by id.
106      */
107     @PUT
108     @Path("/{vnfmId}")
109     @Consumes(MediaType.APPLICATION_JSON)
110     @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
111     @ApiOperation(value = "update a vnfm")
112     @ApiResponses(value = {
113             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
114             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
115                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
116             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
117                     response = String.class)})
118     @Timed
119     public Response updateVnfm(@ApiParam(value = "vnfm", required = true) VnfmRegisterInfo vnfm,
120             @ApiParam(value = "vnfm id", required = true) @PathParam("vnfmId") String vnfmId) {
121         LOGGER.info("start update vnfm .id:" + vnfmId + " info:" + extsysUtil.objectToString(vnfm));
122         return VnfmManagerWrapper.getInstance().updateVnfm(vnfm, vnfmId);
123     }
124
125     /**
126      * add vnfm .
127      */
128     @POST
129     @Consumes(MediaType.APPLICATION_JSON)
130     @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
131     @ApiOperation(value = "create a vnfm")
132     @ApiResponses(value = {
133             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
134             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
135                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
136             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
137                     response = String.class)})
138     @Timed
139     public Response registerVnfm(@ApiParam(value = "vnfm", required = true) VnfmRegisterInfo vnfm) {
140         return VnfmManagerWrapper.getInstance().registerVnfm(vnfm);
141     }
142 }