Use lombok in drools-pdp #2 58/123158/2
authorJim Hahn <jrh3@att.com>
Thu, 5 Aug 2021 18:53:19 +0000 (14:53 -0400)
committerJim Hahn <jrh3@att.com>
Thu, 5 Aug 2021 19:25:14 +0000 (15:25 -0400)
Updated feature-session-persistence thru drools-domains.

Issue-ID: POLICY-3397
Change-Id: I0b1c6da8b2301c00dd792675e8cf1f49888edb9f
Signed-off-by: Jim Hahn <jrh3@att.com>
26 files changed:
feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java
feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsSessionEntity.java
feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java
feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/JpaDroolsSessionConnector.java
feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java
feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/DroolsSessionEntityTest.java
feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/PersistenceFeatureTest.java
feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java
feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPdpIntegrityMonitor.java
feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java
feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java
feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java
feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionConstants.java
feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TtControllerTask.java
policy-core/src/main/java/org/onap/policy/drools/core/DroolsExecutor.java
policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApiConstants.java
policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmx.java
policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmxListener.java
policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysFailLock.java
policy-core/src/main/java/org/onap/policy/drools/properties/DroolsPropertyConstants.java
policy-core/src/main/java/org/onap/policy/drools/util/FeatureEnabledChecker.java
policy-core/src/main/java/org/onap/policy/drools/util/KieUtils.java
policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java
policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionTest.java

index 93440da..ab85864 100644 (file)
 
 package org.onap.policy.drools.persistence;
 
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
 import org.eclipse.persistence.config.PersistenceUnitProperties;
 
