aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2017-09-14 01:55:30 -0500
committerJorge Hernandez <jh1730@att.com>2017-09-14 15:00:40 -0500
commit403fe412004ffded378c71df3f17b022a6518442 (patch)
tree44dffde62e6461d3d758a86b6d07748916f37e77 /controlloop/common/eventmanager/src
parent0f7e3fb817487b85a4200eb39a5755888c5ad04b (diff)
master lab template maintained under archetype
This is work in progress, the official pom.xml with dependencies, drl template, and support files for controller deployment are maintained here. In the near future the junit template should be consolidated with this one. Added controlloop.properties.environment, this environment file will be populated at installation time with the lab's aai url, etc .. and will be accessible by any drools application such as control loops through the PolicyEngine interface. Note that PDP-D server already supports these environment files, so it is just natural. Therefore, this is the default mechanism to provide to applications, the url, username, and passwords to use at runtime by the control loops for the time being. In the future MSB could set them globally here through existing APIs, or it can be queried by any drools application using MSB library, doesn't matter. There's been some trouble playing nicely with the dependencies used by a control loop application classsloader, and the pdp-d middleware one, causing issues between dependencies version of libraries. Specifically, the snakeyaml library does not play well across classloader when using constructor functionality, note that the snakeyaml libraries are pulled also from jackson parsers used in the pdp-d. I made a change in ControlLoopProcessor to specifically tell the "Yaml" object which classloader to use in order to find the class with the constructor that is intended to be built, otherwise, yaml libraries use a different classloader that does not have visibility into the ControlLoopPolicy that is trying to construct, and fails. This also should respect junits that use the same classloader I pressume and does not give issues. Change-Id: I36271d29cdbf8ff861f9c03ff91cf7116927906a Issue-ID: POLICY-162 Signed-off-by: Jorge Hernandez <jh1730@att.com>
Diffstat (limited to 'controlloop/common/eventmanager/src')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java162
1 files changed, 81 insertions, 81 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java
index b6fad23d9..f2c565d9a 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,91 +20,91 @@
package org.onap.policy.controlloop.processor;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.Constructor;
-
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.policy.ControlLoop;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.onap.policy.controlloop.policy.FinalResult;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.PolicyResult;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor;
public class ControlLoopProcessor {
-
- private final String yaml;
- private final ControlLoopPolicy policy;
- private String currentPolicy = null;
-
- public ControlLoopProcessor(String yaml) throws ControlLoopException {
- this.yaml = yaml;
- try {
- Yaml y = new Yaml(new Constructor(ControlLoopPolicy.class));
- Object obj = y.load(this.yaml);
- if (obj instanceof ControlLoopPolicy) {
- this.policy = (ControlLoopPolicy) obj;
- this.currentPolicy = this.policy.getControlLoop().getTrigger_policy();
- } else {
- this.policy = null;
- throw new ControlLoopException("Unable to parse yaml into ControlLoopPolicy object");
- }
- } catch (Exception e) {
- //
- // Most likely this is a YAML Exception
- //
- throw new ControlLoopException(e);
- }
- }
-
- public ControlLoop getControlLoop() {
- return this.policy.getControlLoop();
- }
-
- public FinalResult checkIsCurrentPolicyFinal() {
- return FinalResult.toResult(this.currentPolicy);
- }
-
- public Policy getCurrentPolicy() {
- for (Policy policy : this.policy.getPolicies()) {
- if (policy.getId().equals(this.currentPolicy)) {
- return policy;
- }
- }
- return null;
- }
-
- public void nextPolicyForResult(PolicyResult result) throws ControlLoopException {
- Policy policy = this.getCurrentPolicy();
- try {
- if (this.policy == null) {
- throw new ControlLoopException("There is no current policy to determine where to go to.");
- }
- switch (result) {
- case SUCCESS:
- this.currentPolicy = policy.getSuccess();
- break;
- case FAILURE:
- this.currentPolicy = policy.getFailure();
- break;
- case FAILURE_TIMEOUT:
- this.currentPolicy = policy.getFailure_timeout();
- break;
- case FAILURE_RETRIES:
- this.currentPolicy = policy.getFailure_retries();
- break;
- case FAILURE_EXCEPTION:
- this.currentPolicy = policy.getFailure_exception();
- break;
- case FAILURE_GUARD:
- this.currentPolicy = policy.getFailure_guard();
- break;
- default:
- throw new ControlLoopException("Bad policy result given: " + result);
- }
- } catch (ControlLoopException e) {
- this.currentPolicy = FinalResult.FINAL_FAILURE_EXCEPTION.toString();
- throw e;
- }
- }
-
+
+ private final String yaml;
+ private final ControlLoopPolicy policy;
+ private String currentPolicy = null;
+
+ public ControlLoopProcessor(String yaml) throws ControlLoopException {
+ this.yaml = yaml;
+ try {
+ final Yaml y = new Yaml(new CustomClassLoaderConstructor(ControlLoopPolicy.class,
+ ControlLoopPolicy.class.getClassLoader()));
+ final Object obj = y.load(this.yaml);
+ if (obj instanceof ControlLoopPolicy) {
+ this.policy = (ControlLoopPolicy) obj;
+ this.currentPolicy = this.policy.getControlLoop().getTrigger_policy();
+ } else {
+ this.policy = null;
+ throw new ControlLoopException("Unable to parse yaml into ControlLoopPolicy object");
+ }
+ } catch (final Exception e) {
+ //
+ // Most likely this is a YAML Exception
+ //
+ throw new ControlLoopException(e);
+ }
+ }
+
+ public ControlLoop getControlLoop() {
+ return this.policy.getControlLoop();
+ }
+
+ public FinalResult checkIsCurrentPolicyFinal() {
+ return FinalResult.toResult(this.currentPolicy);
+ }
+
+ public Policy getCurrentPolicy() {
+ for (final Policy policy : this.policy.getPolicies()) {
+ if (policy.getId().equals(this.currentPolicy)) {
+ return policy;
+ }
+ }
+ return null;
+ }
+
+ public void nextPolicyForResult(PolicyResult result) throws ControlLoopException {
+ final Policy policy = this.getCurrentPolicy();
+ try {
+ if (this.policy == null) {
+ throw new ControlLoopException("There is no current policy to determine where to go to.");
+ }
+ switch (result) {
+ case SUCCESS:
+ this.currentPolicy = policy.getSuccess();
+ break;
+ case FAILURE:
+ this.currentPolicy = policy.getFailure();
+ break;
+ case FAILURE_TIMEOUT:
+ this.currentPolicy = policy.getFailure_timeout();
+ break;
+ case FAILURE_RETRIES:
+ this.currentPolicy = policy.getFailure_retries();
+ break;
+ case FAILURE_EXCEPTION:
+ this.currentPolicy = policy.getFailure_exception();
+ break;
+ case FAILURE_GUARD:
+ this.currentPolicy = policy.getFailure_guard();
+ break;
+ default:
+ throw new ControlLoopException("Bad policy result given: " + result);
+ }
+ } catch (final ControlLoopException e) {
+ this.currentPolicy = FinalResult.FINAL_FAILURE_EXCEPTION.toString();
+ throw e;
+ }
+ }
+
}