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