Simplify esr-server project level.
[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.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.aai.VimData;
26 import org.onap.aai.esr.entity.rest.VimRestData;
27 import org.onap.aai.esr.exception.ExtsysException;
28 import org.onap.aai.esr.util.ExtsysUtil;
29 import org.onap.aai.esr.util.RestResponseUtil;
30 import org.onap.aai.esr.wrapper.VimManagerWrapper;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 import java.util.ArrayList;
35 import java.util.List;
36 import javax.ws.rs.Consumes;
37 import javax.ws.rs.DELETE;
38 import javax.ws.rs.GET;
39 import javax.ws.rs.POST;
40 import javax.ws.rs.PUT;
41 import javax.ws.rs.Path;
42 import javax.ws.rs.PathParam;
43 import javax.ws.rs.Produces;
44 import javax.ws.rs.core.MediaType;
45 import javax.ws.rs.core.Response;
46
47 @Path("/vims")
48 @Api(tags = {" vim Management "})
49 public class VimManager {
50
51   private static final Logger LOGGER = LoggerFactory.getLogger(VimManager.class);
52
53   /**
54    * query all VIM.
55    */
56   @Path("")
57   @GET
58   @ApiOperation(value = "get  all vim ")
59   @Produces(MediaType.APPLICATION_JSON)
60   @ApiResponses(value = {
61       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
62           response = String.class),
63       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
64           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
65       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
66           response = String.class)})
67   @Timed
68   public Response queryVimList() {
69     return VimManagerWrapper.getInstance().queryVimList();
70   }
71
72   /**
73    * query vim by id.
74    */
75   @Path("/{vimId}")
76   @GET
77   @ApiOperation(value = "get vim by id")
78   @Produces(MediaType.APPLICATION_JSON)
79   @ApiResponses(value = {
80       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
81           response = String.class),
82       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
83           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
84       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
85           response = String.class)})
86   @Timed
87   public Response queryVimById(@ApiParam(value = "vim id") @PathParam("vimId") String vimId) {
88     LOGGER.info("start query vim by id." + vimId);
89     return VimManagerWrapper.getInstance().queryVimById(vimId);
90   }
91   
92   /**
93    * delete vim by id.
94    */
95   @Path("/{vimId}")
96   @DELETE
97   @ApiOperation(value = "delete a vim")
98   @ApiResponses(value = {
99       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
100           response = String.class),
101       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
102           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
103       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
104           response = String.class)})
105   @Timed
106   public Response delvim(@ApiParam(value = "vim id") @PathParam("vimId") String vimId) {
107     LOGGER.info("start delete vim .id:" + vimId);
108     return VimManagerWrapper.getInstance().delVim(vimId);
109   }
110   
111   /**
112    * update vim by id.
113    */
114   @PUT
115   @Path("/{vimId}")
116   @Consumes(MediaType.APPLICATION_JSON)
117   @Produces(MediaType.APPLICATION_JSON)
118   @ApiOperation(value = "update a vim")
119   @ApiResponses(value = {
120       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
121           response = String.class),
122       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
123           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
124       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
125           response = String.class)})
126   @Timed
127   public Response updatevims(@ApiParam(value = "vim", required = true) VimRestData vim,
128       @ApiParam(value = "vim id", required = true) @PathParam("vimId") String vimId) {
129     LOGGER.info("start update vim .id:" + vimId + " info:" + ExtsysUtil.objectToString(vim));
130     return VimManagerWrapper.getInstance().updateVim(vim);
131   }
132   
133   /**
134    * register vim .
135    */
136   @POST
137   @Path("")
138   @Consumes(MediaType.APPLICATION_JSON)
139   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
140   @ApiOperation(value = "create a vim")
141   @ApiResponses(value = {
142       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
143           response = String.class),
144       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
145           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
146       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
147           response = String.class)})
148   @Timed
149   public Response registerVims(@ApiParam(value = "vim", required = true) VimRestData vim) {
150     LOGGER.info("start add vim" + " info:" + ExtsysUtil.objectToString(vim));
151     return VimManagerWrapper.getInstance().registerVim(vim);
152   }
153 }