diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2017-11-30 15:26:33 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-11-30 15:26:33 +0000 |
commit | 7a8d505b684cc568d0f50179ff2c3a4e4880f65d (patch) | |
tree | 39621b9237831fbe27fc72f2c7975bd2d576a1a6 | |
parent | 46f1e7e0f4a916af93c82be907433813664c75b5 (diff) | |
parent | f2c75918e425d62d0332da4685cae3518a50d4bb (diff) |
Merge "Refactored code to reduce technical debt."
2 files changed, 40 insertions, 33 deletions
diff --git a/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java b/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java index a23f2a46..5e209faa 100644 --- a/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java +++ b/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java @@ -64,7 +64,7 @@ public interface TestTransaction { */ class TTImpl implements TestTransaction { - final protected Map<String, TTControllerTask> controllers = new HashMap<>(); + protected final Map<String, TTControllerTask> controllers = new HashMap<>(); @Override public synchronized void register(PolicyController controller) { @@ -158,34 +158,7 @@ class TTControllerTask implements Runnable { while (this.controller.isAlive() && !this.controller.isLocked() && drools.isBrained() && this.alive) { - for (final String session : sessions) { - final List<Object> facts = this.controller.getDrools().factQuery(session, - TestTransaction.TT_FPC, TestTransaction.TT_COUNTER, false); - if (facts == null || facts.size() != 1) { - /* - * unexpected something wrong here, can't expect to recover note this exception is - * caught right below at the exit of run() - */ - logger.error( - "Controller: {}, with rules artifact: (group) {}, (artifact) {}, (version) {} - FPC query failed after EventObject insertion! ", - this.controller.getName(), this.controller.getDrools().getGroupId(), - this.controller.getDrools().getArtifactId(), - this.controller.getDrools().getVersion()); - break; - } - logger.debug("Facts: {}", facts); - - final long fpc = (Long) facts.get(0); - if (fpc != fpcs.get(session)) - logger.info("Controller: {} , session {} - Forward progress successful: {} -> {}", - this.controller.getName(), session, fpcs.get(session), fpc); - else - logger.error("Controller: {}, session {} - Forward progress failure: {}", - this.controller.getName(), session, fpc); - - fpcs.put(session, fpc); - drools.getContainer().insert(session, new EventObject(TestTransaction.TT_UUID)); - } + injectTxIntoSessions(sessions, fpcs, drools); if (!this.alive) return; @@ -208,7 +181,41 @@ class TTControllerTask implements Runnable { this.alive = false; } } + + private void injectTxIntoSessions(List<String> sessions, HashMap<String, Long> fpcs, DroolsController drools) { + for (final String session : sessions) { + final List<Object> facts = this.controller.getDrools().factQuery(session, + TestTransaction.TT_FPC, TestTransaction.TT_COUNTER, false); + if (facts == null || facts.size() != 1) { + /* + * unexpected something wrong here, can't expect to recover note this exception is + * caught right below at the exit of run() + */ + logger.error( + "Controller: {}, with rules artifact: (group) {}, (artifact) {}, (version) {} - FPC query failed after EventObject insertion! ", + this.controller.getName(), this.controller.getDrools().getGroupId(), + this.controller.getDrools().getArtifactId(), + this.controller.getDrools().getVersion()); + break; + } + logger.debug("Facts: {}", facts); + + final long fpc = (Long) facts.get(0); + if (fpc != fpcs.get(session)) + logger.info("Controller: {} , session {} - Forward progress successful: {} -> {}", + this.controller.getName(), session, fpcs.get(session), fpc); + else + logger.error("Controller: {}, session {} - Forward progress failure: {}", + this.controller.getName(), session, fpc); + + fpcs.put(session, fpc); + drools.getContainer().insert(session, new EventObject(TestTransaction.TT_UUID)); + } + + } + + @Override public String toString() { final StringBuilder builder = new StringBuilder(); diff --git a/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionFeature.java b/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionFeature.java index 72c54969..e78668ab 100644 --- a/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionFeature.java +++ b/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionFeature.java @@ -33,7 +33,7 @@ public class TestTransactionFeature implements PolicyControllerFeatureAPI { // get an instance of logger private static final Logger logger = LoggerFactory.getLogger(TestTransactionFeature.class); - + @Override public boolean afterStart(PolicyController controller){ @@ -49,7 +49,7 @@ public class TestTransactionFeature implements PolicyControllerFeatureAPI { @Override public boolean afterLock(PolicyController controller) { - logger.info("CONTROLLER " + controller.getName() + " LOCKED"); + logger.info("controller {} locked", controller.getName()); TestTransaction.manager.unregister(controller); return false; @@ -57,7 +57,7 @@ public class TestTransactionFeature implements PolicyControllerFeatureAPI { @Override public boolean afterUnlock(PolicyController controller) { - logger.info("CONTROLLER " + controller.getName() + " UNLOCKED"); + logger.info("controller {} unlocked", controller.getName()); if (controller.isAlive() && !controller.isLocked() && @@ -69,7 +69,7 @@ public class TestTransactionFeature implements PolicyControllerFeatureAPI { @Override public boolean beforeStop(PolicyController controller) { - logger.info("CONTROLLER " + controller.getName() + " ABOUT TO STOP"); + logger.info("controller {} stopping", controller.getName()); TestTransaction.manager.unregister(controller); |