summaryrefslogtreecommitdiffstats
path: root/policy-management/src
diff options
context:
space:
mode:
Diffstat (limited to 'policy-management/src')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java4
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java6
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java28
-rw-r--r--policy-management/src/main/server-gen/bin/deploy-artifact7
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsController2Test.java34
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/GsonMgmtTestBuilder.java11
6 files changed, 42 insertions, 48 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
index 5b4e4ded..27a3289a 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -131,7 +132,7 @@ public interface DroolsController extends Startable, Lockable {
PolicyContainer getContainer();
/**
- * Does it owns the coder.
+ * Does it own the coder.
*
* @param coderClass the encoder object
* @param modelHash the hash for the model
@@ -161,7 +162,6 @@ public interface DroolsController extends Startable, Lockable {
* @param decoderConfigurations - decoder configurations
* @param encoderConfigurations - encoder configurations
*
- * @throws Exception from within drools libraries
* @throws LinkageError from within drools libraries
*/
void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java
index 3a50b9f7..5491eac7 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,11 +60,6 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
protected Map<String, DroolsController> droolsControllers = new HashMap<>();
/**
- * Null Drools Controller.
- */
- protected NullDroolsController nullDroolsController = new NullDroolsController();
-
- /**
* Constructs the object.
*/
public IndexedDroolsControllerFactory() {
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
index d7d387b8..e93adec5 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +28,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
+import lombok.Getter;
import lombok.NonNull;
import org.apache.commons.collections4.queue.CircularFifoQueue;
import org.drools.core.ClassObjectFilter;
@@ -117,7 +119,10 @@ public class MavenDroolsController implements DroolsController {
/**
* original Drools Model/Rules classloader hash.
+ * -- GETTER --
+ * Get model class loader hash.
*/
+ @Getter
protected int modelClassLoaderHash;
/**
@@ -272,7 +277,7 @@ public class MavenDroolsController implements DroolsController {
String potentialCodedClass = coderFilter.getCodedClass();
JsonProtocolFilter protocolFilter = coderFilter.getFilter();
- if (!isClass(potentialCodedClass)) {
+ if (isNotAClass(potentialCodedClass)) {
throw makeRetrieveEx(potentialCodedClass);
} else {
logClassFetched(potentialCodedClass);
@@ -306,7 +311,7 @@ public class MavenDroolsController implements DroolsController {
&& !customGsonCoder.getClassContainer().isEmpty()) {
String customGsonCoderClass = customGsonCoder.getClassContainer();
- if (!isClass(customGsonCoderClass)) {
+ if (isNotAClass(customGsonCoderClass)) {
throw makeRetrieveEx(customGsonCoderClass);
} else {
logClassFetched(customGsonCoderClass);
@@ -371,7 +376,7 @@ public class MavenDroolsController implements DroolsController {
@Override
public boolean ownsCoder(Class<?> coderClass, int modelHash) {
- if (!isClass(coderClass.getName())) {
+ if (isNotAClass(coderClass.getName())) {
logger.error("{}{} cannot be retrieved. ", this, coderClass.getName());
return false;
}
@@ -624,15 +629,6 @@ public class MavenDroolsController implements DroolsController {
return this.policyContainer.getGroupId();
}
- /**
- * Get model class loader hash.
- *
- * @return the modelClassLoaderHash
- */
- public int getModelClassLoaderHash() {
- return modelClassLoaderHash;
- }
-
@Override
public synchronized boolean lock() {
logger.info("LOCK: {}", this);
@@ -706,9 +702,7 @@ public class MavenDroolsController implements DroolsController {
* @return the attached Policy Container
*/
protected List<PolicySession> getSessions() {
- List<PolicySession> sessions = new ArrayList<>();
- sessions.addAll(this.policyContainer.getPolicySessions());
- return sessions;
+ return new ArrayList<>(this.policyContainer.getPolicySessions());
}
/**
@@ -1007,7 +1001,7 @@ public class MavenDroolsController implements DroolsController {
return new PolicyContainer(groupId, artifactId, version);
}
- protected boolean isClass(String className) {
- return ReflectionUtil.isClass(this.policyContainer.getClassLoader(), className);
+ protected boolean isNotAClass(String className) {
+ return !ReflectionUtil.isClass(this.policyContainer.getClassLoader(), className);
}
}
diff --git a/policy-management/src/main/server-gen/bin/deploy-artifact b/policy-management/src/main/server-gen/bin/deploy-artifact
index 6c63750d..3e7664f0 100644
--- a/policy-management/src/main/server-gen/bin/deploy-artifact
+++ b/policy-management/src/main/server-gen/bin/deploy-artifact
@@ -21,6 +21,8 @@
source ${POLICY_HOME}/etc/profile.d/env.sh
+export MVN_PLUGIN_VERSION=3.1.1
+
##############################################################################
# Usage: usage
##############################################################################
@@ -400,7 +402,8 @@ function installJar
fi
mvn ${CUSTOM_SETTINGS} ${MVN_PROXY_SETTINGS} \
- org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=${file}
+ org.apache.maven.plugins:maven-install-plugin:${MVN_PLUGIN_VERSION}:install-file \
+ -Dfile=${file}
return $?
}
@@ -425,7 +428,7 @@ function installPom
fi
mvn ${CUSTOM_SETTINGS} ${MVN_PROXY_SETTINGS} \
- org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file \
+ org.apache.maven.plugins:maven-install-plugin:${MVN_PLUGIN_VERSION}:install-file \
-Dpackaging=pom \
-Dfile="${file}" \
-DpomFile="${file}"
diff --git a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsController2Test.java b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsController2Test.java
index 1384501c..f91c437a 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsController2Test.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsController2Test.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,7 +37,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -191,14 +191,14 @@ public class MavenDroolsController2Test {
*/
@Before
public void setUp() {
- when(droolsProviders.getList()).thenReturn(Arrays.asList(prov1, prov2));
+ when(droolsProviders.getList()).thenReturn(List.of(prov1, prov2));
when(coderMgr.isDecodingSupported(GROUP, ARTIFACT, TOPIC)).thenReturn(true);
when(coderMgr.decode(GROUP, ARTIFACT, TOPIC, EVENT_TEXT)).thenReturn(EVENT);
when(kieSess.getFactCount()).thenReturn(FACT_COUNT);
- when(kieSess.getFactHandles()).thenReturn(Arrays.asList(fact1, fact2, factex, fact3));
- when(kieSess.getFactHandles(any())).thenReturn(Arrays.asList(fact1, fact3));
+ when(kieSess.getFactHandles()).thenReturn(List.of(fact1, fact2, factex, fact3));
+ when(kieSess.getFactHandles(any())).thenReturn(List.of(fact1, fact3));
when(kieSess.getKieBase()).thenReturn(kieBase);
when(kieSess.getQueryResults(QUERY, PARM1, PARM2)).thenReturn(queryResults);
@@ -209,15 +209,15 @@ public class MavenDroolsController2Test {
when(kieSess.getObject(fact3)).thenReturn(FACT3_OBJECT);
when(kieSess.getObject(factex)).thenThrow(RUNTIME_EX);
- when(kieBase.getKiePackages()).thenReturn(Arrays.asList(pkg1, pkg2));
+ when(kieBase.getKiePackages()).thenReturn(List.of(pkg1, pkg2));
- when(pkg1.getQueries()).thenReturn(Arrays.asList(query3));
- when(pkg2.getQueries()).thenReturn(Arrays.asList(query2, query1));
+ when(pkg1.getQueries()).thenReturn(List.of(query3));
+ when(pkg2.getQueries()).thenReturn(List.of(query2, query1));
when(query1.getName()).thenReturn(QUERY);
when(query2.getName()).thenReturn(QUERY2);
- when(queryResults.iterator()).thenReturn(Arrays.asList(row1, row2).iterator());
+ when(queryResults.iterator()).thenReturn(List.of(row1, row2).iterator());
when(row1.get(ENTITY)).thenReturn(FACT1_OBJECT);
when(row2.get(ENTITY)).thenReturn(FACT3_OBJECT);
@@ -235,7 +235,7 @@ public class MavenDroolsController2Test {
when(sess2.getFullName()).thenReturn(FULL_SESSION2);
when(container.getClassLoader()).thenReturn(CLASS_LOADER);
- when(container.getPolicySessions()).thenReturn(Arrays.asList(sess1, sess2));
+ when(container.getPolicySessions()).thenReturn(List.of(sess1, sess2));
when(container.insertAll(EVENT)).thenReturn(true);
when(decoder1.getTopic()).thenReturn(TOPIC);
@@ -244,8 +244,8 @@ public class MavenDroolsController2Test {
when(encoder1.getTopic()).thenReturn(TOPIC);
when(encoder2.getTopic()).thenReturn(TOPIC2);
- decoders = Arrays.asList(decoder1, decoder2);
- encoders = Arrays.asList(encoder1, encoder2);
+ decoders = List.of(decoder1, decoder2);
+ encoders = List.of(encoder1, encoder2);
when(decoder1.getCustomGsonCoder()).thenReturn(gson1);
when(encoder2.getCustomGsonCoder()).thenReturn(gson2);
@@ -259,11 +259,11 @@ public class MavenDroolsController2Test {
when(filter2.getCodedClass()).thenReturn(Integer.class.getName());
when(filter2.getFilter()).thenReturn(jsonFilter2);
- when(decoder1.getCoderFilters()).thenReturn(Arrays.asList(filter1a, filter1b));
+ when(decoder1.getCoderFilters()).thenReturn(List.of(filter1a, filter1b));
when(decoder2.getCoderFilters()).thenReturn(Collections.emptyList());
when(encoder1.getCoderFilters()).thenReturn(Collections.emptyList());
- when(encoder2.getCoderFilters()).thenReturn(Arrays.asList(filter2));
+ when(encoder2.getCoderFilters()).thenReturn(List.of(filter2));
when(sink.getTopic()).thenReturn(TOPIC);
when(sink.send(EVENT_TEXT)).thenReturn(true);
@@ -470,8 +470,8 @@ public class MavenDroolsController2Test {
// unknown class
drools = new MyDrools(GROUP, ARTIFACT, VERSION, null, null) {
@Override
- protected boolean isClass(String className) {
- return false;
+ protected boolean isNotAClass(String className) {
+ return true;
}
};
assertFalse(drools.ownsCoder(String.class, hc));
@@ -880,7 +880,7 @@ public class MavenDroolsController2Test {
assertEquals(GROUP, drools.getGroupId());
assertEquals(CLASS_LOADER_HASHCODE, drools.getModelClassLoaderHash());
assertSame(container, drools.getContainer());
- assertEquals(Arrays.asList(sess1, sess2), drools.getSessions());
+ assertEquals(List.of(sess1, sess2), drools.getSessions());
// test junit methods - need a controller with fewer overrides
drools = new MavenDroolsController(GROUP, ARTIFACT, VERSION, null, null) {
@@ -929,7 +929,7 @@ public class MavenDroolsController2Test {
@Test
public void testGetBaseDomainNames() {
KieContainer kiecont = mock(KieContainer.class);
- when(kiecont.getKieBaseNames()).thenReturn(Arrays.asList("kieA", "kieB"));
+ when(kiecont.getKieBaseNames()).thenReturn(List.of("kieA", "kieB"));
when(container.getKieContainer()).thenReturn(kiecont);
assertEquals("[kieA, kieB]", drools.getBaseDomainNames().toString());
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/GsonMgmtTestBuilder.java b/policy-management/src/test/java/org/onap/policy/drools/system/GsonMgmtTestBuilder.java
index e6569bc5..bf6201b9 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/GsonMgmtTestBuilder.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/GsonMgmtTestBuilder.java
@@ -3,6 +3,7 @@
* policy-management
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,7 +51,7 @@ public class GsonMgmtTestBuilder extends GsonTestUtilsBuilder {
Class<? super T> clazz = type.getRawType();
if (TopicSource.class.isAssignableFrom(clazz)) {
- return new GsonSerializer<T>() {
+ return new GsonSerializer<>() {
@Override
public void write(JsonWriter out, T value) throws IOException {
TopicSource obj = (TopicSource) value;
@@ -80,7 +81,7 @@ public class GsonMgmtTestBuilder extends GsonTestUtilsBuilder {
Class<? super T> clazz = type.getRawType();
if (TopicSink.class.isAssignableFrom(clazz)) {
- return new GsonSerializer<T>() {
+ return new GsonSerializer<>() {
@Override
public void write(JsonWriter out, T value) throws IOException {
TopicSink obj = (TopicSink) value;
@@ -110,13 +111,13 @@ public class GsonMgmtTestBuilder extends GsonTestUtilsBuilder {
Class<? super T> clazz = type.getRawType();
if (DroolsController.class.isAssignableFrom(clazz)) {
- return new GsonSerializer<T>() {
+ return new GsonSerializer<>() {
@Override
public void write(JsonWriter out, T value) throws IOException {
DroolsController obj = (DroolsController) value;
out.beginObject().name("group").value(obj.getGroupId()).name("artifact")
- .value(obj.getArtifactId()).name("version").value(obj.getVersion())
- .endObject();
+ .value(obj.getArtifactId()).name("version").value(obj.getVersion())
+ .endObject();
}
};
}