d01114e1eb55c7df31397d682e73e53b9d062e24
[aai/esr-server.git] / esr-core / 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 org.eclipse.jetty.http.HttpStatus;
25 import org.onap.aai.esr.entity.aai.VnfmData;
26 import org.onap.aai.esr.entity.rest.VnfmRestData;
27 import org.onap.aai.esr.exception.ExtsysException;
28 import org.onap.aai.esr.handle.VnfmHandler;
29 import org.onap.aai.esr.util.ExtsysUtil;
30 import org.onap.aai.esr.util.RestResponseUtil;
31 import org.onap.aai.esr.wrapper.VnfmManagerWrapper;
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("/vnfms")
49 @Api(tags = {" vnfm Management "})
50 public class VnfmManager {
51
52   VnfmHandler handler = new VnfmHandler();
53   private static final Logger LOGGER = LoggerFactory.getLogger(VnfmManager.class);
54
55   /**
56    * query all vnfm.
57    */
58   @Path("")
59   @GET
60   @ApiOperation(value = "get  all vnfm ")
61   @Produces(MediaType.APPLICATION_JSON)
62   @ApiResponses(value = {
63       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
64           response = String.class),
65       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
66           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
67       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
68           response = String.class)})
69   @Timed
70   public Response queryVnfmList() {
71     LOGGER.info("start query all vnfm!");
72     return VnfmManagerWrapper.getInstance().queryVnfmList();
73   }
74   
75   /**
76    * query  vnfm by id.
77    */
78   @Path("/{vnfmId}")
79   @GET
80   @ApiOperation(value = "get vnfm by id")
81   @Produces(MediaType.APPLICATION_JSON)
82   @ApiResponses(value = {
83       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
84           response = String.class),
85       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
86           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
87       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
88           response = String.class)})
89   @Timed
90   public Response queryVnfmById(@ApiParam(value = "vnfm id") @PathParam("vnfmId") String vnfmId) {
91     LOGGER.info("start query  vnfm by id." + vnfmId);
92     return VnfmManagerWrapper.getInstance().queryVnfmById(vnfmId);
93   }
94   
95   /**
96    * delete  vnfm by id.
97    */
98   @Path("/{vnfmId}")
99   @DELETE
100   @ApiOperation(value = "delete a vnfm")
101   @ApiResponses(value = {
102       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
103           response = String.class),
104       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
105           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
106       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
107           response = String.class)})
108   @Timed
109   public Response delVnfm(@ApiParam(value = "vnfm id") @PathParam("vnfmId") String vnfmId) {
110     LOGGER.info("start delete vnfm .id:" + vnfmId);
111     return VnfmManagerWrapper.getInstance().delVnfm(vnfmId);
112   }
113   
114   /**
115    * update  vnfm by id.
116    */
117   @PUT
118   @Path("/{vnfmId}")
119   @Consumes(MediaType.APPLICATION_JSON)
120   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
121   @ApiOperation(value = "update a vnfm")
122   @ApiResponses(value = {
123       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
124           response = String.class),
125       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
126           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
127       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
128           response = String.class)})
129   @Timed
130   public Response updateVnfm(@ApiParam(value = "vnfm", required = true) VnfmRestData vnfm,
131       @ApiParam(value = "vnfm id", required = true) @PathParam("vnfmId") String vnfmId) {
132     LOGGER.info("start update vnfm .id:" + vnfmId + " info:" + ExtsysUtil.objectToString(vnfm));
133     return VnfmManagerWrapper.getInstance().updateVnfm(vnfm, vnfmId);
134   }
135   
136   /**
137    * add  vnfm .
138    */
139   @POST
140   @Path("")
141   @Consumes(MediaType.APPLICATION_JSON)
142   @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
143   @ApiOperation(value = "create a vnfm")
144   @ApiResponses(value = {
145       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
146           response = String.class),
147       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
148           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
149       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
150           response = String.class)})
151   @Timed
152   public Response registerVnfm(@ApiParam(value = "vnfm", required = true) VnfmRestData vnfm) {
153     return VnfmManagerWrapper.getInstance().registerVnfm(vnfm);
154   }
155 }