diff options
author | adheli.tavares <adheli.tavares@est.tech> | 2023-10-04 16:13:59 +0100 |
---|---|---|
committer | adheli.tavares <adheli.tavares@est.tech> | 2023-10-04 16:14:33 +0100 |
commit | b6d09ef9da41191199f2da7958d5b418ed2da8d9 (patch) | |
tree | 0a14755192f1418ab4c14e06858d0993a090bb40 | |
parent | 396f60280265a37379916ad12752a94691118f65 (diff) |
Remove AAF from drools-pdp
Issue-ID: POLICY-4592
Change-Id: Ibe7fb63017f862bdab4a80444a00324040b1ab87
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
17 files changed, 132 insertions, 222 deletions
diff --git a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/AafHealthCheckFilter.java b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/AafHealthCheckFilter.java deleted file mode 100644 index 47a617b3..00000000 --- a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/AafHealthCheckFilter.java +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * ============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========================================================= - */ - -package org.onap.policy.drools.healthcheck; - -import org.onap.policy.common.endpoints.http.server.aaf.AafGranularAuthFilter; -import org.onap.policy.drools.server.restful.aaf.AafBase; - -/** - * Healthcheck AAF Authorization Filter. - */ -public class AafHealthCheckFilter extends AafGranularAuthFilter { - - @Override - public String getPermissionTypeRoot() { - return AafBase.AAF_ROOT_PERMISSION; - } -} diff --git a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckManager.java b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckManager.java index 0e81c206..31f865aa 100644 --- a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckManager.java +++ b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheckManager.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2022 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. @@ -456,10 +457,6 @@ public class HealthCheckManager implements HealthCheck { return false; } - if (this.healthcheckServer.isAaf()) { - this.healthcheckServer.addFilterClass(null, AafHealthCheckFilter.class.getName()); - } - return startServer(this.healthcheckServer); } diff --git a/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/RestHealthCheckTest.java b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/RestHealthCheckTest.java index 13ad5211..2ab1fe82 100644 --- a/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/RestHealthCheckTest.java +++ b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/RestHealthCheckTest.java @@ -26,6 +26,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import jakarta.ws.rs.core.Response; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; @@ -102,6 +103,7 @@ public class RestHealthCheckTest { * Tear down. */ + @AfterClass public static void tearDown() { HttpClientFactoryInstance.getClientFactory().destroy(); HttpServletServerFactoryInstance.getServerFactory().destroy(); diff --git a/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/TestAafHealthCheckFilter.java b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/TestAafHealthCheckFilter.java deleted file mode 100644 index 3abcd32e..00000000 --- a/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/TestAafHealthCheckFilter.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============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========================================================= - */ - -package org.onap.policy.drools.healthcheck; - -import jakarta.servlet.http.HttpServletRequest; -import org.onap.policy.common.utils.network.NetworkUtil; - -/** - * Healthcheck AAF Authorization Filter. - */ -public class TestAafHealthCheckFilter extends AafHealthCheckFilter { - - @Override - protected String getRole(HttpServletRequest request) { - String expectedPerm = "org.onap.policy.pdpd.healthcheck.test|" - + NetworkUtil.getHostname() + "|get"; - if (!expectedPerm.equals(super.getRole(request))) { - throw new IllegalStateException("unexpected AAF granular permission"); - } else { - return "user"; - } - } - - @Override - public String getPermissionTypeRoot() { - return "org.onap.policy.pdpd"; - } -} diff --git a/feature-healthcheck/src/test/resources/feature-healthcheck.properties b/feature-healthcheck/src/test/resources/feature-healthcheck.properties index 63a71b6e..6f9b21a9 100644 --- a/feature-healthcheck/src/test/resources/feature-healthcheck.properties +++ b/feature-healthcheck/src/test/resources/feature-healthcheck.properties @@ -3,6 +3,7 @@ # ONAP # ================================================================================ # Copyright (C) 2022 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. @@ -24,7 +25,6 @@ http.server.services.HEALTHCHECK.host=localhost http.server.services.HEALTHCHECK.userName=username http.server.services.HEALTHCHECK.password=password http.server.services.HEALTHCHECK.restClasses=org.onap.policy.drools.healthcheck.RestMockHealthCheck -http.server.services.HEALTHCHECK.filterClasses=org.onap.policy.drools.healthcheck.TestAafHealthCheckFilter http.server.services.HEALTHCHECK.port=7777 http.server.services.LIVENESS.host=localhost diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java index 953f0b37..a50deb21 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.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. diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateActive.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateActive.java index 80d0bc7e..202eb98b 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateActive.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateActive.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Bell Canada. + * 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. @@ -24,6 +25,7 @@ package org.onap.policy.drools.lifecycle; import java.util.Collections; import lombok.NonNull; import lombok.ToString; +import org.jetbrains.annotations.NotNull; import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.enums.PdpResponseStatus; import org.onap.policy.models.pdp.enums.PdpState; @@ -44,12 +46,12 @@ public class LifecycleStateActive extends LifecycleStateRunning { } @Override - protected boolean stateChangeToActive(PdpStateChange change) { + protected boolean stateChangeToActive(@NotNull PdpStateChange change) { return fsm.statusAction(response(change.getRequestId(), PdpResponseStatus.SUCCESS, null)); } @Override - protected boolean stateChangeToPassive(PdpStateChange change) { + protected boolean stateChangeToPassive(@NotNull PdpStateChange change) { undeployPolicies(Collections.emptyList()); fsm.transitionToAction(new LifecycleStatePassive(fsm)); return fsm.statusAction(response(change.getRequestId(), PdpResponseStatus.SUCCESS, null)); diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java index db4f23d8..fc62b947 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Bell Canada. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021, 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. @@ -157,10 +157,10 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { failedPolicies.addAll(results.getRight()); // If there are *new* native controller policies deployed, there may - // existing native artifact policies (previous to the update event + // be existing native artifact policies (previous to the update event // processing) that would need to be reapplied. This requires // going through the list of those native artifact policies that - // were neither deployed or undeployed and re-apply them on top + // were neither deployed nor undeployed and re-apply them on top // of the controllers. failedPolicies.addAll(reApplyNativeArtifactPolicies(activePoliciesPreUpdate, activePoliciesPreUpdateMap)); @@ -169,7 +169,7 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { // non-native policies (previous to the update event processing) // that will need to be reapplied as the new controllers don't know about them. // This requires going through the list of those non-native policies - // which neither were undeployed or deployed and re-apply them on top of the + // which neither were undeployed nor deployed and re-apply them on top of the // new "brained" controllers. failedPolicies.addAll(reApplyNonNativePolicies(activePoliciesPreUpdateMap)); @@ -228,11 +228,11 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { return Collections.emptyList(); } - // need to re-apply non native policies + // need to re-apply non-native policies // get the non-native policies to be reapplied, this is just the intersection of - // the original active set, and the new active set (i.e policies that have not changed, - // or in other words, have not been neither deployed or undeployed. + // the original active set, and the new active set (i.e. policies that have not changed, + // or in other words, have not been deployed or undeployed). List<ToscaPolicy> preNonNativePolicies = fsm.getNonNativePolicies(preActivePoliciesMap); preNonNativePolicies.retainAll(fsm.getNonNativePolicies(activePoliciesByType)); @@ -262,8 +262,8 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { // need to re-apply native artifact policies // get the native artifact policies to be reapplied, this is just the intersection of - // the original active set, and the new active set (i.e policies that have not changed, - // or in other words, have not been neither deployed or undeployed). + // the original active set, and the new active set (i.e. policies that have not changed, + // or in other words, have not been deployed or undeployed). List<ToscaPolicy> preNativeArtifactPolicies = fsm.getNativeArtifactPolicies(preActivePoliciesMap); preNativeArtifactPolicies.retainAll(fsm.getNativeArtifactPolicies(activePoliciesByType)); diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java index 90c0d94c..3fa8ac9f 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2021-2022 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021, 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. @@ -69,34 +69,34 @@ public class LifecycleFsmUpdateTest { private static final String EXAMPLE_NATIVE_CONTROLLER_POLICY_NAME = "example.controller"; private static final String EXAMPLE_NATIVE_CONTROLLER_POLICY_JSON = - "src/test/resources/tosca-policy-native-controller-example.json"; + "src/test/resources/tosca-policy-native-controller-example.json"; private static final String EXAMPLE_NATIVE_ARTIFACT_POLICY_NAME = "example.artifact"; private static final String EXAMPLE_NATIVE_ARTIFACT_POLICY_JSON = - "src/test/resources/tosca-policy-native-artifact-example.json"; + "src/test/resources/tosca-policy-native-artifact-example.json"; private static final String EXAMPLE_OTHER_UNVAL_POLICY_NAME = "other-unvalidated"; private static final String EXAMPLE_OTHER_UNVAL_POLICY_JSON = - "src/test/resources/tosca-policy-other-unvalidated.json"; + "src/test/resources/tosca-policy-other-unvalidated.json"; private static final String EXAMPLE_OTHER_VAL_POLICY_NAME = "other-validated"; private static final String EXAMPLE_OTHER_VAL_POLICY_JSON = "src/test/resources/tosca-policy-other-validated.json"; private static final String FOO_NATIVE_CONTROLLER_POLICY_NAME = "foo.controller"; private static final String FOO_NATIVE_CONTROLLER_POLICY_JSON = - "src/test/resources/tosca-policy-native-controller-foo.json"; + "src/test/resources/tosca-policy-native-controller-foo.json"; private static final String FOO_NATIVE_ARTIFACT_POLICY_NAME = "foo.artifact"; private static final String FOO_NATIVE_ARTIFACT_POLICY_JSON = - "src/test/resources/tosca-policy-native-artifact-foo.json"; + "src/test/resources/tosca-policy-native-artifact-foo.json"; private static final String VCPE_OP_POLICY_NAME = "operational.restart"; private static final String VCPE_OPERATIONAL_DROOLS_POLICY_JSON = - "policies/vCPE.policy.operational.input.tosca.json"; + "policies/vCPE.policy.operational.input.tosca.json"; private static final String VFW_OP_POLICY_NAME = "operational.modifyconfig"; private static final String VFW_OPERATIONAL_DROOLS_POLICY_JSON = - "policies/vFirewall.policy.operational.input.tosca.json"; + "policies/vFirewall.policy.operational.input.tosca.json"; private static final StandardCoder coder = new StandardCoder(); @@ -156,9 +156,9 @@ public class LifecycleFsmUpdateTest { NoopTopicFactories.getSinkFactory().destroy(); try { Files.deleteIfExists(Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), - "lifecycle-controller.properties.bak")); + "lifecycle-controller.properties.bak")); Files.deleteIfExists(Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), - "foo-controller.properties.bak")); + "foo-controller.properties.bak")); } catch (IOException ignored) { // NOSONAR // checkstyle } @@ -198,7 +198,7 @@ public class LifecycleFsmUpdateTest { opPolicy = getExamplesPolicy(VFW_OPERATIONAL_DROOLS_POLICY_JSON, VFW_OP_POLICY_NAME); op2Policy = getExamplesPolicy(VCPE_OPERATIONAL_DROOLS_POLICY_JSON, VCPE_OP_POLICY_NAME); controllerPolicy = - getPolicyFromFile(EXAMPLE_NATIVE_CONTROLLER_POLICY_JSON, EXAMPLE_NATIVE_CONTROLLER_POLICY_NAME); + getPolicyFromFile(EXAMPLE_NATIVE_CONTROLLER_POLICY_JSON, EXAMPLE_NATIVE_CONTROLLER_POLICY_NAME); controller2Policy = getPolicyFromFile(FOO_NATIVE_CONTROLLER_POLICY_JSON, FOO_NATIVE_CONTROLLER_POLICY_NAME); artifactPolicy = getPolicyFromFile(EXAMPLE_NATIVE_ARTIFACT_POLICY_JSON, EXAMPLE_NATIVE_ARTIFACT_POLICY_NAME); artifact2Policy = getExamplesPolicy(FOO_NATIVE_ARTIFACT_POLICY_JSON, FOO_NATIVE_ARTIFACT_POLICY_NAME); @@ -212,16 +212,16 @@ public class LifecycleFsmUpdateTest { // native controller policy - deploy // Delta: +controllerPolicy - deltaUpdate(List.of(controllerPolicy), List.of(), List.of(controllerPolicy), 1, 1, 0, 0, 0, 0); + deltaUpdate(List.of(controllerPolicy), List.of(), List.of(controllerPolicy)); // no policies - undeploy // Delta: -controllerPolicy - deltaUpdate(List.of(), List.of(controllerPolicy), List.of(), 1, 1, 0, 1, 1, 0); + deltaUpdate(List.of(), List.of(controllerPolicy), List.of()); // native controller + artifact policy (out of order) - deploy // Delta: +artifactPolicy, +controllerPolicy - deltaUpdate(List.of(artifactPolicy, controllerPolicy), List.of(), List.of(artifactPolicy, controllerPolicy), 3, - 3, 0, 1, 1, 0); + deltaUpdate(List.of(artifactPolicy, controllerPolicy), List.of(), + List.of(artifactPolicy, controllerPolicy)); // attempt to deploy opPolicy but invalid controller // Delta: +opPolicy @@ -229,29 +229,28 @@ public class LifecycleFsmUpdateTest { assertEquals(1, PolicyControllerConstants.getFactory().inventory().size()); assertFalse(fsm.getActivePolicies().contains(opPolicy)); verifyExists(false, "lifecycle", List.of(opPolicy)); - verifyDeploy(List.of(artifactPolicy, controllerPolicy), 4, 3, 1, 1, 1, 0); + verifyDeploy(List.of(artifactPolicy, controllerPolicy)); // Delta: +opPolicy opPolicy.getProperties().remove("controllerName"); - deltaUpdate(List.of(opPolicy), List.of(), List.of(opPolicy, artifactPolicy, controllerPolicy), 5, 4, 1, 1, 1, - 0); + deltaUpdate(List.of(opPolicy), List.of(), List.of(opPolicy, artifactPolicy, controllerPolicy)); verifyExists(true, "lifecycle", List.of(opPolicy)); // Delta: -opPolicy - deltaUpdate(List.of(), List.of(opPolicy), List.of(controllerPolicy, artifactPolicy), 5, 4, 1, 2, 2, 0); + deltaUpdate(List.of(), List.of(opPolicy), List.of(controllerPolicy, artifactPolicy)); assertFalse(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().exists(opPolicy)); // Delta: -artifactPolicy - deltaUpdate(List.of(), List.of(artifactPolicy), List.of(controllerPolicy), 5, 4, 1, 3, 3, 0); + deltaUpdate(List.of(), List.of(artifactPolicy), List.of(controllerPolicy)); assertFalse(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().isBrained()); // Delta: -controllerPolicy - deltaUpdate(List.of(), List.of(controllerPolicy), List.of(), 5, 4, 1, 4, 4, 0); + deltaUpdate(List.of(), List.of(controllerPolicy), List.of()); assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("lifecycle")); // Delta: +controllerPolicy, +artifactPolicy, and +opPolicy deltaUpdate(List.of(opPolicy, artifactPolicy, controllerPolicy), List.of(), - List.of(opPolicy, artifactPolicy, controllerPolicy), 8, 7, 1, 4, 4, 0); + List.of(opPolicy, artifactPolicy, controllerPolicy)); verifyExists(true, "lifecycle", List.of(opPolicy)); // Delta: -artifactPolicy @@ -261,8 +260,7 @@ public class LifecycleFsmUpdateTest { // Delta: +artifactPolicy // from deltas, all delta updates should be successfully applied - deltaUpdate(List.of(artifactPolicy), List.of(), List.of(opPolicy, artifactPolicy, controllerPolicy), 9, 8, 1, 5, - 5, 0); + deltaUpdate(List.of(artifactPolicy), List.of(), List.of(opPolicy, artifactPolicy, controllerPolicy)); verifyExists(true, "lifecycle", List.of(opPolicy)); // Delta: -controllerPolicy @@ -272,30 +270,27 @@ public class LifecycleFsmUpdateTest { // Delta: +controllerPolicy // from deltas, all delta updates should be successfully applied - deltaUpdate(List.of(controllerPolicy), List.of(), List.of(opPolicy, artifactPolicy, controllerPolicy), 10, 9, 1, - 6, 6, 0); + deltaUpdate(List.of(controllerPolicy), List.of(), List.of(opPolicy, artifactPolicy, controllerPolicy)); verifyExists(true, "lifecycle", List.of(opPolicy)); // Delta: +op2Policy, +controller2Policy // from deltas, all delta updates should be successfully applied op2Policy.getProperties().put("controllerName", "lifecycle"); deltaUpdate(List.of(op2Policy, controller2Policy), List.of(), - List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy), 12, 11, 1, 6, 6, 0); + List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy)); verifyExists(true, "lifecycle", List.of(opPolicy, op2Policy)); assertFalse(PolicyControllerConstants.getFactory().get("foo").getDrools().isBrained()); // same operation with duplicates - idempotent operation deltaUpdate(List.of(op2Policy, controller2Policy, opPolicy), List.of(valPolicy, unvalPolicy), - List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy), 12, 11, 1, 6, 6, 0); + List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy)); verifyExists(true, "lifecycle", List.of(opPolicy, op2Policy)); assertFalse(PolicyControllerConstants.getFactory().get("foo").getDrools().isBrained()); // Delta: +artifact2policy, +valPolicy, +unvalPolicy // from deltas, all delta updates should be successfully applied - deltaUpdate( - List.of(valPolicy, unvalPolicy, artifact2Policy), List.of(), List.of(opPolicy, artifactPolicy, - controllerPolicy, op2Policy, controller2Policy, valPolicy, unvalPolicy, artifact2Policy), - 15, 14, 1, 6, 6, 0); + deltaUpdate(List.of(valPolicy, unvalPolicy, artifact2Policy), List.of(), List.of(opPolicy, artifactPolicy, + controllerPolicy, op2Policy, controller2Policy, valPolicy, unvalPolicy, artifact2Policy)); verifyExists(true, "lifecycle", List.of(opPolicy, op2Policy, valPolicy, unvalPolicy)); verifyExists(true, "foo", List.of(valPolicy, unvalPolicy)); verifyExists(false, "foo", List.of(opPolicy, op2Policy)); @@ -303,8 +298,7 @@ public class LifecycleFsmUpdateTest { // Delta: -artifact2Policy, -unvalPolicy // from deltas, all delta updates should be successfully applied, and unvalPolicy disabled deltaUpdate(List.of(), List.of(artifact2Policy, unvalPolicy), - List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy, valPolicy), 15, 14, 1, - 8, 8, 0); + List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy, valPolicy)); verifyExists(true, "lifecycle", List.of(opPolicy, op2Policy, valPolicy)); verifyExists(false, "lifecycle", List.of(unvalPolicy)); assertFalse(PolicyControllerConstants.getFactory().get("foo").getDrools().isBrained()); @@ -314,7 +308,7 @@ public class LifecycleFsmUpdateTest { // should be re-applied. assertTrue(fsm.update(getPdpUpdate(List.of(artifact2Policy), List.of()))); deltaUpdate(List.of(artifact2Policy), List.of(), List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, - controller2Policy, valPolicy, artifact2Policy), 16, 15, 1, 8, 8, 0); + controller2Policy, valPolicy, artifact2Policy)); verifyExists(true, "lifecycle", List.of(opPolicy, op2Policy, valPolicy)); verifyExists(false, "lifecycle", List.of(unvalPolicy)); verifyExists(true, "foo", List.of(valPolicy)); @@ -329,18 +323,18 @@ public class LifecycleFsmUpdateTest { // since -controllerPolicy delta => the existing artifact2Policy, opPolicy, op2Policy become disabled as no // policy type is readily available to host them until there is a host. verifyActivePoliciesWithDisables( - List.of(opPolicy, op2Policy, controller2Policy, valPolicy, artifact2Policy, unvalPolicy), - List.of(opPolicy.getIdentifier(), op2Policy.getIdentifier())); + List.of(opPolicy, op2Policy, controller2Policy, valPolicy, artifact2Policy, unvalPolicy), + List.of(opPolicy.getIdentifier(), op2Policy.getIdentifier())); // Delta: -opPolicy, -op2Policy, -controller2Policy, -valPolicy, -artifact2Policy, -unvalPolicy - // from deltas, -opPolicy and -op2Policy undeploys will fail since there is not controller with that + // from deltas, -opPolicy and -op2Policy undeploys will fail since there is no controller with that // policy type supported assertFalse(fsm.update(getPdpUpdate(List.of(), - List.of(opPolicy, op2Policy, controller2Policy, valPolicy, artifact2Policy, unvalPolicy)))); + List.of(opPolicy, op2Policy, controller2Policy, valPolicy, artifact2Policy, unvalPolicy)))); assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("lifecycle")); assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("foo")); assertEquals(0, PolicyControllerConstants.getFactory().inventory().size()); - verifyDeploy(List.of(), 17, 16, 1, 16, 14, 2); + verifyDeploy(List.of()); fsm.shutdown(); } @@ -361,15 +355,13 @@ public class LifecycleFsmUpdateTest { return update; } - protected void deltaUpdate(List<ToscaPolicy> deploy, List<ToscaPolicy> undeploy, List<ToscaPolicy> active, - long deployCount, long deploySuccess, long deployFail, long undeployCount, long undeploySuccess, - long undeployFail) throws CoderException { + protected void deltaUpdate(List<ToscaPolicy> deploy, List<ToscaPolicy> undeploy, List<ToscaPolicy> active) + throws CoderException { assertTrue(fsm.update(getPdpUpdate(deploy, undeploy))); - verifyDeploy(active, deployCount, deploySuccess, deployFail, undeployCount, undeploySuccess, undeployFail); + verifyDeploy(active); } - private void verifyDeploy(List<ToscaPolicy> active, long deployCount, long deploySuccess, long deployFail, - long undeployCount, long undeploySuccess, long undeployFail) throws CoderException { + private void verifyDeploy(List<ToscaPolicy> active) throws CoderException { verifyActivePolicies(active); } @@ -377,7 +369,7 @@ public class LifecycleFsmUpdateTest { assertTrue(PolicyControllerConstants.getFactory().get(controller).getDrools().isBrained()); for (ToscaPolicy policy : policies) { assertEquals("ID: " + controller + ":" + policy.getIdentifier(), exists, - PolicyControllerConstants.getFactory().get(controller).getDrools().exists(policy)); + PolicyControllerConstants.getFactory().get(controller).getDrools().exists(policy)); } } @@ -386,14 +378,14 @@ public class LifecycleFsmUpdateTest { } protected void verifyActivePoliciesWithDisables(List<ToscaPolicy> testPolicies, - List<ToscaConceptIdentifier> nativeDisables) throws CoderException { + List<ToscaConceptIdentifier> nativeDisables) throws CoderException { // verify that each policy is tracked in the active lists for (ToscaPolicy policy : testPolicies) { assertTrue(policy.getIdentifier().toString(), fsm.getActivePolicies().contains(policy)); if (!nativeDisables.contains(policy.getIdentifier())) { assertTrue(policy.getIdentifier().toString(), - fsm.getPolicyTypesMap().containsKey(policy.getTypeIdentifier())); + fsm.getPolicyTypesMap().containsKey(policy.getTypeIdentifier())); } } assertEquals(testPolicies.size(), fsm.getActivePolicies().size()); @@ -407,7 +399,7 @@ public class LifecycleFsmUpdateTest { // verify that a controller exists for each controller policy assertEquals(fsm.getNativeControllerPolicies(testPoliciesMap).size(), - PolicyControllerConstants.getFactory().inventory().size()); + PolicyControllerConstants.getFactory().inventory().size()); // verify that a brained controller with same application coordinates exist for // each native artifact policy @@ -428,21 +420,21 @@ public class LifecycleFsmUpdateTest { String controllerName = artifactPolicy.getProperties().getController().getName(); assertTrue(PolicyControllerConstants.getFactory().get(controllerName).getDrools().isBrained()); assertEquals(artifactPolicy.getProperties().getRulesArtifact().getGroupId(), - PolicyControllerConstants.getFactory().get(controllerName).getDrools().getGroupId()); + PolicyControllerConstants.getFactory().get(controllerName).getDrools().getGroupId()); assertEquals(artifactPolicy.getProperties().getRulesArtifact().getArtifactId(), - PolicyControllerConstants.getFactory().get(controllerName).getDrools().getArtifactId()); + PolicyControllerConstants.getFactory().get(controllerName).getDrools().getArtifactId()); assertEquals(artifactPolicy.getProperties().getRulesArtifact().getVersion(), - PolicyControllerConstants.getFactory().get(controllerName).getDrools().getVersion()); + PolicyControllerConstants.getFactory().get(controllerName).getDrools().getVersion()); } } protected void verifyNonNativePolicy(ToscaPolicy testPolicy, List<ToscaConceptIdentifier> nativeDisables) - throws CoderException { + throws CoderException { List<ToscaPolicy> nativeArtifactPolicies = - fsm.getNativeArtifactPolicies(fsm.groupPoliciesByPolicyType(fsm.getActivePolicies())); + fsm.getNativeArtifactPolicies(fsm.groupPoliciesByPolicyType(fsm.getActivePolicies())); List<ToscaPolicy> nativeControllerPolicies = - fsm.getNativeControllerPolicies(fsm.groupPoliciesByPolicyType(fsm.getActivePolicies())); + fsm.getNativeControllerPolicies(fsm.groupPoliciesByPolicyType(fsm.getActivePolicies())); String controllerName = (String) testPolicy.getProperties().get("controllerName"); @@ -454,21 +446,21 @@ public class LifecycleFsmUpdateTest { for (ToscaPolicy nativePolicy : nativeArtifactPolicies) { NativeArtifactPolicy artifactPolicy = - fsm.getDomainMaker().convertTo(nativePolicy, NativeArtifactPolicy.class); + fsm.getDomainMaker().convertTo(nativePolicy, NativeArtifactPolicy.class); String artifactControllerName = artifactPolicy.getProperties().getController().getName(); // brained controller check assertTrue(artifactControllerName + ":" + testPolicy.getIdentifier(), - PolicyControllerConstants.getFactory().get(artifactControllerName).getDrools().isBrained()); + PolicyControllerConstants.getFactory().get(artifactControllerName).getDrools().isBrained()); // non native tosca policy as a fact in drools if (PolicyControllerConstants.getFactory().get(artifactControllerName).getPolicyTypes() - .contains(testPolicy.getTypeIdentifier())) { + .contains(testPolicy.getTypeIdentifier())) { assertTrue(artifactControllerName + ":" + testPolicy.getIdentifier(), PolicyControllerConstants - .getFactory().get(artifactControllerName).getDrools().exists(testPolicy)); + .getFactory().get(artifactControllerName).getDrools().exists(testPolicy)); } else { assertFalse(artifactControllerName + ":" + testPolicy.getIdentifier(), PolicyControllerConstants - .getFactory().get(artifactControllerName).getDrools().exists(testPolicy)); + .getFactory().get(artifactControllerName).getDrools().exists(testPolicy)); } // there should always be a controller policy for each artifact policy @@ -493,13 +485,13 @@ public class LifecycleFsmUpdateTest { // verify the policy is present as a fact if there is matching artifact policy List<NativeArtifactPolicy> candidateNativeArtifactPolicies = - getNativeArtifactPolicies(nativeArtifactPolicies, controllerName); + getNativeArtifactPolicies(nativeArtifactPolicies, controllerName); if (candidateNativeArtifactPolicies.size() == 1) { assertTrue(controllerName + ":" + testPolicy.getIdentifier(), - PolicyControllerConstants.getFactory().get(controllerName).getDrools().isBrained()); + PolicyControllerConstants.getFactory().get(controllerName).getDrools().isBrained()); assertTrue(controllerName + ":" + testPolicy.getIdentifier(), - PolicyControllerConstants.getFactory().get(controllerName).getDrools().exists(testPolicy)); + PolicyControllerConstants.getFactory().get(controllerName).getDrools().exists(testPolicy)); // verify that the other brained controllers don't have this non-native policy @@ -522,11 +514,11 @@ public class LifecycleFsmUpdateTest { // at this point the only valid possibility is that there is no native artifact policies assertTrue("There is more than 1 native artifact policy for " + controllerName, - candidateNativeArtifactPolicies.isEmpty()); + candidateNativeArtifactPolicies.isEmpty()); } protected List<NativeArtifactPolicy> getNativeArtifactPoliciesBut(List<ToscaPolicy> nativePolicies, - String controllerName) { + String controllerName) { return nativePolicies.stream().map(nativePolicy -> { try { return fsm.getDomainMaker().convertTo(nativePolicy, NativeArtifactPolicy.class); @@ -534,11 +526,11 @@ public class LifecycleFsmUpdateTest { throw new RuntimeException(nativePolicy.getIdentifier().toString(), ex); } }).filter(nativeArtifactPolicy -> !controllerName - .equals(nativeArtifactPolicy.getProperties().getController().getName())).collect(Collectors.toList()); + .equals(nativeArtifactPolicy.getProperties().getController().getName())).collect(Collectors.toList()); } protected List<NativeArtifactPolicy> getNativeArtifactPolicies(List<ToscaPolicy> nativePolicies, - String controllerName) { + String controllerName) { return nativePolicies.stream().map(nativePolicy -> { try { return fsm.getDomainMaker().convertTo(nativePolicy, NativeArtifactPolicy.class); @@ -546,11 +538,11 @@ public class LifecycleFsmUpdateTest { throw new RuntimeException(nativePolicy.getIdentifier().toString(), ex); } }).filter(nativeArtifactPolicy -> controllerName - .equals(nativeArtifactPolicy.getProperties().getController().getName())).collect(Collectors.toList()); + .equals(nativeArtifactPolicy.getProperties().getController().getName())).collect(Collectors.toList()); } protected List<ControllerPolicy> getNativeControllerPolicies(List<ToscaPolicy> nativePolicies, - String controllerName) { + String controllerName) { return nativePolicies.stream().map(controllerPolicy -> { try { return fsm.getDomainMaker().convertTo(controllerPolicy, ControllerPolicy.class); diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/QueryState.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/QueryState.java index ea74f03a..3e6f9d58 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/QueryState.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/QueryState.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +33,7 @@ import org.slf4j.LoggerFactory; /** * The Query state. In this state, the host waits for the other hosts to identify * themselves. Eventually, a leader should come forth. If not, it will transition to the - * active or inactive state, depending on whether or not it has an assignment in the + * active or inactive state, depending on whether it has an assignment in the * current bucket assignments. The other possibility is that it may <i>become</i> the * leader, in which case it will also transition to the active state. */ @@ -43,7 +44,7 @@ public class QueryState extends ProcessingState { /** * Hosts that have sent an "Identification" message. Always includes this host. */ - private TreeSet<String> alive = new TreeSet<>(); + private final TreeSet<String> alive = new TreeSet<>(); /** * {@code True} if we saw our own Identification method, {@code false} otherwise. 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(); } }; } @@ -4,7 +4,7 @@ ONAP Policy Engine - Drools PDP ================================================================================ Copyright (C) 2017-2022 AT&T Intellectual Property. All rights reserved. - Modifications Copyright (C) 2020,2023 Nordix Foundation. + Modifications Copyright (C) 2020, 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. @@ -48,8 +48,8 @@ <staging.path>content/repositories/staging/</staging.path> <!-- Project common dependency versions --> - <json.path.version>2.4.0</json.path.version> - <hibernate.commons.annotations.version>5.1.2.Final</hibernate.commons.annotations.version> + <json.path.version>2.8.0</json.path.version> + <hibernate.commons.annotations.version>6.0.6.Final</hibernate.commons.annotations.version> <xml.apis.version>1.4.01</xml.apis.version> <policy.common.version>2.0.1-SNAPSHOT</policy.common.version> <policy.models.version>3.0.1-SNAPSHOT</policy.models.version> @@ -152,12 +152,14 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <release>${java.version}</release> + </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> @@ -165,7 +167,7 @@ <dependency> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-webdav-jackrabbit</artifactId> - <version>2.10</version> + <version>3.5.3</version> </dependency> </dependencies> </plugin> |