summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--api-active-standby-management/pom.xml2
-rw-r--r--api-state-management/pom.xml2
-rw-r--r--docker_build.sh14
-rw-r--r--docker_merge.sh14
-rw-r--r--docker_verify.sh14
-rw-r--r--feature-active-standby-management/pom.xml2
-rw-r--r--feature-distributed-locking/pom.xml2
-rw-r--r--feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingFeature.java36
-rw-r--r--feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingProperties.java4
-rw-r--r--feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/TargetLock.java70
-rw-r--r--feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java31
-rw-r--r--feature-eelf/pom.xml2
-rw-r--r--feature-healthcheck/pom.xml2
-rw-r--r--feature-pooling-dmaap/pom.xml2
-rw-r--r--feature-pooling-dmaap/src/test/resources/logback-test.xml19
-rw-r--r--feature-session-persistence/pom.xml2
-rw-r--r--feature-simulators/pom.xml2
-rw-r--r--feature-state-management/pom.xml2
-rw-r--r--feature-test-transaction/pom.xml2
-rwxr-xr-xpackages/base/src/files/etc/cron.d/monitor.cron20
-rw-r--r--packages/docker/README.md4
-rw-r--r--packages/docker/pom.xml21
-rw-r--r--packages/docker/src/main/docker/Dockerfile5
-rw-r--r--packages/docker/src/main/docker/do-start.sh27
-rw-r--r--packages/docker/src/main/docker/wait-for-port.sh19
-rw-r--r--packages/install/src/files/feature-healthcheck.conf19
-rw-r--r--packages/install/src/files/policy-management.conf20
-rw-r--r--policy-core/pom.xml2
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/lock/LockRequestFuture.java4
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPI.java87
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java67
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/lock/SimpleLockManager.java3
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/lock/LockRequestFutureTest.java74
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPITest.java8
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockManagerTest.java37
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/lock/SimpleLockManagerTest.java51
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/lock/TestUtils.java8
-rw-r--r--policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/rules.drl21
-rw-r--r--policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/rules.drl19
-rw-r--r--policy-endpoints/pom.xml8
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java32
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java30
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java11
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java7
-rw-r--r--policy-endpoints/src/test/resources/logback-test.xml19
-rw-r--r--policy-management/pom.xml13
-rw-r--r--policy-management/src/test/resources/logback-test.xml19
-rw-r--r--policy-utils/pom.xml2
-rw-r--r--pom.xml4
-rw-r--r--version.properties2
51 files changed, 570 insertions, 321 deletions
diff --git a/README.md b/README.md
index 1afeaadd..c4ba81a8 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,7 @@
+Copyright 2018 AT&T Intellectual Property. All rights reserved.
+This file is licensed under the CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL LICENSE
+Full license text at https://creativecommons.org/licenses/by/4.0/legalcode
+
This source repository contains the ONAP Policy DroolsPDP code. To build it:
1. using Maven 3
2. git clone http://gerrit.onap.org/r/oparent and copy
diff --git a/api-active-standby-management/pom.xml b/api-active-standby-management/pom.xml
index bfdf578c..659f612d 100644
--- a/api-active-standby-management/pom.xml
+++ b/api-active-standby-management/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>api-active-standby-management</artifactId>
diff --git a/api-state-management/pom.xml b/api-state-management/pom.xml
index 755e4d77..0d187126 100644
--- a/api-state-management/pom.xml
+++ b/api-state-management/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>api-state-management</artifactId>
diff --git a/docker_build.sh b/docker_build.sh
index a7e79db6..6f00f7e8 100644
--- a/docker_build.sh
+++ b/docker_build.sh
@@ -1,4 +1,18 @@
#!/bin/bash
+# Copyright 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
#
echo '============== STARTING SCRIPT TO BUILD DOCKER IMAGES ================='
DOCKER_REPOSITORY=nexus3.onap.org:10003
diff --git a/docker_merge.sh b/docker_merge.sh
index 2175d714..804ea854 100644
--- a/docker_merge.sh
+++ b/docker_merge.sh
@@ -1,4 +1,18 @@
#!/bin/bash
+# Copyright 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
#
echo '============== STARTING SCRIPT TO BUILD DOCKER IMAGES ================='
DOCKER_REPOSITORY=nexus3.onap.org:10003
diff --git a/docker_verify.sh b/docker_verify.sh
index 2e2c7110..009fce44 100644
--- a/docker_verify.sh
+++ b/docker_verify.sh
@@ -1,4 +1,18 @@
#!/bin/bash
+# Copyright 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
#
echo '============== STARTING SCRIPT TO BUILD DOCKER IMAGES ================='
#
diff --git a/feature-active-standby-management/pom.xml b/feature-active-standby-management/pom.xml
index 10cd5351..0b3b585a 100644
--- a/feature-active-standby-management/pom.xml
+++ b/feature-active-standby-management/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>feature-active-standby-management</artifactId>
diff --git a/feature-distributed-locking/pom.xml b/feature-distributed-locking/pom.xml
index c4beacc2..32899720 100644
--- a/feature-distributed-locking/pom.xml
+++ b/feature-distributed-locking/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>feature-distributed-locking</artifactId>
diff --git a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingFeature.java b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingFeature.java
index 3d19c873..019452a0 100644
--- a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingFeature.java
+++ b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingFeature.java
@@ -79,31 +79,31 @@ public class DistributedLockingFeature implements PolicyEngineFeatureAPI, Policy
@Override
public Future<Boolean> beforeLock(String resourceId, String owner, Callback callback) {
- TargetLock tLock = new TargetLock(resourceId, this.uuid, owner, lockProps);
+ TargetLock tLock = new TargetLock(resourceId, uuid, owner, lockProps);
return new LockRequestFuture(resourceId, owner, tLock.lock());
}
@Override
- public Boolean beforeUnlock(String resourceId, String owner) {
- TargetLock tLock = new TargetLock(resourceId, this.uuid, owner, lockProps);
+ public OperResult beforeUnlock(String resourceId, String owner) {
+ TargetLock tLock = new TargetLock(resourceId, uuid, owner, lockProps);
- return tLock.unlock();
+ return(tLock.unlock() ? OperResult.OPER_ACCEPTED : OperResult.OPER_DENIED);
}
@Override
- public Boolean beforeIsLockedBy(String resourceId, String owner) {
- TargetLock tLock = new TargetLock(resourceId, this.uuid, owner, lockProps);
-
- return tLock.isActive();
+ public OperResult beforeIsLockedBy(String resourceId, String owner) {
+ TargetLock tLock = new TargetLock(resourceId, uuid, owner, lockProps);
+
+ return(tLock.isActive() ? OperResult.OPER_ACCEPTED : OperResult.OPER_DENIED);
}
@Override
- public Boolean beforeIsLocked(String resourceId) {
- TargetLock tLock = new TargetLock(resourceId, this.uuid, "dummyOwner", lockProps);
-
- return tLock.isLocked();
+ public OperResult beforeIsLocked(String resourceId) {
+ TargetLock tLock = new TargetLock(resourceId, uuid, "dummyOwner", lockProps);
+
+ return(tLock.isLocked() ? OperResult.OPER_ACCEPTED : OperResult.OPER_DENIED);
}
@Override
@@ -119,7 +119,7 @@ public class DistributedLockingFeature implements PolicyEngineFeatureAPI, Policy
long heartbeatInterval = this.lockProps.getHeartBeatIntervalProperty();
cleanLockTable();
- heartbeat = new Heartbeat(this.uuid, lockProps);
+ initHeartbeat(lockProps);
this.scheduledExecutorService = Executors.newScheduledThreadPool(1);
this.scheduledExecutorService.scheduleAtFixedRate(heartbeat, heartbeatInterval, heartbeatInterval, TimeUnit.MILLISECONDS);
@@ -148,7 +148,7 @@ public class DistributedLockingFeature implements PolicyEngineFeatureAPI, Policy
PreparedStatement statement = conn.prepareStatement("DELETE FROM pooling.locks WHERE host = ? OR expirationTime < ?");
){
- statement.setString(1, this.uuid.toString());
+ statement.setString(1, uuid.toString());
statement.setLong(2, System.currentTimeMillis());
statement.executeUpdate();
@@ -158,6 +158,14 @@ public class DistributedLockingFeature implements PolicyEngineFeatureAPI, Policy
}
+ /**
+ * Initialize the static heartbeat object
+ */
+ private static void initHeartbeat(DistributedLockingProperties lockProps) {
+ heartbeat = new Heartbeat(uuid, lockProps);
+
+ }
+
public static Heartbeat getHeartbeat() {
return heartbeat;
}
diff --git a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingProperties.java b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingProperties.java
index 139bfb7b..97ba3b10 100644
--- a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingProperties.java
+++ b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingProperties.java
@@ -23,14 +23,10 @@ import java.util.Properties;
import org.onap.policy.common.utils.properties.PropertyConfiguration;
import org.onap.policy.common.utils.properties.exception.PropertyException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class DistributedLockingProperties extends PropertyConfiguration{
- private static final Logger logger = LoggerFactory.getLogger(DistributedLockingProperties.class);
-
/**
* Feature properties all begin with this prefix.
*/
diff --git a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/TargetLock.java b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/TargetLock.java
index ceaa849f..4f09dc2a 100644
--- a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/TargetLock.java
+++ b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/TargetLock.java
@@ -88,19 +88,21 @@ public class TargetLock {
*/
private boolean grabLock() {
+ // try to insert a record into the table(thereby grabbing the lock)
try (Connection conn = DriverManager.getConnection(lockProps.getDbUrl(), lockProps.getDbUser(),
lockProps.getDbPwd());
- // try to insert a record into the table(thereby grabbing the lock)
- PreparedStatement statement = conn
- .prepareStatement("INSERT INTO pooling.locks (resourceId, host, owner, expirationTime) values (?, ?, ?, ?)");) {
+ PreparedStatement statement = conn.prepareStatement(
+ "INSERT INTO pooling.locks (resourceId, host, owner, expirationTime) values (?, ?, ?, ?)")) {
+
statement.setString(1, this.resourceId);
statement.setString(2, this.uuid.toString());
statement.setString(3, this.owner);
statement.setLong(4, System.currentTimeMillis() + lockProps.getAgingProperty());
-
statement.executeUpdate();
- } catch (SQLException e) {
+ }
+
+ catch (SQLException e) {
logger.error("error in TargetLock.grabLock()", e);
return secondGrab();
}
@@ -117,9 +119,11 @@ public class TargetLock {
try (Connection conn = DriverManager.getConnection(lockProps.getDbUrl(), lockProps.getDbUser(),
lockProps.getDbPwd());
- PreparedStatement updateStatement = conn.prepareStatement("UPDATE pooling.locks SET host = ?, owner = ?, expirationTime = ? WHERE expirationTime <= ? AND resourceId = ?");
-
- PreparedStatement insertStatement = conn.prepareStatement("INSERT INTO pooling.locks (resourceId, host, owner, expirationTime) values (?, ?, ?, ?)");) {
+ PreparedStatement updateStatement = conn.prepareStatement(
+ "UPDATE pooling.locks SET host = ?, owner = ?, expirationTime = ? WHERE expirationTime <= ? AND resourceId = ?");
+
+ PreparedStatement insertStatement = conn.prepareStatement(
+ "INSERT INTO pooling.locks (resourceId, host, owner, expirationTime) values (?, ?, ?, ?)");) {
updateStatement.setString(1, this.uuid.toString());
updateStatement.setString(2, this.owner);
@@ -132,6 +136,7 @@ public class TargetLock {
if (updateStatement.executeUpdate() == 1) {
return true;
}
+
// If our update does not return 1 row, the lock either has not expired
// or it was removed. Try one last grab
else {
@@ -140,7 +145,7 @@ public class TargetLock {
insertStatement.setString(3, this.owner);
insertStatement.setLong(4, System.currentTimeMillis() + lockProps.getAgingProperty());
- // If our insert returns 1 we successfully grabbed the lock
+ // If our insert returns 1 we successfully grabbed the lock
return (insertStatement.executeUpdate() == 1);
}
@@ -159,13 +164,13 @@ public class TargetLock {
try (Connection conn = DriverManager.getConnection(lockProps.getDbUrl(), lockProps.getDbUser(),
lockProps.getDbPwd());
- PreparedStatement deleteStatement = conn
- .prepareStatement("DELETE FROM pooling.locks WHERE resourceId = ? AND owner = ? AND host = ?");) {
+ PreparedStatement deleteStatement = conn.prepareStatement(
+ "DELETE FROM pooling.locks WHERE resourceId = ? AND owner = ? AND host = ?")) {
deleteStatement.setString(1, this.resourceId);
deleteStatement.setString(2, this.owner);
deleteStatement.setString(3, this.uuid.toString());
-
+
return (deleteStatement.executeUpdate() == 1);
} catch (SQLException e) {
@@ -174,34 +179,35 @@ public class TargetLock {
}
}
-
+
/**
* Is the lock active
*/
public boolean isActive() {
-
try (Connection conn = DriverManager.getConnection(lockProps.getDbUrl(), lockProps.getDbUser(),
lockProps.getDbPwd());
- PreparedStatement selectStatement = conn
- .prepareStatement("SELECT * FROM pooling.locks WHERE resourceId = ? AND host = ? AND owner= ? AND expirationTime >= ?");) {
- {
- selectStatement.setString(1, this.resourceId);
- selectStatement.setString(2, this.uuid.toString());
- selectStatement.setString(3, this.owner);
- selectStatement.setLong(4, System.currentTimeMillis());
+ PreparedStatement selectStatement = conn.prepareStatement(
+ "SELECT * FROM pooling.locks WHERE resourceId = ? AND host = ? AND owner= ? AND expirationTime >= ?")) {
- ResultSet result = selectStatement.executeQuery();
+ selectStatement.setString(1, this.resourceId);
+ selectStatement.setString(2, this.uuid.toString());
+ selectStatement.setString(3, this.owner);
+ selectStatement.setLong(4, System.currentTimeMillis());
+ try (ResultSet result = selectStatement.executeQuery()) {
// This will return true if the
// query returned at least one row
return result.first();
-
}
- } catch (SQLException e) {
+
+ }
+
+ catch (SQLException e) {
logger.error("error in TargetLock.isActive()", e);
return false;
}
+
}
/**
@@ -211,20 +217,20 @@ public class TargetLock {
try (Connection conn = DriverManager.getConnection(lockProps.getDbUrl(), lockProps.getDbUser(),
lockProps.getDbPwd());
-
+
PreparedStatement selectStatement = conn
- .prepareStatement("SELECT * FROM pooling.locks WHERE resourceId = ? AND expirationTime >= ?");) {
- {
- selectStatement.setString(1, this.resourceId);
- selectStatement.setLong(2, System.currentTimeMillis());
- ResultSet result = selectStatement.executeQuery();
+ .prepareStatement("SELECT * FROM pooling.locks WHERE resourceId = ? AND expirationTime >= ?")) {
+ selectStatement.setString(1, this.resourceId);
+ selectStatement.setLong(2, System.currentTimeMillis());
+ try (ResultSet result = selectStatement.executeQuery()) {
// This will return true if the
// query returned at least one row
return result.first();
-
}
- } catch (SQLException e) {
+ }
+
+ catch (SQLException e) {
logger.error("error in TargetLock.isActive()", e);
return false;
}
diff --git a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java
index 2dc2ceb8..b01d9676 100644
--- a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java
+++ b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java
@@ -25,10 +25,11 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.distributed.locking.DistributedLockingFeature;
+import org.onap.policy.drools.core.lock.PolicyResourceLockFeatureAPI.OperResult;
import org.onap.policy.drools.persistence.SystemPersistence;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -115,7 +116,7 @@ public class TargetLockTest {
}
// Grab reference to heartbeat object
- Heartbeat heartbeat = distLockFeat.getHeartbeat();
+ Heartbeat heartbeat = DistributedLockingFeature.getHeartbeat();
// Pass heartbeat object countdown latch
try {
@@ -149,16 +150,16 @@ public class TargetLockTest {
public void testUnlock() throws InterruptedException, ExecutionException {
distLockFeat.beforeLock("resource1", "owner1", null);
- assertTrue(distLockFeat.beforeUnlock("resource1", "owner1"));
+ assertEquals(OperResult.OPER_ACCEPTED, distLockFeat.beforeUnlock("resource1", "owner1"));
assertTrue(distLockFeat.beforeLock("resource1", "owner1", null).get());
}
@Test
public void testIsActive() {
- assertFalse(distLockFeat.beforeIsLockedBy("resource1", "owner1"));
+ assertEquals(OperResult.OPER_DENIED, distLockFeat.beforeIsLockedBy("resource1", "owner1"));
distLockFeat.beforeLock("resource1", "owner1", null);
- assertTrue(distLockFeat.beforeIsLockedBy("resource1", "owner1"));
- assertFalse(distLockFeat.beforeIsLockedBy("resource1", "owner2"));
+ assertEquals(OperResult.OPER_ACCEPTED, distLockFeat.beforeIsLockedBy("resource1", "owner1"));
+ assertEquals(OperResult.OPER_DENIED, distLockFeat.beforeIsLockedBy("resource1", "owner2"));
// isActive on expiredLock
try (PreparedStatement updateStatement = conn
@@ -172,12 +173,12 @@ public class TargetLockTest {
throw new RuntimeException(e);
}
- assertFalse(distLockFeat.beforeIsLockedBy("resource1", "owner1"));
+ assertEquals(OperResult.OPER_DENIED, distLockFeat.beforeIsLockedBy("resource1", "owner1"));
distLockFeat.beforeLock("resource1", "owner1", null);
//Unlock record, next isActive attempt should fail
distLockFeat.beforeUnlock("resource1", "owner1");
- assertFalse(distLockFeat.beforeIsLockedBy("resource1", "owner1"));
+ assertEquals(OperResult.OPER_DENIED, distLockFeat.beforeIsLockedBy("resource1", "owner1"));
}
@@ -198,7 +199,7 @@ public class TargetLockTest {
}
//Grab reference to heartbeat object
- Heartbeat heartbeat = distLockFeat.getHeartbeat();
+ Heartbeat heartbeat = DistributedLockingFeature.getHeartbeat();
//Pass heartbeat object countdown latch
try {
@@ -210,22 +211,22 @@ public class TargetLockTest {
//At this point the heartbeat object should hve
//refreshed the lock. assert that resource1 is
//locked
- assertTrue(distLockFeat.beforeIsLocked("resource1"));
+ assertEquals(OperResult.OPER_ACCEPTED, distLockFeat.beforeIsLocked("resource1"));
}
@Test
public void unlockBeforeLock() {
- assertFalse(distLockFeat.beforeUnlock("resource1", "owner1"));
+ assertEquals(OperResult.OPER_DENIED, distLockFeat.beforeUnlock("resource1", "owner1"));
distLockFeat.beforeLock("resource1", "owner1", null);
- assertTrue(distLockFeat.beforeUnlock("resource1", "owner1"));
- assertFalse(distLockFeat.beforeUnlock("resource1", "owner1"));
+ assertEquals(OperResult.OPER_ACCEPTED, distLockFeat.beforeUnlock("resource1", "owner1"));
+ assertEquals(OperResult.OPER_DENIED, distLockFeat.beforeUnlock("resource1", "owner1"));
}
@Test
public void testIsLocked() {
- assertFalse(distLockFeat.beforeIsLocked("resource1"));
+ assertEquals(OperResult.OPER_DENIED, distLockFeat.beforeIsLocked("resource1"));
distLockFeat.beforeLock("resource1", "owner1", null);
- assertTrue(distLockFeat.beforeIsLocked("resource1"));
+ assertEquals(OperResult.OPER_ACCEPTED, distLockFeat.beforeIsLocked("resource1"));
}
diff --git a/feature-eelf/pom.xml b/feature-eelf/pom.xml
index 776ca82f..df7f6805 100644
--- a/feature-eelf/pom.xml
+++ b/feature-eelf/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>feature-eelf</artifactId>
diff --git a/feature-healthcheck/pom.xml b/feature-healthcheck/pom.xml
index bbc9a8d2..18138a60 100644
--- a/feature-healthcheck/pom.xml
+++ b/feature-healthcheck/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>feature-healthcheck</artifactId>
diff --git a/feature-pooling-dmaap/pom.xml b/feature-pooling-dmaap/pom.xml
index 6afbd1f1..9fee2a8d 100644
--- a/feature-pooling-dmaap/pom.xml
+++ b/feature-pooling-dmaap/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>feature-pooling-dmaap</artifactId>
diff --git a/feature-pooling-dmaap/src/test/resources/logback-test.xml b/feature-pooling-dmaap/src/test/resources/logback-test.xml
index 6f745157..45d8201d 100644
--- a/feature-pooling-dmaap/src/test/resources/logback-test.xml
+++ b/feature-pooling-dmaap/src/test/resources/logback-test.xml
@@ -1,3 +1,22 @@
+<!--
+ ============LICENSE_START=======================================================
+ ONAP
+ ================================================================================
+ Copyright (C) 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.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ============LICENSE_END=========================================================
+ -->
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
diff --git a/feature-session-persistence/pom.xml b/feature-session-persistence/pom.xml
index 70d37f23..e5743dc0 100644
--- a/feature-session-persistence/pom.xml
+++ b/feature-session-persistence/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>feature-session-persistence</artifactId>
diff --git a/feature-simulators/pom.xml b/feature-simulators/pom.xml
index 767739bc..6c5cc6f6 100644
--- a/feature-simulators/pom.xml
+++ b/feature-simulators/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>feature-simulators</artifactId>
diff --git a/feature-state-management/pom.xml b/feature-state-management/pom.xml
index ec193282..3815d140 100644
--- a/feature-state-management/pom.xml
+++ b/feature-state-management/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>feature-state-management</artifactId>
diff --git a/feature-test-transaction/pom.xml b/feature-test-transaction/pom.xml
index 5866f1f1..1810de60 100644
--- a/feature-test-transaction/pom.xml
+++ b/feature-test-transaction/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>feature-test-transaction</artifactId>
diff --git a/packages/base/src/files/etc/cron.d/monitor.cron b/packages/base/src/files/etc/cron.d/monitor.cron
index d1160f21..68cb310f 100755
--- a/packages/base/src/files/etc/cron.d/monitor.cron
+++ b/packages/base/src/files/etc/cron.d/monitor.cron
@@ -1 +1,21 @@
+###
+# ============LICENSE_START=======================================================
+# Base Package
+# ================================================================================
+# Copyright (C) 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+
* * * * * export POLICY_HOME=${{POLICY_HOME}}; ${{POLICY_HOME}}/bin/monitor >/dev/null 2>&1
diff --git a/packages/docker/README.md b/packages/docker/README.md
index 41a5c6e2..c8bc6b54 100644
--- a/packages/docker/README.md
+++ b/packages/docker/README.md
@@ -1,3 +1,7 @@
+Copyright 2018 AT&T Intellectual Property. All rights reserved.
+This file is licensed under the CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL LICENSE
+Full license text at https://creativecommons.org/licenses/by/4.0/legalcode
+
To build the policy-drools docker image:
1. Build the policy-drools repository
2. Run: policy-drools/docker-verify.sh or policy-drools/docker-build.sh or policy-drools/docker-merge.sh as required.
diff --git a/packages/docker/pom.xml b/packages/docker/pom.xml
index 5d90809b..8d745d28 100644
--- a/packages/docker/pom.xml
+++ b/packages/docker/pom.xml
@@ -65,27 +65,6 @@
</artifactItems>
</configuration>
</execution>
- <execution>
- <id>copy-apps-zip</id>
- <phase>prepare-package</phase>
- <goals>
- <goal>copy</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.directory}/policy-drools</outputDirectory>
- <overWriteReleases>false</overWriteReleases>
- <overWriteSnapshots>true</overWriteSnapshots>
- <artifactItems>
- <artifactItem>
- <groupId>org.onap.policy.drools-applications.controlloop.packages</groupId>
- <artifactId>apps-controlloop</artifactId>
- <version>${project.version}</version>
- <type>zip</type>
- <destFileName>apps-controlloop.zip</destFileName>
- </artifactItem>
- </artifactItems>
- </configuration>
- </execution>
</executions>
</plugin>
<plugin>
diff --git a/packages/docker/src/main/docker/Dockerfile b/packages/docker/src/main/docker/Dockerfile
index 6d5c4ab7..b06edf1b 100644
--- a/packages/docker/src/main/docker/Dockerfile
+++ b/packages/docker/src/main/docker/Dockerfile
@@ -42,13 +42,12 @@ RUN mkdir -p ${POLICY_HOME}/config ${POLICY_LOGS} ${POLICY_INSTALL}/config && \
WORKDIR ${POLICY_INSTALL}
-COPY install-drools.zip apps-controlloop.zip docker-install.sh do-start.sh wait-for-port.sh ./
+COPY install-drools.zip docker-install.sh do-start.sh wait-for-port.sh ./
VOLUME [ "${POLICY_INSTALL}/config", "${POLICY_HOME}/config" ]
RUN unzip -o install-drools.zip && \
- unzip -o apps-controlloop.zip && \
- rm install-drools.zip apps-controlloop.zip && \
+ rm install-drools.zip && \
chown -R policy:policy * && \
chmod +x *.sh
diff --git a/packages/docker/src/main/docker/do-start.sh b/packages/docker/src/main/docker/do-start.sh
index 5f156979..c1ae41d2 100644
--- a/packages/docker/src/main/docker/do-start.sh
+++ b/packages/docker/src/main/docker/do-start.sh
@@ -1,4 +1,23 @@
#!/bin/bash
+###
+# ============LICENSE_START=======================================================
+#
+# ================================================================================
+# Copyright (C) 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
# skip installation if build.info file is present (restarting an existing container)
if [[ -f ${POLICY_HOME}/etc/build.info ]]; then
@@ -23,6 +42,14 @@ else
find -L ${POLICY_HOME}/config -type l -exec rm -- {} +
fi
+ apps=$(ls config/apps*.zip 2> /dev/null)
+
+ echo "Applications found: ${apps}"
+
+ if [[ -n ${apps} ]]; then
+ unzip -o ${apps}
+ fi
+
echo "docker install at ${PWD}"
./docker-install.sh
diff --git a/packages/docker/src/main/docker/wait-for-port.sh b/packages/docker/src/main/docker/wait-for-port.sh
index 10f08ded..65c6a5c1 100644
--- a/packages/docker/src/main/docker/wait-for-port.sh
+++ b/packages/docker/src/main/docker/wait-for-port.sh
@@ -1,4 +1,23 @@
#!/bin/bash
+###
+# ============LICENSE_START=======================================================
+#
+# ================================================================================
+# Copyright (C) 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
if [[ $# -ne 2 ]]; then
echo "Usage: wait-for-port hostname port" >&2
diff --git a/packages/install/src/files/feature-healthcheck.conf b/packages/install/src/files/feature-healthcheck.conf
index f5c3d071..39b6728c 100644
--- a/packages/install/src/files/feature-healthcheck.conf
+++ b/packages/install/src/files/feature-healthcheck.conf
@@ -1,2 +1,21 @@
+###
+# ============LICENSE_START=======================================================
+# ONAP POLICY
+# ================================================================================
+# Copyright (C) 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
HEALTHCHECK_USER=
HEALTHCHECK_PASSWORD=
diff --git a/packages/install/src/files/policy-management.conf b/packages/install/src/files/policy-management.conf
index 1e5fd76b..12ad0f43 100644
--- a/packages/install/src/files/policy-management.conf
+++ b/packages/install/src/files/policy-management.conf
@@ -1,3 +1,23 @@
+###
+# ============LICENSE_START=======================================================
+# ONAP POLICY
+# ================================================================================
+# Copyright (C) 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+
CONTROLLER_ARTIFACT_ID=policy-management
CONTROLLER_NAME=policy-management-controller
CONTROLLER_PORT=9696
diff --git a/policy-core/pom.xml b/policy-core/pom.xml
index 78f9c737..06329887 100644
--- a/policy-core/pom.xml
+++ b/policy-core/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<dependencies>
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/LockRequestFuture.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/LockRequestFuture.java
index 46d1ff2d..a2e9e62e 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/lock/LockRequestFuture.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/LockRequestFuture.java
@@ -183,7 +183,7 @@ public class LockRequestFuture implements Future<Boolean> {
* @return {@code true} if the lock was acquired, {@code false} if it was denied
*/
@Override
- public Boolean get() throws CancellationException, InterruptedException {
+ public Boolean get() throws InterruptedException {
waiter.await();
switch (state.get()) {
@@ -202,7 +202,7 @@ public class LockRequestFuture implements Future<Boolean> {
*/
@Override
public Boolean get(long timeout, TimeUnit unit)
- throws CancellationException, InterruptedException, TimeoutException {
+ throws InterruptedException, TimeoutException {
if (!waiter.await(timeout, unit)) {
throw new TimeoutException("lock request did not complete in time");
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPI.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPI.java
index 718ed5e9..d4e7bee9 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPI.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPI.java
@@ -46,9 +46,9 @@ public interface PolicyResourceLockFeatureAPI extends OrderedService {
new OrderedServiceImpl<>(PolicyResourceLockFeatureAPI.class);
/**
- * Callback that an implementer invokes when a lock is acquired (or denied),
- * asynchronously. The implementer invokes the method to indicate that the lock was
- * acquired (or denied).
+ * Callback that an implementer invokes, asynchronously, when a lock is acquired (or
+ * denied). The implementer invokes the method to indicate that the lock was acquired
+ * (or denied).
*/
@FunctionalInterface
public static interface Callback {
@@ -62,6 +62,31 @@ public interface PolicyResourceLockFeatureAPI extends OrderedService {
}
/**
+ * Result of a requested operation.
+ */
+ public enum OperResult {
+
+ /**
+ * The implementer accepted the request; no additional locking logic should be
+ * performed.
+ */
+ OPER_ACCEPTED,
+
+ /**
+ * The implementer denied the request; no additional locking logic should be
+ * performed.
+ */
+ OPER_DENIED,
+
+
+ /**
+ * The implementer did not handle the request; additional locking logic <i>should
+ * be<i> performed.
+ */
+ OPER_UNHANDLED
+ }
+
+ /**
* This method is called before a lock is acquired on a resource. If a callback is
* provided, and the implementer is unable to acquire the lock immediately, then the
* implementer will invoke the callback once the lock is acquired. If the implementer
@@ -112,21 +137,11 @@ public interface PolicyResourceLockFeatureAPI extends OrderedService {
*
* @param resourceId
* @param owner
- * <dt>true</dt>
- * <dd>the implementer handled the request and found the resource to be locked
- * by the given owner; the resource was unlocked and no additional locking
- * logic should be performed</dd>
- * <dt>false</dt>
- * <dd>the implementer handled the request and found the resource was not
- * locked by given the owner; no additional locking logic should be
- * performed</dd>
- * <dt>null</dt>
- * <dd>the implementer did not handle the request; additional locking logic
- * <i>should be</i> performed
- * </dl>
+ * @return the result, where <b>OPER_DENIED</b> indicates that the lock is not
+ * currently held by the given owner
*/
- public default Boolean beforeUnlock(String resourceId, String owner) {
- return null;
+ public default OperResult beforeUnlock(String resourceId, String owner) {
+ return OperResult.OPER_UNHANDLED;
}
/**
@@ -147,21 +162,11 @@ public interface PolicyResourceLockFeatureAPI extends OrderedService {
* This method is called before a check is made to determine if a resource is locked.
*
* @param resourceId
- * @return
- * <dl>
- * <dt>true</dt>
- * <dd>the implementer handled the request and found the resource to be
- * locked; no additional locking logic should be performed</dd>
- * <dt>false</dt>
- * <dd>the implementer handled the request and found the resource was not
- * locked; no additional locking logic should be performed</dd>
- * <dt>null</dt>
- * <dd>the implementer did not handle the request; additional locking logic
- * <i>should be</i> performed
- * </dl>
+ * @return the result, where <b>OPER_ACCEPTED</b> indicates that the resource is
+ * locked, while <b>OPER_DENIED</b> indicates that it is not
*/
- public default Boolean beforeIsLocked(String resourceId) {
- return null;
+ public default OperResult beforeIsLocked(String resourceId) {
+ return OperResult.OPER_UNHANDLED;
}
/**
@@ -170,21 +175,11 @@ public interface PolicyResourceLockFeatureAPI extends OrderedService {
*
* @param resourceId
* @param owner
- * @return
- * <dl>
- * <dt>true</dt>
- * <dd>the implementer handled the request and found the resource to be locked
- * by the given owner; no additional locking logic should be performed</dd>
- * <dt>false</dt>
- * <dd>the implementer handled the request and found the resource was not
- * locked by given the owner; no additional locking logic should be
- * performed</dd>
- * <dt>null</dt>
- * <dd>the implementer did not handle the request; additional locking logic
- * <i>should be</i> performed
- * </dl>
+ * @return the result, where <b>OPER_ACCEPTED</b> indicates that the resource is
+ * locked by the given owner, while <b>OPER_DENIED</b> indicates that it is
+ * not
*/
- public default Boolean beforeIsLockedBy(String resourceId, String owner) {
- return null;
+ public default OperResult beforeIsLockedBy(String resourceId, String owner) {
+ return OperResult.OPER_UNHANDLED;
}
}
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java
index d51f2b91..97e7242d 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java
@@ -26,7 +26,9 @@ import static org.onap.policy.drools.core.lock.LockRequestFuture.makeNullArgExce
import java.util.List;
import java.util.concurrent.Future;
import java.util.function.Function;
+import java.util.function.Supplier;
import org.onap.policy.drools.core.lock.PolicyResourceLockFeatureAPI.Callback;
+import org.onap.policy.drools.core.lock.PolicyResourceLockFeatureAPI.OperResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,7 +42,7 @@ public class PolicyResourceLockManager extends SimpleLockManager {
/**
* Used to access various objects.
*/
- public static Factory factory = new Factory();
+ private static Factory factory = new Factory();
/**
* Used by junit tests.
@@ -105,17 +107,16 @@ public class PolicyResourceLockManager extends SimpleLockManager {
throw makeNullArgException(MSG_NULL_OWNER);
}
- Boolean result = doIntercept(null, impl -> impl.beforeUnlock(resourceId, owner));
- if (result != null) {
- return result;
- }
- // implementer didn't do the work - use superclass
- boolean unlocked = super.unlock(resourceId, owner);
+ return doBoolIntercept(impl -> impl.beforeUnlock(resourceId, owner), () -> {
+
+ // implementer didn't do the work - defer to the superclass
+ boolean unlocked = super.unlock(resourceId, owner);
- doIntercept(false, impl -> impl.afterUnlock(resourceId, owner, unlocked));
+ doIntercept(false, impl -> impl.afterUnlock(resourceId, owner, unlocked));
- return unlocked;
+ return unlocked;
+ });
}
/**
@@ -128,12 +129,12 @@ public class PolicyResourceLockManager extends SimpleLockManager {
throw makeNullArgException(MSG_NULL_RESOURCE_ID);
}
- Boolean result = doIntercept(null, impl -> impl.beforeIsLocked(resourceId));
- if (result != null) {
- return result;
- }
- return super.isLocked(resourceId);
+ return doBoolIntercept(impl -> impl.beforeIsLocked(resourceId), () ->
+
+ // implementer didn't do the work - defer to the superclass
+ super.isLocked(resourceId)
+ );
}
/**
@@ -150,12 +151,31 @@ public class PolicyResourceLockManager extends SimpleLockManager {
throw makeNullArgException(MSG_NULL_OWNER);
}
- Boolean result = doIntercept(null, impl -> impl.beforeIsLockedBy(resourceId, owner));
- if (result != null) {
- return result;
+ return doBoolIntercept(impl -> impl.beforeIsLockedBy(resourceId, owner), () ->
+
+ // implementer didn't do the work - defer to the superclass
+ super.isLockedBy(resourceId, owner)
+ );
+ }
+
+ /**
+ * Applies a function to each implementer of the lock feature. Returns as soon as one
+ * of them returns a result other than <b>OPER_UNHANDLED</b>. If they all return
+ * <b>OPER_UNHANDLED</b>, then it returns the result of applying the default function.
+ *
+ * @param interceptFunc
+ * @param defaultFunc
+ * @return {@code true} if success, {@code false} otherwise
+ */
+ private boolean doBoolIntercept(Function<PolicyResourceLockFeatureAPI, OperResult> interceptFunc,
+ Supplier<Boolean> defaultFunc) {
+
+ OperResult result = doIntercept(OperResult.OPER_UNHANDLED, interceptFunc);
+ if (result != OperResult.OPER_UNHANDLED) {
+ return (result == OperResult.OPER_ACCEPTED);
}
- return super.isLockedBy(resourceId, owner);
+ return defaultFunc.get();
}
/**
@@ -168,7 +188,7 @@ public class PolicyResourceLockManager extends SimpleLockManager {
* @return first non-null value returned by an implementer, <i>continueValue<i/> if
* they all returned <i>continueValue<i/>
*/
- public static <T> T doIntercept(T continueValue, Function<PolicyResourceLockFeatureAPI, T> func) {
+ private static <T> T doIntercept(T continueValue, Function<PolicyResourceLockFeatureAPI, T> func) {
for (PolicyResourceLockFeatureAPI impl : factory.getImplementers()) {
try {
@@ -189,7 +209,16 @@ public class PolicyResourceLockManager extends SimpleLockManager {
* Initialization-on-demand holder idiom.
*/
private static class Singleton {
+
private static final PolicyResourceLockManager instance = new PolicyResourceLockManager();
+
+ /**
+ * Not invoked.
+ */
+ private Singleton() {
+ super();
+ }
+
}
/**
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/SimpleLockManager.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/SimpleLockManager.java
index 14cffaab..c2d58b85 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/lock/SimpleLockManager.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/SimpleLockManager.java
@@ -49,9 +49,6 @@ public class SimpleLockManager {
super();
}
- // TODO: for ease of use by clients, should we always invoke the callback, even though
- // this is synchronous?
-
/**
* Attempts to lock a resource. This method ignores the callback and always returns a
* {@link CompletedLockRequest}.
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/LockRequestFutureTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/LockRequestFutureTest.java
index 883778eb..2dd90f00 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/LockRequestFutureTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/lock/LockRequestFutureTest.java
@@ -80,13 +80,13 @@ public class LockRequestFutureTest {
public void testLockRequestFutureStringStringBoolean_ArgEx() throws Exception {
// null resource id
- IllegalArgumentException ex = expectException(IllegalArgumentException.class,
- xxx -> new LockRequestFuture(null, OWNER, true));
+ IllegalArgumentException ex =
+ expectException(IllegalArgumentException.class, () -> new LockRequestFuture(null, OWNER, true));
assertEquals("null resourceId", ex.getMessage());
// null owner
- ex = expectException(IllegalArgumentException.class, xxx -> new LockRequestFuture(RESOURCE, null, true));
+ ex = expectException(IllegalArgumentException.class, () -> new LockRequestFuture(RESOURCE, null, true));
assertEquals("null owner", ex.getMessage());
}
@@ -108,12 +108,12 @@ public class LockRequestFutureTest {
// null resource id
IllegalArgumentException ex = expectException(IllegalArgumentException.class,
- xxx -> new LockRequestFuture(null, OWNER, callback));
+ () -> new LockRequestFuture(null, OWNER, callback));
assertEquals("null resourceId", ex.getMessage());
// null owner
- ex = expectException(IllegalArgumentException.class, xxx -> new LockRequestFuture(RESOURCE, null, callback));
+ ex = expectException(IllegalArgumentException.class, () -> new LockRequestFuture(RESOURCE, null, callback));
assertEquals("null owner", ex.getMessage());
@@ -141,7 +141,7 @@ public class LockRequestFutureTest {
assertTrue(fut.isDone());
// should not block now
- expectException(CancellationException.class, xxx -> fut.get(0, TimeUnit.SECONDS));
+ expectException(CancellationException.class, () -> fut.get(0, TimeUnit.SECONDS));
}
@@ -153,7 +153,7 @@ public class LockRequestFutureTest {
assertFalse(fut.cancel(true));
assertTrue(fut.isDone());
- expectException(CancellationException.class, xxx -> fut.get(0, TimeUnit.SECONDS));
+ expectException(CancellationException.class, () -> fut.get(0, TimeUnit.SECONDS));
}
@Test
@@ -201,7 +201,7 @@ public class LockRequestFutureTest {
assertFalse(fut.setLocked(false));
assertTrue(fut.isDone());
- expectException(CancellationException.class, xxx -> fut.get(0, TimeUnit.SECONDS));
+ expectException(CancellationException.class, () -> fut.get(0, TimeUnit.SECONDS));
}
@Test
@@ -296,43 +296,25 @@ public class LockRequestFutureTest {
@Test
public void testGet_Cancelled() throws Exception {
- new Thread() {
- @Override
- public void run() {
- fut.cancel(false);
- }
- }.start();
-
- expectException(CancellationException.class, xxx -> fut.get());
+ new Thread(() -> fut.cancel(false)).start();
+ expectException(CancellationException.class, () -> fut.get());
}
@Test
public void testGet_Acquired() throws Exception {
- new Thread() {
- @Override
- public void run() {
- fut.setLocked(true);
- }
- }.start();
-
+ new Thread(() -> fut.setLocked(true)).start();
assertTrue(fut.get());
}
@Test
public void testGet_Denied() throws Exception {
- new Thread() {
- @Override
- public void run() {
- fut.setLocked(false);
- }
- }.start();
-
+ new Thread(() -> fut.setLocked(false)).start();
assertFalse(fut.get());
}
@Test
public void testGetLongTimeUnit() throws Exception {
- expectException(TimeoutException.class, xxx -> fut.get(0, TimeUnit.SECONDS));
+ expectException(TimeoutException.class, () -> fut.get(0, TimeUnit.SECONDS));
fut.setLocked(true);
assertTrue(fut.get(0, TimeUnit.SECONDS));
@@ -340,43 +322,25 @@ public class LockRequestFutureTest {
@Test
public void testGetLongTimeUnit_Timeout() throws Exception {
- expectException(TimeoutException.class, xxx -> fut.get(0, TimeUnit.SECONDS));
- expectException(TimeoutException.class, xxx -> fut.get(2, TimeUnit.MILLISECONDS));
+ expectException(TimeoutException.class, () -> fut.get(0, TimeUnit.SECONDS));
+ expectException(TimeoutException.class, () -> fut.get(2, TimeUnit.MILLISECONDS));
}
@Test
public void testGetLongTimeUnit_Cancelled() throws Exception {
- new Thread() {
- @Override
- public void run() {
- fut.cancel(false);
- }
- }.start();
-
- expectException(CancellationException.class, xxx -> fut.get(WAIT_SEC, TimeUnit.SECONDS));
+ new Thread(() -> fut.cancel(false)).start();
+ expectException(CancellationException.class, () -> fut.get(WAIT_SEC, TimeUnit.SECONDS));
}
@Test
public void testGetLongTimeUnit_Acquired() throws Exception {
- new Thread() {
- @Override
- public void run() {
- fut.setLocked(true);
- }
- }.start();
-
+ new Thread(() -> fut.setLocked(true)).start();
assertTrue(fut.get(WAIT_SEC, TimeUnit.SECONDS));
}
@Test
public void testGetLongTimeUnit_Denied() throws Exception {
- new Thread() {
- @Override
- public void run() {
- fut.setLocked(false);
- }
- }.start();
-
+ new Thread(() -> fut.setLocked(false)).start();
assertFalse(fut.get(WAIT_SEC, TimeUnit.SECONDS));
}
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPITest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPITest.java
index 5a826bb7..57adc847 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPITest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPITest.java
@@ -20,10 +20,12 @@
package org.onap.policy.drools.core.lock;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.drools.core.lock.PolicyResourceLockFeatureAPI.OperResult;
public class PolicyResourceLockFeatureAPITest {
@@ -55,7 +57,7 @@ public class PolicyResourceLockFeatureAPITest {
@Test
public void testBeforeUnlock() {
- assertNull(api.beforeUnlock(RESOURCE_ID, OWNER));
+ assertEquals(OperResult.OPER_UNHANDLED, api.beforeUnlock(RESOURCE_ID, OWNER));
}
@Test
@@ -66,11 +68,11 @@ public class PolicyResourceLockFeatureAPITest {
@Test
public void testBeforeIsLocked() {
- assertNull(api.beforeIsLocked(RESOURCE_ID));
+ assertEquals(OperResult.OPER_UNHANDLED, api.beforeIsLocked(RESOURCE_ID));
}
@Test
public void testBeforeIsLockedBy() {
- assertNull(api.beforeIsLockedBy(RESOURCE_ID, OWNER));
+ assertEquals(OperResult.OPER_UNHANDLED, api.beforeIsLockedBy(RESOURCE_ID, OWNER));
}
}
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockManagerTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockManagerTest.java
index 2f8b5f83..fe883acf 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockManagerTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockManagerTest.java
@@ -42,6 +42,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.drools.core.lock.PolicyResourceLockFeatureAPI.Callback;
+import org.onap.policy.drools.core.lock.PolicyResourceLockFeatureAPI.OperResult;
import org.onap.policy.drools.core.lock.PolicyResourceLockManager.Factory;
public class PolicyResourceLockManagerTest {
@@ -111,9 +112,9 @@ public class PolicyResourceLockManagerTest {
*/
private void initImplementer(PolicyResourceLockFeatureAPI impl) {
when(impl.beforeLock(anyString(), anyString(), any(Callback.class))).thenReturn(null);
- when(impl.beforeUnlock(anyString(), anyString())).thenReturn(null);
- when(impl.beforeIsLocked(anyString())).thenReturn(null);
- when(impl.beforeIsLockedBy(anyString(), anyString())).thenReturn(null);
+ when(impl.beforeUnlock(anyString(), anyString())).thenReturn(OperResult.OPER_UNHANDLED);
+ when(impl.beforeIsLocked(anyString())).thenReturn(OperResult.OPER_UNHANDLED);
+ when(impl.beforeIsLockedBy(anyString(), anyString())).thenReturn(OperResult.OPER_UNHANDLED);
}
@Test
@@ -147,10 +148,10 @@ public class PolicyResourceLockManagerTest {
@Test
public void testLock_ArgEx() {
IllegalArgumentException ex =
- expectException(IllegalArgumentException.class, xxx -> mgr.lock(null, OWNER1, callback1));
+ expectException(IllegalArgumentException.class, () -> mgr.lock(null, OWNER1, callback1));
assertEquals(NULL_RESOURCE_ID, ex.getMessage());
- ex = expectException(IllegalArgumentException.class, xxx -> mgr.lock(RESOURCE_A, null, callback1));
+ ex = expectException(IllegalArgumentException.class, () -> mgr.lock(RESOURCE_A, null, callback1));
assertEquals(NULL_OWNER, ex.getMessage());
// this should not throw an exception
@@ -250,10 +251,10 @@ public class PolicyResourceLockManagerTest {
@Test
public void testUnlock_ArgEx() {
- IllegalArgumentException ex = expectException(IllegalArgumentException.class, xxx -> mgr.unlock(null, OWNER1));
+ IllegalArgumentException ex = expectException(IllegalArgumentException.class, () -> mgr.unlock(null, OWNER1));
assertEquals(NULL_RESOURCE_ID, ex.getMessage());
- ex = expectException(IllegalArgumentException.class, xxx -> mgr.unlock(RESOURCE_A, null));
+ ex = expectException(IllegalArgumentException.class, () -> mgr.unlock(RESOURCE_A, null));
assertEquals(NULL_OWNER, ex.getMessage());
}
@@ -263,7 +264,7 @@ public class PolicyResourceLockManagerTest {
mgr.lock(RESOURCE_A, OWNER1, null);
// have impl1 intercept
- when(impl1.beforeUnlock(RESOURCE_A, OWNER1)).thenReturn(true);
+ when(impl1.beforeUnlock(RESOURCE_A, OWNER1)).thenReturn(OperResult.OPER_ACCEPTED);
assertTrue(mgr.unlock(RESOURCE_A, OWNER1));
@@ -280,7 +281,7 @@ public class PolicyResourceLockManagerTest {
mgr.lock(RESOURCE_A, OWNER1, null);
// have impl1 intercept
- when(impl1.beforeUnlock(RESOURCE_A, OWNER1)).thenReturn(false);
+ when(impl1.beforeUnlock(RESOURCE_A, OWNER1)).thenReturn(OperResult.OPER_DENIED);
assertFalse(mgr.unlock(RESOURCE_A, OWNER1));
@@ -365,7 +366,7 @@ public class PolicyResourceLockManagerTest {
@Test
public void testIsLocked_ArgEx() {
- IllegalArgumentException ex = expectException(IllegalArgumentException.class, xxx -> mgr.isLocked(null));
+ IllegalArgumentException ex = expectException(IllegalArgumentException.class, () -> mgr.isLocked(null));
assertEquals(NULL_RESOURCE_ID, ex.getMessage());
}
@@ -373,7 +374,7 @@ public class PolicyResourceLockManagerTest {
public void testIsLocked_BeforeIntercepted_True() {
// have impl1 intercept
- when(impl1.beforeIsLocked(RESOURCE_A)).thenReturn(true);
+ when(impl1.beforeIsLocked(RESOURCE_A)).thenReturn(OperResult.OPER_ACCEPTED);;
assertTrue(mgr.isLocked(RESOURCE_A));
@@ -388,7 +389,7 @@ public class PolicyResourceLockManagerTest {
mgr.lock(RESOURCE_A, OWNER1, null);
// have impl1 intercept
- when(impl1.beforeIsLocked(RESOURCE_A)).thenReturn(false);
+ when(impl1.beforeIsLocked(RESOURCE_A)).thenReturn(OperResult.OPER_DENIED);
assertFalse(mgr.isLocked(RESOURCE_A));
@@ -420,10 +421,10 @@ public class PolicyResourceLockManagerTest {
@Test
public void testIsLockedBy_ArgEx() {
IllegalArgumentException ex =
- expectException(IllegalArgumentException.class, xxx -> mgr.isLockedBy(null, OWNER1));
+ expectException(IllegalArgumentException.class, () -> mgr.isLockedBy(null, OWNER1));
assertEquals(NULL_RESOURCE_ID, ex.getMessage());
- ex = expectException(IllegalArgumentException.class, xxx -> mgr.isLockedBy(RESOURCE_A, null));
+ ex = expectException(IllegalArgumentException.class, () -> mgr.isLockedBy(RESOURCE_A, null));
assertEquals(NULL_OWNER, ex.getMessage());
}
@@ -431,7 +432,7 @@ public class PolicyResourceLockManagerTest {
public void testIsLockedBy_BeforeIntercepted_True() {
// have impl1 intercept
- when(impl1.beforeIsLockedBy(RESOURCE_A, OWNER1)).thenReturn(true);
+ when(impl1.beforeIsLockedBy(RESOURCE_A, OWNER1)).thenReturn(OperResult.OPER_ACCEPTED);;
assertTrue(mgr.isLockedBy(RESOURCE_A, OWNER1));
@@ -446,7 +447,7 @@ public class PolicyResourceLockManagerTest {
mgr.lock(RESOURCE_A, OWNER1, null);
// have impl1 intercept
- when(impl1.beforeIsLockedBy(RESOURCE_A, OWNER1)).thenReturn(false);
+ when(impl1.beforeIsLockedBy(RESOURCE_A, OWNER1)).thenReturn(OperResult.OPER_DENIED);
assertFalse(mgr.isLockedBy(RESOURCE_A, OWNER1));
@@ -479,7 +480,7 @@ public class PolicyResourceLockManagerTest {
@Test
public void testDoIntercept_Impl1() {
- when(impl1.beforeIsLocked(RESOURCE_A)).thenReturn(true);
+ when(impl1.beforeIsLocked(RESOURCE_A)).thenReturn(OperResult.OPER_ACCEPTED);;
assertTrue(mgr.isLocked(RESOURCE_A));
@@ -489,7 +490,7 @@ public class PolicyResourceLockManagerTest {
@Test
public void testDoIntercept_Impl2() {
- when(impl2.beforeIsLocked(RESOURCE_A)).thenReturn(true);
+ when(impl2.beforeIsLocked(RESOURCE_A)).thenReturn(OperResult.OPER_ACCEPTED);;
assertTrue(mgr.isLocked(RESOURCE_A));
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/SimpleLockManagerTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/SimpleLockManagerTest.java
index 6abc5bf9..833e1c7d 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/SimpleLockManagerTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/lock/SimpleLockManagerTest.java
@@ -98,10 +98,10 @@ public class SimpleLockManagerTest {
@Test
public void testLock_ArgEx() {
IllegalArgumentException ex =
- expectException(IllegalArgumentException.class, xxx -> mgr.lock(null, OWNER1, null));
+ expectException(IllegalArgumentException.class, () -> mgr.lock(null, OWNER1, null));
assertEquals(NULL_RESOURCE_ID, ex.getMessage());
- ex = expectException(IllegalArgumentException.class, xxx -> mgr.lock(RESOURCE_A, null, null));
+ ex = expectException(IllegalArgumentException.class, () -> mgr.lock(RESOURCE_A, null, null));
assertEquals(NULL_OWNER, ex.getMessage());
// this should not throw an exception
@@ -118,10 +118,10 @@ public class SimpleLockManagerTest {
@Test
public void testUnlock_ArgEx() {
- IllegalArgumentException ex = expectException(IllegalArgumentException.class, xxx -> mgr.unlock(null, OWNER1));
+ IllegalArgumentException ex = expectException(IllegalArgumentException.class, () -> mgr.unlock(null, OWNER1));
assertEquals(NULL_RESOURCE_ID, ex.getMessage());
- ex = expectException(IllegalArgumentException.class, xxx -> mgr.unlock(RESOURCE_A, null));
+ ex = expectException(IllegalArgumentException.class, () -> mgr.unlock(RESOURCE_A, null));
assertEquals(NULL_OWNER, ex.getMessage());
}
@@ -156,7 +156,7 @@ public class SimpleLockManagerTest {
@Test
public void testIsLocked_ArgEx() {
- IllegalArgumentException ex = expectException(IllegalArgumentException.class, xxx -> mgr.isLocked(null));
+ IllegalArgumentException ex = expectException(IllegalArgumentException.class, () -> mgr.isLocked(null));
assertEquals(NULL_RESOURCE_ID, ex.getMessage());
}
@@ -181,10 +181,10 @@ public class SimpleLockManagerTest {
@Test
public void testIsLockedBy_ArgEx() {
IllegalArgumentException ex =
- expectException(IllegalArgumentException.class, xxx -> mgr.isLockedBy(null, OWNER1));
+ expectException(IllegalArgumentException.class, () -> mgr.isLockedBy(null, OWNER1));
assertEquals(NULL_RESOURCE_ID, ex.getMessage());
- ex = expectException(IllegalArgumentException.class, xxx -> mgr.isLockedBy(RESOURCE_A, null));
+ ex = expectException(IllegalArgumentException.class, () -> mgr.isLockedBy(RESOURCE_A, null));
assertEquals(NULL_OWNER, ex.getMessage());
}
@@ -221,34 +221,31 @@ public class SimpleLockManagerTest {
for (int x = 0; x < nthreads; ++x) {
String owner = "owner." + x;
- Thread t = new Thread() {
- @Override
- public void run() {
+ Thread t = new Thread(() -> {
- for (int y = 0; y < nlocks; ++y) {
- String res = resources[y % resources.length];
+ for (int y = 0; y < nlocks; ++y) {
+ String res = resources[y % resources.length];
- try {
- // some locks will be acquired, some denied
- mgr.lock(res, owner, null).get();
+ try {
+ // some locks will be acquired, some denied
+ mgr.lock(res, owner, null).get();
- // do some "work"
- stopper.await(1L, TimeUnit.MILLISECONDS);
+ // do some "work"
+ stopper.await(1L, TimeUnit.MILLISECONDS);
- mgr.unlock(res, owner);
+ mgr.unlock(res, owner);
- } catch (CancellationException | ExecutionException e) {
- nfail.incrementAndGet();
+ } catch (CancellationException | ExecutionException e) {
+ nfail.incrementAndGet();
- } catch (InterruptedException expected) {
- Thread.currentThread().interrupt();
- break;
- }
+ } catch (InterruptedException expected) {
+ Thread.currentThread().interrupt();
+ break;
}
-
- completed.countDown();
}
- };
+
+ completed.countDown();
+ });
t.setDaemon(true);
threads.add(t);
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/TestUtils.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/TestUtils.java
index 2e353936..f843f6ab 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/TestUtils.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/lock/TestUtils.java
@@ -31,7 +31,7 @@ public class TestUtils {
*/
public static <T> T expectException(Class<T> clazz, VoidFunction func) {
try {
- func.apply(null);
+ func.apply();
throw new AssertionError("missing exception");
} catch (Exception e) {
@@ -50,10 +50,6 @@ public class TestUtils {
@FunctionalInterface
public static interface VoidFunction {
- /**
- *
- * @param arg always {@code null}
- */
- public void apply(Void arg) throws Exception;
+ public void apply() throws Exception;
}
}
diff --git a/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/rules.drl b/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/rules.drl
index 9dac208b..426c4df9 100644
--- a/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/rules.drl
+++ b/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/rules.drl
@@ -1,4 +1,23 @@
-package org.onap.policy.drools.core.test;
+/*
+ * ============LICENSE_START=======================================================
+ * policy-core
+ * ================================================================================
+ * Copyright (C) 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+ package org.onap.policy.drools.core.test;
rule "Initialization"
when
diff --git a/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/rules.drl b/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/rules.drl
index e69b6597..a53047a2 100644
--- a/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/rules.drl
+++ b/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/rules.drl
@@ -1,3 +1,22 @@
+/*
+ * ============LICENSE_START=======================================================
+ * policy-core
+ * ================================================================================
+ * Copyright (C) 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
package org.onap.policy.drools.core.test;
rule "Initialization"
diff --git a/policy-endpoints/pom.xml b/policy-endpoints/pom.xml
index 9f8cabc9..f43b4c93 100644
--- a/policy-endpoints/pom.xml
+++ b/policy-endpoints/pom.xml
@@ -2,7 +2,7 @@
============LICENSE_START=======================================================
ONAP Policy Engine - Drools PDP
================================================================================
- 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.
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>policy-endpoints</artifactId>
@@ -51,10 +51,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
- <exclusion>
- <groupId>com.att.nsa</groupId>
- <artifactId>saClientLibrary</artifactId>
- </exclusion>
</exclusions>
</dependency>
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 db240b3d..70c37d55 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
@@ -122,28 +122,40 @@ 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) {
+ this(servers, topic, apiKey, apiSecret, null, null,
+ consumerGroup, consumerInstance, fetchTimeout, fetchLimit,
+ useHttps, useSelfSignedCerts);
+ }
+
+ public CambriaConsumerWrapper(List<String> servers, String topic, String apiKey,
+ String apiSecret, String username, String password,
+ String consumerGroup, String consumerInstance, int fetchTimeout,
+ int fetchLimit, boolean useHttps, boolean useSelfSignedCerts) {
this.fetchTimeout = fetchTimeout;
this.builder = new CambriaClientBuilders.ConsumerBuilder();
+ builder.knownAs(consumerGroup, consumerInstance).usingHosts(servers).onTopic(topic)
+ .waitAtServer(fetchTimeout).receivingAtMost(fetchLimit);
+
+ // Set read timeout to fetch timeout + 30 seconds (TBD: this should be configurable)
+ builder.withSocketTimeout(fetchTimeout + 30000);
+
if (useHttps) {
+ builder.usingHttps();
if (useSelfSignedCerts) {
- builder.knownAs(consumerGroup, consumerInstance).usingHosts(servers).onTopic(topic)
- .waitAtServer(fetchTimeout).receivingAtMost(fetchLimit).usingHttps()
- .allowSelfSignedCertificates();
- } else {
- builder.knownAs(consumerGroup, consumerInstance).usingHosts(servers).onTopic(topic)
- .waitAtServer(fetchTimeout).receivingAtMost(fetchLimit).usingHttps();
+ builder.allowSelfSignedCertificates();
}
- } else {
- builder.knownAs(consumerGroup, consumerInstance).usingHosts(servers).onTopic(topic)
- .waitAtServer(fetchTimeout).receivingAtMost(fetchLimit);
}
if (apiKey != null && !apiKey.isEmpty() && apiSecret != null && !apiSecret.isEmpty()) {
- builder.authenticatedBy(apiKey, apiSecret);
+ builder.authenticatedBy(apiKey, apiSecret);
+ }
+
+ if (username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
+ builder.authenticatedByHttp(username, password);
}
try {
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 852c9c16..8e18bba8 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
@@ -74,18 +74,23 @@ public interface BusPublisher {
public CambriaPublisherWrapper(List<String> servers, String topic,
String apiKey,
String apiSecret, boolean useHttps) {
+ this(servers, topic, apiKey, apiSecret, null, null, useHttps);
+ }
+
+ public CambriaPublisherWrapper(List<String> servers, String topic,
+ String apiKey, String apiSecret,
+ String username, String password,
+ boolean useHttps) {
+
PublisherBuilder builder = new CambriaClientBuilders.PublisherBuilder();
-
- if (useHttps){
-
- builder.usingHosts(servers)
- .onTopic(topic)
- .usingHttps();
- }
- else{
- builder.usingHosts(servers)
- .onTopic(topic);
+ builder.usingHosts(servers).onTopic(topic);
+
+ // Set read timeout to 30 seconds (TBD: this should be configurable)
+ builder.withSocketTimeout(30000);
+
+ if (useHttps){
+ builder.usingHttps();
}
@@ -94,6 +99,11 @@ public interface BusPublisher {
builder.authenticatedBy(apiKey, apiSecret);
}
+ if (username != null && !username.isEmpty() &&
+ password != null && !password.isEmpty()) {
+ builder.authenticatedByHttp(username, password);
+ }
+
try {
this.publisher = builder.build();
} catch (MalformedURLException | GeneralSecurityException e) {
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java
index 912607fd..718bb21d 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java
@@ -2,7 +2,7 @@
* ============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.
@@ -114,10 +114,11 @@ public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTop
(this.longitude == null || this.longitude.isEmpty()) &&
(this.partner == null || this.partner.isEmpty())) {
this.publisher =
- new BusPublisher.DmaapAafPublisherWrapper(this.servers,
+ new BusPublisher.CambriaPublisherWrapper(this.servers,
this.topic,
- this.userName,
- this.password, this.useHttps);
+ this.apiKey, this.apiSecret,
+ this.userName, this.password,
+ this.useHttps);
} else {
this.publisher =
new BusPublisher.DmaapDmePublisherWrapper(this.servers, this.topic,
@@ -148,4 +149,4 @@ public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTop
return builder.toString();
}
-} \ No newline at end of file
+}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
index 6c1bc8a0..88d67fd2 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
@@ -2,7 +2,7 @@
* ============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.
@@ -162,11 +162,12 @@ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource
(this.longitude == null || this.longitude.isEmpty()) &&
(this.partner == null || this.partner.isEmpty())) {
this.consumer =
- new BusConsumer.DmaapAafConsumerWrapper(this.servers, this.topic,
+ new BusConsumer.CambriaConsumerWrapper(this.servers, this.topic,
this.apiKey, this.apiSecret,
this.userName, this.password,
this.consumerGroup, this.consumerInstance,
- this.fetchTimeout, this.fetchLimit, this.useHttps);
+ this.fetchTimeout, this.fetchLimit,
+ this.useHttps, this.allowSelfSignedCerts);
} else {
this.consumer =
new BusConsumer.DmaapDmeConsumerWrapper(this.servers, this.topic,
diff --git a/policy-endpoints/src/test/resources/logback-test.xml b/policy-endpoints/src/test/resources/logback-test.xml
index 6f745157..b3feef90 100644
--- a/policy-endpoints/src/test/resources/logback-test.xml
+++ b/policy-endpoints/src/test/resources/logback-test.xml
@@ -1,3 +1,22 @@
+<!--
+ ============LICENSE_START=======================================================
+ ONAP
+ ================================================================================
+ Copyright (C) 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.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ============LICENSE_END=========================================================
+ -->
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
diff --git a/policy-management/pom.xml b/policy-management/pom.xml
index 2c0f968e..56037f36 100644
--- a/policy-management/pom.xml
+++ b/policy-management/pom.xml
@@ -3,7 +3,7 @@
============LICENSE_START=======================================================
ONAP Policy Engine - Drools PDP
================================================================================
- 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.
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<artifactId>policy-management</artifactId>
@@ -235,6 +235,15 @@
<version>4.1</version>
</dependency>
+ <!-- if we don't explicitly specify the version here, we seem to end up
+ with version 1.4 (as a dependency to drools-core). This version is
+ not compatible with 'saClientLibrary' version 1.2.1-oss -->
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.9</version>
+ </dependency>
+
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
diff --git a/policy-management/src/test/resources/logback-test.xml b/policy-management/src/test/resources/logback-test.xml
index b2ddf807..e88f1473 100644
--- a/policy-management/src/test/resources/logback-test.xml
+++ b/policy-management/src/test/resources/logback-test.xml
@@ -1,3 +1,22 @@
+<!--
+ ============LICENSE_START=======================================================
+ ONAP
+ ================================================================================
+ Copyright (C) 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.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ============LICENSE_END=========================================================
+ -->
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
diff --git a/policy-utils/pom.xml b/policy-utils/pom.xml
index 19d54dc8..45cfd2d4 100644
--- a/policy-utils/pom.xml
+++ b/policy-utils/pom.xml
@@ -28,7 +28,7 @@
<parent>
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
diff --git a/pom.xml b/pom.xml
index a8d8fab8..1cfb2d2c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<groupId>org.onap.policy.drools-pdp</groupId>
<artifactId>drools-pdp</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>policy-drools-pdp</name>
@@ -58,7 +58,7 @@
<!-- Project common dependency versions -->
<dmaap.version>1.1.3</dmaap.version>
- <cambria.version>0.0.1</cambria.version>
+ <cambria.version>1.2.1-oss</cambria.version>
<jersey.version>2.25.1</jersey.version>
<jersey.swagger.version>1.5.18</jersey.swagger.version>
<jackson.version>2.9.5</jackson.version>
diff --git a/version.properties b/version.properties
index 08f1f93f..146a672f 100644
--- a/version.properties
+++ b/version.properties
@@ -4,7 +4,7 @@
major=1
minor=2
-patch=0
+patch=1
base_version=${major}.${minor}.${patch}