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 io.swagger.annotations.Api;
24 import io.swagger.annotations.ApiOperation;
25 import io.swagger.annotations.ApiParam;
26 import io.swagger.annotations.ApiResponse;
27 import io.swagger.annotations.ApiResponses;
28 import java.util.List;
29 import java.util.UUID;
30 import java.util.stream.Collectors;
31 import javax.ws.rs.Consumes;
32 import javax.ws.rs.GET;
33 import javax.ws.rs.Path;
34 import javax.ws.rs.PathParam;
35 import javax.ws.rs.Produces;
36 import javax.ws.rs.core.MediaType;
37 import javax.ws.rs.core.Response;
38 import javax.ws.rs.core.Response.Status;
39 import org.onap.policy.aai.AaiManager;
40 import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
41 import org.onap.policy.drools.apps.controlloop.feature.management.ControlLoopManagementFeature;
42 import org.onap.policy.drools.system.PolicyEngineConstants;
43 import org.onap.policy.rest.RestManager;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * Telemetry Extensions for Control Loops in the PDP-D.
52 @Produces(MediaType.APPLICATION_JSON)
53 @Consumes(MediaType.APPLICATION_JSON)
55 public class RestControlLoopManager {
56 private static final Logger logger = LoggerFactory.getLogger(RestControlLoopManager.class);
61 * @param controllerName controller name.
62 * @param sessionName session name.
63 * @return list of controller names.
66 @Path("engine/controllers/{controller}/drools/facts/{session}/controlloops")
67 @ApiOperation(value = "Control Loops", notes = "Compact list", responseContainer = "List")
68 @ApiResponses(value = {@ApiResponse(code = 404, message = "Control Loops cannot be found")})
69 public Response controlLoops(
70 @ApiParam(value = "Policy Controller Name", required = true) @PathParam("controller") String controllerName,
71 @ApiParam(value = "Drools Session Name", required = true) @PathParam("session") String sessionName) {
74 List<String> controlLoopNames =
75 ControlLoopManagementFeature.controlLoops(controllerName, sessionName)
76 .map(ControlLoopParams::getClosedLoopControlName)
77 .collect(Collectors.toList());
79 return Response.status(Response.Status.OK).entity(controlLoopNames).build();
80 } catch (IllegalArgumentException e) {
81 logger.error("'GET' controlloops threw an exception", e);
82 return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
89 * @param controllerName controller name.
90 * @param sessionName session name.
91 * @param controlLoopName control loop name.
92 * @return control loop.
95 @Path("engine/controllers/{controller}/drools/facts/{session}/controlloops/{controlLoopName}")
96 @ApiOperation(value = "Control Loop", notes = "Control Loop Parameters", responseContainer = "List")
97 @ApiResponses(value = {@ApiResponse(code = 404, message = "The Control Loop cannot be found")})
98 public Response controlLoop(
99 @ApiParam(value = "Policy Controller Name", required = true) @PathParam("controller") String controllerName,
100 @ApiParam(value = "Drools Session Name", required = true) @PathParam("session") String sessionName,
101 @ApiParam(value = "Control Loop Name", required = true) @PathParam("controlLoopName") String controlLoopName) {
104 List<ControlLoopParams> controlLoopParams =
105 ControlLoopManagementFeature.controlLoops(controllerName, sessionName)
106 .filter(c -> c.getClosedLoopControlName().equals(controlLoopName))
107 .collect(Collectors.toList());
109 return Response.status(Response.Status.OK).entity(controlLoopParams).build();
110 } catch (IllegalArgumentException e) {
111 logger.error("'GET' controlloop threw an exception", e);
112 return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
119 * @param vserverId vServer identifier.
120 * @return query results.
123 @Path("engine/tools/controlloops/aai/customQuery/{vserverId}")
124 @ApiOperation(value = "AAI Custom Query")
125 public Response aaiCustomQuery(@ApiParam(value = "vserver Identifier") String vserverId) {
126 var mgr = PolicyEngineConstants.getManager();
130 .entity(new AaiManager(new RestManager())
131 .getCustomQueryResponse(
132 mgr.getEnvironmentProperty("aai.url"),
133 mgr.getEnvironmentProperty("aai.username"),
134 mgr.getEnvironmentProperty("aai.password"),