* @return a generic Topic Source
* @throws IllegalArgumentException when invalid arguments are provided
*/
- public List<? extends TopicSource> addTopicSources(Properties properties)
- throws IllegalArgumentException;
+ public List<TopicSource> addTopicSources(Properties properties);
/**
* Add Topic Sinks to the communication infrastructure initialized per
* @return a generic Topic Sink
* @throws IllegalArgumentException when invalid arguments are provided
*/
- public List<? extends TopicSink> addTopicSinks(Properties properties)
- throws IllegalArgumentException;
+ public List<TopicSink> addTopicSinks(Properties properties);
/**
* gets all Topic Sources
* @return the Topic Source List
*/
- List<? extends TopicSource> getTopicSources();
+ List<TopicSource> getTopicSources();
/**
* get the Topic Sources for the given topic name
* @throws IllegalStateException if the entity is in an invalid state
* @throws IllegalArgumentException if invalid parameters are present
*/
- public List<? extends TopicSource> getTopicSources(List<String> topicNames)
- throws IllegalStateException, IllegalArgumentException;
+ public List<TopicSource> getTopicSources(List<String> topicNames);
/**
* gets the Topic Source for the given topic name and
*/
public TopicSource getTopicSource(Topic.CommInfrastructure commType,
String topicName)
- throws IllegalStateException, IllegalArgumentException,
- UnsupportedOperationException;
+ throws UnsupportedOperationException;
/**
* get the UEB Topic Source for the given topic name
* example multiple TopicReaders for a topic name and communication infrastructure
* @throws IllegalArgumentException if invalid parameters are present
*/
- public UebTopicSource getUebTopicSource(String topicName)
- throws IllegalStateException, IllegalArgumentException;
+ public UebTopicSource getUebTopicSource(String topicName);
/**
* get the DMAAP Topic Source for the given topic name
* example multiple TopicReaders for a topic name and communication infrastructure
* @throws IllegalArgumentException if invalid parameters are present
*/
- public DmaapTopicSource getDmaapTopicSource(String topicName)
- throws IllegalStateException, IllegalArgumentException;
+ public DmaapTopicSource getDmaapTopicSource(String topicName);
/**
* get the Topic Sinks for the given topic name
* @throws IllegalStateException
* @throws IllegalArgumentException
*/
- public List<? extends TopicSink> getTopicSinks(List<String> topicNames)
- throws IllegalStateException, IllegalArgumentException;
+ public List<TopicSink> getTopicSinks(List<String> topicNames);
/**
* get the Topic Sinks for the given topic name and
*/
public TopicSink getTopicSink(Topic.CommInfrastructure commType,
String topicName)
- throws IllegalStateException, IllegalArgumentException,
- UnsupportedOperationException;
+ throws UnsupportedOperationException;
/**
* get the Topic Sinks for the given topic name and
* example multiple TopicWriters for a topic name and communication infrastructure
* @throws IllegalArgumentException if invalid parameters are present
*/
- public List<? extends TopicSink> getTopicSinks(String topicName)
- throws IllegalStateException, IllegalArgumentException;
+ public List<TopicSink> getTopicSinks(String topicName);
/**
* get the UEB Topic Source for the given topic name
* example multiple TopicReaders for a topic name and communication infrastructure
* @throws IllegalArgumentException if invalid parameters are present
*/
- public UebTopicSink getUebTopicSink(String topicName)
- throws IllegalStateException, IllegalArgumentException;
+ public UebTopicSink getUebTopicSink(String topicName);
/**
* get the no-op Topic Sink for the given topic name
* example multiple TopicReaders for a topic name and communication infrastructure
* @throws IllegalArgumentException if invalid parameters are present
*/
- public NoopTopicSink getNoopTopicSink(String topicName)
- throws IllegalStateException, IllegalArgumentException;
+ public NoopTopicSink getNoopTopicSink(String topicName);
/**
* get the DMAAP Topic Source for the given topic name
* example multiple TopicReaders for a topic name and communication infrastructure
* @throws IllegalArgumentException if invalid parameters are present
*/
- public DmaapTopicSink getDmaapTopicSink(String topicName)
- throws IllegalStateException, IllegalArgumentException;
+ public DmaapTopicSink getDmaapTopicSink(String topicName);
/**
* gets only the UEB Topic Sources
* gets all Topic Sinks
* @return the Topic Sink List
*/
- public List<? extends TopicSink> getTopicSinks();
+ public List<TopicSink> getTopicSinks();
/**
* gets only the UEB Topic Sinks
*/
protected volatile boolean alive = false;
- /**
- * {@inheritDoc}
- */
@Override
- public List<? extends TopicSource> addTopicSources(Properties properties) throws IllegalArgumentException {
+ public List<TopicSource> addTopicSources(Properties properties) {
// 1. Create UEB Sources
// 2. Create DMAAP Sources
- List<TopicSource> sources = new ArrayList<TopicSource>();
+ List<TopicSource> sources = new ArrayList<>();
sources.addAll(UebTopicSource.factory.build(properties));
sources.addAll(DmaapTopicSource.factory.build(properties));
return sources;
}
- /**
- * {@inheritDoc}
- */
@Override
- public List<? extends TopicSink> addTopicSinks(Properties properties) throws IllegalArgumentException {
+ public List<TopicSink> addTopicSinks(Properties properties) {
// 1. Create UEB Sinks
// 2. Create DMAAP Sinks
- List<TopicSink> sinks = new ArrayList<TopicSink>();
+ List<TopicSink> sinks = new ArrayList<>();
sinks.addAll(UebTopicSink.factory.build(properties));
sinks.addAll(DmaapTopicSink.factory.build(properties));
return sinks;
}
- /**
- * {@inheritDoc}
- */
@Override
- public List<? extends TopicSource> getTopicSources() {
+ public List<TopicSource> getTopicSources() {
- List<TopicSource> sources = new ArrayList<TopicSource>();
+ List<TopicSource> sources = new ArrayList<>();
sources.addAll(UebTopicSource.factory.inventory());
sources.addAll(DmaapTopicSource.factory.inventory());
return sources;
}
- /**
- * {@inheritDoc}
- */
@Override
- public List<? extends TopicSink> getTopicSinks() {
+ public List<TopicSink> getTopicSinks() {
- List<TopicSink> sinks = new ArrayList<TopicSink>();
+ List<TopicSink> sinks = new ArrayList<>();
sinks.addAll(UebTopicSink.factory.inventory());
sinks.addAll(DmaapTopicSink.factory.inventory());
return sinks;
}
- /**
- * {@inheritDoc}
- */
@JsonIgnore
@Override
public List<UebTopicSource> getUebTopicSources() {
return UebTopicSource.factory.inventory();
}
- /**
- * {@inheritDoc}
- */
@JsonIgnore
@Override
public List<DmaapTopicSource> getDmaapTopicSources() {
return DmaapTopicSource.factory.inventory();
}
- /**
- * {@inheritDoc}
- */
@JsonIgnore
@Override
public List<UebTopicSink> getUebTopicSinks() {
return UebTopicSink.factory.inventory();
}
- /**
- * {@inheritDoc}
- */
@JsonIgnore
@Override
public List<DmaapTopicSink> getDmaapTopicSinks() {
return DmaapTopicSink.factory.inventory();
}
- /**
- * {@inheritDoc}
- */
@JsonIgnore
@Override
public List<NoopTopicSink> getNoopTopicSinks() {
return NoopTopicSink.factory.inventory();
}
- /**
- * {@inheritDoc}
- */
@Override
- public boolean start() throws IllegalStateException {
+ public boolean start() {
synchronized (this) {
if (this.locked) {
}
- /**
- * {@inheritDoc}
- */
@Override
- public boolean stop() throws IllegalStateException {
+ public boolean stop() {
/*
* stop regardless if it is locked, in other
*/
@JsonIgnore
protected List<Startable> getEndpoints() {
- List<Startable> endpoints = new ArrayList<Startable>();
+ List<Startable> endpoints = new ArrayList<>();
endpoints.addAll(this.getTopicSources());
endpoints.addAll(this.getTopicSinks());
return endpoints;
}
-
- /**
- * {@inheritDoc}
- */
@Override
- public void shutdown() throws IllegalStateException {
+ public void shutdown() {
UebTopicSource.factory.destroy();
UebTopicSink.factory.destroy();
DmaapTopicSink.factory.destroy();
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean isAlive() {
return this.alive;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean lock() {
return true;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean unlock() {
synchronized (this) {
return true;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean isLocked() {
return this.locked;
}
- /**
- * {@inheritDoc}
- */
@Override
- public List<? extends TopicSource> getTopicSources(List<String> topicNames)
- throws IllegalStateException, IllegalArgumentException {
+ public List<TopicSource> getTopicSources(List<String> topicNames) {
if (topicNames == null) {
throw new IllegalArgumentException("must provide a list of topics");
}
- List<TopicSource> sources = new ArrayList<TopicSource>();
+ List<TopicSource> sources = new ArrayList<>();
for (String topic: topicNames) {
try {
TopicSource uebSource = this.getUebTopicSource(topic);
return sources;
}
- /**
- * {@inheritDoc}
- */
@Override
- public List<? extends TopicSink> getTopicSinks(List<String> topicNames)
- throws IllegalStateException, IllegalArgumentException {
+ public List<TopicSink> getTopicSinks(List<String> topicNames) {
if (topicNames == null) {
throw new IllegalArgumentException("must provide a list of topics");
}
- List<TopicSink> sinks = new ArrayList<TopicSink>();
+ List<TopicSink> sinks = new ArrayList<>();
for (String topic: topicNames) {
try {
TopicSink uebSink = this.getUebTopicSink(topic);
return sinks;
}
- /**
- * {@inheritDoc}
- */
@Override
public TopicSource getTopicSource(Topic.CommInfrastructure commType, String topicName)
- throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException {
+ throws UnsupportedOperationException {
if (commType == null) {
throw new IllegalArgumentException
}
}
- /**
- * {@inheritDoc}
- */
@Override
public TopicSink getTopicSink(Topic.CommInfrastructure commType, String topicName)
- throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException {
+ throws UnsupportedOperationException {
if (commType == null) {
throw new IllegalArgumentException
("Invalid parameter: a communication infrastructure required to fetch " + topicName);
}
}
- /**
- * {@inheritDoc}
- */
@Override
- public List<? extends TopicSink> getTopicSinks(String topicName)
- throws IllegalStateException, IllegalArgumentException {
+ public List<TopicSink> getTopicSinks(String topicName) {
if (topicName == null) {
throw new IllegalArgumentException
("Invalid parameter: a communication infrastructure required to fetch " + topicName);
}
- List<TopicSink> sinks = new ArrayList<TopicSink>();
+ List<TopicSink> sinks = new ArrayList<>();
try {
sinks.add(this.getUebTopicSink(topicName));
return sinks;
}
- /**
- * {@inheritDoc}
- */
@Override
- public UebTopicSource getUebTopicSource(String topicName) throws IllegalStateException, IllegalArgumentException {
+ public UebTopicSource getUebTopicSource(String topicName) {
return UebTopicSource.factory.get(topicName);
}
- /**
- * {@inheritDoc}
- */
@Override
- public UebTopicSink getUebTopicSink(String topicName) throws IllegalStateException, IllegalArgumentException {
+ public UebTopicSink getUebTopicSink(String topicName) {
return UebTopicSink.factory.get(topicName);
}
@Override
- public DmaapTopicSource getDmaapTopicSource(String topicName)
- throws IllegalStateException, IllegalArgumentException {
+ public DmaapTopicSource getDmaapTopicSource(String topicName) {
return DmaapTopicSource.factory.get(topicName);
}
@Override
- public DmaapTopicSink getDmaapTopicSink(String topicName) throws IllegalStateException, IllegalArgumentException {
+ public DmaapTopicSink getDmaapTopicSink(String topicName) {
return DmaapTopicSink.factory.get(topicName);
}
@Override
- public NoopTopicSink getNoopTopicSink(String topicName) throws IllegalStateException, IllegalArgumentException {
+ public NoopTopicSink getNoopTopicSink(String topicName) {
return NoopTopicSink.factory.get(topicName);
}
/**
* Listener for event messages entering the Policy Engine
*/
+@FunctionalInterface
public interface TopicListener {
/**
String partitionKey,
boolean managed,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException;
+ boolean allowSelfSignedCerts);
/**
* Creates an DMAAP Topic Sink based on properties files
* @return an DMAAP Topic Sink
* @throws IllegalArgumentException if invalid parameters are present
*/
- public List<DmaapTopicSink> build(Properties properties)
- throws IllegalArgumentException;
+ public List<DmaapTopicSink> build(Properties properties);
/**
* Instantiates a new DMAAP Topic Sink
* @return an DMAAP Topic Sink
* @throws IllegalArgumentException if invalid parameters are present
*/
- public DmaapTopicSink build(List<String> servers, String topic)
- throws IllegalArgumentException;
+ public DmaapTopicSink build(List<String> servers, String topic);
/**
* Destroys an DMAAP Topic Sink based on a topic
* @throws IllegalStateException if the DMAAP Topic Reader is
* an incorrect state
*/
- public DmaapTopicSink get(String topic)
- throws IllegalArgumentException, IllegalStateException;
+ public DmaapTopicSink get(String topic);
/**
* Provides a snapshot of the DMAAP Topic Sinks
/**
* DMAAP Topic Name Index
*/
- protected HashMap<String, DmaapTopicSink> dmaapTopicWriters =
- new HashMap<String, DmaapTopicSink>();
+ protected HashMap<String, DmaapTopicSink> dmaapTopicWriters = new HashMap<>();
- /**
- * {@inheritDoc}
- */
@Override
public DmaapTopicSink build(List<String> servers,
String topic,
Map<String,String> additionalProps,
boolean managed,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ boolean allowSelfSignedCerts) {
if (topic == null || topic.isEmpty()) {
throw new IllegalArgumentException("A topic must be provided");
}
}
- /**
- * {@inheritDoc}
- */
@Override
public DmaapTopicSink build(List<String> servers,
String topic,
String password,
String partitionKey,
boolean managed,
- boolean useHttps, boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ boolean useHttps, boolean allowSelfSignedCerts) {
if (topic == null || topic.isEmpty()) {
throw new IllegalArgumentException("A topic must be provided");
}
}
-
- /**
- * {@inheritDoc}
- */
@Override
- public DmaapTopicSink build(List<String> servers, String topic) throws IllegalArgumentException {
+ public DmaapTopicSink build(List<String> servers, String topic) {
return this.build(servers, topic, null, null, null, null, null, true, false, false);
}
-
- /**
- * {@inheritDoc}
- */
@Override
- public List<DmaapTopicSink> build(Properties properties) throws IllegalArgumentException {
+ public List<DmaapTopicSink> build(Properties properties) {
String writeTopics = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS);
if (writeTopics == null || writeTopics.isEmpty()) {
logger.info("{}: no topic for DMaaP Sink", this);
- return new ArrayList<DmaapTopicSink>();
+ return new ArrayList<>();
}
- List<String> writeTopicList = new ArrayList<String>(Arrays.asList(writeTopics.split("\\s*,\\s*")));
- List<DmaapTopicSink> newDmaapTopicSinks = new ArrayList<DmaapTopicSink>();
+ List<String> writeTopicList = new ArrayList<>(Arrays.asList(writeTopics.split("\\s*,\\s*")));
+ List<DmaapTopicSink> newDmaapTopicSinks = new ArrayList<>();
synchronized(this) {
for (String topic: writeTopicList) {
if (this.dmaapTopicWriters.containsKey(topic)) {
PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX);
List<String> serverList;
- if (servers != null && !servers.isEmpty()) serverList = new ArrayList<String>(Arrays.asList(servers.split("\\s*,\\s*")));
+ if (servers != null && !servers.isEmpty()) serverList = new ArrayList<>(Arrays.asList(servers.split("\\s*,\\s*")));
else serverList = new ArrayList<>();
String apiKey = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS +
}
}
- /**
- * {@inheritDoc}
- */
@Override
- public void destroy(String topic)
- throws IllegalArgumentException {
+ public void destroy(String topic) {
if (topic == null || topic.isEmpty()) {
throw new IllegalArgumentException("A topic must be provided");
dmaapTopicWriter.shutdown();
}
- /**
- * {@inheritDoc}
- */
@Override
public void destroy() {
List<DmaapTopicSink> writers = this.inventory();
}
}
- /**
- * {@inheritDoc}
- */
@Override
- public DmaapTopicSink get(String topic)
- throws IllegalArgumentException, IllegalStateException {
+ public DmaapTopicSink get(String topic) {
if (topic == null || topic.isEmpty()) {
throw new IllegalArgumentException("A topic must be provided");
}
}
- /**
- * {@inheritDoc}
- */
@Override
public synchronized List<DmaapTopicSink> inventory() {
List<DmaapTopicSink> writers =
- new ArrayList<DmaapTopicSink>(this.dmaapTopicWriters.values());
+ new ArrayList<>(this.dmaapTopicWriters.values());
return writers;
}
* @param topic topic
* @throws IllegalArgumentException if an invalid argument has been passed in
*/
- public NoopTopicSink(List<String> servers, String topic) throws IllegalArgumentException {
+ public NoopTopicSink(List<String> servers, String topic) {
super(servers, topic);
}
@Override
- public boolean send(String message) throws IllegalArgumentException, IllegalStateException {
+ public boolean send(String message) {
if (message == null || message.isEmpty())
throw new IllegalArgumentException("Message to send is empty");
}
@Override
- public boolean start() throws IllegalStateException {
+ public boolean start() {
logger.info("{}: starting", this);
synchronized(this) {
}
@Override
- public boolean stop() throws IllegalStateException {
+ public boolean stop() {
synchronized(this) {
this.alive = false;
}
}
@Override
- public void shutdown() throws IllegalStateException {
+ public void shutdown() {
this.stop();
}
* @return a noop topic sink
* @throws IllegalArgumentException if invalid parameters are present
*/
- public List<NoopTopicSink> build(Properties properties)
- throws IllegalArgumentException;
+ public List<NoopTopicSink> build(Properties properties);
/**
* builds a noop sink
* @return a noop topic sink
* @throws IllegalArgumentException if invalid parameters are present
*/
- public NoopTopicSink build(List<String> servers, String topic, boolean managed)
- throws IllegalArgumentException;
+ public NoopTopicSink build(List<String> servers, String topic, boolean managed);
/**
* Destroys a sink based on the topic
* @throws IllegalArgumentException if an invalid topic is provided
* @throws IllegalStateException if the sink is in an incorrect state
*/
- public NoopTopicSink get(String topic)
- throws IllegalArgumentException, IllegalStateException;
+ public NoopTopicSink get(String topic);
/**
* Provides a snapshot of the UEB Topic Writers
/**
* noop topic sinks map
*/
- protected HashMap<String, NoopTopicSink> noopTopicSinks = new HashMap<String, NoopTopicSink>();
+ protected HashMap<String, NoopTopicSink> noopTopicSinks = new HashMap<>();
@Override
- public List<NoopTopicSink> build(Properties properties) throws IllegalArgumentException {
+ public List<NoopTopicSink> build(Properties properties) {
String sinkTopics = properties.getProperty(PolicyProperties.PROPERTY_NOOP_SINK_TOPICS);
if (sinkTopics == null || sinkTopics.isEmpty()) {
logger.info("{}: no topic for noop sink", this);
- return new ArrayList<NoopTopicSink>();
+ return new ArrayList<>();
}
- List<String> sinkTopicList = new ArrayList<String>(Arrays.asList(sinkTopics.split("\\s*,\\s*")));
+ List<String> sinkTopicList = new ArrayList<>(Arrays.asList(sinkTopics.split("\\s*,\\s*")));
List<NoopTopicSink> newSinks = new ArrayList<NoopTopicSink>();
synchronized(this) {
for (String topic: sinkTopicList) {
if (servers == null || servers.isEmpty())
servers = "noop";
- List<String> serverList = new ArrayList<String>(Arrays.asList(servers.split("\\s*,\\s*")));
+ List<String> serverList = new ArrayList<>(Arrays.asList(servers.split("\\s*,\\s*")));
String managedString = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS + "." + topic +
PolicyProperties.PROPERTY_MANAGED_SUFFIX);
}
@Override
- public NoopTopicSink build(List<String> servers, String topic, boolean managed) throws IllegalArgumentException {
+ public NoopTopicSink build(List<String> servers, String topic, boolean managed) {
if (servers == null) {
servers = new ArrayList<>();
}
}
@Override
- public NoopTopicSink get(String topic) throws IllegalArgumentException, IllegalStateException {
+ public NoopTopicSink get(String topic) {
if (topic == null || topic.isEmpty()) {
throw new IllegalArgumentException("A topic must be provided");
}
String partitionKey,
boolean managed,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException;
+ boolean allowSelfSignedCerts);
/**
* Creates an UEB Topic Writer based on properties files
* @return an UEB Topic Writer
* @throws IllegalArgumentException if invalid parameters are present
*/
- public List<UebTopicSink> build(Properties properties)
- throws IllegalArgumentException;
+ public List<UebTopicSink> build(Properties properties);
/**
* Instantiates a new UEB Topic Writer
* @return an UEB Topic Writer
* @throws IllegalArgumentException if invalid parameters are present
*/
- public UebTopicSink build(List<String> servers, String topic)
- throws IllegalArgumentException;
+ public UebTopicSink build(List<String> servers, String topic);
/**
* Destroys an UEB Topic Writer based on a topic
* @throws IllegalStateException if the UEB Topic Reader is
* an incorrect state
*/
- public UebTopicSink get(String topic)
- throws IllegalArgumentException, IllegalStateException;
+ public UebTopicSink get(String topic);
/**
* Provides a snapshot of the UEB Topic Writers
protected HashMap<String, UebTopicSink> uebTopicSinks =
new HashMap<String, UebTopicSink>();
- /**
- * {@inheritDoc}
- */
@Override
public UebTopicSink build(List<String> servers,
String topic,
String partitionKey,
boolean managed,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ boolean allowSelfSignedCerts) {
if (servers == null || servers.isEmpty()) {
throw new IllegalArgumentException("UEB Server(s) must be provided");
}
- /**
- * {@inheritDoc}
- */
@Override
- public UebTopicSink build(List<String> servers, String topic) throws IllegalArgumentException {
+ public UebTopicSink build(List<String> servers, String topic) {
return this.build(servers, topic, null, null, null, true, false, false);
}
- /**
- * {@inheritDoc}
- */
@Override
- public List<UebTopicSink> build(Properties properties) throws IllegalArgumentException {
+ public List<UebTopicSink> build(Properties properties) {
String writeTopics = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS);
if (writeTopics == null || writeTopics.isEmpty()) {
logger.info("{}: no topic for UEB Sink", this);
- return new ArrayList<UebTopicSink>();
+ return new ArrayList<>();
}
- List<String> writeTopicList = new ArrayList<String>(Arrays.asList(writeTopics.split("\\s*,\\s*")));
- List<UebTopicSink> newUebTopicSinks = new ArrayList<UebTopicSink>();
+ List<String> writeTopicList = new ArrayList<>(Arrays.asList(writeTopics.split("\\s*,\\s*")));
+ List<UebTopicSink> newUebTopicSinks = new ArrayList<>();
synchronized(this) {
for (String topic: writeTopicList) {
if (this.uebTopicSinks.containsKey(topic)) {
continue;
}
- List<String> serverList = new ArrayList<String>(Arrays.asList(servers.split("\\s*,\\s*")));
+ List<String> serverList = new ArrayList<>(Arrays.asList(servers.split("\\s*,\\s*")));
String apiKey = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS +
"." + topic +
}
}
- /**
- * {@inheritDoc}
- */
@Override
- public void destroy(String topic)
- throws IllegalArgumentException {
+ public void destroy(String topic) {
if (topic == null || topic.isEmpty()) {
throw new IllegalArgumentException("A topic must be provided");
uebTopicWriter.shutdown();
}
- /**
- * {@inheritDoc}
- */
@Override
public void destroy() {
List<UebTopicSink> writers = this.inventory();
}
}
- /**
- * {@inheritDoc}
- */
@Override
- public UebTopicSink get(String topic)
- throws IllegalArgumentException, IllegalStateException {
+ public UebTopicSink get(String topic) {
if (topic == null || topic.isEmpty()) {
throw new IllegalArgumentException("A topic must be provided");
}
}
- /**
- * {@inheritDoc}
- */
@Override
public synchronized List<UebTopicSink> inventory() {
List<UebTopicSink> writers =
- new ArrayList<UebTopicSink>(this.uebTopicSinks.values());
+ new ArrayList<>(this.uebTopicSinks.values());
return writers;
}
}
}
- /**
- * {@inheritDoc}
- */
+ @Override
public Iterable<String> fetch() throws IOException {
return this.consumer.fetch();
}
- /**
- * {@inheritDoc}
- */
+ @Override
public void close() {
this.consumer.close();
}
*/
public abstract class DmaapConsumerWrapper implements BusConsumer {
+ /**
+ * logger
+ */
private static Logger logger = LoggerFactory.getLogger(DmaapConsumerWrapper.class);
+ /**
+ * fetch timeout
+ */
protected int fetchTimeout;
+
+ /**
+ * close condition
+ */
protected Object closeCondition = new Object();
/**
this.consumer.setPassword(password);
}
- /**
- * {@inheritDoc}
- */
@Override
public Iterable<String> fetch() throws InterruptedException, IOException {
MRConsumerResponse response = this.consumer.fetchWithReturnConsumerResponse();
synchronized (closeCondition) {
closeCondition.wait(fetchTimeout);
}
- return new ArrayList<String>();
+ return new ArrayList<>();
} else {
logger.debug("DMaaP consumer received {} : {}" +
response.getResponseCode(),
synchronized (closeCondition) {
closeCondition.wait(fetchTimeout);
}
+
/* fall through */
}
}
if (response.getActualMessages() == null)
- return new ArrayList<String>();
+ return new ArrayList<>();
else
return response.getActualMessages();
}
- /**
- * {@inheritDoc}
- */
@Override
public void close() {
synchronized (closeCondition) {
// super constructor sets servers = {""} if empty to avoid errors when using DME2
if ((servers.size() == 1 && servers.get(0).equals("")) ||
- (servers == null) || (servers.size() == 0)) {
+ (servers == null) || (servers.isEmpty())) {
throw new IllegalArgumentException("Must provide at least one host for HTTP AAF");
}
*
* @param servletPath servlet path
* @param restClass JAX-RS API Class
+ *
* @throws IllegalArgumentException unable to process because of invalid input
* @throws IllegalStateException unable to process because of invalid state
*/
- public void addServletClass(String servletPath, String restClass)
- throws IllegalArgumentException, IllegalStateException;
+ public void addServletClass(String servletPath, String restClass);
/**
* adds a package containing JAX-RS classes to serve REST requests
*
* @param servletPath servlet path
* @param restPackage JAX-RS package to scan
+ *
* @throws IllegalArgumentException unable to process because of invalid input
* @throws IllegalStateException unable to process because of invalid state
*/
- public void addServletPackage(String servletPath, String restPackage)
- throws IllegalArgumentException, IllegalStateException;
+ public void addServletPackage(String servletPath, String restPackage);
/**
* blocking start of the http server
* @return true if start was successful
*
* @throws IllegalArgumentException if arguments are invalid
+ * @throws InterruptedException if the blocking operation is interrupted
*/
- public boolean waitedStart(long maxWaitTime) throws IllegalArgumentException;
+ public boolean waitedStart(long maxWaitTime) throws InterruptedException;
/**
import java.util.HashMap;
import org.eclipse.jetty.servlet.ServletHolder;
+import org.onap.policy.drools.utils.NetworkUtil;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
* REST Jetty Server that uses Jersey Servlets to support JAX-RS Web Services
*/
public class JettyJerseyServer extends JettyServletServer {
+
+ /**
+ * Swagger API Base Path
+ */
+ protected static final String SWAGGER_API_BASEPATH = "swagger.api.basepath";
/**
- * Jersey Packages Init Param Name
+ * Swagger Context ID
*/
- protected static final String JERSEY_INIT_PACKAGES_PARAM_NAME = "jersey.config.server.provider.packages";
+ protected static final String SWAGGER_CONTEXT_ID = "swagger.context.id";
/**
- * Jersey Packages Init Param Value
+ * Swagger Scanner ID
*/
- protected static final String JERSEY_INIT_PACKAGES_PARAM_VALUE = "com.fasterxml.jackson.jaxrs.json";
+ protected static final String SWAGGER_SCANNER_ID = "swagger.scanner.id";
+
+ /**
+ * Swagger Pretty Print
+ */
+ protected static final String SWAGGER_PRETTY_PRINT = "swagger.pretty.print";
/**
* Swagger Packages
*/
protected static final String SWAGGER_INIT_PACKAGES_PARAM_VALUE = "io.swagger.jaxrs.listing";
+
+ /**
+ * Jersey Packages Init Param Name
+ */
+ protected static final String JERSEY_INIT_PACKAGES_PARAM_NAME = "jersey.config.server.provider.packages";
+
+ /**
+ * Jersey Packages Init Param Value
+ */
+ protected static final String JERSEY_INIT_PACKAGES_PARAM_VALUE = "com.fasterxml.jackson.jaxrs.json";
/**
* Jersey Classes Init Param Name
*
* @throws IllegalArgumentException in invalid arguments are provided
*/
- public JettyJerseyServer(String name, String host, int port, String contextPath, boolean swagger)
- throws IllegalArgumentException {
+ public JettyJerseyServer(String name, String host, int port, String contextPath, boolean swagger) {
super(name, host, port, contextPath);
if (swagger) {
ServletHolder swaggerServlet = context.addServlet(JerseyJaxrsConfig.class, "/");
String hostname = this.connector.getHost();
- if (hostname == null || hostname.isEmpty() || hostname.equals("0.0.0.0")) {
+ if (hostname == null || hostname.isEmpty() || hostname.equals(NetworkUtil.IPv4_WILDCARD_ADDRESS)) {
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
- logger.warn("{}: can't resolve connector's hostname: ", this);
+ logger.warn("{}: can't resolve connector's hostname: {}", this, hostname, e);
hostname = "localhost";
}
}
- swaggerServlet.setInitParameter("swagger.api.basepath",
+ swaggerServlet.setInitParameter(SWAGGER_API_BASEPATH,
"http://" + hostname + ":" + this.connector.getPort() + "/");
- swaggerServlet.setInitParameter("swagger.context.id", swaggerId);
- swaggerServlet.setInitParameter("swagger.scanner.id", swaggerId);
- swaggerServlet.setInitParameter("swagger.pretty.print", "true");
+ swaggerServlet.setInitParameter(SWAGGER_CONTEXT_ID, swaggerId);
+ swaggerServlet.setInitParameter(SWAGGER_SCANNER_ID, swaggerId);
+ swaggerServlet.setInitParameter(SWAGGER_PRETTY_PRINT, "true");
swaggerServlet.setInitOrder(2);
if (logger.isDebugEnabled())
*
* @throws IllegalArgumentException if invalid arguments are provided
*/
- protected synchronized ServletHolder getServlet(String servletPath)
- throws IllegalArgumentException {
+ protected synchronized ServletHolder getServlet(String servletPath) {
ServletHolder jerseyServlet = servlets.get(servletPath);
if (jerseyServlet == null) {
}
@Override
- public synchronized void addServletPackage(String servletPath, String restPackage)
- throws IllegalArgumentException, IllegalStateException {
+ public synchronized void addServletPackage(String servletPath, String restPackage) {
if (restPackage == null || restPackage.isEmpty())
throw new IllegalArgumentException("No discoverable REST package provided");
SWAGGER_INIT_PACKAGES_PARAM_VALUE + "," +
restPackage;
- jerseyServlet.setInitParameter("swagger.context.id", swaggerId);
- jerseyServlet.setInitParameter("swagger.scanner.id", swaggerId);
+ jerseyServlet.setInitParameter(SWAGGER_CONTEXT_ID, swaggerId);
+ jerseyServlet.setInitParameter(SWAGGER_SCANNER_ID, swaggerId);
} else {
initPackages = JERSEY_INIT_PACKAGES_PARAM_VALUE + "," +
restPackage;
}
@Override
- public synchronized void addServletClass(String servletPath, String restClass)
- throws IllegalArgumentException, IllegalStateException {
+ public synchronized void addServletClass(String servletPath, String restClass) {
if (restClass == null || restClass.isEmpty())
throw new IllegalArgumentException("No discoverable REST class provided");
SWAGGER_INIT_CLASSNAMES_PARAM_VALUE + "," +
restClass;
- jerseyServlet.setInitParameter("swagger.context.id", swaggerId);
- jerseyServlet.setInitParameter("swagger.scanner.id", swaggerId);
+ jerseyServlet.setInitParameter(SWAGGER_CONTEXT_ID, swaggerId);
+ jerseyServlet.setInitParameter(SWAGGER_SCANNER_ID, swaggerId);
} else {
initClasses = JERSEY_JACKSON_INIT_CLASSNAMES_PARAM_VALUE + "," + restClass;
}
/*-
* ============LICENSE_START=======================================================
- * policy-endpoints
+ * ONAP
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
*/
public abstract class JettyServletServer implements HttpServletServer, Runnable {
+ /**
+ * Logger
+ */
private static Logger logger = LoggerFactory.getLogger(JettyServletServer.class);
+ /**
+ * server name
+ */
protected final String name;
+ /**
+ * server host address
+ */
protected final String host;
+
+ /**
+ * server port to bind
+ */
protected final int port;
+ /**
+ * server auth user name
+ */
protected String user;
+
+ /**
+ * server auth password name
+ */
protected String password;
+ /**
+ * server base context path
+ */
protected final String contextPath;
+ /**
+ * embedded jetty server
+ */
protected final Server jettyServer;
+
+ /**
+ * servlet context
+ */
protected final ServletContextHandler context;
+
+ /**
+ * jetty connector
+ */
protected final ServerConnector connector;
+ /**
+ * jetty thread
+ */
protected volatile Thread jettyThread;
+ /**
+ * start condition
+ */
protected Object startCondition = new Object();
- public JettyServletServer(String name, String host, int port, String contextPath)
- throws IllegalArgumentException {
+ /**
+ * constructor
+ *
+ * @param name server name
+ * @param host server host
+ * @param port server port
+ * @param contextPath context path
+ *
+ * @throws IllegalArgumentException if invalid parameters are passed in
+ */
+ public JettyServletServer(String name, String host, int port, String contextPath) {
if (name == null || name.isEmpty())
name = "http-" + port;
this.jettyServer.setHandler(context);
}
- /**
- * {@inheritDoc}
- */
@Override
public void setBasicAuthentication(String user, String password, String servletPath) {
if (user == null || user.isEmpty() || password == null || password.isEmpty())
}
/**
- * Jetty Server Execution
+ * jetty server execution
*/
@Override
public void run() {
}
@Override
- public boolean waitedStart(long maxWaitTime) throws IllegalArgumentException {
+ public boolean waitedStart(long maxWaitTime) throws InterruptedException {
logger.info("{}: WAITED-START", this);
if (maxWaitTime < 0)
} catch (InterruptedException e) {
logger.warn("{}: waited-start has been interrupted", this);
- return false;
+ throw e;
}
}
}
}
- /**
- * {@inheritDoc}
- */
@Override
- public boolean start() throws IllegalStateException {
+ public boolean start() {
logger.info("{}: STARTING", this);
synchronized(this) {
return true;
}
- /**
- * {@inheritDoc}
- */
@Override
- public boolean stop() throws IllegalStateException {
+ public boolean stop() {
logger.info("{}: STOPPING", this);
synchronized(this) {
return true;
}
- /**
- * {@inheritDoc}
- */
@Override
- public void shutdown() throws IllegalStateException {
+ public void shutdown() {
logger.info("{}: SHUTTING DOWN", this);
this.stop();
if (jettyThreadCopy.isAlive()) {
try {
- jettyThreadCopy.join(1000L);
+ jettyThreadCopy.join(2000L);
} catch (InterruptedException e) {
logger.warn("{}: error while shutting down management server", this);
+ Thread.currentThread().interrupt();
}
if (!jettyThreadCopy.isInterrupted()) {
try {
jettyThreadCopy.interrupt();
} catch(Exception e) {
// do nothing
- logger.warn("{}: exception while shutting down (OK)", this);
+ logger.warn("{}: exception while shutting down (OK)", this, e);
}
}
}
this.jettyServer.destroy();
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean isAlive() {
if (this.jettyThread != null)
private static Logger logger = LoggerFactory.getLogger(HttpClientTest.class);
@BeforeClass
- public static void setUp() {
+ public static void setUp() throws InterruptedException {
logger.info("-- setup() --");
/* echo server */
public DroolsController build(Properties properties,
List<? extends TopicSource> eventSources,
List<? extends TopicSink> eventSinks)
- throws IllegalArgumentException, LinkageError;
+ throws LinkageError;
/**
* Explicit construction of a Drools Controller
String version,
List<TopicCoderFilterConfiguration> decoderConfigurations,
List<TopicCoderFilterConfiguration> encoderConfigurations)
- throws IllegalArgumentException, LinkageError;
+ throws LinkageError;
/**
* Releases the Drools Controller from operation
*/
public DroolsController get(String groupId,
String artifactId,
- String version)
- throws IllegalArgumentException;
+ String version);
/**
* returns the current inventory of Drools Controllers
/**
* Policy Controller Name Index
*/
- protected HashMap<String, DroolsController> droolsControllers =
- new HashMap<String, DroolsController>();
+ protected HashMap<String, DroolsController> droolsControllers = new HashMap<>();
/**
* Null Drools Controller
}
}
- /**
- * {@inheritDoc}
- */
@Override
public DroolsController build(Properties properties,
List<? extends TopicSource> eventSources,
List<? extends TopicSink> eventSinks)
- throws IllegalArgumentException, LinkageError {
+ throws LinkageError {
String groupId = properties.getProperty(PolicyProperties.RULES_GROUPID);
if (groupId == null || groupId.isEmpty())
* @throws IllegalArgumentException invalid input data
*/
protected List<TopicCoderFilterConfiguration> codersAndFilters
- (Properties properties, List<? extends Topic> topicEntities)
- throws IllegalArgumentException {
+ (Properties properties, List<? extends Topic> topicEntities) {
String PROPERTY_TOPIC_ENTITY_PREFIX;
List<TopicCoderFilterConfiguration>
- topics2DecodedClasses2Filters =
- new ArrayList<TopicCoderFilterConfiguration>();
+ topics2DecodedClasses2Filters = new ArrayList<>();
if (topicEntities.isEmpty())
return topics2DecodedClasses2Filters;
for (Topic topic: topicEntities) {
/* source or sink ? ueb or dmaap? */
- boolean isSource = (topic instanceof TopicSource);
+ boolean isSource = topic instanceof TopicSource;
CommInfrastructure commInfra = topic.getTopicCommInfrastructure();
if (commInfra == CommInfrastructure.UEB) {
if (isSource) {
continue;
}
- List<PotentialCoderFilter> classes2Filters = new ArrayList<PotentialCoderFilter>();
+ List<PotentialCoderFilter> classes2Filters = new ArrayList<>();
List<String> aTopicClasses =
- new ArrayList<String>(Arrays.asList(eventClasses.split("\\s*,\\s*")));
+ new ArrayList<>(Arrays.asList(eventClasses.split("\\s*,\\s*")));
for (String aClass: aTopicClasses) {
"." + aClass +
PolicyProperties.PROPERTY_TOPIC_EVENTS_FILTER_SUFFIX);
- List<Pair<String,String>> filters = new ArrayList<Pair<String,String>>();
+ List<Pair<String,String>> filters = new ArrayList<>();
if (filter == null || filter.isEmpty()) {
// 4. topic -> class -> with no filters
// There are filters associated with the applicability of
// this class for decoding.
List<String> listOfFilters =
- new ArrayList<String>(Arrays.asList(filter.split("\\s*,\\s*")));
+ new ArrayList<>(Arrays.asList(filter.split("\\s*,\\s*")));
for (String nameValue: listOfFilters) {
String fieldName;
return topics2DecodedClasses2Filters;
}
- /**
- * {@inheritDoc}
- * @param decoderConfiguration
- */
@Override
public DroolsController build(String newGroupId,
String newArtifactId,
String newVersion,
List<TopicCoderFilterConfiguration> decoderConfigurations,
List<TopicCoderFilterConfiguration> encoderConfigurations)
- throws IllegalArgumentException, LinkageError {
+ throws LinkageError {
- if (newGroupId == null || newArtifactId == null || newVersion == null ||
- newGroupId.isEmpty() || newArtifactId.isEmpty() || newVersion.isEmpty()) {
- throw new IllegalArgumentException("Missing maven coordinates: " +
- newGroupId + ":" + newArtifactId + ":" +
- newVersion);
- }
+ if (newGroupId == null || newGroupId.isEmpty())
+ throw new IllegalArgumentException("Missing maven group-id coordinate");
+
+ if (newArtifactId == null || newArtifactId.isEmpty())
+ throw new IllegalArgumentException("Missing maven artifact-id coordinate");
+
+ if (newVersion == null || newVersion.isEmpty())
+ throw new IllegalArgumentException("Missing maven version coordinate");
String controllerId = newGroupId + ":" + newArtifactId;
DroolsController controllerCopy = null;
return controller;
}
- /**
- * {@inheritDoc}
- */
@Override
- public void destroy(DroolsController controller) throws IllegalArgumentException {
+ public void destroy(DroolsController controller) {
unmanage(controller);
controller.halt();
}
- /**
- * {@inheritDoc}
- */
@Override
public void destroy() {
List<DroolsController> controllers = this.inventory();
* @return
* @throws IllegalArgumentException
*/
- protected void unmanage(DroolsController controller) throws IllegalArgumentException {
+ protected void unmanage(DroolsController controller) {
if (controller == null) {
throw new IllegalArgumentException("No controller provided");
}
}
}
- /**
- * {@inheritDoc}
- */
@Override
- public void shutdown(DroolsController controller) throws IllegalArgumentException {
+ public void shutdown(DroolsController controller) {
this.unmanage(controller);
controller.shutdown();
}
- /**
- * {@inheritDoc}
- */
@Override
public void shutdown() {
List<DroolsController> controllers = this.inventory();
}
}
- /**
- * {@inheritDoc}
- */
@Override
public DroolsController get(String groupId,
String artifactId,
- String version)
- throws IllegalArgumentException, IllegalStateException {
+ String version) {
if (groupId == null || artifactId == null ||
groupId.isEmpty() || artifactId.isEmpty()) {
}
}
- /**
- * {@inheritDoc}
- */
@Override
public List<DroolsController> inventory() {
List<DroolsController> controllers =
- new ArrayList<DroolsController>(this.droolsControllers.values());
+ new ArrayList<>(this.droolsControllers.values());
return controllers;
}
String artifactId,
String version,
List<TopicCoderFilterConfiguration> decoderConfigurations,
- List<TopicCoderFilterConfiguration> encoderConfigurations)
- throws IllegalArgumentException {
+ List<TopicCoderFilterConfiguration> encoderConfigurations) {
- if (logger.isInfoEnabled())
- logger.info("DROOLS CONTROLLER: instantiation " + this +
- " -> {" + groupId + ":" + artifactId + ":" + version + "}");
-
- if (groupId == null || artifactId == null || version == null ||
- groupId.isEmpty() || artifactId.isEmpty() || version.isEmpty()) {
- throw new IllegalArgumentException("Missing maven coordinates: " +
- groupId + ":" + artifactId + ":" +
- version);
- }
+ logger.info("drools-controller instantiation [{}:{}:{}]", groupId, artifactId, version);
+
+ if (groupId == null || groupId.isEmpty())
+ throw new IllegalArgumentException("Missing maven group-id coordinate");
+
+ if (artifactId == null || artifactId.isEmpty())
+ throw new IllegalArgumentException("Missing maven artifact-id coordinate");
+
+ if (version == null || version.isEmpty())
+ throw new IllegalArgumentException("Missing maven version coordinate");
this.policyContainer= new PolicyContainer(groupId, artifactId, version);
this.init(decoderConfigurations, encoderConfigurations);
- if (logger.isInfoEnabled())
- logger.info("DROOLS CONTROLLER: instantiation completed " + this);
+ logger.debug("{}: instantiation completed ", this);
}
/**
this.modelClassLoaderHash = this.policyContainer.getClassLoader().hashCode();
}
- /**
- * {@inheritDoc}
- */
@Override
public void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
List<TopicCoderFilterConfiguration> decoderConfigurations,
List<TopicCoderFilterConfiguration> encoderConfigurations)
- throws IllegalArgumentException, LinkageError {
+ throws LinkageError {
- if (logger.isInfoEnabled())
- logger.info("UPDATE-TO-VERSION: " + this + " -> {" + newGroupId + ":" + newArtifactId + ":" + newVersion + "}");
+ logger.info("{}: updating version -> [{}:{}:{}]", newGroupId, newArtifactId, newVersion);
- if (newGroupId == null || newArtifactId == null || newVersion == null ||
- newGroupId.isEmpty() || newArtifactId.isEmpty() || newVersion.isEmpty()) {
- throw new IllegalArgumentException("Missing maven coordinates: " +
- newGroupId + ":" + newArtifactId + ":" +
- newVersion);
- }
+ if (newGroupId == null || newGroupId.isEmpty())
+ throw new IllegalArgumentException("Missing maven group-id coordinate");
+
+ if (newArtifactId == null || newArtifactId.isEmpty())
+ throw new IllegalArgumentException("Missing maven artifact-id coordinate");
+
+ if (newVersion == null || newVersion.isEmpty())
+ throw new IllegalArgumentException("Missing maven version coordinate");
if (newGroupId.equalsIgnoreCase(DroolsController.NO_GROUP_ID) ||
newArtifactId.equalsIgnoreCase(DroolsController.NO_ARTIFACT_ID) ||
* @param decoderConfiguration list of topic -> decoders -> filters mapping
*/
protected void initCoders(List<TopicCoderFilterConfiguration> coderConfigurations,
- boolean decoder)
- throws IllegalArgumentException {
+ boolean decoder) {
if (logger.isInfoEnabled())
logger.info("INIT-CODERS: " + this);
/**
* remove decoders.
*/
- protected void removeDecoders()
- throws IllegalArgumentException {
+ protected void removeDecoders(){
if (logger.isInfoEnabled())
logger.info("REMOVE-DECODERS: " + this);
/**
* remove decoders.
*/
- protected void removeEncoders()
- throws IllegalArgumentException {
+ protected void removeEncoders() {
if (logger.isInfoEnabled())
logger.info("REMOVE-ENCODERS: " + this);
}
- /**
- * {@inheritDoc}
- */
@Override
- public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) throws IllegalStateException {
+ public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) {
if (!ReflectionUtil.isClass
(this.policyContainer.getClassLoader(), coderClass.getCanonicalName())) {
logger.error(this + coderClass.getCanonicalName() + " cannot be retrieved. ");
}
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean start() {
return this.policyContainer.start();
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean stop() {
return this.policyContainer.stop();
}
-
- /**
- * {@inheritDoc}
- */
@Override
- public void shutdown() throws IllegalStateException {
+ public void shutdown() {
logger.info("{}: SHUTDOWN", this);
try {
}
-
- /**
- * {@inheritDoc}
- */
@Override
- public void halt() throws IllegalStateException {
+ public void halt() {
logger.info("{}: HALT", this);
try {
}
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean isAlive() {
return this.alive;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean offer(String topic, String event) {
logger.debug("{}: OFFER: {} <- {}", this, topic, event);
// 0. Check if the policy container has any sessions
- if (this.policyContainer.getPolicySessions().size() <= 0) {
+ if (this.policyContainer.getPolicySessions().isEmpty()) {
// no sessions
return true;
}
return true;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean deliver(TopicSink sink, Object event)
- throws IllegalArgumentException,
- IllegalStateException,
- UnsupportedOperationException {
+ throws UnsupportedOperationException {
if (logger.isInfoEnabled())
logger.info(this + "DELIVER: " + event + " FROM " + this + " TO " + sink);
}
- /**
- * {@inheritDoc}
- */
@Override
public String getVersion() {
return this.policyContainer.getVersion();
}
- /**
- * {@inheritDoc}
- */
@Override
public String getArtifactId() {
return this.policyContainer.getArtifactId();
}
- /**
- * {@inheritDoc}
- */
@Override
public String getGroupId() {
return this.policyContainer.getGroupId();
return modelClassLoaderHash;
}
- /**
- * {@inheritDoc}
- */
@Override
public synchronized boolean lock() {
logger.info("LOCK: " + this);
return true;
}
- /**
- * {@inheritDoc}
- */
@Override
public synchronized boolean unlock() {
logger.info("UNLOCK: " + this);
return true;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean isLocked() {
return this.locked;
}
- /**
- * {@inheritDoc}
- */
@JsonIgnore
+ @Override
public PolicyContainer getContainer() {
return this.policyContainer;
}
- /**
- * {@inheritDoc}
- */
@JsonProperty("sessions")
@Override
public List<String> getSessionNames() {
return getSessionNames(true);
}
- /**
- * {@inheritDoc}
- */
@JsonProperty("sessionCoordinates")
@Override
public List<String> getCanonicalSessionNames() {
* @return session names
*/
protected List<String> getSessionNames(boolean abbreviated) {
- List<String> sessionNames = new ArrayList<String>();
+ List<String> sessionNames = new ArrayList<>();
try {
for (PolicySession session: this.policyContainer.getPolicySessions()) {
if (abbreviated)
* @return the attached Policy Container
*/
protected List<PolicySession> getSessions() {
- List<PolicySession> sessions = new ArrayList<PolicySession>();
+ List<PolicySession> sessions = new ArrayList<>();
sessions.addAll(this.policyContainer.getPolicySessions());
return sessions;
}
throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
}
- /**
- * {@inheritDoc}
- */
@Override
- public Map<String,Integer> factClassNames(String sessionName) throws IllegalArgumentException {
+ public Map<String,Integer> factClassNames(String sessionName) {
if (sessionName == null || sessionName.isEmpty())
throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
-
- // List<String> classNames = new ArrayList<>();
+
Map<String,Integer> classNames = new HashMap<>();
PolicySession session = getSession(sessionName);
return classNames;
}
- /**
- * {@inheritDoc}
- */
@Override
- public long factCount(String sessionName) throws IllegalArgumentException {
+ public long factCount(String sessionName) {
if (sessionName == null || sessionName.isEmpty())
throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
return session.getKieSession().getFactCount();
}
- /**
- * {@inheritDoc}
- */
@Override
public List<Object> facts(String sessionName, String className, boolean delete) {
if (sessionName == null || sessionName.isEmpty())
return factObjects;
}
- /**
- * {@inheritDoc}
- */
@Override
public List<Object> factQuery(String sessionName, String queryName, String queriedEntity, boolean delete, Object... queryParams) {
if (sessionName == null || sessionName.isEmpty())
return factObjects;
}
- /**
- * {@inheritDoc}
- */
@Override
- public Class<?> fetchModelClass(String className) throws IllegalStateException {
+ public Class<?> fetchModelClass(String className) {
Class<?> modelClass =
ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className);
return modelClass;
}
}
-
- /**
- * {@inheritDoc}
- */
@Override
public boolean isBrained() {
return true;
*/
public class NullDroolsController implements DroolsController {
- /**
- * {@inheritDoc}
- */
@Override
- public boolean start() throws IllegalStateException {
+ public boolean start() {
return false;
}
- /**
- * {@inheritDoc}
- */
@Override
- public boolean stop() throws IllegalStateException {
+ public boolean stop() {
return false;
}
- /**
- * {@inheritDoc}
- */
@Override
- public void shutdown() throws IllegalStateException {
+ public void shutdown() {
return;
}
- /**
- * {@inheritDoc}
- */
@Override
- public void halt() throws IllegalStateException {
+ public void halt() {
return;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean isAlive() {
return false;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean lock() {
return false;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean unlock() {
return false;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean isLocked() {
return false;
}
- /**
- * {@inheritDoc}
- */
@Override
public String getGroupId() {
return NO_GROUP_ID;
}
- /**
- * {@inheritDoc}
- */
@Override
public String getArtifactId() {
return NO_ARTIFACT_ID;
}
- /**
- * {@inheritDoc}
- */
@Override
public String getVersion() {
return NO_VERSION;
}
- /**
- * {@inheritDoc}
- */
@Override
public List<String> getSessionNames() {
- return new ArrayList<String>();
+ return new ArrayList<>();
}
- /**
- * {@inheritDoc}
- */
@Override
public List<String> getCanonicalSessionNames() {
- return new ArrayList<String>();
+ return new ArrayList<>();
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean offer(String topic, String event) {
return false;
}
- /**
- * {@inheritDoc}
- */
@Override
- public boolean deliver(TopicSink sink, Object event)
- throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException {
+ public boolean deliver(TopicSink sink, Object event) throws UnsupportedOperationException {
throw new IllegalStateException(this.getClass().getCanonicalName() + " invoked");
}
- /**
- * {@inheritDoc}
- */
@Override
public Object[] getRecentSourceEvents() {
return new String[0];
}
- /**
- * {@inheritDoc}
- */
@Override
public PolicyContainer getContainer() {
return null;
}
- /**
- * {@inheritDoc}
- */
@Override
public String[] getRecentSinkEvents() {
return new String[0];
}
- /**
- * {@inheritDoc}
- */
@Override
- public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) throws IllegalStateException {
+ public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) {
throw new IllegalStateException(this.getClass().getCanonicalName() + " invoked");
}
- /**
- * {@inheritDoc}
- */
@Override
- public Class<?> fetchModelClass(String className) throws IllegalArgumentException {
+ public Class<?> fetchModelClass(String className) {
throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked");
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean isBrained() {
return false;
}
- /**
- * {@inheritDoc}
- */
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
return builder.toString();
}
- /**
- * {@inheritDoc}
- */
@Override
public void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
List<TopicCoderFilterConfiguration> decoderConfigurations,
throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked");
}
- /**
- * {@inheritDoc}
- */
@Override
public Map<String, Integer> factClassNames(String sessionName)
throws IllegalArgumentException {
return new HashMap<String,Integer>();
}
- /**
- * {@inheritDoc}
- */
@Override
- public long factCount(String sessionName) throws IllegalArgumentException {
+ public long factCount(String sessionName) {
return 0;
}
- /**
- * {@inheritDoc}
- */
@Override
public List<Object> facts(String sessionName, String className, boolean delete) {
- return new ArrayList<Object>();
+ return new ArrayList<>();
}
- /**
- * {@inheritDoc}
- */
@Override
public List<Object> factQuery(String sessionName, String queryName,
String queriedEntity,
boolean delete, Object... queryParams) {
- return new ArrayList<Object>();
+ return new ArrayList<>();
}
}
*
* @param controllerName the controller name
* @param configuration object containing the configuration
+ *
* @return true if storage is succesful, false otherwise
* @throws IllegalArgumentException if the configuration cannot be handled by the persistence manager
*/
- public boolean storeController(String controllerName, Object configuration)
- throws IllegalArgumentException;
+ public boolean storeController(String controllerName, Object configuration);
/**
* delete controller configuration
*
* @param controllerName controller name
* @return properties for this controller
+ *
* @throws IllegalArgumentException if the controller name does not lead to a properties configuration
*/
- public Properties getControllerProperties(String controllerName)
- throws IllegalArgumentException;
+ public Properties getControllerProperties(String controllerName);
/**
* get properties by name
*
* @param name
* @return properties
+ *
* @throws IllegalArgumentException if the name does not lead to a properties configuration
*/
- public Properties getProperties(String name) throws IllegalArgumentException;
+ public Properties getProperties(String name);
/**
* Persistence Manager. For now it is a file-based properties management,
/**
* deletes properties-based controller configuration
* @param controllerName the controller name
+ *
* @return true if the properties has been deleted from disk, false otherwise
*/
@Override
}
@Override
- public Properties getControllerProperties(String controllerName) throws IllegalArgumentException {
+ public Properties getControllerProperties(String controllerName) {
return this.getProperties(controllerName + CONTROLLER_SUFFIX_IDENTIFIER);
}
@Override
- public Properties getProperties(String name) throws IllegalArgumentException {
+ public Properties getProperties(String name) {
Path propertiesPath =
Paths.get(CONFIG_DIR_NAME, name + ".properties");
logger.warn("{}: can't read properties @ {}", name, propertiesPath);
throw new IllegalArgumentException("can't read properties for " +
name + " @ " +
- propertiesPath);
+ propertiesPath, e);
}
}
}
/**
* Logger
*/
- private static Logger logger = LoggerFactory.getLogger(GsonProtocolCoderToolset.class);
+ private static final Logger logger = LoggerFactory.getLogger(GsonProtocolCoderToolset.class);
/**
* Formatter for JSON encoding/decoding
*/
@JsonIgnore
- public static DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx");
+ public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx");
@JsonIgnore
- public static DateTimeFormatter zuluFormat = DateTimeFormatter.ISO_INSTANT;
+ public static final DateTimeFormatter zuluFormat = DateTimeFormatter.ISO_INSTANT;
/**
* Adapter for ZonedDateTime
*/
-
public static class GsonUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> {
public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context)
return Response.status(Response.Status.OK).
entity(PolicyEngine.manager.getFeatureProvider(featureName)).build();
} catch(IllegalArgumentException iae) {
+ logger.debug("feature unavailable: {}", featureName, iae);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(iae.getMessage())).build();
}
entity(PolicyController.factory.getFeatureProvider(featureName)).
build();
} catch(IllegalArgumentException iae) {
+ logger.debug("{}: cannot feature {} because of {}", this, featureName, iae.getMessage(), iae);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(iae.getMessage())).build();
}
entity(PolicyController.factory.get(controllerName)).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + " not acceptable")).
build();
entity(new Error(controllerName + " does not exist")).
build();
} catch (IllegalArgumentException e) {
- logger.info("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
+ logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.BAD_REQUEST).
entity(new Error(controllerName + " not found: " + e.getMessage())).
build();
} catch (IllegalStateException e) {
- logger.info("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
+ logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + " not acceptable")).build();
}
try {
PolicyEngine.manager.removePolicyController(controllerName);
} catch (IllegalArgumentException | IllegalStateException e) {
- logger.info("{}: cannot remove policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
+ logger.debug("{}: cannot remove policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
entity(new Error(e.getMessage())).
build();
entity(controller.getProperties()).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + " not acceptable")).
build();
entity(drools).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + " not acceptable")).
build();
entity(sessionCounts).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + " not acceptable")).
build();
entity(drools.factClassNames(sessionName)).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error("entity not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + sessionName + " not acceptable")).
build();
else
return Response.status(Response.Status.OK).entity(facts.size()).build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + sessionName + ":" + factType +
" not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + sessionName + ":" + factType +
" not acceptable")).
List<Object> facts = drools.facts(sessionName, factType, true);
return Response.status(Response.Status.OK).entity(facts).build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}",
+ this, controllerName, sessionName, factType, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + sessionName + ":" + factType +
" not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}",
+ this, controllerName, sessionName, factType, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + sessionName + ":" + factType +
" not acceptable")).
build();
} catch (Exception e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}",
+ this, controllerName, sessionName, factType, e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
entity(new Error(e.getMessage())).
build();
else
return Response.status(Response.Status.OK).entity(facts.size()).build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}",
+ this, controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + sessionName + ":" + queryName +
queriedEntity + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}",
+ this, controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + sessionName + ":" + queryName +
queriedEntity + " not acceptable")).
build();
} catch (Exception e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}",
+ this, controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
entity(new Error(e.getMessage())).
build();
facts = drools.factQuery(sessionName, queryName, queriedEntity, false, queryParameters.toArray());
return Response.status(Response.Status.OK).entity(facts).build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
+ this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + sessionName + ":" + queryName +
queriedEntity + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
+ this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + sessionName + ":" + queryName +
queriedEntity + " not acceptable")).
build();
} catch (Exception e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
+ this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
entity(new Error(e.getMessage())).
build();
facts = drools.factQuery(sessionName, queryName, queriedEntity, true, queryParameters.toArray());
return Response.status(Response.Status.OK).entity(facts).build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
+ this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + sessionName + ":" + queryName +
queriedEntity + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
+ this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + sessionName + ":" + queryName +
queriedEntity + " not acceptable")).
build();
} catch (Exception e) {
+ logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}",
+ this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
entity(new Error(e.getMessage())).
build();
entity(decoders).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + " not acceptable")).
build();
entity(filters).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + " not acceptable")).
build();
entity(decoder).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}",
+ this, controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + topic + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}",
+ this, controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + topic + " not acceptable")).
build();
entity(decoder.getCoders()).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}",
+ this, controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + topic + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}",
+ this, controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + topic + " not acceptable")).
build();
entity(filters).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}",
+ this, controllerName, topic, factClass, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + topic + ":" +
factClass + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}",
+ this, controllerName, topic, factClass, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + topic + ":" +
factClass + " not acceptable")).
entity(filters).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} filters {} because of {}",
+ this, controllerName, topic, factClass, configFilters, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + topic + ":" +
factClass + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} filters {} because of {}",
+ this, controllerName, topic, factClass, configFilters, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + topic + ":" +
factClass + " not acceptable")).
entity(filter.getRules()).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}",
+ this, controllerName, topic, factClass, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + topic + ":" +
factClass + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}",
+ this, controllerName, topic, factClass, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + topic + ":" +
factClass + " not acceptable")).
entity(filter.getRules(ruleName)).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} rule {} because of {}",
+ this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + topic + ":" +
factClass + ": " + ruleName + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} rule {} because of {}",
+ this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + topic + ":" +
factClass + ":" + ruleName + " not acceptable")).
entity(filter.getRules()).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} rule {} because of {}",
+ this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + topic + ":" +
factClass + ": " + ruleName + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} rule {} because of {}",
+ this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + topic + ":" +
factClass + ":" + ruleName + " not acceptable")).
entity(filter.getRules()).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot access decoder filter rules for policy-controller {} topic {} type {} rule {} because of {}",
+ this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + topic + ":" +
factClass + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot access decoder filter rules for policy-controller {} topic {} type {} rule {} because of {}",
+ this, controllerName, topic, factClass, ruleName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + topic + ":" +
factClass + " not acceptable")).
try {
policyController = PolicyController.factory.get(controllerName);
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}",
+ this, controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(controllerName + ":" + topic + ":" +
" not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}",
+ this, controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + ":" + topic + ":" +
" not acceptable")).
json);
result.decoding = true;
} catch (Exception e) {
+ logger.debug("{}: cannot get policy-controller {} topic {} because of {}",
+ this, controllerName, topic, e.getMessage(), e);
return Response.status(Response.Status.BAD_REQUEST).
entity(new Error(e.getMessage())).
build();
result.encoding = true;
} catch (Exception e) {
// continue so to propagate decoding results ..
+ logger.debug("{}: cannot encode for policy-controller {} topic {} because of {}",
+ this, controllerName, topic, e.getMessage(), e);
}
return Response.status(Response.Status.OK).
encoders = EventProtocolCoder.manager.getEncoderFilters
(drools.getGroupId(), drools.getArtifactId());
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot get encoder filters for policy-controller {} because of {}",
+ this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.BAD_REQUEST).
entity(new Error(controllerName + " not found: " + e.getMessage())).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot get encoder filters for policy-controller {} because of {}",
+ this, controllerName, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(controllerName + " is not accepting the request")).build();
}
entity(new Error("Failure to inject event over " + topic)).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}",
+ this, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(topic + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}",
+ this, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(topic + " not acceptable due to current state")).
build();
} catch (Exception e) {
+ logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}",
+ this, topic, e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
entity(new Error(e.getMessage())).
build();
entity(new Error("Failure to inject event over " + topic)).
build();
} catch (IllegalArgumentException e) {
+ logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}",
+ this, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).
entity(new Error(topic + " not found")).
build();
} catch (IllegalStateException e) {
+ logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}",
+ this, topic, e.getMessage(), e);
return Response.status(Response.Status.NOT_ACCEPTABLE).
entity(new Error(topic + " not acceptable due to current state")).
build();
} catch (Exception e) {
+ logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}",
+ this, topic, e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
entity(new Error(e.getMessage())).
build();
* @return the underlying drools controller
* @throws IllegalArgumentException if an invalid controller name has been passed in
*/
- protected DroolsController getDroolsController(String controllerName) throws IllegalArgumentException {
+ protected DroolsController getDroolsController(String controllerName) {
PolicyController controller = PolicyController.factory.get(controllerName);
if (controller == null)
throw new IllegalArgumentException(controllerName + " does not exist");
* @throws IllegalArgumentException when invalid or insufficient
* properties are provided
*/
- public void configure(Properties properties) throws IllegalArgumentException;
+ public void configure(Properties properties);
/**
* registers a new Policy Controller with the Policy Engine
* this operation is not permitted.
* @return the newly instantiated Policy Controller
*/
- public PolicyController createPolicyController(String name, Properties properties)
- throws IllegalArgumentException, IllegalStateException;
+ public PolicyController createPolicyController(String name, Properties properties);
/**
* updates the Policy Engine with the given configuration
* @throws IllegalArgumentException if invalid argument provided
* @throws IllegalStateException if the system is in an invalid state
*/
- public boolean configure(PdpdConfiguration configuration)
- throws IllegalArgumentException, IllegalStateException;
+ public boolean configure(PdpdConfiguration configuration);
/**
* updates a set of Policy Controllers with configuration information
* @throws IllegalArgumentException
* @throws IllegalStateException
*/
- public List<PolicyController> updatePolicyControllers(List<ControllerConfiguration> configuration)
- throws IllegalArgumentException, IllegalStateException;
+ public List<PolicyController> updatePolicyControllers(List<ControllerConfiguration> configuration);
/**
* updates an already existing Policy Controller with configuration information
* @throws IllegalStateException if the controller is in a bad state
* @throws Exception any other reason
*/
- public PolicyController updatePolicyController(ControllerConfiguration configuration)
- throws Exception;
+ public PolicyController updatePolicyController(ControllerConfiguration configuration);
/**
* removes the Policy Controller identified by its name from the Policy Engine
protected Gson decoder = new GsonBuilder().disableHtmlEscaping().create();
- /**
- * {@inheritDoc}
- */
@Override
public synchronized void boot(String cliArgs[]) {
}
}
- /**
- * {@inheritDoc}
- */
@Override
- public synchronized void configure(Properties properties) throws IllegalArgumentException {
+ public synchronized void configure(Properties properties) {
if (properties == null) {
logger.warn("No properties provided");
return;
}
- /**
- * {@inheritDoc}
- */
@Override
public synchronized PolicyController createPolicyController(String name, Properties properties)
throws IllegalArgumentException, IllegalStateException {
}
- /**
- * {@inheritDoc}
- */
@Override
- public boolean configure(PdpdConfiguration config) throws IllegalArgumentException, IllegalStateException {
+ public boolean configure(PdpdConfiguration config) {
if (config == null)
throw new IllegalArgumentException("No configuration provided");
}
}
- /**
- * {@inheritDoc}
- */
@Override
public List<PolicyController> updatePolicyControllers(List<ControllerConfiguration> configControllers)
throws IllegalArgumentException, IllegalStateException {
return policyControllers;
}
- /**
- * {@inheritDoc}
- */
@Override
- public PolicyController updatePolicyController(ControllerConfiguration configController)
- throws Exception {
+ public PolicyController updatePolicyController(ControllerConfiguration configController) {
if (configController == null)
throw new IllegalArgumentException("No controller configuration has been provided");
policyController = PolicyController.factory.get(controllerName);
} catch (IllegalArgumentException e) {
// not found
- logger.warn("Policy Controller " + controllerName + " not found");
+ logger.warn("Policy Controller " + controllerName + " not found", e);
}
if (policyController == null) {
}
}
- /**
- * {@inheritDoc}
- */
@Override
- public synchronized boolean start() throws IllegalStateException {
+ public synchronized boolean start() {
/* policy-engine dispatch pre start hook */
for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) {
return success;
}
- /**
- * {@inheritDoc}
- */
@Override
public synchronized boolean stop() {
return success;
}
- /**
- * {@inheritDoc}
- */
@Override
- public synchronized void shutdown() throws IllegalStateException {
+ public synchronized void shutdown() {
/* policy-engine dispatch pre shutdown hook */
for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) {
}).start();
}
- /**
- * {@inheritDoc}
- */
@Override
public synchronized boolean isAlive() {
return this.alive;
}
- /**
- * {@inheritDoc}
- */
@Override
public synchronized boolean lock() {
return success;
}
- /**
- * {@inheritDoc}
- */
@Override
public synchronized boolean unlock() {
return success;
}
- /**
- * {@inheritDoc}
- */
@Override
public synchronized boolean isLocked() {
return this.locked;
}
- /**
- * {@inheritDoc}
- */
@Override
public void removePolicyController(String name) {
PolicyController.factory.destroy(name);
}
- /**
- * {@inheritDoc}
- */
@Override
public void removePolicyController(PolicyController controller) {
PolicyController.factory.destroy(controller);
}
- /**
- * {@inheritDoc}
- */
@JsonIgnore
@Override
public List<PolicyController> getPolicyControllers() {
return PolicyController.factory.inventory();
}
- /**
- * {@inheritDoc}
- */
@JsonProperty("controllers")
@Override
public List<String> getPolicyControllerIds() {
return controllerNames;
}
- /**
- * {@inheritDoc}
- */
@Override
@JsonIgnore
public Properties getProperties() {
}
- /**
- * {@inheritDoc}
- */
@SuppressWarnings("unchecked")
@Override
public List<TopicSource> getSources() {
return (List<TopicSource>) this.sources;
}
- /**
- * {@inheritDoc}
- */
@SuppressWarnings("unchecked")
@Override
public List<TopicSink> getSinks() {
return (List<TopicSink>) this.sinks;
}
- /**
- * {@inheritDoc}
- */
@Override
public List<HttpServletServer> getHttpServers() {
return this.httpServers;
}
-
- /**
- * {@inheritDoc}
- */
@Override
public List<String> getFeatures() {
List<String> features = new ArrayList<String>();
}
return features;
}
-
- /**
- * {@inheritDoc}
- */
+
@JsonIgnore
@Override
public List<PolicyEngineFeatureAPI> getFeatureProviders() {
return PolicyEngineFeatureAPI.providers.getList();
}
- /**
- * {@inheritDoc}
- */
@Override
- public PolicyEngineFeatureAPI getFeatureProvider(String featureName) throws IllegalArgumentException {
+ public PolicyEngineFeatureAPI getFeatureProvider(String featureName) {
if (featureName == null || featureName.isEmpty())
throw new IllegalArgumentException("A feature name must be provided");
throw new IllegalArgumentException("Invalid Feature Name: " + featureName);
}
- /**
- * {@inheritDoc}
- */
@Override
public void onTopicEvent(CommInfrastructure commType, String topic, String event) {
/* configuration request */
}
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean deliver(String topic, Object event)
throws IllegalArgumentException, IllegalStateException {
topic, event);
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean deliver(String busType, String topic, Object event)
throws IllegalArgumentException, IllegalStateException,
topic, event);
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean deliver(Topic.CommInfrastructure busType,
String topic, Object event)
}
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean deliver(Topic.CommInfrastructure busType,
String topic, String event)
}
}
- /**
- * {@inheritDoc}
- */
@Override
public synchronized void activate() {
}
}
- /**
- * {@inheritDoc}
- */
@Override
public synchronized void deactivate() {
PolicyController testController = PolicyController.factory.get("unnamed");
assertFalse(testController.getDrools().isAlive());
assertFalse(testController.getDrools().isLocked());
+
+ PolicyEngine.manager.removePolicyController("unnamed");
+ assertTrue(PolicyController.factory.inventory().isEmpty());
}
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.utils;
+
+/**
+ * Network Utilities
+ */
+public class NetworkUtil {
+
+ /**
+ * IPv4 Wildcard IP address
+ */
+ public static final String IPv4_WILDCARD_ADDRESS = "0.0.0.0";
+
+ /* Other methods will be added as needed */
+
+}
classLoader);
return aClass;
} catch (Exception e) {
- logger.error("FETCHED-CLASS {} IN {} does NOT EXIST", className, classLoader);
+ logger.error("class {} fetched in {} does not exist", className, classLoader, e);
}
return null;