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