[POLICY-11] New REST APIs to obtain facts info
[policy/drools-pdp.git] / policy-management / src / main / java / org / openecomp / policy / drools / server / restful / RestManager.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-management
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.policy.drools.server.restful;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Properties;
26 import java.util.UUID;
27 import java.util.regex.Pattern;
28
29 import javax.ws.rs.Consumes;
30 import javax.ws.rs.DELETE;
31 import javax.ws.rs.DefaultValue;
32 import javax.ws.rs.GET;
33 import javax.ws.rs.POST;
34 import javax.ws.rs.PUT;
35 import javax.ws.rs.Path;
36 import javax.ws.rs.PathParam;
37 import javax.ws.rs.Produces;
38 import javax.ws.rs.QueryParam;
39 import javax.ws.rs.core.MediaType;
40 import javax.ws.rs.core.Response;
41 import javax.ws.rs.core.Response.Status;
42
43 import org.openecomp.policy.common.logging.eelf.MessageCodes;
44 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
45 import org.openecomp.policy.common.logging.flexlogger.Logger;
46 import org.openecomp.policy.drools.controller.DroolsController;
47 import org.openecomp.policy.drools.event.comm.TopicEndpoint;
48 import org.openecomp.policy.drools.event.comm.TopicSink;
49 import org.openecomp.policy.drools.event.comm.TopicSource;
50 import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSink;
51 import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSource;
52 import org.openecomp.policy.drools.event.comm.bus.UebTopicSink;
53 import org.openecomp.policy.drools.event.comm.bus.UebTopicSource;
54 import org.openecomp.policy.drools.properties.PolicyProperties;
55 import org.openecomp.policy.drools.protocol.coders.EventProtocolCoder;
56 import org.openecomp.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
57 import org.openecomp.policy.drools.protocol.coders.JsonProtocolFilter;
58 import org.openecomp.policy.drools.protocol.coders.JsonProtocolFilter.FilterRule;
59 import org.openecomp.policy.drools.protocol.coders.ProtocolCoderToolset;
60 import org.openecomp.policy.drools.protocol.configuration.ControllerConfiguration;
61 import org.openecomp.policy.drools.protocol.configuration.PdpdConfiguration;
62 import org.openecomp.policy.drools.system.PolicyController;
63 import org.openecomp.policy.drools.system.PolicyEngine;
64
65
66 /**
67  * REST Endpoint for management of the Drools PDP
68  */
69 @Path("/policy/pdp")
70 public class RestManager {
71         /**
72          * Logger
73          */
74         private static Logger  logger = FlexLogger.getLogger(RestManager.class);  
75         
76         /**
77          * gets the Policy Engine
78          * 
79          * @return the Policy Engine
80          */
81     @GET
82     @Path("engine")
83     @Produces(MediaType.APPLICATION_JSON)
84     public PolicyEngine engine() {      
85         return PolicyEngine.manager;
86     }
87     
88     
89     /**
90      * Updates the Policy Engine
91      * 
92      * @param configuration configuration
93      * @return Policy Engine
94      */
95     @PUT
96     @Path("engine")
97     @Produces(MediaType.APPLICATION_JSON)
98     @Consumes(MediaType.APPLICATION_JSON)
99     public Response updateEngine(PdpdConfiguration configuration) {
100         PolicyController controller = null;
101         boolean success = true;
102                 try {
103                         success = PolicyEngine.manager.configure(configuration);
104                 } catch (Exception e) {
105                         success = false;
106                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
107                               "PolicyEngine", this.toString());
108                 }
109         
110                 if (!success)
111                         return Response.status(Response.Status.NOT_ACCEPTABLE).
112                     entity(new Error("cannot perform operation")).build();
113                 else
114                         return Response.status(Response.Status.OK).entity(controller).build();
115     }
116     
117     /**
118      * Activates the Policy Engine
119      * 
120      * @param configuration configuration
121      * @return Policy Engine
122      */
123     @PUT
124     @Path("engine/activation")
125     @Produces(MediaType.APPLICATION_JSON)
126     public Response activateEngine() {
127         boolean success = true;
128                 try {
129                         PolicyEngine.manager.activate();
130                 } catch (Exception e) {
131                         success = false;
132                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
133                               "PolicyEngine", this.toString());
134                 }
135         
136                 if (!success)
137                         return Response.status(Response.Status.NOT_ACCEPTABLE).
138                     entity(new Error("cannot perform operation")).build();
139                 else
140                         return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build();
141     }
142     
143     /**
144      * Activates the Policy Engine
145      * 
146      * @param configuration configuration
147      * @return Policy Engine
148      */
149     @PUT
150     @Path("engine/deactivation")
151     @Produces(MediaType.APPLICATION_JSON)
152     public Response deactivateEngine() {
153         boolean success = true;
154                 try {
155                         PolicyEngine.manager.deactivate();
156                 } catch (Exception e) {
157                         success = false;
158                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
159                               "PolicyEngine", this.toString());
160                 }
161         
162                 if (!success)
163                         return Response.status(Response.Status.NOT_ACCEPTABLE).
164                     entity(new Error("cannot perform operation")).build();
165                 else
166                         return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build();
167     }
168     
169     @DELETE
170     @Path("engine")
171     @Produces(MediaType.APPLICATION_JSON)
172     public Response engineShutdown() { 
173         try {
174                         PolicyEngine.manager.shutdown();
175                 } catch (IllegalStateException e) {
176                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
177                                                   "shutdown: " + PolicyEngine.manager);
178                 return Response.status(Response.Status.BAD_REQUEST).
179                                 entity(PolicyEngine.manager).
180                                 build();
181                 }
182         
183                 return Response.status(Response.Status.OK).
184                                 entity(PolicyEngine.manager).
185                                 build();
186     }   
187     
188     @PUT
189     @Path("engine/lock")
190     @Produces(MediaType.APPLICATION_JSON)
191     @Consumes(MediaType.APPLICATION_JSON)
192     public Response lockEngine() {
193         boolean success = PolicyEngine.manager.lock();
194         if (success)
195                 return Response.status(Status.OK).
196                                         entity("Policy Engine is locked").
197                                         build();
198         else
199                 return Response.status(Status.SERVICE_UNAVAILABLE).
200                                         entity("Policy Engine cannot be locked").
201                                         build();
202     }
203     
204     @DELETE
205     @Path("engine/unlock")
206     @Produces(MediaType.APPLICATION_JSON)
207     @Consumes(MediaType.APPLICATION_JSON)
208     public Response unlockEngine() {
209         boolean success = PolicyEngine.manager.unlock();
210         if (success)
211                 return Response.status(Status.OK).
212                                         entity("Policy Engine is unlocked").
213                                         build();
214         else
215                 return Response.status(Status.SERVICE_UNAVAILABLE).
216                                         entity("Policy Engine cannot be unlocked").
217                                         build();
218     }
219     
220     @GET
221     @Path("engine/controllers")
222     @Produces(MediaType.APPLICATION_JSON)
223     public List<PolicyController> controllers() {
224         return PolicyEngine.manager.getPolicyControllers();
225     }
226     
227     @POST
228     @Path("engine/controllers")
229     @Produces(MediaType.APPLICATION_JSON)
230     @Consumes(MediaType.APPLICATION_JSON)
231     public Response addController(Properties config) {
232         if (config == null)
233                 return Response.status(Response.Status.BAD_REQUEST).
234                                         entity(new Error("A configuration must be provided")).
235                                         build();
236         
237         String controllerName = config.getProperty(PolicyProperties.PROPERTY_CONTROLLER_NAME);
238         if (controllerName == null || controllerName.isEmpty())
239                 return Response.status(Response.Status.BAD_REQUEST).
240                                         entity(new Error
241                                                                 ("Configuration must have an entry for " + 
242                                                      PolicyProperties.PROPERTY_CONTROLLER_NAME)).
243                                         build();
244         
245         PolicyController controller;
246                 try {
247                         controller = PolicyController.factory.get(controllerName);
248                         if (controller != null)
249                                 return Response.status(Response.Status.NOT_MODIFIED).
250                                                         entity(controller).
251                                                         build();
252                 } catch (IllegalArgumentException e) {
253                         // This is OK
254                 } catch (IllegalStateException e) {
255                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
256                               controllerName, this.toString());
257                         return Response.status(Response.Status.NOT_ACCEPTABLE).
258                             entity(new Error(controllerName + " not found")).build();
259                 }
260         
261         try {
262                         controller = PolicyEngine.manager.createPolicyController
263                                         (config.getProperty(PolicyProperties.PROPERTY_CONTROLLER_NAME), config);
264                 } catch (IllegalArgumentException | IllegalStateException e) {
265                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
266                                           controllerName, this.toString());
267                 return Response.status(Response.Status.BAD_REQUEST).
268                                                                 entity(new Error(e.getMessage())).
269                                                                 build();
270                 }
271         
272         try {
273                         boolean success = controller.start();
274                         if (!success) {
275                                 logger.warn("Can't start " + controllerName + ": " + controller.toString());
276                                 return Response.status(Response.Status.PARTIAL_CONTENT).
277                                        entity(new Error(controllerName + " can't be started")).build();
278                         }
279                 } catch (IllegalStateException e) {
280                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
281                     controllerName, this.toString());
282                         return Response.status(Response.Status.PARTIAL_CONTENT).
283                                    entity(controller).build();
284                 }
285         
286                 return Response.status(Response.Status.CREATED).
287                 entity(controller).
288                 build();
289     }    
290     
291     @GET
292     @Path("engine/controllers/{controllerName}")
293     @Produces(MediaType.APPLICATION_JSON)
294     public Response controller(@PathParam("controllerName") String controllerName) {
295         PolicyController controller = null;
296                 try {
297                         controller = PolicyController.factory.get(controllerName);
298                 } catch (IllegalArgumentException e) {
299                         logger.info("Can't retrieve controller " + controllerName + 
300                                                   ".  Reason: " + e.getMessage());
301                 } catch (IllegalStateException e) {
302                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
303                               controllerName, this.toString());
304                         return Response.status(Response.Status.NOT_ACCEPTABLE).
305                             entity(new Error(controllerName + " not acceptable")).build();
306                 }
307         
308                 if (controller != null)
309                 return Response.status(Response.Status.OK).
310                                 entity(controller).build();
311                 else
312                         return Response.status(Response.Status.NOT_FOUND).
313                                            entity(new Error(controllerName + " not found")).build();
314     }
315     
316     @DELETE
317     @Path("engine/controllers/{controllerName}")
318     @Produces(MediaType.APPLICATION_JSON)
319     @Consumes(MediaType.APPLICATION_JSON)
320     public Response deleteController(@PathParam("controllerName") String controllerName) {
321         
322         if (controllerName == null || controllerName.isEmpty())
323                 return Response.status(Response.Status.BAD_REQUEST).
324                                         entity("A controller name must be provided").
325                                         build();
326         
327         PolicyController controller;
328         try {
329                 controller =
330                                 PolicyController.factory.get(controllerName);
331                 if (controller == null)
332                         return Response.status(Response.Status.BAD_REQUEST).
333                                                 entity(new Error(controllerName + "  does not exist")).
334                                                 build();
335                 } catch (IllegalArgumentException e) {
336                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
337                                           controllerName, this.toString());
338                         return Response.status(Response.Status.BAD_REQUEST).
339                                                                 entity(new Error(controllerName +  " not found: " + e.getMessage())).
340                                                                 build();
341                 } catch (IllegalStateException e) {
342                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
343                               controllerName, this.toString());
344                         return Response.status(Response.Status.NOT_ACCEPTABLE).
345                                    entity(new Error(controllerName + " not acceptable")).build();
346                 }
347         
348         try {
349                         PolicyEngine.manager.removePolicyController(controllerName);
350                 } catch (IllegalArgumentException | IllegalStateException e) {
351                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
352                                           controllerName + controller);
353                 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
354                                                                entity(new Error(e.getMessage())).
355                                                                build();
356                 }
357         
358                 return Response.status(Response.Status.OK).
359                 entity(controller).
360                 build();
361     }
362     
363     /**
364      * Updates the Policy Engine
365      * 
366      * @param configuration configuration
367      * @return Policy Engine
368      */
369     @PUT
370     @Path("engine/controllers/{controllerName}")
371     @Produces(MediaType.APPLICATION_JSON)
372     @Consumes(MediaType.APPLICATION_JSON)
373     public Response updateController(@PathParam("controllerName") String controllerName,
374                                          ControllerConfiguration controllerConfiguration) {
375         
376         if (controllerName == null || controllerName.isEmpty() || 
377             controllerConfiguration == null || 
378             controllerConfiguration.getName().intern() != controllerName)
379                 return Response.status(Response.Status.BAD_REQUEST).
380                                         entity("A valid or matching controller names must be provided").
381                                         build();
382         
383         PolicyController controller;
384         try {
385                 controller = PolicyEngine.manager.updatePolicyController(controllerConfiguration);
386                 if (controller == null)
387                         return Response.status(Response.Status.BAD_REQUEST).
388                                                 entity(new Error(controllerName + "  does not exist")).
389                                                 build();
390                 } catch (IllegalArgumentException e) {
391                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
392                                           controllerName, this.toString());
393                         return Response.status(Response.Status.BAD_REQUEST).
394                                                                 entity(new Error(controllerName +  " not found: " + e.getMessage())).
395                                                                 build();
396                 } catch (Exception e) {
397                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
398                               controllerName, this.toString());
399                         return Response.status(Response.Status.NOT_ACCEPTABLE).
400                                    entity(new Error(controllerName + " not acceptable")).build();
401                 }
402         
403                 return Response.status(Response.Status.OK).
404                 entity(controller).
405                 build();
406     }
407     
408     @GET
409     @Path("engine/controllers/{controllerName}/drools")
410     @Produces(MediaType.APPLICATION_JSON)
411     public Response drools(@PathParam("controllerName") String controllerName) {
412                 try {
413                         DroolsController drools = getDroolsController(controllerName);                  
414                         return Response.status(Response.Status.OK).
415                                        entity(drools).
416                                        build();
417                 } catch (IllegalArgumentException | IllegalStateException e) {
418                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
419                           controllerName, this.toString());
420                         return Response.status(Response.Status.BAD_REQUEST).
421                                                        entity(new Error(e.getMessage())).
422                                                        build();
423                 }
424     }
425     
426     @GET
427     @Path("engine/controllers/{controllerName}/drools/facts/{sessionName}")
428     @Produces(MediaType.APPLICATION_JSON)
429     public Response droolsFacts(@DefaultValue("false") @QueryParam("count") boolean count,
430                                     @PathParam("controllerName") String controllerName,
431                                     @PathParam("sessionName") String sessionName) {
432                 try {
433                         DroolsController drools = getDroolsController(controllerName);
434                         if (!count)
435                                 return Response.status(Response.Status.OK).
436                                                entity(drools.factClassNames(sessionName)).
437                                                build();
438                         else
439                                 return Response.status(Response.Status.OK).
440                                        entity(new Long(drools.factCount(sessionName))).
441                                        build();
442                 } catch (IllegalArgumentException | IllegalStateException e) {
443                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
444                           controllerName, this.toString());
445                         return Response.status(Response.Status.BAD_REQUEST).
446                                                        entity(new Error(e.getMessage())).
447                                                        build();
448                 }
449     }
450     
451     @GET
452     @Path("engine/controllers/{controllerName}/drools/facts/{sessionName}/{className}")
453     @Produces(MediaType.APPLICATION_JSON)
454     public Response droolsFacts(@DefaultValue("false") @QueryParam("count") boolean count,
455                                     @PathParam("controllerName") String controllerName,
456                                     @PathParam("sessionName") String sessionName,
457                                     @PathParam("className") String className) {
458                 try {
459                         DroolsController drools = getDroolsController(controllerName);
460                         List<Object> facts = drools.facts(sessionName, className);
461                         if (!count)
462                                 return Response.status(Response.Status.OK).entity(facts).build();
463                         else
464                                 return Response.status(Response.Status.OK).entity(facts.size()).build();
465                 } catch (IllegalArgumentException | IllegalStateException e) {
466                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
467                           controllerName, this.toString());
468                         return Response.status(Response.Status.BAD_REQUEST).
469                                                        entity(new Error(e.getMessage())).
470                                                        build();
471                 }
472     }
473     
474     @GET
475     @Path("engine/controllers/{controllerName}/drools/facts/{sessionName}/{queryName}/{queriedEntity}")
476     @Produces(MediaType.APPLICATION_JSON)
477     public Response droolsFacts(@DefaultValue("false") @QueryParam("count") boolean count,
478                                     @PathParam("controllerName") String controllerName,
479                                     @PathParam("sessionName") String sessionName,
480                                     @PathParam("queryName") String queryName,
481                                     @PathParam("queriedEntity") String queriedEntity) {
482                 try {
483                         DroolsController drools = getDroolsController(controllerName);
484                         List<Object> facts = drools.factQuery(sessionName, queryName, queriedEntity);
485                         if (!count)
486                                 return Response.status(Response.Status.OK).entity(facts).build();
487                         else
488                                 return Response.status(Response.Status.OK).entity(facts.size()).build();
489                 } catch (IllegalArgumentException | IllegalStateException e) {
490                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
491                           controllerName, this.toString());
492                         return Response.status(Response.Status.BAD_REQUEST).
493                                                        entity(new Error(e.getMessage())).
494                                                        build();
495                 }
496     }
497     
498     @GET
499     @Path("engine/controllers/{controllerName}/decoders")
500     @Produces(MediaType.APPLICATION_JSON)
501     public Response decoders(@PathParam("controllerName") String controllerName) {
502                 try {
503                         DroolsController drools = getDroolsController(controllerName);
504                         List<ProtocolCoderToolset> decoders = EventProtocolCoder.manager.getDecoders
505                                                                                                                 (drools.getGroupId(), drools.getArtifactId());                  
506                         return Response.status(Response.Status.OK).
507                                        entity(decoders).
508                                        build();
509                 } catch (IllegalArgumentException | IllegalStateException e) {
510                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
511                           controllerName, this.toString());
512                         return Response.status(Response.Status.BAD_REQUEST).
513                                                        entity(new Error(e.getMessage())).
514                                                        build();
515                 }
516     }
517     
518     @GET
519     @Path("engine/controllers/{controllerName}/decoders/filters")
520     @Produces(MediaType.APPLICATION_JSON)
521     public Response decoderFilters(@PathParam("controllerName") String controllerName) {
522                 try {
523                         DroolsController drools = getDroolsController(controllerName);
524                         List<CoderFilters> filters = EventProtocolCoder.manager.getDecoderFilters
525                                                         (drools.getGroupId(), drools.getArtifactId());
526                         return Response.status(Response.Status.OK).
527                                     entity(filters).
528                                     build();
529                 } catch (IllegalArgumentException | IllegalStateException e) {
530                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
531                           controllerName, this.toString());
532                         return Response.status(Response.Status.BAD_REQUEST).
533                                                        entity(new Error(e.getMessage())).
534                                                        build();
535                 }
536     }
537     
538     @GET
539     @Path("engine/controllers/{controllerName}/decoders/{topicName}")
540     @Produces(MediaType.APPLICATION_JSON)
541     public Response decoder(@PathParam("controllerName") String controllerName,
542                                  @PathParam("topicName") String topicName) {
543                 try {
544                         DroolsController drools = getDroolsController(controllerName);
545                         ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
546                                                         (drools.getGroupId(), drools.getArtifactId(), topicName);
547                         return Response.status(Response.Status.OK).
548                                     entity(decoder).
549                                     build();
550                 } catch (IllegalArgumentException | IllegalStateException e) {
551                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
552                           controllerName, this.toString());
553                         return Response.status(Response.Status.BAD_REQUEST).
554                                                        entity(new Error(e.getMessage())).
555                                                        build();
556                 }
557     }    
558     
559     @GET
560     @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters")
561     @Produces(MediaType.APPLICATION_JSON)
562     public Response decoderFilter(@PathParam("controllerName") String controllerName,
563                                        @PathParam("topicName") String topicName) {
564                 try {
565                         DroolsController drools = getDroolsController(controllerName);
566                         ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
567                                                                                                 (drools.getGroupId(), drools.getArtifactId(), topicName);
568                         if (decoder == null)
569                         return Response.status(Response.Status.BAD_REQUEST).
570                                         entity(new Error(topicName + "  does not exist")).
571                                         build();
572                         else
573                                 return Response.status(Response.Status.OK).
574                             entity(decoder.getCoders()).
575                             build();
576                 } catch (IllegalArgumentException | IllegalStateException e) {
577                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
578                           controllerName, this.toString());
579                         return Response.status(Response.Status.BAD_REQUEST).
580                                                        entity(new Error(e.getMessage())).
581                                                        build();
582                 }
583     }
584     
585     @GET
586     @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters/{factClassName}")
587     @Produces(MediaType.APPLICATION_JSON)
588     public Response decoderFilter(@PathParam("controllerName") String controllerName,
589                                        @PathParam("topicName") String topicName,
590                                        @PathParam("factClassName") String factClass) {
591                 try {
592                         DroolsController drools = getDroolsController(controllerName);
593                 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
594                                                                                         (drools.getGroupId(), drools.getArtifactId(), topicName);
595                         CoderFilters filters = decoder.getCoder(factClass);
596                         if (filters == null)
597                         return Response.status(Response.Status.BAD_REQUEST).
598                                         entity(new Error(topicName + ":" + factClass + "  does not exist")).
599                                         build();
600                         else
601                                 return Response.status(Response.Status.OK).
602                         entity(filters).
603                         build();
604                 } catch (IllegalArgumentException | IllegalStateException e) {
605                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
606                           controllerName, this.toString());
607                         return Response.status(Response.Status.BAD_REQUEST).
608                                                        entity(new Error(e.getMessage())).
609                                                        build();
610                 }
611     }
612     
613     @POST
614     @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters/{factClassName}")
615     @Consumes(MediaType.APPLICATION_JSON)
616     @Produces(MediaType.APPLICATION_JSON)
617     public Response decoderFilter(@PathParam("controllerName") String controllerName,
618                                       @PathParam("topicName") String topicName,
619                                       @PathParam("factClassName") String factClass,
620                                       JsonProtocolFilter configFilters) {
621         
622         if (configFilters == null) {
623                 return Response.status(Response.Status.BAD_REQUEST).
624                                         entity(new Error("Configuration Filters not provided")).
625                                         build();
626         }
627         
628                 try {
629                         DroolsController drools = getDroolsController(controllerName);
630                 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
631                                                                                         (drools.getGroupId(), drools.getArtifactId(), topicName);
632                 CoderFilters filters = decoder.getCoder(factClass);
633                         if (filters == null)
634                         return Response.status(Response.Status.BAD_REQUEST).
635                                         entity(new Error(topicName + ":" + factClass + "  does not exist")).
636                                         build();
637                         filters.setFilter(configFilters);
638                         return Response.status(Response.Status.OK).
639                                     entity(filters).
640                                     build();
641                 } catch (IllegalArgumentException | IllegalStateException e) {
642                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
643                           controllerName, this.toString());
644                         return Response.status(Response.Status.BAD_REQUEST).
645                                                        entity(new Error(e.getMessage())).
646                                                        build();
647                 }
648     }
649     
650     @GET
651     @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters/{factClassName}/rules")
652     @Produces(MediaType.APPLICATION_JSON)
653     public Response decoderFilterRules(@PathParam("controllerName") String controllerName,
654                                           @PathParam("topicName") String topicName,
655                                           @PathParam("factClassName") String factClass) {
656                 try {
657                         DroolsController drools = getDroolsController(controllerName);
658                 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
659                                                                                         (drools.getGroupId(), drools.getArtifactId(), topicName);
660                 
661                 CoderFilters filters = decoder.getCoder(factClass);
662                         if (filters == null)
663                         return Response.status(Response.Status.BAD_REQUEST).
664                                         entity(new Error(controllerName + ":" + topicName + ":" + factClass + "  does not exist")).
665                                         build();
666                         
667                         JsonProtocolFilter filter = filters.getFilter();
668                         if (filter == null)
669                         return Response.status(Response.Status.BAD_REQUEST).
670                                         entity(new Error(controllerName + ":" + topicName + ":" + factClass + "  no filters")).
671                                         build();
672                         
673                         return Response.status(Response.Status.OK).
674                                     entity(filter.getRules()).
675                                     build();
676                 } catch (IllegalArgumentException | IllegalStateException e) {
677                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
678                           controllerName, this.toString());
679                         return Response.status(Response.Status.BAD_REQUEST).
680                                                        entity(new Error(e.getMessage())).
681                                                        build();
682                 }
683     }
684     
685     @GET
686     @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters/{factClassName}/rules/{ruleName}")
687     @Produces(MediaType.APPLICATION_JSON)
688     public Response decoderFilterRules(@PathParam("controllerName") String controllerName,
689                                           @PathParam("topicName") String topicName,
690                                           @PathParam("factClassName") String factClass,
691                                           @PathParam("ruleName") String ruleName) {
692                 try {
693                         DroolsController drools = getDroolsController(controllerName);
694                 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
695                                                                                         (drools.getGroupId(), drools.getArtifactId(), topicName);
696                 
697                 CoderFilters filters = decoder.getCoder(factClass);
698                         if (filters == null)
699                         return Response.status(Response.Status.BAD_REQUEST).
700                                         entity(new Error(controllerName + ":" + topicName + ":" + factClass + "  does not exist")).
701                                         build();
702                         
703                         JsonProtocolFilter filter = filters.getFilter();
704                         if (filter == null)
705                         return Response.status(Response.Status.BAD_REQUEST).
706                                         entity(new Error(controllerName + ":" + topicName + ":" + factClass + "  no filters")).
707                                         build();
708                         
709                         return Response.status(Response.Status.OK).
710                                     entity(filter.getRules(ruleName)).
711                                     build();
712                 } catch (IllegalArgumentException | IllegalStateException e) {
713                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
714                           controllerName, this.toString());
715                         return Response.status(Response.Status.BAD_REQUEST).
716                                                        entity(new Error(e.getMessage())).
717                                                        build();
718                 }
719     }
720     
721     @DELETE
722     @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters/{factClassName}/rules/{ruleName}")
723     @Consumes(MediaType.APPLICATION_JSON)
724     @Produces(MediaType.APPLICATION_JSON)
725     public Response deleteDecoderFilterRule(@PathParam("controllerName") String controllerName,
726                                                   @PathParam("topicName") String topicName,
727                                                   @PathParam("factClassName") String factClass,
728                                                   @PathParam("ruleName") String ruleName,
729                                                   FilterRule rule) {
730                 
731                 try {
732                         DroolsController drools = getDroolsController(controllerName);
733                 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
734                                                                                         (drools.getGroupId(), drools.getArtifactId(), topicName);
735                 
736                 CoderFilters filters = decoder.getCoder(factClass);
737                         if (filters == null)
738                         return Response.status(Response.Status.BAD_REQUEST).
739                                         entity(new Error(controllerName + ":" + topicName + ":" + factClass + "  does not exist")).
740                                         build();
741                         
742                         JsonProtocolFilter filter = filters.getFilter();
743                         if (filter == null)
744                         return Response.status(Response.Status.BAD_REQUEST).
745                                         entity(new Error(controllerName + ":" + topicName + ":" + factClass + "  no filters")).
746                                         build();
747                         
748                         if (rule == null) {
749                                 filter.deleteRules(ruleName);
750                                 return Response.status(Response.Status.OK).
751                             entity(filter.getRules()).
752                             build();            
753                         }
754                         
755                         if (rule.getName() == null || !rule.getName().equals(ruleName))
756                         return Response.status(Response.Status.BAD_REQUEST).
757                                         entity(new Error(controllerName + ":" + topicName + ":" + factClass + ":" + ruleName + 
758                                                                  " rule name request inconsistencies (" + rule.getName() + ")")).
759                                         build();
760                         
761                         filter.deleteRule(ruleName, rule.getRegex());
762                         return Response.status(Response.Status.OK).
763                                     entity(filter.getRules()).
764                                     build();
765                 } catch (IllegalArgumentException | IllegalStateException e) {
766                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
767                           controllerName, this.toString());
768                         return Response.status(Response.Status.BAD_REQUEST).
769                                                        entity(new Error(e.getMessage())).
770                                                        build();
771                 }
772     }
773     
774     @PUT
775     @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters/{factClassName}/rules")
776     @Produces(MediaType.APPLICATION_JSON)
777     public Response decoderFilterRule(@PathParam("controllerName") String controllerName,
778                                               @PathParam("topicName") String topicName,
779                                               @PathParam("factClassName") String factClass,
780                                               JsonProtocolFilter.FilterRule rule) {
781                 
782                 try {
783                         DroolsController drools = getDroolsController(controllerName);
784                 ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders
785                                                                                         (drools.getGroupId(), drools.getArtifactId(), topicName);
786                 
787                 CoderFilters filters = decoder.getCoder(factClass);
788                         if (filters == null)
789                         return Response.status(Response.Status.BAD_REQUEST).
790                                         entity(new Error(controllerName + ":" + topicName + ":" + factClass + "  does not exist")).
791                                         build();
792                         
793                         JsonProtocolFilter filter = filters.getFilter();
794                         if (filter == null)
795                         return Response.status(Response.Status.BAD_REQUEST).
796                                         entity(new Error(controllerName + ":" + topicName + ":" + factClass + "  no filters")).
797                                         build();
798                         
799                         if (rule.getName() == null)
800                         return Response.status(Response.Status.BAD_REQUEST).
801                                         entity(new Error(controllerName + ":" + topicName + ":" + factClass +  
802                                                                  " rule name request inconsistencies (" + rule.getName() + ")")).
803                                         build();
804                         
805                         filter.addRule(rule.getName(), rule.getRegex());
806                         return Response.status(Response.Status.OK).
807                                     entity(filter.getRules()).
808                                     build();
809                 } catch (IllegalArgumentException | IllegalStateException e) {
810                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
811                           controllerName, this.toString());
812                         return Response.status(Response.Status.BAD_REQUEST).
813                                                        entity(new Error(e.getMessage())).
814                                                        build();
815                 }
816     }
817     
818     @GET
819     @Path("engine/controllers/{controllerName}/encoders")
820     @Produces(MediaType.APPLICATION_JSON)
821     public Response encoderFilters(@PathParam("controllerName") String controllerName) {        
822                 List<CoderFilters> encoders;
823                 try {
824                         PolicyController controller = PolicyController.factory.get(controllerName);
825                 if (controller == null)
826                         return Response.status(Response.Status.BAD_REQUEST).
827                                                 entity(new Error(controllerName + "  does not exist")).
828                                                 build();
829                         DroolsController drools = controller.getDrools();
830                 if (drools == null)
831                         return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
832                                                 entity(new Error(controllerName + "  has not drools component")).
833                                                 build();
834                         encoders = EventProtocolCoder.manager.getEncoderFilters
835                                                         (drools.getGroupId(), drools.getArtifactId());
836                 } catch (IllegalArgumentException e) {
837                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
838                           controllerName, this.toString());
839                         return Response.status(Response.Status.BAD_REQUEST).
840                                                        entity(new Error(controllerName +  " not found: " + e.getMessage())).
841                                                        build();
842                 } catch (IllegalStateException e) {
843                         logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
844                     controllerName, this.toString());
845                         return Response.status(Response.Status.NOT_ACCEPTABLE).
846                             entity(new Error(controllerName + " is not accepting the request")).build();
847                 }
848                 
849                 return Response.status(Response.Status.OK).
850                                entity(encoders).
851                                build();
852     }
853     
854     @POST
855     @Path("engine/controllers/{controllerName}/decoders/{topic}")
856     @Produces(MediaType.APPLICATION_JSON)
857     public Response decode(@PathParam("controllerName") String controllerName,
858                                    @PathParam("topic") String topic,
859                                    String json) {
860         
861         PolicyController policyController = PolicyController.factory.get(controllerName);
862         
863         CodingResult result = new CodingResult();
864                 result.decoding = false;
865                 result.encoding = false;
866                 result.jsonEncoding = null;
867
868                 Object event;
869         try {
870                 event = EventProtocolCoder.manager.decode
871                                         (policyController.getDrools().getGroupId(), 
872                                          policyController.getDrools().getArtifactId(), 
873                                          topic, 
874                                          json);
875                 result.decoding = true;
876         } catch (Exception e) {
877                 return Response.status(Response.Status.BAD_REQUEST).
878                                 entity(new Error(e.getMessage())).
879                                 build();
880         }
881         
882         try {
883                 result.jsonEncoding = EventProtocolCoder.manager.encode(topic, event);
884                 result.encoding = true;
885         } catch (Exception e) {
886                 return Response.status(Response.Status.OK).
887                                 entity(result).
888                                 build();
889         } 
890         
891                 return Response.status(Response.Status.OK).
892                 entity(result).
893                 build();
894     }
895     
896         @GET
897     @Path("engine/topics")
898     @Produces(MediaType.APPLICATION_JSON)
899     public TopicEndpoint topics() {
900         return TopicEndpoint.manager;
901     }
902     
903         @SuppressWarnings("unchecked")
904         @GET
905     @Path("engine/topics/sources")
906     @Produces(MediaType.APPLICATION_JSON)
907     public List<TopicSource> sources() {
908         return (List<TopicSource>) TopicEndpoint.manager.getTopicSources();
909     }
910     
911     @SuppressWarnings("unchecked")
912         @GET
913     @Path("engine/topics/sinks")
914     @Produces(MediaType.APPLICATION_JSON)
915     public List<TopicSink> sinks() {
916         return (List<TopicSink>) TopicEndpoint.manager.getTopicSinks();
917     }
918     
919         @GET
920     @Path("engine/topics/sources/ueb")
921     @Produces(MediaType.APPLICATION_JSON)
922     public List<UebTopicSource> uebSources() {
923         return TopicEndpoint.manager.getUebTopicSources();
924     }
925     
926         @GET
927     @Path("engine/topics/sinks/ueb")
928     @Produces(MediaType.APPLICATION_JSON)
929     public List<UebTopicSink> uebSinks() {
930         return (List<UebTopicSink>) TopicEndpoint.manager.getUebTopicSinks();
931     }
932     
933         @GET
934     @Path("engine/topics/sources/dmaap")
935     @Produces(MediaType.APPLICATION_JSON)
936     public List<DmaapTopicSource> dmaapSources() {
937         return TopicEndpoint.manager.getDmaapTopicSources();
938     }
939     
940         @GET
941     @Path("engine/topics/sinks/dmaap")
942     @Produces(MediaType.APPLICATION_JSON)
943     public List<DmaapTopicSink> dmaapSinks() {
944         return (List<DmaapTopicSink>) TopicEndpoint.manager.getDmaapTopicSinks();
945     }
946     
947     @SuppressWarnings("unchecked")
948     @GET
949     @Path("engine/topics/{topic}/sources")
950     @Produces(MediaType.APPLICATION_JSON)
951     public List<TopicSource> sourceTopic(@PathParam("topic") String topic) {
952         List<String> topics = new ArrayList<String>();
953         topics.add(topic);
954         
955         return (List<TopicSource>) TopicEndpoint.manager.getTopicSources(topics);
956     }
957     
958     @SuppressWarnings("unchecked")
959     @GET
960     @Path("engine/topics/{topic}/sinks")
961     @Produces(MediaType.APPLICATION_JSON)
962     public List<TopicSink> sinkTopic(@PathParam("topic") String topic) {
963         List<String> topics = new ArrayList<String>();
964         topics.add(topic);
965         
966         return (List<TopicSink>) TopicEndpoint.manager.getTopicSinks(topics);
967     }
968     
969     
970     @GET
971     @Path("engine/topics/{topic}/ueb/source")
972     @Produces(MediaType.APPLICATION_JSON)
973     public UebTopicSource uebSourceTopic(@PathParam("topic") String topic) {
974         return TopicEndpoint.manager.getUebTopicSource(topic);
975     }
976     
977     @GET
978     @Path("engine/topics/{topic}/ueb/sink")
979     @Produces(MediaType.APPLICATION_JSON)
980     public UebTopicSink uebSinkTopic(@PathParam("topic") String topic) {
981         return TopicEndpoint.manager.getUebTopicSink(topic);
982     }
983     
984     @GET
985     @Path("engine/topics/{topic}/dmaap/source")
986     @Produces(MediaType.APPLICATION_JSON)
987     public DmaapTopicSource dmaapSourceTopic(@PathParam("topic") String topic) {
988         return TopicEndpoint.manager.getDmaapTopicSource(topic);
989     }
990     
991     @GET
992     @Path("engine/topics/{topic}/dmaap/sink")
993     @Produces(MediaType.APPLICATION_JSON)
994     public DmaapTopicSink dmaapSinkTopic(@PathParam("topic") String topic) {
995         return TopicEndpoint.manager.getDmaapTopicSink(topic);
996     }
997     
998     @GET
999     @Path("engine/topics/{topic}/ueb/source/events")
1000     @Produces(MediaType.APPLICATION_JSON)
1001     public Response uebSourceEvent(@PathParam("topic") String topicName) {
1002         
1003         UebTopicSource uebReader = TopicEndpoint.manager.getUebTopicSource(topicName);
1004         String[] events = uebReader.getRecentEvents();
1005                 return Response.status(Status.OK).
1006                         entity(events).
1007                         build();
1008     }
1009     
1010     @GET
1011     @Path("engine/topics/{topic}/ueb/sink/events")
1012     @Produces(MediaType.APPLICATION_JSON)
1013     public Response uebSinkEvent(@PathParam("topic") String topicName) {
1014         
1015         UebTopicSink uebSink = TopicEndpoint.manager.getUebTopicSink(topicName);
1016         String[] events = uebSink.getRecentEvents();
1017                 return Response.status(Status.OK).
1018                         entity(events).
1019                         build();
1020     }
1021     
1022     @GET
1023     @Path("engine/topics/{topic}/dmaap/source/events")
1024     @Produces(MediaType.APPLICATION_JSON)
1025     public Response dmaapSourcevent(@PathParam("topic") String topicName) {
1026         
1027         DmaapTopicSource uebReader = TopicEndpoint.manager.getDmaapTopicSource(topicName);
1028         String[] events = uebReader.getRecentEvents();
1029                 return Response.status(Status.OK).
1030                         entity(events).
1031                         build();
1032     }
1033     
1034     @GET
1035     @Path("engine/topics/{topic}/dmaap/sink/events")
1036     @Produces(MediaType.APPLICATION_JSON)
1037     public Response dmaapSinkEvent(@PathParam("topic") String topicName) {
1038         
1039         DmaapTopicSink uebSink = TopicEndpoint.manager.getDmaapTopicSink(topicName);
1040         String[] events = uebSink.getRecentEvents();
1041                 return Response.status(Status.OK).
1042                         entity(events).
1043                         build();
1044     }
1045     
1046     @PUT
1047     @Path("engine/topics/{topic}/ueb/sources/events")
1048     @Consumes(MediaType.TEXT_PLAIN)
1049     @Produces(MediaType.APPLICATION_JSON)
1050     public Response uebOffer(@PathParam("topic") String topicName,
1051                                  String json) {
1052         try {
1053                         UebTopicSource uebReader = TopicEndpoint.manager.getUebTopicSource(topicName);
1054                         boolean success = uebReader.offer(json);
1055                         if (success)
1056                                 return Response.status(Status.OK).
1057                                                         entity("Successfully injected event over " + topicName).
1058                                                         build();
1059                         else
1060                                 return Response.status(Status.NOT_ACCEPTABLE).
1061                                                         entity("Failure to inject event over " + topicName).
1062                                                         build();
1063                 } catch (Exception e) {
1064                 return Response.status(Response.Status.BAD_REQUEST).
1065                                 entity(new Error(e.getMessage())).
1066                                 build();
1067                 } 
1068     }
1069     
1070     @PUT
1071     @Path("engine/topics/{topic}/dmaap/sources/events")
1072     @Consumes(MediaType.TEXT_PLAIN)
1073     @Produces(MediaType.APPLICATION_JSON)
1074     public Response dmaapOffer(@PathParam("topic") String topicName,
1075                                    String json) {
1076         try {
1077                         DmaapTopicSource dmaapReader = TopicEndpoint.manager.getDmaapTopicSource(topicName);
1078                         boolean success = dmaapReader.offer(json);
1079                         if (success)
1080                                 return Response.status(Status.OK).
1081                                                         entity("Successfully injected event over " + topicName).
1082                                                         build();
1083                         else
1084                                 return Response.status(Status.NOT_ACCEPTABLE).
1085                                                         entity("Failure to inject event over " + topicName).
1086                                                         build();
1087                 } catch (Exception e) {
1088                 return Response.status(Response.Status.BAD_REQUEST).
1089                                 entity(new Error(e.getMessage())).
1090                                 build();
1091                 } 
1092     }
1093     
1094     @PUT
1095     @Path("engine/topics/lock")
1096     @Produces(MediaType.APPLICATION_JSON)
1097     @Consumes(MediaType.APPLICATION_JSON)
1098     public Response lockTopics() {
1099         boolean success = TopicEndpoint.manager.lock();
1100         if (success)
1101                 return Response.status(Status.OK).
1102                                         entity("Endpoints are locked").
1103                                         build();
1104         else
1105                 return Response.status(Status.SERVICE_UNAVAILABLE).
1106                                         entity("Endpoints cannot be locked").
1107                                         build();
1108     }
1109     
1110     @DELETE
1111     @Path("engine/topics/lock")
1112     @Produces(MediaType.APPLICATION_JSON)
1113     @Consumes(MediaType.APPLICATION_JSON)
1114     public Response unlockTopics() {
1115         boolean success = TopicEndpoint.manager.unlock();
1116         if (success)
1117                 return Response.status(Status.OK).
1118                                         entity("Endpoints are unlocked").
1119                                         build();
1120         else
1121                 return Response.status(Status.SERVICE_UNAVAILABLE).
1122                                         entity("Endpoints cannot be unlocked").
1123                                         build();
1124     }
1125     
1126     @PUT
1127     @Path("engine/topics/{topic}/ueb/sources/lock")
1128     @Produces(MediaType.APPLICATION_JSON)
1129     @Consumes(MediaType.APPLICATION_JSON)
1130     public Response lockTopic(@PathParam("topic") String topicName) {
1131         UebTopicSource reader = TopicEndpoint.manager.getUebTopicSource(topicName);     
1132         boolean success = reader.lock();
1133         if (success)
1134                 return Response.status(Status.OK).
1135                                         entity("Endpoints are unlocked").
1136                                         build();
1137         else
1138                 return Response.status(Status.SERVICE_UNAVAILABLE).
1139                                         entity("Endpoints cannot be unlocked").
1140                                         build();
1141     }
1142     
1143     @PUT
1144     @Path("engine/topics/{topic}/ueb/sources/unlock")
1145     @Produces(MediaType.APPLICATION_JSON)
1146     @Consumes(MediaType.APPLICATION_JSON)
1147     public Response unlockTopic(@PathParam("topic") String topicName) {
1148         UebTopicSource reader = TopicEndpoint.manager.getUebTopicSource(topicName);     
1149         boolean success = reader.unlock();
1150         if (success)
1151                 return Response.status(Status.OK).
1152                                         entity("Endpoints are unlocked").
1153                                         build();
1154         else
1155                 return Response.status(Status.SERVICE_UNAVAILABLE).
1156                                         entity("Endpoints cannot be unlocked").
1157                                         build();
1158     }
1159     
1160     @PUT
1161     @Path("engine/controllers/{controllerName}/lock")
1162     @Produces(MediaType.APPLICATION_JSON)
1163     public Response lockController(@PathParam("controllerName") String controllerName) {
1164         PolicyController policyController = PolicyController.factory.get(controllerName);
1165         boolean success = policyController.lock();
1166         if (success)
1167                 return Response.status(Status.OK).
1168                                         entity("Controller " + controllerName + " is now locked").
1169                                         build();
1170         else
1171                 return Response.status(Status.SERVICE_UNAVAILABLE).
1172                                         entity("Controller " + controllerName + " cannot be locked").
1173                                         build();
1174     }  
1175     
1176     @DELETE
1177     @Path("engine/controllers/{controllerName}/lock")
1178     @Produces(MediaType.APPLICATION_JSON)
1179     public Response unlockController(@PathParam("controllerName") String controllerName) {
1180         PolicyController policyController = PolicyController.factory.get(controllerName);
1181         boolean success = policyController.unlock();
1182         if (success)
1183                 return Response.status(Status.OK).
1184                                         entity("Controller " + controllerName + " is now unlocked").
1185                                         build();
1186         else
1187                 return Response.status(Status.SERVICE_UNAVAILABLE).
1188                                         entity("Controller " + controllerName + " cannot be unlocked").
1189                                         build();
1190     }
1191     
1192     @POST
1193     @Path("engine/util/coders/filters/rules/{ruleName}")
1194     @Produces(MediaType.APPLICATION_JSON)
1195     public Response rules(@DefaultValue("false") @QueryParam("negate") boolean negate,
1196                               @PathParam("ruleName") String name,
1197                               String regex) {           
1198         String literalRegex = Pattern.quote(regex);
1199         if (negate)
1200                 literalRegex = "^(?!" + literalRegex + "$).*";
1201         
1202                 return Response.status(Status.OK).
1203                                         entity(new JsonProtocolFilter.FilterRule(name,literalRegex)).
1204                                         build();
1205     }
1206     
1207     @GET
1208     @Path("engine/util/uuid")
1209     public Response uuid() {    
1210                 return Response.status(Status.OK).
1211                         entity(UUID.randomUUID().toString()).
1212                         build();
1213     }
1214     
1215     
1216     protected DroolsController getDroolsController(String controllerName) throws IllegalArgumentException {
1217                 PolicyController controller = PolicyController.factory.get(controllerName);
1218         if (controller == null)
1219                 throw new IllegalArgumentException(controllerName + "  does not exist");
1220
1221                 DroolsController drools = controller.getDrools();
1222         if (drools == null)
1223                 throw new IllegalArgumentException(controllerName + "  has no drools configuration");
1224         
1225         return drools;
1226     }
1227     
1228     /*
1229      * Helper classes for aggregation of results
1230      */
1231     
1232     
1233         public static class Endpoints {
1234                 public List<TopicSource> sources;
1235                 public List<TopicSink> sinks;
1236                 
1237                 public Endpoints(List<TopicSource> sources,
1238                                          List<TopicSink> sinks) {
1239                         this.sources = sources;
1240                         this.sinks = sinks;
1241                 }
1242         }
1243         
1244         public static class Endpoint {
1245                 public TopicSource source;
1246                 public TopicSink sink;
1247                 
1248                 public Endpoint(TopicSource source,
1249                                            TopicSink sink) {
1250                         this.source = source;
1251                         this.sink = sink;
1252                 }
1253         }
1254         
1255         public static class CodingResult {
1256                 public String jsonEncoding;
1257                 public Boolean encoding;
1258                 public Boolean decoding;
1259         }
1260         
1261         public static class Error {
1262                 public String error;
1263
1264                 /**
1265                  * @param error
1266                  */
1267                 public Error(String error) {
1268                         this.error = error;
1269                 }
1270         }
1271 }
1272