summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2020-02-07 13:10:03 -0600
committerjhh <jorge.hernandez-herrero@att.com>2020-02-07 13:17:05 -0600
commita4a2486342a637a0d2f27ed2f2a07a98597dcd5e (patch)
tree7993b0ab410c7df47ca68729685447c7f26a2f6b /controlloop/common/eventmanager
parentfa4292c3b2a85d0cd8a5536462ea6081ae09c1e2 (diff)
activate refactoring in ControlLoopEventManager
This is to support backwards compatible implementation of Tosca Compliant Operational Policies. Issue-ID: POLICY-2360 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: I0e8b96b19375c58e4b62e0dcd1da5c508091ea2f Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'controlloop/common/eventmanager')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java131
1 files changed, 69 insertions, 62 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
index 868ab00a3..f297a8f6b 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* controlloop event manager
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 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.
@@ -186,42 +186,66 @@ public class ControlLoopEventManager implements Serializable {
return requestId;
}
+
+ private VirtualControlLoopNotification rejectNotification(VirtualControlLoopEvent event, String message) {
+ VirtualControlLoopNotification notification = new VirtualControlLoopNotification(event);
+ notification.setNotification(ControlLoopNotificationType.REJECTED);
+ notification.setMessage(message);
+ return notification;
+ }
+
/**
- * Activate a control loop event.
+ * Preactivations check for an event.
*
* @param event the event
* @return the VirtualControlLoopNotification
*/
- public VirtualControlLoopNotification activate(VirtualControlLoopEvent event) {
- VirtualControlLoopNotification notification = new VirtualControlLoopNotification(event);
+ private VirtualControlLoopNotification preActivationChecks(VirtualControlLoopEvent event) {
try {
//
// This method should ONLY be called ONCE
//
if (this.isActivated) {
- throw new ControlLoopException("ControlLoopEventManager has already been activated.");
+ return rejectNotification(event, "ControlLoopEventManager has already been activated.");
}
+
//
// Syntax check the event
//
checkEventSyntax(event);
-
- //
- // At this point we are good to go with this event
- //
- this.onset = event;
- this.numOnsets = 1;
- //
- notification.setNotification(ControlLoopNotificationType.ACTIVE);
- //
- // Set ourselves as active
- //
- this.isActivated = true;
} catch (ControlLoopException e) {
- logger.error("{}: activate by event threw: ", this, e);
- notification.setNotification(ControlLoopNotificationType.REJECTED);
- notification.setMessage(e.getMessage());
+ logger.warn("{}: invalid event syntax: ", this, e);
+ return rejectNotification(event, e.getMessage());
+
+ }
+
+ return new VirtualControlLoopNotification(event);
+ }
+
+ /**
+ * Activate a control loop event.
+ *
+ * @param event the event
+ * @return the VirtualControlLoopNotification
+ */
+ public VirtualControlLoopNotification activate(VirtualControlLoopEvent event) {
+ VirtualControlLoopNotification notification = preActivationChecks(event);
+ if (notification.getNotification() == ControlLoopNotificationType.REJECTED) {
+ return notification;
}
+
+ //
+ // At this point we are good to go with this event
+ //
+ this.onset = event;
+ this.numOnsets = 1;
+ //
+ //
+ // Set ourselves as active
+ //
+ this.isActivated = true;
+
+ notification.setNotification(ControlLoopNotificationType.ACTIVE);
return notification;
}
@@ -233,32 +257,15 @@ public class ControlLoopEventManager implements Serializable {
* @return the VirtualControlLoopNotification
*/
public VirtualControlLoopNotification activate(String yamlSpecification, VirtualControlLoopEvent event) {
- VirtualControlLoopNotification notification = new VirtualControlLoopNotification(event);
- try {
- //
- // This method should ONLY be called ONCE
- //
- if (this.isActivated) {
- throw new ControlLoopException("ControlLoopEventManager has already been activated.");
- }
- //
- // Syntax check the event
- //
- checkEventSyntax(event);
-
- //
- // Check the YAML
- //
- if (yamlSpecification == null || yamlSpecification.length() < 1) {
- throw new ControlLoopException("yaml specification is null or 0 length");
- }
- } catch (ControlLoopException e) {
- logger.error("{}: activate by YAML specification and event threw: ", this, e);
- notification.setNotification(ControlLoopNotificationType.REJECTED);
- notification.setMessage(e.getMessage());
+ VirtualControlLoopNotification notification = preActivationChecks(event);
+ if (notification.getNotification() == ControlLoopNotificationType.REJECTED) {
return notification;
}
+ if (yamlSpecification == null || yamlSpecification.length() < 1) {
+ return rejectNotification(event, "yaml specification is null or 0 length");
+ }
+
String decodedYaml = null;
try {
decodedYaml = URLDecoder.decode(yamlSpecification, "UTF-8");
@@ -266,10 +273,8 @@ public class ControlLoopEventManager implements Serializable {
yamlSpecification = decodedYaml;
}
} catch (UnsupportedEncodingException e) {
- logger.error("{}: YAML decode in activate by YAML specification and event threw: ", this, e);
- notification.setNotification(ControlLoopNotificationType.REJECTED);
- notification.setMessage(e.getMessage());
- return notification;
+ logger.warn("{}: YAML decode in activate by YAML specification and event threw: ", this, e);
+ return rejectNotification(event, e.getMessage());
}
try {
@@ -277,24 +282,26 @@ public class ControlLoopEventManager implements Serializable {
// Parse the YAML specification
//
this.processor = new ControlLoopProcessor(yamlSpecification);
- //
- // At this point we are good to go with this event
- //
- this.onset = event;
- this.numOnsets = 1;
- //
- //
- //
- notification.setNotification(ControlLoopNotificationType.ACTIVE);
- //
- // Set ourselves as active
- //
- this.isActivated = true;
} catch (ControlLoopException e) {
logger.error("{}: activate by YAML specification and event threw: ", this, e);
- notification.setNotification(ControlLoopNotificationType.REJECTED);
- notification.setMessage(e.getMessage());
+ return rejectNotification(event, e.getMessage());
}
+
+ //
+ // At this point we are good to go with this event
+ //
+ this.onset = event;
+ this.numOnsets = 1;
+
+ //
+ // Set ourselves as active
+ //
+ this.isActivated = true;
+
+ //
+ //
+ //
+ notification.setNotification(ControlLoopNotificationType.ACTIVE);
return notification;
}