diff options
Diffstat (limited to 'policy-management/src/main')
3 files changed, 32 insertions, 45 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java index 6ddcc364..3bd339a2 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java @@ -34,7 +34,6 @@ import org.kie.api.definition.KiePackage; import org.kie.api.definition.rule.Query; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; -import org.kie.api.runtime.rule.QueryResults; import org.kie.api.runtime.rule.QueryResultsRow; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.gson.annotation.GsonJsonIgnore; @@ -71,7 +70,7 @@ public class MavenDroolsController implements DroolsController { /** * logger. */ - private static Logger logger = LoggerFactory.getLogger(MavenDroolsController.class); + private static final Logger logger = LoggerFactory.getLogger(MavenDroolsController.class); /** * Policy Container, the access object to the policy-core layer. @@ -262,7 +261,7 @@ public class MavenDroolsController implements DroolsController { for (TopicCoderFilterConfiguration coderConfig: coderConfigurations) { String topic = coderConfig.getTopic(); - CustomGsonCoder customGsonCoder = getCustomCoder(coderConfig); + var customGsonCoder = getCustomCoder(coderConfig); List<PotentialCoderFilter> coderFilters = coderConfig.getCoderFilters(); if (coderFilters == null || coderFilters.isEmpty()) { @@ -301,7 +300,7 @@ public class MavenDroolsController implements DroolsController { } private CustomGsonCoder getCustomCoder(TopicCoderFilterConfiguration coderConfig) { - CustomGsonCoder customGsonCoder = coderConfig.getCustomGsonCoder(); + var customGsonCoder = coderConfig.getCustomGsonCoder(); if (customGsonCoder != null && customGsonCoder.getClassContainer() != null && !customGsonCoder.getClassContainer().isEmpty()) { @@ -745,8 +744,8 @@ public class MavenDroolsController implements DroolsController { Map<String, Integer> classNames = new HashMap<>(); - PolicySession session = getSession(sessionName); - KieSession kieSession = session.getKieSession(); + var session = getSession(sessionName); + var kieSession = session.getKieSession(); Collection<FactHandle> facts = kieSession.getFactHandles(); for (FactHandle fact : facts) { @@ -775,8 +774,7 @@ public class MavenDroolsController implements DroolsController { public long factCount(String sessionName) { validateSessionName(sessionName); - PolicySession session = getSession(sessionName); - return session.getKieSession().getFactCount(); + return getSession(sessionName).getKieSession().getFactCount(); } @Override @@ -793,8 +791,8 @@ public class MavenDroolsController implements DroolsController { throw new IllegalArgumentException("Class cannot be fetched in model's classloader: " + className); } - PolicySession session = getSession(sessionName); - KieSession kieSession = session.getKieSession(); + var session = getSession(sessionName); + var kieSession = session.getKieSession(); List<Object> factObjects = new ArrayList<>(); @@ -835,14 +833,14 @@ public class MavenDroolsController implements DroolsController { throw new IllegalArgumentException("Invalid Queried Entity: " + queriedEntity); } - PolicySession session = getSession(sessionName); - KieSession kieSession = session.getKieSession(); + var session = getSession(sessionName); + var kieSession = session.getKieSession(); validateQueryName(kieSession, queryName); List<Object> factObjects = new ArrayList<>(); - QueryResults queryResults = kieSession.getQueryResults(queryName, queryParams); + var queryResults = kieSession.getQueryResults(queryName, queryParams); for (QueryResultsRow row : queryResults) { try { factObjects.add(row.get(queriedEntity)); @@ -871,11 +869,11 @@ public class MavenDroolsController implements DroolsController { @Override public <T> boolean delete(@NonNull String sessionName, @NonNull T objFact) { - KieSession kieSession = getSession(sessionName).getKieSession(); + var kieSession = getSession(sessionName).getKieSession(); // try first to get the object to delete first by reference - FactHandle quickFact = kieSession.getFactHandle(objFact); + var quickFact = kieSession.getFactHandle(objFact); if (quickFact != null) { logger.info("Fast delete of {} from {}", objFact, sessionName); kieSession.delete(quickFact); @@ -906,10 +904,10 @@ public class MavenDroolsController implements DroolsController { @Override public <T> boolean delete(@NonNull String sessionName, @NonNull Class<T> fact) { - PolicySession session = getSession(sessionName); - KieSession kieSession = session.getKieSession(); + var session = getSession(sessionName); + var kieSession = session.getKieSession(); - boolean success = true; + var success = true; Collection<FactHandle> factHandles = kieSession.getFactHandles(new ClassObjectFilter(fact)); for (FactHandle factHandle : factHandles) { try { @@ -929,7 +927,7 @@ public class MavenDroolsController implements DroolsController { @Override public <T> boolean exists(@NonNull String sessionName, @NonNull T objFact) { - KieSession kieSession = getSession(sessionName).getKieSession(); + var kieSession = getSession(sessionName).getKieSession(); if (kieSession.getFactHandle(objFact) != null) { return true; } @@ -965,7 +963,7 @@ public class MavenDroolsController implements DroolsController { @Override public Object[] getRecentSourceEvents() { synchronized (this.recentSourceEvents) { - Object[] events = new Object[recentSourceEvents.size()]; + var events = new Object[recentSourceEvents.size()]; return recentSourceEvents.toArray(events); } } @@ -978,7 +976,7 @@ public class MavenDroolsController implements DroolsController { @Override public String[] getRecentSinkEvents() { synchronized (this.recentSinkEvents) { - String[] events = new String[recentSinkEvents.size()]; + var events = new String[recentSinkEvents.size()]; return recentSinkEvents.toArray(events); } } @@ -991,18 +989,8 @@ public class MavenDroolsController implements DroolsController { @Override public String toString() { - StringBuilder builder = new StringBuilder(); - builder - .append("MavenDroolsController [policyContainer=") - .append(policyContainer.getName()) - .append(":") - .append(", alive=") - .append(alive) - .append(", locked=") - .append(", modelClassLoaderHash=") - .append(modelClassLoaderHash) - .append("]"); - return builder.toString(); + return "MavenDroolsController [policyContainer=" + policyContainer.getName() + ":" + ", alive=" + alive + + ", locked=" + ", modelClassLoaderHash=" + modelClassLoaderHash + "]"; } // these may be overridden by junit tests diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java index 84247efe..56e3f3f2 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java @@ -76,7 +76,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { /* A PolicyController does not exist */ - PolicyController controller = newPolicyController(name, properties); + var controller = newPolicyController(name, properties); String coordinates = toKey(controller.getDrools().getGroupId(), controller.getDrools().getArtifactId()); diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java index 25601c8b..ec24286a 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java @@ -56,7 +56,6 @@ import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.onap.policy.common.gson.annotation.GsonJsonIgnore; import org.onap.policy.common.gson.annotation.GsonJsonProperty; import org.onap.policy.common.utils.services.FeatureApiUtils; -import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.controller.DroolsControllerConstants; import org.onap.policy.drools.core.PolicyContainer; import org.onap.policy.drools.core.jmx.PdpJmxListener; @@ -227,7 +226,7 @@ class PolicyEngineManager implements PolicyEngine { @Override public final Properties defaultTelemetryConfig() { - final Properties defaultConfig = new Properties(); + final var defaultConfig = new Properties(); defaultConfig.put(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES, "TELEMETRY"); defaultConfig.put(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + TELEMETRY_SERVER_DEFAULT_NAME @@ -379,7 +378,7 @@ class PolicyEngineManager implements PolicyEngine { final String entity = config.getEntity(); - MdcTransaction mdcTrans = MdcTransaction.newTransaction(config.getRequestId(), "brmsgw"); + var mdcTrans = MdcTransaction.newTransaction(config.getRequestId(), "brmsgw"); if (this.getSources().size() == 1) { Topic topic = this.getSources().get(0); mdcTrans.setServiceName(topic.getTopic()).setRemoteHost(topic.getServers().toString()) @@ -459,7 +458,7 @@ class PolicyEngineManager implements PolicyEngine { .setTargetServiceName(configController.getOperation()) .setTargetVirtualEntity("" + configController.getDrools()); try { - final PolicyController policyController = this.updatePolicyController(configController); + var policyController = this.updatePolicyController(configController); policyControllers.add(policyController); mdcTrans.setStatusCode(true).transaction(); } catch (final Exception e) { @@ -493,7 +492,7 @@ class PolicyEngineManager implements PolicyEngine { throw new IllegalArgumentException("operation must be provided"); } - PolicyController policyController = getController(controllerName); + var policyController = getController(controllerName); if (policyController == null) { policyController = findController(controllerName, operation); @@ -533,7 +532,7 @@ class PolicyEngineManager implements PolicyEngine { logger.warn("controller {} does not exist. Attempting recovery from disk", controllerName); - final Properties controllerProperties = + var controllerProperties = getPersistenceManager().getControllerProperties(controllerName); /* @@ -795,7 +794,7 @@ class PolicyEngineManager implements PolicyEngine { * ..) are stuck */ - Thread exitThread = makeShutdownThread(); + var exitThread = makeShutdownThread(); exitThread.start(); /* policy-engine dispatch pre shutdown hook */ @@ -940,7 +939,7 @@ class PolicyEngineManager implements PolicyEngine { this.locked = true; - boolean success = true; + var success = true; final List<PolicyController> controllers = getControllerFactory().inventory(); for (final PolicyController controller : controllers) { try { @@ -1201,7 +1200,7 @@ class PolicyEngineManager implements PolicyEngine { * additional processing */ try { - final DroolsController droolsController = getProtocolCoder().getDroolsController(topic, event); + var droolsController = getProtocolCoder().getDroolsController(topic, event); final PolicyController controller = getControllerFactory().get(droolsController); if (controller != null) { return controller.deliver(busType, topic, event); @@ -1246,7 +1245,7 @@ class PolicyEngineManager implements PolicyEngine { } try { - final TopicSink sink = getTopicEndpointManager().getTopicSink(busType, topic); + var sink = getTopicEndpointManager().getTopicSink(busType, topic); if (sink == null) { throw new IllegalStateException("Inconsistent State: " + this); @@ -1411,7 +1410,7 @@ class PolicyEngineManager implements PolicyEngine { } protected ScheduledExecutorService makeScheduledExecutor(int nthreads) { - ScheduledThreadPoolExecutor exsvc = new ScheduledThreadPoolExecutor(nthreads); + var exsvc = new ScheduledThreadPoolExecutor(nthreads); exsvc.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); exsvc.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); exsvc.setRemoveOnCancelPolicy(true); |