summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java25
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java6
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java24
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java32
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PMStandbyStateChangeNotifier.java12
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java5
-rw-r--r--feature-active-standby-management/src/test/java/org/onap/policy/drools/controller/test/AllSeemsWellTest.java11
-rw-r--r--feature-active-standby-management/src/test/java/org/onap/policy/drools/controller/test/StandbyStateManagementTest.java45
-rw-r--r--feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java19
-rw-r--r--feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java22
-rw-r--r--feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java10
-rw-r--r--feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java10
-rw-r--r--feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java140
-rw-r--r--feature-simulators/src/main/java/org/onap/policy/drools/simulators/DMaaPSimulatorJaxRs.java14
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java5
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java10
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/properties/Startable.java10
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java56
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicSink.java6
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java21
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java66
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java14
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java16
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java43
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java33
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java34
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java32
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java28
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java58
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java23
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureAPI.java17
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java19
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java14
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java16
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java216
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java66
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java92
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java14
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java8
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java8
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java14
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java56
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/Main.java2
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java22
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java76
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java95
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java21
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java18
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedServiceImpl.java40
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/utils/TripleTest.java4
50 files changed, 792 insertions, 856 deletions
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java
index d2c542fb..932ebb2d 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -80,7 +80,7 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureAPI,
* {@inheritDoc}
*/
@Override
- public void globalInit(String args[], String configDir)
+ public void globalInit(String[] args, String configDir)
{
// This must come first since it initializes myPdp
initializePersistence(configDir);
@@ -164,7 +164,7 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureAPI,
*/
DroolsPdp existingPdp = conn.getPdp(resourceName);
if (existingPdp != null) {
- System.out.println("Found existing PDP record, pdpId="
+ logger.info("Found existing PDP record, pdpId="
+ existingPdp.getPdpId() + ", isDesignated="
+ existingPdp.isDesignated() + ", updatedDate="
+ existingPdp.getUpdatedDate());
@@ -176,18 +176,17 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureAPI,
myPdp = new DroolsPdpImpl(resourceName,false,4,new Date());
}
- String site_name = ActiveStandbyProperties.getProperty(ActiveStandbyProperties.SITE_NAME);
- if (site_name == null) {
- site_name = "";
+ String siteName = ActiveStandbyProperties.getProperty(ActiveStandbyProperties.SITE_NAME);
+ if (siteName == null) {
+ siteName = "";
}else{
- site_name = site_name.trim();
+ siteName = siteName.trim();
}
- myPdp.setSiteName(site_name);
+ myPdp.setSiteName(siteName);
if(electionHandler == null){
electionHandler = new DroolsPdpsElectionHandler(conn,myPdp);
}
}
- System.out.println("\n\nThis controller is a standby, waiting to be chosen as primary...\n\n");
logger.info("\n\nThis controller is a standby, waiting to be chosen as primary...\n\n");
}
@@ -199,7 +198,7 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureAPI,
*/
public static DroolsPdpsConnector getDroolsPdpsConnector(String pu) {
- Map<String, Object> propMap = new HashMap<String, Object>();
+ Map<String, Object> propMap = new HashMap<>();
propMap.put("javax.persistence.jdbc.driver", ActiveStandbyProperties
.getProperty(ActiveStandbyProperties.DB_DRIVER));
propMap.put("javax.persistence.jdbc.url",
@@ -211,9 +210,7 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureAPI,
EntityManagerFactory emf = Persistence.createEntityManagerFactory(
pu, propMap);
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emf);
-
- return conn;
+ return new JpaDroolsPdpsConnector(emf);
}
/**
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java
index 8c1d9f2e..690b260c 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -65,7 +65,7 @@ public abstract class DroolsPdpObject implements DroolsPdp{
}
@Override
public int comparePriority(DroolsPdp other, String previousSite){
- if(previousSite == null || previousSite.equals("")){
+ if(previousSite == null || previousSite.isEmpty()){
return comparePriority(other);
}
if(nullSafeCompare(this.getSiteName(),other.getSiteName()) == 0){
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
index 2836f92f..1a09d920 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -23,6 +23,7 @@ package org.onap.policy.drools.activestandby;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
@@ -33,7 +34,7 @@ import org.onap.policy.drools.statemanagement.StateManagementFeatureAPI;
public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
// get an instance of logger
- private final static Logger logger = LoggerFactory.getLogger(DroolsPdpsElectionHandler.class);
+ private static final Logger logger = LoggerFactory.getLogger(DroolsPdpsElectionHandler.class);
private DroolsPdpsConnector pdpsConnector;
private Object checkWaitTimerLock = new Object();
private Object designationWaiterLock = new Object();
@@ -70,13 +71,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
private StateManagementFeatureAPI stateManagementFeature;
private static boolean isUnitTesting = false;
- public static void setIsUnitTesting(boolean val){
- isUnitTesting = val;
- }
private static boolean isStalled = false;
- public static void setIsStalled(boolean val){
- isStalled = val;
- }
public DroolsPdpsElectionHandler(DroolsPdpsConnector pdps, DroolsPdp myPdp){
if (pdps == null) {
@@ -152,6 +147,13 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
}
}
+ public static void setIsUnitTesting(boolean val){
+ isUnitTesting = val;
+ }
+ public static void setIsStalled(boolean val){
+ isStalled = val;
+ }
+
/*
* When the JpaDroolsPdpsConnector.standDown() method is invoked, it needs
* access to myPdp, so it can keep its designation status in sync with the
@@ -194,7 +196,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
//It is possible that multiple PDPs are designated lead. So, we will make a list of all designated
//PDPs and then decide which one really should be designated at the end.
- ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
+ ArrayList<DroolsPdp> listOfDesignated = new ArrayList<>();
Collection<DroolsPdp> pdps = pdpsConnector.getDroolsPdps();
DroolsPdp designatedPdp = null;
@@ -767,7 +769,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
return mostRecentPrimary;
}
- public DroolsPdp computeDesignatedPdp(ArrayList<DroolsPdp> listOfDesignated, DroolsPdp mostRecentPrimary){
+ public DroolsPdp computeDesignatedPdp(List<DroolsPdp> listOfDesignated, DroolsPdp mostRecentPrimary){
DroolsPdp designatedPdp = null;
DroolsPdp lowestPriorityPdp = null;
if(listOfDesignated.size() > 1){
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java
index 0d931acc..dc907b27 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -53,7 +53,7 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
em.getTransaction().begin();
Query droolsPdpsListQuery = em.createQuery("SELECT p FROM DroolsPdpEntity p");
List<?> droolsPdpsList = droolsPdpsListQuery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
- LinkedList<DroolsPdp> droolsPdpsReturnList = new LinkedList<DroolsPdp>();
+ LinkedList<DroolsPdp> droolsPdpsReturnList = new LinkedList<>();
for(Object o : droolsPdpsList){
if(o instanceof DroolsPdp){
//Make sure it is not a cached version
@@ -613,24 +613,22 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
*/
private static void cleanup(EntityManager em, String method)
{
- if (em != null) {
- if (em.isOpen()) {
- if (em.getTransaction().isActive()) {
- // there is an active EntityTransaction -- roll it back
- try {
- em.getTransaction().rollback();
- } catch (Exception e) {
- logger.error(method + ": Caught Exception attempting to rollback EntityTransaction,", e);
- }
- }
-
- // now, close the EntityManager
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ // there is an active EntityTransaction -- roll it back
try {
- em.close();
+ em.getTransaction().rollback();
} catch (Exception e) {
- logger.error(method + ": Caught Exception attempting to close EntityManager, ", e);
+ logger.error(method + ": Caught Exception attempting to rollback EntityTransaction,", e);
}
}
+
+ // now, close the EntityManager
+ try {
+ em.close();
+ } catch (Exception e) {
+ logger.error(method + ": Caught Exception attempting to close EntityManager, ", e);
+ }
}
}
}
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PMStandbyStateChangeNotifier.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PMStandbyStateChangeNotifier.java
index 5a6dd8fa..84cc8dbd 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PMStandbyStateChangeNotifier.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PMStandbyStateChangeNotifier.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -101,11 +101,9 @@ public class PMStandbyStateChangeNotifier extends StateChangeNotifier {
* has synchronize all of its methods. Only one stateManagement operation can occur at a time. Thus,
* only one handleStateChange() call will ever be made at a time.
*/
- if(logger.isInfoEnabled()){
- if(logger.isDebugEnabled()){
- logger.debug("handleStateChange: Entering, message={}, standbyStatus={}",
- super.getMessage(), super.getStateManagement().getStandbyStatus());
- }
+ if(logger.isDebugEnabled()){
+ logger.debug("handleStateChange: Entering, message={}, standbyStatus={}",
+ super.getMessage(), super.getStateManagement().getStandbyStatus());
}
String standbyStatus = super.getStateManagement().getStandbyStatus();
String pdpId = ActiveStandbyProperties
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java
index db848ebb..b5fe3071 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -20,6 +20,7 @@
package org.onap.policy.drools.activestandby;
+@FunctionalInterface
public interface ThreadRunningChecker {
public void checkThreadStatus();
diff --git a/feature-active-standby-management/src/test/java/org/onap/policy/drools/controller/test/AllSeemsWellTest.java b/feature-active-standby-management/src/test/java/org/onap/policy/drools/controller/test/AllSeemsWellTest.java
index 0318bed6..19265206 100644
--- a/feature-active-standby-management/src/test/java/org/onap/policy/drools/controller/test/AllSeemsWellTest.java
+++ b/feature-active-standby-management/src/test/java/org/onap/policy/drools/controller/test/AllSeemsWellTest.java
@@ -37,7 +37,6 @@ import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.onap.policy.common.im.StateManagement;
import org.onap.policy.drools.activestandby.ActiveStandbyFeatureAPI;
@@ -264,7 +263,7 @@ public class AllSeemsWellTest {
logger.debug("testAllSeemsWell: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
+ "time to check droolspdpentity table", sleepTime);
- Thread.sleep(sleepTime);
+ sleep(sleepTime);
// Verify that this formerly un-designated PDP in HOT_STANDBY is now designated and providing service.
@@ -292,7 +291,7 @@ public class AllSeemsWellTest {
//It takes 10x the update interval (1 sec) before the watcher will declare the election handler dead
//and that just stops forward progress counter. So, the fp monitor must then run to determine
//if the fpc has stalled. That will take about another 5 sec.
- Thread.sleep(stalledElectionHandlerSleepTime);
+ sleep(stalledElectionHandlerSleepTime);
logger.debug("testAllSeemsWell: After isStalled=true, PDP= {} "
+ "has standbyStatus= {}", thisPdpId, smf.getStandbyStatus(thisPdpId));
@@ -302,7 +301,7 @@ public class AllSeemsWellTest {
//Now lets resume the election handler
DroolsPdpsElectionHandler.setIsStalled(false);
- Thread.sleep(resumedElectionHandlerSleepTime);
+ sleep(resumedElectionHandlerSleepTime);
logger.debug("testAllSeemsWell: After isStalled=false, PDP= {} "
+ "has standbyStatus= {}", thisPdpId, smf.getStandbyStatus(thisPdpId));
@@ -313,4 +312,8 @@ public class AllSeemsWellTest {
logger.debug("\n\ntestAllSeemsWell: Exiting\n\n");
}
+
+ private void sleep(long sleepms) throws InterruptedException {
+ Thread.sleep(sleepms);
+ }
}
diff --git a/feature-active-standby-management/src/test/java/org/onap/policy/drools/controller/test/StandbyStateManagementTest.java b/feature-active-standby-management/src/test/java/org/onap/policy/drools/controller/test/StandbyStateManagementTest.java
index 876cd99a..66af3eaa 100644
--- a/feature-active-standby-management/src/test/java/org/onap/policy/drools/controller/test/StandbyStateManagementTest.java
+++ b/feature-active-standby-management/src/test/java/org/onap/policy/drools/controller/test/StandbyStateManagementTest.java
@@ -38,7 +38,6 @@ import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.onap.policy.common.im.AdministrativeStateException;
import org.onap.policy.common.im.IntegrityMonitor;
@@ -274,7 +273,7 @@ public class StandbyStateManagementTest {
assertTrue(pmNotifier.getPreviousStandbyStatus().equals(PMStandbyStateChangeNotifier.HOTSTANDBY_OR_COLDSTANDBY));
//Sleep long enough for the delayActivationTimer to run
- Thread.sleep(5000);
+ sleep(5000);
assertTrue(pmNotifier.getPreviousStandbyStatus().equals(StateManagement.PROVIDING_SERVICE));
//standbystatus = providingservice
@@ -790,7 +789,7 @@ public class StandbyStateManagementTest {
logger.debug("testColdStandby: Runner started; Sleeping "
+ interruptRecoveryTime + "ms before promoting PDP= {}",
thisPdpId);
- Thread.sleep(interruptRecoveryTime);
+ sleep(interruptRecoveryTime);
logger.debug("testColdStandby: Promoting PDP={}", thisPdpId);
smf.promote();
@@ -802,7 +801,7 @@ public class StandbyStateManagementTest {
logger.debug("testColdStandby: Locking smf");
smf.lock();
- Thread.sleep(interruptRecoveryTime);
+ sleep(interruptRecoveryTime);
// Verify that the PDP is no longer designated.
@@ -812,7 +811,7 @@ public class StandbyStateManagementTest {
assertTrue(droolsPdpEntity.isDesignated() == false);
logger.debug("\n\ntestColdStandby: Exiting\n\n");
- Thread.sleep(interruptRecoveryTime);
+ sleep(interruptRecoveryTime);
}
@@ -918,7 +917,7 @@ public class StandbyStateManagementTest {
logger.debug("testHotStandby1: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
+ "time to check droolspdpentity table", sleepTime);
- Thread.sleep(sleepTime);
+ sleep(sleepTime);
// Verify that this formerly un-designated PDP in HOT_STANDBY is now designated and providing service.
@@ -936,7 +935,7 @@ public class StandbyStateManagementTest {
//policyManagementRunner.stopRunner();
logger.debug("\n\ntestHotStandby1: Exiting\n\n");
- Thread.sleep(interruptRecoveryTime);
+ sleep(interruptRecoveryTime);
}
@@ -1066,7 +1065,7 @@ public class StandbyStateManagementTest {
logger.info("testHotStandby2: Runner started; Sleeping {} "
+ "ms before promoting/demoting", interruptRecoveryTime);
- Thread.sleep(interruptRecoveryTime);
+ sleep(interruptRecoveryTime);
logger.info("testHotStandby2: Runner started; promoting PDP={}", activePdpId);
//At this point, the newly created pdp will have set the state to disabled/failed/cold standby
@@ -1085,7 +1084,7 @@ public class StandbyStateManagementTest {
logger.info("testHotStandby2: Sleeping {} ms, to allow JpaDroolsPdpsConnector "
+ "time to check droolspdpentity table", sleepTime);
- Thread.sleep(sleepTime);
+ sleep(sleepTime);
/*
* Verify that this PDP, demoted to HOT_STANDBY, is now
@@ -1108,7 +1107,7 @@ public class StandbyStateManagementTest {
//policyManagementRunner.stopRunner();
logger.info("\n\ntestHotStandby2: Exiting\n\n");
- Thread.sleep(interruptRecoveryTime);
+ sleep(interruptRecoveryTime);
}
@@ -1221,7 +1220,7 @@ public class StandbyStateManagementTest {
logger.debug("testLocking1: Runner started; Sleeping "
+ interruptRecoveryTime + "ms before promoting PDP={}",
thisPdpId);
- Thread.sleep(interruptRecoveryTime);
+ sleep(interruptRecoveryTime);
logger.debug("testLocking1: Promoting PDP={}", thisPdpId);
sm.promote();
@@ -1229,7 +1228,7 @@ public class StandbyStateManagementTest {
logger.debug("testLocking1: Sleeping {} ms, to allow time for "
+ "policy-management.Main class to come up, designated= {}",
sleepTime, conn.getPdp(thisPdpId).isDesignated());
- Thread.sleep(sleepTime);
+ sleep(sleepTime);
logger.debug("testLocking1: Waking up and invoking startTransaction on active PDP={}"
+ ", designated= {}",thisPdpId, conn.getPdp(thisPdpId).isDesignated());
@@ -1258,7 +1257,7 @@ public class StandbyStateManagementTest {
logger.debug("testLocking1: sleeping" + electionWaitSleepTime
+ " to allow election handler to re-promote PDP={}", thisPdpId);
- Thread.sleep(electionWaitSleepTime);
+ sleep(electionWaitSleepTime);
logger.debug("testLocking1: Invoking startTransaction on re-promoted PDP={}"
+ ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
@@ -1283,7 +1282,7 @@ public class StandbyStateManagementTest {
// Just to avoid any race conditions, sleep a little after locking
logger.debug("testLocking1: Sleeping a few millis after locking, to avoid race condition");
- Thread.sleep(100);
+ sleep(100);
logger.debug("testLocking1: Invoking startTransaction on locked PDP= {}"
+ ", designated= {}",thisPdpId, conn.getPdp(thisPdpId).isDesignated());
@@ -1309,7 +1308,7 @@ public class StandbyStateManagementTest {
// Just to avoid any race conditions, sleep a little after locking
logger.debug("testLocking1: Sleeping a few millis after unlocking, to avoid race condition");
- Thread.sleep(electionWaitSleepTime);
+ sleep(electionWaitSleepTime);
logger.debug("testLocking1: Invoking startTransaction on unlocked PDP="
+ thisPdpId
@@ -1337,7 +1336,7 @@ public class StandbyStateManagementTest {
// Just to avoid any race conditions, sleep a little after promoting
logger.debug("testLocking1: Sleeping a few millis after demoting, to avoid race condition");
- Thread.sleep(100);
+ sleep(100);
logger.debug("testLocking1: Invoking startTransaction on demoted PDP={}"
+ ", designated={}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
@@ -1357,7 +1356,7 @@ public class StandbyStateManagementTest {
}
logger.debug("\n\ntestLocking1: Exiting\n\n");
- Thread.sleep(interruptRecoveryTime);
+ sleep(interruptRecoveryTime);
}
@@ -1483,7 +1482,7 @@ public class StandbyStateManagementTest {
logger.debug("testLocking2: Runner started; Sleeping {} ms "
+ "before promoting/demoting", interruptRecoveryTime);
- Thread.sleep(interruptRecoveryTime);
+ sleep(interruptRecoveryTime);
logger.debug("testLocking2: Promoting PDP= {}", thisPdpId);
sm.promote();
@@ -1493,7 +1492,7 @@ public class StandbyStateManagementTest {
sm2.demote();
logger.debug("testLocking2: Sleeping {} ms, to allow time for to come up", sleepTime);
- Thread.sleep(sleepTime);
+ sleep(sleepTime);
logger.debug("testLocking2: Waking up and invoking startTransaction on active PDP={}"
+ ", designated= {}", thisPdpId, conn.getPdp(thisPdpId).isDesignated());
@@ -1521,7 +1520,7 @@ public class StandbyStateManagementTest {
logger.debug("testLocking2: sleeping {}"
+ " to allow election handler to re-promote PDP={}", electionWaitSleepTime, thisPdpId);
- Thread.sleep(electionWaitSleepTime);
+ sleep(electionWaitSleepTime);
logger.debug("testLocking2: Waking up and invoking startTransaction "
+ "on re-promoted PDP= {}, designated= {}",
@@ -1546,6 +1545,10 @@ public class StandbyStateManagementTest {
assertTrue(standbyPdpDesignated == false);
logger.debug("\n\ntestLocking2: Exiting\n\n");
- Thread.sleep(interruptRecoveryTime);
+ sleep(interruptRecoveryTime);
+ }
+
+ private void sleep(long sleepms) throws InterruptedException {
+ Thread.sleep(sleepms);
}
}
diff --git a/feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java b/feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java
index e48bd2fa..aac456e2 100644
--- a/feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java
+++ b/feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-eelf
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -36,7 +36,7 @@ import org.onap.policy.drools.system.PolicyEngine;
public class EelfFeature implements PolicyEngineFeatureAPI {
@Override
- final public boolean beforeBoot(PolicyEngine engine, String cliArgs[]) {
+ public final boolean beforeBoot(PolicyEngine engine, String[] cliArgs) {
String logback = System.getProperty(Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY,
Main.LOGBACK_CONFIGURATION_FILE_DEFAULT);
@@ -53,17 +53,18 @@ public class EelfFeature implements PolicyEngineFeatureAPI {
Logger logger = FlexLogger.getLogger(this.getClass(), true);
if (logger.isInfoEnabled()) {
- logger.info("eelf-feature: Property " + Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY + "=" +
- System.getProperty(Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY));
- logger.info("eelf-feature: Property " + Configuration.PROPERTY_LOGGING_FILE_PATH + "=" +
- System.getProperty(Configuration.PROPERTY_LOGGING_FILE_PATH));
- logger.info("eelf-feature: Property " + Configuration.PROPERTY_LOGGING_FILE_NAME + "=" +
- System.getProperty(Configuration.PROPERTY_LOGGING_FILE_NAME));
+ logProperty(logger, Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY);
+ logProperty(logger, Configuration.PROPERTY_LOGGING_FILE_PATH);
+ logProperty(logger, Configuration.PROPERTY_LOGGING_FILE_NAME);
}
return false;
}
+ private void logProperty(Logger logger, String propnm) {
+ logger.info("eelf-feature: Property " + propnm + "=" + System.getProperty(propnm));
+ }
+
@Override
public int getSequenceNumber() {
return 0;
diff --git a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
index bdb15a70..8fa6dfab 100644
--- a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
+++ b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-healthcheck
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -38,6 +38,11 @@ import org.slf4j.LoggerFactory;
* Healthcheck
*/
public interface HealthCheck extends Startable {
+
+ /**
+ * Healthcheck Monitor
+ */
+ public static final HealthCheck monitor = new HealthCheckMonitor();
/**
* Healthcheck Report
@@ -156,7 +161,7 @@ public interface HealthCheck extends Startable {
return details;
}
- public void setDetails(ArrayList<Report> details) {
+ public void setDetails(List<Report> details) {
this.details = details;
}
}
@@ -166,11 +171,6 @@ public interface HealthCheck extends Startable {
* @return a report
*/
public Reports healthCheck();
-
- /**
- * Healthcheck Monitor
- */
- public static final HealthCheck monitor = new HealthCheckMonitor();
}
/**
@@ -243,7 +243,7 @@ class HealthCheckMonitor implements HealthCheck {
* {@inheritDoc}
*/
@Override
- public boolean start() throws IllegalStateException {
+ public boolean start() {
try {
this.healthCheckProperties = SystemPersistence.manager.getProperties(HealthCheckFeature.CONFIGURATION_PROPERTIES_NAME);
@@ -265,7 +265,7 @@ class HealthCheckMonitor implements HealthCheck {
* {@inheritDoc}
*/
@Override
- public boolean stop() throws IllegalStateException {
+ public boolean stop() {
for (HttpServletServer server : servers) {
try {
@@ -290,7 +290,7 @@ class HealthCheckMonitor implements HealthCheck {
* {@inheritDoc}
*/
@Override
- public void shutdown() throws IllegalStateException {
+ public void shutdown() {
this.stop();
}
diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java
index 42a638a0..c3f00359 100644
--- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java
+++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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,8 +21,6 @@
package org.onap.policy.drools.persistence;
public class DroolsPersistenceProperties {
- private DroolsPersistenceProperties() {
- }
/*
* feature-session-persistence.properties parameter key values
*/
@@ -32,4 +30,8 @@ public class DroolsPersistenceProperties {
public static final String DB_PWD = "javax.persistence.jdbc.password";
public static final String DB_SESSIONINFO_TIMEOUT = "persistence.sessioninfo.timeout";
public static final String JTA_OBJECTSTORE_DIR = "persistence.objectstore.dir";
+
+ private DroolsPersistenceProperties() {
+ super();
+ }
}
diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java
index 9bb26ac1..47ed221e 100644
--- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java
+++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -54,11 +54,7 @@ public class EntityMgrTrans extends EntityMgrCloser {
userTrans.begin();
em.joinTransaction();
- } catch (RuntimeException e) {
- em.close();
- throw new EntityMgrException(e);
-
- } catch (NotSupportedException | SystemException e) {
+ } catch (RuntimeException |NotSupportedException | SystemException e) {
em.close();
throw new EntityMgrException(e);
}
diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java
index 032383b4..129be8a7 100644
--- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java
+++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -148,7 +148,7 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
* {@inheritDoc}
*/
@Override
- public void globalInit(String args[], String configDir) {
+ public void globalInit(String[] args, String configDir) {
kieSvcFact = fact.getKieServices();
@@ -448,21 +448,71 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
ds.close();
}
}
- }
- /* ============================================================ */
+ /**
+ * Configures java system properties for JPA/JTA.
+ */
+ private void configureSysProps() {
+ System.setProperty("com.arjuna.ats.arjuna.coordinator.defaultTimeout", "60");
+ System.setProperty("com.arjuna.ats.arjuna.objectstore.objectStoreDir",
+ persistProps.getProperty(DroolsPersistenceProperties.JTA_OBJECTSTORE_DIR));
+ System.setProperty("ObjectStoreEnvironmentBean.objectStoreDir",
+ persistProps.getProperty(DroolsPersistenceProperties.JTA_OBJECTSTORE_DIR));
+ }
- /**
- * Configures java system properties for JPA/JTA.
- */
- private void configureSysProps() {
- System.setProperty("com.arjuna.ats.arjuna.coordinator.defaultTimeout", "60");
- System.setProperty("com.arjuna.ats.arjuna.objectstore.objectStoreDir",
- persistProps.getProperty(DroolsPersistenceProperties.JTA_OBJECTSTORE_DIR));
- System.setProperty("ObjectStoreEnvironmentBean.objectStoreDir",
- persistProps.getProperty(DroolsPersistenceProperties.JTA_OBJECTSTORE_DIR));
+ /**
+ * Configures a Kie Environment
+ *
+ * @param env
+ * environment to be configured
+ * @param emf
+ * entity manager factory
+ */
+ private void configureKieEnv(Environment env, EntityManagerFactory emf) {
+ env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
+ env.set(EnvironmentName.TRANSACTION, fact.getUserTrans());
+ env.set(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY, fact.getTransSyncReg());
+ env.set(EnvironmentName.TRANSACTION_MANAGER, fact.getTransMgr());
+ }
+
+ /**
+ * Gets a session's ID from the persistent store.
+ *
+ * @param conn
+ * persistence connector
+ * @param sessnm
+ * name of the session
+ * @return the session's id, or {@code -1} if the session is not found
+ */
+ private long getSessionId(DroolsSessionConnector conn, String sessnm) {
+ DroolsSession sess = conn.get(sessnm);
+ return sess != null ? sess.getSessionId() : -1;
+ }
+
+ /**
+ * Replaces a session within the persistent store, if it exists. Adds it
+ * otherwise.
+ *
+ * @param conn
+ * persistence connector
+ * @param sessnm
+ * name of session to be updated
+ * @param kieSession
+ * new session information
+ */
+ private void replaceSession(DroolsSessionConnector conn, String sessnm, KieSession kieSession) {
+
+ DroolsSessionEntity sess = new DroolsSessionEntity();
+
+ sess.setSessionName(sessnm);
+ sess.setSessionId(kieSession.getIdentifier());
+
+ conn.replace(sess);
+ }
}
+ /* ============================================================ */
+
/**
* Gets the data source properties.
*
@@ -485,21 +535,6 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
}
/**
- * Configures a Kie Environment
- *
- * @param env
- * environment to be configured
- * @param emf
- * entity manager factory
- */
- private void configureKieEnv(Environment env, EntityManagerFactory emf) {
- env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
- env.set(EnvironmentName.TRANSACTION, fact.getUserTrans());
- env.set(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY, fact.getTransSyncReg());
- env.set(EnvironmentName.TRANSACTION_MANAGER, fact.getTransMgr());
- }
-
- /**
* Removes "old" Drools 'sessioninfo' records, so they aren't used to
* restore data to Drools sessions. This also has the useful side-effect of
* removing abandoned records as well.
@@ -543,41 +578,6 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
}
/**
- * Gets a session's ID from the persistent store.
- *
- * @param conn
- * persistence connector
- * @param sessnm
- * name of the session
- * @return the session's id, or {@code -1} if the session is not found
- */
- private long getSessionId(DroolsSessionConnector conn, String sessnm) {
- DroolsSession sess = conn.get(sessnm);
- return sess != null ? sess.getSessionId() : -1;
- }
-
- /**
- * Replaces a session within the persistent store, if it exists. Adds it
- * otherwise.
- *
- * @param conn
- * persistence connector
- * @param sessnm
- * name of session to be updated
- * @param kieSession
- * new session information
- */
- private void replaceSession(DroolsSessionConnector conn, String sessnm, KieSession kieSession) {
-
- DroolsSessionEntity sess = new DroolsSessionEntity();
-
- sess.setSessionName(sessnm);
- sess.setSessionId(kieSession.getIdentifier());
-
- conn.replace(sess);
- }
-
- /**
* Determine whether persistence is enabled for a specific container
*
* @param container
@@ -801,7 +801,8 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
// We want to continue, despite any exceptions that occur
// while rules are fired.
- for (;;) {
+ boolean cont = true;
+ while(cont) {
try {
if (kieSession.fireAllRules() > 0) {
@@ -815,16 +816,17 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
} catch (Exception | LinkageError e) {
logger.error("Exception during kieSession.fireAllRules", e);
}
+
try {
if (stopped.await(sleepTime, TimeUnit.MILLISECONDS)) {
- break;
+ cont = false;
}
} catch (InterruptedException e) {
logger.error("startThread exception: ", e);
Thread.currentThread().interrupt();
- break;
+ cont = false;
}
}
@@ -892,6 +894,10 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine
private static class SingletonRegistry {
private static final TransactionSynchronizationRegistry transreg = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();
+
+ private SingletonRegistry() {
+ super();
+ }
}
/**
diff --git a/feature-simulators/src/main/java/org/onap/policy/drools/simulators/DMaaPSimulatorJaxRs.java b/feature-simulators/src/main/java/org/onap/policy/drools/simulators/DMaaPSimulatorJaxRs.java
index bdabc6ee..2513a040 100644
--- a/feature-simulators/src/main/java/org/onap/policy/drools/simulators/DMaaPSimulatorJaxRs.java
+++ b/feature-simulators/src/main/java/org/onap/policy/drools/simulators/DMaaPSimulatorJaxRs.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-simulators
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
@Path("/events")
public class DMaaPSimulatorJaxRs {
+ private static final String NO_DATA_MSG = "No Data";
private static final Map<String, BlockingQueue<String>> queues = new ConcurrentHashMap<>();
private static final Logger logger = LoggerFactory.getLogger(DMaaPSimulatorJaxRs.class);
private static int responseCode = 200;
@@ -57,7 +58,6 @@ public class DMaaPSimulatorJaxRs {
try {
httpResponse.flushBuffer();
} catch (IOException e) {
- final Logger logger = LoggerFactory.getLogger(DMaaPSimulatorJaxRs.class);
logger.error("flushBuffer threw: ", e);
return "Got an error";
}
@@ -68,14 +68,15 @@ public class DMaaPSimulatorJaxRs {
}
if (queues.containsKey(topicName)) {
BlockingQueue<String> queue = queues.get(topicName);
- String response = "No Data";
+ String response = NO_DATA_MSG;
try {
response = queue.poll(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
logger.debug("error in DMaaP simulator", e);
+ Thread.currentThread().interrupt();
}
if (response == null) {
- response = "No Data";
+ response = NO_DATA_MSG;
}
return response;
}
@@ -86,12 +87,13 @@ public class DMaaPSimulatorJaxRs {
BlockingQueue<String> queue = queues.get(topicName);
String response = queue.poll();
if (response == null) {
- response = "No Data";
+ response = NO_DATA_MSG;
}
return response;
}
} catch (InterruptedException e) {
logger.debug("error in DMaaP simulator", e);
+ Thread.currentThread().interrupt();
}
}
return "No topic";
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
index 7dc53ce2..4806df04 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-core
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -350,7 +350,6 @@ public class PolicyContainer implements Startable
* with this name
*/
public PolicySession adoptKieSession(String name, KieSession kieSession)
- throws IllegalArgumentException, IllegalStateException
{
if(name == null){
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 984ff47f..431050f5 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
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -71,7 +71,7 @@ public class PolicySession
private ThreadModel threadModel = null;
// supports 'getCurrentSession()' method
- private static ThreadLocal<PolicySession> policySession =
+ private static ThreadLocal<PolicySession> policySess =
new ThreadLocal<>();
/**
@@ -194,7 +194,7 @@ public class PolicySession
public void setPolicySession()
{
// this sets a 'ThreadLocal' variable
- policySession.set(this);
+ policySess.set(this);
}
/**
@@ -204,7 +204,7 @@ public class PolicySession
*/
public static PolicySession getCurrentSession()
{
- return policySession.get();
+ return policySess.get();
}
/**
diff --git a/policy-core/src/main/java/org/onap/policy/drools/properties/Startable.java b/policy-core/src/main/java/org/onap/policy/drools/properties/Startable.java
index e0f03bb1..6fa2e58b 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/properties/Startable.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/properties/Startable.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-core
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -35,7 +35,7 @@ public interface Startable {
* @throws IllegalStateException. if the element is in a state that
* conflicts with the start operation.
*/
- public boolean start() throws IllegalStateException;
+ public boolean start();
/**
* Stop operation. The entity can be restarted again by invoking
@@ -46,7 +46,7 @@ public interface Startable {
* @throws IllegalStateException. if the element is in a state that
* conflicts with the stop operation.
*/
- public boolean stop()throws IllegalStateException;
+ public boolean stop();
/**
* shutdown operation. The terminate operation yields the entity
@@ -55,7 +55,7 @@ public interface Startable {
* @throws IllegalStateException. if the element is in a state that
* conflicts with the stop operation.
*/
- public void shutdown()throws IllegalStateException;
+ public void shutdown();
/**
* is it alive?
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java
index fc7db6f7..5c04bb8f 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -43,6 +43,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
public interface TopicEndpoint extends Startable, Lockable {
/**
+ * singleton for global access
+ */
+ public static final TopicEndpoint manager = new ProxyTopicEndpointManager();
+
+ /**
* Add Topic Sources to the communication infrastructure initialized per properties
*
* @param properties properties for Topic Source construction
@@ -90,8 +95,7 @@ public interface TopicEndpoint extends Startable, Lockable {
* @throws IllegalArgumentException if invalid parameters are present
* @throws UnsupportedOperationException if the operation is not supported.
*/
- public TopicSource getTopicSource(Topic.CommInfrastructure commType, String topicName)
- throws UnsupportedOperationException;
+ public TopicSource getTopicSource(Topic.CommInfrastructure commType, String topicName);
/**
* get the UEB Topic Source for the given topic name
@@ -138,8 +142,7 @@ public interface TopicEndpoint extends Startable, Lockable {
* TopicWriters for a topic name and communication infrastructure
* @throws IllegalArgumentException if invalid parameters are present
*/
- public TopicSink getTopicSink(Topic.CommInfrastructure commType, String topicName)
- throws UnsupportedOperationException;
+ public TopicSink getTopicSink(Topic.CommInfrastructure commType, String topicName);
/**
* get the Topic Sinks for the given topic name and all the underlying communication
@@ -232,11 +235,6 @@ public interface TopicEndpoint extends Startable, Lockable {
* @return the NOOP Topic Sinks List
*/
public List<NoopTopicSink> getNoopTopicSinks();
-
- /**
- * singleton for global access
- */
- public static final TopicEndpoint manager = new ProxyTopicEndpointManager();
}
@@ -552,17 +550,14 @@ class ProxyTopicEndpointManager implements TopicEndpoint {
}
@Override
- public TopicSource getTopicSource(Topic.CommInfrastructure commType, String topicName)
- throws UnsupportedOperationException {
+ public TopicSource getTopicSource(Topic.CommInfrastructure commType, String topicName) {
if (commType == null) {
- throw new IllegalArgumentException(
- "Invalid parameter: a communication infrastructure required to fetch " + topicName);
+ throw parmException(topicName);
}
if (topicName == null) {
- throw new IllegalArgumentException(
- "Invalid parameter: a communication infrastructure required to fetch " + topicName);
+ throw parmException(topicName);
}
switch (commType) {
@@ -575,17 +570,19 @@ class ProxyTopicEndpointManager implements TopicEndpoint {
}
}
+ private IllegalArgumentException parmException(String topicName) {
+ return new IllegalArgumentException(
+ "Invalid parameter: a communication infrastructure required to fetch " + topicName);
+ }
+
@Override
- public TopicSink getTopicSink(Topic.CommInfrastructure commType, String topicName)
- throws UnsupportedOperationException {
+ public TopicSink getTopicSink(Topic.CommInfrastructure commType, String topicName) {
if (commType == null) {
- throw new IllegalArgumentException(
- "Invalid parameter: a communication infrastructure required to fetch " + topicName);
+ throw parmException(topicName);
}
if (topicName == null) {
- throw new IllegalArgumentException(
- "Invalid parameter: a communication infrastructure required to fetch " + topicName);
+ throw parmException(topicName);
}
switch (commType) {
@@ -603,8 +600,7 @@ class ProxyTopicEndpointManager implements TopicEndpoint {
@Override
public List<TopicSink> getTopicSinks(String topicName) {
if (topicName == null) {
- throw new IllegalArgumentException(
- "Invalid parameter: a communication infrastructure required to fetch " + topicName);
+ throw parmException(topicName);
}
final List<TopicSink> sinks = new ArrayList<>();
@@ -612,24 +608,28 @@ class ProxyTopicEndpointManager implements TopicEndpoint {
try {
sinks.add(this.getUebTopicSink(topicName));
} catch (final Exception e) {
- logger.debug("No sink for topic: {}", topicName, e);
+ logNoSink(topicName, e);
}
try {
sinks.add(this.getDmaapTopicSink(topicName));
} catch (final Exception e) {
- logger.debug("No sink for topic: {}", topicName, e);
+ logNoSink(topicName, e);
}
try {
sinks.add(this.getNoopTopicSink(topicName));
} catch (final Exception e) {
- logger.debug("No sink for topic: {}", topicName, e);
+ logNoSink(topicName, e);
}
return sinks;
}
+private void logNoSink(String topicName, Exception ex) {
+ logger.debug("No sink for topic: {}", topicName, ex);
+}
+
@Override
public UebTopicSource getUebTopicSource(String topicName) {
return UebTopicSource.factory.get(topicName);
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicSink.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicSink.java
index b7937ec3..5ea849ee 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicSink.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicSink.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -35,6 +35,6 @@ public interface TopicSink extends Topic {
* @throws IllegalStateException the entity is in an state that prevents
* it from sending messages, for example, locked or stopped.
*/
- public boolean send(String message) throws IllegalArgumentException, IllegalStateException;
+ public boolean send(String message);
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java
index 43854c2a..5ff5084e 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -167,6 +167,8 @@ public interface DmaapTopicSinkFactory {
* Factory of DMAAP Reader Topics indexed by topic name
*/
class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory {
+ private static final String MISSING_TOPIC = "A topic must be provided";
+
/**
* Logger
*/
@@ -196,7 +198,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory {
boolean allowSelfSignedCerts) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
synchronized (this) {
@@ -230,7 +232,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory {
boolean useHttps, boolean allowSelfSignedCerts) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
synchronized (this) {
@@ -277,7 +279,8 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory {
PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX);
List<String> serverList;
- if (servers != null && !servers.isEmpty()) serverList = new ArrayList<>(Arrays.asList(servers.split("\\s*,\\s*")));
+ if (servers != null && !servers.isEmpty())
+ serverList = new ArrayList<>(Arrays.asList(servers.split("\\s*,\\s*")));
else serverList = new ArrayList<>();
String apiKey = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS +
@@ -404,7 +407,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory {
public void destroy(String topic) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
DmaapTopicSink dmaapTopicWriter;
@@ -435,7 +438,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory {
public DmaapTopicSink get(String topic) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
synchronized(this) {
@@ -449,9 +452,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory {
@Override
public synchronized List<DmaapTopicSink> inventory() {
- List<DmaapTopicSink> writers =
- new ArrayList<>(this.dmaapTopicWriters.values());
- return writers;
+ return new ArrayList<>(this.dmaapTopicWriters.values());
}
@Override
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java
index d5894d5e..5a8e2a72 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -53,8 +53,7 @@ public interface DmaapTopicSourceFactory {
* @return an DMAAP Topic Source
* @throws IllegalArgumentException if invalid parameters are present
*/
- public List<DmaapTopicSource> build(Properties properties)
- throws IllegalArgumentException;
+ public List<DmaapTopicSource> build(Properties properties);
/**
* Instantiates a new DMAAP Topic Source
@@ -88,8 +87,7 @@ public interface DmaapTopicSourceFactory {
int fetchLimit,
boolean managed,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException;
+ boolean allowSelfSignedCerts);
/**
* Instantiates a new DMAAP Topic Source
@@ -135,8 +133,7 @@ public interface DmaapTopicSourceFactory {
Map<String,String> additionalProps,
boolean managed,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException;
+ boolean allowSelfSignedCerts);
/**
* Instantiates a new DMAAP Topic Source
@@ -152,8 +149,7 @@ public interface DmaapTopicSourceFactory {
public DmaapTopicSource build(List<String> servers,
String topic,
String apiKey,
- String apiSecret)
- throws IllegalArgumentException;
+ String apiSecret);
/**
* Instantiates a new DMAAP Topic Source
@@ -165,8 +161,7 @@ public interface DmaapTopicSourceFactory {
* @throws IllegalArgumentException if invalid parameters are present
*/
public DmaapTopicSource build(List<String> servers,
- String topic)
- throws IllegalArgumentException;
+ String topic);
/**
* Destroys an DMAAP Topic Source based on a topic
@@ -189,8 +184,7 @@ public interface DmaapTopicSourceFactory {
* @throws IllegalStateException if the DMAAP Topic Source is
* an incorrect state
*/
- public DmaapTopicSource get(String topic)
- throws IllegalArgumentException, IllegalStateException;
+ public DmaapTopicSource get(String topic);
/**
* Provides a snapshot of the DMAAP Topic Sources
@@ -207,6 +201,8 @@ public interface DmaapTopicSourceFactory {
*/
class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
+ private static final String MISSING_TOPIC = "A topic must be provided";
+
/**
* Logger
*/
@@ -240,11 +236,10 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
Map<String,String> additionalProps,
boolean managed,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ boolean allowSelfSignedCerts) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
synchronized(this) {
@@ -282,15 +277,14 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
int fetchLimit,
boolean managed,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ boolean allowSelfSignedCerts) {
if (servers == null || servers.isEmpty()) {
throw new IllegalArgumentException("DMaaP Server(s) must be provided");
}
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
synchronized(this) {
@@ -315,8 +309,7 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
* {@inheritDoc}
*/
@Override
- public List<DmaapTopicSource> build(Properties properties)
- throws IllegalArgumentException {
+ public List<DmaapTopicSource> build(Properties properties) {
String readTopics = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS);
if (readTopics == null || readTopics.isEmpty()) {
@@ -325,11 +318,11 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
}
List<String> readTopicList = new ArrayList<>(Arrays.asList(readTopics.split("\\s*,\\s*")));
- List<DmaapTopicSource> dmaapTopicSource_s = new ArrayList<>();
+ List<DmaapTopicSource> dmaapTopicSourceLst = new ArrayList<>();
synchronized(this) {
for (String topic: readTopicList) {
if (this.dmaapTopicSources.containsKey(topic)) {
- dmaapTopicSource_s.add(this.dmaapTopicSources.get(topic));
+ dmaapTopicSourceLst.add(this.dmaapTopicSources.get(topic));
continue;
}
@@ -338,7 +331,8 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX);
List<String> serverList;
- if (servers != null && !servers.isEmpty()) serverList = new ArrayList<>(Arrays.asList(servers.split("\\s*,\\s*")));
+ if (servers != null && !servers.isEmpty())
+ serverList = new ArrayList<>(Arrays.asList(servers.split("\\s*,\\s*")));
else serverList = new ArrayList<>();
String apiKey = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS +
@@ -490,10 +484,10 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
dme2Latitude, dme2Longitude, dme2AdditionalProps,
managed, useHttps, allowSelfSignedCerts);
- dmaapTopicSource_s.add(uebTopicSource);
+ dmaapTopicSourceLst.add(uebTopicSource);
}
}
- return dmaapTopicSource_s;
+ return dmaapTopicSourceLst;
}
/**
@@ -504,7 +498,7 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
public DmaapTopicSource build(List<String> servers,
String topic,
String apiKey,
- String apiSecret) throws IllegalArgumentException {
+ String apiSecret) {
return this.build(servers, topic,
apiKey, apiSecret, null, null,
null, null,
@@ -520,7 +514,7 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
* @throws IllegalArgumentException
*/
@Override
- public DmaapTopicSource build(List<String> servers, String topic) throws IllegalArgumentException {
+ public DmaapTopicSource build(List<String> servers, String topic) {
return this.build(servers, topic, null, null);
}
@@ -528,11 +522,10 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
* {@inheritDoc}
*/
@Override
- public void destroy(String topic)
- throws IllegalArgumentException {
+ public void destroy(String topic) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
DmaapTopicSource uebTopicSource;
@@ -552,11 +545,10 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
* {@inheritDoc}
*/
@Override
- public DmaapTopicSource get(String topic)
- throws IllegalArgumentException, IllegalStateException {
+ public DmaapTopicSource get(String topic) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
synchronized(this) {
@@ -570,9 +562,7 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
@Override
public synchronized List<DmaapTopicSource> inventory() {
- List<DmaapTopicSource> readers =
- new ArrayList<>(this.dmaapTopicSources.values());
- return readers;
+ return new ArrayList<>(this.dmaapTopicSources.values());
}
@Override
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java
index 1958da06..8633d093 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -94,7 +94,9 @@ public interface NoopTopicSinkFactory {
* Factory of noop sinks
*/
class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory {
- /**
+ private static final String MISSING_TOPIC = "A topic must be provided";
+
+/**
* Logger
*/
private static Logger logger = LoggerFactory.getLogger(IndexedUebTopicSinkFactory.class);
@@ -159,7 +161,7 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory {
}
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
synchronized (this) {
@@ -179,7 +181,7 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory {
@Override
public void destroy(String topic) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
NoopTopicSink noopSink;
@@ -209,7 +211,7 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory {
@Override
public NoopTopicSink get(String topic) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
synchronized (this) {
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java
index fc4229c3..10468bef 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -116,6 +116,8 @@ public interface UebTopicSinkFactory {
* Factory of UEB Reader Topics indexed by topic name
*/
class IndexedUebTopicSinkFactory implements UebTopicSinkFactory {
+ private static final String MISSING_TOPIC = "A topic must be provided";
+
/**
* Logger
*/
@@ -142,7 +144,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory {
}
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
synchronized (this) {
@@ -245,7 +247,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory {
public void destroy(String topic) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
UebTopicSink uebTopicWriter;
@@ -276,7 +278,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory {
public UebTopicSink get(String topic) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
synchronized(this) {
@@ -290,9 +292,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory {
@Override
public synchronized List<UebTopicSink> inventory() {
- List<UebTopicSink> writers =
- new ArrayList<>(this.uebTopicSinks.values());
- return writers;
+ return new ArrayList<>(this.uebTopicSinks.values());
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java
index d614d100..d48be278 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -44,8 +44,7 @@ public interface UebTopicSourceFactory {
* @return an UEB Topic Source
* @throws IllegalArgumentException if invalid parameters are present
*/
- public List<UebTopicSource> build(Properties properties)
- throws IllegalArgumentException;
+ public List<UebTopicSource> build(Properties properties);
/**
* Instantiates a new UEB Topic Source
@@ -73,8 +72,7 @@ public interface UebTopicSourceFactory {
int fetchLimit,
boolean managed,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException;
+ boolean allowSelfSignedCerts);
/**
* Instantiates a new UEB Topic Source
@@ -90,8 +88,7 @@ public interface UebTopicSourceFactory {
public UebTopicSource build(List<String> servers,
String topic,
String apiKey,
- String apiSecret)
- throws IllegalArgumentException;
+ String apiSecret);
/**
* Instantiates a new UEB Topic Source
@@ -103,8 +100,7 @@ public interface UebTopicSourceFactory {
* @throws IllegalArgumentException if invalid parameters are present
*/
public UebTopicSource build(List<String> servers,
- String topic)
- throws IllegalArgumentException;
+ String topic);
/**
* Destroys an UEB Topic Source based on a topic
@@ -127,8 +123,7 @@ public interface UebTopicSourceFactory {
* @throws IllegalStateException if the UEB Topic Source is
* an incorrect state
*/
- public UebTopicSource get(String topic)
- throws IllegalArgumentException, IllegalStateException;
+ public UebTopicSource get(String topic);
/**
* Provides a snapshot of the UEB Topic Sources
@@ -143,6 +138,8 @@ public interface UebTopicSourceFactory {
* Factory of UEB Source Topics indexed by topic name
*/
class IndexedUebTopicSourceFactory implements UebTopicSourceFactory {
+ private static final String MISSING_TOPIC = "A topic must be provided";
+
/**
* Logger
*/
@@ -168,14 +165,13 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory {
int fetchLimit,
boolean managed,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ boolean allowSelfSignedCerts) {
if (servers == null || servers.isEmpty()) {
throw new IllegalArgumentException("UEB Server(s) must be provided");
}
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
synchronized(this) {
@@ -200,8 +196,7 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory {
* {@inheritDoc}
*/
@Override
- public List<UebTopicSource> build(Properties properties)
- throws IllegalArgumentException {
+ public List<UebTopicSource> build(Properties properties) {
String readTopics = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS);
if (readTopics == null || readTopics.isEmpty()) {
@@ -334,11 +329,10 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory {
* {@inheritDoc}
*/
@Override
- public void destroy(String topic)
- throws IllegalArgumentException {
+ public void destroy(String topic) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
UebTopicSource uebTopicSource;
@@ -358,11 +352,10 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory {
* {@inheritDoc}
*/
@Override
- public UebTopicSource get(String topic)
- throws IllegalArgumentException, IllegalStateException {
+ public UebTopicSource get(String topic) {
if (topic == null || topic.isEmpty()) {
- throw new IllegalArgumentException("A topic must be provided");
+ throw new IllegalArgumentException(MISSING_TOPIC);
}
synchronized(this) {
@@ -376,9 +369,7 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory {
@Override
public synchronized List<UebTopicSource> inventory() {
- List<UebTopicSource> readers =
- new ArrayList<>(this.uebTopicSources.values());
- return readers;
+ return new ArrayList<>(this.uebTopicSources.values());
}
@Override
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java
index 06503304..984baa79 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -101,8 +101,7 @@ public interface BusConsumer {
*/
public CambriaConsumerWrapper(List<String> servers, String topic, String apiKey,
String apiSecret, String consumerGroup, String consumerInstance, int fetchTimeout,
- int fetchLimit, boolean useHttps, boolean useSelfSignedCerts)
- throws IllegalArgumentException {
+ int fetchLimit, boolean useHttps, boolean useSelfSignedCerts) {
this.fetchTimeout = fetchTimeout;
@@ -368,27 +367,16 @@ public interface BusConsumer {
additionalProps.get(DmaapTopicSinkFactory.DME2_ROUTE_OFFER_PROPERTY);
if (environment == null || environment.isEmpty()) {
- throw new IllegalArgumentException(
- "Missing " + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + topic
- + PolicyProperties.PROPERTY_DMAAP_DME2_ENVIRONMENT_SUFFIX
- + " property for DME2 in DMaaP");
+ throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_ENVIRONMENT_SUFFIX);
}
if (aftEnvironment == null || aftEnvironment.isEmpty()) {
- throw new IllegalArgumentException(
- "Missing " + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + topic
- + PolicyProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX
- + " property for DME2 in DMaaP");
+ throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX);
}
if (latitude == null || latitude.isEmpty()) {
- throw new IllegalArgumentException("Missing "
- + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + topic
- + PolicyProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX + " property for DME2 in DMaaP");
+ throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX);
}
if (longitude == null || longitude.isEmpty()) {
- throw new IllegalArgumentException(
- "Missing " + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + topic
- + PolicyProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX
- + " property for DME2 in DMaaP");
+ throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX);
}
if ((dme2Partner == null || dme2Partner.isEmpty())
@@ -459,6 +447,13 @@ public interface BusConsumer {
logger.info("{}: CREATION", this);
}
+
+ private IllegalArgumentException parmException(String topic, String propnm) {
+ return new IllegalArgumentException(
+ "Missing " + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + topic
+ + propnm + " property for DME2 in DMaaP");
+
+ }
}
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java
index f664cfa7..852c9c16 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -51,7 +51,7 @@ public interface BusPublisher {
* @return true if success, false otherwise
* @throws IllegalArgumentException if no message provided
*/
- public boolean send(String partitionId, String message) throws IllegalArgumentException;
+ public boolean send(String partitionId, String message);
/**
* closes the publisher
@@ -73,7 +73,7 @@ public interface BusPublisher {
public CambriaPublisherWrapper(List<String> servers, String topic,
String apiKey,
- String apiSecret, boolean useHttps) throws IllegalArgumentException {
+ String apiSecret, boolean useHttps) {
PublisherBuilder builder = new CambriaClientBuilders.PublisherBuilder();
@@ -105,8 +105,7 @@ public interface BusPublisher {
* {@inheritDoc}
*/
@Override
- public boolean send(String partitionId, String message)
- throws IllegalArgumentException {
+ public boolean send(String partitionId, String message) {
if (message == null)
throw new IllegalArgumentException("No message provided");
@@ -169,7 +168,7 @@ public interface BusPublisher {
public DmaapPublisherWrapper(ProtocolTypeConstants protocol,
List<String> servers, String topic,
String username,
- String password, boolean useHttps) throws IllegalArgumentException {
+ String password, boolean useHttps) {
if (topic == null || topic.isEmpty())
@@ -260,8 +259,7 @@ public interface BusPublisher {
* {@inheritDoc}
*/
@Override
- public boolean send(String partitionId, String message)
- throws IllegalArgumentException {
+ public boolean send(String partitionId, String message) {
if (message == null)
throw new IllegalArgumentException("No message provided");
@@ -322,17 +320,13 @@ public interface BusPublisher {
String dme2RouteOffer = additionalProps.get(DmaapTopicSinkFactory.DME2_ROUTE_OFFER_PROPERTY);
if (environment == null || environment.isEmpty()) {
- throw new IllegalArgumentException("Missing " + PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS +
- "." + topic + PolicyProperties.PROPERTY_DMAAP_DME2_ENVIRONMENT_SUFFIX + " property for DME2 in DMaaP");
+ throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_ENVIRONMENT_SUFFIX);
} if (aftEnvironment == null || aftEnvironment.isEmpty()) {
- throw new IllegalArgumentException("Missing " + PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS +
- "." + topic + PolicyProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX + " property for DME2 in DMaaP");
+ throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX);
} if (latitude == null || latitude.isEmpty()) {
- throw new IllegalArgumentException("Missing " + PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS +
- "." + topic + PolicyProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX + " property for DME2 in DMaaP");
+ throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX);
} if (longitude == null || longitude.isEmpty()) {
- throw new IllegalArgumentException("Missing " + PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS +
- "." + topic + PolicyProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX + " property for DME2 in DMaaP");
+ throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX);
}
if ((dme2Partner == null || dme2Partner.isEmpty()) && (dme2RouteOffer == null || dme2RouteOffer.isEmpty())) {
@@ -381,5 +375,11 @@ public interface BusPublisher {
this.publisher.setProps(props);
}
+
+ private IllegalArgumentException parmException(String topic, String propnm) {
+ return new IllegalArgumentException("Missing " + PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS +
+ "." + topic + propnm + " property for DME2 in DMaaP");
+
+ }
}
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
index f531c441..bdb95e77 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -51,6 +51,12 @@ public interface DroolsController extends Startable, Lockable {
public static final String NO_VERSION = "NO-VERSION";
/**
+ * Factory to track and manage drools controllers
+ */
+ public static final DroolsControllerFactory factory =
+ new IndexedDroolsControllerFactory();
+
+ /**
* get group id
* @return group id
*/
@@ -106,9 +112,7 @@ public interface DroolsController extends Startable, Lockable {
* to the functionality missing (ie. communication infrastructure
* not supported.
*/
- public boolean deliver(TopicSink sink, Object event)
- throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException;
+ public boolean deliver(TopicSink sink, Object event);
/**
*
@@ -133,7 +137,7 @@ public interface DroolsController extends Startable, Lockable {
* @param encodedObject
* @return
*/
- public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) throws IllegalStateException;
+ public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash);
/**
* fetches a class from the model
@@ -141,7 +145,7 @@ public interface DroolsController extends Startable, Lockable {
* @param className the class to fetch
* @return the actual class object, or null if not found
*/
- public Class<?> fetchModelClass(String className) throws IllegalArgumentException;
+ public Class<?> fetchModelClass(String className);
/**
* is this controller Smart?
@@ -164,14 +168,14 @@ public interface DroolsController extends Startable, Lockable {
public void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
List<TopicCoderFilterConfiguration> decoderConfigurations,
List<TopicCoderFilterConfiguration> encoderConfigurations)
- throws IllegalArgumentException, LinkageError;
+ throws LinkageError;
/**
* gets the classnames of facts as well as the current count
* @param sessionName the session name
* @return map of class to count
*/
- public Map<String,Integer> factClassNames(String sessionName) throws IllegalArgumentException;
+ public Map<String,Integer> factClassNames(String sessionName);
/**
* gets the count of facts for a given session
@@ -179,7 +183,7 @@ public interface DroolsController extends Startable, Lockable {
* @return the fact count
* @throws IllegalArgumentException
*/
- public long factCount(String sessionName) throws IllegalArgumentException;
+ public long factCount(String sessionName);
/**
* gets all the facts of a given class for a given session
@@ -208,11 +212,5 @@ public interface DroolsController extends Startable, Lockable {
* halts and permanently releases all resources
* @throws IllegalStateException
*/
- public void halt() throws IllegalStateException;
-
- /**
- * Factory to track and manage drools controllers
- */
- public static final DroolsControllerFactory factory =
- new IndexedDroolsControllerFactory();
+ public void halt();
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java
index 0b9f9887..65c9f334 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -207,7 +207,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
protected List<TopicCoderFilterConfiguration> codersAndFilters
(Properties properties, List<? extends Topic> topicEntities) {
- String PROPERTY_TOPIC_ENTITY_PREFIX;
+ String propertyTopicEntityPrefix;
List<TopicCoderFilterConfiguration>
topics2DecodedClasses2Filters = new ArrayList<>();
@@ -222,19 +222,19 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
CommInfrastructure commInfra = topic.getTopicCommInfrastructure();
if (commInfra == CommInfrastructure.UEB) {
if (isSource) {
- PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + ".";
+ propertyTopicEntityPrefix = PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + ".";
} else {
- PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_UEB_SINK_TOPICS + ".";
+ propertyTopicEntityPrefix = PolicyProperties.PROPERTY_UEB_SINK_TOPICS + ".";
}
} else if (commInfra == CommInfrastructure.DMAAP) {
if (isSource) {
- PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + ".";
+ propertyTopicEntityPrefix = PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + ".";
} else {
- PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + ".";
+ propertyTopicEntityPrefix = PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + ".";
}
} else if (commInfra == CommInfrastructure.NOOP) {
if (!isSource)
- PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_NOOP_SINK_TOPICS + ".";
+ propertyTopicEntityPrefix = PolicyProperties.PROPERTY_NOOP_SINK_TOPICS + ".";
else
continue;
} else {
@@ -249,7 +249,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
// instead of the ones provided in the platform
String customGson = properties.getProperty
- (PROPERTY_TOPIC_ENTITY_PREFIX +
+ (propertyTopicEntityPrefix +
aTopic +
PolicyProperties.PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_GSON_SUFFIX);
@@ -264,7 +264,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
}
String customJackson = properties.getProperty
- (PROPERTY_TOPIC_ENTITY_PREFIX +
+ (propertyTopicEntityPrefix +
aTopic +
PolicyProperties.PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_JACKSON_SUFFIX);
@@ -281,7 +281,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
// 3. second the list of classes associated with each topic
String eventClasses =
- properties.getProperty(PROPERTY_TOPIC_ENTITY_PREFIX + aTopic + PolicyProperties.PROPERTY_TOPIC_EVENTS_SUFFIX);
+ properties.getProperty(propertyTopicEntityPrefix + aTopic + PolicyProperties.PROPERTY_TOPIC_EVENTS_SUFFIX);
if (eventClasses == null || eventClasses.isEmpty()) {
// TODO warn
@@ -299,7 +299,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
// 4. third, for each coder class, get the list of field filters
String filter = properties.getProperty
- (PROPERTY_TOPIC_ENTITY_PREFIX +
+ (propertyTopicEntityPrefix +
aTopic +
PolicyProperties.PROPERTY_TOPIC_EVENTS_SUFFIX +
"." + aClass +
@@ -509,9 +509,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
@Override
public List<DroolsController> inventory() {
- List<DroolsController> controllers =
- new ArrayList<>(this.droolsControllers.values());
- return controllers;
+ return new ArrayList<>(this.droolsControllers.values());
}
@Override
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 8a0073c0..1901526c 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
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -251,11 +251,10 @@ public class MavenDroolsController implements DroolsController {
String customGsonCoderClass = coderConfig.getCustomGsonCoder().getClassContainer();
if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(),
customGsonCoderClass)) {
- logger.error(customGsonCoderClass + " cannot be retrieved");
- throw new IllegalArgumentException(customGsonCoderClass + " cannot be retrieved");
+ throw makeRetrieveEx(customGsonCoderClass);
} else {
if (logger.isInfoEnabled())
- logger.info("CLASS FETCHED " + customGsonCoderClass);
+ logClassFetched(customGsonCoderClass);
}
}
@@ -267,11 +266,10 @@ public class MavenDroolsController implements DroolsController {
String customJacksonCoderClass = coderConfig.getCustomJacksonCoder().getClassContainer();
if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(),
customJacksonCoderClass)) {
- logger.error(customJacksonCoderClass + " cannot be retrieved");
- throw new IllegalArgumentException(customJacksonCoderClass + " cannot be retrieved");
+ throw makeRetrieveEx(customJacksonCoderClass);
} else {
if (logger.isInfoEnabled())
- logger.info("CLASS FETCHED " + customJacksonCoderClass);
+ logClassFetched(customJacksonCoderClass);
}
}
@@ -286,11 +284,10 @@ public class MavenDroolsController implements DroolsController {
if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(),
potentialCodedClass)) {
- logger.error(potentialCodedClass + " cannot be retrieved");
- throw new IllegalArgumentException(potentialCodedClass + " cannot be retrieved");
+ throw makeRetrieveEx(potentialCodedClass);
} else {
if (logger.isInfoEnabled())
- logger.info("CLASS FETCHED " + potentialCodedClass);
+ logClassFetched(potentialCodedClass);
}
if (decoder)
@@ -309,6 +306,24 @@ public class MavenDroolsController implements DroolsController {
}
}
+ /**
+ * Logs an error and makes an exception for an item that cannot be retrieved.
+ * @param itemName
+ * @return a new exception
+ */
+ private IllegalArgumentException makeRetrieveEx(String itemName) {
+ logger.error(itemName + " cannot be retrieved");
+ return new IllegalArgumentException(itemName + " cannot be retrieved");
+ }
+
+ /**
+ * Logs the name of the class that was fetched.
+ * @param className
+ */
+ private void logClassFetched(String className) {
+ logger.info("CLASS FETCHED " + className);
+ }
+
/**
* remove decoders.
@@ -521,8 +536,7 @@ public class MavenDroolsController implements DroolsController {
}
@Override
- public boolean deliver(TopicSink sink, Object event)
- throws UnsupportedOperationException {
+ public boolean deliver(TopicSink sink, Object event) {
if (logger.isInfoEnabled())
logger.info(this + "DELIVER: " + event + " FROM " + this + " TO " + sink);
@@ -665,13 +679,17 @@ public class MavenDroolsController implements DroolsController {
return session;
}
- throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
+ throw invalidSessNameEx(sessionName);
+ }
+
+ private IllegalArgumentException invalidSessNameEx(String sessionName) {
+ return new IllegalArgumentException("Invalid Session Name: " + sessionName);
}
@Override
public Map<String,Integer> factClassNames(String sessionName) {
if (sessionName == null || sessionName.isEmpty())
- throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
+ throw invalidSessNameEx(sessionName);
Map<String,Integer> classNames = new HashMap<>();
@@ -697,7 +715,7 @@ public class MavenDroolsController implements DroolsController {
@Override
public long factCount(String sessionName) {
if (sessionName == null || sessionName.isEmpty())
- throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
+ throw invalidSessNameEx(sessionName);
PolicySession session = getSession(sessionName);
return session.getKieSession().getFactCount();
@@ -706,7 +724,7 @@ public class MavenDroolsController implements DroolsController {
@Override
public List<Object> facts(String sessionName, String className, boolean delete) {
if (sessionName == null || sessionName.isEmpty())
- throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
+ throw invalidSessNameEx(sessionName);
if (className == null || className.isEmpty())
throw new IllegalArgumentException("Invalid Class Name: " + className);
@@ -738,7 +756,7 @@ public class MavenDroolsController implements DroolsController {
@Override
public List<Object> factQuery(String sessionName, String queryName, String queriedEntity, boolean delete, Object... queryParams) {
if (sessionName == null || sessionName.isEmpty())
- throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
+ throw invalidSessNameEx(sessionName);
if (queryName == null || queryName.isEmpty())
throw new IllegalArgumentException("Invalid Query Name: " + queryName);
@@ -779,9 +797,7 @@ public class MavenDroolsController implements DroolsController {
@Override
public Class<?> fetchModelClass(String className) {
- Class<?> modelClass =
- ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className);
- return modelClass;
+ return ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className);
}
/**
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java
index 6dd542c3..245b0b58 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -106,8 +106,8 @@ public class NullDroolsController implements DroolsController {
}
@Override
- public boolean deliver(TopicSink sink, Object event) throws UnsupportedOperationException {
- throw new IllegalStateException(this.getClass().getCanonicalName() + " invoked");
+ public boolean deliver(TopicSink sink, Object event) {
+ throw new IllegalStateException(makeInvokeMsg());
}
@Override
@@ -127,12 +127,12 @@ public class NullDroolsController implements DroolsController {
@Override
public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) {
- throw new IllegalStateException(this.getClass().getCanonicalName() + " invoked");
+ throw new IllegalStateException(makeInvokeMsg());
}
@Override
public Class<?> fetchModelClass(String className) {
- throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked");
+ throw new IllegalArgumentException(makeInvokeMsg());
}
@Override
@@ -151,13 +151,12 @@ public class NullDroolsController implements DroolsController {
public void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
List<TopicCoderFilterConfiguration> decoderConfigurations,
List<TopicCoderFilterConfiguration> encoderConfigurations)
- throws IllegalArgumentException, LinkageError {
- throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked");
+ throws LinkageError {
+ throw new IllegalArgumentException(makeInvokeMsg());
}
@Override
- public Map<String, Integer> factClassNames(String sessionName)
- throws IllegalArgumentException {
+ public Map<String, Integer> factClassNames(String sessionName) {
return new HashMap<>();
}
@@ -177,4 +176,8 @@ public class NullDroolsController implements DroolsController {
boolean delete, Object... queryParams) {
return new ArrayList<>();
}
+
+ private String makeInvokeMsg() {
+ return this.getClass().getCanonicalName() + " invoked";
+ }
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureAPI.java b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureAPI.java
index 9d166f58..d4ebc232 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureAPI.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureAPI.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -28,6 +28,12 @@ import org.onap.policy.drools.utils.OrderedService;
import org.onap.policy.drools.utils.OrderedServiceImpl;
public interface PolicyControllerFeatureAPI extends OrderedService {
+
+ /**
+ * Feature providers implementing this interface
+ */
+ public static final OrderedServiceImpl<PolicyControllerFeatureAPI> providers =
+ new OrderedServiceImpl<PolicyControllerFeatureAPI>(PolicyControllerFeatureAPI.class);
/**
* called before creating a controller with name 'name' and
@@ -212,11 +218,4 @@ public interface PolicyControllerFeatureAPI extends OrderedService {
String topic,
Object event,
boolean success) {return false;}
-
-
- /**
- * Feature providers implementing this interface
- */
- public static final OrderedServiceImpl<PolicyControllerFeatureAPI> providers =
- new OrderedServiceImpl<PolicyControllerFeatureAPI>(PolicyControllerFeatureAPI.class);
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java
index eb65c706..956401ad 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-engine
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -30,7 +30,12 @@ import org.onap.policy.drools.utils.OrderedServiceImpl;
* Policy Engine Feature API.
* Provides Interception Points during the Policy Engine lifecycle.
*/
-public interface PolicyEngineFeatureAPI extends OrderedService {
+public interface PolicyEngineFeatureAPI extends OrderedService {
+ /**
+ * Feature providers implementing this interface
+ */
+ public static final OrderedServiceImpl<PolicyEngineFeatureAPI> providers =
+ new OrderedServiceImpl<>(PolicyEngineFeatureAPI.class);
/**
* intercept before the Policy Engine is commanded to boot.
@@ -39,7 +44,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
* of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
- public default boolean beforeBoot(PolicyEngine engine, String cliArgs[]) {return false;};
+ public default boolean beforeBoot(PolicyEngine engine, String[] cliArgs) {return false;};
/**
* intercept after the Policy Engine is booted.
@@ -193,10 +198,4 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
* lower priority features. False, otherwise.
*/
public default boolean afterShutdown(PolicyEngine engine) {return false;};
-
- /**
- * Feature providers implementing this interface
- */
- public static final OrderedServiceImpl<PolicyEngineFeatureAPI> providers =
- new OrderedServiceImpl<>(PolicyEngineFeatureAPI.class);
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java b/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
index b436ef97..45c5c428 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -43,29 +43,29 @@ public class FileSystemPersistence implements SystemPersistence {
/**
* policy controllers suffix
*/
- public final static String CONTROLLER_SUFFIX_IDENTIFIER = "-controller";
+ public static final String CONTROLLER_SUFFIX_IDENTIFIER = "-controller";
/**
* policy controller properties file suffix
*/
- public final static String PROPERTIES_FILE_CONTROLLER_SUFFIX =
+ public static final String PROPERTIES_FILE_CONTROLLER_SUFFIX =
CONTROLLER_SUFFIX_IDENTIFIER + ".properties";
/**
* policy controller properties file suffix
*/
- public final static String PROPERTIES_FILE_CONTROLLER_BACKUP_SUFFIX =
+ public static final String PROPERTIES_FILE_CONTROLLER_BACKUP_SUFFIX =
CONTROLLER_SUFFIX_IDENTIFIER + ".properties.bak";
/**
* policy engine properties file name
*/
- public final static String PROPERTIES_FILE_ENGINE = "policy-engine.properties";
+ public static final String PROPERTIES_FILE_ENGINE = "policy-engine.properties";
/**
* Installation environment suffix for files
*/
- public final static String ENV_SUFFIX = ".environment";
+ public static final String ENV_SUFFIX = ".environment";
/**
* configuration directory
diff --git a/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java b/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java
index eb1521ba..0d0a33ce 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -34,6 +34,12 @@ public interface SystemPersistence {
public static final String DEFAULT_CONFIGURATION_DIR = "config";
/**
+ * Persistence Manager. For now it is a file-based properties management, In the future, it will
+ * probably be DB based, so manager implementation will change.
+ */
+ public static final SystemPersistence manager = new FileSystemPersistence();
+
+ /**
* sets a configuration directory and ensures it exists
*
* @param configDir configuration directory or null to use the default one
@@ -123,10 +129,4 @@ public interface SystemPersistence {
* @throws IllegalArgumentException if the name does not lead to a properties configuration
*/
public Properties getProperties(String name);
-
- /**
- * Persistence Manager. For now it is a file-based properties management, In the future, it will
- * probably be DB based, so manager implementation will change.
- */
- public static final SystemPersistence manager = new FileSystemPersistence();
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java
index 54466775..d0008f08 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
@@ -39,6 +39,11 @@ import org.slf4j.LoggerFactory;
*/
public interface EventProtocolCoder {
+ /**
+ * singleton reference to the global event protocol coder
+ */
+ public static EventProtocolCoder manager = new MultiplexorEventProtocolCoder();
+
public static class CoderFilters {
/**
@@ -133,8 +138,7 @@ public interface EventProtocolCoder {
JsonProtocolFilter protocolFilter,
CustomGsonCoder customGsonCoder,
CustomJacksonCoder customJacksonCoder,
- int modelClassLoaderHash)
- throws IllegalArgumentException;
+ int modelClassLoaderHash);
/**
* removes all decoders associated with the controller id
@@ -144,7 +148,7 @@ public interface EventProtocolCoder {
*
* @throws IllegalArgumentException if invalid arguments have been provided
*/
- void removeEncoders(String groupId, String artifactId, String topic) throws IllegalArgumentException;
+ void removeEncoders(String groupId, String artifactId, String topic);
/**
* removes decoders associated with the controller id and topic
@@ -154,7 +158,7 @@ public interface EventProtocolCoder {
*
* @throws IllegalArgumentException if invalid arguments have been provided
*/
- public void removeDecoders(String groupId, String artifactId, String topic) throws IllegalArgumentException;
+ public void removeDecoders(String groupId, String artifactId, String topic);
/**
* Given a controller id and a topic, it gives back its filters
@@ -167,8 +171,7 @@ public interface EventProtocolCoder {
*
* @throw IllegalArgumentException if an invalid parameter is passed
*/
- public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic)
- throws IllegalArgumentException;
+ public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic);
/**
@@ -182,8 +185,7 @@ public interface EventProtocolCoder {
*
* @throw IllegalArgumentException if an invalid parameter is passed
*/
- public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic)
- throws IllegalArgumentException;
+ public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic);
/**
* Given a controller id and a topic, it gives back all the decoding configurations
@@ -196,8 +198,7 @@ public interface EventProtocolCoder {
*
* @throw IllegalArgumentException if an invalid parameter is passed
*/
- public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId)
- throws IllegalArgumentException;
+ public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId);
/**
@@ -207,7 +208,7 @@ public interface EventProtocolCoder {
*
* @throws IllegalArgumentException if invalid arguments have been provided
*/
- public List<CoderFilters> getDecoderFilters(String groupId, String artifactId) throws IllegalArgumentException;
+ public List<CoderFilters> getDecoderFilters(String groupId, String artifactId);
/**
@@ -221,8 +222,7 @@ public interface EventProtocolCoder {
*
* @throw IllegalArgumentException if an invalid parameter is passed
*/
- public List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic)
- throws IllegalArgumentException;
+ public List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic);
/**
* gets all encoders associated with the group and artifact ids
@@ -231,7 +231,7 @@ public interface EventProtocolCoder {
*
* @throws IllegalArgumentException if invalid arguments have been provided
*/
- public List<CoderFilters> getEncoderFilters(String groupId, String artifactId) throws IllegalArgumentException;
+ public List<CoderFilters> getEncoderFilters(String groupId, String artifactId);
/**
* Given a controller id, a topic, and a classname, it gives back the classes that implements the decoding
@@ -245,8 +245,7 @@ public interface EventProtocolCoder {
*
* @throw IllegalArgumentException if an invalid parameter is passed
*/
- public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname)
- throws IllegalArgumentException;
+ public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname);
/**
* is there a decoder supported for the controller id and topic
@@ -275,8 +274,7 @@ public interface EventProtocolCoder {
JsonProtocolFilter protocolFilter,
CustomGsonCoder customGsonCoder,
CustomJacksonCoder customJacksonCoder,
- int modelClassLoaderHash)
- throws IllegalArgumentException;
+ int modelClassLoaderHash);
/**
* is there an encoder supported for the controller id and topic
@@ -298,8 +296,7 @@ public interface EventProtocolCoder {
* @return
* @throws IllegalArgumentException invalid arguments passed in
*/
- public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname)
- throws IllegalArgumentException;
+ public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname);
/**
* get encoder based on topic and encoded class
@@ -309,8 +306,7 @@ public interface EventProtocolCoder {
* @return
* @throws IllegalArgumentException invalid arguments passed in
*/
- public List<CoderFilters> getReverseEncoderFilters(String topic, String encodedClass)
- throws IllegalArgumentException;
+ public List<CoderFilters> getReverseEncoderFilters(String topic, String encodedClass);
/**
* gets the identifier of the creator of the encoder
@@ -320,8 +316,7 @@ public interface EventProtocolCoder {
* @return a drools controller
* @throws IllegalArgumentException invalid arguments passed in
*/
- public DroolsController getDroolsController(String topic, Object encodedClass)
- throws IllegalArgumentException;
+ public DroolsController getDroolsController(String topic, Object encodedClass);
/**
* gets the identifier of the creator of the encoder
@@ -331,8 +326,7 @@ public interface EventProtocolCoder {
* @return list of drools controllers
* @throws IllegalArgumentException invalid arguments passed in
*/
- public List<DroolsController> getDroolsControllers(String topic, Object encodedClass)
- throws IllegalArgumentException;
+ public List<DroolsController> getDroolsControllers(String topic, Object encodedClass);
/**
* decode topic's stringified event (json) to corresponding Event Object.
@@ -346,8 +340,7 @@ public interface EventProtocolCoder {
* @throws UnsupportedOperationException if the operation is not supported
* @throws IllegalStateException if the system is in an illegal state
*/
- public Object decode(String groupId, String artifactId, String topic, String json)
- throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException;
+ public Object decode(String groupId, String artifactId, String topic, String json);
/**
* encodes topic's stringified event (json) to corresponding Event Object.
@@ -359,8 +352,7 @@ public interface EventProtocolCoder {
*
* @throws IllegalArgumentException invalid arguments passed in
*/
- public String encode(String groupId, String artifactId, String topic, Object event)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException;
+ public String encode(String groupId, String artifactId, String topic, Object event);
/**
* encodes topic's stringified event (json) to corresponding Event Object.
@@ -371,8 +363,7 @@ public interface EventProtocolCoder {
* @throws IllegalArgumentException invalid arguments passed in
* @throws UnsupportedOperationException operation cannot be performed
*/
- public String encode(String topic, Object event)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException;
+ public String encode(String topic, Object event);
/**
* encodes topic's stringified event (json) to corresponding Event Object.
@@ -384,13 +375,7 @@ public interface EventProtocolCoder {
* @throws IllegalArgumentException invalid arguments passed in
* @throws UnsupportedOperationException operation cannot be performed
*/
- public String encode(String topic, Object event, DroolsController droolsController)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException;
-
- /**
- * singleton reference to the global event protocol coder
- */
- public static EventProtocolCoder manager = new MultiplexorEventProtocolCoder();
+ public String encode(String topic, Object event, DroolsController droolsController);
}
/**
@@ -423,8 +408,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
JsonProtocolFilter protocolFilter,
CustomGsonCoder customGsonCoder,
CustomJacksonCoder customJacksonCoder,
- int modelClassLoaderHash)
- throws IllegalArgumentException {
+ int modelClassLoaderHash) {
logger.info("{}: add-decoder {}:{}:{}:{}:{}:{}:{}:{}", this,
groupId, artifactId, topic, eventClass,
protocolFilter, customGsonCoder, customJacksonCoder,
@@ -442,8 +426,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
JsonProtocolFilter protocolFilter,
CustomGsonCoder customGsonCoder,
CustomJacksonCoder customJacksonCoder,
- int modelClassLoaderHash)
- throws IllegalArgumentException {
+ int modelClassLoaderHash) {
logger.info("{}: add-decoder {}:{}:{}:{}:{}:{}:{}:{}", this,
groupId, artifactId, topic, eventClass,
protocolFilter, customGsonCoder, customJacksonCoder,
@@ -456,8 +439,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public void removeDecoders(String groupId, String artifactId, String topic)
- throws IllegalArgumentException {
+ public void removeDecoders(String groupId, String artifactId, String topic) {
logger.info("{}: remove-decoder {}:{}:{}", this, groupId, artifactId, topic);
this.decoders.remove(groupId, artifactId, topic);
}
@@ -466,8 +448,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public void removeEncoders(String groupId, String artifactId, String topic)
- throws IllegalArgumentException {
+ public void removeEncoders(String groupId, String artifactId, String topic) {
logger.info("{}: remove-encoder {}:{}:{}", this, groupId, artifactId, topic);
this.encoders.remove(groupId, artifactId, topic);
}
@@ -492,8 +473,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public Object decode(String groupId, String artifactId, String topic, String json)
- throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException {
+ public Object decode(String groupId, String artifactId, String topic, String json) {
logger.debug("{}: decode {}:{}:{}:{}", this, groupId, artifactId, topic, json);
return this.decoders.decode(groupId, artifactId, topic, json);
}
@@ -502,8 +482,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public String encode(String groupId, String artifactId, String topic, Object event)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException {
+ public String encode(String groupId, String artifactId, String topic, Object event) {
logger.debug("{}: encode {}:{}:{}:{}", this, groupId, artifactId, topic, event);
return this.encoders.encode(groupId, artifactId, topic, event);
}
@@ -512,8 +491,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public String encode(String topic, Object event)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException {
+ public String encode(String topic, Object event) {
logger.debug("{}: encode {}:{}", this, topic, event);
return this.encoders.encode(topic, event);
}
@@ -522,8 +500,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public String encode(String topic, Object event, DroolsController droolsController)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException {
+ public String encode(String topic, Object event, DroolsController droolsController) {
logger.debug("{}: encode {}:{}:{}", this, topic, event, droolsController);
return this.encoders.encode(topic, event, droolsController);
}
@@ -532,8 +509,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic)
- throws IllegalArgumentException {
+ public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic) {
return this.decoders.getFilters(groupId, artifactId, topic);
}
@@ -541,8 +517,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic)
- throws IllegalArgumentException {
+ public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic) {
Pair<ProtocolCoderToolset,ProtocolCoderToolset> decoderToolsets = this.decoders.getCoders(groupId, artifactId, topic);
if (decoderToolsets == null)
throw new IllegalArgumentException("Decoders not found for " + groupId + ":" + artifactId + ":" + topic);
@@ -554,8 +529,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic)
- throws IllegalArgumentException {
+ public List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic) {
return this.encoders.getFilters(groupId, artifactId, topic);
}
@@ -563,8 +537,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname)
- throws IllegalArgumentException {
+ public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname) {
return this.decoders.getFilters(groupId, artifactId, topic, classname);
}
@@ -572,8 +545,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname)
- throws IllegalArgumentException {
+ public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname) {
return this.encoders.getFilters(groupId, artifactId, topic, classname);
}
@@ -581,7 +553,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public List<CoderFilters> getReverseEncoderFilters(String topic, String encodedClass) throws IllegalArgumentException {
+ public List<CoderFilters> getReverseEncoderFilters(String topic, String encodedClass) {
return this.encoders.getReverseFilters(topic, encodedClass);
}
@@ -595,8 +567,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* @throws IllegalArgumentException if invalid input
*/
@Override
- public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId)
- throws IllegalArgumentException {
+ public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId) {
List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> decoderToolsets = this.decoders.getCoders(groupId, artifactId);
if (decoderToolsets == null)
@@ -614,7 +585,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public List<CoderFilters> getDecoderFilters(String groupId, String artifactId) throws IllegalArgumentException {
+ public List<CoderFilters> getDecoderFilters(String groupId, String artifactId) {
return this.decoders.getFilters(groupId, artifactId);
}
@@ -623,7 +594,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public List<CoderFilters> getEncoderFilters(String groupId, String artifactId) throws IllegalArgumentException {
+ public List<CoderFilters> getEncoderFilters(String groupId, String artifactId) {
return this.encoders.getFilters(groupId, artifactId);
}
@@ -631,7 +602,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public DroolsController getDroolsController(String topic, Object encodedClass) throws IllegalArgumentException {
+ public DroolsController getDroolsController(String topic, Object encodedClass) {
return this.encoders.getDroolsController(topic, encodedClass);
}
@@ -639,7 +610,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* {@inheritDoc}
*/
@Override
- public List<DroolsController> getDroolsControllers(String topic, Object encodedClass) throws IllegalArgumentException {
+ public List<DroolsController> getDroolsControllers(String topic, Object encodedClass) {
return this.encoders.getDroolsControllers(topic, encodedClass);
}
@@ -660,6 +631,16 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
* class and best fitted json parsing tools.
*/
abstract class GenericEventProtocolCoder {
+ private static final String INVALID_ARTIFACT_ID_MSG = "Invalid artifact id";
+
+ private static final String INVALID_GROUP_ID_MSG = "Invalid group id";
+
+ private static final String INVALID_TOPIC_MSG = "Invalid Topic";
+
+ private static final String UNSUPPORTED_MSG = "Unsupported";
+
+ private static final String MISSING_CLASS = "class must be provided";
+
private static Logger logger = LoggerFactory.getLogger(GenericEventProtocolCoder.class);
/**
@@ -702,17 +683,16 @@ abstract class GenericEventProtocolCoder {
JsonProtocolFilter protocolFilter,
CustomGsonCoder customGsonCoder,
CustomJacksonCoder customJacksonCoder,
- int modelClassLoaderHash)
- throws IllegalArgumentException {
+ int modelClassLoaderHash) {
if (groupId == null || groupId.isEmpty()) {
- throw new IllegalArgumentException("Invalid group id");
+ throw new IllegalArgumentException(INVALID_GROUP_ID_MSG);
}
if (artifactId == null || artifactId.isEmpty())
- throw new IllegalArgumentException("Invalid artifact id");
+ throw new IllegalArgumentException(INVALID_ARTIFACT_ID_MSG);
if (topic == null || topic.isEmpty())
- throw new IllegalArgumentException("Invalid Topic");
+ throw new IllegalArgumentException(INVALID_TOPIC_MSG);
if (eventClass == null) {
throw new IllegalArgumentException("Invalid Event Class");
@@ -841,17 +821,16 @@ abstract class GenericEventProtocolCoder {
* @param topic topic
* @throws IllegalArgumentException if invalid input
*/
- public void remove(String groupId, String artifactId, String topic)
- throws IllegalArgumentException {
+ public void remove(String groupId, String artifactId, String topic) {
if (groupId == null || groupId.isEmpty())
- throw new IllegalArgumentException("Invalid group id");
+ throw new IllegalArgumentException(INVALID_GROUP_ID_MSG);
if (artifactId == null || artifactId.isEmpty())
- throw new IllegalArgumentException("Invalid artifact id");
+ throw new IllegalArgumentException(INVALID_ARTIFACT_ID_MSG);
if (topic == null || topic.isEmpty())
- throw new IllegalArgumentException("Invalid Topic");
+ throw new IllegalArgumentException(INVALID_TOPIC_MSG);
String key = this.codersKey(groupId, artifactId, topic);
@@ -899,13 +878,13 @@ abstract class GenericEventProtocolCoder {
public boolean isCodingSupported(String groupId, String artifactId, String topic) {
if (groupId == null || groupId.isEmpty())
- throw new IllegalArgumentException("Invalid group id");
+ throw new IllegalArgumentException(INVALID_GROUP_ID_MSG);
if (artifactId == null || artifactId.isEmpty())
- throw new IllegalArgumentException("Invalid artifact id");
+ throw new IllegalArgumentException(INVALID_ARTIFACT_ID_MSG);
if (topic == null || topic.isEmpty())
- throw new IllegalArgumentException("Invalid Topic");
+ throw new IllegalArgumentException(INVALID_TOPIC_MSG);
String key = this.codersKey(groupId, artifactId, topic);
synchronized(this) {
@@ -924,8 +903,7 @@ abstract class GenericEventProtocolCoder {
* @throws IllegalArgumentException if invalid argument is provided
* @throws UnsupportedOperationException if the operation cannot be performed
*/
- public Object decode(String groupId, String artifactId, String topic, String json)
- throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException {
+ public Object decode(String groupId, String artifactId, String topic, String json) {
if (!isCodingSupported(groupId, artifactId, topic))
throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic) + " for encoding");
@@ -974,8 +952,7 @@ abstract class GenericEventProtocolCoder {
* @throws IllegalArgumentException if invalid argument is provided
* @throws UnsupportedOperationException if the operation cannot be performed
*/
- public String encode(String groupId, String artifactId, String topic, Object event)
- throws IllegalArgumentException, UnsupportedOperationException {
+ public String encode(String groupId, String artifactId, String topic, Object event) {
if (!isCodingSupported(groupId, artifactId, topic))
throw new IllegalArgumentException
@@ -998,8 +975,7 @@ abstract class GenericEventProtocolCoder {
* @throws IllegalArgumentException if invalid argument is provided
* @throws UnsupportedOperationException if the operation cannot be performed
*/
- protected String encodeInternal(String key, Object event)
- throws IllegalArgumentException, UnsupportedOperationException {
+ protected String encodeInternal(String key, Object event) {
logger.debug("{}: encode for {}: {}", this, key, event);
@@ -1045,8 +1021,7 @@ abstract class GenericEventProtocolCoder {
* @throws IllegalArgumentException if invalid argument is provided
* @throws UnsupportedOperationException if the operation cannot be performed
*/
- public String encode(String topic, Object event)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException {
+ public String encode(String topic, Object event) {
if (event == null)
throw new IllegalArgumentException("Invalid encoded class");
@@ -1074,8 +1049,7 @@ abstract class GenericEventProtocolCoder {
* @throws IllegalArgumentException if invalid argument is provided
* @throws UnsupportedOperationException if the operation cannot be performed
*/
- public String encode(String topic, Object encodedClass, DroolsController droolsController)
- throws IllegalArgumentException, IllegalArgumentException, UnsupportedOperationException {
+ public String encode(String topic, Object encodedClass, DroolsController droolsController) {
if (encodedClass == null)
throw new IllegalArgumentException("Invalid encoded class");
@@ -1095,8 +1069,7 @@ abstract class GenericEventProtocolCoder {
* @throws IllegalStateException
* @throws IllegalArgumentException
*/
- protected List<DroolsController> droolsCreators(String topic, Object encodedClass)
- throws IllegalStateException, IllegalArgumentException {
+ protected List<DroolsController> droolsCreators(String topic, Object encodedClass) {
List<DroolsController> droolsControllers = new ArrayList<>();
@@ -1152,8 +1125,7 @@ abstract class GenericEventProtocolCoder {
* @return list of coders
* @throws IllegalArgumentException if invalid input
*/
- public List<CoderFilters> getFilters(String groupId, String artifactId, String topic)
- throws IllegalArgumentException {
+ public List<CoderFilters> getFilters(String groupId, String artifactId, String topic) {
if (!isCodingSupported(groupId, artifactId, topic))
throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic));
@@ -1172,15 +1144,13 @@ abstract class GenericEventProtocolCoder {
* @return list of coders
* @throws IllegalArgumentException if invalid input
*/
- public Pair<ProtocolCoderToolset,ProtocolCoderToolset> getCoders(String groupId, String artifactId, String topic)
- throws IllegalArgumentException {
+ public Pair<ProtocolCoderToolset,ProtocolCoderToolset> getCoders(String groupId, String artifactId, String topic) {
if (!isCodingSupported(groupId, artifactId, topic))
throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic));
String key = this.codersKey(groupId, artifactId, topic);
- Pair<ProtocolCoderToolset,ProtocolCoderToolset> coderTools = coders.get(key);
- return coderTools;
+ return coders.get(key);
}
/**
@@ -1191,14 +1161,13 @@ abstract class GenericEventProtocolCoder {
* @return list of coders
* @throws IllegalArgumentException if invalid input
*/
- public List<CoderFilters> getFilters(String groupId, String artifactId)
- throws IllegalArgumentException {
+ public List<CoderFilters> getFilters(String groupId, String artifactId) {
if (groupId == null || groupId.isEmpty())
- throw new IllegalArgumentException("Invalid group id");
+ throw new IllegalArgumentException(INVALID_GROUP_ID_MSG);
if (artifactId == null || artifactId.isEmpty())
- throw new IllegalArgumentException("Invalid artifact id");
+ throw new IllegalArgumentException(INVALID_ARTIFACT_ID_MSG);
String key = this.codersKey(groupId, artifactId, "");
@@ -1220,14 +1189,13 @@ abstract class GenericEventProtocolCoder {
* @return list of coders
* @throws IllegalArgumentException if invalid input
*/
- public List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> getCoders(String groupId, String artifactId)
- throws IllegalArgumentException {
+ public List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> getCoders(String groupId, String artifactId) {
if (groupId == null || groupId.isEmpty())
- throw new IllegalArgumentException("Invalid group id");
+ throw new IllegalArgumentException(INVALID_GROUP_ID_MSG);
if (artifactId == null || artifactId.isEmpty())
- throw new IllegalArgumentException("Invalid artifact id");
+ throw new IllegalArgumentException(INVALID_ARTIFACT_ID_MSG);
String key = this.codersKey(groupId, artifactId, "");
@@ -1252,8 +1220,7 @@ abstract class GenericEventProtocolCoder {
* @return list of coders
* @throws IllegalArgumentException if invalid input
*/
- public CoderFilters getFilters(String groupId, String artifactId, String topic, String classname)
- throws IllegalArgumentException {
+ public CoderFilters getFilters(String groupId, String artifactId, String topic, String classname) {
if (!isCodingSupported(groupId, artifactId, topic))
throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic));
@@ -1274,14 +1241,13 @@ abstract class GenericEventProtocolCoder {
* @return
* @throws IllegalArgumentException
*/
- public List<CoderFilters> getReverseFilters(String topic, String codedClass)
- throws IllegalArgumentException {
+ public List<CoderFilters> getReverseFilters(String topic, String codedClass) {
if (topic == null || topic.isEmpty())
- throw new IllegalArgumentException("Unsupported");
+ throw new IllegalArgumentException(UNSUPPORTED_MSG);
if (codedClass == null)
- throw new IllegalArgumentException("class must be provided");
+ throw new IllegalArgumentException(MISSING_CLASS);
String key = this.reverseCodersKey(topic, codedClass);
List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> toolsets = this.reverseCoders.get(key);
@@ -1305,14 +1271,13 @@ abstract class GenericEventProtocolCoder {
* @return
* @throws IllegalArgumentException
*/
- DroolsController getDroolsController(String topic, Object fact)
- throws IllegalArgumentException {
+ DroolsController getDroolsController(String topic, Object fact) {
if (topic == null || topic.isEmpty())
- throw new IllegalArgumentException("Unsupported");
+ throw new IllegalArgumentException(UNSUPPORTED_MSG);
if (fact == null)
- throw new IllegalArgumentException("class must be provided");
+ throw new IllegalArgumentException(MISSING_CLASS);
List<DroolsController> droolsControllers = droolsCreators(topic, fact);
@@ -1335,14 +1300,13 @@ abstract class GenericEventProtocolCoder {
* @return
* @throws IllegalArgumentException
*/
- List<DroolsController> getDroolsControllers(String topic, Object fact)
- throws IllegalArgumentException {
+ List<DroolsController> getDroolsControllers(String topic, Object fact) {
if (topic == null || topic.isEmpty())
- throw new IllegalArgumentException("Unsupported");
+ throw new IllegalArgumentException(UNSUPPORTED_MSG);
if (fact == null)
- throw new IllegalArgumentException("class must be provided");
+ throw new IllegalArgumentException(MISSING_CLASS);
List<DroolsController> droolsControllers = droolsCreators(topic, fact);
if (droolsControllers.size() > 1) {
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java
index c5f82a47..a5902d66 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
@@ -37,6 +37,7 @@ import com.google.gson.JsonParser;
*/
public class JsonProtocolFilter {
+ private static final String MISSING_RULE_NAME = "no rule name provided";
/**
* Logger
*/
@@ -128,35 +129,11 @@ public class JsonProtocolFilter {
protected List<FilterRule> rules = new CopyOnWriteArrayList<>();
/**
- *
- * @param rawFilters raw filter initialization
- *
- * @throws IllegalArgumentException an invalid input has been provided
- */
- public static JsonProtocolFilter fromRawFilters(List<Pair<String, String>> rawFilters)
- throws IllegalArgumentException {
-
- if (rawFilters == null) {
- throw new IllegalArgumentException("No raw filters provided");
- }
-
- List<FilterRule> filters = new ArrayList<>();
- for (Pair<String, String> filterPair: rawFilters) {
- if (filterPair.first() == null || filterPair.first().isEmpty()) {
- continue;
- }
-
- filters.add(new FilterRule(filterPair.first(), filterPair.second()));
- }
- return new JsonProtocolFilter(filters);
- }
-
- /**
* Create a Protocol Filter
*
* @throws IllegalArgumentException an invalid input has been provided
*/
- public JsonProtocolFilter() throws IllegalArgumentException {}
+ public JsonProtocolFilter() {}
/**
*
@@ -164,7 +141,7 @@ public class JsonProtocolFilter {
*
* @throws IllegalArgumentException an invalid input has been provided
*/
- public JsonProtocolFilter(List<FilterRule> filters) throws IllegalArgumentException {
+ public JsonProtocolFilter(List<FilterRule> filters) {
List<FilterRule> temp = new ArrayList<>();
for (FilterRule rule : filters) {
if (rule.getName() == null || rule.getName().isEmpty()) {
@@ -180,6 +157,29 @@ public class JsonProtocolFilter {
this.rules.addAll(temp);
}
+
+ /**
+ *
+ * @param rawFilters raw filter initialization
+ *
+ * @throws IllegalArgumentException an invalid input has been provided
+ */
+ public static JsonProtocolFilter fromRawFilters(List<Pair<String, String>> rawFilters) {
+
+ if (rawFilters == null) {
+ throw new IllegalArgumentException("No raw filters provided");
+ }
+
+ List<FilterRule> filters = new ArrayList<>();
+ for (Pair<String, String> filterPair: rawFilters) {
+ if (filterPair.first() == null || filterPair.first().isEmpty()) {
+ continue;
+ }
+
+ filters.add(new FilterRule(filterPair.first(), filterPair.second()));
+ }
+ return new JsonProtocolFilter(filters);
+ }
/**
* are there any filters?
@@ -198,7 +198,7 @@ public class JsonProtocolFilter {
*
* @throws IllegalArgumentException an invalid input has been provided
*/
- public boolean accept(JsonElement json) throws IllegalArgumentException {
+ public boolean accept(JsonElement json) {
if (json == null) {
throw new IllegalArgumentException("no JSON provided");
}
@@ -248,7 +248,7 @@ public class JsonProtocolFilter {
*
* @throws IllegalArgumentException an invalid input has been provided
*/
- public boolean accept(String json) throws IllegalArgumentException {
+ public boolean accept(String json) {
if (json == null || json.isEmpty()) {
throw new IllegalArgumentException("no JSON provided");
}
@@ -279,7 +279,7 @@ public class JsonProtocolFilter {
public List<FilterRule> getRules(String name) {
if (name == null || name.isEmpty())
- throw new IllegalArgumentException("no rule name provided");
+ throw new IllegalArgumentException(MISSING_RULE_NAME);
ArrayList<FilterRule> temp = new ArrayList<>();
for (FilterRule rule : this.rules) {
@@ -300,7 +300,7 @@ public class JsonProtocolFilter {
public void deleteRules(String name) {
if (name == null || name.isEmpty())
- throw new IllegalArgumentException("no rule name provided");
+ throw new IllegalArgumentException(MISSING_RULE_NAME);
List<FilterRule> temp = new ArrayList<>();
for (FilterRule rule : this.rules) {
@@ -313,7 +313,7 @@ public class JsonProtocolFilter {
public void deleteRule(String name, String regex) {
if (name == null || name.isEmpty())
- throw new IllegalArgumentException("no rule name provided");
+ throw new IllegalArgumentException(MISSING_RULE_NAME);
String nonNullRegex = regex;
if (regex == null || regex.isEmpty()) {
@@ -332,7 +332,7 @@ public class JsonProtocolFilter {
public void addRule(String name, String regex) {
if (name == null || name.isEmpty())
- throw new IllegalArgumentException("no rule name provided");
+ throw new IllegalArgumentException(MISSING_RULE_NAME);
String nonNullRegex = regex;
if (regex == null || regex.isEmpty()) {
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
index cb039ee5..7ee8b08a 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
@@ -20,21 +20,6 @@
package org.onap.policy.drools.protocol.coders;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParseException;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonPrimitive;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
@@ -44,6 +29,7 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
+
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomCoder;
@@ -52,6 +38,21 @@ import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.Cust
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+
/**
* Protocol Coding/Decoding Toolset
*/
@@ -109,7 +110,7 @@ public abstract class ProtocolCoderToolset {
*/
public ProtocolCoderToolset(String topic, String controllerId, String groupId, String artifactId,
String codedClass, JsonProtocolFilter filters, CustomCoder customCoder,
- int modelClassLoaderHash) throws IllegalArgumentException {
+ int modelClassLoaderHash) {
if (topic == null || controllerId == null || groupId == null || artifactId == null
|| codedClass == null || filters == null || topic.isEmpty() || controllerId.isEmpty()) {
@@ -243,8 +244,7 @@ public abstract class ProtocolCoderToolset {
* @throws UnsupportedOperationException can't filter
* @throws IllegalArgumentException invalid input
*/
- protected CoderFilters filter(String json)
- throws UnsupportedOperationException, IllegalArgumentException, IllegalStateException {
+ protected CoderFilters filter(String json) {
// 1. Get list of decoding classes for this controller Id and topic
@@ -297,8 +297,7 @@ public abstract class ProtocolCoderToolset {
* @throws IllegalArgumentException if an invalid parameter has been received
* @throws UnsupportedOperationException if parsing into POJO is not possible
*/
- public abstract Object decode(String json)
- throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException;
+ public abstract Object decode(String json);
/**
* Encodes a POJO object into a JSON String
@@ -308,8 +307,7 @@ public abstract class ProtocolCoderToolset {
* @throws IllegalArgumentException if an invalid parameter has been received
* @throws UnsupportedOperationException if parsing into POJO is not possible
*/
- public abstract String encode(Object event)
- throws IllegalArgumentException, UnsupportedOperationException;
+ public abstract String encode(Object event);
@Override
public String toString() {
@@ -328,7 +326,11 @@ public abstract class ProtocolCoderToolset {
* Tools used for encoding/decoding using Jackson
*/
class JacksonProtocolCoderToolset extends ProtocolCoderToolset {
- private static Logger logger = LoggerFactory.getLogger(JacksonProtocolCoderToolset.class);
+ private static final String WARN_FETCH_FAILED = "{}: cannot fetch application class {}";
+private static final String WARN_FETCH_FAILED_BECAUSE = "{}: cannot fetch application class {} because of {}";
+private static final String FETCH_FAILED = "cannot fetch application class ";
+private static final String ENCODE_FAILED = "event cannot be encoded";
+private static Logger logger = LoggerFactory.getLogger(JacksonProtocolCoderToolset.class);
/**
* decoder
*/
@@ -381,8 +383,7 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset {
* {@inheritDoc}
*/
@Override
- public Object decode(String json)
- throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException {
+ public Object decode(String json) {
// 0. Use custom coder if available
@@ -408,21 +409,20 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset {
try {
decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass());
if (decoderClass == null) {
- logger.warn("{}: cannot fetch application class {}", this, decoderFilter.getCodedClass());
+ logger.warn(WARN_FETCH_FAILED, this, decoderFilter.getCodedClass());
throw new IllegalStateException(
- "cannot fetch application class " + decoderFilter.getCodedClass());
+ FETCH_FAILED + decoderFilter.getCodedClass());
}
} catch (final Exception e) {
- logger.warn("{}: cannot fetch application class {} because of {}", this,
+ logger.warn(WARN_FETCH_FAILED_BECAUSE, this,
decoderFilter.getCodedClass(), e.getMessage());
throw new UnsupportedOperationException(
- "cannot fetch application class " + decoderFilter.getCodedClass(), e);
+ FETCH_FAILED + decoderFilter.getCodedClass(), e);
}
try {
- final Object fact = this.decoder.readValue(json, decoderClass);
- return fact;
+ return this.decoder.readValue(json, decoderClass);
} catch (final Exception e) {
logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(),
e.getMessage(), e);
@@ -435,8 +435,7 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset {
* {@inheritDoc}
*/
@Override
- public String encode(Object event)
- throws IllegalArgumentException, UnsupportedOperationException {
+ public String encode(Object event) {
// 0. Use custom coder if available
@@ -446,11 +445,10 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset {
}
try {
- final String encodedEvent = this.encoder.writeValueAsString(event);
- return encodedEvent;
+ return this.encoder.writeValueAsString(event);
} catch (final JsonProcessingException e) {
logger.error("{} cannot encode {} because of {}", this, event, e.getMessage(), e);
- throw new UnsupportedOperationException("event cannot be encoded");
+ throw new UnsupportedOperationException(ENCODE_FAILED);
}
}
@@ -491,7 +489,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> {
@Override
public ZonedDateTime deserialize(JsonElement element, Type type,
- JsonDeserializationContext context) throws JsonParseException {
+ JsonDeserializationContext context) {
try {
return ZonedDateTime.parse(element.getAsString(), format);
} catch (final Exception e) {
@@ -511,8 +509,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
implements JsonSerializer<Instant>, JsonDeserializer<Instant> {
@Override
- public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
- throws JsonParseException {
+ public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
return Instant.ofEpochMilli(json.getAsLong());
}
@@ -578,8 +575,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
* {@inheritDoc}
*/
@Override
- public Object decode(String json)
- throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException {
+ public Object decode(String json) {
final DroolsController droolsController =
DroolsController.factory.get(this.groupId, this.artifactId, "");
@@ -617,8 +613,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
final Object gsonObject = gsonField.get(null);
final Method fromJsonMethod = gsonObject.getClass().getDeclaredMethod("fromJson",
new Class[] {String.class, Class.class});
- final Object fact = fromJsonMethod.invoke(gsonObject, json, decoderClass);
- return fact;
+ return fromJsonMethod.invoke(gsonObject, json, decoderClass);
} catch (final Exception e) {
logger.warn("{}: cannot fetch application class {} because of {}", this,
decoderFilter.getCodedClass(), e.getMessage());
@@ -627,8 +622,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
}
} else {
try {
- final Object fact = this.decoder.fromJson(json, decoderClass);
- return fact;
+ return this.decoder.fromJson(json, decoderClass);
} catch (final Exception e) {
logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(),
e.getMessage(), e);
@@ -644,8 +638,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
* {@inheritDoc}
*/
@Override
- public String encode(Object event)
- throws IllegalArgumentException, UnsupportedOperationException {
+ public String encode(Object event) {
if (this.customCoder != null) {
try {
@@ -657,8 +650,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
final Object gsonObject = gsonField.get(null);
final Method toJsonMethod =
gsonObject.getClass().getDeclaredMethod("toJson", new Class[] {Object.class});
- final String encodedJson = (String) toJsonMethod.invoke(gsonObject, event);
- return encodedJson;
+ return (String) toJsonMethod.invoke(gsonObject, event);
} catch (final Exception e) {
logger.warn("{} cannot custom-encode {} because of {}", this, event, e.getMessage(), e);
throw new UnsupportedOperationException("event cannot be encoded", e);
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java
index 93737267..7c1b128f 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -28,7 +28,7 @@ public class TopicCoderFilterConfiguration {
* Custom coder, contains class and static field to access parser that the controller
* desires to use instead of the framework provided parser
*/
- public static abstract class CustomCoder {
+ public abstract static class CustomCoder {
protected String className;
protected String staticCoderField;
@@ -41,7 +41,7 @@ public class TopicCoderFilterConfiguration {
*
* @param rawCustomCoder with format: <class-containing-custom-coder>,<static-coder-field>
*/
- public CustomCoder(String rawCustomCoder) throws IllegalArgumentException {
+ public CustomCoder(String rawCustomCoder) {
if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) {
this.className = rawCustomCoder.substring(0,rawCustomCoder.indexOf(","));
@@ -62,7 +62,7 @@ public class TopicCoderFilterConfiguration {
* @param classContainer
* @param staticCoderField
*/
- public CustomCoder(String className, String staticCoderField) throws IllegalArgumentException {
+ public CustomCoder(String className, String staticCoderField) {
if (className == null || className.isEmpty()) {
throw new IllegalArgumentException("No classname to create CustomCoder cannot be created");
}
@@ -120,7 +120,7 @@ public class TopicCoderFilterConfiguration {
super(className, staticCoderField);
}
- public CustomGsonCoder(String customGson) throws IllegalArgumentException {
+ public CustomGsonCoder(String customGson) {
super(customGson);
}
@@ -139,7 +139,7 @@ public class TopicCoderFilterConfiguration {
super(className, staticCoderField);
}
- public CustomJacksonCoder(String customJackson) throws IllegalArgumentException {
+ public CustomJacksonCoder(String customJackson) {
super(customJackson);
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java
index 845c4944..62b66611 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -68,7 +68,7 @@ public class ControllerConfiguration {
private DroolsConfiguration drools;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<>();
- protected final static Object NOT_FOUND_VALUE = new Object();
+ protected static final Object NOT_FOUND_VALUE = new Object();
/**
* No args constructor for use in serialization
@@ -259,7 +259,7 @@ public class ControllerConfiguration {
if (other == this) {
return true;
}
- if ((other instanceof ControllerConfiguration) == false) {
+ if (!(other instanceof ControllerConfiguration)) {
return false;
}
ControllerConfiguration rhs = ((ControllerConfiguration) other);
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java
index e822d88e..cac4f565 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -64,7 +64,7 @@ public class DroolsConfiguration {
private String version;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<>();
- protected final static Object NOT_FOUND_VALUE = new Object();
+ protected static final Object NOT_FOUND_VALUE = new Object();
/**
* No args constructor for use in serialization
@@ -257,7 +257,7 @@ public class DroolsConfiguration {
if (other == this) {
return true;
}
- if ((other instanceof DroolsConfiguration) == false) {
+ if (!(other instanceof DroolsConfiguration)) {
return false;
}
DroolsConfiguration rhs = ((DroolsConfiguration) other);
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java
index c7a227b1..29888bbb 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -70,7 +70,7 @@ public class PdpdConfiguration {
private List<ControllerConfiguration> controllers = new ArrayList<>();
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<>();
- protected final static Object NOT_FOUND_VALUE = new Object();
+ protected static final Object NOT_FOUND_VALUE = new Object();
/**
* No args constructor for use in serialization
@@ -197,8 +197,7 @@ public class PdpdConfiguration {
return this;
}
- @SuppressWarnings("unchecked")
- protected boolean declaredProperty(String name, Object value) {
+ protected boolean declaredProperty(String name, Object value) {
switch (name) {
case "requestID":
callSetRequestId(value);
@@ -262,7 +261,7 @@ public class PdpdConfiguration {
if (other == this) {
return true;
}
- if ((other instanceof PdpdConfiguration) == false) {
+ if (!(other instanceof PdpdConfiguration)) {
return false;
}
PdpdConfiguration rhs = (PdpdConfiguration) other;
@@ -285,7 +284,8 @@ public class PdpdConfiguration {
}
}
- public void callSetControllers(Object value) {
+ @SuppressWarnings("unchecked")
+ public void callSetControllers(Object value) {
if (value instanceof List) {
setControllers((List<ControllerConfiguration> ) value);
} else {
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 25f378a7..cd1edca5 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
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -1816,7 +1816,7 @@ public class RestManager {
return Response.status(Status.OK).entity(source).build();
else
return Response.status(Status.NOT_ACCEPTABLE)
- .entity(new Error("cannot perform operation on " + topic)).build();
+ .entity(makeTopicOperError(topic)).build();
}
@DELETE
@@ -1833,7 +1833,11 @@ public class RestManager {
return Response.status(Status.OK).entity(source).build();
else
return Response.status(Status.NOT_ACCEPTABLE)
- .entity(new Error("cannot perform operation on " + topic)).build();
+ .entity(makeTopicOperError(topic)).build();
+ }
+
+ private Error makeTopicOperError(String topic) {
+ return new Error("cannot perform operation on " + topic);
}
@GET
@@ -1858,7 +1862,7 @@ public class RestManager {
return Response.status(Status.OK).entity(source).build();
else
return Response.status(Status.NOT_ACCEPTABLE)
- .entity(new Error("cannot perform operation on " + topic)).build();
+ .entity(makeTopicOperError(topic)).build();
}
@DELETE
@@ -1875,7 +1879,7 @@ public class RestManager {
return Response.status(Status.OK).entity(source).build();
else
return Response.status(Status.SERVICE_UNAVAILABLE)
- .entity(new Error("cannot perform operation on " + topic)).build();
+ .entity(makeTopicOperError(topic)).build();
}
@PUT
@@ -1904,23 +1908,25 @@ public class RestManager {
return Response.status(Status.NOT_ACCEPTABLE)
.entity(new Error("Failure to inject event over " + topic)).build();
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", this, topic,
- e.getMessage(), e);
+ logNoUebEncoder(topic, e);
return Response.status(Response.Status.NOT_FOUND).entity(new Error(topic + " not found"))
.build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", this, topic,
- e.getMessage(), e);
+ logNoUebEncoder(topic, e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
.entity(new Error(topic + " not acceptable due to current state")).build();
} catch (final Exception e) {
- logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", this, topic,
- e.getMessage(), e);
+ logNoUebEncoder(topic, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(new Error(e.getMessage())).build();
}
}
+ private void logNoUebEncoder(String topic, Exception ex) {
+ logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", this, topic,
+ ex.getMessage(), ex);
+ }
+
@PUT
@Path("engine/topics/sources/dmaap/{topic}/events")
@Consumes(MediaType.TEXT_PLAIN)
@@ -1948,23 +1954,25 @@ public class RestManager {
return Response.status(Status.NOT_ACCEPTABLE)
.entity(new Error("Failure to inject event over " + topic)).build();
} catch (final IllegalArgumentException e) {
- logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", this, topic,
- e.getMessage(), e);
+ logNoDmaapEncoder(topic, e);
return Response.status(Response.Status.NOT_FOUND).entity(new Error(topic + " not found"))
.build();
} catch (final IllegalStateException e) {
- logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", this, topic,
- e.getMessage(), e);
+ logNoDmaapEncoder(topic, e);
return Response.status(Response.Status.NOT_ACCEPTABLE)
.entity(new Error(topic + " not acceptable due to current state")).build();
} catch (final Exception e) {
- logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", this, topic,
- e.getMessage(), e);
+ logNoDmaapEncoder(topic, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(new Error(e.getMessage())).build();
}
}
+ private void logNoDmaapEncoder(String topic, Exception ex) {
+ logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", this, topic,
+ ex.getMessage(), ex);
+ }
+
@GET
@Path("engine/tools/uuid")
@ApiOperation(value = "Produces an UUID", notes = "UUID generation utility")
@@ -2122,18 +2130,18 @@ public class RestManager {
* Generic Error Reporting class
*/
public static class Error {
- private String error;
+ private String msg;
- public Error(String error) {
- this.setError(error);
+ public Error(String msg) {
+ this.setError(msg);
}
public String getError() {
- return error;
+ return msg;
}
- public void setError(String error) {
- this.error = error;
+ public void setError(String msg) {
+ this.msg = msg;
}
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/Main.java b/policy-management/src/main/java/org/onap/policy/drools/system/Main.java
index 61719312..314bbc04 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/Main.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/Main.java
@@ -58,7 +58,7 @@ public class Main {
* @param args program arguments
* @throws IOException
*/
- public static void main(String args[]) {
+ public static void main(String[] args) {
/* logging defaults */
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java
index e6e1ca7e..5324937e 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -41,6 +41,12 @@ import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
public interface PolicyController extends Startable, Lockable {
/**
+ * Factory that tracks and manages Policy Controllers
+ */
+ public static PolicyControllerFactory factory =
+ new IndexedPolicyControllerFactory();
+
+ /**
* name of this Policy Controller
*/
public String getName();
@@ -91,20 +97,12 @@ public interface PolicyController extends Startable, Lockable {
* not supported.
*/
public boolean deliver(CommInfrastructure busType, String topic,
- Object event)
- throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException;
+ Object event);
/**
* halts and permanently releases all resources
* @throws IllegalStateException
*/
- public void halt() throws IllegalStateException;
-
- /**
- * Factory that tracks and manages Policy Controllers
- */
- public static PolicyControllerFactory factory =
- new IndexedPolicyControllerFactory();
+ public void halt();
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java
index 8c188c0b..c5787dda 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -50,8 +50,7 @@ public interface PolicyControllerFactory {
*
* @throws IllegalArgumentException invalid values provided in properties
*/
- public PolicyController build(String name, Properties properties)
- throws IllegalArgumentException;
+ public PolicyController build(String name, Properties properties);
/**
* patches (updates) a controller from a critical configuration update.
@@ -82,8 +81,7 @@ public interface PolicyControllerFactory {
* @throws IllegalArgumentException
* @throws IllegalStateException
*/
- public PolicyController get(DroolsController droolsController)
- throws IllegalArgumentException, IllegalStateException;
+ public PolicyController get(DroolsController droolsController);
/**
* Makes the Policy Controller identified by controllerName not operational, but
@@ -92,7 +90,7 @@ public interface PolicyControllerFactory {
* @param controllerName name of the policy controller
* @throws IllegalArgumentException invalid arguments
*/
- public void shutdown(String controllerName) throws IllegalArgumentException;;
+ public void shutdown(String controllerName);
/**
* Makes the Policy Controller identified by controller not operational, but
@@ -101,7 +99,7 @@ public interface PolicyControllerFactory {
* @param controller a Policy Controller
* @throws IllegalArgumentException invalid arguments
*/
- public void shutdown(PolicyController controller) throws IllegalArgumentException;
+ public void shutdown(PolicyController controller);
/**
* Releases all Policy Controllers from operation
@@ -114,7 +112,7 @@ public interface PolicyControllerFactory {
* @param controllerName name of the policy controller
* @throws IllegalArgumentException invalid arguments
*/
- public void destroy(String controllerName) throws IllegalArgumentException;;
+ public void destroy(String controllerName);
/**
* Destroys this Policy Controller
@@ -122,7 +120,7 @@ public interface PolicyControllerFactory {
* @param controller a Policy Controller
* @throws IllegalArgumentException invalid arguments
*/
- public void destroy(PolicyController controller) throws IllegalArgumentException;
+ public void destroy(PolicyController controller);
/**
* Releases all Policy Controller resources
@@ -137,8 +135,7 @@ public interface PolicyControllerFactory {
* @throws IllegalArgumentException
* @throws IllegalStateException
*/
- public PolicyController get(String policyControllerName)
- throws IllegalArgumentException, IllegalStateException;
+ public PolicyController get(String policyControllerName);
/**
* gets the Policy Controller identified by group and artifact ids
@@ -149,8 +146,7 @@ public interface PolicyControllerFactory {
* @throws IllegalArgumentException
* @throws IllegalStateException
*/
- public PolicyController get(String groupId, String artifactId)
- throws IllegalArgumentException, IllegalStateException;
+ public PolicyController get(String groupId, String artifactId);
/**
* get features attached to the Policy Controllers
@@ -162,8 +158,7 @@ public interface PolicyControllerFactory {
* get named feature attached to the Policy Controllers
* @return the feature
*/
- public PolicyControllerFeatureAPI getFeatureProvider(String featureName)
- throws IllegalArgumentException;
+ public PolicyControllerFeatureAPI getFeatureProvider(String featureName);
/**
* get features attached to the Policy Controllers
@@ -213,8 +208,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* {@inheritDoc}
*/
@Override
- public synchronized PolicyController build(String name, Properties properties)
- throws IllegalArgumentException {
+ public synchronized PolicyController build(String name, Properties properties) {
if (this.policyControllers.containsKey(name)) {
return this.policyControllers.get(name);
@@ -241,11 +235,10 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* {@inheritDoc}
*/
@Override
- public synchronized PolicyController patch(String name, DroolsConfiguration droolsConfig)
- throws IllegalArgumentException {
+ public synchronized PolicyController patch(String name, DroolsConfiguration droolsConfig) {
if (name == null || name.isEmpty() || !this.policyControllers.containsKey(name)) {
- throw new IllegalArgumentException("Invalid " + name);
+ throw makeArgEx(name);
}
if (droolsConfig == null)
@@ -273,8 +266,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* {@inheritDoc}
*/
@Override
- public PolicyController patch(PolicyController controller, DroolsConfiguration droolsConfig)
- throws IllegalArgumentException {
+ public PolicyController patch(PolicyController controller, DroolsConfiguration droolsConfig) {
if (controller == null)
throw new IllegalArgumentException("Not a valid controller: null");
@@ -300,10 +292,10 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* {@inheritDoc}
*/
@Override
- public void shutdown(String controllerName) throws IllegalArgumentException {
+ public void shutdown(String controllerName) {
if (controllerName == null || controllerName.isEmpty()) {
- throw new IllegalArgumentException("Invalid " + controllerName);
+ throw makeArgEx(controllerName);
}
synchronized(this) {
@@ -320,7 +312,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* {@inheritDoc}
*/
@Override
- public void shutdown(PolicyController controller) throws IllegalArgumentException {
+ public void shutdown(PolicyController controller) {
this.unmanage(controller);
controller.shutdown();
}
@@ -348,7 +340,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* @return
* @throws IllegalArgumentException
*/
- protected void unmanage(PolicyController controller) throws IllegalArgumentException {
+ protected void unmanage(PolicyController controller) {
PolicyController tempController = controller;
if (tempController == null) {
throw new IllegalArgumentException("Invalid Controller");
@@ -370,10 +362,10 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* {@inheritDoc}
*/
@Override
- public void destroy(String controllerName) throws IllegalArgumentException {
+ public void destroy(String controllerName) {
if (controllerName == null || controllerName.isEmpty()) {
- throw new IllegalArgumentException("Invalid " + controllerName);
+ throw makeArgEx(controllerName);
}
synchronized(this) {
@@ -390,7 +382,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* {@inheritDoc}
*/
@Override
- public void destroy(PolicyController controller) throws IllegalArgumentException {
+ public void destroy(PolicyController controller) {
this.unmanage(controller);
controller.halt();
}
@@ -415,17 +407,17 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* {@inheritDoc}
*/
@Override
- public PolicyController get(String name) throws IllegalArgumentException, IllegalStateException {
+ public PolicyController get(String name) {
if (name == null || name.isEmpty()) {
- throw new IllegalArgumentException("Invalid " + name);
+ throw makeArgEx(name);
}
synchronized(this) {
if (this.policyControllers.containsKey(name)) {
return this.policyControllers.get(name);
} else {
- throw new IllegalArgumentException("Invalid " + name);
+ throw makeArgEx(name);
}
}
}
@@ -434,8 +426,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* {@inheritDoc}
*/
@Override
- public PolicyController get(String groupId, String artifactId)
- throws IllegalArgumentException, IllegalStateException {
+ public PolicyController get(String groupId, String artifactId) {
if (groupId == null || groupId.isEmpty() ||
artifactId == null || artifactId.isEmpty()) {
@@ -447,7 +438,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
if (this.coordinates2Controller.containsKey(key)) {
return this.coordinates2Controller.get(key);
} else {
- throw new IllegalArgumentException("Invalid " + key);
+ throw makeArgEx(key);
}
}
}
@@ -456,8 +447,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* {@inheritDoc}
*/
@Override
- public PolicyController get(DroolsController droolsController)
- throws IllegalArgumentException, IllegalStateException {
+ public PolicyController get(DroolsController droolsController) {
if (droolsController == null) {
throw new IllegalArgumentException("No Drools Controller provided");
@@ -479,9 +469,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
*/
@Override
public List<PolicyController> inventory() {
- List<PolicyController> controllers =
- new ArrayList<>(this.policyControllers.values());
- return controllers;
+ return new ArrayList<>(this.policyControllers.values());
}
/**
@@ -509,7 +497,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* {@inheritDoc}
*/
@Override
- public PolicyControllerFeatureAPI getFeatureProvider(String featureName) throws IllegalArgumentException {
+ public PolicyControllerFeatureAPI getFeatureProvider(String featureName) {
if (featureName == null || featureName.isEmpty())
throw new IllegalArgumentException("A feature name must be provided");
@@ -520,4 +508,8 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
throw new IllegalArgumentException("Invalid Feature Name: " + featureName);
}
+
+ private IllegalArgumentException makeArgEx(String argName) {
+ return new IllegalArgumentException("Invalid " + argName);
+ }
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java
index c90d8bea..a1fee763 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -67,6 +67,11 @@ import com.google.gson.GsonBuilder;
*/
public interface PolicyEngine extends Startable, Lockable, TopicListener {
/**
+ * Policy Engine Manager
+ */
+ public static final PolicyEngine manager = new PolicyEngineManager();
+
+ /**
* Default Telemetry Server Port
*/
public static final int TELEMETRY_SERVER_DEFAULT_PORT = 9696;
@@ -86,7 +91,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
*
* @param cliArgs command line arguments
*/
- public void boot(String cliArgs[]);
+ public void boot(String[] cliArgs);
/**
* configure the policy engine according to the given properties
@@ -246,8 +251,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
*
* @return the feature
*/
- public PolicyEngineFeatureAPI getFeatureProvider(String featureName)
- throws IllegalArgumentException;
+ public PolicyEngineFeatureAPI getFeatureProvider(String featureName);
/**
* get features attached to the Policy Engine
@@ -267,8 +271,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* @throws IllegalStateException when the engine is in a state where this operation is not
* permitted (ie. locked or stopped).
*/
- public boolean deliver(String topic, Object event)
- throws IllegalArgumentException, IllegalStateException;
+ public boolean deliver(String topic, Object event);
/**
* Attempts the dispatching of an "event" object over communication infrastructure "busType"
@@ -284,8 +287,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
* missing (ie. communication infrastructure not supported.
*/
- public boolean deliver(String busType, String topic, Object event)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException;
+ public boolean deliver(String busType, String topic, Object event);
/**
* Attempts the dispatching of an "event" object over communication infrastructure "busType"
@@ -301,8 +303,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
* missing (ie. communication infrastructure not supported.
*/
- public boolean deliver(CommInfrastructure busType, String topic, Object event)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException;
+ public boolean deliver(CommInfrastructure busType, String topic, Object event);
/**
* Attempts delivering of an String over communication infrastructure "busType"
@@ -318,8 +319,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
* missing (ie. communication infrastructure not supported.
*/
- public boolean deliver(CommInfrastructure busType, String topic, String event)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException;
+ public boolean deliver(CommInfrastructure busType, String topic, String event);
/**
* Invoked when the host goes into the active state.
@@ -337,11 +337,6 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* @return policy engine configuration
*/
public Properties defaultTelemetryConfig();
-
- /**
- * Policy Engine Manager
- */
- public final static PolicyEngine manager = new PolicyEngineManager();
}
@@ -349,7 +344,15 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* Policy Engine Manager Implementation
*/
class PolicyEngineManager implements PolicyEngine {
- /**
+ private static final String INVALID_TOPIC_MSG = "Invalid Topic";
+
+private static final String INVALID_EVENT_MSG = "Invalid Event";
+
+private static final String ENGINE_STOPPED_MSG = "Policy Engine is stopped";
+
+private static final String ENGINE_LOCKED_MSG = "Policy Engine is locked";
+
+/**
* logger
*/
private static final Logger logger = LoggerFactory.getLogger(PolicyEngineManager.class);
@@ -396,7 +399,7 @@ class PolicyEngineManager implements PolicyEngine {
@Override
- public synchronized void boot(String cliArgs[]) {
+ public synchronized void boot(String[] cliArgs) {
for (final PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) {
try {
@@ -531,8 +534,7 @@ class PolicyEngineManager implements PolicyEngine {
}
@Override
- public synchronized PolicyController createPolicyController(String name, Properties properties)
- throws IllegalArgumentException, IllegalStateException {
+ public synchronized PolicyController createPolicyController(String name, Properties properties) {
String tempName = name;
// check if a PROPERTY_CONTROLLER_NAME property is present
@@ -601,8 +603,7 @@ class PolicyEngineManager implements PolicyEngine {
@Override
public List<PolicyController> updatePolicyControllers(
- List<ControllerConfiguration> configControllers)
- throws IllegalArgumentException, IllegalStateException {
+ List<ControllerConfiguration> configControllers) {
final List<PolicyController> policyControllers = new ArrayList<>();
if (configControllers == null || configControllers.isEmpty()) {
@@ -739,7 +740,7 @@ class PolicyEngineManager implements PolicyEngine {
boolean success = true;
if (this.locked)
- throw new IllegalStateException("Engine is locked");
+ throw new IllegalStateException(ENGINE_LOCKED_MSG);
this.alive = true;
@@ -1199,24 +1200,23 @@ class PolicyEngineManager implements PolicyEngine {
}
@Override
- public boolean deliver(String topic, Object event)
- throws IllegalArgumentException, IllegalStateException {
+ public boolean deliver(String topic, Object event) {
/*
* Note this entry point is usually from the DRL
*/
if (topic == null || topic.isEmpty())
- throw new IllegalArgumentException("Invalid Topic");
+ throw new IllegalArgumentException(INVALID_TOPIC_MSG);
if (event == null)
- throw new IllegalArgumentException("Invalid Event");
+ throw new IllegalArgumentException(INVALID_EVENT_MSG);
if (!this.isAlive())
- throw new IllegalStateException("Policy Engine is stopped");
+ throw new IllegalStateException(ENGINE_STOPPED_MSG);
if (this.isLocked())
- throw new IllegalStateException("Policy Engine is locked");
+ throw new IllegalStateException(ENGINE_LOCKED_MSG);
final List<? extends TopicSink> topicSinks = TopicEndpoint.manager.getTopicSinks(topic);
if (topicSinks == null || topicSinks.isEmpty() || topicSinks.size() > 1)
@@ -1227,8 +1227,7 @@ class PolicyEngineManager implements PolicyEngine {
}
@Override
- public boolean deliver(String busType, String topic, Object event)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException {
+ public boolean deliver(String busType, String topic, Object event) {
/*
* Note this entry point is usually from the DRL (one of the reasons busType is String.
@@ -1238,10 +1237,10 @@ class PolicyEngineManager implements PolicyEngine {
throw new IllegalArgumentException("Invalid Communication Infrastructure");
if (topic == null || topic.isEmpty())
- throw new IllegalArgumentException("Invalid Topic");
+ throw new IllegalArgumentException(INVALID_TOPIC_MSG);
if (event == null)
- throw new IllegalArgumentException("Invalid Event");
+ throw new IllegalArgumentException(INVALID_EVENT_MSG);
boolean valid = false;
for (final Topic.CommInfrastructure comm : Topic.CommInfrastructure.values()) {
@@ -1255,30 +1254,29 @@ class PolicyEngineManager implements PolicyEngine {
if (!this.isAlive())
- throw new IllegalStateException("Policy Engine is stopped");
+ throw new IllegalStateException(ENGINE_STOPPED_MSG);
if (this.isLocked())
- throw new IllegalStateException("Policy Engine is locked");
+ throw new IllegalStateException(ENGINE_LOCKED_MSG);
return this.deliver(Topic.CommInfrastructure.valueOf(busType), topic, event);
}
@Override
- public boolean deliver(Topic.CommInfrastructure busType, String topic, Object event)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException {
+ public boolean deliver(Topic.CommInfrastructure busType, String topic, Object event) {
if (topic == null || topic.isEmpty())
- throw new IllegalArgumentException("Invalid Topic");
+ throw new IllegalArgumentException(INVALID_TOPIC_MSG);
if (event == null)
- throw new IllegalArgumentException("Invalid Event");
+ throw new IllegalArgumentException(INVALID_EVENT_MSG);
if (!this.isAlive())
- throw new IllegalStateException("Policy Engine is stopped");
+ throw new IllegalStateException(ENGINE_STOPPED_MSG);
if (this.isLocked())
- throw new IllegalStateException("Policy Engine is locked");
+ throw new IllegalStateException(ENGINE_LOCKED_MSG);
/*
* Try to send through the controller, this is the preferred way, since it may want to apply
@@ -1312,20 +1310,19 @@ class PolicyEngineManager implements PolicyEngine {
}
@Override
- public boolean deliver(Topic.CommInfrastructure busType, String topic, String event)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException {
+ public boolean deliver(Topic.CommInfrastructure busType, String topic, String event) {
if (topic == null || topic.isEmpty())
- throw new IllegalArgumentException("Invalid Topic");
+ throw new IllegalArgumentException(INVALID_TOPIC_MSG);
if (event == null || event.isEmpty())
- throw new IllegalArgumentException("Invalid Event");
+ throw new IllegalArgumentException(INVALID_EVENT_MSG);
if (!this.isAlive())
- throw new IllegalStateException("Policy Engine is stopped");
+ throw new IllegalStateException(ENGINE_STOPPED_MSG);
if (this.isLocked())
- throw new IllegalStateException("Policy Engine is locked");
+ throw new IllegalStateException(ENGINE_LOCKED_MSG);
try {
final TopicSink sink = TopicEndpoint.manager.getTopicSink(busType, topic);
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java b/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java
index 0645bdc5..ea631fae 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -111,8 +111,7 @@ public class AggregatedPolicyController implements PolicyController,
*
* @throws IllegalArgumentException when invalid arguments are provided
*/
- public AggregatedPolicyController(String name, Properties properties)
- throws IllegalArgumentException {
+ public AggregatedPolicyController(String name, Properties properties) {
this.name = name;
@@ -139,7 +138,7 @@ public class AggregatedPolicyController implements PolicyController,
* initialize drools layer
* @throws IllegalArgumentException if invalid parameters are passed in
*/
- protected void initDrools(Properties properties) throws IllegalArgumentException {
+ protected void initDrools(Properties properties) {
try {
// Register with drools infrastructure
this.droolsController = DroolsController.factory.build(properties, sources, sinks);
@@ -153,7 +152,7 @@ public class AggregatedPolicyController implements PolicyController,
* initialize sinks
* @throws IllegalArgumentException if invalid parameters are passed in
*/
- protected void initSinks() throws IllegalArgumentException {
+ protected void initSinks() {
this.topic2Sinks.clear();
for (TopicSink sink: sinks) {
this.topic2Sinks.put(sink.getTopic(), sink);
@@ -224,7 +223,7 @@ public class AggregatedPolicyController implements PolicyController,
* {@inheritDoc}
*/
@Override
- public boolean start() throws IllegalStateException {
+ public boolean start() {
logger.info("{}: start", this);
for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) {
@@ -328,7 +327,7 @@ public class AggregatedPolicyController implements PolicyController,
* {@inheritDoc}
*/
@Override
- public void shutdown() throws IllegalStateException {
+ public void shutdown() {
logger.info("{}: shutdown", this);
for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) {
@@ -360,7 +359,7 @@ public class AggregatedPolicyController implements PolicyController,
* {@inheritDoc}
*/
@Override
- public void halt() throws IllegalStateException {
+ public void halt() {
logger.info("{}: halt", this);
for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) {
@@ -432,9 +431,7 @@ public class AggregatedPolicyController implements PolicyController,
*/
@Override
public boolean deliver(Topic.CommInfrastructure commType,
- String topic, Object event)
- throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
+ String topic, Object event) {
if (logger.isDebugEnabled())
logger.debug("{}: deliver event to {}:{}: {}", this, commType, topic, event);
diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java
index e3dd7c54..c7113cd4 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java
@@ -20,16 +20,13 @@
package org.onap.policy.drools.protocol.coders;
-import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
-import com.fasterxml.jackson.annotation.PropertyAccessor;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -47,6 +44,11 @@ import org.onap.policy.drools.utils.Triple;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
/**
* ProtocolCoder Toolset JUNITs
*/
@@ -157,7 +159,8 @@ public class ProtocolCoderToolsetTest {
decode(protocolFilter, coderToolset, triple, tripleEncoded);
}
- private void decode(JsonProtocolFilter protocolFilter, ProtocolCoderToolset coderToolset,
+ @SuppressWarnings("unchecked")
+ private void decode(JsonProtocolFilter protocolFilter, ProtocolCoderToolset coderToolset,
Triple<String, String, String> triple, String tripleEncoded) {
Triple<String, String, String> tripleDecoded = null;
@@ -273,9 +276,8 @@ public class ProtocolCoderToolsetTest {
droolsControllerConfig.put(PolicyProperties.PROPERTY_NOOP_SINK_TOPICS + "." +
JUNIT_PROTOCOL_CODER_TOPIC + PolicyProperties.PROPERTY_TOPIC_EVENTS_SUFFIX,
Triple.class.getCanonicalName());
-
- DroolsController droolsController =
- DroolsController.factory.build(droolsControllerConfig, null, noopTopics);
+
+ DroolsController.factory.build(droolsControllerConfig, null, noopTopics);
}
private JsonProtocolFilter createFilterSet() {
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedServiceImpl.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedServiceImpl.java
index 99c4566a..d0b451f1 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedServiceImpl.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedServiceImpl.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-utils
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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,7 +21,6 @@
package org.onap.policy.drools.utils;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -98,30 +97,17 @@ public class OrderedServiceImpl<T extends OrderedService>
// Sort the list according to sequence number, and then alphabetically
// according to full class name.
- Collections.sort(tmp, new Comparator<T>()
- {
- @Override
- public int compare(T o1, T o2)
- {
- int s1 = o1.getSequenceNumber();
- int s2 = o2.getSequenceNumber();
- int rval;
- if (s1 < s2)
- {
- rval = -1;
- }
- else if (s1 > s2)
- {
- rval = 1;
- }
- else
- {
- rval = o1.getClass().getName().compareTo
- (o2.getClass().getName());
- }
- return rval;
- }
- });
+ Collections.sort(tmp, (o1, o2) -> {
+ int s1 = o1.getSequenceNumber();
+ int s2 = o2.getSequenceNumber();
+ if (s1 < s2) {
+ return -1;
+ } else if (s1 > s2) {
+ return 1;
+ } else {
+ return o1.getClass().getName().compareTo(o2.getClass().getName());
+ }
+ });
// create an unmodifiable version of this list
implementers = Collections.unmodifiableList(tmp);
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/TripleTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/TripleTest.java
index cdb93e8a..ff613938 100644
--- a/policy-utils/src/test/java/org/onap/policy/drools/utils/TripleTest.java
+++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/TripleTest.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
@@ -28,7 +28,7 @@ public class TripleTest {
@Test
public void test() {
Triple<String, String, String> triple =
- new Triple("one", "two", "three");
+ new Triple<>("one", "two", "three");
Assert.assertTrue("one".equals(triple.first()));
Assert.assertTrue("one".equals(triple.getFirst()));