2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2021 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 jakarta.ws.rs.Consumes;
25 import jakarta.ws.rs.GET;
26 import jakarta.ws.rs.Path;
27 import jakarta.ws.rs.PathParam;
28 import jakarta.ws.rs.Produces;
29 import jakarta.ws.rs.core.MediaType;
30 import jakarta.ws.rs.core.Response;
31 import jakarta.ws.rs.core.Response.Status;
32 import java.util.List;
33 import java.util.UUID;
34 import java.util.stream.Collectors;
35 import org.onap.policy.aai.AaiManager;
36 import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
37 import org.onap.policy.drools.apps.controlloop.feature.management.ControlLoopManagementFeature;
38 import org.onap.policy.drools.system.PolicyEngineConstants;
39 import org.onap.policy.rest.RestManager;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 * Telemetry Extensions for Control Loops in the PDP-D.
48 @Produces(MediaType.APPLICATION_JSON)
49 @Consumes(MediaType.APPLICATION_JSON)
50 public class RestControlLoopManager implements PolicyApi {
51 private static final Logger logger = LoggerFactory.getLogger(RestControlLoopManager.class);
56 * @param controllerName controller name.
57 * @param sessionName session name.
58 * @return list of controller names.
61 @Path("engine/controllers/{controller}/drools/facts/{session}/controlloops")
62 public Response controlLoops(
63 @PathParam("controller") String controllerName,
64 @PathParam("session") String sessionName) {
67 List<String> controlLoopNames =
68 ControlLoopManagementFeature.controlLoops(controllerName, sessionName)
69 .map(ControlLoopParams::getClosedLoopControlName)
70 .collect(Collectors.toList());
72 return Response.status(Response.Status.OK).entity(controlLoopNames).build();
73 } catch (IllegalArgumentException e) {
74 logger.error("'GET' controlloops threw an exception", e);
75 return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
82 * @param controllerName controller name.
83 * @param sessionName session name.
84 * @param controlLoopName control loop name.
85 * @return control loop.
88 @Path("engine/controllers/{controller}/drools/facts/{session}/controlloops/{controlLoopName}")
89 public Response controlLoop(
90 @PathParam("controller") String controllerName,
91 @PathParam("session") String sessionName,
92 @PathParam("controlLoopName") String controlLoopName) {
95 List<ControlLoopParams> controlLoopParams =
96 ControlLoopManagementFeature.controlLoops(controllerName, sessionName)
97 .filter(c -> c.getClosedLoopControlName().equals(controlLoopName))
98 .collect(Collectors.toList());
100 return Response.status(Response.Status.OK).entity(controlLoopParams).build();
101 } catch (IllegalArgumentException e) {
102 logger.error("'GET' controlloop threw an exception", e);
103 return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
110 * @param vserverId vServer identifier.
111 * @return query results.
114 @Path("engine/tools/controlloops/aai/customQuery/{vserverId}")
115 public Response aaiCustomQuery(@PathParam("vserverId") String vserverId) {
116 var mgr = PolicyEngineConstants.getManager();
120 .entity(new AaiManager(new RestManager())
121 .getCustomQueryResponse(
122 mgr.getEnvironmentProperty("aai.url"),
123 mgr.getEnvironmentProperty("aai.username"),
124 mgr.getEnvironmentProperty("aai.password"),