Realize update registered VIM.
[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 org.eclipse.jetty.http.HttpStatus;
24 import org.onap.aai.esr.entity.rest.VimRegisterInfo;
25 import org.onap.aai.esr.util.ExtsysUtil;
26 import org.onap.aai.esr.wrapper.VimManagerWrapper;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
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("/vims")
42 @Api(tags = {" vim Management "})
43 public class VimManager {
44
45   private static final Logger LOGGER = LoggerFactory.getLogger(VimManager.class);
46
47   /**
48    * query all VIM.
49    */
50   @GET
51   @ApiOperation(value = "get  all vim ")
52   @Produces(MediaType.APPLICATION_JSON)
53   @ApiResponses(value = {
54       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
55           response = String.class),
56       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
57           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
58       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
59           response = String.class)})
60   @Timed
61   public Response queryVimList() {
62     return VimManagerWrapper.getInstance().queryVimListDetails();
63   }
64
65   /**
66    * query vim by id.
67    */
68   @Path("/{cloudOwner}/{cloudRegionId}")
69   @GET
70   @ApiOperation(value = "get vim by id")
71   @Produces(MediaType.APPLICATION_JSON)
72   @ApiResponses(value = {
73       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
74           response = String.class),
75       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
76           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
77       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
78           response = String.class)})
79   @Timed
80   public Response queryVimById(@PathParam("cloudOwner") String cloudOwner, @PathParam("cloudRegionId") String cloudRegionId) {
81     LOGGER.info("start query vim by cloud owner and cloud region id." + cloudOwner +"," + cloudRegionId);
82     return VimManagerWrapper.getInstance().queryVimById(cloudOwner, cloudRegionId);
83   }
84   
85   /**
86    * delete vim by id.
87    */
88   @Path("/{vimId}")
89   @DELETE
90   @ApiOperation(value = "delete a vim")
91   @ApiResponses(value = {
92       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
93           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 delvim(@PathParam("vimId") String vimId) {
100     LOGGER.info("start delete vim .id:" + vimId);
101     return VimManagerWrapper.getInstance().delVim(vimId);
102   }
103   
104   /**
105    * update vim by id.
106    */
107   @PUT
108   @Path("/{vimId}")
109   @Consumes(MediaType.APPLICATION_JSON)
110   @Produces(MediaType.APPLICATION_JSON)
111   @ApiOperation(value = "update a vim")
112   @ApiResponses(value = {
113       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
114           response = String.class),
115       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
116           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
117       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
118           response = String.class)})
119   @Timed
120   public Response updatevims(VimRegisterInfo vim, @PathParam("vimId") String vimId) {
121     LOGGER.info("start update vim .id:" + vimId + " info:" + ExtsysUtil.objectToString(vim));
122     return VimManagerWrapper.getInstance().updateVim(vim);
123   }
124   
125   /**
126    * register vim .
127    */
128   @POST
129   @Consumes(MediaType.APPLICATION_JSON)
130   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
131   @ApiOperation(value = "create a vim")
132   @ApiResponses(value = {
133       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
134           response = String.class),
135       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
136           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
137       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
138           response = String.class)})
139   @Timed
140   public Response registerVims(VimRegisterInfo vim) {
141     LOGGER.info("start add vim" + " info:" + ExtsysUtil.objectToString(vim));
142     return VimManagerWrapper.getInstance().registerVim(vim);
143   }
144 }