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