Fix the sonar issue of esr-server.
[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.VnfmRestData;
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   /**
49    * query all vnfm.
50    */
51   @Path("")
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",
57           response = String.class),
58       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
59           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
60       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
61           response = String.class)})
62   @Timed
63   public Response queryVnfmList() {
64     LOGGER.info("start query all vnfm!");
65     return VnfmManagerWrapper.getInstance().queryVnfmList();
66   }
67   
68   /**
69    * query  vnfm by id.
70    */
71   @Path("/{vnfmId}")
72   @GET
73   @ApiOperation(value = "get vnfm by id")
74   @Produces(MediaType.APPLICATION_JSON)
75   @ApiResponses(value = {
76       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
77           response = String.class),
78       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
79           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
80       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
81           response = String.class)})
82   @Timed
83   public Response queryVnfmById(@ApiParam(value = "vnfm id") @PathParam("vnfmId") String vnfmId) {
84     LOGGER.info("start query  vnfm by id." + vnfmId);
85     return VnfmManagerWrapper.getInstance().queryVnfmById(vnfmId);
86   }
87   
88   /**
89    * delete  vnfm by id.
90    */
91   @Path("/{vnfmId}")
92   @DELETE
93   @ApiOperation(value = "delete a vnfm")
94   @ApiResponses(value = {
95       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
96           response = String.class),
97       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
98           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
99       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
100           response = String.class)})
101   @Timed
102   public Response delVnfm(@ApiParam(value = "vnfm id") @PathParam("vnfmId") String vnfmId) {
103     LOGGER.info("start delete vnfm .id:" + vnfmId);
104     return VnfmManagerWrapper.getInstance().delVnfm(vnfmId);
105   }
106   
107   /**
108    * update  vnfm by id.
109    */
110   @PUT
111   @Path("/{vnfmId}")
112   @Consumes(MediaType.APPLICATION_JSON)
113   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
114   @ApiOperation(value = "update a vnfm")
115   @ApiResponses(value = {
116       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
117           response = String.class),
118       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
119           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
120       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
121           response = String.class)})
122   @Timed
123   public Response updateVnfm(@ApiParam(value = "vnfm", required = true) VnfmRestData vnfm,
124       @ApiParam(value = "vnfm id", required = true) @PathParam("vnfmId") String vnfmId) {
125     LOGGER.info("start update vnfm .id:" + vnfmId + " info:" + ExtsysUtil.objectToString(vnfm));
126     return VnfmManagerWrapper.getInstance().updateVnfm(vnfm, vnfmId);
127   }
128   
129   /**
130    * add  vnfm .
131    */
132   @POST
133   @Path("")
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) VnfmRestData vnfm) {
146     return VnfmManagerWrapper.getInstance().registerVnfm(vnfm);
147   }
148 }