11fba23c9062cdddd9fb96b1d4e0c977e1aca894
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / resource / EmsManager.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 io.swagger.annotations.SwaggerDefinition;
25
26 import org.eclipse.jetty.http.HttpStatus;
27 import org.onap.aai.esr.entity.rest.EmsRegisterInfo;
28 import org.onap.aai.esr.util.ExtsysUtil;
29 import org.onap.aai.esr.wrapper.EmsManagerWrapper;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;  
32
33 import javax.ws.rs.Consumes;
34 import javax.ws.rs.DELETE;
35 import javax.ws.rs.GET;
36 import javax.ws.rs.POST;
37 import javax.ws.rs.PUT;
38 import javax.ws.rs.Path;
39 import javax.ws.rs.PathParam;
40 import javax.ws.rs.Produces;
41 import javax.ws.rs.core.MediaType;
42 import javax.ws.rs.core.Response;
43
44 @SwaggerDefinition
45 @Path("/emses")
46 @Api(tags = {" ems Management "})
47 public class EmsManager {
48
49   private static final Logger LOGGER = LoggerFactory.getLogger(EmsManager.class);
50
51   private static ExtsysUtil extsysUtil = new ExtsysUtil();
52   
53   /**
54    * query all ems.
55    */
56   @GET
57   @ApiOperation(value = "get  all ems ")
58   @Produces(MediaType.APPLICATION_JSON)
59   @ApiResponses(value = {
60       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
61           response = String.class),
62       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
63           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
64       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
65           response = String.class)})
66   @Timed
67   public Response queryEmsList() {
68     LOGGER.info("start query all ems!");
69     return EmsManagerWrapper.getInstance().queryEmsList();
70   }
71   
72   /**
73    * query  ems info by id.
74    */
75   @Path("/{emsId}")
76   @GET
77   @ApiOperation(value = "get ems 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 queryemsById(@ApiParam(value = "ems id") @PathParam("emsId") String emsId) {
88     LOGGER.info("start query  ems by id." + emsId);
89     return EmsManagerWrapper.getInstance().queryEmsById(emsId);
90   }
91   
92   /**
93    * delete ems by id.
94    */
95   @Path("/{emsId}")
96   @DELETE
97   @ApiOperation(value = "delete a ems")
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 delems(@ApiParam(value = "ems id") @PathParam("emsId") String emsId) {
107     LOGGER.info("start delete ems .id:" + emsId);
108     return EmsManagerWrapper.getInstance().delEms(emsId);
109   }
110   
111   /**
112    * update ems by id.
113    */
114   @PUT
115   @Path("/{emsId}")
116   @Consumes(MediaType.APPLICATION_JSON)
117   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
118   @ApiOperation(value = "update a ems")
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 updateEms(@ApiParam(value = "ems", required = true) EmsRegisterInfo ems,
128       @ApiParam(value = "ems id", required = true) @PathParam("emsId") String emsId) {
129     LOGGER.info("start update ems .id:" + emsId + " info:" + extsysUtil.objectToString(ems));
130     return EmsManagerWrapper.getInstance().updateEms(ems, emsId);
131   }
132   
133   /**
134    * register ems.
135    */
136   @POST
137   @Consumes(MediaType.APPLICATION_JSON)
138   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
139   @ApiOperation(value = "create a ems")
140   @ApiResponses(value = {
141       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
142           response = String.class),
143       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
144           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
145       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
146           response = String.class)})
147   @Timed
148   public Response registerEms(@ApiParam(value = "ems", required = true) EmsRegisterInfo ems) {
149     LOGGER.info("start add ems" + " info:" + extsysUtil.objectToString(ems));
150     return EmsManagerWrapper.getInstance().registerEms(ems);
151   }
152 }