Add swagger.json to main/resources.
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / resource / VimManager.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.ApiResponse;
22 import io.swagger.annotations.ApiResponses;
23 import io.swagger.annotations.SwaggerDefinition;
24
25 import org.eclipse.jetty.http.HttpStatus;
26 import org.onap.aai.esr.entity.rest.VimRegisterInfo;
27 import org.onap.aai.esr.util.ExtsysUtil;
28 import org.onap.aai.esr.wrapper.VimManagerWrapper;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 import javax.ws.rs.Consumes;
33 import javax.ws.rs.DELETE;
34 import javax.ws.rs.GET;
35 import javax.ws.rs.POST;
36 import javax.ws.rs.PUT;
37 import javax.ws.rs.Path;
38 import javax.ws.rs.PathParam;
39 import javax.ws.rs.Produces;
40 import javax.ws.rs.core.MediaType;
41 import javax.ws.rs.core.Response;
42
43 @SwaggerDefinition
44 @Path("/vims")
45 @Api(tags = {" vim Management "})
46 public class VimManager {
47
48   private static final Logger LOGGER = LoggerFactory.getLogger(VimManager.class);
49
50   private static ExtsysUtil extsysUtil = new ExtsysUtil();
51   
52   /**
53    * query all VIM.
54    */
55   @GET
56   @ApiOperation(value = "get  all vim ")
57   @Produces(MediaType.APPLICATION_JSON)
58   @ApiResponses(value = {
59       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
60           response = String.class),
61       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
62           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
63       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
64           response = String.class)})
65   @Timed
66   public Response queryVimList() {
67     return VimManagerWrapper.getInstance().queryVimListDetails();
68   }
69
70   /**
71    * query vim by id.
72    */
73   @Path("/{cloudOwner}/{cloudRegionId}")
74   @GET
75   @ApiOperation(value = "get vim by id")
76   @Produces(MediaType.APPLICATION_JSON)
77   @ApiResponses(value = {
78       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
79           response = String.class),
80       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
81           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
82       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
83           response = String.class)})
84   @Timed
85   public Response queryVimById(@PathParam("cloudOwner") String cloudOwner, @PathParam("cloudRegionId") String cloudRegionId) {
86     LOGGER.info("start query vim by cloud owner and cloud region id." + cloudOwner +"," + cloudRegionId);
87     return VimManagerWrapper.getInstance().queryVimById(cloudOwner, cloudRegionId);
88   }
89   
90   /**
91    * delete vim by id.
92    */
93   @Path("/{cloudOwner}/{cloudRegionId}")
94   @DELETE
95   @ApiOperation(value = "delete a vim")
96   @ApiResponses(value = {
97       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
98           response = String.class),
99       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
100           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
101       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
102           response = String.class)})
103   @Timed
104   public Response delvim(@PathParam("cloudOwner") String cloudOwner,@PathParam("cloudRegionId") String cloudRegionId) {
105     LOGGER.info("start delete cloud-owner :" + cloudOwner +", cloud-region-id: " + cloudRegionId);
106     return VimManagerWrapper.getInstance().delVim(cloudOwner, cloudRegionId);
107   }
108   
109   /**
110    * update vim by id.
111    */
112   @PUT
113   @Path("/{cloudOwner}/{cloudRegionId}")
114   @Consumes(MediaType.APPLICATION_JSON)
115   @Produces(MediaType.APPLICATION_JSON)
116   @ApiOperation(value = "update a vim")
117   @ApiResponses(value = {
118       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
119           response = String.class),
120       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
121           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
122       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
123           response = String.class)})
124   @Timed
125   public Response updatevims(@PathParam("cloudOwner") String cloudOwner, @PathParam("cloudRegionId") String cloudRegionId, VimRegisterInfo vim) {
126     LOGGER.info("start update vim info:" + extsysUtil.objectToString(vim));
127     return VimManagerWrapper.getInstance().updateVim(cloudOwner, cloudRegionId, vim);
128   }
129   
130   /**
131    * register vim .
132    */
133   @POST
134   @Consumes(MediaType.APPLICATION_JSON)
135   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
136   @ApiOperation(value = "create a vim")
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 registerVims(VimRegisterInfo vim) {
146     LOGGER.info("start add vim" + " info:" + extsysUtil.objectToString(vim));
147     return VimManagerWrapper.getInstance().registerVim(vim);
148   }
149 }