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