a122c47441d6a7a7f423d8cdb5cd4bc38664fe27
[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 import javax.ws.rs.Consumes;
30 import javax.ws.rs.DELETE;
31 import javax.ws.rs.GET;
32 import javax.ws.rs.POST;
33 import javax.ws.rs.PUT;
34 import javax.ws.rs.Path;
35 import javax.ws.rs.PathParam;
36 import javax.ws.rs.Produces;
37 import javax.ws.rs.core.MediaType;
38 import javax.ws.rs.core.Response;
39
40 @Path("/vims")
41 @Api(tags = {" vim Management "})
42 public class VimManager {
43
44     private static final Logger LOGGER = LoggerFactory.getLogger(VimManager.class);
45
46     private static ExtsysUtil extsysUtil = new ExtsysUtil();
47
48     /**
49      * query all VIM.
50      */
51     @GET
52     @ApiOperation(value = "get  all vim ")
53     @Produces(MediaType.APPLICATION_JSON)
54     @ApiResponses(value = {
55             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", 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", response = String.class),
74             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
75                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
76             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
77                     response = String.class)})
78     @Timed
79     public Response queryVimById(@PathParam("cloudOwner") String cloudOwner,
80             @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("/{cloudOwner}/{cloudRegionId}")
89     @DELETE
90     @ApiOperation(value = "delete a vim")
91     @ApiResponses(value = {
92             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
93             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
94                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
95             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
96                     response = String.class)})
97     @Timed
98     public Response delvim(@PathParam("cloudOwner") String cloudOwner,
99             @PathParam("cloudRegionId") String cloudRegionId) {
100         LOGGER.info("start delete cloud-owner :" + cloudOwner + ", cloud-region-id: " + cloudRegionId);
101         return VimManagerWrapper.getInstance().delVim(cloudOwner, cloudRegionId);
102     }
103
104     /**
105      * update vim by id.
106      */
107     @PUT
108     @Path("/{cloudOwner}/{cloudRegionId}")
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", response = String.class),
114             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
115                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
116             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
117                     response = String.class)})
118     @Timed
119     public Response updatevims(@PathParam("cloudOwner") String cloudOwner,
120             @PathParam("cloudRegionId") String cloudRegionId, VimRegisterInfo vim) {
121         LOGGER.info("start update vim info:" + extsysUtil.objectToString(vim));
122         return VimManagerWrapper.getInstance().updateVim(cloudOwner, cloudRegionId, 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", response = String.class),
134             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
135                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
136             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
137                     response = String.class)})
138     @Timed
139     public Response registerVims(VimRegisterInfo vim) {
140         LOGGER.info("start add vim" + " info:" + extsysUtil.objectToString(vim));
141         return VimManagerWrapper.getInstance().registerVim(vim);
142     }
143 }