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