Clean Annotations drools-applications
[policy/drools-applications.git] / controlloop / common / feature-controlloop-trans / src / main / java / org / onap / policy / drools / server / restful / RestTransactionTracker.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2023 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.drools.server.restful;
23
24 import java.util.UUID;
25 import javax.ws.rs.Consumes;
26 import javax.ws.rs.GET;
27 import javax.ws.rs.PUT;
28 import javax.ws.rs.Path;
29 import javax.ws.rs.PathParam;
30 import javax.ws.rs.Produces;
31 import javax.ws.rs.core.MediaType;
32 import javax.ws.rs.core.Response;
33 import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
34 import org.onap.policy.controlloop.VirtualControlLoopNotification;
35 import org.onap.policy.drools.apps.controlloop.feature.trans.ControlLoopMetricsManager;
36
37 /**
38  * REST Transaction Tracker.
39  */
40
41 @Path("/policy/pdp/engine/controllers/transactions")
42 @Produces({MediaType.APPLICATION_JSON, YamlMessageBodyHandler.APPLICATION_YAML})
43 @Consumes({MediaType.APPLICATION_JSON, YamlMessageBodyHandler.APPLICATION_YAML})
44 public class RestTransactionTracker implements PolicyApi {
45
46     /**
47      * GET transactions.
48      */
49
50     @Override
51     @GET
52     @Path("inprogress")
53     public Response transactions() {
54         return Response.status(Response.Status.OK)
55                        .entity(ControlLoopMetricsManager.getManager().getTransactions()).build();
56     }
57
58     /**
59      * GET one transaction.
60      */
61
62     @Override
63     @GET
64     @Path("inprogress/{transactionId}")
65     public Response transactionId(@PathParam("transactionId") String transactionId) {
66         VirtualControlLoopNotification notification =
67                 ControlLoopMetricsManager.getManager().getTransaction(UUID.fromString(transactionId));
68         return Response.status((notification != null) ? Response.Status.OK : Response.Status.NOT_FOUND)
69                        .entity(notification).build();
70     }
71
72     /**
73      * Resets the cache with a new cache size.
74      */
75
76     @Override
77     @PUT
78     @Path("cacheSize/{cacheSize}")
79     public Response cacheSize1(@PathParam("cacheSize") int cacheSize) {
80         ControlLoopMetricsManager.getManager().resetCache(cacheSize,
81                 ControlLoopMetricsManager.getManager().getTransactionTimeout());
82         return Response.status(Response.Status.OK)
83                        .entity(ControlLoopMetricsManager.getManager().getCacheSize()).build();
84     }
85
86     /**
87      * GET the cache size.
88      */
89
90     @Override
91     @GET
92     @Path("cacheSize")
93     public Response cacheSize() {
94         return Response.status(Response.Status.OK)
95                        .entity(ControlLoopMetricsManager.getManager().getCacheSize()).build();
96     }
97
98     /**
99      * Resets the cache with a new transaction timeout in seconds.
100      */
101     @Override
102     @PUT
103     @Path("timeout/{timeoutSecs}")
104     public Response timeout(@PathParam("timeoutSecs") long timeoutSecs) {
105         ControlLoopMetricsManager.getManager().resetCache(
106                 ControlLoopMetricsManager.getManager().getCacheSize(), timeoutSecs);
107         return Response.status(Response.Status.OK)
108                        .entity(ControlLoopMetricsManager.getManager().getTransactionTimeout()).build();
109     }
110
111     /**
112      * GET the cache timeout.
113      */
114     @Override
115     @GET
116     @Path("timeout")
117     public Response timeout1() {
118         return Response.status(Response.Status.OK)
119                        .entity(ControlLoopMetricsManager.getManager().getTransactionTimeout()).build();
120     }
121
122 }