diff options
Diffstat (limited to 'policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java')
-rw-r--r-- | policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java | 481 |
1 files changed, 263 insertions, 218 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java index a5fbfdd3..2d40a1f1 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java +++ b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java @@ -58,15 +58,17 @@ import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.features.PolicyControllerFeatureApi; import org.onap.policy.drools.features.PolicyEngineFeatureApi; -import org.onap.policy.drools.properties.DroolsProperties; -import org.onap.policy.drools.protocol.coders.EventProtocolCoder; +import org.onap.policy.drools.properties.DroolsPropertyConstants; import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters; +import org.onap.policy.drools.protocol.coders.EventProtocolCoderConstants; import org.onap.policy.drools.protocol.coders.JsonProtocolFilter; import org.onap.policy.drools.protocol.coders.ProtocolCoderToolset; import org.onap.policy.drools.protocol.configuration.ControllerConfiguration; import org.onap.policy.drools.protocol.configuration.PdpdConfiguration; import org.onap.policy.drools.system.PolicyController; +import org.onap.policy.drools.system.PolicyControllerConstants; import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.drools.system.PolicyEngineConstants; import org.onap.policy.drools.utils.logging.LoggerUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,10 +86,49 @@ import org.slf4j.LoggerFactory; schemes = {SwaggerDefinition.Scheme.HTTP}, tags = {@Tag(name = "pdp-d-telemetry", description = "Drools PDP Telemetry Operations")}) public class RestManager { + + private static final String CANNOT_PERFORM_OPERATION = "cannot perform operation"; + private static final String NO_FILTERS = " no filters"; + private static final String NOT_FOUND = " not found: "; + private static final String NOT_FOUND_MSG = " not found"; + private static final String DOES_NOT_EXIST_MSG = " does not exist"; + private static final String NOT_ACCEPTABLE_MSG = " not acceptable"; + private static final String FETCH_POLICY_FAILED = "{}: cannot get policy-controller because of {}"; + private static final String FETCH_POLICY_BY_NAME_FAILED = "{}: cannot get policy-controller {} because of {}"; + private static final String FETCH_POLICY_BY_TOPIC_FAILED = + "{}: cannot get policy-controller {} topic {} because of {}"; + private static final String FETCH_DROOLS_FAILED = "{}: cannot get drools-controller {} because of {}"; + private static final String FETCH_DROOLS_BY_ENTITY_FAILED = + "{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}"; + private static final String FETCH_DROOLS_BY_PARAMS_FAILED = + "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}"; + private static final String FETCH_DROOLS_BY_FACTTYPE_FAILED = + "{}: cannot get: drools-controller {}, session {}, factType {}, because of {}"; + private static final String FETCH_DECODERS_BY_POLICY_FAILED = + "{}: cannot get decoders for policy-controller {} because of {}"; + private static final String FETCH_DECODERS_BY_TOPIC_FAILED = + "{}: cannot get decoders for policy-controller {} topic {} because of {}"; + private static final String FETCH_DECODER_BY_TYPE_FAILED = + "{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}"; + private static final String FETCH_DECODER_BY_FILTER_FAILED = + "{}: cannot get decoder filters for policy-controller {} topic {} type {} filters {} because of {}"; + private static final String FETCH_ENCODER_BY_FILTER_FAILED = + "{}: cannot get encoder filters for policy-controller {} because of {}"; + /** * Logger. */ - private static Logger logger = LoggerFactory.getLogger(RestManager.class); + private static final Logger logger = LoggerFactory.getLogger(RestManager.class); + + /** + * Feed Ports into Resources. + */ + private static final List<String> INPUTS = Arrays.asList("configuration"); + + /** + * Resource Toggles. + */ + private static final List<String> SWITCHES = Arrays.asList("activation", "lock"); /** * GET. @@ -99,7 +140,7 @@ public class RestManager { @ApiOperation(value = "Retrieves the Engine Operational Status", notes = "Top-level abstraction. Provides a global view of resources", response = PolicyEngine.class) public Response engine() { - return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build(); + return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager()).build(); } /** @@ -114,13 +155,14 @@ public class RestManager { response = PolicyEngine.class) public Response engineShutdown() { try { - PolicyEngine.manager.shutdown(); + PolicyEngineConstants.getManager().shutdown(); } catch (final IllegalStateException e) { - logger.error("{}: cannot shutdown {} because of {}", this, PolicyEngine.manager, e.getMessage(), e); - return Response.status(Response.Status.BAD_REQUEST).entity(PolicyEngine.manager).build(); + logger.error("{}: cannot shutdown {} because of {}", this, PolicyEngineConstants.getManager(), + e.getMessage(), e); + return Response.status(Response.Status.BAD_REQUEST).entity(PolicyEngineConstants.getManager()).build(); } - return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build(); + return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager()).build(); } /** @@ -133,7 +175,7 @@ public class RestManager { @ApiOperation(value = "Engine Features", notes = "Provides the list of loaded features using the PolicyEngineFeatureAPI", responseContainer = "List") public Response engineFeatures() { - return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatures()).build(); + return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getFeatures()).build(); } @GET @@ -142,7 +184,8 @@ public class RestManager { notes = "Provides detailed list of loaded features using the PolicyEngineFeatureAPI", responseContainer = "List", response = PolicyEngineFeatureApi.class) public Response engineFeaturesInventory() { - return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatureProviders()).build(); + return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getFeatureProviders()) + .build(); } /** @@ -158,8 +201,8 @@ public class RestManager { public Response engineFeature( @ApiParam(value = "Feature Name", required = true) @PathParam("featureName") String featureName) { try { - return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatureProvider(featureName)) - .build(); + return Response.status(Response.Status.OK) + .entity(PolicyEngineConstants.getManager().getFeatureProvider(featureName)).build(); } catch (final IllegalArgumentException iae) { logger.debug("feature unavailable: {}", featureName, iae); return Response.status(Response.Status.NOT_FOUND).entity(new Error(iae.getMessage())).build(); @@ -175,7 +218,7 @@ public class RestManager { @Path("engine/inputs") @ApiOperation(value = "Engine Input Ports", notes = "List of input ports", responseContainer = "List") public Response engineInputs() { - return Response.status(Response.Status.OK).entity(Arrays.asList(Inputs.values())).build(); + return Response.status(Response.Status.OK).entity(INPUTS).build(); } /** @@ -193,14 +236,15 @@ public class RestManager { final PolicyController controller = null; boolean success; try { - success = PolicyEngine.manager.configure(configuration); + success = PolicyEngineConstants.getManager().configure(configuration); } catch (final Exception e) { success = false; - logger.info("{}: cannot configure {} because of {}", this, PolicyEngine.manager, e.getMessage(), e); + logger.info("{}: cannot configure {} because of {}", this, PolicyEngineConstants.getManager(), + e.getMessage(), e); } if (!success) { - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation")) + return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION)) .build(); } else { return Response.status(Response.Status.OK).entity(controller).build(); @@ -217,7 +261,7 @@ public class RestManager { @ApiOperation(value = "Engine Configuration Properties", notes = "Used for booststrapping the engine", response = Properties.class) public Response engineProperties() { - return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getProperties()).build(); + return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getProperties()).build(); } /** @@ -230,7 +274,7 @@ public class RestManager { @ApiOperation(value = "Engine Environment Properties", notes = "Installation and OS environment properties used by the engine", response = Properties.class) public Response engineEnvironment() { - return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getEnvironment()).build(); + return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getEnvironment()).build(); } /** @@ -243,9 +287,10 @@ public class RestManager { @Consumes(MediaType.TEXT_PLAIN) @ApiOperation(value = "Gets an environment variable", response = String.class) public Response engineEnvironment( - @ApiParam(value = "Environment Property", required = true) @PathParam("envProperty") String envProperty) { - return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getEnvironmentProperty(envProperty)) - .build(); + @ApiParam(value = "Environment Property", + required = true) @PathParam("envProperty") String envProperty) { + return Response.status(Response.Status.OK) + .entity(PolicyEngineConstants.getManager().getEnvironmentProperty(envProperty)).build(); } /** @@ -261,7 +306,7 @@ public class RestManager { public Response engineEnvironmentAdd( @ApiParam(value = "Environment Property", required = true) @PathParam("envProperty") String envProperty, @ApiParam(value = "Environment Value", required = true) String envValue) { - final String previousValue = PolicyEngine.manager.setEnvironmentProperty(envProperty, envValue); + final String previousValue = PolicyEngineConstants.getManager().setEnvironmentProperty(envProperty, envValue); return Response.status(Response.Status.OK).entity(previousValue).build(); } @@ -275,7 +320,7 @@ public class RestManager { @ApiOperation(value = "Engine Control Switches", notes = "List of the Engine Control Switches", responseContainer = "List") public Response engineSwitches() { - return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build(); + return Response.status(Response.Status.OK).entity(SWITCHES).build(); } /** @@ -292,17 +337,18 @@ public class RestManager { public Response engineActivation() { boolean success = true; try { - PolicyEngine.manager.activate(); + PolicyEngineConstants.getManager().activate(); } catch (final Exception e) { success = false; - logger.info("{}: cannot activate {} because of {}", this, PolicyEngine.manager, e.getMessage(), e); + logger.info("{}: cannot activate {} because of {}", this, PolicyEngineConstants.getManager(), + e.getMessage(), e); } if (!success) { - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation")) + return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION)) .build(); } else { - return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build(); + return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager()).build(); } } @@ -320,17 +366,18 @@ public class RestManager { public Response engineDeactivation() { boolean success = true; try { - PolicyEngine.manager.deactivate(); + PolicyEngineConstants.getManager().deactivate(); } catch (final Exception e) { success = false; - logger.info("{}: cannot deactivate {} because of {}", this, PolicyEngine.manager, e.getMessage(), e); + logger.info("{}: cannot deactivate {} because of {}", this, PolicyEngineConstants.getManager(), + e.getMessage(), e); } if (!success) { - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation")) + return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION)) .build(); } else { - return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build(); + return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager()).build(); } } @@ -347,11 +394,11 @@ public class RestManager { @ApiResponses(value = {@ApiResponse(code = 406, message = "The system is an administrative state that prevents " + "this request to be fulfilled")}) public Response engineLock() { - final boolean success = PolicyEngine.manager.lock(); + final boolean success = PolicyEngineConstants.getManager().lock(); if (success) { - return Response.status(Status.OK).entity(PolicyEngine.manager).build(); + return Response.status(Status.OK).entity(PolicyEngineConstants.getManager()).build(); } else { - return Response.status(Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation")).build(); + return Response.status(Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION)).build(); } } @@ -368,11 +415,11 @@ public class RestManager { @ApiResponses(value = {@ApiResponse(code = 406, message = "The system is an administrative state that prevents " + "this request to be fulfilled")}) public Response engineUnlock() { - final boolean success = PolicyEngine.manager.unlock(); + final boolean success = PolicyEngineConstants.getManager().unlock(); if (success) { - return Response.status(Status.OK).entity(PolicyEngine.manager).build(); + return Response.status(Status.OK).entity(PolicyEngineConstants.getManager()).build(); } else { - return Response.status(Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation")).build(); + return Response.status(Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION)).build(); } } @@ -386,7 +433,8 @@ public class RestManager { @ApiOperation(value = "Lists the Policy Controllers Names", notes = "Unique Policy Controller Identifiers", responseContainer = "List") public Response controllers() { - return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getPolicyControllerIds()).build(); + return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getPolicyControllerIds()) + .build(); } /** @@ -399,7 +447,8 @@ public class RestManager { @ApiOperation(value = "Lists the Policy Controllers", notes = "Detailed list of Policy Controllers", responseContainer = "List", response = PolicyController.class) public Response controllerInventory() { - return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getPolicyControllers()).build(); + return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getPolicyControllers()) + .build(); } /** @@ -424,17 +473,17 @@ public class RestManager { .build(); } - final String controllerName = config.getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME); + final String controllerName = config.getProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME); if (controllerName == null || controllerName.isEmpty()) { return Response.status(Response.Status.BAD_REQUEST) .entity(new Error( - "Configuration must have an entry for " + DroolsProperties.PROPERTY_CONTROLLER_NAME)) + "Configuration must have an entry for " + DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME)) .build(); } PolicyController controller; try { - controller = PolicyController.factory.get(controllerName); + controller = PolicyControllerConstants.getFactory().get(controllerName); if (controller != null) { return Response.status(Response.Status.NOT_MODIFIED).entity(controller).build(); } @@ -442,14 +491,14 @@ public class RestManager { logger.trace("OK ", e); // This is OK } catch (final IllegalStateException e) { - logger.info("{}: cannot get policy-controller because of {}", this, e.getMessage(), e); - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not found")) + logger.info(FETCH_POLICY_FAILED, this, e.getMessage(), e); + return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + NOT_FOUND_MSG)) .build(); } try { - controller = PolicyEngine.manager - .createPolicyController(config.getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME), config); + controller = PolicyEngineConstants.getManager().createPolicyController( + config.getProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME), config); } catch (IllegalArgumentException | IllegalStateException e) { logger.warn("{}: cannot create policy-controller because of {}", this, e.getMessage(), e); return Response.status(Response.Status.BAD_REQUEST).entity(new Error(e.getMessage())).build(); @@ -480,7 +529,7 @@ public class RestManager { @ApiOperation(value = "Lists of Feature Providers Identifiers", notes = "Unique Policy Controller Identifiers", responseContainer = "List") public Response controllerFeatures() { - return Response.status(Response.Status.OK).entity(PolicyEngine.manager.getFeatures()).build(); + return Response.status(Response.Status.OK).entity(PolicyEngineConstants.getManager().getFeatures()).build(); } /** @@ -494,7 +543,8 @@ public class RestManager { notes = "Provides detailed list of loaded features using the PolicyControllerFeatureAPI", responseContainer = "List", response = PolicyControllerFeatureApi.class) public Response controllerFeaturesInventory() { - return Response.status(Response.Status.OK).entity(PolicyController.factory.getFeatureProviders()).build(); + return Response.status(Response.Status.OK) + .entity(PolicyControllerConstants.getFactory().getFeatureProviders()).build(); } /** @@ -511,8 +561,9 @@ public class RestManager { public Response controllerFeature( @ApiParam(value = "Feature Name", required = true) @PathParam("featureName") String featureName) { try { - return Response.status(Response.Status.OK).entity(PolicyController.factory.getFeatureProvider(featureName)) - .build(); + return Response.status(Response.Status.OK) + .entity(PolicyControllerConstants.getFactory().getFeatureProvider(featureName)) + .build(); } catch (final IllegalArgumentException iae) { logger.debug("{}: cannot feature {} because of {}", this, featureName, iae.getMessage(), iae); return Response.status(Response.Status.NOT_FOUND).entity(new Error(iae.getMessage())).build(); @@ -537,14 +588,15 @@ public class RestManager { public Response controller(@ApiParam(value = "Policy Controller Name", required = true) @PathParam("controller") String controllerName) { try { - return Response.status(Response.Status.OK).entity(PolicyController.factory.get(controllerName)).build(); + return Response.status(Response.Status.OK) + .entity(PolicyControllerConstants.getFactory().get(controllerName)).build(); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); - return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + " not found")).build(); + logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e); + return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable")) - .build(); + logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e); + return Response.status(Response.Status.NOT_ACCEPTABLE) + .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build(); } } @@ -569,23 +621,23 @@ public class RestManager { PolicyController controller; try { - controller = PolicyController.factory.get(controllerName); + controller = PolicyControllerConstants.getFactory().get(controllerName); if (controller == null) { return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + " does not exist")).build(); + .entity(new Error(controllerName + DOES_NOT_EXIST_MSG)).build(); } } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); + logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e); return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + " not found: " + e.getMessage())).build(); + .entity(new Error(controllerName + NOT_FOUND + e.getMessage())).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable")) - .build(); + logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e); + return Response.status(Response.Status.NOT_ACCEPTABLE) + .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build(); } try { - PolicyEngine.manager.removePolicyController(controllerName); + PolicyEngineConstants.getManager().removePolicyController(controllerName); } catch (IllegalArgumentException | IllegalStateException e) { logger.debug("{}: cannot remove policy-controller {} because of {}", this, controllerName, e.getMessage(), e); @@ -611,15 +663,15 @@ public class RestManager { public Response controllerProperties(@ApiParam(value = "Policy Controller Name", required = true) @PathParam("controller") String controllerName) { try { - final PolicyController controller = PolicyController.factory.get(controllerName); + final PolicyController controller = PolicyControllerConstants.getFactory().get(controllerName); return Response.status(Response.Status.OK).entity(controller.getProperties()).build(); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); - return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + " not found")).build(); + logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e); + return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable")) - .build(); + logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e); + return Response.status(Response.Status.NOT_ACCEPTABLE) + .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build(); } } @@ -632,7 +684,7 @@ public class RestManager { @Path("engine/controllers/{controller}/inputs") @ApiOperation(value = "Policy Controller Input Ports", notes = "List of input ports", responseContainer = "List") public Response controllerInputs() { - return Response.status(Response.Status.OK).entity(Arrays.asList(Inputs.values())).build(); + return Response.status(Response.Status.OK).entity(INPUTS).build(); } /** @@ -659,21 +711,21 @@ public class RestManager { PolicyController controller; try { - controller = PolicyEngine.manager.updatePolicyController(controllerConfiguration); + controller = PolicyEngineConstants.getManager().updatePolicyController(controllerConfiguration); if (controller == null) { return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + " does not exist")).build(); + .entity(new Error(controllerName + DOES_NOT_EXIST_MSG)).build(); } } catch (final IllegalArgumentException e) { logger.info("{}: cannot update policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + " not found: " + e.getMessage())).build(); + .entity(new Error(controllerName + NOT_FOUND + e.getMessage())).build(); } catch (final Exception e) { logger.info("{}: cannot update policy-controller {} because of {}", this, controllerName, e.getMessage(), - e); - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable")) - .build(); + e); + return Response.status(Response.Status.NOT_ACCEPTABLE) + .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build(); } return Response.status(Response.Status.OK).entity(controller).build(); @@ -689,7 +741,7 @@ public class RestManager { @ApiOperation(value = "Policy Controller Switches", notes = "List of the Policy Controller Switches", responseContainer = "List") public Response controllerSwitches() { - return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build(); + return Response.status(Response.Status.OK).entity(SWITCHES).build(); } /** @@ -705,7 +757,7 @@ public class RestManager { message = "The system is an administrative state that prevents " + "this request to be fulfilled")}) public Response controllerLock(@ApiParam(value = "Policy Controller Name", required = true) @PathParam("controller") String controllerName) { - final PolicyController policyController = PolicyController.factory.get(controllerName); + final PolicyController policyController = PolicyControllerConstants.getFactory().get(controllerName); final boolean success = policyController.lock(); if (success) { return Response.status(Status.OK).entity(policyController).build(); @@ -728,7 +780,7 @@ public class RestManager { message = "The system is an administrative state that prevents " + "this request to be fulfilled")}) public Response controllerUnlock(@ApiParam(value = "Policy Controller Name", required = true) @PathParam("controller") String controllerName) { - final PolicyController policyController = PolicyController.factory.get(controllerName); + final PolicyController policyController = PolicyControllerConstants.getFactory().get(controllerName); final boolean success = policyController.unlock(); if (success) { return Response.status(Status.OK).entity(policyController).build(); @@ -757,12 +809,12 @@ public class RestManager { final DroolsController drools = this.getDroolsController(controllerName); return Response.status(Response.Status.OK).entity(drools).build(); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e); - return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + " not found")).build(); + logger.debug(FETCH_DROOLS_FAILED, this, controllerName, e.getMessage(), e); + return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e); - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable")) - .build(); + logger.debug(FETCH_DROOLS_FAILED, this, controllerName, e.getMessage(), e); + return Response.status(Response.Status.NOT_ACCEPTABLE) + .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build(); } } @@ -789,12 +841,12 @@ public class RestManager { } return Response.status(Response.Status.OK).entity(sessionCounts).build(); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); - return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + " not found")).build(); + logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e); + return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable")) - .build(); + logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e); + return Response.status(Response.Status.NOT_ACCEPTABLE) + .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build(); } } @@ -818,12 +870,12 @@ public class RestManager { final DroolsController drools = this.getDroolsController(controllerName); return Response.status(Response.Status.OK).entity(drools.factClassNames(sessionName)).build(); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e); + logger.debug(FETCH_DROOLS_FAILED, this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND).entity(new Error("entity not found")).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e); + logger.debug(FETCH_DROOLS_FAILED, this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) - .entity(new Error(controllerName + ":" + sessionName + " not acceptable")).build(); + .entity(new Error(controllerName + ":" + sessionName + NOT_ACCEPTABLE_MSG)).build(); } } @@ -856,13 +908,14 @@ public class RestManager { return Response.status(Response.Status.OK).entity(facts.size()).build(); } } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); + logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) - .entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not found")).build(); + .entity(new Error(controllerName + ":" + sessionName + ":" + factType + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); + logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) - .entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not acceptable")).build(); + .entity(new Error(controllerName + ":" + sessionName + ":" + factType + NOT_ACCEPTABLE_MSG)) + .build(); } } @@ -899,21 +952,21 @@ public class RestManager { return Response.status(Response.Status.OK).entity(facts.size()).build(); } } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}", this, + logger.debug(FETCH_DROOLS_BY_ENTITY_FAILED, this, controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) .entity(new Error( - controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not found")) + controllerName + ":" + sessionName + ":" + queryName + queriedEntity + NOT_FOUND_MSG)) .build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}", this, + logger.debug(FETCH_DROOLS_BY_ENTITY_FAILED, this, controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) .entity(new Error( - controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not acceptable")) + controllerName + ":" + sessionName + ":" + queryName + queriedEntity + NOT_ACCEPTABLE_MSG)) .build(); } catch (final Exception e) { - logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}", this, + logger.debug(FETCH_DROOLS_BY_ENTITY_FAILED, this, controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage())).build(); } @@ -954,23 +1007,23 @@ public class RestManager { return Response.status(Response.Status.OK).entity(facts).build(); } catch (final IllegalArgumentException e) { logger.debug( - "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}", + FETCH_DROOLS_BY_PARAMS_FAILED, this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) .entity(new Error( - controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not found")) + controllerName + ":" + sessionName + ":" + queryName + queriedEntity + NOT_FOUND_MSG)) .build(); } catch (final IllegalStateException e) { logger.debug( - "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}", + FETCH_DROOLS_BY_PARAMS_FAILED, this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) .entity(new Error( - controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not acceptable")) + controllerName + ":" + sessionName + ":" + queryName + queriedEntity + NOT_ACCEPTABLE_MSG)) .build(); } catch (final Exception e) { logger.debug( - "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}", + FETCH_DROOLS_BY_PARAMS_FAILED, this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage())).build(); } @@ -1002,17 +1055,18 @@ public class RestManager { final List<Object> facts = drools.facts(sessionName, factType, true); return Response.status(Response.Status.OK).entity(facts).build(); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", this, + logger.debug(FETCH_DROOLS_BY_FACTTYPE_FAILED, this, controllerName, sessionName, factType, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) - .entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not found")).build(); + .entity(new Error(controllerName + ":" + sessionName + ":" + factType + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", this, - controllerName, sessionName, factType, e.getMessage(), e); + logger.debug(FETCH_DROOLS_BY_FACTTYPE_FAILED, this, + controllerName, sessionName, factType, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) - .entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not acceptable")).build(); + .entity(new Error(controllerName + ":" + sessionName + ":" + factType + NOT_ACCEPTABLE_MSG)) + .build(); } catch (final Exception e) { - logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", this, + logger.debug(FETCH_DROOLS_BY_FACTTYPE_FAILED, this, controllerName, sessionName, factType, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage())).build(); } @@ -1054,23 +1108,23 @@ public class RestManager { return Response.status(Response.Status.OK).entity(facts).build(); } catch (final IllegalArgumentException e) { logger.debug( - "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}", + FETCH_DROOLS_BY_PARAMS_FAILED, this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) .entity(new Error( - controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not found")) + controllerName + ":" + sessionName + ":" + queryName + queriedEntity + NOT_FOUND_MSG)) .build(); } catch (final IllegalStateException e) { logger.debug( - "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}", + FETCH_DROOLS_BY_PARAMS_FAILED, this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) .entity(new Error( - controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not acceptable")) + controllerName + ":" + sessionName + ":" + queryName + queriedEntity + NOT_ACCEPTABLE_MSG)) .build(); } catch (final Exception e) { logger.debug( - "{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}", + FETCH_DROOLS_BY_PARAMS_FAILED, this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage())).build(); } @@ -1111,17 +1165,17 @@ public class RestManager { try { final DroolsController drools = this.getDroolsController(controllerName); final List<ProtocolCoderToolset> decoders = - EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId()); + EventProtocolCoderConstants.getManager().getDecoders(drools.getGroupId(), drools.getArtifactId()); return Response.status(Response.Status.OK).entity(decoders).build(); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, + logger.debug(FETCH_DECODERS_BY_POLICY_FAILED, this, controllerName, e.getMessage(), e); - return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + " not found")).build(); + return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, - e.getMessage(), e); - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable")) - .build(); + logger.debug(FETCH_DECODERS_BY_POLICY_FAILED, this, controllerName, + e.getMessage(), e); + return Response.status(Response.Status.NOT_ACCEPTABLE) + .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build(); } } @@ -1146,18 +1200,18 @@ public class RestManager { required = true) @PathParam("controller") String controllerName) { try { final DroolsController drools = this.getDroolsController(controllerName); - final List<CoderFilters> filters = - EventProtocolCoder.manager.getDecoderFilters(drools.getGroupId(), drools.getArtifactId()); + final List<CoderFilters> filters = EventProtocolCoderConstants.getManager() + .getDecoderFilters(drools.getGroupId(), drools.getArtifactId()); return Response.status(Response.Status.OK).entity(filters).build(); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, + logger.debug(FETCH_DECODERS_BY_POLICY_FAILED, this, controllerName, e.getMessage(), e); - return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + " not found")).build(); + return Response.status(Response.Status.NOT_FOUND).entity(new Error(controllerName + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, - e.getMessage(), e); - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Error(controllerName + " not acceptable")) - .build(); + logger.debug(FETCH_DECODERS_BY_POLICY_FAILED, this, controllerName, + e.getMessage(), e); + return Response.status(Response.Status.NOT_ACCEPTABLE) + .entity(new Error(controllerName + NOT_ACCEPTABLE_MSG)).build(); } } @@ -1182,19 +1236,19 @@ public class RestManager { @ApiParam(value = "Networked Topic Name", required = true) @PathParam("topic") String topic) { try { final DroolsController drools = this.getDroolsController(controllerName); - final ProtocolCoderToolset decoder = - EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); + final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() + .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); return Response.status(Response.Status.OK).entity(decoder).build(); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", this, + logger.debug(FETCH_DECODERS_BY_TOPIC_FAILED, this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) - .entity(new Error(controllerName + ":" + topic + " not found")).build(); + .entity(new Error(controllerName + ":" + topic + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", this, + logger.debug(FETCH_DECODERS_BY_TOPIC_FAILED, this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) - .entity(new Error(controllerName + ":" + topic + " not acceptable")).build(); + .entity(new Error(controllerName + ":" + topic + NOT_ACCEPTABLE_MSG)).build(); } } @@ -1220,24 +1274,24 @@ public class RestManager { @ApiParam(value = "Networked Topic Name", required = true) @PathParam("topic") String topic) { try { final DroolsController drools = this.getDroolsController(controllerName); - final ProtocolCoderToolset decoder = - EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); + final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() + .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); if (decoder == null) { - return Response.status(Response.Status.BAD_REQUEST).entity(new Error(topic + " does not exist")) + return Response.status(Response.Status.BAD_REQUEST).entity(new Error(topic + DOES_NOT_EXIST_MSG)) .build(); } else { return Response.status(Response.Status.OK).entity(decoder.getCoders()).build(); } } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", this, + logger.debug(FETCH_DECODERS_BY_TOPIC_FAILED, this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) - .entity(new Error(controllerName + ":" + topic + " not found")).build(); + .entity(new Error(controllerName + ":" + topic + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", this, + logger.debug(FETCH_DECODERS_BY_TOPIC_FAILED, this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) - .entity(new Error(controllerName + ":" + topic + " not acceptable")).build(); + .entity(new Error(controllerName + ":" + topic + NOT_ACCEPTABLE_MSG)).build(); } } @@ -1264,25 +1318,25 @@ public class RestManager { @ApiParam(value = "Fact Type", required = true) @PathParam("factType") String factClass) { try { final DroolsController drools = this.getDroolsController(controllerName); - final ProtocolCoderToolset decoder = - EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); + final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() + .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); final CoderFilters filters = decoder.getCoder(factClass); if (filters == null) { return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(topic + ":" + factClass + " does not exist")).build(); + .entity(new Error(topic + ":" + factClass + DOES_NOT_EXIST_MSG)).build(); } else { return Response.status(Response.Status.OK).entity(filters).build(); } } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", this, + logger.debug(FETCH_DECODER_BY_TYPE_FAILED, this, controllerName, topic, factClass, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", this, + logger.debug(FETCH_DECODER_BY_TYPE_FAILED, this, controllerName, topic, factClass, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_ACCEPTABLE_MSG)).build(); } } @@ -1318,27 +1372,27 @@ public class RestManager { try { final DroolsController drools = this.getDroolsController(controllerName); - final ProtocolCoderToolset decoder = - EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); + final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() + .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); final CoderFilters filters = decoder.getCoder(factClass); if (filters == null) { return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(topic + ":" + factClass + " does not exist")).build(); + .entity(new Error(topic + ":" + factClass + DOES_NOT_EXIST_MSG)).build(); } filters.setFilter(configFilters); return Response.status(Response.Status.OK).entity(filters).build(); } catch (final IllegalArgumentException e) { logger.debug( - "{}: cannot get decoder filters for policy-controller {} topic {} type {} filters {} because of {}", + FETCH_DECODER_BY_FILTER_FAILED, this, controllerName, topic, factClass, configFilters, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { logger.debug( - "{}: cannot get decoder filters for policy-controller {} topic {} type {} filters {} because of {}", + FETCH_DECODER_BY_FILTER_FAILED, this, controllerName, topic, factClass, configFilters, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_ACCEPTABLE_MSG)).build(); } } @@ -1363,32 +1417,32 @@ public class RestManager { @ApiParam(value = "Fact Type", required = true) @PathParam("factType") String factClass) { try { final DroolsController drools = this.getDroolsController(controllerName); - final ProtocolCoderToolset decoder = - EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); + final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() + .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); final CoderFilters filters = decoder.getCoder(factClass); if (filters == null) { return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " does not exist")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + DOES_NOT_EXIST_MSG)).build(); } final JsonProtocolFilter filter = filters.getFilter(); if (filter == null) { return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " no filters")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + NO_FILTERS)).build(); } return Response.status(Response.Status.OK).entity(filter.getRule()).build(); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", this, + logger.debug(FETCH_DECODER_BY_TYPE_FAILED, this, controllerName, topic, factClass, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", this, + logger.debug(FETCH_DECODER_BY_TYPE_FAILED, this, controllerName, topic, factClass, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_ACCEPTABLE_MSG)).build(); } } @@ -1415,37 +1469,37 @@ public class RestManager { try { final DroolsController drools = this.getDroolsController(controllerName); - final ProtocolCoderToolset decoder = - EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); + final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() + .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); final CoderFilters filters = decoder.getCoder(factClass); if (filters == null) { return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " does not exist")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + DOES_NOT_EXIST_MSG)).build(); } final JsonProtocolFilter filter = filters.getFilter(); if (filter == null) { return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " no filters")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + NO_FILTERS)).build(); } filter.setRule(null); return Response.status(Response.Status.OK).entity(filter.getRule()).build(); } catch (final IllegalArgumentException e) { logger.debug( - "{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", + FETCH_DECODER_BY_TYPE_FAILED, this, controllerName, topic, factClass, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found")) + .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_FOUND_MSG)) .build(); } catch (final IllegalStateException e) { logger.debug( - "{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", + FETCH_DECODER_BY_TYPE_FAILED, this, controllerName, topic, factClass, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) .entity(new Error( - controllerName + ":" + topic + ":" + factClass + " not acceptable")) + controllerName + ":" + topic + ":" + factClass + NOT_ACCEPTABLE_MSG)) .build(); } } @@ -1473,19 +1527,19 @@ public class RestManager { try { final DroolsController drools = this.getDroolsController(controllerName); - final ProtocolCoderToolset decoder = - EventProtocolCoder.manager.getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); + final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() + .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); final CoderFilters filters = decoder.getCoder(factClass); if (filters == null) { return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " does not exist")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + DOES_NOT_EXIST_MSG)).build(); } final JsonProtocolFilter filter = filters.getFilter(); if (filter == null) { return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " no filters")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + NO_FILTERS)).build(); } if (rule == null || rule.isEmpty()) { @@ -1501,14 +1555,14 @@ public class RestManager { + "topic {} type {} because of {}", this, controllerName, topic, factClass, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) - .entity(new Error(controllerName + ":" + topic + " not found")).build(); + .entity(new Error(controllerName + ":" + topic + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { logger.debug( "{}: cannot access decoder filter rules for policy-controller {} " + "topic {} type {} because of {}", this, controllerName, topic, factClass, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + factClass + NOT_ACCEPTABLE_MSG)).build(); } } @@ -1532,17 +1586,17 @@ public class RestManager { PolicyController policyController; try { - policyController = PolicyController.factory.get(controllerName); + policyController = PolicyControllerConstants.getFactory().get(controllerName); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", this, + logger.debug(FETCH_DECODERS_BY_TOPIC_FAILED, this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND) - .entity(new Error(controllerName + ":" + topic + ":" + " not found")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + NOT_FOUND_MSG)).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", this, + logger.debug(FETCH_DECODERS_BY_TOPIC_FAILED, this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) - .entity(new Error(controllerName + ":" + topic + ":" + " not acceptable")).build(); + .entity(new Error(controllerName + ":" + topic + ":" + NOT_ACCEPTABLE_MSG)).build(); } final CodingResult result = new CodingResult(); @@ -1552,17 +1606,17 @@ public class RestManager { Object event; try { - event = EventProtocolCoder.manager.decode(policyController.getDrools().getGroupId(), + event = EventProtocolCoderConstants.getManager().decode(policyController.getDrools().getGroupId(), policyController.getDrools().getArtifactId(), topic, json); result.setDecoding(true); } catch (final Exception e) { - logger.debug("{}: cannot get policy-controller {} topic {} because of {}", this, controllerName, topic, + logger.debug(FETCH_POLICY_BY_TOPIC_FAILED, this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.BAD_REQUEST).entity(new Error(e.getMessage())).build(); } try { - result.setJsonEncoding(EventProtocolCoder.manager.encode(topic, event)); + result.setJsonEncoding(EventProtocolCoderConstants.getManager().encode(topic, event)); result.setEncoding(true); } catch (final Exception e) { // continue so to propagate decoding results .. @@ -1589,16 +1643,17 @@ public class RestManager { required = true) @PathParam("controller") String controllerName) { List<CoderFilters> encoders; try { - final PolicyController controller = PolicyController.factory.get(controllerName); + final PolicyController controller = PolicyControllerConstants.getFactory().get(controllerName); final DroolsController drools = controller.getDrools(); - encoders = EventProtocolCoder.manager.getEncoderFilters(drools.getGroupId(), drools.getArtifactId()); + encoders = EventProtocolCoderConstants.getManager().getEncoderFilters(drools.getGroupId(), + drools.getArtifactId()); } catch (final IllegalArgumentException e) { - logger.debug("{}: cannot get encoder filters for policy-controller {} because of {}", this, controllerName, + logger.debug(FETCH_ENCODER_BY_FILTER_FAILED, this, controllerName, e.getMessage(), e); return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + " not found: " + e.getMessage())).build(); + .entity(new Error(controllerName + NOT_FOUND + e.getMessage())).build(); } catch (final IllegalStateException e) { - logger.debug("{}: cannot get encoder filters for policy-controller {} because of {}", this, controllerName, + logger.debug(FETCH_ENCODER_BY_FILTER_FAILED, this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE) .entity(new Error(controllerName + " is not accepting the request")).build(); @@ -1620,7 +1675,7 @@ public class RestManager { @ApiOperation(value = "Topics Control Switches", notes = "List of the Topic Control Switches", responseContainer = "List") public Response topicSwitches() { - return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build(); + return Response.status(Response.Status.OK).entity(SWITCHES).build(); } /** @@ -1639,7 +1694,7 @@ public class RestManager { if (success) { return Response.status(Status.OK).entity(TopicEndpointManager.getManager()).build(); } else { - return Response.status(Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation")).build(); + return Response.status(Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION)).build(); } } @@ -1659,7 +1714,7 @@ public class RestManager { if (success) { return Response.status(Status.OK).entity(TopicEndpointManager.getManager()).build(); } else { - return Response.status(Status.NOT_ACCEPTABLE).entity(new Error("cannot perform operation")).build(); + return Response.status(Status.NOT_ACCEPTABLE).entity(new Error(CANNOT_PERFORM_OPERATION)).build(); } } @@ -1832,7 +1887,7 @@ public class RestManager { public Response commSourceTopicSwitches( @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm ) { - return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build(); + return Response.status(Response.Status.OK).entity(SWITCHES).build(); } /** @@ -1845,7 +1900,7 @@ public class RestManager { public Response commSinkTopicSwitches( @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm ) { - return Response.status(Response.Status.OK).entity(Arrays.asList(Switches.values())).build(); + return Response.status(Response.Status.OK).entity(SWITCHES).build(); } /** @@ -2028,9 +2083,13 @@ public class RestManager { .build(); } } catch (IllegalArgumentException e) { + logger.debug("{}: cannot offer to topic {} because of {}", this, topic, e.getMessage(), + e); return Response.status(Response.Status.NOT_FOUND) - .entity(new Error(topic + " not found")).build(); + .entity(new Error(topic + NOT_FOUND_MSG)).build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot offer to topic {} because of {}", this, topic, e.getMessage(), + e); return Response.status(Response.Status.NOT_ACCEPTABLE) .entity(new Error(topic + " not acceptable due to current state")) .build(); @@ -2144,14 +2203,14 @@ public class RestManager { * @throws IllegalArgumentException if an invalid controller name has been passed in */ protected DroolsController getDroolsController(String controllerName) { - final PolicyController controller = PolicyController.factory.get(controllerName); + final PolicyController controller = PolicyControllerConstants.getFactory().get(controllerName); if (controller == null) { - throw new IllegalArgumentException(controllerName + " does not exist"); + throw new IllegalArgumentException(controllerName + DOES_NOT_EXIST_MSG); } final DroolsController drools = controller.getDrools(); if (drools == null) { - throw new IllegalArgumentException(controllerName + " has no drools configuration"); + throw new IllegalArgumentException(controllerName + " has no drools configuration"); } return drools; @@ -2229,19 +2288,5 @@ public class RestManager { this.msg = msg; } } - - /** - * Feed Ports into Resources. - */ - public enum Inputs { - configuration, - } - - /** - * Resource Toggles. - */ - public enum Switches { - activation, lock, - } } |