-public class DroolsPersistenceProperties {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DroolsPersistenceProperties {
     /*
      * feature-session-persistence.properties parameter key values
      */
@@ -32,8 +35,4 @@ public class DroolsPersistenceProperties {
     public static final String DB_PWD = PersistenceUnitProperties.JDBC_PASSWORD;
     public static final String DB_SESSIONINFO_TIMEOUT = "persistence.sessioninfo.timeout";
     public static final String JTA_OBJECTSTORE_DIR = "persistence.objectstore.dir";
-
-    private DroolsPersistenceProperties() {
-        super();
-    }
 }
index ec9e5b7..9ac6856 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-session-persistence
  * ================================================================================
- * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2020-2021 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.
@@ -29,14 +29,23 @@ import javax.persistence.PrePersist;
 import javax.persistence.PreUpdate;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
 
 @Entity
+@Getter
+@Setter
+@EqualsAndHashCode(onlyExplicitlyIncluded = true)
+@NoArgsConstructor
 public class DroolsSessionEntity implements Serializable, DroolsSession {
 
     private static final long serialVersionUID = -5495057038819948709L;
 
     @Id
     @Column(name = "sessionName", nullable = false)
+    @EqualsAndHashCode.Include
     private String sessionName = "-1";
 
     @Column(name = "sessionId", nullable = false)
@@ -50,9 +59,6 @@ public class DroolsSessionEntity implements Serializable, DroolsSession {
     @Column(name = "updatedDate", nullable = false)
     private Date updatedDate;
 
-    public DroolsSessionEntity() {
-    }
-
     public DroolsSessionEntity(String sessionName, long sessionId) {
         this.sessionName = sessionName;
         this.sessionId = sessionId;
@@ -69,64 +75,6 @@ public class DroolsSessionEntity implements Serializable, DroolsSession {
         this.updatedDate = new Date();
     }
 
-    @Override
-    public String getSessionName() {
-        return sessionName;
-    }
-
-    @Override
-    public void setSessionName(String sessionName) {
-        this.sessionName = sessionName;
-    }
-
-    @Override
-    public long getSessionId() {
-        return sessionId;
-    }
-
-    @Override
-    public void setSessionId(long sessionId) {
-        this.sessionId = sessionId;
-    }
-
-    @Override
-    public Date getCreatedDate() {
-        return createdDate;
-    }
-
-    @Override
-    public void setCreatedDate(Date createdDate) {
-        this.createdDate = createdDate;
-    }
-
-    @Override
-    public Date getUpdatedDate() {
-        return updatedDate;
-    }
-
-    @Override
-    public void setUpdatedDate(Date updatedDate) {
-        this.updatedDate = updatedDate;
-    }
-
-    @Override
-    public boolean equals(Object other) {
-        if (other instanceof DroolsSession) {
-            DroolsSession session = (DroolsSession) other;
-            return this.getSessionName().equals(session.getSessionName());
-        } else {
-            return false;
-        }
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + getSessionName().hashCode();
-        return result;
-    }
-
     @Override
     public String toString() {
         return "{name=" + getSessionName() + ", id=" + getSessionId() + "}";
index 988cd9c..7103c47 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-session-persistence
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2021 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.
@@ -28,6 +28,9 @@ import javax.transaction.RollbackException;
 import javax.transaction.Status;
 import javax.transaction.SystemException;
 import javax.transaction.UserTransaction;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.Setter;
 import org.onap.policy.common.utils.jpa.EntityMgrCloser;
 
 /**
@@ -40,6 +43,8 @@ public class EntityMgrTrans extends EntityMgrCloser {
     /**
      * Transaction to be rolled back.
      */
+    @Getter(AccessLevel.PROTECTED)
+    @Setter(AccessLevel.PROTECTED)
     private static UserTransaction userTrans = com.arjuna.ats.jta.UserTransaction.userTransaction();
 
     /**
@@ -70,24 +75,6 @@ public class EntityMgrTrans extends EntityMgrCloser {
         }
     }
 
-    /**
-     * Gets the user transaction. For use by junit tests.
-     *
-     * @return the user transaction
-     */
-    protected static UserTransaction getUserTrans() {
-        return userTrans;
-    }
-
-    /**
-     * Sets the user transaction. For use by junit tests.
-     *
-     * @param userTrans the new user transaction
-     */
-    protected static void setUserTrans(UserTransaction userTrans) {
-        EntityMgrTrans.userTrans = userTrans;
-    }
-
     /**
      * Commits the transaction.
      */
@@ -146,7 +133,7 @@ public class EntityMgrTrans extends EntityMgrCloser {
 
         /**
          * Constructor.
-         * 
+         *
          * @param ex exception to be wrapped
          */
         public EntityMgrException(Exception ex) {
index d682e56..8fcbc79 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-session-persistence
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2021 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.
@@ -22,19 +22,17 @@ package org.onap.policy.drools.persistence;
 
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
+import lombok.AllArgsConstructor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@AllArgsConstructor
 public class JpaDroolsSessionConnector implements DroolsSessionConnector {
 
     private static Logger logger = LoggerFactory.getLogger(JpaDroolsSessionConnector.class);
 
     private final EntityManagerFactory emf;
 
-    public JpaDroolsSessionConnector(EntityManagerFactory emf) {
-        this.emf = emf;
-    }
-
     @Override
     public DroolsSession get(String sessName) {
 
index 3c3e500..a929c71 100644 (file)
@@ -151,7 +151,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine
     @Override
     public PolicySession.ThreadModel selectThreadModel(PolicySession session) {
 
-        var policyContainer = session.getPolicyContainer();
+        var policyContainer = session.getContainer();
         if (isPersistenceEnabled(policyContainer, session.getName())) {
             return new PersistentThreadModel(session, getProperties(policyContainer));
         }
@@ -165,7 +165,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine
     public void disposeKieSession(PolicySession policySession) {
 
         ContainerAdjunct contAdj =
-                (ContainerAdjunct) policySession.getPolicyContainer().getAdjunct(this);
+                (ContainerAdjunct) policySession.getContainer().getAdjunct(this);
         if (contAdj != null) {
             contAdj.disposeKieSession(policySession.getName());
         }
@@ -178,7 +178,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine
     public void destroyKieSession(PolicySession policySession) {
 
         ContainerAdjunct contAdj =
-                (ContainerAdjunct) policySession.getPolicyContainer().getAdjunct(this);
+                (ContainerAdjunct) policySession.getContainer().getAdjunct(this);
         if (contAdj != null) {
             contAdj.destroyKieSession(policySession.getName());
         }
index 2cc7d33..bd97916 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-session-persistence
  * ================================================================================
- * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2020-2021 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.
@@ -173,20 +173,7 @@ public class DroolsSessionEntityTest {
      * @param sessid session id
      * @return a new session Entity
      */
-    @SuppressWarnings("serial")
     private DroolsSessionEntity makeEnt2(String sessnm, long sessid) {
-
-        return new DroolsSessionEntity() {
-
-            @Override
-            public String getSessionName() {
-                return sessnm;
-            }
-
-            @Override
-            public long getSessionId() {
-                return sessid;
-            }
-        };
+        return new DroolsSessionEntity(sessnm, sessid);
     }
 }
index ec26198..4450b8c 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-session-persistence
  * ================================================================================
- * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2020-2021 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.
@@ -188,7 +188,7 @@ public class PersistenceFeatureTest {
         KieContainer kiecont = mock(KieContainer.class);
         when(polcont.getKieContainer()).thenReturn(kiecont);
 
-        when(polsess.getPolicyContainer()).thenReturn(polcont);
+        when(polsess.getContainer()).thenReturn(polcont);
 
         when(kiecont.getKieBase(anyString())).thenReturn(kiebase);
     }
@@ -1167,7 +1167,7 @@ public class PersistenceFeatureTest {
 
         when(sess.getSessionId()).thenReturn(sessid);
 
-        when(polsess.getPolicyContainer()).thenReturn(polcont);
+        when(polsess.getContainer()).thenReturn(polcont);
         when(polsess.getName()).thenReturn(sessnm);
 
         if (loadOk) {
index 2dc751b..0c75006 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-state-management
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019, 2021 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.
@@ -27,6 +27,8 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Properties;
 import java.util.UUID;
+import lombok.Getter;
+import lombok.Setter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,7 +44,9 @@ public class DbAudit extends DroolsPdpIntegrityMonitor.AuditBase {
     // invoked -- doing this avoids the need to create the table in advance.
     private static boolean createTableNeeded = true;
 
-    private static boolean isJunit = false;
+    @Getter
+    @Setter
+    private static boolean junit = false;
 
     /** Constructor - set the name to 'Database'. */
     private DbAudit() {
@@ -53,14 +57,6 @@ public class DbAudit extends DroolsPdpIntegrityMonitor.AuditBase {
         DbAudit.createTableNeeded = isNeeded;
     }
 
-    public static synchronized void setIsJunit(boolean isJUnit) {
-        DbAudit.isJunit = isJUnit;
-    }
-
-    public static boolean isJunit() {
-        return DbAudit.isJunit;
-    }
-
     /**
      * Get the instance.
      *
@@ -77,7 +73,7 @@ public class DbAudit extends DroolsPdpIntegrityMonitor.AuditBase {
     @Override
     public void invoke(Properties properties) {
         logger.debug("Running 'DbAudit.invoke'");
-        boolean doCreate = createTableNeeded && !isJunit;
+        boolean doCreate = createTableNeeded && !isJunit();
 
         if (!isActive()) {
             logger.info("DbAudit.invoke: exiting because isActive = false");
index 09dd275..da94302 100644 (file)
@@ -23,6 +23,8 @@ package org.onap.policy.drools.statemanagement;
 import java.io.IOException;
 import java.util.List;
 import java.util.Properties;
+import lombok.Getter;
+import lombok.Setter;
 import org.onap.policy.common.capabilities.Startable;
 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
@@ -305,11 +307,13 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor {
     /**
      * This is the base class for audits invoked in 'subsystemTest'.
      */
+    @Getter
     public abstract static class AuditBase {
         // name of the audit
         protected String name;
 
         // non-null indicates the error response
+        @Setter
         protected String response;
 
         /**
@@ -322,33 +326,6 @@ public class DroolsPdpIntegrityMonitor extends IntegrityMonitor {
             this.response = null;
         }
 
-        /**
-         * Get the name.
-         *
-         * @return the name of this audit
-         */
-        public String getName() {
-            return name;
-        }
-
-        /**
-         * Get the response.
-         *
-         * @return the response String (non-null indicates the error message)
-         */
-        public String getResponse() {
-            return response;
-        }
-
-        /**
-         * Set the response string to the specified value.
-         *
-         * @param value the new value of the response string (null = no errors)
-         */
-        public void setResponse(String value) {
-            response = value;
-        }
-
         /**
          * Abstract method to invoke the audit.
          *
index 438b6ec..29576c4 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-state-management
  * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 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.
@@ -37,6 +37,8 @@ import java.util.TreeSet;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
 import org.onap.policy.common.im.IntegrityMonitorException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,6 +54,7 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
     private static final Logger logger = LoggerFactory.getLogger(RepositoryAudit.class);
 
     // single global instance of this audit object
+    @Getter
     private static RepositoryAudit instance = new RepositoryAudit();
 
     // Regex pattern used to find additional repos in the form "repository(number).id.url"
@@ -64,15 +67,6 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
         super("Repository");
     }
 
-    /**
-     * Get the integrity monitor instance.
-     *
-     * @return the single 'RepositoryAudit' instance
-     */
-    public static DroolsPdpIntegrityMonitor.AuditBase getInstance() {
-        return instance;
-    }
-
     /**
      * First, get the names of each property from StateManagementProperties. For each property name, check if it is of
      * the form "repository(number).audit.id" If so, we extract the number and determine if there exists another
@@ -560,27 +554,13 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
     /**
      * An instance of this class exists for each artifact that we are trying to download.
      */
+    @AllArgsConstructor
     static class Artifact {
         String groupId;
         String artifactId;
         String version;
         String type;
 
-        /**
-         * Constructor - populate the 'Artifact' instance.
-         *
-         * @param groupId groupId of artifact
-         * @param artifactId artifactId of artifact
-         * @param version version of artifact
-         * @param type type of the artifact (e.g. "jar")
-         */
-        Artifact(String groupId, String artifactId, String version, String type) {
-            this.groupId = groupId;
-            this.artifactId = artifactId;
-            this.version = version;
-            this.type = type;
-        }
-
         /**
          * Constructor - populate an 'Artifact' instance.
          *
index 20494b0..1582ace 100644 (file)
 package org.onap.policy.drools.statemanagement;
 
 import java.util.Properties;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
 import org.eclipse.persistence.config.PersistenceUnitProperties;
 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class StateManagementProperties {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class StateManagementProperties {
     // get an instance of logger
     private static final Logger logger = LoggerFactory.getLogger(StateManagementProperties.class);
 
@@ -62,11 +66,9 @@ public class StateManagementProperties {
     public static final String WRITE_FPC_INTERVAL = "write_fpc_interval";
     public static final String DEPENDENCY_GROUPS = "dependency_groups";
 
+    @Getter
     private static Properties properties = null;
 
-    private StateManagementProperties() {
-    }
-
     /**
      * Initialize the parameter values from the feature-state-management.properties file values.
      *
@@ -88,8 +90,4 @@ public class StateManagementProperties {
     public static String getProperty(String key) {
         return properties.getProperty(key);
     }
-
-    public static Properties getProperties() {
-        return properties;
-    }
 }
index 8d47e1d..578b622 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * policy-persistence
  * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 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.
@@ -110,7 +110,7 @@ public class StateManagementTest {
 
         String configDir = "src/test/resources";
 
-        DbAudit.setIsJunit(true);
+        DbAudit.setJunit(true);
 
         Properties fsmProperties = new Properties();
         fsmProperties.load(new FileInputStream(new File(
index 9b5ad25..a02cf49 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-test-transaction
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 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.
 
 package org.onap.policy.drools.testtransaction;
 
+import lombok.AccessLevel;
 import lombok.Getter;
+import lombok.NoArgsConstructor;
 
-public class TestTransactionConstants {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TestTransactionConstants {
 
     public static final String TT_FPC = "TT.FPC";
     public static final String TT_COUNTER = "$ttc";
@@ -31,8 +34,4 @@ public class TestTransactionConstants {
 
     @Getter
     private static final TestTransaction manager = new TtImpl();
-
-    private TestTransactionConstants() {
-        // do nothing
-    }
 }
index baecdfd..bfd94df 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.policy.drools.testtransaction;
 import java.util.EventObject;
 import java.util.HashMap;
 import java.util.List;
+import lombok.Getter;
 import org.onap.policy.drools.controller.DroolsController;
 import org.onap.policy.drools.system.PolicyController;
 import org.slf4j.Logger;
@@ -32,6 +33,7 @@ import org.slf4j.LoggerFactory;
  * TtControllerTask implements the Runnabale interface Carries out the injection of an event into a
  * drools session and subsequent query of a counter to ensure that forward progress is occuring.
  */
+@Getter
 public class TtControllerTask implements Runnable {
 
     // get an instance of logger
@@ -53,14 +55,6 @@ public class TtControllerTask implements Runnable {
         this.thread.start();
     }
 
-    public PolicyController getController() {
-        return this.controller;
-    }
-
-    public synchronized boolean isAlive() {
-        return this.alive;
-    }
-
     /**
      * Stops the task.
      */
@@ -75,10 +69,6 @@ public class TtControllerTask implements Runnable {
         }
     }
 
-    public Thread getThread() {
-        return this.thread;
-    }
-
     @Override
     public void run() {
         try {
index 538970d..d996d5a 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 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.
 package org.onap.policy.drools.core;
 
 import java.util.concurrent.Executor;
+import lombok.AllArgsConstructor;
 import org.drools.core.WorkingMemory;
 
 /**
  * An executor that executes its tasks by inserting {@link DroolsRunnable} objects into
  * the working memory of a running session.
  */
+@AllArgsConstructor
 public class DroolsExecutor implements Executor {
     private final WorkingMemory workingMemory;
 
-    /**
-     * Constructs the object.
-     *
-     * @param workingMemory where tasks should be injected
-     */
-    public DroolsExecutor(WorkingMemory workingMemory) {
-        this.workingMemory = workingMemory;
-    }
-
     @Override
     public void execute(Runnable command) {
         DroolsRunnable runnable = command::run;
index 5bce350..1eab676 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * policy-core
  * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,7 +26,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
-import org.kie.api.KieBase;
+import lombok.Getter;
 import org.kie.api.KieServices;
 import org.kie.api.builder.KieScanner;
 import org.kie.api.builder.Message;
@@ -57,6 +57,7 @@ public class PolicyContainer implements Startable {
     private ConcurrentHashMap<Object, Object> adjuncts = new ConcurrentHashMap<>();
 
     // 'KieContainer' associated with this 'PolicyContainer'
+    @Getter
     private KieContainer kieContainer;
 
     // indicates whether the PolicyContainer is 'started'
@@ -106,7 +107,7 @@ public class PolicyContainer implements Startable {
      * @param releaseId indicates the artifact that is to be installed in this container
      */
     public PolicyContainer(ReleaseId releaseId) {
-        ReleaseId newReleaseId = releaseId;
+        var newReleaseId = releaseId;
         if (newReleaseId.getVersion().contains(",")) {
             // this is actually a comma-separated list of release ids
             newReleaseId =
@@ -192,15 +193,6 @@ public class PolicyContainer implements Startable {
         return kieContainer.getReleaseId().toString();
     }
 
-    /**
-     * Get kie container.
-     *
-     * @return the associated 'KieContainer' instance
-     */
-    public KieContainer getKieContainer() {
-        return kieContainer;
-    }
-
     /**
      * Get class loader.
      *
@@ -332,8 +324,8 @@ public class PolicyContainer implements Startable {
             logger.info("adoptKieSession:name: {} kieSession: {}", name, kieSession);
         }
         // fetch KieBase, and verify it belongs to this KieContainer
-        boolean match = false;
-        KieBase kieBase = kieSession.getKieBase();
+        var match = false;
+        var kieBase = kieSession.getKieBase();
         logger.info("adoptKieSession:kieBase: {}", kieBase);
         for (String kieBaseName : kieContainer.getKieBaseNames()) {
             logger.info("adoptKieSession:kieBaseName: {}", kieBaseName);
@@ -358,7 +350,7 @@ public class PolicyContainer implements Startable {
             // create the new 'PolicySession', add it to the table,
             // and return the object to the caller
             logger.info("adoptKieSession:create a new policySession with name {}", name);
-            PolicySession policySession = new PolicySession(name, this, kieSession);
+            var policySession = new PolicySession(name, this, kieSession);
             sessions.put(name, policySession);
 
             // notify features
@@ -383,8 +375,8 @@ public class PolicyContainer implements Startable {
      *         how to determine success/failure)
      */
     public String updateToVersion(String newVersion) {
-        ReleaseId releaseId = kieContainer.getReleaseId();
-        Results results = this.updateToVersion(
+        var releaseId = kieContainer.getReleaseId();
+        var results = this.updateToVersion(
                 kieServices.newReleaseId(releaseId.getGroupId(), releaseId.getArtifactId(), newVersion));
 
         List<Message> messages = results == null ? null : results.getMessages();
@@ -411,7 +403,7 @@ public class PolicyContainer implements Startable {
         }
 
         // update the version
-        Results results = kieContainer.updateToVersion(releaseId);
+        var results = kieContainer.updateToVersion(releaseId);
 
 
         // add common KiePackage instances
@@ -519,7 +511,7 @@ public class PolicyContainer implements Startable {
      * @return 'true' if the fact was inserted into at least one session, 'false' if not
      */
     public boolean insertAll(Object object) {
-        boolean rval = false;
+        var rval = false;
         synchronized (sessions) {
             for (PolicySession session : sessions.values()) {
                 session.insertDrools(object);
@@ -553,7 +545,7 @@ public class PolicyContainer implements Startable {
             for (String kieSessionName : kieContainer.getKieSessionNamesInKieBase(kieBaseName)) {
                 // if the 'PolicySession' does not currently exist, this method
                 // call will attempt to create it
-                PolicySession session = activatePolicySession(kieSessionName, kieBaseName);
+                var session = activatePolicySession(kieSessionName, kieBaseName);
                 if (session != null) {
                     session.startThread();
                 }
@@ -708,7 +700,7 @@ public class PolicyContainer implements Startable {
      * @param args standard 'main' arguments, which are currently ignored
      */
     public static void globalInit(String[] args) {
-        String configDir = "config";
+        var configDir = "config";
         logger.info("PolicyContainer.main: configDir={}", configDir);
 
         // invoke 'globalInit' on all of the features
index fb17b10..1f8a61c 100644 (file)
@@ -22,6 +22,7 @@
 package org.onap.policy.drools.core;
 
 import java.util.concurrent.ConcurrentHashMap;
+import lombok.Getter;
 import org.kie.api.event.rule.AfterMatchFiredEvent;
 import org.kie.api.event.rule.AgendaEventListener;
 import org.kie.api.event.rule.AgendaGroupPoppedEvent;
@@ -52,11 +53,18 @@ public class PolicySession
         implements AgendaEventListener, RuleRuntimeEventListener {
     // get an instance of logger
     private static Logger logger = LoggerFactory.getLogger(PolicySession.class);
+
+    // supports 'getCurrentSession()' method
+    private static ThreadLocal<PolicySession> policySess =
+            new ThreadLocal<>();
+
     // name of the 'PolicySession' and associated 'KieSession'
+    @Getter
     private String name;
 
     // the associated 'PolicyContainer', which may have additional
     // 'PolicySession' instances in addition to this one
+    @Getter
     private PolicyContainer container;
 
     // maps feature objects to per-PolicyContainer data
@@ -64,15 +72,12 @@ public class PolicySession
             new ConcurrentHashMap<>();
 
     // associated 'KieSession' instance
+    @Getter
     private KieSession kieSession;
 
     // if not 'null', this is the thread model processing the 'KieSession'
     private ThreadModel threadModel = null;
 
-    // supports 'getCurrentSession()' method
-    private static ThreadLocal<PolicySession> policySess =
-            new ThreadLocal<>();
-
     /**
      * Internal constructor - create a 'PolicySession' instance.
      *
@@ -89,35 +94,6 @@ public class PolicySession
         kieSession.addEventListener((RuleRuntimeEventListener) this);
     }
 
-    /**
-     * Get policy container.
-     *
-     * @return the 'PolicyContainer' object containing this session
-     */
-    public PolicyContainer getPolicyContainer() {
-        return container;
-    }
-
-    /**
-     * Get Kie Session.
-     *
-     * @return the associated 'KieSession' instance
-     */
-    public KieSession getKieSession() {
-        return kieSession;
-    }
-
-    /**
-     * Get name.
-     *
-     * @return the local name of this session, which should either match the
-     *     name specified in 'kmodule.xml' file associated with this session, or the
-     *     name passed on the 'PolicyContainer.adoptKieSession' method.
-     */
-    public String getName() {
-        return name;
-    }
-
     /**
      * Get full name.
      *
index 174ac79..9880884 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * policy-core
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 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.
 
 package org.onap.policy.drools.core;
 
+import lombok.AccessLevel;
 import lombok.Getter;
+import lombok.NoArgsConstructor;
 import org.onap.policy.common.utils.services.OrderedServiceImpl;
 
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
 public class PolicySessionFeatureApiConstants {
     /**
      * 'FeatureAPI.impl.getList()' returns an ordered list of objects
@@ -31,8 +34,4 @@ public class PolicySessionFeatureApiConstants {
     @Getter
     private static final OrderedServiceImpl<PolicySessionFeatureApi> impl =
             new OrderedServiceImpl<>(PolicySessionFeatureApi.class);
-
-    private PolicySessionFeatureApiConstants() {
-        // do nothing
-    }
 }
index e1a8975..0f4add7 100644 (file)
@@ -2,14 +2,14 @@
  * ============LICENSE_START=======================================================
  * policy-core
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2021 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.
 package org.onap.policy.drools.core.jmx;
 
 import java.util.concurrent.atomic.AtomicLong;
+import lombok.Getter;
 
 public class PdpJmx implements PdpJmxMBean  {
 
+    @Getter
     private static PdpJmx instance = new PdpJmx();
+
     private final AtomicLong updates = new AtomicLong();
     private final AtomicLong actions = new AtomicLong();
 
-    public static PdpJmx getInstance() {
-        return instance;
-    }
-
     @Override
     public long getUpdates() {
         return updates.longValue();
index 924f2b0..4a39173 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * policy-core
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2021 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.
@@ -24,25 +24,24 @@ import java.lang.management.ManagementFactory;
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.InstanceNotFoundException;
 import javax.management.MBeanRegistrationException;
-import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
 import javax.management.NotCompliantMBeanException;
 import javax.management.ObjectName;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
 public class PdpJmxListener {
 
     public static final Logger logger = LoggerFactory.getLogger(PdpJmxListener.class);
 
-    private PdpJmxListener() {
-    }
-
     /**
      * Stop the listener.
      */
     public static void stop() {
-        final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        final var server = ManagementFactory.getPlatformMBeanServer();
         try {
             server.unregisterMBean(new ObjectName("PolicyEngine:type=PdpJmx"));
         } catch (MBeanRegistrationException | InstanceNotFoundException
@@ -58,7 +57,7 @@ public class PdpJmxListener {
      *  Start.
      */
     public static void start() {
-        final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        final var server = ManagementFactory.getPlatformMBeanServer();
         try {
             server.registerMBean(PdpJmx.getInstance(), new ObjectName("PolicyEngine:type=PdpJmx"));
         } catch (InstanceAlreadyExistsException | MBeanRegistrationException
index 03024f5..dbb2088 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 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.
 
 package org.onap.policy.drools.core.lock;
 
+import lombok.NoArgsConstructor;
 
 /**
  * Lock implementation whose operations always fail.
  */
+@NoArgsConstructor
 public class AlwaysFailLock extends LockImpl {
     private static final long serialVersionUID = 1L;
 
-    /**
-     * Constructs the object.
-     */
-    public AlwaysFailLock() {
-        super();
-    }
-
     /**
      * Constructs the object.
      *
index 197c972..110412a 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * policy-core
  * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 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.
 
 package org.onap.policy.drools.properties;
 
-public class DroolsPropertyConstants {
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DroolsPropertyConstants {
 
     /* Controller Properties */
 
@@ -36,8 +40,4 @@ public class DroolsPropertyConstants {
     public static final String RULES_GROUPID = "rules.groupId";
     public static final String RULES_ARTIFACTID = "rules.artifactId";
     public static final String RULES_VERSION = "rules.version";
-
-    private DroolsPropertyConstants() {
-        // do nothing
-    }
 }
index aaafd0e..755e7a1 100644 (file)
@@ -2,14 +2,14 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2021 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.
 package org.onap.policy.drools.util;
 
 import java.util.Properties;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
 
 /**
  * Checks whether or not a feature is enabled.
  */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
 public class FeatureEnabledChecker {
 
-    /**
-     * Constructor.
-     */
-    private FeatureEnabledChecker() {
-        super();
-    }
-
     /**
      * Determines if a feature is enabled.
-     * 
+     *
      * @param props properties from which to extract the "enabled" flag
      * @param propName the name of the "enabled" property
      * @return {@code true} if the feature is enabled, or {@code false} if it is not
index d56af11..043e2b1 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2021 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.
@@ -33,6 +33,8 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
 import lombok.NonNull;
 import org.apache.commons.io.IOUtils;
 import org.drools.compiler.kie.builder.impl.InternalKieModule;
@@ -44,7 +46,6 @@ import org.kie.api.builder.KieBuilder;
 import org.kie.api.builder.KieFileSystem;
 import org.kie.api.builder.Message;
 import org.kie.api.builder.ReleaseId;
-import org.kie.api.builder.model.KieModuleModel;
 import org.kie.api.definition.KiePackage;
 import org.kie.api.definition.rule.Rule;
 import org.kie.api.runtime.KieContainer;
@@ -56,7 +57,8 @@ import org.slf4j.LoggerFactory;
 /**
  * Kie related utilities.
  */
-public class KieUtils {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class KieUtils {
 
     private static final Logger logger = LoggerFactory.getLogger(KieUtils.class);
 
@@ -64,25 +66,21 @@ public class KieUtils {
     private static final String RESOURCE_PREFIX = "src/main/resources/drools";
     private static final String RESOURCE_SUFFIX = ".drl";
 
-    private KieUtils() {
-        // Utility class
-    }
-
     /**
      * Installs a rules artifact in the local maven repository.
      */
     public static ReleaseId installArtifact(File kmodule, File pom, String drlKJarPath, @NonNull List<File> drls)
         throws IOException {
-        KieModuleModel kieModule = KieModuleModelImpl.fromXML(kmodule);
+        var kieModule = KieModuleModelImpl.fromXML(kmodule);
 
-        final KieFileSystem kieFileSystem = KieServices.Factory.get().newKieFileSystem();
+        final var kieFileSystem = KieServices.Factory.get().newKieFileSystem();
         kieFileSystem.writeKModuleXML(kieModule.toXML());
         kieFileSystem.writePomXML(new String(Files.readAllBytes(pom.toPath())));
         for (File drl : drls) {
             kieFileSystem.write(drlKJarPath + drl.getName(), new String(Files.readAllBytes(drl.toPath())));
         }
 
-        KieBuilder kieBuilder = build(kieFileSystem);
+        var kieBuilder = build(kieFileSystem);
         return getReleaseId(kieBuilder, pom);
     }
 
@@ -95,7 +93,7 @@ public class KieUtils {
     }
 
     private static ReleaseId getReleaseId(KieBuilder kieBuilder, File pomFile) {
-        ReleaseId releaseId = kieBuilder.getKieModule().getReleaseId();
+        var releaseId = kieBuilder.getKieModule().getReleaseId();
         KieMavenRepository
             .getKieMavenRepository()
             .installArtifact(releaseId,
@@ -164,7 +162,7 @@ public class KieUtils {
     }
 
     private static KieBuilder build(KieFileSystem kieFileSystem) {
-        KieBuilder kieBuilder = KieServices.Factory.get().newKieBuilder(kieFileSystem);
+        var kieBuilder = KieServices.Factory.get().newKieBuilder(kieFileSystem);
         List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
         if (messages != null && !messages.isEmpty()) {
             throw new IllegalArgumentException(messages.toString());
@@ -198,11 +196,11 @@ public class KieUtils {
         }
 
         // generate a 'KieFileSystem' from these resources
-        KieServices kieServices = KieServices.Factory.get();
-        KieFileSystem kfs = kieServices.newKieFileSystem();
-        int index = 1;
+        var kieServices = KieServices.Factory.get();
+        var kfs = kieServices.newKieFileSystem();
+        var index = 1;
         while (resources.hasMoreElements()) {
-            URL url = resources.nextElement();
+            var url = resources.nextElement();
             try (InputStream is = url.openStream()) {
                 // convert a resource to a byte array
                 byte[] drl = IOUtils.toByteArray(is);
@@ -216,7 +214,7 @@ public class KieUtils {
         }
 
         // do a build of the 'KieFileSystem'
-        KieBuilder builder = kieServices.newKieBuilder(kfs, classLoader);
+        var builder = kieServices.newKieBuilder(kfs, classLoader);
         builder.buildAll();
         List<Message> results = builder.getResults().getMessages();
         if (!results.isEmpty()) {
index 9fe5c70..81ca340 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * policy-core
  * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 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.
@@ -128,7 +128,7 @@ public class DroolsContainerTest {
             }
 
             // verify session attributes
-            assertEquals(container, session.getPolicyContainer());
+            assertEquals(container, session.getContainer());
             assertEquals("session1", session.getName());
             assertEquals("org.onap.policy.drools-pdp:drools-artifact1:17.1.0-SNAPSHOT:session1",
                     session.getFullName());
@@ -158,7 +158,7 @@ public class DroolsContainerTest {
             assertEquals("17.2.0-SNAPSHOT", container.getVersion());
 
             // verify new session attributes
-            assertEquals(container, session.getPolicyContainer());
+            assertEquals(container, session.getContainer());
             assertEquals("session1", session.getName());
             assertEquals("org.onap.policy.drools-pdp:drools-artifact1:17.2.0-SNAPSHOT:session1",
                     session.getFullName());
@@ -290,7 +290,7 @@ public class DroolsContainerTest {
             }
 
             // verify session attributes
-            assertEquals(container, session.getPolicyContainer());
+            assertEquals(container, session.getContainer());
             assertEquals("session1", session.getName());
             assertEquals("org.onap.policy.drools-pdp:drools-artifact1:17.1.0-SNAPSHOT:session1",
                     session.getFullName());
index 3b88219..e937bb3 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020-2021 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.
@@ -69,7 +69,7 @@ public class PolicySessionTest {
         verify(kie).addEventListener(rule);
 
         // test other simple methods
-        assertEquals(container, session.getPolicyContainer());
+        assertEquals(container, session.getContainer());
         assertEquals(kie, session.getKieSession());
         assertEquals(MY_NAME, session.getName());
         assertEquals(CONTAINER + ":" + MY_NAME, session.getFullName());