2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.ArrayList;
24 import java.util.Arrays;
25 import java.util.HashMap;
26 import java.util.List;
28 import java.util.Properties;
29 import java.util.UUID;
30 import java.util.regex.Pattern;
32 import javax.ws.rs.Consumes;
33 import javax.ws.rs.DELETE;
34 import javax.ws.rs.DefaultValue;
35 import javax.ws.rs.GET;
36 import javax.ws.rs.POST;
37 import javax.ws.rs.PUT;
38 import javax.ws.rs.Path;
39 import javax.ws.rs.PathParam;
40 import javax.ws.rs.Produces;
41 import javax.ws.rs.QueryParam;
42 import javax.ws.rs.core.MediaType;
43 import javax.ws.rs.core.Response;
44 import javax.ws.rs.core.Response.Status;
46 import org.onap.policy.drools.controller.DroolsController;
47 import org.onap.policy.drools.event.comm.TopicEndpoint;
48 import org.onap.policy.drools.event.comm.TopicSink;
49 import org.onap.policy.drools.event.comm.TopicSource;
50 import org.onap.policy.drools.event.comm.bus.DmaapTopicSink;
51 import org.onap.policy.drools.event.comm.bus.DmaapTopicSource;
52 import org.onap.policy.drools.event.comm.bus.UebTopicSink;
53 import org.onap.policy.drools.event.comm.bus.UebTopicSource;
54 import org.onap.policy.drools.features.PolicyControllerFeatureAPI;
55 import org.onap.policy.drools.features.PolicyEngineFeatureAPI;
56 import org.onap.policy.drools.properties.PolicyProperties;
57 import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
58 import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
59 import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
60 import org.onap.policy.drools.protocol.coders.JsonProtocolFilter.FilterRule;
61 import org.onap.policy.drools.protocol.coders.ProtocolCoderToolset;
62 import org.onap.policy.drools.protocol.configuration.ControllerConfiguration;
63 import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
64 import org.onap.policy.drools.system.PolicyController;
65 import org.onap.policy.drools.system.PolicyEngine;
66 import org.slf4j.Logger;
67 import org.slf4j.LoggerFactory;
69 import ch.qos.logback.classic.LoggerContext;
70 import io.swagger.annotations.Api;
71 import io.swagger.annotations.ApiOperation;
72 import io.swagger.annotations.ApiParam;
73 import io.swagger.annotations.ApiResponse;
74 import io.swagger.annotations.ApiResponses;
75 import io.swagger.annotations.Info;
76 import io.swagger.annotations.SwaggerDefinition;
77 import io.swagger.annotations.Tag;
81 * Telemetry JAX-RS Interface to the PDP-D
85 @Produces(MediaType.APPLICATION_JSON)
86 @Consumes(MediaType.APPLICATION_JSON)
90 description = "PDP-D Telemetry Services",
92 title = "PDP-D Telemetry"
94 consumes = {MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN},
95 produces = {MediaType.APPLICATION_JSON},
96 schemes = {SwaggerDefinition.Scheme.HTTP},
98 @Tag(name = "pdp-d-telemetry", description = "Drools PDP Telemetry Operations")
101 public class RestManager {
105 private static Logger logger = LoggerFactory.getLogger(RestManager.class);
110 value="Retrieves the Engine Operational Status",
111 notes="Top-level abstraction. Provides a global view of resources",
112 response=PolicyEngine.class
114 public Response engine() {
115 return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build();
121 value="Shuts down the Engine",
122 notes="Deleting the engine, the top-level abstraction, equivalenty shuts it down",
123 response=PolicyEngine.class
125 public Response engineShutdown() {
127 PolicyEngine.manager.shutdown();
128 } catch (IllegalStateException e) {
129 logger.error("{}: cannot shutdown {} because of {}", this, PolicyEngine.manager, e.getMessage(), e);
130 return Response.status(Response.Status.BAD_REQUEST).
131 entity(PolicyEngine.manager).
135 return Response.status(Response.Status.OK).
136 entity(PolicyEngine.manager).
141 @Path("engine/features")
143 value="Engine Features",
144 notes="Provides the list of loaded features using the PolicyEngineFeatureAPI",
145 responseContainer="List"
147 public Response engineFeatures() {
148 return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatures()).build();
152 @Path("engine/features/inventory")
154 value="Engine Detailed Feature Inventory",
155 notes="Provides detailed list of loaded features using the PolicyEngineFeatureAPI",
156 responseContainer="List",
157 response=PolicyEngineFeatureAPI.class
159 public Response engineFeaturesInventory() {
160 return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatureProviders()).build();
164 @Path("engine/features/{featureName}")
166 value="Engine Feature",
167 notes="Provides Details for a given feature Engine Provider",
168 response=PolicyEngineFeatureAPI.class
170 @ApiResponses(value = {
171 @ApiResponse(code=404, message = "The feature cannot be found")
173 public Response engineFeature(@ApiParam(value="Feature Name", required=true)
174 @PathParam("featureName") String featureName) {
176 return Response.status(Response.Status.OK).
177 entity(PolicyEngine.manager.getFeatureProvider(featureName)).build();
178 } catch(IllegalArgumentException iae) {
179 logger.debug("feature unavailable: {}", featureName, iae);
180 return Response.status(Response.Status.NOT_FOUND).
181 entity(new Error(iae.getMessage())).build();
186 @Path("engine/inputs")
188 value="Engine Input Ports",
189 notes="List of input ports",
190 responseContainer="List"
192 public Response engineInputs() {
193 return Response.status(Response.Status.OK).
194 entity(Arrays.asList(Inputs.values())).
199 @Path("engine/inputs/configuration")
201 value="Engine Input Configuration Requests",
202 notes="Feeds a configuration request input into the Engine"
204 @ApiResponses(value={
205 @ApiResponse(code=406, message = "The configuration request cannot be honored")
207 public Response engineUpdate(
208 @ApiParam(value="Configuration to apply", required=true) PdpdConfiguration configuration) {
209 PolicyController controller = null;
210 boolean success = true;
212 success = PolicyEngine.manager.configure(configuration);
213 } catch (Exception e) {
215 logger.info("{}: cannot configure {} because of {}", this, PolicyEngine.manager, e.getMessage(), e);
219 return Response.status(Response.Status.NOT_ACCEPTABLE).
220 entity(new Error("cannot perform operation")).build();
222 return Response.status(Response.Status.OK).entity(controller).build();
226 @Path("engine/properties")
228 value="Engine Configuration Properties",
229 notes="Used for booststrapping the engine",
230 response=Properties.class
232 public Response engineProperties() {
233 return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getProperties()).build();
237 @Path("engine/switches")
239 value="Engine Control Switches",
240 notes="List of the Engine Control Switches",
241 responseContainer="List"
243 public Response engineSwitches() {
244 return Response.status(Response.Status.OK).
245 entity(Arrays.asList(Switches.values())).
250 @Path("engine/switches/activation")
252 value="Switches on the Engine Activation Switch",
253 notes="Turns on Activation Switch on the Engine. This order entails that the engine " +
254 "and controllers are unlocked and started",
255 response=PolicyEngine.class
257 public Response engineActivation() {
258 boolean success = true;
260 PolicyEngine.manager.activate();
261 } catch (Exception e) {
263 logger.info("{}: cannot activate {} because of {}", this, PolicyEngine.manager, e.getMessage(), e);
267 return Response.status(Response.Status.NOT_ACCEPTABLE).
268 entity(new Error("cannot perform operation")).build();
270 return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build();
274 @Path("engine/switches/activation")
276 value="Switches off Engine Activation Switch",
277 notes="Turns off the Activation Switch on the Engine. This order entails that the engine " +
278 "and controllers are locked (with the exception of those resources defined as unmanaged)",
279 response=PolicyEngine.class
281 public Response engineDeactivation() {
282 boolean success = true;
284 PolicyEngine.manager.deactivate();
285 } catch (Exception e) {
287 logger.info("{}: cannot deactivate {} because of {}", this, PolicyEngine.manager, e.getMessage(), e);
291 return Response.status(Response.Status.NOT_ACCEPTABLE).
292 entity(new Error("cannot perform operation")).build();
294 return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build();
298 @Path("engine/switches/lock")
300 value="Switches on the Engine Lock Control",
301 notes="This switch locks all the engine resources as a whole, except those that are defined unmanaged",
302 response=PolicyEngine.class
304 @ApiResponses(value = {
305 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
306 "this request to be fulfilled")
308 public Response engineLock() {
309 boolean success = PolicyEngine.manager.lock();
311 return Response.status(Status.OK).
312 entity(PolicyEngine.manager).
315 return Response.status(Status.NOT_ACCEPTABLE).
316 entity(new Error("cannot perform operation")).
321 @Path("engine/switches/lock")
323 value="Switches off the Lock control",
324 notes="This switch locks all the engine resources as a whole, except those that are defined unmanaged",
325 response=PolicyEngine.class
327 @ApiResponses(value = {
328 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
329 "this request to be fulfilled")
331 public Response engineUnlock() {
332 boolean success = PolicyEngine.manager.unlock();
334 return Response.status(Status.OK).
335 entity(PolicyEngine.manager).
338 return Response.status(Status.NOT_ACCEPTABLE).
339 entity(new Error("cannot perform operation")).
344 @Path("engine/controllers")
346 value="Lists the Policy Controllers Names",
347 notes="Unique Policy Controller Identifiers",
348 responseContainer="List"
350 public Response controllers() {
351 return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getPolicyControllerIds()).build();
355 @Path("engine/controllers/inventory")
357 value="Lists the Policy Controllers",
358 notes="Detailed list of Policy Controllers",
359 responseContainer="List",
360 response=PolicyController.class
362 public Response controllerInventory() {
363 return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getPolicyControllers()).build();
367 @Path("engine/controllers")
369 value="Creates and starts a new Policy Controller",
370 notes="Controller creation based on properties",
371 response=PolicyController.class
373 @ApiResponses(value = {
374 @ApiResponse(code=400, message = "Invalid configuration information has been provided"),
375 @ApiResponse(code=304, message = "The controller already exists"),
376 @ApiResponse(code=406, message = "The administrative state of the system prevents it " +
377 "from processing this request"),
378 @ApiResponse(code=206, message = "The controller has been created " +
379 "but cannot be started"),
380 @ApiResponse(code=201, message = "The controller has been succesfully created and started")
382 public Response controllerAdd(@ApiParam(value="Configuration Properties to apply", required = true)
385 return Response.status(Response.Status.BAD_REQUEST).
386 entity(new Error("A configuration must be provided")).
389 String controllerName = config.getProperty(PolicyProperties.PROPERTY_CONTROLLER_NAME);
390 if (controllerName == null || controllerName.isEmpty())
391 return Response.status(Response.Status.BAD_REQUEST).
393 ("Configuration must have an entry for " +
394 PolicyProperties.PROPERTY_CONTROLLER_NAME)).
397 PolicyController controller;
399 controller = PolicyController.factory.get(controllerName);
400 if (controller != null)
401 return Response.status(Response.Status.NOT_MODIFIED).
404 } catch (IllegalArgumentException e) {
406 } catch (IllegalStateException e) {
407 logger.info("{}: cannot get policy-controller because of {}", this, e.getMessage(), e);
408 return Response.status(Response.Status.NOT_ACCEPTABLE).
409 entity(new Error(controllerName + " not found")).build();
413 controller = PolicyEngine.manager.createPolicyController
414 (config.getProperty(PolicyProperties.PROPERTY_CONTROLLER_NAME), config);
415 } catch (IllegalArgumentException | IllegalStateException e) {
416 logger.warn("{}: cannot create policy-controller because of {}", this, e.getMessage(), e);
417 return Response.status(Response.Status.BAD_REQUEST).
418 entity(new Error(e.getMessage())).
423 boolean success = controller.start();
425 logger.info("{}: cannot start {}", this, controller);
426 return Response.status(Response.Status.PARTIAL_CONTENT).
427 entity(new Error(controllerName + " can't be started")).build();
429 } catch (IllegalStateException e) {
430 logger.info("{}: cannot start {} because of {}", this, controller, e.getMessage(), e);;
431 return Response.status(Response.Status.PARTIAL_CONTENT).
432 entity(controller).build();
435 return Response.status(Response.Status.CREATED).
441 @Path("engine/controllers/features")
443 value="Lists of Feature Providers Identifiers",
444 notes="Unique Policy Controller Identifiers",
445 responseContainer="List"
447 public Response controllerFeatures() {
448 return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatures()).build();
452 @Path("engine/controllers/features/inventory")
454 value="Detailed Controllers Feature Inventory",
455 notes="Provides detailed list of loaded features using the PolicyControllerFeatureAPI",
456 responseContainer="List",
457 response=PolicyControllerFeatureAPI.class
459 public Response controllerFeaturesInventory() {
460 return Response.status(Response.Status.OK).
461 entity(PolicyController.factory.getFeatureProviders()).
466 @Path("engine/controllers/features/{featureName}")
468 value="Controller Feature",
469 notes="Provides Details for a given Policy Controller feature provider",
470 response=PolicyControllerFeatureAPI.class
472 @ApiResponses(value = {
473 @ApiResponse(code=404, message = "The feature cannot be found")
475 public Response controllerFeature(@ApiParam(value="Feature Name", required=true)
476 @PathParam("featureName") String featureName) {
478 return Response.status(Response.Status.OK).
479 entity(PolicyController.factory.getFeatureProvider(featureName)).
481 } catch(IllegalArgumentException iae) {
482 logger.debug("{}: cannot feature {} because of {}", this, featureName, iae.getMessage(), iae);
483 return Response.status(Response.Status.NOT_FOUND).
484 entity(new Error(iae.getMessage())).build();
489 @Path("engine/controllers/{controller}")
491 value="Retrieves a Policy Controller",
492 notes="A Policy Controller is a concrete drools application abstraction. " +
493 "It aggregates networking, drools, and other resources," +
494 "as provides operational controls over drools applications",
495 response=PolicyController.class
497 @ApiResponses(value = {
498 @ApiResponse(code=404, message="The controller cannot be found"),
499 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
500 "this request to be fulfilled")
502 public Response controller(@ApiParam(value="Policy Controller Name", required=true)
503 @PathParam("controller") String controllerName) {
505 return Response.status(Response.Status.OK).
506 entity(PolicyController.factory.get(controllerName)).
508 } catch (IllegalArgumentException e) {
509 logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
510 return Response.status(Response.Status.NOT_FOUND).
511 entity(new Error(controllerName + " not found")).
513 } catch (IllegalStateException e) {
514 logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
515 return Response.status(Response.Status.NOT_ACCEPTABLE).
516 entity(new Error(controllerName + " not acceptable")).
522 @Path("engine/controllers/{controller}")
524 value="Deletes a Policy Controller",
525 notes="A Policy Controller is a concrete drools application abstraction. " +
526 "It aggregates networking, drools, and other resources," +
527 "as provides operational controls over drools applications",
528 response=PolicyController.class
530 @ApiResponses(value = {
531 @ApiResponse(code=404, message="The controller cannot be found"),
532 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
533 "this request to be fulfilled"),
534 @ApiResponse(code=500, message="A problem has occurred while deleting the Policy Controller")
536 public Response controllerDelete(@ApiParam(value="Policy Controller Name", required=true)
537 @PathParam("controller") String controllerName) {
539 PolicyController controller;
542 PolicyController.factory.get(controllerName);
543 if (controller == null)
544 return Response.status(Response.Status.BAD_REQUEST).
545 entity(new Error(controllerName + " does not exist")).
547 } catch (IllegalArgumentException e) {
548 logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
549 return Response.status(Response.Status.BAD_REQUEST).
550 entity(new Error(controllerName + " not found: " + e.getMessage())).
552 } catch (IllegalStateException e) {
553 logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
554 return Response.status(Response.Status.NOT_ACCEPTABLE).
555 entity(new Error(controllerName + " not acceptable")).build();
559 PolicyEngine.manager.removePolicyController(controllerName);
560 } catch (IllegalArgumentException | IllegalStateException e) {
561 logger.debug("{}: cannot remove policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
562 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
563 entity(new Error(e.getMessage())).
567 return Response.status(Response.Status.OK).
573 @Path("engine/controllers/{controller}/properties")
575 value="Retrieves the configuration properties of a Policy Controller",
576 notes="Configuration resources used by the controller if Properties format",
577 response=PolicyController.class
579 @ApiResponses(value = {
580 @ApiResponse(code=404, message="The controller cannot be found"),
581 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
582 "this request to be fulfilled")
584 public Response controllerProperties(@ApiParam(value="Policy Controller Name", required=true)
585 @PathParam("controller") String controllerName) {
587 PolicyController controller = PolicyController.factory.get(controllerName);
588 return Response.status(Response.Status.OK).
589 entity(controller.getProperties()).
591 } catch (IllegalArgumentException e) {
592 logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
593 return Response.status(Response.Status.NOT_FOUND).
594 entity(new Error(controllerName + " not found")).
596 } catch (IllegalStateException e) {
597 logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
598 return Response.status(Response.Status.NOT_ACCEPTABLE).
599 entity(new Error(controllerName + " not acceptable")).
605 @Path("engine/controllers/{controller}/inputs")
607 value="Policy Controller Input Ports",
608 notes="List of input ports",
609 responseContainer="List"
611 public Response controllerInputs() {
612 return Response.status(Response.Status.OK).
613 entity(Arrays.asList(Inputs.values())).
618 @Path("engine/controllers/{controller}/inputs/configuration")
620 value="Policy Controller Input Configuration Requests",
621 notes="Feeds a configuration request input into the given Policy Controller"
623 @ApiResponses(value={
624 @ApiResponse(code=400, message = "The configuration request is invalid"),
625 @ApiResponse(code=406, message = "The configuration request cannot be honored")
627 public Response controllerUpdate(@ApiParam(value="Policy Controller Name", required=true)
628 @PathParam("controller") String controllerName,
629 @ApiParam(value="Configuration to apply", required=true)
630 ControllerConfiguration controllerConfiguration) {
632 if (controllerName == null || controllerName.isEmpty() ||
633 controllerConfiguration == null ||
634 controllerConfiguration.getName().intern() != controllerName)
635 return Response.status(Response.Status.BAD_REQUEST).
636 entity("A valid or matching controller names must be provided").
639 PolicyController controller;
641 controller = PolicyEngine.manager.updatePolicyController(controllerConfiguration);
642 if (controller == null)
643 return Response.status(Response.Status.BAD_REQUEST).
644 entity(new Error(controllerName + " does not exist")).
646 } catch (IllegalArgumentException e) {
647 logger.info("{}: cannot update policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
648 return Response.status(Response.Status.BAD_REQUEST).
649 entity(new Error(controllerName + " not found: " + e.getMessage())).
651 } catch (Exception e) {
652 logger.info("{}: cannot update policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
653 return Response.status(Response.Status.NOT_ACCEPTABLE).
654 entity(new Error(controllerName + " not acceptable")).build();
657 return Response.status(Response.Status.OK).
663 @Path("engine/controllers/{controller}/switches")
665 value="Policy Controller Switches",
666 notes="List of the Policy Controller Switches",
667 responseContainer="List"
669 public Response controllerSwitches() {
670 return Response.status(Response.Status.OK).
671 entity(Arrays.asList(Switches.values())).
676 @Path("engine/controllers/{controller}/switches/lock")
678 value="Switches on the Policy Controller Lock Control",
679 notes="This action on the switch locks the Policy Controller",
680 response=PolicyController.class
682 @ApiResponses(value = {
683 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
684 "this request to be fulfilled")
686 public Response controllerLock(@ApiParam(value="Policy Controller Name", required=true)
687 @PathParam("controller") String controllerName) {
688 PolicyController policyController = PolicyController.factory.get(controllerName);
689 boolean success = policyController.lock();
691 return Response.status(Status.OK).
692 entity(policyController).
695 return Response.status(Status.NOT_ACCEPTABLE).
696 entity(new Error("Controller " + controllerName + " cannot be locked")).
701 @Path("engine/controllers/{controller}/switches/lock")
703 value="Switches off the Policy Controller Lock Control",
704 notes="This action on the switch unlocks the Policy Controller",
705 response=PolicyController.class
707 @ApiResponses(value = {
708 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
709 "this request to be fulfilled")
711 public Response controllerUnlock(@ApiParam(value="Policy Controller Name", required=true)
712 @PathParam("controller") String controllerName) {
713 PolicyController policyController = PolicyController.factory.get(controllerName);
714 boolean success = policyController.unlock();
716 return Response.status(Status.OK).
717 entity(policyController).
720 return Response.status(Status.NOT_ACCEPTABLE).
721 entity(new Error("Controller " + controllerName + " cannot be unlocked")).
726 @Path("engine/controllers/{controller}/drools")
728 value="Retrieves the Drools Controller subcomponent of the Policy Controller",
729 notes="The Drools Controller provides an abstraction over the Drools subsystem",
730 response=DroolsController.class
732 @ApiResponses(value = {
733 @ApiResponse(code=404, message="The controller cannot be found"),
734 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
735 "this request to be fulfilled")
737 public Response drools(@ApiParam(value="Policy Controller Name", required=true)
738 @PathParam("controller") String controllerName) {
740 DroolsController drools = getDroolsController(controllerName);
741 return Response.status(Response.Status.OK).
744 } catch (IllegalArgumentException e) {
745 logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e);
746 return Response.status(Response.Status.NOT_FOUND).
747 entity(new Error(controllerName + " not found")).
749 } catch (IllegalStateException e) {
750 logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e);
751 return Response.status(Response.Status.NOT_ACCEPTABLE).
752 entity(new Error(controllerName + " not acceptable")).
758 @Path("engine/controllers/{controller}/drools/facts")
760 value="Retrieves Facts Summary information for a given controller",
761 notes="Provides the session names, and a count of fact object in the drools working memory",
762 responseContainer="Map"
764 @ApiResponses(value = {
765 @ApiResponse(code=404, message="The controller cannot be found"),
766 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
767 "this request to be fulfilled")
769 public Response droolsFacts(@ApiParam(value="Policy Controller Name", required=true)
770 @PathParam("controller") String controllerName) {
772 Map<String,Long> sessionCounts = new HashMap<>();
773 DroolsController drools = getDroolsController(controllerName);
774 for (String session : drools.getSessionNames()) {
775 sessionCounts.put(session, drools.factCount(session));
777 return Response.status(Response.Status.OK).
778 entity(sessionCounts).
780 } catch (IllegalArgumentException e) {
781 logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
782 return Response.status(Response.Status.NOT_FOUND).
783 entity(new Error(controllerName + " not found")).
785 } catch (IllegalStateException e) {
786 logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
787 return Response.status(Response.Status.NOT_ACCEPTABLE).
788 entity(new Error(controllerName + " not acceptable")).
794 @Path("engine/controllers/{controller}/drools/facts/{session}")
796 value="Retrieves Fact Types (classnames) for a given controller and its count",
797 notes="The fact types are the classnames of the objects inserted in the drools working memory",
798 responseContainer="Map"
800 @ApiResponses(value = {
801 @ApiResponse(code=404, message="The controller or session cannot be found"),
802 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
803 "this request to be fulfilled")
805 public Response droolsFacts(@ApiParam(value="Policy Controller Name", required=true)
806 @PathParam("controller") String controllerName,
807 @ApiParam(value="Drools Session Name", required=true)
808 @PathParam("session") String sessionName) {
810 DroolsController drools = getDroolsController(controllerName);
811 return Response.status(Response.Status.OK).
812 entity(drools.factClassNames(sessionName)).
814 } catch (IllegalArgumentException e) {
815 logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e);
816 return Response.status(Response.Status.NOT_FOUND).
817 entity(new Error("entity not found")).
819 } catch (IllegalStateException e) {
820 logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e);
821 return Response.status(Response.Status.NOT_ACCEPTABLE).
822 entity(new Error(controllerName + ":" + sessionName + " not acceptable")).
828 @Path("engine/controllers/{controller}/drools/facts/{session}/{factType}")
830 value="Retrieves fact objects of a given type in the drools working memory" +
831 "for a given controller and session",
832 notes="The fact types are the classnames of the objects inserted in the drools working memory",
833 responseContainer="List"
835 @ApiResponses(value = {
836 @ApiResponse(code=404, message="The controller, session, or fact type cannot be found"),
837 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
838 "this request to be fulfilled")
840 public Response droolsFacts(@ApiParam(value="Fact count", required=false)
841 @DefaultValue("false") @QueryParam("count") boolean count,
842 @ApiParam(value="Policy Controller Name", required=true)
843 @PathParam("controller") String controllerName,
844 @ApiParam(value="Drools Session Name", required=true)
845 @PathParam("session") String sessionName,
846 @ApiParam(value="Drools Fact Type", required=true)
847 @PathParam("factType") String factType) {
849 DroolsController drools = getDroolsController(controllerName);
850 List<Object> facts = drools.facts(sessionName, factType, false);
852 return Response.status(Response.Status.OK).entity(facts).build();
854 return Response.status(Response.Status.OK).entity(facts.size()).build();
855 } catch (IllegalArgumentException e) {
856 logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
857 return Response.status(Response.Status.NOT_FOUND).
858 entity(new Error(controllerName + ":" + sessionName + ":" + factType +
861 } catch (IllegalStateException e) {
862 logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
863 return Response.status(Response.Status.NOT_ACCEPTABLE).
864 entity(new Error(controllerName + ":" + sessionName + ":" + factType +
871 @Path("engine/controllers/{controller}/drools/facts/{session}/{factType}")
873 value="Deletes all the fact objects of a given type from the drools working memory" +
874 "for a given controller and session. The objects retracted from the working " +
875 "memory are provided in the response.",
876 notes="The fact types are the classnames of the objects inserted in the drools working memory",
877 responseContainer="List"
879 @ApiResponses(value = {
880 @ApiResponse(code=404, message="The controller, session, or fact type, cannot be found"),
881 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
882 "this request to be fulfilled"),
883 @ApiResponse(code=500, message="A server error has occurred processing this request")
885 public Response droolsFactsDelete(@ApiParam(value="Policy Controller Name", required=true)
886 @PathParam("controller") String controllerName,
887 @ApiParam(value="Drools Session Name", required=true)
888 @PathParam("session") String sessionName,
889 @ApiParam(value="Drools Fact Type", required=true)
890 @PathParam("factType") String factType) {
892 DroolsController drools = getDroolsController(controllerName);
893 List<Object> facts = drools.facts(sessionName, factType, true);
894 return Response.status(Response.Status.OK).entity(facts).build();
895 } catch (IllegalArgumentException e) {
896 logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}",
897 this, controllerName, sessionName, factType, e.getMessage(), e);
898 return Response.status(Response.Status.NOT_FOUND).
899 entity(new Error(controllerName + ":" + sessionName + ":" + factType +
902 } catch (IllegalStateException e) {
903 logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}",
904 this, controllerName, sessionName, factType, e.getMessage(), e);
905 return Response.status(Response.Status.NOT_ACCEPTABLE).
906 entity(new Error(controllerName + ":" + sessionName + ":" + factType +
909 } catch (Exception e) {
910 logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}",
911 this, controllerName, sessionName, factType, e.getMessage(), e);
912 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
913 entity(new Error(e.getMessage())).
919 @Path("engine/controllers/{controller}/drools/facts/{session}/{query}/{queriedEntity}")
921 value="Gets all the fact objects returned by a DRL query with no parameters from the drools working memory" +
922 "for a given controller and session",
923 notes="The DRL query must be defined in the DRL file",
924 responseContainer="List"
926 @ApiResponses(value = {
927 @ApiResponse(code=404, message="The controller, session, or query information, cannot be found"),
928 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
929 "this request to be fulfilled"),
930 @ApiResponse(code=500, message="A server error has occurred processing this request")
932 public Response droolsFacts(@ApiParam(value="Fact count", required=false)
933 @DefaultValue("false") @QueryParam("count") boolean count,
934 @ApiParam(value="Policy Controller Name", required=true)
935 @PathParam("controller") String controllerName,
936 @ApiParam(value="Drools Session Name", required=true)
937 @PathParam("session") String sessionName,
938 @ApiParam(value="Query Name Present in DRL", required=true)
939 @PathParam("query") String queryName,
940 @ApiParam(value="Query Identifier Present in the DRL Query", required=true)
941 @PathParam("queriedEntity") String queriedEntity) {
943 DroolsController drools = getDroolsController(controllerName);
944 List<Object> facts = drools.factQuery(sessionName, queryName, queriedEntity, false);
946 return Response.status(Response.Status.OK).entity(facts).build();
948 return Response.status(Response.Status.OK).entity(facts.size()).build();
949 } catch (IllegalArgumentException e) {
950 logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}",
951 this, controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e);
952 return Response.status(Response.Status.NOT_FOUND).
953 entity(new Error(controllerName + ":" + sessionName + ":" + queryName +
954 queriedEntity + " not found")).
956 } catch (IllegalStateException e) {
957 logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}",
958 this, controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e);
959 return Response.status(Response.Status.NOT_ACCEPTABLE).
960 entity(new Error(controllerName + ":" + sessionName + ":" + queryName +
961 queriedEntity + " not acceptable")).
963 } catch (Exception e) {
964 logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}",
965 this, controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e);
966 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
967 entity(new Error(e.getMessage())).
973 @Path("engine/controllers/{controller}/drools/facts/{session}/{query}/{queriedEntity}")
975 value="Gets all the fact objects returned by a DRL query with parameters from the drools working memory" +
976 "for a given controller and session",
977 notes="The DRL query with parameters must be defined in the DRL file",
978 responseContainer="List"
980 @ApiResponses(value = {
981 @ApiResponse(code=404, message="The controller, session, or query information, cannot be found"),
982 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
983 "this request to be fulfilled"),
984 @ApiResponse(code=500, message="A server error has occurred processing this request")
986 public Response droolsFacts(@ApiParam(value="Policy Controller Name", required=true)
987 @PathParam("controller") String controllerName,
988 @ApiParam(value="Drools Session Name", required=true)
989 @PathParam("session") String sessionName,
990 @ApiParam(value="Query Name Present in DRL", required=true)
991 @PathParam("query") String queryName,
992 @ApiParam(value="Query Identifier Present in the DRL Query", required=true)
993 @PathParam("queriedEntity") String queriedEntity,
994 @ApiParam(value="Query Parameter Values to pass in the DRL Query", required=false)
995 List<Object> queryParameters) {
997 DroolsController drools = getDroolsController(controllerName);
999 if (queryParameters == null || queryParameters.isEmpty())
1000 facts = drools.factQuery(sessionName, queryName, queriedEntity, false);
1002 facts = drools.factQuery(sessionName, queryName, queriedEntity, false, queryParameters.toArray());
1003 return Response.status(Response.Status.OK).entity(facts).build();
1004 } catch (IllegalArgumentException e) {
1005 logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
1006 this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
1007 return Response.status(Response.Status.NOT_FOUND).
1008 entity(new Error(controllerName + ":" + sessionName + ":" + queryName +
1009 queriedEntity + " not found")).
1011 } catch (IllegalStateException e) {
1012 logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
1013 this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
1014 return Response.status(Response.Status.NOT_ACCEPTABLE).
1015 entity(new Error(controllerName + ":" + sessionName + ":" + queryName +
1016 queriedEntity + " not acceptable")).
1018 } catch (Exception e) {
1019 logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
1020 this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
1021 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
1022 entity(new Error(e.getMessage())).
1028 @Path("engine/controllers/{controller}/drools/facts/{session}/{query}/{queriedEntity}")
1030 value="Deletes all the fact objects returned by a DRL query with parameters from the drools working memory" +
1031 "for a given controller and session",
1032 notes="The DRL query with parameters must be defined in the DRL file",
1033 responseContainer="List"
1035 @ApiResponses(value = {
1036 @ApiResponse(code=404, message="The controller, session, or query information, cannot be found"),
1037 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1038 "this request to be fulfilled"),
1039 @ApiResponse(code=500, message="A server error has occurred processing this request")
1041 public Response droolsFactsDelete(@ApiParam(value="Policy Controller Name", required=true)
1042 @PathParam("controller") String controllerName,
1043 @ApiParam(value="Drools Session Name", required=true)
1044 @PathParam("session") String sessionName,
1045 @ApiParam(value="Query Name Present in DRL", required=true)
1046 @PathParam("query") String queryName,
1047 @ApiParam(value="Query Identifier Present in the DRL Query", required=true)
1048 @PathParam("queriedEntity") String queriedEntity,
1049 @ApiParam(value="Query Parameter Values to pass in the DRL Query", required=false)
1050 List<Object> queryParameters) {
1052 DroolsController drools = getDroolsController(controllerName);
1054 if (queryParameters == null || queryParameters.isEmpty())
1055 facts = drools.factQuery(sessionName, queryName, queriedEntity, true);
1057 facts = drools.factQuery(sessionName, queryName, queriedEntity, true, queryParameters.toArray());
1058 return Response.status(Response.Status.OK).entity(facts).build();
1059 } catch (IllegalArgumentException e) {
1060 logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
1061 this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
1062 return Response.status(Response.Status.NOT_FOUND).
1063 entity(new Error(controllerName + ":" + sessionName + ":" + queryName +
1064 queriedEntity + " not found")).
1066 } catch (IllegalStateException e) {
1067 logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
1068 this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
1069 return Response.status(Response.Status.NOT_ACCEPTABLE).
1070 entity(new Error(controllerName + ":" + sessionName + ":" + queryName +
1071 queriedEntity + " not acceptable")).
1073 } catch (Exception e) {
1074 logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
1075 this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
1076 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
1077 entity(new Error(e.getMessage())).
1083 @Path("engine/controllers/tools/coders/decoders/filters/rules/{ruleName}")
1085 value="Produces a Decoder Rule Filter in a format that the Policy Controller can understand",
1086 notes="The result can be used with other APIs to attach a filter to a decoder"
1088 public Response rules(@ApiParam(value="Negate regex?", required=true)
1089 @DefaultValue("false") @QueryParam("negate") boolean negate,
1090 @ApiParam(value="Rule Name", required=true)
1091 @PathParam("ruleName") String name,
1092 @ApiParam(value="Regex expression", required=true)
1094 String literalRegex = Pattern.quote(regex);
1096 literalRegex = "^(?!" + literalRegex + "$).*";
1098 return Response.status(Status.OK).
1099 entity(new JsonProtocolFilter.FilterRule(name,literalRegex)).
1104 @Path("engine/controllers/{controller}/decoders")
1106 value="Gets all the decoders used by a controller",
1107 notes="A Policy Controller uses decoders to deserialize incoming network messages from " +
1108 "subscribed network topics into specific (fact) objects. " +
1109 "The deserialized (fact) object will typically be inserted in the drools working " +
1110 " memory of the controlled drools application.",
1111 responseContainer="List",
1112 response=ProtocolCoderToolset.class
1114 @ApiResponses(value = {
1115 @ApiResponse(code=404, message="The controller cannot be found"),
1116 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1117 "this request to be fulfilled")
1119 public Response decoders(@ApiParam(value="Policy Controller Name", required=true)
1120 @PathParam("controller") String controllerName) {
1122 DroolsController drools = getDroolsController(controllerName);
1123 List<ProtocolCoderToolset> decoders = EventProtocolCoder.manager.getDecoders
1124 (drools.getGroupId(), drools.getArtifactId());
1125 return Response.status(Response.Status.OK).
1128 } catch (IllegalArgumentException e) {
1129 logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
1130 return Response.status(Response.Status.NOT_FOUND).
1131 entity(new Error(controllerName + " not found")).
1133 } catch (IllegalStateException e) {
1134 logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
1135 return Response.status(Response.Status.NOT_ACCEPTABLE).
1136 entity(new Error(controllerName + " not acceptable")).
1142 @Path("engine/controllers/{controller}/decoders/filters")
1144 value="Gets all the filters used by a controller",
1145 notes="A Policy Controller uses decoders to deserialize incoming network messages from " +
1146 "subscribed network topics into specific (fact) objects. " +
1147 "The deserialized (fact) object will typically be inserted in the drools working " +
1148 " memory of the controlled drools application." +
1149 "Acceptance filters are used to filter out undesired network messages for the given controller",
1150 responseContainer="List",
1151 response=CoderFilters.class
1153 @ApiResponses(value = {
1154 @ApiResponse(code=404, message="The controller cannot be found"),
1155 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1156 "this request to be fulfilled")
1158 public Response decoderFilters(@ApiParam(value="Policy Controller Name", required=true)
1159 @PathParam("controller") String controllerName) {
1161 DroolsController drools = getDroolsController(controllerName);
1162 List<CoderFilters> filters = EventProtocolCoder.manager.getDecoderFilters
1163 (drools.getGroupId(), drools.getArtifactId());
1164 return Response.status(Response.Status.OK).
1167 } catch (IllegalArgumentException e) {
1168 logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
1169 return Response.status(Response.Status.NOT_FOUND).
1170 entity(new Error(controllerName + " not found")).
1172 } catch (IllegalStateException e) {
1173 logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
1174 return Response.status(Response.Status.NOT_ACCEPTABLE).
1175 entity(new Error(controllerName + " not acceptable")).
1181 @Path("engine/controllers/{controller}/decoders/{topic}")
1183 value="Gets all the decoders in use by a controller for a networked topic",
1184 notes="A Policy Controller uses decoders to deserialize incoming network messages from " +
1185 "subscribed network topics into specific (fact) objects. " +
1186 "The deserialized (fact) object will typically be inserted in the drools working " +
1187 " memory of the controlled drools application.",
1188 responseContainer="List",
1189 response=ProtocolCoderToolset.class
1191 @ApiResponses(value = {
1192 @ApiResponse(code=404, message="The controller or topic cannot be found"),
1193 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1194 "this request to be fulfilled")
1196 public Response decoder(@ApiParam(value="Policy Controller Name", required=true)
1197 @PathParam("controller") String controllerName,
1198 @ApiParam(value="Networked Topic Name", required=true)
1199 @PathParam("topic") String topic) {
1201 DroolsController drools = getDroolsController(controllerName);
1202 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
1203 (drools.getGroupId(), drools.getArtifactId(), topic);
1204 return Response.status(Response.Status.OK).
1207 } catch (IllegalArgumentException e) {
1208 logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}",
1209 this, controllerName, topic, e.getMessage(), e);
1210 return Response.status(Response.Status.NOT_FOUND).
1211 entity(new Error(controllerName + ":" + topic + " not found")).
1213 } catch (IllegalStateException e) {
1214 logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}",
1215 this, controllerName, topic, e.getMessage(), e);
1216 return Response.status(Response.Status.NOT_ACCEPTABLE).
1217 entity(new Error(controllerName + ":" + topic + " not acceptable")).
1223 @Path("engine/controllers/{controller}/decoders/{topic}/filters")
1225 value="Gets all filters attached to decoders for a given networked topic in use by a controller",
1226 notes="A Policy Controller uses decoders to deserialize incoming network messages from " +
1227 "subscribed network topics into specific (fact) objects. " +
1228 "The deserialized (fact) object will typically be inserted in the drools working " +
1229 " memory of the controlled drools application." +
1230 "Acceptance filters are used to filter out undesired network messages for the given controller",
1231 responseContainer="List",
1232 response=CoderFilters.class
1234 @ApiResponses(value = {
1235 @ApiResponse(code=404, message="The controller or topic cannot be found"),
1236 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1237 "this request to be fulfilled")
1239 public Response decoderFilter(@ApiParam(value="Policy Controller Name", required=true)
1240 @PathParam("controller") String controllerName,
1241 @ApiParam(value="Networked Topic Name", required=true)
1242 @PathParam("topic") String topic) {
1244 DroolsController drools = getDroolsController(controllerName);
1245 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
1246 (drools.getGroupId(), drools.getArtifactId(), topic);
1247 if (decoder == null)
1248 return Response.status(Response.Status.BAD_REQUEST).
1249 entity(new Error(topic + " does not exist")).
1252 return Response.status(Response.Status.OK).
1253 entity(decoder.getCoders()).
1255 } catch (IllegalArgumentException e) {
1256 logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}",
1257 this, controllerName, topic, e.getMessage(), e);
1258 return Response.status(Response.Status.NOT_FOUND).
1259 entity(new Error(controllerName + ":" + topic + " not found")).
1261 } catch (IllegalStateException e) {
1262 logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}",
1263 this, controllerName, topic, e.getMessage(), e);
1264 return Response.status(Response.Status.NOT_ACCEPTABLE).
1265 entity(new Error(controllerName + ":" + topic + " not acceptable")).
1271 @Path("engine/controllers/{controller}/decoders/{topic}/filters/{factType}")
1273 value="Gets all filters attached to decoders for a given subscribed networked topic " +
1275 notes="Decoders are associated with networked topics. A Policy Controller manages " +
1276 "multiple topics and therefore its attached decoders. " +
1277 "A Policy Controller uses filters to further specify the fact mapping. " +
1278 "Filters are applied on a per fact type (classname).",
1279 responseContainer="List",
1280 response=CoderFilters.class
1282 @ApiResponses(value = {
1283 @ApiResponse(code=404, message="The controller, topic, or fact type cannot be found"),
1284 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1285 "this request to be fulfilled")
1287 public Response decoderFilter(@ApiParam(value="Policy Controller Name", required=true)
1288 @PathParam("controller") String controllerName,
1289 @ApiParam(value="Networked Topic Name", required=true)
1290 @PathParam("topic") String topic,
1291 @ApiParam(value="Fact Type", required=true)
1292 @PathParam("factType") String factClass) {
1294 DroolsController drools = getDroolsController(controllerName);
1295 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
1296 (drools.getGroupId(), drools.getArtifactId(), topic);
1297 CoderFilters filters = decoder.getCoder(factClass);
1298 if (filters == null)
1299 return Response.status(Response.Status.BAD_REQUEST).
1300 entity(new Error(topic + ":" + factClass + " does not exist")).
1303 return Response.status(Response.Status.OK).
1306 } catch (IllegalArgumentException e) {
1307 logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}",
1308 this, controllerName, topic, factClass, e.getMessage(), e);
1309 return Response.status(Response.Status.NOT_FOUND).
1310 entity(new Error(controllerName + ":" + topic + ":" +
1311 factClass + " not found")).
1313 } catch (IllegalStateException e) {
1314 logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}",
1315 this, controllerName, topic, factClass, e.getMessage(), e);
1316 return Response.status(Response.Status.NOT_ACCEPTABLE).
1317 entity(new Error(controllerName + ":" + topic + ":" +
1318 factClass + " not acceptable")).
1324 @Path("engine/controllers/{controller}/decoders/{topic}/filters/{factType}")
1326 value="Attaches filters to the decoder for a given networked topic " +
1328 notes="Decoders are associated with networked topics. A Policy Controller manages " +
1329 "multiple topics and therefore its attached decoders. " +
1330 "A Policy Controller uses filters to further specify the fact mapping. " +
1331 "Filters are applied on a per fact type (classname).",
1332 responseContainer="List",
1333 response=CoderFilters.class
1335 @ApiResponses(value = {
1336 @ApiResponse(code=404, message="The controller, topic, fact type, cannot be found, " +
1337 "or a filter has not been provided"),
1338 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1339 "this request to be fulfilled")
1341 public Response decoderFilter(@ApiParam(value="Policy Controller Name", required=true)
1342 @PathParam("controller") String controllerName,
1343 @ApiParam(value="Topic Name", required=true)
1344 @PathParam("topic") String topic,
1345 @ApiParam(value="Fact Type", required=true)
1346 @PathParam("factType") String factClass,
1347 @ApiParam(value="Configuration Filter", required=true)
1348 JsonProtocolFilter configFilters) {
1350 if (configFilters == null) {
1351 return Response.status(Response.Status.BAD_REQUEST).
1352 entity(new Error("Configuration Filters not provided")).
1357 DroolsController drools = getDroolsController(controllerName);
1358 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
1359 (drools.getGroupId(), drools.getArtifactId(), topic);
1360 CoderFilters filters = decoder.getCoder(factClass);
1361 if (filters == null)
1362 return Response.status(Response.Status.BAD_REQUEST).
1363 entity(new Error(topic + ":" + factClass + " does not exist")).
1365 filters.setFilter(configFilters);
1366 return Response.status(Response.Status.OK).
1369 } catch (IllegalArgumentException e) {
1370 logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} filters {} because of {}",
1371 this, controllerName, topic, factClass, configFilters, e.getMessage(), e);
1372 return Response.status(Response.Status.NOT_FOUND).
1373 entity(new Error(controllerName + ":" + topic + ":" +
1374 factClass + " not found")).
1376 } catch (IllegalStateException e) {
1377 logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} filters {} because of {}",
1378 this, controllerName, topic, factClass, configFilters, e.getMessage(), e);
1379 return Response.status(Response.Status.NOT_ACCEPTABLE).
1380 entity(new Error(controllerName + ":" + topic + ":" +
1381 factClass + " not acceptable")).
1387 @Path("engine/controllers/{controller}/decoders/{topic}/filters/{factType}/rules")
1389 value="Gets the filter rules attached to a topic decoder of a controller",
1390 notes="Decoders are associated with networked topics. A Policy Controller manages " +
1391 "multiple topics and therefore its attached decoders. " +
1392 "A Policy Controller uses filters to further specify the fact mapping. " +
1393 "Filters are applied on a per fact type and are composed of field matching rules. ",
1394 responseContainer="List",
1395 response=FilterRule.class
1397 @ApiResponses(value = {
1398 @ApiResponse(code=404, message="The controller, topic, or fact type cannot be found"),
1399 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1400 "this request to be fulfilled")
1402 public Response decoderFilterRules(@ApiParam(value="Policy Controller Name", required=true)
1403 @PathParam("controller") String controllerName,
1404 @ApiParam(value="Topic Name", required=true)
1405 @PathParam("topic") String topic,
1406 @ApiParam(value="Fact Type", required=true)
1407 @PathParam("factType") String factClass) {
1409 DroolsController drools = getDroolsController(controllerName);
1410 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
1411 (drools.getGroupId(), drools.getArtifactId(), topic);
1413 CoderFilters filters = decoder.getCoder(factClass);
1414 if (filters == null)
1415 return Response.status(Response.Status.BAD_REQUEST).
1416 entity(new Error(controllerName + ":" + topic + ":" + factClass + " does not exist")).
1419 JsonProtocolFilter filter = filters.getFilter();
1421 return Response.status(Response.Status.BAD_REQUEST).
1422 entity(new Error(controllerName + ":" + topic + ":" + factClass + " no filters")).
1425 return Response.status(Response.Status.OK).
1426 entity(filter.getRules()).
1428 } catch (IllegalArgumentException e) {
1429 logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}",
1430 this, controllerName, topic, factClass, e.getMessage(), e);
1431 return Response.status(Response.Status.NOT_FOUND).
1432 entity(new Error(controllerName + ":" + topic + ":" +
1433 factClass + " not found")).
1435 } catch (IllegalStateException e) {
1436 logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}",
1437 this, controllerName, topic, factClass, e.getMessage(), e);
1438 return Response.status(Response.Status.NOT_ACCEPTABLE).
1439 entity(new Error(controllerName + ":" + topic + ":" +
1440 factClass + " not acceptable")).
1446 @Path("engine/controllers/{controller}/decoders/{topic}/filters/{factType}/rules/{ruleName}")
1448 value="Gets a filter rule by name attached to a topic decoder of a controller",
1449 notes="Decoders are associated with networked topics. A Policy Controller manages " +
1450 "multiple topics and therefore its attached decoders. " +
1451 "A Policy Controller uses filters to further specify the fact mapping. " +
1452 "Filters are applied on a per fact type and are composed of field matching rules. ",
1453 responseContainer="List",
1454 response=FilterRule.class
1456 @ApiResponses(value = {
1457 @ApiResponse(code=404, message="The controller, topic, fact type, or rule name cannot be found"),
1458 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1459 "this request to be fulfilled")
1461 public Response decoderFilterRules(@ApiParam(value="Policy Controller Name", required=true)
1462 @PathParam("controller") String controllerName,
1463 @ApiParam(value="Topic Name", required=true)
1464 @PathParam("topic") String topic,
1465 @ApiParam(value="Fact Type", required=true)
1466 @PathParam("factType") String factClass,
1467 @ApiParam(value="Rule Name", required=true)
1468 @PathParam("ruleName") String ruleName) {
1470 DroolsController drools = getDroolsController(controllerName);
1471 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
1472 (drools.getGroupId(), drools.getArtifactId(), topic);
1474 CoderFilters filters = decoder.getCoder(factClass);
1475 if (filters == null)
1476 return Response.status(Response.Status.BAD_REQUEST).
1477 entity(new Error(controllerName + ":" + topic + ":" + factClass + " does not exist")).
1480 JsonProtocolFilter filter = filters.getFilter();
1482 return Response.status(Response.Status.BAD_REQUEST).
1483 entity(new Error(controllerName + ":" + topic + ":" + factClass + " no filters")).
1486 return Response.status(Response.Status.OK).
1487 entity(filter.getRules(ruleName)).
1489 } catch (IllegalArgumentException e) {
1490 logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} rule {} because of {}",
1491 this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
1492 return Response.status(Response.Status.NOT_FOUND).
1493 entity(new Error(controllerName + ":" + topic + ":" +
1494 factClass + ": " + ruleName + " not found")).
1496 } catch (IllegalStateException e) {
1497 logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} rule {} because of {}",
1498 this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
1499 return Response.status(Response.Status.NOT_ACCEPTABLE).
1500 entity(new Error(controllerName + ":" + topic + ":" +
1501 factClass + ":" + ruleName + " not acceptable")).
1507 @Path("engine/controllers/{controller}/decoders/{topic}/filters/{factType}/rules/{ruleName}")
1509 value="Deletes a filter rule by name attached to a topic decoder of a controller",
1510 notes="Decoders are associated with networked topics. A Policy Controller manages " +
1511 "multiple topics and therefore its attached decoders. " +
1512 "A Policy Controller uses filters to further specify the fact mapping. " +
1513 "Filters are applied on a per fact type and are composed of field matching rules. ",
1514 responseContainer="List",
1515 response=FilterRule.class
1517 @ApiResponses(value = {
1518 @ApiResponse(code=404, message="The controller, topic, fact type, or rule name cannot be found"),
1519 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1520 "this request to be fulfilled")
1522 public Response decoderFilterRuleDelete(@ApiParam(value="Policy Controller Name", required=true)
1523 @PathParam("controller") String controllerName,
1524 @ApiParam(value="Topic Name", required=true)
1525 @PathParam("topic") String topic,
1526 @ApiParam(value="Fact Type", required=true)
1527 @PathParam("factType") String factClass,
1528 @ApiParam(value="Rule Name", required=true)
1529 @PathParam("ruleName") String ruleName,
1530 @ApiParam(value="Filter Rule", required=true)
1534 DroolsController drools = getDroolsController(controllerName);
1535 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
1536 (drools.getGroupId(), drools.getArtifactId(), topic);
1538 CoderFilters filters = decoder.getCoder(factClass);
1539 if (filters == null)
1540 return Response.status(Response.Status.BAD_REQUEST).
1541 entity(new Error(controllerName + ":" + topic + ":" + factClass + " does not exist")).
1544 JsonProtocolFilter filter = filters.getFilter();
1546 return Response.status(Response.Status.BAD_REQUEST).
1547 entity(new Error(controllerName + ":" + topic + ":" + factClass + " no filters")).
1551 filter.deleteRules(ruleName);
1552 return Response.status(Response.Status.OK).
1553 entity(filter.getRules()).
1557 if (rule.getName() == null || !rule.getName().equals(ruleName))
1558 return Response.status(Response.Status.BAD_REQUEST).
1559 entity(new Error(controllerName + ":" + topic + ":" + factClass + ":" + ruleName +
1560 " rule name request inconsistencies (" + rule.getName() + ")")).
1563 filter.deleteRule(ruleName, rule.getRegex());
1564 return Response.status(Response.Status.OK).
1565 entity(filter.getRules()).
1567 } catch (IllegalArgumentException e) {
1568 logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} rule {} because of {}",
1569 this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
1570 return Response.status(Response.Status.NOT_FOUND).
1571 entity(new Error(controllerName + ":" + topic + ":" +
1572 factClass + ": " + ruleName + " not found")).
1574 } catch (IllegalStateException e) {
1575 logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} rule {} because of {}",
1576 this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
1577 return Response.status(Response.Status.NOT_ACCEPTABLE).
1578 entity(new Error(controllerName + ":" + topic + ":" +
1579 factClass + ":" + ruleName + " not acceptable")).
1585 @Path("engine/controllers/{controller}/decoders/{topic}/filters/{factType}/rules")
1587 value="Places a new filter rule in a topic decoder",
1588 notes="Decoders are associated with networked topics. A Policy Controller manages " +
1589 "multiple topics and therefore its attached decoders. " +
1590 "A Policy Controller uses filters to further specify the fact mapping. " +
1591 "Filters are applied on a per fact type and are composed of field matching rules. ",
1592 responseContainer="List",
1593 response=FilterRule.class
1595 @ApiResponses(value = {
1596 @ApiResponse(code=404, message="The controller, topic, or fact type cannot be found"),
1597 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1598 "this request to be fulfilled")
1600 public Response decoderFilterRule(@ApiParam(value="Policy Controller Name", required=true)
1601 @PathParam("controller") String controllerName,
1602 @ApiParam(value="Topic Name", required=true)
1603 @PathParam("topic") String topic,
1604 @ApiParam(value="Fact Type", required=true)
1605 @PathParam("factType") String factClass,
1606 @ApiParam(value="Rule Name", required=true)
1607 @PathParam("ruleName") String ruleName,
1608 @ApiParam(value="Filter Rule", required=true)
1612 DroolsController drools = getDroolsController(controllerName);
1613 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
1614 (drools.getGroupId(), drools.getArtifactId(), topic);
1616 CoderFilters filters = decoder.getCoder(factClass);
1617 if (filters == null)
1618 return Response.status(Response.Status.BAD_REQUEST).
1619 entity(new Error(controllerName + ":" + topic + ":" + factClass + " does not exist")).
1622 JsonProtocolFilter filter = filters.getFilter();
1624 return Response.status(Response.Status.BAD_REQUEST).
1625 entity(new Error(controllerName + ":" + topic + ":" + factClass + " no filters")).
1628 if (rule.getName() == null)
1629 return Response.status(Response.Status.BAD_REQUEST).
1630 entity(new Error(controllerName + ":" + topic + ":" + factClass +
1631 " rule name request inconsistencies (" + rule.getName() + ")")).
1634 filter.addRule(rule.getName(), rule.getRegex());
1635 return Response.status(Response.Status.OK).
1636 entity(filter.getRules()).
1638 } catch (IllegalArgumentException e) {
1639 logger.debug("{}: cannot access decoder filter rules for policy-controller {} topic {} type {} rule {} because of {}",
1640 this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
1641 return Response.status(Response.Status.NOT_FOUND).
1642 entity(new Error(controllerName + ":" + topic + ":" +
1643 factClass + " not found")).
1645 } catch (IllegalStateException e) {
1646 logger.debug("{}: cannot access decoder filter rules for policy-controller {} topic {} type {} rule {} because of {}",
1647 this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
1648 return Response.status(Response.Status.NOT_ACCEPTABLE).
1649 entity(new Error(controllerName + ":" + topic + ":" +
1650 factClass + " not acceptable")).
1656 @Path("engine/controllers/{controller}/decoders/{topic}")
1657 @Consumes(MediaType.TEXT_PLAIN)
1659 value="Decodes a string into a fact object, and encodes it back into a string",
1660 notes="Tests the decode/encode functions of a controller",
1661 response=CodingResult.class
1663 @ApiResponses(value = {
1664 @ApiResponse(code=400, message="Bad input has been provided"),
1665 @ApiResponse(code=404, message="The controller cannot be found"),
1666 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1667 "this request to be fulfilled")
1669 public Response decode(@ApiParam(value="Policy Controller Name", required=true)
1670 @PathParam("controller") String controllerName,
1671 @ApiParam(value="Topic Name", required=true)
1672 @PathParam("topic") String topic,
1673 @ApiParam(value="JSON String to decode", required=true)
1676 PolicyController policyController;
1678 policyController = PolicyController.factory.get(controllerName);
1679 } catch (IllegalArgumentException e) {
1680 logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}",
1681 this, controllerName, topic, e.getMessage(), e);
1682 return Response.status(Response.Status.NOT_FOUND).
1683 entity(new Error(controllerName + ":" + topic + ":" +
1686 } catch (IllegalStateException e) {
1687 logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}",
1688 this, controllerName, topic, e.getMessage(), e);
1689 return Response.status(Response.Status.NOT_ACCEPTABLE).
1690 entity(new Error(controllerName + ":" + topic + ":" +
1691 " not acceptable")).
1695 CodingResult result = new CodingResult();
1696 result.decoding = false;
1697 result.encoding = false;
1698 result.jsonEncoding = null;
1702 event = EventProtocolCoder.manager.decode
1703 (policyController.getDrools().getGroupId(),
1704 policyController.getDrools().getArtifactId(),
1707 result.decoding = true;
1708 } catch (Exception e) {
1709 logger.debug("{}: cannot get policy-controller {} topic {} because of {}",
1710 this, controllerName, topic, e.getMessage(), e);
1711 return Response.status(Response.Status.BAD_REQUEST).
1712 entity(new Error(e.getMessage())).
1717 result.jsonEncoding = EventProtocolCoder.manager.encode(topic, event);
1718 result.encoding = true;
1719 } catch (Exception e) {
1720 // continue so to propagate decoding results ..
1721 logger.debug("{}: cannot encode for policy-controller {} topic {} because of {}",
1722 this, controllerName, topic, e.getMessage(), e);
1725 return Response.status(Response.Status.OK).
1731 @Path("engine/controllers/{controller}/encoders")
1733 value="Retrieves the encoder filters of a controller",
1734 notes="The encoders serializes a fact object, typically for network transmission",
1735 responseContainer="List",
1736 response=CoderFilters.class
1738 @ApiResponses(value = {
1739 @ApiResponse(code=400, message="Bad input has been provided"),
1740 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1741 "this request to be fulfilled")
1743 public Response encoderFilters(@ApiParam(value="Policy Controller Name", required=true)
1744 @PathParam("controller") String controllerName) {
1745 List<CoderFilters> encoders;
1747 PolicyController controller = PolicyController.factory.get(controllerName);
1748 DroolsController drools = controller.getDrools();
1749 encoders = EventProtocolCoder.manager.getEncoderFilters
1750 (drools.getGroupId(), drools.getArtifactId());
1751 } catch (IllegalArgumentException e) {
1752 logger.debug("{}: cannot get encoder filters for policy-controller {} because of {}",
1753 this, controllerName, e.getMessage(), e);
1754 return Response.status(Response.Status.BAD_REQUEST).
1755 entity(new Error(controllerName + " not found: " + e.getMessage())).
1757 } catch (IllegalStateException e) {
1758 logger.debug("{}: cannot get encoder filters for policy-controller {} because of {}",
1759 this, controllerName, e.getMessage(), e);
1760 return Response.status(Response.Status.NOT_ACCEPTABLE).
1761 entity(new Error(controllerName + " is not accepting the request")).build();
1764 return Response.status(Response.Status.OK).
1770 @Path("engine/topics")
1772 value="Retrieves the managed topics",
1773 notes="Network Topics Aggregation",
1774 response=TopicEndpoint.class
1776 public Response topics() {
1777 return Response.status(Response.Status.OK).
1778 entity(TopicEndpoint.manager).
1783 @Path("engine/topics/switches")
1785 value="Topics Control Switches",
1786 notes="List of the Topic Control Switches",
1787 responseContainer="List"
1789 public Response topicSwitches() {
1790 return Response.status(Response.Status.OK).
1791 entity(Arrays.asList(Switches.values())).
1796 @Path("engine/topics/switches/lock")
1798 value="Locks all the managed topics",
1799 notes="The operation affects all managed sources and sinks",
1800 response=TopicEndpoint.class
1802 @ApiResponses(value = {
1803 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1804 "this request to be fulfilled")
1806 public Response topicsLock() {
1807 boolean success = TopicEndpoint.manager.lock();
1809 return Response.status(Status.OK).
1810 entity(TopicEndpoint.manager).
1813 return Response.status(Status.NOT_ACCEPTABLE).
1814 entity(new Error("cannot perform operation")).
1819 @Path("engine/topics/switches/lock")
1821 value="Unlocks all the managed topics",
1822 notes="The operation affects all managed sources and sinks",
1823 response=TopicEndpoint.class
1825 @ApiResponses(value = {
1826 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
1827 "this request to be fulfilled")
1829 public Response topicsUnlock() {
1830 boolean success = TopicEndpoint.manager.unlock();
1832 return Response.status(Status.OK).
1833 entity(TopicEndpoint.manager).
1836 return Response.status(Status.NOT_ACCEPTABLE).
1837 entity(new Error("cannot perform operation")).
1842 @Path("engine/topics/sources")
1844 value="Retrieves the managed topic sources",
1845 notes="Network Topic Sources Agregation",
1846 responseContainer="List",
1847 response=TopicSource.class
1849 public Response sources() {
1850 return Response.status(Response.Status.OK).
1851 entity(TopicEndpoint.manager.getTopicSources()).
1856 @Path("engine/topics/sinks")
1858 value="Retrieves the managed topic sinks",
1859 notes="Network Topic Sinks Agregation",
1860 responseContainer="List",
1861 response=TopicSink.class
1863 public Response sinks() {
1864 return Response.status(Response.Status.OK).
1865 entity(TopicEndpoint.manager.getTopicSinks()).
1870 @Path("engine/topics/sources/ueb")
1872 value="Retrieves the UEB managed topic sources",
1873 notes="UEB Topic Sources Agregation",
1874 responseContainer="List",
1875 response=UebTopicSource.class
1877 public Response uebSources() {
1878 return Response.status(Response.Status.OK).
1879 entity(TopicEndpoint.manager.getUebTopicSources()).
1884 @Path("engine/topics/sinks/ueb")
1886 value="Retrieves the UEB managed topic sinks",
1887 notes="UEB Topic Sinks Agregation",
1888 responseContainer="List",
1889 response=UebTopicSource.class
1891 public Response uebSinks() {
1892 return Response.status(Response.Status.OK).
1893 entity(TopicEndpoint.manager.getUebTopicSinks()).
1898 @Path("engine/topics/sources/dmaap")
1900 value="Retrieves the DMaaP managed topic sources",
1901 notes="DMaaP Topic Sources Agregation",
1902 responseContainer="List",
1903 response=DmaapTopicSource.class
1905 public Response dmaapSources() {
1906 return Response.status(Response.Status.OK).
1907 entity(TopicEndpoint.manager.getDmaapTopicSources()).
1912 @Path("engine/topics/sinks/dmaap")
1914 value="Retrieves the DMaaP managed topic sinks",
1915 notes="DMaaP Topic Sinks Agregation",
1916 responseContainer="List",
1917 response=DmaapTopicSink.class
1919 public Response dmaapSinks() {
1920 return Response.status(Response.Status.OK).
1921 entity(TopicEndpoint.manager.getDmaapTopicSinks()).
1926 @Path("engine/topics/sources/ueb/{topic}")
1928 value="Retrieves an UEB managed topic source",
1929 notes="This is an UEB Network Communicaton Endpoint source of messages for the Engine",
1930 response=UebTopicSource.class
1932 public Response uebSourceTopic(@ApiParam(value="Topic Name", required=true)
1933 @PathParam("topic") String topic) {
1934 return Response.status(Response.Status.OK).
1935 entity(TopicEndpoint.manager.getUebTopicSource(topic)).
1940 @Path("engine/topics/sinks/ueb/{topic}")
1942 value="Retrieves an UEB managed topic sink",
1943 notes="This is an UEB Network Communicaton Endpoint destination of messages from the Engine",
1944 response=UebTopicSink.class
1946 public Response uebSinkTopic(@ApiParam(value="Topic Name", required=true)
1947 @PathParam("topic") String topic) {
1948 return Response.status(Response.Status.OK).
1949 entity(TopicEndpoint.manager.getUebTopicSink(topic)).
1954 @Path("engine/topics/sources/dmaap/{topic}")
1956 value="Retrieves a DMaaP managed topic source",
1957 notes="This is a DMaaP Network Communicaton Endpoint source of messages for the Engine",
1958 response=DmaapTopicSource.class
1960 public Response dmaapSourceTopic(@ApiParam(value="Topic Name", required=true)
1961 @PathParam("topic") String topic) {
1962 return Response.status(Response.Status.OK).
1963 entity(TopicEndpoint.manager.getDmaapTopicSource(topic)).
1968 @Path("engine/topics/sinks/dmaap/{topic}")
1970 value="Retrieves a DMaaP managed topic sink",
1971 notes="This is a DMaaP Network Communicaton Endpoint destination of messages from the Engine",
1972 response=DmaapTopicSink.class
1974 public Response dmaapSinkTopic(@ApiParam(value="Topic Name", required=true)
1975 @PathParam("topic") String topic) {
1976 return Response.status(Response.Status.OK).
1977 entity(TopicEndpoint.manager.getDmaapTopicSink(topic)).
1982 @Path("engine/topics/sources/ueb/{topic}/events")
1984 value="Retrieves the latest events received by an UEB topic",
1985 notes="This is a UEB Network Communicaton Endpoint source of messages for the Engine",
1986 responseContainer="List"
1988 public Response uebSourceEvents(@ApiParam(value="Topic Name", required=true)
1989 @PathParam("topic") String topic) {
1990 return Response.status(Status.OK).
1991 entity(Arrays.asList(TopicEndpoint.manager.getUebTopicSource(topic).getRecentEvents())).
1996 @Path("engine/topics/sinks/ueb/{topic}/events")
1998 value="Retrieves the latest events sent from a topic",
1999 notes="This is a UEB Network Communicaton Endpoint sink of messages from the Engine",
2000 responseContainer="List"
2002 public Response uebSinkEvents(@ApiParam(value="Topic Name", required=true)
2003 @PathParam("topic") String topic) {
2004 return Response.status(Status.OK).
2005 entity(Arrays.asList(TopicEndpoint.manager.getUebTopicSink(topic).getRecentEvents())).
2010 @Path("engine/topics/sources/dmaap/{topic}/events")
2012 value="Retrieves the latest events received by a DMaaP topic",
2013 notes="This is a DMaaP Network Communicaton Endpoint source of messages for the Engine",
2014 responseContainer="List"
2016 public Response dmaapSourceEvents(@ApiParam(value="Topic Name", required=true)
2017 @PathParam("topic") String topic) {
2018 return Response.status(Status.OK).
2019 entity(Arrays.asList(TopicEndpoint.manager.getDmaapTopicSource(topic).getRecentEvents())).
2024 @Path("engine/topics/sinks/dmaap/{topic}/events")
2026 value="Retrieves the latest events send through a DMaaP topic",
2027 notes="This is a DMaaP Network Communicaton Endpoint destination of messages from the Engine",
2028 responseContainer="List"
2030 public Response dmaapSinkEvents(
2031 @PathParam("topic") String topic) {
2032 return Response.status(Status.OK).
2033 entity(Arrays.asList(TopicEndpoint.manager.getDmaapTopicSink(topic).getRecentEvents())).
2038 @Path("engine/topics/sources/ueb/{topic}/switches")
2040 value="UEB Topic Control Switches",
2041 notes="List of the UEB Topic Control Switches",
2042 responseContainer="List"
2044 public Response uebTopicSwitches() {
2045 return Response.status(Response.Status.OK).
2046 entity(Arrays.asList(Switches.values())).
2051 @Path("engine/topics/sources/ueb/{topic}/switches/lock")
2053 value="Locks an UEB Source topic",
2054 response=UebTopicSource.class
2056 @ApiResponses(value = {
2057 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
2058 "this request to be fulfilled")
2060 public Response uebTopicLock(@ApiParam(value="Topic Name", required=true)
2061 @PathParam("topic") String topic) {
2062 UebTopicSource source = TopicEndpoint.manager.getUebTopicSource(topic);
2063 boolean success = source.lock();
2065 return Response.status(Status.OK).
2069 return Response.status(Status.NOT_ACCEPTABLE).
2070 entity(new Error("cannot perform operation on " + topic)).
2075 @Path("engine/topics/sources/ueb/{topic}/switches/lock")
2077 value="Unlocks an UEB Source topic",
2078 response=UebTopicSource.class
2080 @ApiResponses(value = {
2081 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
2082 "this request to be fulfilled")
2084 public Response uebTopicUnlock(@ApiParam(value="Topic Name", required=true)
2085 @PathParam("topic") String topic) {
2086 UebTopicSource source = TopicEndpoint.manager.getUebTopicSource(topic);
2087 boolean success = source.unlock();
2089 return Response.status(Status.OK).
2093 return Response.status(Status.NOT_ACCEPTABLE).
2094 entity(new Error("cannot perform operation on " + topic)).
2099 @Path("engine/topics/sources/dmaap/{topic}/switches")
2101 value="DMaaP Topic Control Switches",
2102 notes="List of the DMaaP Topic Control Switches",
2103 responseContainer="List"
2105 public Response dmaapTopicSwitches() {
2106 return Response.status(Response.Status.OK).
2107 entity(Arrays.asList(Switches.values())).
2112 @Path("engine/topics/sources/dmaap/{topic}/switches/lock")
2114 value="Locks an DMaaP Source topic",
2115 response=DmaapTopicSource.class
2117 @ApiResponses(value = {
2118 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
2119 "this request to be fulfilled")
2121 public Response dmmapTopicLock(@ApiParam(value="Topic Name", required=true)
2122 @PathParam("topic") String topic) {
2123 DmaapTopicSource source = TopicEndpoint.manager.getDmaapTopicSource(topic);
2124 boolean success = source.lock();
2126 return Response.status(Status.OK).
2130 return Response.status(Status.NOT_ACCEPTABLE).
2131 entity(new Error("cannot perform operation on " + topic)).
2136 @Path("engine/topics/sources/dmaap/{topic}/switches/lock")
2138 value="Unlocks an DMaaP Source topic",
2139 response=DmaapTopicSource.class
2141 @ApiResponses(value = {
2142 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
2143 "this request to be fulfilled")
2145 public Response dmaapTopicUnlock(@ApiParam(value="Topic Name", required=true)
2146 @PathParam("topic") String topic) {
2147 DmaapTopicSource source = TopicEndpoint.manager.getDmaapTopicSource(topic);
2148 boolean success = source.unlock();
2150 return Response.status(Status.OK).
2154 return Response.status(Status.SERVICE_UNAVAILABLE).
2155 entity(new Error("cannot perform operation on " + topic)).
2160 @Path("engine/topics/sources/ueb/{topic}/events")
2161 @Consumes(MediaType.TEXT_PLAIN)
2163 value="Offers an event to an UEB topic for internal processing by the engine",
2164 notes="The offered event is treated as it was incoming from the network",
2165 responseContainer="List"
2167 @ApiResponses(value = {
2168 @ApiResponse(code=404, message="The topic information cannot be found"),
2169 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
2170 "this request to be fulfilled"),
2171 @ApiResponse(code=500, message="A server error has occurred processing this request")
2173 public Response uebOffer(@ApiParam(value="Topic Name", required=true)
2174 @PathParam("topic") String topic,
2175 @ApiParam(value="Network Message", required=true)
2178 UebTopicSource uebReader = TopicEndpoint.manager.getUebTopicSource(topic);
2179 boolean success = uebReader.offer(json);
2181 return Response.status(Status.OK).
2182 entity(Arrays.asList(TopicEndpoint.manager.getUebTopicSource(topic).getRecentEvents())).
2185 return Response.status(Status.NOT_ACCEPTABLE).
2186 entity(new Error("Failure to inject event over " + topic)).
2188 } catch (IllegalArgumentException e) {
2189 logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}",
2190 this, topic, e.getMessage(), e);
2191 return Response.status(Response.Status.NOT_FOUND).
2192 entity(new Error(topic + " not found")).
2194 } catch (IllegalStateException e) {
2195 logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}",
2196 this, topic, e.getMessage(), e);
2197 return Response.status(Response.Status.NOT_ACCEPTABLE).
2198 entity(new Error(topic + " not acceptable due to current state")).
2200 } catch (Exception e) {
2201 logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}",
2202 this, topic, e.getMessage(), e);
2203 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
2204 entity(new Error(e.getMessage())).
2210 @Path("engine/topics/sources/dmaap/{topic}/events")
2211 @Consumes(MediaType.TEXT_PLAIN)
2213 value="Offers an event to a DMaaP topic for internal processing by the engine",
2214 notes="The offered event is treated as it was incoming from the network",
2215 responseContainer="List"
2217 @ApiResponses(value = {
2218 @ApiResponse(code=404, message="The topic information cannot be found"),
2219 @ApiResponse(code=406, message="The system is an administrative state that prevents " +
2220 "this request to be fulfilled"),
2221 @ApiResponse(code=500, message="A server error has occurred processing this request")
2223 public Response dmaapOffer(@ApiParam(value="Topic Name", required=true)
2224 @PathParam("topic") String topic,
2225 @ApiParam(value="Network Message", required=true)
2228 DmaapTopicSource dmaapReader = TopicEndpoint.manager.getDmaapTopicSource(topic);
2229 boolean success = dmaapReader.offer(json);
2231 return Response.status(Status.OK).
2232 entity(Arrays.asList(TopicEndpoint.manager.getDmaapTopicSource(topic).getRecentEvents())).
2235 return Response.status(Status.NOT_ACCEPTABLE).
2236 entity(new Error("Failure to inject event over " + topic)).
2238 } catch (IllegalArgumentException e) {
2239 logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}",
2240 this, topic, e.getMessage(), e);
2241 return Response.status(Response.Status.NOT_FOUND).
2242 entity(new Error(topic + " not found")).
2244 } catch (IllegalStateException e) {
2245 logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}",
2246 this, topic, e.getMessage(), e);
2247 return Response.status(Response.Status.NOT_ACCEPTABLE).
2248 entity(new Error(topic + " not acceptable due to current state")).
2250 } catch (Exception e) {
2251 logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}",
2252 this, topic, e.getMessage(), e);
2253 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
2254 entity(new Error(e.getMessage())).
2260 @Path("engine/tools/uuid")
2262 value="Produces an UUID",
2263 notes="UUID generation utility"
2265 @Produces(MediaType.TEXT_PLAIN)
2266 public Response uuid() {
2267 return Response.status(Status.OK).
2268 entity(UUID.randomUUID().toString()).
2273 @Path("engine/tools/loggers")
2275 value="all active loggers",
2276 responseContainer="List"
2278 @ApiResponses(value = {
2279 @ApiResponse(code=500, message="logging misconfiguration")
2281 public Response loggers() {
2282 List<String> names = new ArrayList<String>();
2283 if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) {
2284 logger.warn("The SLF4J logger factory is not configured for logback");
2285 return Response.status(Status.INTERNAL_SERVER_ERROR).
2286 entity(names).build();
2289 LoggerContext context =
2290 (LoggerContext) LoggerFactory.getILoggerFactory();
2291 for (Logger logger: context.getLoggerList()) {
2292 names.add(logger.getName());
2295 return Response.status(Status.OK).
2301 @Path("engine/tools/loggers/{logger}")
2302 @Produces(MediaType.TEXT_PLAIN)
2304 value="logging level of a logger"
2306 @ApiResponses(value = {
2307 @ApiResponse(code=500, message="logging misconfiguration"),
2308 @ApiResponse(code=404, message="logger not found")
2310 public Response loggerName(@ApiParam(value="Logger Name", required=true)
2311 @PathParam("logger") String loggerName) {
2312 if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) {
2313 logger.warn("The SLF4J logger factory is not configured for logback");
2314 return Response.status(Status.INTERNAL_SERVER_ERROR).build();
2317 LoggerContext context =
2318 (LoggerContext) LoggerFactory.getILoggerFactory();
2319 ch.qos.logback.classic.Logger logger = context.getLogger(loggerName);
2320 if (logger == null) {
2321 return Response.status(Status.NOT_FOUND).build();
2324 String loggerLevel = (logger.getLevel() != null) ? logger.getLevel().toString() : "";
2325 return Response.status(Status.OK).entity(loggerLevel).build();
2329 @Path("engine/tools/loggers/{logger}/{level}")
2330 @Produces(MediaType.TEXT_PLAIN)
2331 @Consumes(MediaType.TEXT_PLAIN)
2333 value="sets the logger level",
2334 notes="Please use the SLF4J logger levels"
2336 @ApiResponses(value = {
2337 @ApiResponse(code=500, message="logging misconfiguration"),
2338 @ApiResponse(code=404, message="logger not found")
2340 public Response loggerName(@ApiParam(value="Logger Name", required=true)
2341 @PathParam("logger") String loggerName,
2342 @ApiParam(value="Logger Level", required=true)
2343 @PathParam("level") String loggerLevel) {
2344 if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) {
2345 logger.warn("The SLF4J logger factory is not configured for logback");
2346 return Response.status(Status.INTERNAL_SERVER_ERROR).build();
2349 LoggerContext context =
2350 (LoggerContext) LoggerFactory.getILoggerFactory();
2351 ch.qos.logback.classic.Logger logger = context.getLogger(loggerName);
2352 if (logger == null) {
2353 return Response.status(Status.NOT_FOUND).build();
2356 logger.setLevel(ch.qos.logback.classic.Level.toLevel(loggerLevel));
2357 return Response.status(Status.OK).entity(logger.getLevel().toString()).build();
2361 * gets the underlying drools controller from the named policy controller
2362 * @param controllerName the policy controller name
2363 * @return the underlying drools controller
2364 * @throws IllegalArgumentException if an invalid controller name has been passed in
2366 protected DroolsController getDroolsController(String controllerName) {
2367 PolicyController controller = PolicyController.factory.get(controllerName);
2368 if (controller == null)
2369 throw new IllegalArgumentException(controllerName + " does not exist");
2371 DroolsController drools = controller.getDrools();
2373 throw new IllegalArgumentException(controllerName + " has no drools configuration");
2379 * Helper classes for aggregation of results
2383 public String toString() {
2384 StringBuilder builder = new StringBuilder();
2385 builder.append("rest-telemetry-api []");
2386 return builder.toString();
2390 * Coding/Encoding Results Aggregation Helper class
2392 public static class CodingResult {
2397 public String jsonEncoding;
2402 public Boolean encoding;
2407 public Boolean decoding;
2411 * Generic Error Reporting class
2413 public static class Error {
2414 public String error;
2416 public Error(String error) {
2422 * Feed Ports into Resources
2424 public enum Inputs {
2431 public enum Switches {