summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/main
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2023-10-04 15:38:04 +0100
committeradheli.tavares <adheli.tavares@est.tech>2023-10-04 15:42:27 +0100
commit336d94aa7cf3e23b5b62772504edb0d1daeb9520 (patch)
tree0c567dacc4b9521e273499f87a0b2d9c5be4a5dd /controlloop/common/eventmanager/src/main
parentfc19178b956f4474ed14e810fd911ac60f3756d0 (diff)
Java 17 and sonar fixes.
- change on maven.compiler to new resource property targeting java 17 version - sonar bugs on try-resource and some code smells Issue-ID: POLICY-4677 Issue-ID: POLICY-4837 Change-Id: I50a2170db80619c2ac95131ab5c91a6f767a5c30 Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'controlloop/common/eventmanager/src/main')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcome.java7
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithSteps.java6
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java23
3 files changed, 21 insertions, 15 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcome.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcome.java
index 79fe0b78d..84389b8c5 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcome.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcome.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 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.
@@ -20,6 +21,7 @@
package org.onap.policy.controlloop.eventmanager;
+import java.io.Serial;
import java.util.Deque;
import java.util.LinkedList;
import java.util.UUID;
@@ -40,22 +42,22 @@ import org.onap.policy.drools.domain.models.operational.OperationalTarget;
/**
* Manager for a single control loop event, with operation outcomes.
*/
+@Getter
public abstract class ClEventManagerWithOutcome<T extends Step> extends ClEventManagerWithSteps<T>
implements StepContext {
+ @Serial
private static final long serialVersionUID = -1216568161322872641L;
/**
* Number of attempts, so far, for the current step.
*/
- @Getter
private int attempts;
/**
* Full history of operations that have been processed by the rules. This includes the
* items in {@link #partialHistory}.
*/
- @Getter
private final transient Deque<OperationOutcome2> fullHistory = new LinkedList<>();
/**
@@ -63,7 +65,6 @@ public abstract class ClEventManagerWithOutcome<T extends Step> extends ClEventM
* When a step is started, its "start" outcome is added. However, once it completes,
* its "start" outcome is removed and the "completed" outcome is added.
*/
- @Getter
private final transient Deque<OperationOutcome2> partialHistory = new LinkedList<>();
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithSteps.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithSteps.java
index a44936640..511d93b9d 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithSteps.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithSteps.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 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.
@@ -20,6 +21,7 @@
package org.onap.policy.controlloop.eventmanager;
+import java.io.Serial;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedHashMap;
@@ -55,6 +57,7 @@ import org.slf4j.LoggerFactory;
public abstract class ClEventManagerWithSteps<T extends Step> extends ControlLoopEventManager implements StepContext {
private static final Logger logger = LoggerFactory.getLogger(ClEventManagerWithSteps.class);
+ @Serial
private static final long serialVersionUID = -1216568161322872641L;
/**
@@ -99,7 +102,7 @@ public abstract class ClEventManagerWithSteps<T extends Step> extends ControlLoo
/**
* Result of the last policy operation. This is just a place where the rules can store
- * the value for passing to {@link #loadNextPolicy()}.
+ * the value for passing to {@link #loadNextPolicy(OperationResult)}.
*/
@Getter
@Setter
@@ -266,6 +269,7 @@ public abstract class ClEventManagerWithSteps<T extends Step> extends ControlLoo
}
// initialize the step so we can query its properties
+ assert getSteps().peek() != null;
getSteps().peek().init();
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java
index 36d0ba59c..16cf527d5 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java
@@ -168,15 +168,15 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
* Takes records from {@link #operations} and stores them in the queue. Continues to
* run until {@link #stop()} is invoked, or the thread is interrupted.
*
- * @param emfactory entity manager factory
+ * @param factory entity manager factory
*/
- private void run(EntityManagerFactory emfactory) {
- try {
+ private void run(EntityManagerFactory factory) {
+ try (factory) {
// store records until stopped, continuing if an exception occurs
while (!stopped) {
try {
Record triple = operations.take();
- storeBatch(emfactory.createEntityManager(), triple);
+ storeBatch(factory.createEntityManager(), triple);
} catch (RuntimeException e) {
logger.error("failed to save data to operation history table", e);
@@ -188,26 +188,27 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
}
}
- storeRemainingRecords(emfactory);
+ storeRemainingRecords(factory);
} finally {
synchronized (this) {
stopped = true;
}
- emfactory.close();
}
}
/**
* Store any remaining records, but stop at the first exception.
*
- * @param emfactory entity manager factory
+ * @param factory entity manager factory
*/
- private void storeRemainingRecords(EntityManagerFactory emfactory) {
+ private void storeRemainingRecords(EntityManagerFactory factory) {
try {
while (!operations.isEmpty()) {
- storeBatch(emfactory.createEntityManager(), operations.poll());
+ try (var em = factory.createEntityManager()) {
+ storeBatch(em, operations.poll());
+ }
}
} catch (RuntimeException e) {
@@ -224,8 +225,8 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
private void storeBatch(EntityManager entityManager, Record firstRecord) {
logger.info("store operation history record batch");
- try (var emc = new EntityMgrCloser(entityManager);
- var trans = new EntityTransCloser(entityManager.getTransaction())) {
+ try (var ignored = new EntityMgrCloser(entityManager);
+ var trans = new EntityTransCloser(entityManager.getTransaction())) {
var nrecords = 0;
var rec = firstRecord;