summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/eventmanager/src')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java31
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java37
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java162
-rw-r--r--controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml6
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java30
5 files changed, 124 insertions, 142 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 c2846f86d..f891a2c6a 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
@@ -26,18 +26,17 @@ import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
-import java.util.List;
import java.util.UUID;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Iterator;
+import org.onap.policy.aai.AAIGETVnfResponse;
+import org.onap.policy.aai.AAIGETVserverResponse;
+import org.onap.policy.aai.AAIManager;
import org.onap.policy.controlloop.ControlLoopEventStatus;
+import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.ControlLoopNotificationType;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
-import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.policy.FinalResult;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.processor.ControlLoopProcessor;
@@ -49,13 +48,6 @@ import org.onap.policy.guard.TargetLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.onap.policy.aai.AAIManager;
-import org.onap.policy.aai.AAIGETVserverResponse;
-import org.onap.policy.aai.AAIGETVnfResponse;
-import org.onap.policy.aai.RelatedToPropertyItem;
-import org.onap.policy.aai.RelationshipList;
-import org.onap.policy.aai.Relationship;
-
public class ControlLoopEventManager implements LockCallback, Serializable {
/**
@@ -68,7 +60,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
public final UUID requestID;
private String controlLoopResult;
- private ControlLoopProcessor processor = null;
+ private transient ControlLoopProcessor processor = null;
private VirtualControlLoopEvent onset;
private Integer numOnsets = 0;
private Integer numAbatements = 0;
@@ -78,7 +70,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
private boolean isActivated = false;
private LinkedList<ControlLoopOperation> controlLoopHistory = new LinkedList<>();
private ControlLoopOperationManager currentOperation = null;
- private TargetLock targetLock = null;
+ private transient TargetLock targetLock = null;
private static AAIGETVnfResponse vnfResponse = null;
private static AAIGETVserverResponse vserverResponse = null;
@@ -589,7 +581,6 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
}
public static boolean isClosedLoopDisabled(AAIGETVnfResponse aaiResponse) {
- RelationshipList relationshipList = new RelationshipList();
if (aaiResponse != null && aaiResponse.isClosedLoopDisabled != null) {
String value = aaiResponse.isClosedLoopDisabled;
if ("true".equalsIgnoreCase(value) || "T".equalsIgnoreCase(value) ||
@@ -602,7 +593,6 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
}
public static boolean isClosedLoopDisabled(AAIGETVserverResponse aaiResponse) {
- RelationshipList relationshipList = new RelationshipList();
if (aaiResponse != null && aaiResponse.isClosedLoopDisabled != null) {
String value = aaiResponse.isClosedLoopDisabled;
if ("true".equalsIgnoreCase(value) || "T".equalsIgnoreCase(value) ||
@@ -633,9 +623,8 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
try {
if (vserverName != null) {
- AAIManager manager = new AAIManager();
String url = "https://aai-ext1.test.att.com:8443/aai/v11/nodes/vservers?vserver-name=";
- response = manager.getQueryByVserverName(url, user, password, requestID, vserverName);
+ response = AAIManager.getQueryByVserverName(url, user, password, requestID, vserverName);
}
} catch (Exception e) {
logger.error("getAAIVserverInfo exception: ", e);
@@ -655,13 +644,11 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
try {
if (vnfName != null) {
- AAIManager manager = new AAIManager();
String url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=";
- response = manager.getQueryByVnfName(url, user, password, requestID, vnfName);
+ response = AAIManager.getQueryByVnfName(url, user, password, requestID, vnfName);
} else if (vnfID != null) {
- AAIManager manager = new AAIManager();
String url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf/";
- response = manager.getQueryByVnfID(url, user, password, requestID, vnfID);
+ response = AAIManager.getQueryByVnfID(url, user, password, requestID, vnfID);
}
} catch (Exception e) {
logger.error("getAAIVnfInfo exception: ", e);
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
index a1ae9f0d5..8849a2351 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
@@ -20,11 +20,13 @@
package org.onap.policy.controlloop.eventmanager;
+import java.io.InputStream;
import java.io.Serializable;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.AbstractMap;
import java.util.LinkedList;
+import java.util.Properties;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
@@ -37,14 +39,14 @@ import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actor.appc.APPCActorServiceProvider;
+import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider;
import org.onap.policy.controlloop.actor.vfc.VFCActorServiceProvider;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.controlloop.actor.mso.MSOActorServiceProvider;
-import org.onap.policy.mso.SOResponse;
+import org.onap.policy.controlloop.actor.so.SOActorServiceProvider;
+import org.onap.policy.so.SOResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider;
public class ControlLoopOperationManager implements Serializable {
@@ -69,13 +71,13 @@ public class ControlLoopOperationManager implements Serializable {
//
//public final ATTControlLoopEvent onset;
public final ControlLoopEvent onset;
- public final Policy policy;
+ public final transient Policy policy;
//
// Properties used to track the Operation
//
private int attempts = 0;
- private Operation currentOperation = null;
+ private transient Operation currentOperation = null;
private LinkedList<Operation> operationHistory = new LinkedList<Operation>();
private PolicyResult policyResult = null;
private ControlLoopEventManager eventManager = null;
@@ -105,7 +107,7 @@ public class ControlLoopOperationManager implements Serializable {
}
private String guardApprovalStatus = "NONE";//"NONE", "PERMIT", "DENY"
- private Object operationRequest;
+ private transient Object operationRequest;
public Object getOperationRequest() {
return operationRequest;
@@ -214,12 +216,12 @@ public class ControlLoopOperationManager implements Serializable {
this.currentOperation = operation;
return operationRequest;
case "SO":
- MSOActorServiceProvider SOAsp = new MSOActorServiceProvider();
+ SOActorServiceProvider SOAsp = new SOActorServiceProvider();
this.operationRequest = SOAsp.constructRequest((VirtualControlLoopEvent)onset, operation.operation, this.policy);
-
+
// Save the operation
this.currentOperation = operation;
-
+
return operationRequest;
case "VFC":
this.operationRequest = VFCActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, operation.operation, this.policy);
@@ -364,9 +366,9 @@ public class ControlLoopOperationManager implements Serializable {
}
return PolicyResult.FAILURE;
}
-
+
}
-
+
return null;
}
@@ -512,13 +514,24 @@ public class ControlLoopOperationManager implements Serializable {
private void storeOperationInDataBase(){
+ // DB Properties
+ Properties props = new Properties();
+ try (InputStream is = org.onap.policy.guard.PIPEngineGetHistory.class.getResourceAsStream(org.onap.policy.guard.PIPEngineGetHistory.OPS_HIST_PROPS_LOC)){
+ props.load(is);
+ } catch (Exception ex) {
+ logger.error("getCountFromDB threw: ", ex);
+ return;
+ }
String OpsHistPU = System.getProperty("OperationsHistoryPU");
if(OpsHistPU == null || !OpsHistPU.equals("TestOperationsHistoryPU")){
OpsHistPU = "OperationsHistoryPU";
}
+ else{
+ props.clear();
+ }
EntityManager em;
try{
- em = Persistence.createEntityManagerFactory(OpsHistPU).createEntityManager();
+ em = Persistence.createEntityManagerFactory(OpsHistPU, props).createEntityManager();
}catch(Exception e){
logger.error("storeOperationInDataBase threw: ", e);
return;
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;
+ }
+ }
+
}
diff --git a/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml b/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
index 27c64b60a..827e2562b 100644
--- a/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
+++ b/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
@@ -11,12 +11,8 @@
<properties>
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
- <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://localhost:3306/policy" />
- <property name="javax.persistence.jdbc.user" value="root" />
- <property name="javax.persistence.jdbc.password" value="aaaa" />
<property name="eclipselink.logging.level" value="WARNING" />
+ <!-- Credential and URL properties located in /guard/src/main/resources/operation_history.properties -->
</properties>
</persistence-unit>
-
-
</persistence>
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
index ef7a1a94c..2e208748f 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
@@ -20,40 +20,26 @@
package org.onap.policy.controlloop.eventmanager;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.time.Instant;
import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
import java.util.UUID;
import org.junit.Test;
-import org.onap.policy.aai.AAIGETVserverResponse;
import org.onap.policy.aai.AAIGETVnfResponse;
+import org.onap.policy.aai.AAIGETVserverResponse;
+import org.onap.policy.aai.RelatedToProperty;
import org.onap.policy.aai.RelatedToPropertyItem;
import org.onap.policy.aai.Relationship;
import org.onap.policy.aai.RelationshipData;
import org.onap.policy.aai.RelationshipDataItem;
import org.onap.policy.aai.RelationshipList;
-import org.onap.policy.aai.AAIManager;
-import org.onap.policy.aai.RelatedToProperty;
-import org.onap.policy.appc.Request;
-import org.onap.policy.appc.Response;
-import org.onap.policy.appc.ResponseCode;
-import org.onap.policy.appc.ResponseValue;
import org.onap.policy.controlloop.ControlLoopEventStatus;
-
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.Util;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.controlloop.processor.ControlLoopProcessor;
-import org.onap.policy.controlloop.processor.ControlLoopProcessorTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -79,6 +65,7 @@ public class ControlLoopEventManagerTest {
final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml");
onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName();
try {
+ @SuppressWarnings("unused")
ControlLoopEventManager eventManager = new ControlLoopEventManager(onset.closedLoopControlName, onset.requestID);
onset.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
@@ -104,32 +91,31 @@ public class ControlLoopEventManagerTest {
onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName();
try {
- ControlLoopEventManager eventManager = new ControlLoopEventManager(onset.closedLoopControlName, onset.requestID);
onset.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
logger.info("testIsClosedLoopDisabled --");
- AAIManager manager = new AAIManager();
String user = "POLICY";
String password = "POLICY";
String vnfID = "83f674e8-7555-44d7-9a39-bdc3770b0491";
String url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf/";
AAIGETVnfResponse response = getQueryByVnfID2(url, user, password, onset.requestID, vnfID);
assertNotNull(response);
- boolean disabled = eventManager.isClosedLoopDisabled(response);
+ boolean disabled = ControlLoopEventManager.isClosedLoopDisabled(response);
logger.info("QueryByVnfID - isClosedLoopDisabled: " + disabled);
String vnfName = "lll_vnf_010317";
url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=";
response = getQueryByVnfName2(url, user, password, onset.requestID, vnfName);
assertNotNull(response);
- disabled = eventManager.isClosedLoopDisabled(response);
+ disabled = ControlLoopEventManager.isClosedLoopDisabled(response);
logger.info("QueryByVnfName2 - isClosedLoopDisabled: " + disabled);
String vserverName = "USMSO1SX7NJ0103UJZZ01-vjunos0";
url = "https://aai-ext1.test.att.com:8443//aai/v11/nodes/vservers?vserver-name=";
+ @SuppressWarnings("unused")
AAIGETVserverResponse response2 = getQueryByVserverName2(url, user, password, onset.requestID, vserverName);
assertNotNull(response);
- disabled = eventManager.isClosedLoopDisabled(response);
+ disabled = ControlLoopEventManager.isClosedLoopDisabled(response);
logger.info("QueryByVserverName - isClosedLoopDisabled: " + disabled);
} catch (Exception e) {
fail(e.getMessage());