893b5b543a40d727b77249234902d9aa2e2c61b3
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / resource / VnfmManager.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.VnfmRegisterInfo;
28 import org.onap.aai.esr.util.ExtsysUtil;
29 import org.onap.aai.esr.wrapper.VnfmManagerWrapper;
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("/vnfms")
46 @Api(tags = {" vnfm Management "})
47 public class VnfmManager {
48
49   private static final Logger LOGGER = LoggerFactory.getLogger(VnfmManager.class);
50
51   private static ExtsysUtil extsysUtil = new ExtsysUtil();
52   
53   /**
54    * query all vnfm.
55    */
56   @GET
57   @ApiOperation(value = "get  all vnfm ")
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 queryVnfmList() {
68     LOGGER.info("start query all vnfm!");
69     return VnfmManagerWrapper.getInstance().queryVnfmList();
70   }
71   
72   /**
73    * query  vnfm by id.
74    */
75   @Path("/{vnfmId}")
76   @GET
77   @ApiOperation(value = "get vnfm 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 queryVnfmById(@ApiParam(value = "vnfm id") @PathParam("vnfmId") String vnfmId) {
88     LOGGER.info("start query  vnfm by id." + vnfmId);
89     return VnfmManagerWrapper.getInstance().queryVnfmById(vnfmId);
90   }
91   
92   /**
93    * delete  vnfm by id.
94    */
95   @Path("/{vnfmId}")
96   @DELETE
97   @ApiOperation(value = "delete a vnfm")
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 delVnfm(@ApiParam(value = "vnfm id") @PathParam("vnfmId") String vnfmId) {
107     LOGGER.info("start delete vnfm .id:" + vnfmId);
108     return VnfmManagerWrapper.getInstance().delVnfm(vnfmId);
109   }
110   
111   /**
112    * update  vnfm by id.
113    */
114   @PUT
115   @Path("/{vnfmId}")
116   @Consumes(MediaType.APPLICATION_JSON)
117   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
118   @ApiOperation(value = "update a vnfm")
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 updateVnfm(@ApiParam(value = "vnfm", required = true) VnfmRegisterInfo vnfm,
128       @ApiParam(value = "vnfm id", required = true) @PathParam("vnfmId") String vnfmId) {
129     LOGGER.info("start update vnfm .id:" + vnfmId + " info:" + extsysUtil.objectToString(vnfm));
130     return VnfmManagerWrapper.getInstance().updateVnfm(vnfm, vnfmId);
131   }
132   
133   /**
134    * add  vnfm .
135    */
136   @POST
137   @Consumes(MediaType.APPLICATION_JSON)
138   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
139   @ApiOperation(value = "create a vnfm")
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 registerVnfm(@ApiParam(value = "vnfm", required = true) VnfmRegisterInfo vnfm) {
149     return VnfmManagerWrapper.getInstance().registerVnfm(vnfm);
150   }
151 }