diff options
author | Jim Hahn <jrh3@att.com> | 2020-06-25 11:12:36 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-06-25 11:57:00 -0400 |
commit | 069dbb206cedae6c664972cfb8baf036989d61a0 (patch) | |
tree | e0a2f0edd840775000c947811157ac81cb719981 /controlloop/m2/base/src | |
parent | 68cdd3fe41fe7fa101d0d2331bd493a67e16203f (diff) |
Use parent snapshot in drools-apps
Fixed checkstyle issues that were subsequently reported.
Also fixed a few eclipse warnings.
Also fixed some of the sonar issues in the files that were touched:
- use "{}" in logger calls
- camelcase method names
- use "<?>" instead of generics
- add serialization ID
Issue-ID: POLICY-2188
Change-Id: I5c94a2e26dd74a61a0a919e1c3da17ab02a5bc9d
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/m2/base/src')
7 files changed, 21 insertions, 35 deletions
diff --git a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/GuardAdjunct.java b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/GuardAdjunct.java index 34397e2b9..d3675ae12 100644 --- a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/GuardAdjunct.java +++ b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/GuardAdjunct.java @@ -21,7 +21,6 @@ package org.onap.policy.m2.base; import java.io.Serializable; - import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.guard.GuardContext; diff --git a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/OnsetAdapter.java b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/OnsetAdapter.java index 37a999f06..3c164cfd2 100644 --- a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/OnsetAdapter.java +++ b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/OnsetAdapter.java @@ -21,15 +21,12 @@ package org.onap.policy.m2.base; import java.io.Serializable; - import java.util.ArrayList; import java.util.HashSet; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; - import org.onap.policy.controlloop.ControlLoopEvent; import org.onap.policy.controlloop.ControlLoopNotification; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +39,7 @@ public class OnsetAdapter implements Serializable { private static Logger logger = LoggerFactory.getLogger(OnsetAdapter.class); // table mapping onset message class to 'OnsetAdapter' instance - private static Map<Class,OnsetAdapter> map = new ConcurrentHashMap<>(); + private static Map<Class<?>, OnsetAdapter> map = new ConcurrentHashMap<>(); /** * This method is called to add an entry to the table. @@ -51,7 +48,7 @@ public class OnsetAdapter implements Serializable { * @param value an instance of 'OnsetAdapter' that should be * associated with 'clazz' */ - public static void register(Class clazz, OnsetAdapter value) { + public static void register(Class<?> clazz, OnsetAdapter value) { // only create an entry if one doesn't already exist map.putIfAbsent(clazz, value); } @@ -79,14 +76,14 @@ public class OnsetAdapter implements Serializable { // one will be chosen "at random". // we need to look for the best match of 'clazz' - HashSet<Class> matches = new HashSet<>(); - Class chosenMatch = null; + HashSet<Class<?>> matches = new HashSet<>(); + Class<?> chosenMatch = null; synchronized (map) { for (Class<?> possibleMatch : map.keySet()) { if (possibleMatch.isAssignableFrom(clazz)) { // we have a match -- see if it is the best match boolean add = true; - for (Class<?> match : new ArrayList<Class>(matches)) { + for (Class<?> match : new ArrayList<Class<?>>(matches)) { if (match.isAssignableFrom(possibleMatch)) { // 'possibleMatch' is a better match than 'match' matches.remove(match); @@ -134,6 +131,8 @@ public class OnsetAdapter implements Serializable { // the new 'ControlLoopNotification' is abstract public static class BaseControlLoopNotification extends ControlLoopNotification { + private static final long serialVersionUID = 1L; + BaseControlLoopNotification(ControlLoopEvent event) { super(event); } diff --git a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Operation.java b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Operation.java index ec5ab8ef6..c8ee901c3 100644 --- a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Operation.java +++ b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Operation.java @@ -21,7 +21,6 @@ package org.onap.policy.m2.base; import java.io.Serializable; - import org.onap.policy.controlloop.ControlLoopException; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.policy.Policy; diff --git a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Transaction.java b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Transaction.java index 41c251e2a..f964e207e 100644 --- a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Transaction.java +++ b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Transaction.java @@ -29,11 +29,9 @@ import java.util.List; import java.util.Map; import java.util.ServiceLoader; import java.util.UUID; - import lombok.Getter; import org.drools.core.WorkingMemory; import org.kie.api.runtime.rule.FactHandle; - import org.onap.policy.controlloop.ControlLoopEvent; import org.onap.policy.controlloop.ControlLoopNotification; import org.onap.policy.controlloop.ControlLoopNotificationType; @@ -42,7 +40,6 @@ import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.controlloop.policy.FinalResult; import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.policy.PolicyResult; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,7 +55,7 @@ public class Transaction implements Serializable { // This table maps 'actor' names to objects implementing the // 'Actor' interface. 'ServiceLoader' is used to locate and create // these objects, and populate the table. - private static Map<String,Actor> nameToActor = new HashMap<>(); + private static Map<String, Actor> nameToActor = new HashMap<>(); static { // use 'ServiceLoader' to locate all of the 'Actor' implementations @@ -428,7 +425,7 @@ public class Transaction implements Serializable { break; case FAILURE: - nextPolicy = processResult_Failure(); + nextPolicy = processResultFailure(); break; case FAILURE_TIMEOUT: @@ -499,7 +496,7 @@ public class Transaction implements Serializable { } // returns the next policy if the current operation fails - private String processResult_Failure() { + private String processResultFailure() { String nextPolicy = null; int attempt = currentOperation.getAttempt(); if (attempt <= currentPolicy.getRetry()) { @@ -507,20 +504,19 @@ public class Transaction implements Serializable { Actor actor = nameToActor.get(currentPolicy.getActor()); if (actor != null) { attempt += 1; - logger.debug("found Actor, attempt " + attempt); + logger.debug("found Actor, attempt {}", attempt); currentOperation = actor.createOperation(this, currentPolicy, onset, attempt); createHistEntry(); } else { - logger.error("'Transaction' can't find actor " - + currentPolicy.getActor()); + logger.error("'Transaction' can't find actor {}", currentPolicy.getActor()); } } else { // operation failed, and no retries (or no retries left) nextPolicy = (attempt == 1 ? currentPolicy.getFailure() : currentPolicy.getFailure_retries()); - logger.debug("moving to policy " + nextPolicy); + logger.debug("moving to policy {}", nextPolicy); } return nextPolicy; } @@ -592,11 +588,10 @@ public class Transaction implements Serializable { actor.createOperation(this, currentPolicy, onset, 1); createHistEntry(); } else { - logger.error("'Transaction' can't find actor " - + currentPolicy.getActor()); + logger.error("'Transaction' can't find actor {}", currentPolicy.getActor()); } } else { - logger.error("Transaction' can't find policy " + id); + logger.error("Transaction' can't find policy {}", id); } if (currentOperation == null) { @@ -670,7 +665,7 @@ public class Transaction implements Serializable { T adjunct = null; try { // create the adjunct (may trigger an exception) - adjunct = clazz.newInstance(); + adjunct = clazz.getDeclaredConstructor().newInstance(); // initialize the adjunct (may also trigger an exception */ adjunct.init(Transaction.this); diff --git a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/ActorOperationTest.java b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/ActorOperationTest.java index ce5f2df1f..33b4928b1 100644 --- a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/ActorOperationTest.java +++ b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/ActorOperationTest.java @@ -25,7 +25,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import org.junit.Test; - import org.onap.policy.controlloop.ControlLoopEvent; import org.onap.policy.controlloop.ControlLoopException; import org.onap.policy.controlloop.policy.Policy; @@ -37,6 +36,7 @@ public class ActorOperationTest { public static final String STATE = "COMPLETE"; public static class TestOperation implements Operation { + private static final long serialVersionUID = 1L; @Override public Object getRequest() throws ControlLoopException { diff --git a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/GuardAdjunctTest.java b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/GuardAdjunctTest.java index 78aab89d4..facde545a 100644 --- a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/GuardAdjunctTest.java +++ b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/GuardAdjunctTest.java @@ -26,14 +26,11 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import java.time.Instant; import java.util.UUID; - import org.junit.BeforeClass; import org.junit.Test; - import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.guard.GuardContext; @@ -41,7 +38,6 @@ import org.powermock.reflect.Whitebox; public class GuardAdjunctTest { private static final String ADJUNCT_CONTEXT_FIELD = "context"; - private static final String ADJUNCT_TRANSACTION_FIELD = "transaction"; private static GuardAdjunct adjunct; private static Transaction transaction; @@ -73,7 +69,7 @@ public class GuardAdjunctTest { assertTrue(adjunct.asyncQuery(policy, "testTarget", UUID.randomUUID().toString())); GuardContext savedContext = Whitebox.getInternalState(adjunct, ADJUNCT_CONTEXT_FIELD); - Whitebox.setInternalState(adjunct, ADJUNCT_CONTEXT_FIELD, (GuardContext)null); + Whitebox.setInternalState(adjunct, ADJUNCT_CONTEXT_FIELD, (GuardContext) null); try { assertFalse(adjunct.asyncQuery(policy, "testTarget", UUID.randomUUID().toString())); diff --git a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java index 30546d0ec..c5fa6befd 100644 --- a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java +++ b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java @@ -25,14 +25,13 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.time.Instant; import java.util.LinkedList; import java.util.UUID; - import org.drools.core.WorkingMemory; import org.drools.core.impl.StatefulKnowledgeSessionImpl; import org.junit.BeforeClass; @@ -46,7 +45,6 @@ import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.controlloop.policy.FinalResult; import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.policy.Target; -import org.onap.policy.m2.base.GuardAdjunct; public class TransactionTest { @@ -61,7 +59,7 @@ public class TransactionTest { public static void setUpBeforeClass() { mockWorkingMemory = mock(WorkingMemory.class); FactHandle factHandle = mock(FactHandle.class); - when(mockWorkingMemory.getFactHandle(anyObject())).thenReturn(factHandle); + when(mockWorkingMemory.getFactHandle(any())).thenReturn(factHandle); } @Test @@ -310,7 +308,7 @@ public class TransactionTest { Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop()); ControlLoopNotification notification = transaction.processError(); assertNull(notification); - + VirtualControlLoopEvent onset = createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name"); transaction.setControlLoopEvent(onset); |