Add DMaaP simulator for CSIT testing
[policy/models.git] / models-sim / models-sim-dmaap / src / main / java / org / onap / policy / models / sim / dmaap / rest / DmaapSimRestControllerV1.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.sim.dmaap.rest;
22
23 import io.swagger.annotations.ApiOperation;
24 import io.swagger.annotations.ApiResponse;
25 import io.swagger.annotations.ApiResponses;
26 import io.swagger.annotations.Authorization;
27 import javax.ws.rs.GET;
28 import javax.ws.rs.POST;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.PathParam;
31 import javax.ws.rs.QueryParam;
32 import javax.ws.rs.core.Response;
33
34 import org.onap.policy.models.sim.dmaap.provider.DmaapSimProvider;
35
36 /**
37  * Class to provide REST endpoints for DMaaP simulator component statistics.
38  */
39 @Path("/events")
40 public class DmaapSimRestControllerV1 extends BaseRestControllerV1 {
41
42     /**
43      * Get a DMaaP message.
44      *
45      * @param topicName topic to get message from
46      * @param consumerGroup consumer group that is getting the message
47      * @param consumerId consumer ID that is getting the message
48      * @param timeout timeout for the message
49      * @return the message
50      */
51     @GET
52     @Path("{topicName}/{consumerGroup}/{consumerId}")
53     // @formatter:off
54     @ApiOperation(
55             value = "Get a DMaaP event on a topic",
56             notes = "Returns an event on a DMaaP topic",
57             response = Object.class,
58             authorizations =
59                 @Authorization(value = AUTHORIZATION_TYPE)
60         )
61     @ApiResponses(
62             value = {
63                 @ApiResponse(
64                         code = AUTHENTICATION_ERROR_CODE,
65                         message = AUTHENTICATION_ERROR_MESSAGE),
66                 @ApiResponse(
67                         code = AUTHORIZATION_ERROR_CODE,
68                         message = AUTHORIZATION_ERROR_MESSAGE),
69                 @ApiResponse(
70                         code = SERVER_ERROR_CODE,
71                         message = SERVER_ERROR_MESSAGE)
72             }
73         )
74     // @formatter:on
75     public Response getDmaaapMessage(@PathParam("topicName") final String topicName,
76             @PathParam("consumerGroup") final String consumerGroup, @PathParam("consumerId") final String consumerId,
77             @QueryParam("timeout") final int timeout) {
78
79         return new DmaapSimProvider().processDmaapMessageGet(topicName, consumerGroup, consumerId, timeout);
80     }
81
82     /**
83      * Post a DMaaP message.
84      *
85      * @param topicName topic to get message from415
86      * @return the response to the post
87      */
88     @POST
89     @Path("{topicName}")
90     // @formatter:off
91     @ApiOperation(
92             value = "Post a DMaaP event on a topic",
93             notes = "Returns an event on a DMaaP topic",
94             response = Response.class,
95             authorizations =
96                 @Authorization(value = AUTHORIZATION_TYPE)
97         )
98     @ApiResponses(
99             value = {
100                 @ApiResponse(
101                         code = AUTHENTICATION_ERROR_CODE,
102                         message = AUTHENTICATION_ERROR_MESSAGE),
103                 @ApiResponse(
104                         code = AUTHORIZATION_ERROR_CODE,
105                         message = AUTHORIZATION_ERROR_MESSAGE),
106                 @ApiResponse(
107                         code = SERVER_ERROR_CODE,
108                         message = SERVER_ERROR_MESSAGE)
109             }
110         )
111     // @formatter:on
112     public Response postDmaaapMessage(@PathParam("topicName") final String topicName, final Object dmaapMessage) {
113
114         return new DmaapSimProvider().processDmaapMessagePut(topicName, dmaapMessage);
115     }
116 }