2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.drools.server.restful;
23 import io.swagger.annotations.Api;
24 import io.swagger.annotations.ApiOperation;
25 import io.swagger.annotations.ApiParam;
26 import java.util.UUID;
27 import javax.ws.rs.Consumes;
28 import javax.ws.rs.GET;
29 import javax.ws.rs.PUT;
30 import javax.ws.rs.Path;
31 import javax.ws.rs.PathParam;
32 import javax.ws.rs.Produces;
33 import javax.ws.rs.core.MediaType;
34 import javax.ws.rs.core.Response;
35 import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
36 import org.onap.policy.controlloop.VirtualControlLoopNotification;
37 import org.onap.policy.drools.apps.controlloop.feature.trans.ControlLoopMetricsManager;
40 * REST Transaction Tracker.
43 @Path("/policy/pdp/engine/controllers/transactions")
44 @Produces({MediaType.APPLICATION_JSON, YamlMessageBodyHandler.APPLICATION_YAML})
45 @Consumes({MediaType.APPLICATION_JSON, YamlMessageBodyHandler.APPLICATION_YAML})
47 public class RestTransactionTracker {
55 @ApiOperation(value = "Retrieve in-progress transactions", responseContainer = "List")
56 public Response transactions() {
57 return Response.status(Response.Status.OK)
58 .entity(ControlLoopMetricsManager.getManager().getTransactions()).build();
62 * GET one transaction.
66 @Path("inprogress/{transactionId}")
67 @ApiOperation(value = "Retrieve an in-progress transaction", response = VirtualControlLoopNotification.class)
68 public Response transactionId(
69 @ApiParam(value = "UUID", required = true) @PathParam("transactionId") String transactionId) {
70 VirtualControlLoopNotification notification =
71 ControlLoopMetricsManager.getManager().getTransaction(UUID.fromString(transactionId));
72 return Response.status((notification != null) ? Response.Status.OK : Response.Status.NOT_FOUND)
73 .entity(notification).build();
77 * Resets the cache with a new cache size.
81 @Path("cacheSize/{cacheSize}")
82 @ApiOperation(value = "Sets the cache size", response = Integer.class)
83 public Response cacheSize(
84 @ApiParam(value = "cache size", required = true) @PathParam("cacheSize") int cacheSize) {
85 ControlLoopMetricsManager.getManager().resetCache(cacheSize,
86 ControlLoopMetricsManager.getManager().getTransactionTimeout());
87 return Response.status(Response.Status.OK)
88 .entity(ControlLoopMetricsManager.getManager().getCacheSize()).build();
97 @ApiOperation(value = "Gets the cache size", response = Integer.class)
98 public Response cacheSize() {
99 return Response.status(Response.Status.OK)
100 .entity(ControlLoopMetricsManager.getManager().getCacheSize()).build();
104 * Resets the cache with a new transaction timeout in seconds.
108 @Path("timeout/{timeoutSecs}")
109 @ApiOperation(value = "Sets the timeout in seconds", response = Integer.class)
110 public Response timeout(
111 @ApiParam(value = "timeout", required = true) @PathParam("timeoutSecs") long timeoutSecs) {
112 ControlLoopMetricsManager.getManager().resetCache(
113 ControlLoopMetricsManager.getManager().getCacheSize(), timeoutSecs);
114 return Response.status(Response.Status.OK)
115 .entity(ControlLoopMetricsManager.getManager().getTransactionTimeout()).build();
119 * GET the cache timeout.
124 @ApiOperation(value = "Gets the cache timeout", response = Long.class)
125 public Response timeout() {
126 return Response.status(Response.Status.OK)
127 .entity(ControlLoopMetricsManager.getManager().getTransactionTimeout()).build();