diff options
author | jhh <jorge.hernandez-herrero@att.com> | 2021-05-10 17:13:57 -0500 |
---|---|---|
committer | jhh <jorge.hernandez-herrero@att.com> | 2021-05-10 17:13:57 -0500 |
commit | 61b27e147b5d8d816488b3a5a5dc1d57a1539186 (patch) | |
tree | 8c3269d5423f6b827526018f4d0a90467701bc67 | |
parent | 534201ccd5b6d3bbb115c7021b881594efef405e (diff) |
interrupted exception and var usage sonars
Issue-ID: POLICY-3230
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Change-Id: I50a4ee81f0a1c97df25732a4e4507e8b7f8c8e4d
3 files changed, 66 insertions, 50 deletions
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java index 680abf3f..09dd275e 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * feature-state-management + * ONAP * ================================================================================ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -47,7 +47,7 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor { private static DroolsPdpIntegrityMonitor im = null; // list of audits to run - private static AuditBase[] audits = new AuditBase[] {DbAudit.getInstance(), RepositoryAudit.getInstance()}; + private static final AuditBase[] audits = new AuditBase[] {DbAudit.getInstance(), RepositoryAudit.getInstance()}; private static Properties subsystemTestProperties = null; @@ -57,8 +57,7 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor { * Constructor - pass arguments to superclass, but remember properties. * * @param resourceName unique name of this Integrity Monitor - * @param url the JMX URL of the MBean server - * @param properties properties used locally, as well as by 'IntegrityMonitor' + * @param consolidatedProperties properties used locally, as well as by 'IntegrityMonitor' * @throws IntegrityMonitorException (passed from superclass) */ private DroolsPdpIntegrityMonitor(String resourceName, Properties consolidatedProperties) @@ -87,7 +86,7 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor { logger.info("init: Entering and invoking PropertyUtil.getProperties() on '{}'", configDir); // read in properties - Properties stateManagementProperties = getProperties(configDir); + var stateManagementProperties = getProperties(configDir); // fetch and verify definitions of some properties, adding defaults where // appropriate @@ -241,7 +240,7 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor { * * @param props set of properties * @param name name of the property to check - * @param expected expected/default value + * @param dflt expected/default value */ private static void addDefaultPropWarn(Properties props, String name, String dflt) { String val = props.getProperty(name); @@ -282,7 +281,7 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor { } // will contain list of subsystems where the audit failed - String responseMsg = ""; + var responseMsg = ""; // Loop through all of the audits, and see which ones have failed. // NOTE: response information is stored within the audit objects @@ -354,7 +353,7 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor { * Abstract method to invoke the audit. * * @param persistenceProperties Used for DB access - * @throws Exception passed in by the audit + * @throws IntegrityMonitorException passed in by the audit */ abstract void invoke(Properties persistenceProperties) throws IntegrityMonitorException; } @@ -392,6 +391,7 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor { server.waitedStart(5); } catch (Exception e) { logger.error("Exception waiting for servers to start: ", e); + Thread.currentThread().interrupt(); } } diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java index 389d5b37..fb17b10a 100644 --- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java +++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java @@ -1,8 +1,8 @@ /* * ============LICENSE_START======================================================= - * policy-core + * ONAP * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -469,8 +469,9 @@ public class PolicySession // one more interrupt, just in case the 'kieSession.halt()' // didn't work for some reason thread.interrupt(); - } catch (Exception e) { + } catch (InterruptedException e) { logger.error("stopThread in thread.join error", e); + Thread.currentThread().interrupt(); } } @@ -497,7 +498,7 @@ public class PolicySession // We want to continue looping, despite any exceptions that occur // while rules are fired. - KieSession kieSession1 = session.getKieSession(); + var kieSession1 = session.getKieSession(); while (repeat) { try { kieSession1.fireUntilHalt(); 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 db280a1f..e704f0b0 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ package org.onap.policy.drools.server.restful; import ch.qos.logback.classic.LoggerContext; +import com.google.re2j.Pattern; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -340,7 +341,7 @@ public class RestManager { + "and controllers are unlocked and started", response = PolicyEngine.class) public Response engineActivation() { - boolean success = true; + var success = true; try { PolicyEngineConstants.getManager().activate(); } catch (final Exception e) { @@ -369,7 +370,7 @@ public class RestManager { + "and controllers are locked (with the exception of those resources defined as unmanaged)", response = PolicyEngine.class) public Response engineDeactivation() { - boolean success = true; + var success = true; try { PolicyEngineConstants.getManager().deactivate(); } catch (final Exception e) { @@ -710,7 +711,7 @@ public class RestManager { } return catchArgStateGenericEx(() -> { - PolicyController controller = + var controller = PolicyEngineConstants.getManager().updatePolicyController(controllerConfiguration); if (controller == null) { return Response.status(Response.Status.BAD_REQUEST) @@ -752,7 +753,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 = PolicyControllerConstants.getFactory().get(controllerName); + var policyController = PolicyControllerConstants.getFactory().get(controllerName); final boolean success = policyController.lock(); if (success) { return Response.status(Status.OK).entity(policyController).build(); @@ -775,7 +776,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 = PolicyControllerConstants.getFactory().get(controllerName); + var policyController = PolicyControllerConstants.getFactory().get(controllerName); final boolean success = policyController.unlock(); if (success) { return Response.status(Status.OK).entity(policyController).build(); @@ -802,7 +803,7 @@ public class RestManager { required = true) @PathParam("controller") String controllerName) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); return Response.status(Response.Status.OK).entity(drools).build(); }, e -> { @@ -829,7 +830,7 @@ public class RestManager { return catchArgStateGenericEx(() -> { final Map<String, Long> sessionCounts = new HashMap<>(); - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); for (final String session : drools.getSessionNames()) { sessionCounts.put(session, drools.factCount(session)); } @@ -859,7 +860,7 @@ public class RestManager { @ApiParam(value = "Drools Session Name", required = true) @PathParam("session") String sessionName) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); return drools.factClassNames(sessionName); }, e -> { @@ -890,7 +891,7 @@ public class RestManager { @ApiParam(value = "Drools Fact Type", required = true) @PathParam("factType") String factType) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); final List<Object> facts = drools.facts(sessionName, factType, false); return (count ? facts.size() : facts); @@ -926,7 +927,7 @@ public class RestManager { required = true) @PathParam("queriedEntity") String queriedEntity) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); final List<Object> facts = drools.factQuery(sessionName, queryName, queriedEntity, false); return (count ? facts.size() : facts); @@ -963,7 +964,7 @@ public class RestManager { required = false) List<Object> queryParameters) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); if (queryParameters == null || queryParameters.isEmpty()) { return drools.factQuery(sessionName, queryName, queriedEntity, false); } else { @@ -1000,7 +1001,7 @@ public class RestManager { @ApiParam(value = "Drools Fact Type", required = true) @PathParam("factType") String factType) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); return drools.facts(sessionName, factType, true); }, e -> { @@ -1037,7 +1038,7 @@ public class RestManager { required = false) List<Object> queryParameters) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); if (queryParameters == null || queryParameters.isEmpty()) { return drools.factQuery(sessionName, queryName, queriedEntity, true); } else { @@ -1085,7 +1086,7 @@ public class RestManager { required = true) @PathParam("controller") String controllerName) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); return EventProtocolCoderConstants.getManager().getDecoders(drools.getGroupId(), drools.getArtifactId()); }, e -> { @@ -1116,7 +1117,7 @@ public class RestManager { required = true) @PathParam("controller") String controllerName) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); return EventProtocolCoderConstants.getManager() .getDecoderFilters(drools.getGroupId(), drools.getArtifactId()); @@ -1147,7 +1148,7 @@ public class RestManager { @ApiParam(value = "Networked Topic Name", required = true) @PathParam("topic") String topic) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); return EventProtocolCoderConstants.getManager() .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); @@ -1179,7 +1180,7 @@ public class RestManager { @ApiParam(value = "Networked Topic Name", required = true) @PathParam("topic") String topic) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); if (decoder == null) { @@ -1218,7 +1219,7 @@ public class RestManager { @ApiParam(value = "Fact Type", required = true) @PathParam("factType") String factClass) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); final CoderFilters filters = decoder.getCoder(factClass); @@ -1267,7 +1268,7 @@ public class RestManager { } return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); final CoderFilters filters = decoder.getCoder(factClass); @@ -1306,7 +1307,7 @@ public class RestManager { @ApiParam(value = "Fact Type", required = true) @PathParam("factType") String factClass) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); @@ -1353,7 +1354,7 @@ public class RestManager { @ApiParam(value = "Fact Type", required = true) @PathParam("factType") String factClass) { return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); @@ -1409,7 +1410,7 @@ public class RestManager { } private Object decoderFilterRule2(String controllerName, String topic, String factClass, String rule) { - final DroolsController drools = this.getDroolsController(controllerName); + var drools = this.getDroolsController(controllerName); final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); @@ -1452,6 +1453,16 @@ public class RestManager { @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic, @ApiParam(value = "JSON String to decode", required = true) String json) { + if (!checkValidNameInput(controllerName)) { + return Response.status(Response.Status.NOT_ACCEPTABLE) + .entity(new Error("controllerName contains whitespaces " + NOT_ACCEPTABLE_MSG)).build(); + } + + if (!checkValidNameInput(topic)) { + return Response.status(Response.Status.NOT_ACCEPTABLE) + .entity(new Error("topic contains whitespaces " + NOT_ACCEPTABLE_MSG)).build(); + } + PolicyController policyController; try { policyController = PolicyControllerConstants.getFactory().get(controllerName); @@ -1467,7 +1478,7 @@ public class RestManager { .entity(new Error(controllerName + ":" + topic + ":" + NOT_ACCEPTABLE_MSG)).build(); } - final CodingResult result = new CodingResult(); + var result = new CodingResult(); result.setDecoding(false); result.setEncoding(false); result.setJsonEncoding(null); @@ -1512,7 +1523,7 @@ public class RestManager { return catchArgStateGenericEx(() -> { final PolicyController controller = PolicyControllerConstants.getFactory().get(controllerName); - final DroolsController drools = controller.getDrools(); + var drools = controller.getDrools(); return EventProtocolCoderConstants.getManager() .getEncoderFilters(drools.getGroupId(), drools.getArtifactId()); @@ -1616,7 +1627,7 @@ public class RestManager { @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm ) { List<TopicSource> sources = new ArrayList<>(); - Status status = Status.OK; + var status = Status.OK; switch (CommInfrastructure.valueOf(comm.toUpperCase())) { case UEB: sources.addAll(TopicEndpointManager.getManager().getUebTopicSources()); @@ -1646,7 +1657,7 @@ public class RestManager { @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm ) { List<TopicSink> sinks = new ArrayList<>(); - Status status = Status.OK; + var status = Status.OK; switch (CommInfrastructure.valueOf(comm.toUpperCase())) { case UEB: sinks.addAll(TopicEndpointManager.getManager().getUebTopicSinks()); @@ -1776,7 +1787,7 @@ public class RestManager { @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm, @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic ) { - TopicSource source = + var source = TopicEndpointManager.getManager().getTopicSource(CommInfrastructure.valueOf(comm.toUpperCase()), topic); return getResponse(topic, source.lock(), source); } @@ -1793,7 +1804,7 @@ public class RestManager { @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm, @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic ) { - TopicSource source = + var source = TopicEndpointManager.getManager().getTopicSource(CommInfrastructure.valueOf(comm.toUpperCase()), topic); return getResponse(topic, source.unlock(), source); } @@ -1810,7 +1821,7 @@ public class RestManager { @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm, @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic ) { - TopicSource source = + var source = TopicEndpointManager.getManager().getTopicSource(CommInfrastructure.valueOf(comm.toUpperCase()), topic); return getResponse(topic, source.start(), source); } @@ -1827,7 +1838,7 @@ public class RestManager { @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm, @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic ) { - TopicSource source = + var source = TopicEndpointManager.getManager().getTopicSource(CommInfrastructure.valueOf(comm.toUpperCase()), topic); return getResponse(topic, source.stop(), source); } @@ -1844,7 +1855,7 @@ public class RestManager { @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm, @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic ) { - TopicSink sink = + var sink = TopicEndpointManager.getManager().getTopicSink(CommInfrastructure.valueOf(comm.toUpperCase()), topic); return getResponse(topic, sink.lock(), sink); } @@ -1861,7 +1872,7 @@ public class RestManager { @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm, @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic ) { - TopicSink sink = + var sink = TopicEndpointManager.getManager().getTopicSink(CommInfrastructure.valueOf(comm.toUpperCase()), topic); return getResponse(topic, sink.unlock(), sink); } @@ -1878,7 +1889,7 @@ public class RestManager { @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm, @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic ) { - TopicSink sink = + var sink = TopicEndpointManager.getManager().getTopicSink(CommInfrastructure.valueOf(comm.toUpperCase()), topic); return getResponse(topic, sink.start(), sink); } @@ -1895,7 +1906,7 @@ public class RestManager { @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm, @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic ) { - TopicSink sink = + var sink = TopicEndpointManager.getManager().getTopicSink(CommInfrastructure.valueOf(comm.toUpperCase()), topic); return getResponse(topic, sink.stop(), sink); } @@ -1932,7 +1943,7 @@ public class RestManager { @ApiParam(value = "Network Message", required = true) String json) { return catchArgStateGenericEx(() -> { - TopicSource source = TopicEndpointManager.getManager() + var source = TopicEndpointManager.getManager() .getTopicSource(CommInfrastructure.valueOf(comm.toUpperCase()), topic); if (source.offer(json)) { return Arrays.asList(source.getRecentEvents()); @@ -2003,7 +2014,7 @@ public class RestManager { } final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); - final ch.qos.logback.classic.Logger lgr = context.getLogger(loggerName); + var lgr = context.getLogger(loggerName); if (lgr == null) { return Response.status(Status.NOT_FOUND).build(); } @@ -2056,7 +2067,7 @@ public class RestManager { throw new IllegalArgumentException(controllerName + DOES_NOT_EXIST_MSG); } - final DroolsController drools = controller.getDrools(); + var drools = controller.getDrools(); if (drools == null) { throw new IllegalArgumentException(controllerName + " has no drools configuration"); } @@ -2098,6 +2109,10 @@ public class RestManager { } } + public static boolean checkValidNameInput(String test) { + return Pattern.matches("\\S+", test); + } + /* * Helper classes for aggregation of results */ |