Fix build breakage in drools-apps due to pair 63/109663/1
authorJim Hahn <jrh3@att.com>
Mon, 29 Jun 2020 21:43:07 +0000 (17:43 -0400)
committerJim Hahn <jrh3@att.com>
Mon, 29 Jun 2020 21:44:28 +0000 (17:44 -0400)
The Pair changes made in drools-pdp also broke drools-apps builds.
Replaced usage of drools.utils.Pair with apache Pair.

Issue-ID: POLICY-2202
Change-Id: I50aaad47c243637688602ae6cb680a929fe3edd9
Signed-off-by: Jim Hahn <jrh3@att.com>
controlloop/common/controller-usecases/src/main/resources/usecases.drl
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java

index 3fe2cdd..dabc02f 100644 (file)
@@ -21,6 +21,8 @@
 
 package org.onap.policy.controlloop;
 
+import org.apache.commons.lang3.tuple.Pair;
+
 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
 import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
 import org.onap.policy.controlloop.CanonicalOnset;
@@ -50,7 +52,6 @@ import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
 import org.onap.policy.cds.CdsResponse;
 import org.onap.policy.cds.client.CdsProcessorGrpcClient;
 import org.onap.policy.cds.properties.CdsServerProperties;
-import org.onap.policy.drools.utils.Pair;
 import org.onap.policy.sdnr.PciRequestWrapper;
 import org.onap.policy.sdnr.PciResponseWrapper;
 import org.onap.policy.sdnr.PciRequest;
@@ -432,15 +433,15 @@ rule "EVENT.MANAGER"
 
               Pair<Lock,Lock> oldNew = $manager.lockCurrentOperation(
                         new LockCallbackWorkingMemory($params.getClosedLoopControlName(), drools.getWorkingMemory()));
-              if(oldNew.first() != null) {
+              if(oldNew.getLeft() != null) {
                   logger.debug("{}: {}.{}: retracting lock={}", $clName,
-                              $params.getPolicyName(), drools.getRule().getName(), oldNew.first());
-                  retract(oldNew.first());
+                              $params.getPolicyName(), drools.getRule().getName(), oldNew.getLeft());
+                  retract(oldNew.getLeft());
               }
-              if(oldNew.second() != null) {
+              if(oldNew.getRight() != null) {
                   logger.debug("{}: {}.{}: inserting lock={}", $clName,
-                              $params.getPolicyName(), drools.getRule().getName(), oldNew.second());
-                  insert(oldNew.second());
+                              $params.getPolicyName(), drools.getRule().getName(), oldNew.getRight());
+                  insert(oldNew.getRight());
               }
 
               //
index 6e88ce9..5546a0b 100644 (file)
@@ -37,6 +37,7 @@ import java.util.UUID;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.aai.AaiCqResponse;
 import org.onap.policy.aai.AaiManager;
 import org.onap.policy.aai.util.AaiException;
@@ -54,7 +55,6 @@ import org.onap.policy.drools.core.lock.LockCallback;
 import org.onap.policy.drools.core.lock.LockImpl;
 import org.onap.policy.drools.core.lock.LockState;
 import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.drools.utils.Pair;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 import org.onap.policy.rest.RestManager;
 import org.slf4j.Logger;
@@ -525,12 +525,12 @@ public class ControlLoopEventManager implements Serializable {
         if (this.targetLock != null) {
             // we have the lock - just extend it
             this.targetLock.extend(holdSec, callback);
-            return new Pair<>(oldLock, null);
+            return Pair.of(oldLock, null);
 
         } else if (this.useTargetLock) {
             this.targetLock = createRealLock(this.currentOperation.getTargetEntity(), this.onset.getRequestId(),
                             holdSec, callback);
-            return new Pair<>(oldLock, this.targetLock);
+            return Pair.of(oldLock, this.targetLock);
 
         } else {
             // Not using target locks - create a lock w/o actually locking.
@@ -540,7 +540,7 @@ public class ControlLoopEventManager implements Serializable {
 
             // Note: no need to invoke callback, as the lock is already ACTIVE
 
-            return new Pair<>(oldLock, this.targetLock);
+            return Pair.of(oldLock, this.targetLock);
         }
     }
 
index 2d9fb7e..7479f66 100644 (file)
@@ -46,6 +46,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.tuple.Pair;
 import org.jetbrains.annotations.NotNull;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -66,7 +67,6 @@ import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.drools.core.lock.Lock;
 import org.onap.policy.drools.core.lock.LockCallback;
 import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.drools.utils.Pair;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 import org.powermock.reflect.Whitebox;
 
@@ -454,15 +454,15 @@ public class ControlLoopEventManagerTest {
         assertNull(clom.getOperationResult());
 
         Pair<Lock, Lock> lockPair = manager.lockCurrentOperation(callback);
-        assertNull(lockPair.first());
-        assertNotNull(lockPair.second());
+        assertNull(lockPair.getLeft());
+        assertNotNull(lockPair.getRight());
 
         // pseudo lock - session should NOT have been notified of the change
         verify(callback, never()).lockAvailable(any());
         verify(callback, never()).lockUnavailable(any());
 
         // repeat - should cause an extension
-        Lock lock = lockPair.second();
+        Lock lock = lockPair.getRight();
         lockPair = manager.lockCurrentOperation(callback);
 
         /*
@@ -474,20 +474,20 @@ public class ControlLoopEventManagerTest {
 
         assertSame(lock, manager.unlockCurrentOperation());
 
-        assertNull(lockPair.first());
-        assertNull(lockPair.second());
+        assertNull(lockPair.getLeft());
+        assertNull(lockPair.getRight());
 
         // force it to use a pseudo lock
         manager.setUseTargetLock(false);
         lockPair = manager.lockCurrentOperation(callback);
-        assertNull(lockPair.first());
-        assertNotNull(lockPair.second());
+        assertNull(lockPair.getLeft());
+        assertNotNull(lockPair.getRight());
 
-        lock = lockPair.second();
+        lock = lockPair.getRight();
 
         lockPair = manager.lockCurrentOperation(callback);
-        assertNull(lockPair.first());
-        assertNull(lockPair.second());
+        assertNull(lockPair.getLeft());
+        assertNull(lockPair.getRight());
 
         // first lock uses a pseudo lock, so it will only update when extended
         verify(callback).lockAvailable(lock);
@@ -498,14 +498,14 @@ public class ControlLoopEventManagerTest {
         Whitebox.setInternalState(manager, TARGET_LOCK_FIELD, lock);
 
         lockPair = manager.lockCurrentOperation(callback);
-        assertSame(lock, lockPair.first());
-        assertNotNull(lockPair.second());
+        assertSame(lock, lockPair.getLeft());
+        assertNotNull(lockPair.getRight());
 
-        lock = lockPair.second();
+        lock = lockPair.getRight();
 
         lockPair = manager.lockCurrentOperation(callback);
-        assertNull(lockPair.first());
-        assertNull(lockPair.second());
+        assertNull(lockPair.getLeft());
+        assertNull(lockPair.getRight());
 
         // first lock uses a pseudo lock, so it won't do an update
         verify(callback).lockAvailable(lock);
@@ -515,8 +515,8 @@ public class ControlLoopEventManagerTest {
 
         // try again - this time don't return the fact handle- no change in count
         lockPair = manager.lockCurrentOperation(callback);
-        assertNull(lockPair.first());
-        assertNotNull(lockPair.second());
+        assertNull(lockPair.getLeft());
+        assertNotNull(lockPair.getRight());
     }
 
     @Test