Updated policy-management thru policy-utils.
Issue-ID: POLICY-3397
Change-Id: Ie9498fe912e8338ddc32a40774c3cb63d84f079a
Signed-off-by: Jim Hahn <jrh3@att.com>
.eventClass(potentialCodedClass)
.protocolFilter(protocolFilter)
.customGsonCoder(customGsonCoder)
- .modelClassLoaderHash(this.policyContainer.getClassLoader().hashCode()));
+ .modelClassLoaderHash(this.policyContainer.getClassLoader().hashCode()).build());
} else {
getCoderManager().addEncoder(
EventProtocolParams.builder().groupId(this.getGroupId())
.artifactId(this.getArtifactId()).topic(topic)
.eventClass(potentialCodedClass).protocolFilter(protocolFilter)
.customGsonCoder(customGsonCoder)
- .modelClassLoaderHash(this.policyContainer.getClassLoader().hashCode()));
+ .modelClassLoaderHash(this.policyContainer.getClassLoader().hashCode()).build());
}
}
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * 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.List;
import java.util.Properties;
import java.util.function.BiPredicate;
+import lombok.Getter;
+import lombok.ToString;
import org.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.utils.PropertyUtil;
import org.slf4j.Logger;
/**
* Properties based Persistence.
*/
+@Getter
+@ToString
public class FileSystemPersistence implements SystemPersistence {
/**
public static final String SYSTEM_PROPERTIES_FILE_SUFFIX = SYSTEM_PROPERTIES_SUFFIX + PROPERTIES_FILE_EXTENSION;
/**
- * Configuration directory.
+ * Logger.
*/
- protected Path configurationDirectory = Paths.get(SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR);
+ private static final Logger logger = LoggerFactory.getLogger(FileSystemPersistence.class);
/**
- * Logger.
+ * Configuration directory.
*/
- private static final Logger logger = LoggerFactory.getLogger(FileSystemPersistence.class);
+ protected Path configurationPath = Paths.get(SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR);
+
@Override
public void setConfigurationDir(String configDir) {
if (tempConfigDir == null) {
tempConfigDir = SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR;
- this.configurationDirectory = Paths.get(SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR);
+ this.configurationPath = Paths.get(SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR);
}
if (!tempConfigDir.equals(SystemPersistenceConstants.DEFAULT_CONFIGURATION_DIR)) {
- this.configurationDirectory = Paths.get(tempConfigDir);
+ this.configurationPath = Paths.get(tempConfigDir);
}
setConfigurationDir();
@Override
public void setConfigurationDir() {
- if (Files.notExists(this.configurationDirectory)) {
+ if (Files.notExists(this.configurationPath)) {
try {
- Files.createDirectories(this.configurationDirectory);
+ Files.createDirectories(this.configurationPath);
} catch (final IOException e) {
- throw new IllegalStateException("cannot create " + this.configurationDirectory, e);
+ throw new IllegalStateException("cannot create " + this.configurationPath, e);
}
}
- if (!Files.isDirectory(this.configurationDirectory)) {
+ if (!Files.isDirectory(this.configurationPath)) {
throw new IllegalStateException(
- "config directory: " + this.configurationDirectory + " is not a directory");
+ "config directory: " + this.configurationPath + " is not a directory");
}
}
- @Override
- public Path getConfigurationPath() {
- return this.configurationDirectory;
- }
-
protected Properties getProperties(Path propertiesPath) {
if (!Files.exists(propertiesPath)) {
throw new IllegalArgumentException("properties for " + propertiesPath.toString() + " are not persisted.");
throw new IllegalArgumentException("properties name must be provided");
}
- Path propertiesPath = Paths.get(this.configurationDirectory.toString());
+ var propertiesPath = Paths.get(this.configurationPath.toString());
if (name.endsWith(PROPERTIES_FILE_EXTENSION) || name.endsWith(ENV_FILE_EXTENSION)) {
propertiesPath = propertiesPath.resolve(name);
} else {
private void addToPropertiesList(File file, List<Properties> properties,
BiPredicate<String, Properties> preCondition) {
try {
- Properties proposedProps = getProperties(file.getName());
+ var proposedProps = getProperties(file.getName());
if (preCondition.test(file.getName(), proposedProps)) {
properties.add(proposedProps);
}
throw new IllegalArgumentException("environment name must be provided");
}
- return this.getProperties(Paths.get(this.configurationDirectory.toString(), name + ENV_FILE_SUFFIX));
+ return this.getProperties(Paths.get(this.configurationPath.toString(), name + ENV_FILE_SUFFIX));
}
@Override
}
private boolean testControllerName(String controllerFilename, Properties controllerProperties) {
- String controllerName = controllerFilename
+ var controllerName = controllerFilename
.substring(0, controllerFilename.length() - PROPERTIES_FILE_CONTROLLER_SUFFIX.length());
String controllerPropName = controllerProperties.getProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME);
if (controllerPropName == null) {
}
protected boolean backup(String name, String fileSuffix) {
- Path path = Paths.get(this.configurationDirectory.toString(), name + fileSuffix);
+ var path = Paths.get(this.configurationPath.toString(), name + fileSuffix);
if (Files.exists(path)) {
try {
logger.info("{}: there is an existing configuration file @ {} ", this, path);
- Path bakPath = Paths.get(this.configurationDirectory.toString(),
+ var bakPath = Paths.get(this.configurationPath.toString(),
name + fileSuffix + FILE_BACKUP_SUFFIX);
Files.copy(path, bakPath, StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
}
private boolean store(String name, Properties properties, String fileSuffix) {
- Path path = Paths.get(this.configurationDirectory.toString(), name + fileSuffix);
+ var path = Paths.get(this.configurationPath.toString(), name + fileSuffix);
if (Files.exists(path)) {
try {
- Properties oldProperties = PropertyUtil.getProperties(path.toFile());
+ var oldProperties = PropertyUtil.getProperties(path.toFile());
if (oldProperties.equals(properties)) {
logger.info("{}: noop: a properties file with the same contents exists for controller {}.", this,
name);
}
}
- File file = path.toFile();
- try (FileWriter writer = new FileWriter(file)) {
+ var file = path.toFile();
+ try (var writer = new FileWriter(file)) {
properties.store(writer, "Machine created Policy Controller Configuration");
} catch (Exception e) {
logger.warn("{}: {} cannot be saved", this, name, e);
}
protected boolean delete(String name, String fileSuffix) {
- Path path = Paths.get(this.configurationDirectory.toString(), name + fileSuffix);
+ var path = Paths.get(this.configurationPath.toString(), name + fileSuffix);
if (Files.exists(path)) {
try {
- Path bakPath = Paths.get(this.configurationDirectory.toString(),
+ var bakPath = Paths.get(this.configurationPath.toString(),
name + fileSuffix + FILE_BACKUP_SUFFIX);
Files.move(path, bakPath, StandardCopyOption.REPLACE_EXISTING);
} catch (final Exception e) {
* provides a list of files sorted by name in ascending order in the configuration directory.
*/
private File[] sortedListFiles() {
- File[] dirFiles = this.configurationDirectory.toFile().listFiles();
+ File[] dirFiles = this.configurationPath.toFile().listFiles();
if (dirFiles != null) {
Arrays.sort(dirFiles, Comparator.comparing(File::getName));
} else {
}
return dirFiles;
}
-
- @Override
- public String toString() {
- return "FileSystemPersistence [configurationDirectory=" + this.configurationDirectory + "]";
- }
}
package org.onap.policy.drools.persistence;
+import lombok.AccessLevel;
import lombok.Getter;
+import lombok.NoArgsConstructor;
-public class SystemPersistenceConstants {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class SystemPersistenceConstants {
/**
* configuration directory.
*/
*/
@Getter
private static final SystemPersistence manager = new FileSystemPersistence();
-
- private SystemPersistenceConstants() {
- // do nothing
- }
}
package org.onap.policy.drools.protocol.coders;
import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
import org.onap.policy.drools.controller.DroolsController;
/**
*/
public interface EventProtocolCoder {
+ @Getter
+ @Setter
+ @ToString
+ @AllArgsConstructor
public static class CoderFilters {
/**
* classloader hash.
*/
protected int modelClassLoaderHash;
-
- /**
- * constructor.
- *
- * @param codedClass coder class
- * @param filter filters to apply
- */
- public CoderFilters(String codedClass, JsonProtocolFilter filter, int modelClassLoaderHash) {
- this.factClass = codedClass;
- this.filter = filter;
- this.modelClassLoaderHash = modelClassLoaderHash;
- }
-
- /**
- * Get coded class.
- *
- * @return the codedClass
- */
- public String getCodedClass() {
- return factClass;
- }
-
- /**
- * Set coded class.
- *
- * @param codedClass the decodedClass to set
- */
- public void setCodedClass(String codedClass) {
- this.factClass = codedClass;
- }
-
- /**
- * Get filter.
- *
- * @return the filter
- */
- public JsonProtocolFilter getFilter() {
- return filter;
- }
-
- /**
- * Set filter.
- *
- * @param filter the filter to set
- */
- public void setFilter(JsonProtocolFilter filter) {
- this.filter = filter;
- }
-
- public int getModelClassLoaderHash() {
- return modelClassLoaderHash;
- }
-
- public void setFromClassLoaderHash(int fromClassLoaderHash) {
- this.modelClassLoaderHash = fromClassLoaderHash;
- }
-
- @Override
- public String toString() {
- return "CoderFilters [factClass="
- + factClass
- + ", filter="
- + filter
- + ", modelClassLoaderHash="
- + modelClassLoaderHash
- + "]";
- }
}
/**
package org.onap.policy.drools.protocol.coders;
+import lombok.AccessLevel;
import lombok.Getter;
+import lombok.NoArgsConstructor;
-public class EventProtocolCoderConstants {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class EventProtocolCoderConstants {
/**
* singleton reference to the global event protocol coder.
*/
@Getter
private static final EventProtocolCoder manager = new MultiplexorEventProtocolCoder();
-
- private EventProtocolCoderConstants() {
- // do nothing
- }
}
package org.onap.policy.drools.protocol.coders;
-class EventProtocolDecoder extends GenericEventProtocolCoder {
+import lombok.ToString;
- public EventProtocolDecoder() {
- super();
- }
+@ToString(callSuper = true)
+class EventProtocolDecoder extends GenericEventProtocolCoder {
- @Override
- public String toString() {
- return "EventProtocolDecoder [toString()=" + super.toString() + "]";
- }
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * 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.protocol.coders;
-class EventProtocolEncoder extends GenericEventProtocolCoder {
+import lombok.ToString;
- public EventProtocolEncoder() {
- super();
- }
+@ToString(callSuper = true)
+class EventProtocolEncoder extends GenericEventProtocolCoder {
- @Override
- public String toString() {
- return "EventProtocolEncoder [toString()=" + super.toString() + "]";
- }
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
* ================================================================================
* 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.protocol.coders;
-import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomCoder;
+import lombok.Builder;
+import lombok.Getter;
+@Getter
+@Builder
public class EventProtocolParams {
private String groupId;
private String artifactId;
private JsonProtocolFilter protocolFilter;
private TopicCoderFilterConfiguration.CustomGsonCoder customGsonCoder;
private int modelClassLoaderHash;
-
- public String getGroupId() {
- return groupId;
- }
-
- public String getArtifactId() {
- return artifactId;
- }
-
- public String getTopic() {
- return topic;
- }
-
- public String getEventClass() {
- return eventClass;
- }
-
- public JsonProtocolFilter getProtocolFilter() {
- return protocolFilter;
- }
-
- public TopicCoderFilterConfiguration.CustomGsonCoder getCustomGsonCoder() {
- return customGsonCoder;
- }
-
- public int getModelClassLoaderHash() {
- return modelClassLoaderHash;
- }
-
- public static EventProtocolParams builder() {
- return new EventProtocolParams();
- }
-
- /**
- * Setter method.
- *
- * @param groupId of the controller
- * @return EventProtocolParams
- */
- public EventProtocolParams groupId(String groupId) {
- this.groupId = groupId;
- return this;
- }
-
- /**
- * Setter method.
- *
- * @param artifactId of the controller
- * @return EventProtocolParams
- */
- public EventProtocolParams artifactId(String artifactId) {
- this.artifactId = artifactId;
- return this;
- }
-
- /**
- * Setter method.
- *
- * @param topic the topic
- * @return EventProtocolParams
- */
- public EventProtocolParams topic(String topic) {
- this.topic = topic;
- return this;
- }
-
- /**
- * Setter method.
- *
- * @param eventClass the event class
- * @return EventProtocolParams
- */
- public EventProtocolParams eventClass(String eventClass) {
- this.eventClass = eventClass;
- return this;
- }
-
- /**
- * Setter method.
- *
- * @param protocolFilter filters to selectively choose a particular decoder
- * when there are multiples
- * @return EventProtocolParams
- */
- public EventProtocolParams protocolFilter(JsonProtocolFilter protocolFilter) {
- this.protocolFilter = protocolFilter;
- return this;
- }
-
- /**
- * Setter method.
- *
- * @param customGsonCoder custom gscon coder
- * @return EventProtocolParams
- */
- public EventProtocolParams customGsonCoder(
- TopicCoderFilterConfiguration.CustomGsonCoder customGsonCoder) {
- this.customGsonCoder = customGsonCoder;
- return this;
- }
-
- /**
- * Setter method.
- * @param modelClassLoaderHash integer representing model hash
- * @return EventProtocolParams
- */
- public EventProtocolParams modelClassLoaderHash(int modelClassLoaderHash) {
- this.modelClassLoaderHash = modelClassLoaderHash;
- return this;
- }
-
- public CustomCoder getCustomCoder() {
- return this.customGsonCoder;
- }
}
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
* This protocol Coder that does its best attempt to decode/encode, selecting the best class and best fitted json
* parsing tools.
*/
+@ToString
+@NoArgsConstructor(access = AccessLevel.PROTECTED)
abstract class GenericEventProtocolCoder {
private static final String INVALID_ARTIFACT_ID_MSG = "Invalid artifact id";
private static final String INVALID_GROUP_ID_MSG = "Invalid group id";
protected final HashMap<String, List<ProtocolCoderToolset>>
reverseCoders = new HashMap<>();
- GenericEventProtocolCoder() {
- super();
- }
-
/**
* Index a new coder.
*/
logger.info("{}: removed toolset for {}: {}", this, key, coderToolset);
for (CoderFilters codeFilter : coderToolset.getCoders()) {
- String className = codeFilter.getCodedClass();
+ String className = codeFilter.getFactClass();
String reverseKey = this.reverseCodersKey(topic, className);
removeReverseCoder(key, reverseKey);
}
String artifactId = encoderSet.getArtifactId();
List<CoderFilters> coderFilters = encoderSet.getCoders();
for (CoderFilters coder : coderFilters) {
- if (coder.getCodedClass().equals(encodedClass.getClass().getName())) {
+ if (coder.getFactClass().equals(encodedClass.getClass().getName())) {
var droolsController =
DroolsControllerConstants.getFactory().get(groupId, artifactId, "");
if (droolsController.ownsCoder(
}
return droolsControllers;
}
-
- @Override
- public String toString() {
- return "GenericEventProtocolCoder [coders="
- + coders.keySet()
- + ", reverseCoders="
- + reverseCoders.keySet()
- + "]";
- }
}
* ============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.
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
+import lombok.ToString;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
-import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
import org.slf4j.Logger;
/**
* Tools used for encoding/decoding using GSON.
*/
+@ToString(callSuper = true)
class GsonProtocolCoderToolset extends ProtocolCoderToolset {
private static final String CANNOT_FETCH_CLASS = "{}: cannot fetch application class {}";
private static final String FETCH_CLASS_EX_MSG = "cannot fetch application class ";
@Override
public Object decode(String json) {
- final DroolsController droolsController =
+ final var droolsController =
DroolsControllerConstants.getFactory().get(this.groupId, this.artifactId, "");
if (droolsController == null) {
logger.warn("{}: no drools-controller to process {}", this, json);
Class<?> decoderClass;
try {
- decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass());
+ decoderClass = droolsController.fetchModelClass(decoderFilter.getFactClass());
if (decoderClass == null) {
- logger.warn(CANNOT_FETCH_CLASS, this, decoderFilter.getCodedClass());
+ logger.warn(CANNOT_FETCH_CLASS, this, decoderFilter.getFactClass());
throw new IllegalStateException(
- FETCH_CLASS_EX_MSG + decoderFilter.getCodedClass());
+ FETCH_CLASS_EX_MSG + decoderFilter.getFactClass());
}
} catch (final Exception e) {
- logger.warn(CANNOT_FETCH_CLASS, this, decoderFilter.getCodedClass());
+ logger.warn(CANNOT_FETCH_CLASS, this, decoderFilter.getFactClass());
throw new UnsupportedOperationException(
- FETCH_CLASS_EX_MSG + decoderFilter.getCodedClass(), e);
+ FETCH_CLASS_EX_MSG + decoderFilter.getFactClass(), e);
}
if (this.customCoder != null) {
try {
- final Class<?> gsonClassContainer =
+ final var gsonClassContainer =
droolsController.fetchModelClass(this.customCoder.getClassContainer());
- final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField);
- final Object gsonObject = gsonField.get(null);
- final Method fromJsonMethod = gsonObject.getClass().getDeclaredMethod("fromJson",
+ final var gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField);
+ final var gsonObject = gsonField.get(null);
+ final var fromJsonMethod = gsonObject.getClass().getDeclaredMethod("fromJson",
String.class, Class.class);
return fromJsonMethod.invoke(gsonObject, json, decoderClass);
} catch (final Exception e) {
- logger.warn(CANNOT_FETCH_CLASS, this, decoderFilter.getCodedClass());
+ logger.warn(CANNOT_FETCH_CLASS, this, decoderFilter.getFactClass());
throw new UnsupportedOperationException(
- FETCH_CLASS_EX_MSG + decoderFilter.getCodedClass(), e);
+ FETCH_CLASS_EX_MSG + decoderFilter.getFactClass(), e);
}
} else {
try {
} catch (final Exception e) {
logger.warn("{} cannot decode {} into {}", this, json, decoderClass.getName());
throw new UnsupportedOperationException(
- "cannont decode into " + decoderFilter.getCodedClass(), e);
+ "cannont decode into " + decoderFilter.getFactClass(), e);
}
}
}
if (this.customCoder != null) {
try {
- final DroolsController droolsController =
+ final var droolsController =
DroolsControllerConstants.getFactory().get(this.groupId, this.artifactId, null);
final Class<?> gsonClassContainer =
droolsController.fetchModelClass(this.customCoder.getClassContainer());
- final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField);
- final Object gsonObject = gsonField.get(null);
- final Method toJsonMethod =
+ final var gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField);
+ final var gsonObject = gsonField.get(null);
+ final var toJsonMethod =
gsonObject.getClass().getDeclaredMethod("toJson", Object.class);
return (String) toJsonMethod.invoke(gsonObject, event);
} catch (final Exception e) {
}
}
}
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("GsonProtocolCoderToolset [toString()=").append(super.toString()).append("]");
- return builder.toString();
- }
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * 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 com.jayway.jsonpath.Option;
import java.util.ArrayList;
import java.util.List;
+import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** JSON Protocol Filter. */
+@Getter
public class JsonProtocolFilter {
/** Default filter to match anything. */
this.setRule(rule);
}
- /**
- * Gets the filter expression rule.
- *
- * @return the filter expression associated with this JsonProtocolFilter
- */
- public String getRule() {
- return this.rule;
- }
-
/**
* Sets the filter expression rule.
*
import java.util.ArrayList;
import java.util.List;
+import lombok.ToString;
import org.onap.policy.drools.controller.DroolsController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* Protocol Coder that does its best attempt to decode/encode, selecting the best class and best fitted json parsing
* tools.
*/
+@ToString
class MultiplexorEventProtocolCoder implements EventProtocolCoder {
/**
public List<DroolsController> getDroolsControllers(String topic, Object encodedClass) {
return this.encoders.getDroolsControllers(topic, encodedClass);
}
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String toString() {
- return "MultiplexorEventProtocolCoder [decoders="
- + decoders
- + ", encoders="
- + encoders
- + "]";
- }
}
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomCoder;
import org.slf4j.Logger;
/**
* Protocol Coding/Decoding Toolset.
*/
+@Getter
+@ToString
public abstract class ProtocolCoderToolset {
/**
/**
* custom coder.
*/
+ @Setter
protected CustomCoder customCoder;
/**
eventProtocolParams.getEventClass(),
eventProtocolParams.getProtocolFilter(),
eventProtocolParams.getModelClassLoaderHash()));
- this.customCoder = eventProtocolParams.getCustomCoder();
+ this.customCoder = eventProtocolParams.getCustomGsonCoder();
}
/**
}
for (final CoderFilters coder : this.coders) {
- if (coder.getCodedClass().equals(eventClass)) {
+ if (coder.getFactClass().equals(eventClass)) {
coder.setFilter(filter);
- coder.setFromClassLoaderHash(modelClassLoaderHash);
+ coder.setModelClassLoaderHash(modelClassLoaderHash);
return;
}
}
this.coders.removeAll(temp);
}
- /**
- * gets the topic.
- *
- * @return the topic
- */
- public String getTopic() {
- return this.topic;
- }
-
- /**
- * gets the controller id.
- *
- * @return the controller id
- */
- public String getControllerId() {
- return this.controllerId;
- }
-
- /**
- * Get group id.
- *
- * @return the groupId
- */
- public String getGroupId() {
- return this.groupId;
- }
-
- /**
- * Get artifact id.
- *
- * @return the artifactId
- */
- public String getArtifactId() {
- return this.artifactId;
- }
-
- /**
- * Get custom coder.
- *
- * @return the customCoder
- */
- public CustomCoder getCustomCoder() {
- return this.customCoder;
- }
-
- /**
- * Set custom coder.
- *
- * @param customCoder the customCoder to set.
- */
- public void setCustomCoder(CustomCoder customCoder) {
- this.customCoder = customCoder;
- }
-
/**
* performs filtering on a json string.
*
* @throws UnsupportedOperationException if parsing into POJO is not possible
*/
public abstract String encode(Object event);
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("ProtocolCoderToolset [topic=").append(this.topic).append(", controllerId=")
- .append(this.controllerId).append(", groupId=").append(this.groupId).append(", artifactId=")
- .append(this.artifactId).append(", coders=").append(this.coders)
- .append(", customCoder=").append(this.customCoder).append("]");
- return builder.toString();
- }
}
package org.onap.policy.drools.protocol.coders;
import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+@Getter
+@ToString
public class TopicCoderFilterConfiguration {
/**
* Custom coder, contains class and static field to access parser that the controller desires to
* use instead of the framework provided parser.
*/
+ @Getter
+ @Setter
+ @ToString
public abstract static class CustomCoder {
- protected String className;
+ protected String classContainer;
protected String staticCoderField;
/**
protected CustomCoder(String rawCustomCoder) {
if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) {
- this.className = rawCustomCoder.substring(0, rawCustomCoder.indexOf(','));
- if (this.className == null || this.className.isEmpty()) {
+ this.classContainer = rawCustomCoder.substring(0, rawCustomCoder.indexOf(','));
+ if (this.classContainer == null || this.classContainer.isEmpty()) {
throw new IllegalArgumentException(
"No classname to create CustomCoder cannot be created");
}
this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(',') + 1);
if (this.staticCoderField == null || this.staticCoderField.isEmpty()) {
throw new IllegalArgumentException(
- "No staticCoderField to create CustomCoder cannot be created for class " + className);
+ "No staticCoderField to create CustomCoder cannot be created for class " + classContainer);
}
}
}
"No staticCoderField to create CustomCoder cannot be created for class " + className);
}
- this.className = className;
+ this.classContainer = className;
this.staticCoderField = staticCoderField;
}
-
- /**
- * Get class container.
- *
- * @return the className
- **/
- public String getClassContainer() {
- return className;
- }
-
- /**
- * Set class container.
- *
- * @param className the className to set
- **/
- public void setClassContainer(String className) {
- this.className = className;
- }
-
- /**
- * Get static coder field.
- *
- * @return the staticCoderField
- **/
- public String getStaticCoderField() {
- return staticCoderField;
- }
-
- /**
- * Set static coder field.
- *
- * @param staticCoderField the staticGson to set
- **/
- public void setStaticCoderField(String staticCoderField) {
- this.staticCoderField = staticCoderField;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder
- .append("CustomCoder [className=")
- .append(className)
- .append(", staticCoderField=")
- .append(staticCoderField)
- .append("]");
- return builder.toString();
- }
}
+ @ToString(callSuper = true)
public static class CustomGsonCoder extends CustomCoder {
public CustomGsonCoder(String className, String staticCoderField) {
public CustomGsonCoder(String customGson) {
super(customGson);
}
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("CustomGsonCoder [toString()=").append(super.toString()).append("]");
- return builder.toString();
- }
}
/**
* Coder/Decoder class and Filter container. The decoder class is potential, in order to be
* operational needs to be fetched from an available class loader.
*/
+ @Getter
+ @Setter
+ @ToString
+ @AllArgsConstructor
public static class PotentialCoderFilter {
/* decoder class (pending from being able to be fetched and found in some class loader) */
/* filters to apply to the selection of the decodedClass */
protected JsonProtocolFilter filter;
-
- /**
- * constructor.
- *
- * @param codedClass decoder class
- * @param filter filters to apply
- */
- public PotentialCoderFilter(String codedClass, JsonProtocolFilter filter) {
- this.codedClass = codedClass;
- this.filter = filter;
- }
-
- /**
- * Get coded class.
- *
- * @return the decodedClass
- **/
- public String getCodedClass() {
- return codedClass;
- }
-
- /** Set coded class.
- *
- * @param decodedClass the decodedClass to set
- **/
- public void setCodedClass(String decodedClass) {
- this.codedClass = decodedClass;
- }
-
- /**
- * Get filter.
- *
- * @return the filter
- **/
- public JsonProtocolFilter getFilter() {
- return filter;
- }
-
- /**
- * Set filter.
- *
- * @param filter the filter to set
- **/
- public void setFilter(JsonProtocolFilter filter) {
- this.filter = filter;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder
- .append("PotentialCoderFilter [codedClass=")
- .append(codedClass)
- .append(", filter=")
- .append(filter)
- .append("]");
- return builder.toString();
- }
}
/* the source topic */
protected final List<PotentialCoderFilter> coderFilters;
/* custom gson coder that this controller prefers to use instead of the framework ones */
+ @Setter
protected CustomGsonCoder customGsonCoder;
/**
this.topic = topic;
this.customGsonCoder = customGsonCoder;
}
-
- /**
- * Get topic.
- * @return the topic
- **/
- public String getTopic() {
- return topic;
- }
-
- /** Get coder filters.
- *
- * @return the decoderFilters
- **/
- public List<PotentialCoderFilter> getCoderFilters() {
- return coderFilters;
- }
-
- /**
- * Get custom gson coder.
- *
- * @return the customGsonCoder
- **/
- public CustomGsonCoder getCustomGsonCoder() {
- return customGsonCoder;
- }
-
- /**
- * Set custom gson coder.
- *
- * @param customGsonCoder the customGsonCoder to set
- **/
- public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) {
- this.customGsonCoder = customGsonCoder;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder
- .append("TopicCoderFilterConfiguration [topic=")
- .append(topic)
- .append(", coderFilters=")
- .append(coderFilters)
- .append(", customGsonCoder=")
- .append(customGsonCoder)
- .append("]");
- return builder.toString();
- }
}
* ============LICENSE_START=======================================================
* policy-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.HashMap;
import java.util.Map;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
import lombok.ToString;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
*
*/
@ToString
+@EqualsAndHashCode
+@NoArgsConstructor
public class ControllerConfiguration {
public static final String CONFIG_CONTROLLER_OPERATION_CREATE = "create";
public static final String CONFIG_CONTROLLER_OPERATION_LOCK = "lock";
public static final String CONFIG_CONTROLLER_OPERATION_UNLOCK = "unlock";
+ protected static final Object NOT_FOUND_VALUE = new Object();
+
/**
* (Required).
*
@GsonJsonIgnore
private Map<String, Object> additionalProperties = new HashMap<>();
- protected static final Object NOT_FOUND_VALUE = new Object();
-
- /**
- * No args constructor for use in serialization.
- *
- */
- public ControllerConfiguration() {
- // Empty
- }
/**
* Constructor.
return this;
}
- @Override
- public int hashCode() {
- return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties)
- .toHashCode();
- }
-
- @Override
- public boolean equals(Object other) {
- if (other == this) {
- return true;
- }
- if (!(other instanceof ControllerConfiguration)) {
- return false;
- }
- ControllerConfiguration rhs = ((ControllerConfiguration) other);
- return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools)
- .append(additionalProperties, rhs.additionalProperties).isEquals();
- }
-
/**
* Call set name.
*
* ============LICENSE_START=======================================================
* policy-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.HashMap;
import java.util.Map;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
import lombok.ToString;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
*
*/
@ToString
+@EqualsAndHashCode
+@NoArgsConstructor
public class DroolsConfiguration {
+ protected static final Object NOT_FOUND_VALUE = new Object();
+
/**
* Maven Artifact ID
* (Required).
@GsonJsonIgnore
private Map<String, Object> additionalProperties = new HashMap<>();
- protected static final Object NOT_FOUND_VALUE = new Object();
-
- /**
- * No args constructor for use in serialization.
- *
- */
- public DroolsConfiguration() {
- // Empty
- }
/**
* Constructor.
return this;
}
- @Override
- public int hashCode() {
- return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties)
- .toHashCode();
- }
-
- @Override
- public boolean equals(Object other) {
- if (other == this) {
- return true;
- }
- if (!(other instanceof DroolsConfiguration)) {
- return false;
- }
- DroolsConfiguration rhs = ((DroolsConfiguration) other);
- return new EqualsBuilder().append(artifactId, rhs.artifactId)
- .append(groupId, rhs.groupId).append(version, rhs.version)
- .append(additionalProperties, rhs.additionalProperties).isEquals();
- }
-
/**
* Call set artifact id.
*
* ============LICENSE_START=======================================================
* policy-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.HashMap;
import java.util.List;
import java.util.Map;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
import lombok.ToString;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
* ENGINE-CONFIGURATION.
*/
@ToString
+@EqualsAndHashCode
+@NoArgsConstructor
public class PdpdConfiguration {
/** Controller Entity ID. */
public static final String CONFIG_ENTITY_CONTROLLER = "controller";
+ protected static final Object NOT_FOUND_VALUE = new Object();
+
/** Unique Transaction ID. This is an UUID. (Required) */
@GsonJsonProperty("requestID")
private String requestId;
private List<ControllerConfiguration> controllers = new ArrayList<>();
@GsonJsonIgnore private Map<String, Object> additionalProperties = new HashMap<>();
- protected static final Object NOT_FOUND_VALUE = new Object();
-
- /** No args constructor for use in serialization. */
- public PdpdConfiguration() {
- // Empty
- }
/**
* Constructor.
return this;
}
- @Override
- public int hashCode() {
- return new HashCodeBuilder()
- .append(requestId)
- .append(entity)
- .append(controllers)
- .append(additionalProperties)
- .toHashCode();
- }
-
- @Override
- public boolean equals(Object other) {
- if (other == this) {
- return true;
- }
- if (!(other instanceof PdpdConfiguration)) {
- return false;
- }
- PdpdConfiguration rhs = (PdpdConfiguration) other;
- return new EqualsBuilder()
- .append(requestId, rhs.requestId)
- .append(entity, rhs.entity)
- .append(controllers, rhs.controllers)
- .append(additionalProperties, rhs.additionalProperties)
- .isEquals();
- }
-
/**
* Call set request id.
*
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
import org.onap.policy.common.endpoints.event.comm.Topic;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
produces = {MediaType.APPLICATION_JSON, YamlMessageBodyHandler.APPLICATION_YAML},
schemes = {SwaggerDefinition.Scheme.HTTP},
tags = {@Tag(name = "pdp-d-telemetry", description = "Drools PDP Telemetry Operations")})
+@ToString
public class RestManager {
private static final String OFFER_FAILED = "{}: cannot offer to topic {} because of {}";
* Helper classes for aggregation of results
*/
- @Override
- public String toString() {
- return "rest-telemetry-api []";
- }
-
/**
* Coding/Encoding Results Aggregation Helper class.
*/
+ @Getter
+ @Setter
public static class CodingResult {
/**
* serialized output.
* decoding result.
*/
private Boolean decoding;
-
- public String getJsonEncoding() {
- return jsonEncoding;
- }
-
- public void setJsonEncoding(String jsonEncoding) {
- this.jsonEncoding = jsonEncoding;
- }
-
- public Boolean getEncoding() {
- return encoding;
- }
-
- public void setEncoding(Boolean encoding) {
- this.encoding = encoding;
- }
-
- public Boolean getDecoding() {
- return decoding;
- }
-
- public void setDecoding(Boolean decoding) {
- this.decoding = decoding;
- }
}
/**
* Generic Error Reporting class.
*/
+ @AllArgsConstructor
public static class Error {
private String msg;
- public Error(String msg) {
- this.setError(msg);
- }
-
public String getError() {
return msg;
}
}
}
}
-
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * 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.system;
import java.util.Properties;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
/**
* Programmatic entry point to the management layer.
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Main {
/**
* Symmetric Key to decode sensitive configuration data.
*/
protected static final String SYSTEM_SYMM_KEY = "engine.symm.key";
- /** constructor (hides public default one). */
- private Main() {
- }
-
/**
* main.
*
*/
/* start logger */
- Logger logger = LoggerFactory.getLogger(Main.class);
+ var logger = LoggerFactory.getLogger(Main.class);
/* system properties */
setSystemProperties();
.setTargetEntity("controller:" + controllerName)
.setTargetServiceName("start");
- final PolicyController controller =
+ final var controller =
PolicyEngineConstants.getManager().createPolicyController(controllerName, controllerProperties);
controller.start();
}
}
}
-}
\ No newline at end of file
+}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * 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.system;
+import lombok.AccessLevel;
import lombok.Getter;
+import lombok.NoArgsConstructor;
-public class PolicyControllerConstants {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class PolicyControllerConstants {
/**
* Factory that tracks and manages Policy Controllers.
*/
@Getter
private static final PolicyControllerFactory factory = new IndexedPolicyControllerFactory();
-
- private PolicyControllerConstants() {
- // do nothing
- }
}
package org.onap.policy.drools.system;
+import lombok.AccessLevel;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import org.onap.policy.common.utils.network.NetworkUtil;
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class PolicyEngineConstants {
/**
*/
@Getter
private static final PolicyEngine manager = new PolicyEngineManager();
-
- private PolicyEngineConstants() {
- // do nothing
- }
}
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NonNull;
+import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.endpoints.event.comm.Topic;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
/**
* Policy Engine Manager Implementation.
*/
+@ToString(onlyExplicitlyIncluded = true)
class PolicyEngineManager implements PolicyEngine {
/**
* String literals.
* Is the Policy Engine running.
*/
@Getter
+ @ToString.Include
private volatile boolean alive = false;
/**
* Is the engine locked.
*/
@Getter
+ @ToString.Include
private volatile boolean locked = false;
/**
&& policyControllers.size() == configControllers.size());
}
- @Override
- public String toString() {
- return "PolicyEngineManager [alive=" + this.alive + ", locked=" + this.locked + "]";
- }
-
// these methods may be overridden by junit tests
protected List<PolicyEngineFeatureApi> getEngineProviders() {
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
+import lombok.Getter;
+import lombok.ToString;
import org.onap.policy.common.endpoints.event.comm.Topic;
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
* This implementation of the Policy Controller merely aggregates and tracks for management purposes
* all underlying resources that this controller depends upon.
*/
+@ToString(onlyExplicitlyIncluded = true)
public class AggregatedPolicyController implements PolicyController, TopicListener {
private static final String BEFORE_OFFER_FAILURE = "{}: feature {} before-offer failure because of {}";
/**
* identifier for this policy controller.
*/
+ @Getter
+ @ToString.Include
private final String name;
/**
* Abstracted Event Sources List regardless communication technology.
*/
- protected final List<TopicSource> sources;
+ @Getter
+ protected final List<TopicSource> topicSources;
/**
* Abstracted Event Sinks List regardless communication technology.
*/
- protected final List<TopicSink> sinks;
+ @Getter
+ protected final List<TopicSink> topicSinks;
/**
* Mapping topics to sinks.
/**
* Is this Policy Controller running (alive) ? reflects invocation of start()/stop() only.
*/
+ @Getter
+ @ToString.Include
private volatile boolean alive;
/**
* are permitted, more specifically: start(), deliver() and onTopicEvent(). It does not affect
* the ability to stop the underlying drools infrastructure
*/
+ @Getter
+ @ToString.Include
private volatile boolean locked;
/**
* Policy Drools Controller.
*/
+ @ToString.Include
protected final AtomicReference<DroolsController> droolsController = new AtomicReference<>();
/**
// Create/Reuse Readers/Writers for all event sources endpoints
- this.sources = getEndpointManager().addTopicSources(properties);
- this.sinks = getEndpointManager().addTopicSinks(properties);
+ this.topicSources = getEndpointManager().addTopicSources(properties);
+ this.topicSinks = getEndpointManager().addTopicSinks(properties);
initDrools(properties);
initSinks();
protected void initDrools(Properties properties) {
try {
// Register with drools infrastructure
- this.droolsController.set(getDroolsFactory().build(properties, sources, sinks));
+ this.droolsController.set(getDroolsFactory().build(properties, topicSources, topicSinks));
} catch (Exception | LinkageError e) {
logger.error("{}: cannot init-drools", this);
throw new IllegalArgumentException(e);
*/
private void initSinks() {
this.topic2Sinks.clear();
- for (TopicSink sink : sinks) {
+ for (TopicSink sink : topicSinks) {
this.topic2Sinks.put(sink.getTopic(), sink);
}
}
return finalSuccess;
}
- /**
- * {@inheritDoc}.
- */
- @Override
- public String getName() {
- return this.name;
- }
-
/**
* {@inheritDoc}.
*/
// register for events
- for (TopicSource source : sources) {
+ for (TopicSource source : topicSources) {
source.register(this);
}
- for (TopicSink sink : sinks) {
+ for (TopicSink sink : topicSinks) {
try {
sink.start();
} catch (Exception e) {
// 1. Stop registration
- for (TopicSource source : sources) {
+ for (TopicSource source : topicSources) {
source.unregister(this);
}
return success;
}
- /**
- * {@inheritDoc}.
- */
- @Override
- public boolean isAlive() {
- return this.alive;
- }
-
/**
* {@inheritDoc}.
*/
return success;
}
- /**
- * {@inheritDoc}.
- */
- @Override
- public boolean isLocked() {
- return this.locked;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public List<TopicSource> getTopicSources() {
- return this.sources;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public List<TopicSink> getTopicSinks() {
- return this.sinks;
- }
-
/**
* {@inheritDoc}.
*/
return this.properties;
}
- @Override
- public String toString() {
- return "AggregatedPolicyController [name=" + name + ", alive=" + alive
- + ", locked=" + locked + ", droolsController=" + droolsController + "]";
- }
-
// the following methods may be overridden by junit tests
protected SystemPersistence getPersistenceManager() {
import java.util.concurrent.ConcurrentHashMap;
import lombok.AccessLevel;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import org.onap.policy.drools.core.lock.AlwaysFailLock;
import org.onap.policy.drools.core.lock.Lock;
import org.onap.policy.drools.core.lock.LockCallback;
* will be added to the map once free() or extend() is invoked, provided there isn't
* already an entry.
*/
+@Getter
+@NoArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class LockManager<T extends FeatureLockImpl> implements PolicyResourceLockManager {
private static final Logger logger = LoggerFactory.getLogger(LockManager.class);
private boolean locked = false;
- /**
- * Constructs the object.
- */
- protected LockManager() {
- super();
- }
-
- @Override
- public boolean isAlive() {
- return alive;
- }
-
@Override
public synchronized boolean start() {
if (alive) {
stop();
}
- @Override
- public boolean isLocked() {
- return locked;
- }
-
@Override
public synchronized boolean lock() {
if (locked) {
* ============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.
return false;
}
- AtomicBoolean result = new AtomicBoolean(false);
+ var result = new AtomicBoolean(false);
resource2lock.computeIfPresent(getResourceId(), (resourceId, curlock) -> {
// validate parameters
EventProtocolParams params = dec.getAllValues().get(0);
assertEquals(ARTIFACT, params.getArtifactId());
- assertEquals(gson1, params.getCustomCoder());
+ assertEquals(gson1, params.getCustomGsonCoder());
assertEquals(Object.class.getName(), params.getEventClass());
assertEquals(GROUP, params.getGroupId());
assertEquals(CLASS_LOADER_HASHCODE, params.getModelClassLoaderHash());
params = dec.getAllValues().get(1);
assertEquals(ARTIFACT, params.getArtifactId());
- assertEquals(gson1, params.getCustomCoder());
+ assertEquals(gson1, params.getCustomGsonCoder());
assertEquals(String.class.getName(), params.getEventClass());
assertEquals(GROUP, params.getGroupId());
assertEquals(CLASS_LOADER_HASHCODE, params.getModelClassLoaderHash());
params = enc.getAllValues().get(0);
assertEquals(ARTIFACT, params.getArtifactId());
- assertEquals(gson2, params.getCustomCoder());
+ assertEquals(gson2, params.getCustomGsonCoder());
assertEquals(Integer.class.getName(), params.getEventClass());
assertEquals(GROUP, params.getGroupId());
assertEquals(CLASS_LOADER_HASHCODE, params.getModelClassLoaderHash());
* ============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 static org.junit.Assert.assertTrue;
import java.util.Properties;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
import org.junit.Test;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
/**
* Event Test Class.
*/
+ @Getter
+ @AllArgsConstructor
public static class EventTest {
-
private String field;
-
- public EventTest(String field) {
- super();
- this.field = field;
- }
-
- public String getField() {
- return this.field;
- }
-
- public void setField(String field) {
- this.field = field;
- }
}
@Test
EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT)
.topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getName())
.protocolFilter(new JsonProtocolFilter()).customGsonCoder(null)
- .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()));
+ .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()).build());
final String json = EventProtocolCoderConstants.getManager().encode(NOOP_TOPIC,
new DroolsConfiguration(ENCODER_ARTIFACT, ENCODER_GROUP, ENCODER_VERSION));
* ============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.
new GsonProtocolCoderToolset(EventProtocolParams.builder().topic(JUNIT_PROTOCOL_CODER_TOPIC)
.groupId(releaseId.getGroupId()).artifactId(releaseId.getArtifactId())
.eventClass(ThreeStrings.class.getName()).protocolFilter(protocolFilter)
- .customGsonCoder(null).modelClassLoaderHash(12345678), CONTROLLER_ID);
+ .customGsonCoder(null).modelClassLoaderHash(12345678).build(), CONTROLLER_ID);
Assert.assertNotNull(gsonToolset.getEncoder());
Assert.assertNotNull(gsonToolset.getDecoder());
}
CoderFilters coderFilters = coderToolset.getCoder(ThreeStrings.class.getName());
- Assert.assertSame(coderFilters.getCodedClass(), ThreeStrings.class.getName());
+ Assert.assertSame(coderFilters.getFactClass(), ThreeStrings.class.getName());
Assert.assertSame(coderFilters.getFilter(), protocolFilter);
Assert.assertNotNull(coderFilters.getFilter().getRule());
/*-
* ============LICENSE_START=======================================================
- * Configuration Test * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * ONAP
+ * ================================================================================
+ * 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.protocol.configuration;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import java.util.Properties;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.junit.Test;
import org.onap.policy.common.utils.gson.GsonTestUtils;
assertEquals(DROOLS_CONFIG2, controllerConfig2.declaredPropertyOrNotFound(DROOLS_STRING, DROOLS_CONFIG2));
assertEquals(NAME, controllerConfig2.declaredPropertyOrNotFound("dummy", NAME));
- int hashCode = new HashCodeBuilder().append(NAME2).append(OPERATION2).append(DROOLS_CONFIG2)
- .append(additionalProperties).toHashCode();
- assertEquals(controllerConfig2.hashCode(), hashCode);
+ assertThat(controllerConfig2.hashCode()).isNotZero();
}
@Test
/*-
* ============LICENSE_START=======================================================
- * Configuration Test
+ * ONAP
* ================================================================================
- * 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.protocol.configuration;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Properties;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.junit.Test;
import org.onap.policy.common.utils.gson.GsonTestUtils;
assertEquals(VERSION2, droolsConfig2.declaredPropertyOrNotFound(VERSION_STRING, VERSION2));
assertEquals(ARTIFACT2, droolsConfig2.declaredPropertyOrNotFound("dummy", ARTIFACT2));
- final int hashCode = new HashCodeBuilder().append(ARTIFACT2).append(GROUPID2).append(VERSION2)
- .append(additionalProperties).toHashCode();
- assertEquals(droolsConfig2.hashCode(), hashCode);
+ assertThat(droolsConfig2.hashCode()).isNotZero();
}
@Test
/*-
* ============LICENSE_START=======================================================
- * Configuration Test
+ * ONAP
* ================================================================================
- * 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.
@Test
public void testToString() {
- assertTrue(mgr.toString().startsWith("PolicyEngineManager ["));
+ assertTrue(mgr.toString().startsWith("PolicyEngineManager("));
}
/**
EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT)
.topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getName())
.protocolFilter(new JsonProtocolFilter()).customGsonCoder(null)
- .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()));
+ .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()).build());
assertTrue(PolicyEngineConstants.getManager().deliver(NOOP_TOPIC,
new DroolsConfiguration(ENCODER_ARTIFACT, ENCODER_GROUP, ENCODER_VERSION)));
* ============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.
@Test
public void testToString() {
- assertTrue(apc.toString().startsWith("AggregatedPolicyController ["));
+ assertTrue(apc.toString().startsWith("AggregatedPolicyController("));
}
private void validateDeliverFailure(String topic, String event) {
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * 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.
package org.onap.policy.drools.utils;
+import lombok.AllArgsConstructor;
import org.apache.commons.configuration2.interpol.Lookup;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.utils.security.CryptoCoder;
/**
* Crypto Coder value look up. Syntax: ${enc:encoded-value}.
*/
+@AllArgsConstructor
public class CryptoCoderValueLookup implements Lookup {
protected final CryptoCoder cryptoCoder;
- /**
- * Crypto Coder Lookup.
- *
- * @param crypto crypto coder
- */
- public CryptoCoderValueLookup(CryptoCoder crypto) {
- this.cryptoCoder = crypto;
- }
-
@Override
public String lookup(String key) {
if (StringUtils.isBlank(key)) {
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicReference;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.apache.commons.configuration2.ConfigurationConverter;
import org.apache.commons.configuration2.SystemConfiguration;
import org.onap.policy.common.utils.security.CryptoCoder;
* This class provides utilities to read properties from a properties
* file, and optionally get notifications of future changes.
*/
-public class PropertyUtil {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class PropertyUtil {
public static final String ENV_WITH_DEFAULT_PROPERTY_PREFIX = "envd";
public static final String CRYPTO_CODER_PROPERTY_PREFIX = "enc";
* ============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.utils;
+import lombok.AllArgsConstructor;
+
/**
* Reference to an object. Used within functional methods, where thread-safety is not
* required.
- *
+ *
* @param <T> type of object contained within the reference
*/
+@AllArgsConstructor
public class Reference<T> {
private T value;
- /**
- * Constructor.
- *
- * @param value value
- */
- public Reference(T value) {
- this.value = value;
- }
-
/**
* Get the value.
- *
+ *
* @return the current value
*/
public final T get() {
/**
* Sets the reference to point to a new value.
- *
+ *
* @param newValue the new value
*/
public final void set(T newValue) {
/**
* Sets the value to a new value, if the value is currently the same as the old value.
- *
+ *
* @param oldValue old value
* @param newValue new value
* @return {@code true} if the value was updated, {@code false} otherwise
* ============LICENSE_START=======================================================
* policy-utils
* ================================================================================
- * 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.utils;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* Reflection utilities.
*
*/
-public class ReflectionUtil {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ReflectionUtil {
protected static final Logger logger = LoggerFactory.getLogger(ReflectionUtil.class);
- private ReflectionUtil() {
- }
-
/**
* returns (if exists) a class fetched from a given classloader.
- *
+ *
* @param classLoader the class loader
* @param className the class name
* @return the actual class
* @throws IllegalArgumentException if an invalid parameter has been passed in
*/
- public static Class<?> fetchClass(ClassLoader classLoader,
+ public static Class<?> fetchClass(ClassLoader classLoader,
String className) {
if (classLoader == null) {
throw new IllegalArgumentException("A class loader must be provided");
/**
* Is class.
- *
+ *
* @param classLoader target class loader
* @param classname class name to fetch
* @return true if exists
/**
* Is it a sub class.
- *
+ *
* @param parent superclass
* @param presumedSubclass subclass
* @return true if it is a sub class
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.AbstractMatcherFilter;
import ch.qos.logback.core.spi.FilterReply;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
import org.slf4j.Marker;
/**
* Logger Marker Filters to be used in logback.xml configuration
* to accept/deny metric or transaction (audit) events
*/
+@AllArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class LoggerMarkerFilter extends AbstractMatcherFilter<ILoggingEvent> {
protected final Marker marker;
- protected LoggerMarkerFilter(Marker marker) {
- this.marker = marker;
- }
-
@Override
public FilterReply decide(ILoggingEvent event) {
package org.onap.policy.drools.utils.logging;
import ch.qos.logback.classic.LoggerContext;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
/**
* Loger Utils.
*/
-public class LoggerUtil {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class LoggerUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(LoggerUtil.class);
*/
public static final Marker TRANSACTION_LOG_MARKER = MarkerFactory.getMarker(TRANSACTION_LOG_MARKER_NAME);
- private LoggerUtil() {
- // Empty constructor
- }
-
/**
* Set the log level of a logger.
*
package org.onap.policy.drools.utils.logging;
-public class MdcTransactionConstants {
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class MdcTransactionConstants {
/*
* The fields must match the naming given at
* https://wiki.onap.org/pages/viewpage.action?pageId=20087036
* Status Code Error.
*/
public static final String STATUS_CODE_FAILURE = "ERROR";
-
- private MdcTransactionConstants() {
- // do nothing
- }
}