2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.drools.server.restful;
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;
38 * REST Transaction Tracker.
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 {
53 public Response transactions() {
54 return Response.status(Response.Status.OK)
55 .entity(ControlLoopMetricsManager.getManager().getTransactions()).build();
59 * GET one transaction.
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();
73 * Resets the cache with a new cache size.
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();
93 public Response cacheSize() {
94 return Response.status(Response.Status.OK)
95 .entity(ControlLoopMetricsManager.getManager().getCacheSize()).build();
99 * Resets the cache with a new transaction timeout in seconds.
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();
112 * GET the cache timeout.
117 public Response timeout1() {
118 return Response.status(Response.Status.OK)
119 .entity(ControlLoopMetricsManager.getManager().getTransactionTimeout()).build();