Updated feature-session-persistence thru drools-domains.
Issue-ID: POLICY-3397
Change-Id: I0b1c6da8b2301c00dd792675e8cf1f49888edb9f
Signed-off-by: Jim Hahn <jrh3@att.com>
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
*/
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();
- }
}
* ============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.
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)
@Column(name = "updatedDate", nullable = false)
private Date updatedDate;
- public DroolsSessionEntity() {
- }
-
public DroolsSessionEntity(String sessionName, long sessionId) {
this.sessionName = sessionName;
this.sessionId = sessionId;
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() + "}";
* ============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.
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;
/**
/**
* Transaction to be rolled back.
*/
+ @Getter(AccessLevel.PROTECTED)
+ @Setter(AccessLevel.PROTECTED)
private static UserTransaction userTrans = com.arjuna.ats.jta.UserTransaction.userTransaction();
/**
}
}
- /**
- * 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.
*/
/**
* Constructor.
- *
+ *
* @param ex exception to be wrapped
*/
public EntityMgrException(Exception ex) {
* ============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.
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) {
@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));
}
public void disposeKieSession(PolicySession policySession) {
ContainerAdjunct contAdj =
- (ContainerAdjunct) policySession.getPolicyContainer().getAdjunct(this);
+ (ContainerAdjunct) policySession.getContainer().getAdjunct(this);
if (contAdj != null) {
contAdj.disposeKieSession(policySession.getName());
}
public void destroyKieSession(PolicySession policySession) {
ContainerAdjunct contAdj =
- (ContainerAdjunct) policySession.getPolicyContainer().getAdjunct(this);
+ (ContainerAdjunct) policySession.getContainer().getAdjunct(this);
if (contAdj != null) {
contAdj.destroyKieSession(policySession.getName());
}
* ============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.
* @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);
}
}
* ============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.
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);
}
when(sess.getSessionId()).thenReturn(sessid);
- when(polsess.getPolicyContainer()).thenReturn(polcont);
+ when(polsess.getContainer()).thenReturn(polcont);
when(polsess.getName()).thenReturn(sessnm);
if (loadOk) {
* ============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.
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;
// 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() {
DbAudit.createTableNeeded = isNeeded;
}
- public static synchronized void setIsJunit(boolean isJUnit) {
- DbAudit.isJunit = isJUnit;
- }
-
- public static boolean isJunit() {
- return DbAudit.isJunit;
- }
-
/**
* Get the instance.
*
@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");
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;
/**
* 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;
/**
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.
*
* ============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.
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;
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"
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
/**
* 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.
*
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);
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.
*
public static String getProperty(String key) {
return properties.getProperty(key);
}
-
- public static Properties getProperties() {
- return properties;
- }
}
* ============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.
String configDir = "src/test/resources";
- DbAudit.setIsJunit(true);
+ DbAudit.setJunit(true);
Properties fsmProperties = new Properties();
fsmProperties.load(new FileInputStream(new File(
* ============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";
@Getter
private static final TestTransaction manager = new TtImpl();
-
- private TestTransactionConstants() {
- // do nothing
- }
}
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;
* 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
this.thread.start();
}
- public PolicyController getController() {
- return this.controller;
- }
-
- public synchronized boolean isAlive() {
- return this.alive;
- }
-
/**
* Stops the task.
*/
}
}
- public Thread getThread() {
- return this.thread;
- }
-
@Override
public void run() {
try {
* ============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;
* ============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");
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;
private ConcurrentHashMap<Object, Object> adjuncts = new ConcurrentHashMap<>();
// 'KieContainer' associated with this 'PolicyContainer'
+ @Getter
private KieContainer kieContainer;
// indicates whether the PolicyContainer is 'started'
* @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 =
return kieContainer.getReleaseId().toString();
}
- /**
- * Get kie container.
- *
- * @return the associated 'KieContainer' instance
- */
- public KieContainer getKieContainer() {
- return kieContainer;
- }
-
/**
* Get class loader.
*
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);
// 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
* 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();
}
// update the version
- Results results = kieContainer.updateToVersion(releaseId);
+ var results = kieContainer.updateToVersion(releaseId);
// add common KiePackage instances
* @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);
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();
}
* @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
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;
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
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.
*
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.
*
* ============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
@Getter
private static final OrderedServiceImpl<PolicySessionFeatureApi> impl =
new OrderedServiceImpl<>(PolicySessionFeatureApi.class);
-
- private PolicySessionFeatureApiConstants() {
- // do nothing
- }
}
* ============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();
* ============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.
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
* 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
* ============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.
*
* ============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 */
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
- }
}
* ============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
* ============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.
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;
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;
/**
* Kie related utilities.
*/
-public class KieUtils {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class KieUtils {
private static final Logger logger = LoggerFactory.getLogger(KieUtils.class);
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);
}
}
private static ReleaseId getReleaseId(KieBuilder kieBuilder, File pomFile) {
- ReleaseId releaseId = kieBuilder.getKieModule().getReleaseId();
+ var releaseId = kieBuilder.getKieModule().getReleaseId();
KieMavenRepository
.getKieMavenRepository()
.installArtifact(releaseId,
}
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());
}
// 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);
}
// 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()) {
* ============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.
}
// 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());
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());
}
// 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());
* ============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.
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());