Add the framework for PNF registration function
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / resource / PnfManager.java
1 /**
2  * Copyright 2018 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 javax.ws.rs.Consumes;
19 import javax.ws.rs.DELETE;
20 import javax.ws.rs.GET;
21 import javax.ws.rs.POST;
22 import javax.ws.rs.PUT;
23 import javax.ws.rs.Path;
24 import javax.ws.rs.PathParam;
25 import javax.ws.rs.Produces;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
28 import org.eclipse.jetty.http.HttpStatus;
29 import org.onap.aai.esr.entity.rest.PnfRegisterInfo;
30 import org.onap.aai.esr.util.ExtsysUtil;
31 import org.onap.aai.esr.wrapper.PnfManagerWrapper;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import com.codahale.metrics.annotation.Timed;
35 import io.swagger.annotations.Api;
36 import io.swagger.annotations.ApiOperation;
37 import io.swagger.annotations.ApiParam;
38 import io.swagger.annotations.ApiResponse;
39 import io.swagger.annotations.ApiResponses;
40
41 @Path("/pnfs")
42 @Api(tags = {" PNF Management "})
43 public class PnfManager {
44     
45     private static final Logger LOGGER = LoggerFactory.getLogger(PnfManager.class);
46
47     private static ExtsysUtil extsysUtil = new ExtsysUtil();
48     
49     /**
50      * query all pnf.
51      */
52     @GET
53     @ApiOperation(value = "get  all pnf ")
54     @Produces(MediaType.APPLICATION_JSON)
55     @ApiResponses(value = {
56             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
57             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
58                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
59             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
60                     response = String.class)})
61     @Timed
62     public Response queryPnfList() {
63         LOGGER.info("start query all pnf!");
64         return PnfManagerWrapper.getInstance().queryPnfList();
65     }
66     
67     /**
68      * query pnf by id.
69      */
70     @Path("/{pnfId}")
71     @GET
72     @ApiOperation(value = "get pnf by id")
73     @Produces(MediaType.APPLICATION_JSON)
74     @ApiResponses(value = {
75             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
76             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
77                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
78             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
79                     response = String.class)})
80     @Timed
81     public Response queryPnfById(@ApiParam(value = "pnf id") @PathParam("pnfId") String pnfId) {
82         LOGGER.info("start query  pnf by id." + pnfId);
83         return PnfManagerWrapper.getInstance().queryPnfById(pnfId);
84     }
85     
86     /**
87      * delete pnf by id.
88      */
89     @Path("/{pnfId}")
90     @DELETE
91     @ApiOperation(value = "delete a pnf")
92     @ApiResponses(value = {
93             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
94             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
95                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
96             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
97                     response = String.class)})
98     @Timed
99     public Response delPnf(@ApiParam(value = "pnf id") @PathParam("pnfId") String pnfId) {
100         LOGGER.info("start delete pnf .id:" + pnfId);
101         return PnfManagerWrapper.getInstance().delPnf(pnfId);
102     }
103     
104     /**
105      * update pnf by id.
106      */
107     @PUT
108     @Path("/{pnfId}")
109     @Consumes(MediaType.APPLICATION_JSON)
110     @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
111     @ApiOperation(value = "update a pnf")
112     @ApiResponses(value = {
113             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
114             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
115                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
116             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
117                     response = String.class)})
118     @Timed
119     public Response updatePnf(@ApiParam(value = "pnf", required = true) PnfRegisterInfo pnf,
120             @ApiParam(value = "pnf id", required = true) @PathParam("pnfId") String pnfId) {
121         LOGGER.info("start update pnf .id:" + pnfId + " info:" + extsysUtil.objectToString(pnf));
122         return PnfManagerWrapper.getInstance().updatePnf(pnf, pnfId);
123     }
124     
125     /**
126      * add pnf .
127      */
128     @POST
129     @Consumes(MediaType.APPLICATION_JSON)
130     @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
131     @ApiOperation(value = "create a pnf")
132     @ApiResponses(value = {
133             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
134             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
135                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
136             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
137                     response = String.class)})
138     @Timed
139     public Response registerPnf(@ApiParam(value = "pnf", required = true) PnfRegisterInfo pnf) {
140         return PnfManagerWrapper.getInstance().registerPnf(pnf);
141     }
142 }