diff options
Diffstat (limited to 'controlloop')
48 files changed, 2109 insertions, 967 deletions
diff --git a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java index 41a99496c..c0bbfe8f3 100644 --- a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java +++ b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java @@ -94,8 +94,8 @@ public class APPCActorServiceProvider implements Actor { */ Request request = new Request(); request.setCommonHeader(new CommonHeader()); - request.getCommonHeader().setRequestID(onset.requestID); - request.getCommonHeader().setSubRequestID(operation.subRequestId); + request.getCommonHeader().setRequestID(onset.getRequestID()); + request.getCommonHeader().setSubRequestID(operation.getSubRequestId()); request.setAction(policy.getRecipe().substring(0, 1).toUpperCase() + policy.getRecipe().substring(1)); diff --git a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java index e07589081..89de717fb 100644 --- a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java +++ b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java @@ -60,24 +60,24 @@ public class AppcServiceProviderTest { * generic-vnf.vnf-id and a target type of VM. */ onsetEvent = new VirtualControlLoopEvent(); - onsetEvent.closedLoopControlName = "closedLoopControlName-Test"; - onsetEvent.requestID = UUID.randomUUID(); - onsetEvent.closedLoopEventClient = "tca.instance00001"; - onsetEvent.target_type = ControlLoopTargetType.VNF; - onsetEvent.target = "generic-vnf.vnf-name"; - onsetEvent.from = "DCAE"; - onsetEvent.closedLoopAlarmStart = Instant.now(); - onsetEvent.AAI = new HashMap<>(); - onsetEvent.AAI.put("generic-vnf.vnf-name", "fw0001vm001fw001"); - onsetEvent.closedLoopEventStatus = ControlLoopEventStatus.ONSET; + onsetEvent.setClosedLoopControlName("closedLoopControlName-Test"); + onsetEvent.setRequestID(UUID.randomUUID()); + onsetEvent.setClosedLoopEventClient("tca.instance00001"); + onsetEvent.setTargetType(ControlLoopTargetType.VNF); + onsetEvent.setTarget("generic-vnf.vnf-name"); + onsetEvent.setFrom("DCAE"); + onsetEvent.setClosedLoopAlarmStart(Instant.now()); + onsetEvent.setAAI(new HashMap<>()); + onsetEvent.getAAI().put("generic-vnf.vnf-name", "fw0001vm001fw001"); + onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); /* Construct an operation with an APPC actor and ModifyConfig operation. */ operation = new ControlLoopOperation(); - operation.actor = "APPC"; - operation.operation = "ModifyConfig"; - operation.target = "VNF"; - operation.end = Instant.now(); - operation.subRequestId = "1"; + operation.setActor("APPC"); + operation.setOperation("ModifyConfig"); + operation.setTarget("VNF"); + operation.setEnd(Instant.now()); + operation.setSubRequestId("1"); /* Construct a policy specifying to modify configuration. */ policy = new Policy(); @@ -123,7 +123,7 @@ public class AppcServiceProviderTest { /* A common header is required and cannot be null */ assertNotNull(appcRequest.getCommonHeader()); - assertEquals(appcRequest.getCommonHeader().getRequestID(), onsetEvent.requestID); + assertEquals(appcRequest.getCommonHeader().getRequestID(), onsetEvent.getRequestID()); /* An action is required and cannot be null */ assertNotNull(appcRequest.getAction()); diff --git a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java index 0f4a00423..8e416cb63 100644 --- a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java +++ b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java @@ -211,7 +211,7 @@ public class AppcLcmActorServiceProvider implements Actor { */ LCMRequestWrapper dmaapRequest = new LCMRequestWrapper(); dmaapRequest.setVersion("2.0"); - dmaapRequest.setCorrelationId(onset.requestID + "-" + operation.subRequestId); + dmaapRequest.setCorrelationId(onset.getRequestID() + "-" + operation.getSubRequestId()); dmaapRequest.setRpcName(policy.getRecipe().toLowerCase()); dmaapRequest.setType("request"); @@ -220,9 +220,9 @@ public class AppcLcmActorServiceProvider implements Actor { /* The common header is a required field for all APPC requests. */ LCMCommonHeader requestCommonHeader = new LCMCommonHeader(); - requestCommonHeader.setOriginatorId(onset.requestID.toString()); - requestCommonHeader.setRequestId(onset.requestID); - requestCommonHeader.setSubRequestId(operation.subRequestId); + requestCommonHeader.setOriginatorId(onset.getRequestID().toString()); + requestCommonHeader.setRequestId(onset.getRequestID()); + requestCommonHeader.setSubRequestId(operation.getSubRequestId()); appcRequest.setCommonHeader(requestCommonHeader); diff --git a/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java b/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java index d446968ef..b498566da 100644 --- a/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java +++ b/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java @@ -66,24 +66,24 @@ public class AppcLcmServiceProviderTest { * generic-vnf.vnf-id and a target type of VM. */ onsetEvent = new VirtualControlLoopEvent(); - onsetEvent.closedLoopControlName = "closedLoopControlName-Test"; - onsetEvent.requestID = UUID.randomUUID(); - onsetEvent.closedLoopEventClient = "tca.instance00001"; - onsetEvent.target_type = ControlLoopTargetType.VM; - onsetEvent.target = "generic-vnf.vnf-name"; - onsetEvent.from = "DCAE"; - onsetEvent.closedLoopAlarmStart = Instant.now(); - onsetEvent.AAI = new HashMap<>(); - onsetEvent.AAI.put("generic-vnf.vnf-name", "fw0001vm001fw001"); - onsetEvent.closedLoopEventStatus = ControlLoopEventStatus.ONSET; + onsetEvent.setClosedLoopControlName("closedLoopControlName-Test"); + onsetEvent.setRequestID(UUID.randomUUID()); + onsetEvent.setClosedLoopEventClient("tca.instance00001"); + onsetEvent.setTargetType(ControlLoopTargetType.VM); + onsetEvent.setTarget("generic-vnf.vnf-name"); + onsetEvent.setFrom("DCAE"); + onsetEvent.setClosedLoopAlarmStart(Instant.now()); + onsetEvent.setAAI(new HashMap<>()); + onsetEvent.getAAI().put("generic-vnf.vnf-name", "fw0001vm001fw001"); + onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); /* Construct an operation with an APPC actor and restart operation. */ operation = new ControlLoopOperation(); - operation.actor = "APPC"; - operation.operation = "Restart"; - operation.target = "VM"; - operation.end = Instant.now(); - operation.subRequestId = "1"; + operation.setActor("APPC"); + operation.setOperation("Restart"); + operation.setTarget("VM"); + operation.setEnd(Instant.now()); + operation.setSubRequestId("1"); /* Construct a policy specifying to restart vm. */ policy = new Policy(); @@ -98,13 +98,13 @@ public class AppcLcmServiceProviderTest { /* A sample DMAAP request wrapper. */ dmaapRequest = new LCMRequestWrapper(); - dmaapRequest.setCorrelationId(onsetEvent.requestID.toString() + "-" + "1"); + dmaapRequest.setCorrelationId(onsetEvent.getRequestID().toString() + "-" + "1"); dmaapRequest.setRpcName(policy.getRecipe().toLowerCase()); dmaapRequest.setType("request"); /* A sample DMAAP response wrapper */ dmaapResponse = new LCMResponseWrapper(); - dmaapResponse.setCorrelationId(onsetEvent.requestID.toString() + "-" + "1"); + dmaapResponse.setCorrelationId(onsetEvent.getRequestID().toString() + "-" + "1"); dmaapResponse.setRpcName(policy.getRecipe().toLowerCase()); dmaapResponse.setType("response"); @@ -125,9 +125,9 @@ public class AppcLcmServiceProviderTest { appcRequest.setActionIdentifiers(actionIdentifiers); LCMCommonHeader commonHeader = new LCMCommonHeader(); - commonHeader.setRequestId(onsetEvent.requestID); + commonHeader.setRequestId(onsetEvent.getRequestID()); commonHeader.setSubRequestId("1"); - commonHeader.setOriginatorId(onsetEvent.requestID.toString()); + commonHeader.setOriginatorId(onsetEvent.getRequestID().toString()); appcRequest.setCommonHeader(commonHeader); @@ -184,7 +184,7 @@ public class AppcLcmServiceProviderTest { /* A common header is required and cannot be null */ assertNotNull(appcRequest.getCommonHeader()); - assertEquals(appcRequest.getCommonHeader().getRequestId(), onsetEvent.requestID); + assertEquals(appcRequest.getCommonHeader().getRequestId(), onsetEvent.getRequestID()); /* An action is required and cannot be null */ assertNotNull(appcRequest.getAction()); diff --git a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java index 64008e7ff..eb2bc1731 100644 --- a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java +++ b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java @@ -158,7 +158,7 @@ public class SOActorServiceProvider implements Actor { // Map<String, Map<String, String>> aainqinstancefiltermap = new HashMap<>(); Map<String, String> aainqinstancefiltermapitem = new HashMap<>(); - aainqinstancefiltermapitem.put("vserver-name", onset.AAI.get("vserver.vserver-name")); // TO DO: get vserver.vname from dcae onset.AAI.get("vserver.vserver-name") + aainqinstancefiltermapitem.put("vserver-name", onset.getAAI().get("vserver.vserver-name")); // TO DO: get vserver.vname from dcae onset.AAI.get("vserver.vserver-name") aainqinstancefiltermap.put("vserver", aainqinstancefiltermapitem); aainqinstancefilter.getInstanceFilter().add(aainqinstancefiltermap); aainqrequest.setInstanceFilters(aainqinstancefilter); @@ -186,7 +186,7 @@ public class SOActorServiceProvider implements Actor { //***** send the request *****\\ AAINQResponse aainqresponse = new AAIManager(new RESTManager()).postQuery(aaiUrl, aaiUsername, aaiPassword, - aainqrequest, onset.requestID); + aainqrequest, onset.getRequestID()); // Check AAI response if (aainqresponse == null) { @@ -196,7 +196,7 @@ public class SOActorServiceProvider implements Actor { return null; } else { // Create AAINQResponseWrapper - AAINQResponseWrapper aainqResponseWrapper = new AAINQResponseWrapper(onset.requestID, aainqresponse); + AAINQResponseWrapper aainqResponseWrapper = new AAINQResponseWrapper(onset.getRequestID(), aainqresponse); // insert aainqResponseWrapper to memory -- Is this needed? // insert(aainqResponseWrapper); diff --git a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java index efa3dba1f..dae60cb82 100644 --- a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java +++ b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java @@ -70,7 +70,7 @@ public class VFCActorServiceProvider implements Actor { Policy policy, AAIGETVnfResponse vnfResponse) { // Construct an VFC request VFCRequest request = new VFCRequest(); - String serviceInstance = onset.AAI.get("service-instance.service-instance-id"); + String serviceInstance = onset.getAAI().get("service-instance.service-instance-id"); if (serviceInstance == null || "".equals(serviceInstance)) { AAIGETVnfResponse tempVnfResp = vnfResponse; @@ -83,18 +83,18 @@ public class VFCActorServiceProvider implements Actor { serviceInstance = tempVnfResp.getServiceId(); } request.nsInstanceId = serviceInstance; - request.requestId = onset.requestID; + request.requestId = onset.getRequestID(); request.healRequest = new VFCHealRequest(); - request.healRequest.vnfInstanceId = onset.AAI.get("generic-vnf.vnf-id"); - request.healRequest.cause = operation.message; + request.healRequest.vnfInstanceId = onset.getAAI().get("generic-vnf.vnf-id"); + request.healRequest.cause = operation.getMessage(); request.healRequest.additionalParams = new VFCHealAdditionalParams(); switch (policy.getRecipe().toLowerCase()) { case "restart": request.healRequest.additionalParams.action = "restartvm"; request.healRequest.additionalParams.actionInfo = new VFCHealActionVmInfo(); - request.healRequest.additionalParams.actionInfo.vmid = onset.AAI.get("vserver.vserver-id"); - request.healRequest.additionalParams.actionInfo.vmname = onset.AAI.get("vserver.vserver-name"); + request.healRequest.additionalParams.actionInfo.vmid = onset.getAAI().get("vserver.vserver-id"); + request.healRequest.additionalParams.actionInfo.vmname = onset.getAAI().get("vserver.vserver-name"); break; default: return null; @@ -105,9 +105,9 @@ public class VFCActorServiceProvider implements Actor { private static AAIGETVnfResponse getAAIServiceInstance(VirtualControlLoopEvent event) { AAIGETVnfResponse response = null; - UUID requestID = event.requestID; - String vnfName = event.AAI.get("generic-vnf.vnf-name"); - String vnfID = event.AAI.get("generic-vnf.vnf-id"); + UUID requestID = event.getRequestID(); + String vnfName = event.getAAI().get("generic-vnf.vnf-name"); + String vnfID = event.getAAI().get("generic-vnf.vnf-id"); String aaiUrl = PolicyEngine.manager.getEnvironmentProperty("aai.url"); String aaiUsername = PolicyEngine.manager.getEnvironmentProperty("aai.username"); String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password"); 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 559eab9d9..2b296616d 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 @@ -157,15 +157,15 @@ public class ControlLoopEventManager implements LockCallback, Serializable { this.onset = event; this.numOnsets = 1; // - notification.notification = ControlLoopNotificationType.ACTIVE; + notification.setNotification(ControlLoopNotificationType.ACTIVE); // // Set ourselves as active // this.isActivated = true; } catch (ControlLoopException e) { logger.error("{}: activate threw: ",this, e); - notification.notification = ControlLoopNotificationType.REJECTED; - notification.message = e.getMessage(); + notification.setNotification(ControlLoopNotificationType.REJECTED); + notification.setMessage(e.getMessage()); } return notification; } @@ -214,15 +214,15 @@ public class ControlLoopEventManager implements LockCallback, Serializable { // // // - notification.notification = ControlLoopNotificationType.ACTIVE; + notification.setNotification(ControlLoopNotificationType.ACTIVE); // // Set ourselves as active // this.isActivated = true; } catch (ControlLoopException e) { logger.error("{}: activate threw: ",this, e); - notification.notification = ControlLoopNotificationType.REJECTED; - notification.message = e.getMessage(); + notification.setNotification(ControlLoopNotificationType.REJECTED); + notification.setMessage(e.getMessage()); } return notification; } @@ -251,9 +251,9 @@ public class ControlLoopEventManager implements LockCallback, Serializable { // // Yes we have timed out // - notification.notification = ControlLoopNotificationType.FINAL_FAILURE; - notification.message = "Control Loop timed out"; - notification.history.addAll(this.controlLoopHistory); + notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE); + notification.setMessage("Control Loop timed out"); + notification.getHistory().addAll(this.controlLoopHistory); return notification; } // @@ -269,18 +269,18 @@ public class ControlLoopEventManager implements LockCallback, Serializable { switch (result) { case FINAL_FAILURE_EXCEPTION: - notification.message = "Exception in processing closed loop"; + notification.setMessage("Exception in processing closed loop"); case FINAL_FAILURE: case FINAL_FAILURE_RETRIES: case FINAL_FAILURE_TIMEOUT: case FINAL_FAILURE_GUARD: - notification.notification = ControlLoopNotificationType.FINAL_FAILURE; + notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE); break; case FINAL_OPENLOOP: - notification.notification = ControlLoopNotificationType.FINAL_OPENLOOP; + notification.setNotification(ControlLoopNotificationType.FINAL_OPENLOOP); break; case FINAL_SUCCESS: - notification.notification = ControlLoopNotificationType.FINAL_SUCCESS; + notification.setNotification(ControlLoopNotificationType.FINAL_SUCCESS); break; default: return null; @@ -288,7 +288,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { // // Be sure to add all the history // - notification.history.addAll(this.controlLoopHistory); + notification.getHistory().addAll(this.controlLoopHistory); return notification; } @@ -401,7 +401,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { LockResult<GuardResult, TargetLock> lockResult = PolicyGuard.lockTarget( this.currentOperation.policy.getTarget().getType(), this.currentOperation.getTargetEntity(), - this.onset.requestID, + this.onset.getRequestID(), this); // // Was it acquired? @@ -440,7 +440,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { public NEW_EVENT_STATUS onNewEvent(VirtualControlLoopEvent event) throws AAIException { try { this.checkEventSyntax(event); - if (event.closedLoopEventStatus == ControlLoopEventStatus.ONSET) { + if (event.getClosedLoopEventStatus() == ControlLoopEventStatus.ONSET) { // // Check if this is our original ONSET // @@ -460,7 +460,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { // this.numOnsets++; return NEW_EVENT_STATUS.SUBSEQUENT_ONSET; - } else if (event.closedLoopEventStatus == ControlLoopEventStatus.ABATED) { + } else if (event.getClosedLoopEventStatus() == ControlLoopEventStatus.ABATED) { // // Have we already got an abatement? // @@ -499,9 +499,9 @@ public class ControlLoopEventManager implements LockCallback, Serializable { public VirtualControlLoopNotification setControlLoopTimedOut() { this.controlLoopTimedOut = FinalResult.FINAL_FAILURE_TIMEOUT; VirtualControlLoopNotification notification = new VirtualControlLoopNotification(this.onset); - notification.notification = ControlLoopNotificationType.FINAL_FAILURE; - notification.message = "Control Loop timed out"; - notification.history.addAll(this.controlLoopHistory); + notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE); + notification.setMessage("Control Loop timed out"); + notification.getHistory().addAll(this.controlLoopHistory); return notification; } @@ -528,43 +528,43 @@ public class ControlLoopEventManager implements LockCallback, Serializable { } public void checkEventSyntax(VirtualControlLoopEvent event) throws ControlLoopException { - if (event.closedLoopEventStatus == null || - (event.closedLoopEventStatus != ControlLoopEventStatus.ONSET && - event.closedLoopEventStatus != ControlLoopEventStatus.ABATED)) { + if (event.getClosedLoopEventStatus() == null || + (event.getClosedLoopEventStatus() != ControlLoopEventStatus.ONSET && + event.getClosedLoopEventStatus() != ControlLoopEventStatus.ABATED)) { throw new ControlLoopException("Invalid value in closedLoopEventStatus"); } - if (event.closedLoopControlName == null || event.closedLoopControlName.length() < 1) { + if (event.getClosedLoopControlName() == null || event.getClosedLoopControlName().length() < 1) { throw new ControlLoopException("No control loop name"); } - if (event.requestID == null) { + if (event.getRequestID() == null) { throw new ControlLoopException("No request ID"); } - if (event.closedLoopEventStatus == ControlLoopEventStatus.ABATED) { + if (event.getClosedLoopEventStatus() == ControlLoopEventStatus.ABATED) { return; } - if (event.target == null || event.target.length() < 1) { + if (event.getTarget() == null || event.getTarget().length() < 1) { throw new ControlLoopException("No target field"); - } else if (! "VM_NAME".equalsIgnoreCase(event.target) && - ! "VNF_NAME".equalsIgnoreCase(event.target) && - ! "vserver.vserver-name".equalsIgnoreCase(event.target) && - ! "generic-vnf.vnf-id".equalsIgnoreCase(event.target) && - ! "generic-vnf.vnf-name".equalsIgnoreCase(event.target) ) { + } else if (! "VM_NAME".equalsIgnoreCase(event.getTarget()) && + ! "VNF_NAME".equalsIgnoreCase(event.getTarget()) && + ! "vserver.vserver-name".equalsIgnoreCase(event.getTarget()) && + ! "generic-vnf.vnf-id".equalsIgnoreCase(event.getTarget()) && + ! "generic-vnf.vnf-name".equalsIgnoreCase(event.getTarget()) ) { throw new ControlLoopException("target field invalid - expecting VM_NAME or VNF_NAME"); } - if (event.AAI == null) { + if (event.getAAI() == null) { throw new ControlLoopException("AAI is null"); } - if (event.AAI.get("generic-vnf.vnf-id") == null && event.AAI.get("vserver.vserver-name") == null && - event.AAI.get("generic-vnf.vnf-name") == null) { + if (event.getAAI().get("generic-vnf.vnf-id") == null && event.getAAI().get("vserver.vserver-name") == null && + event.getAAI().get("generic-vnf.vnf-name") == null) { throw new ControlLoopException("generic-vnf.vnf-id or generic-vnf.vnf-name or vserver.vserver-name information missing"); } } public void queryAai(VirtualControlLoopEvent event) throws AAIException { - if (event.AAI.get("vserver.is-closed-loop-disabled") == null && - event.AAI.get("generic-vnf.is-closed-loop-disabled") == null) { + if (event.getAAI().get("vserver.is-closed-loop-disabled") == null && + event.getAAI().get("generic-vnf.is-closed-loop-disabled") == null) { try { - if (event.AAI.get("generic-vnf.vnf-id") != null) { + if (event.getAAI().get("generic-vnf.vnf-id") != null) { vnfResponse = getAAIVnfInfo(event); if (vnfResponse == null) { throw new AAIException("AAI Response is null (query by vnf-id)"); @@ -575,7 +575,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { if (isClosedLoopDisabled(vnfResponse) == true) { throw new AAIException("is-closed-loop-disabled is set to true"); } - } else if (event.AAI.get("generic-vnf.vnf-name") != null) { + } else if (event.getAAI().get("generic-vnf.vnf-name") != null) { vnfResponse = getAAIVnfInfo(event); if (vnfResponse == null) { throw new AAIException("AAI Response is null (query by vnf-name)"); @@ -586,7 +586,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { if (isClosedLoopDisabled(vnfResponse) == true) { throw new AAIException("is-closed-loop-disabled is set to true"); } - } else if (event.AAI.get("vserver.vserver-name") != null) { + } else if (event.getAAI().get("vserver.vserver-name") != null) { vserverResponse = getAAIVserverInfo(event); if (vserverResponse == null) { throw new AAIException("AAI Response is null (query by vserver-name)"); @@ -632,25 +632,25 @@ public class ControlLoopEventManager implements LockCallback, Serializable { } public static boolean isClosedLoopDisabled(VirtualControlLoopEvent event) { - if ("true".equalsIgnoreCase(event.AAI.get("vserver.is-closed-loop-disabled")) || - "T".equalsIgnoreCase(event.AAI.get("vserver.is-closed-loop-disabled")) || - "yes".equalsIgnoreCase(event.AAI.get("vserver.is-closed-loop-disabled")) || - "Y".equalsIgnoreCase(event.AAI.get("vserver.is-closed-loop-disabled"))) { + if ("true".equalsIgnoreCase(event.getAAI().get("vserver.is-closed-loop-disabled")) || + "T".equalsIgnoreCase(event.getAAI().get("vserver.is-closed-loop-disabled")) || + "yes".equalsIgnoreCase(event.getAAI().get("vserver.is-closed-loop-disabled")) || + "Y".equalsIgnoreCase(event.getAAI().get("vserver.is-closed-loop-disabled"))) { return true; } - else if ("true".equalsIgnoreCase(event.AAI.get("generic-vnf.is-closed-loop-disabled")) || - "T".equalsIgnoreCase(event.AAI.get("generic-vnf.is-closed-loop-disabled")) || - "yes".equalsIgnoreCase(event.AAI.get("generic-vnf.is-closed-loop-disabled")) || - "Y".equalsIgnoreCase(event.AAI.get("generic-vnf.is-closed-loop-disabled"))) { + else if ("true".equalsIgnoreCase(event.getAAI().get("generic-vnf.is-closed-loop-disabled")) || + "T".equalsIgnoreCase(event.getAAI().get("generic-vnf.is-closed-loop-disabled")) || + "yes".equalsIgnoreCase(event.getAAI().get("generic-vnf.is-closed-loop-disabled")) || + "Y".equalsIgnoreCase(event.getAAI().get("generic-vnf.is-closed-loop-disabled"))) { return true; } return false; } public static AAIGETVserverResponse getAAIVserverInfo(VirtualControlLoopEvent event) throws ControlLoopException { - UUID requestID = event.requestID; + UUID requestID = event.getRequestID(); AAIGETVserverResponse response = null; - String vserverName = event.AAI.get("vserver.vserver-name"); + String vserverName = event.getAAI().get("vserver.vserver-name"); try { if (vserverName != null) { @@ -671,10 +671,10 @@ public class ControlLoopEventManager implements LockCallback, Serializable { } public static AAIGETVnfResponse getAAIVnfInfo(VirtualControlLoopEvent event) throws ControlLoopException { - UUID requestID = event.requestID; + UUID requestID = event.getRequestID(); AAIGETVnfResponse response = null; - String vnfName = event.AAI.get("generic-vnf.vnf-name"); - String vnfID = event.AAI.get("generic-vnf.vnf-id"); + String vnfName = event.getAAI().get("generic-vnf.vnf-name"); + String vnfID = event.getAAI().get("generic-vnf.vnf-id"); aaiHostURL = PolicyEngine.manager.getEnvironmentProperty("aai.url"); aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.username"); @@ -715,7 +715,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { @Override public String toString() { return "ControlLoopEventManager [closedLoopControlName=" + closedLoopControlName + ", requestID=" + requestID - + ", processor=" + processor + ", onset=" + (onset != null ? onset.requestID : "null") + ", numOnsets=" + numOnsets + ", numAbatements=" + + ", processor=" + processor + ", onset=" + (onset != null ? onset.getRequestID() : "null") + ", numOnsets=" + numOnsets + ", numAbatements=" + numAbatements + ", isActivated=" + isActivated + ", currentOperation=" + currentOperation + ", targetLock=" + targetLock + "]"; } 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 8edb7ef14..8160f76fa 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 @@ -62,7 +62,7 @@ public class ControlLoopOperationManager implements Serializable { @Override public String toString() { - return "ControlLoopOperationManager [onset=" + (onset != null ? onset.requestID : "null") + ", policy=" + return "ControlLoopOperationManager [onset=" + (onset != null ? onset.getRequestID() : "null") + ", policy=" + (policy != null ? policy.getId() : "null") + ", attempts=" + attempts + ", policyResult=" + policyResult + ", currentOperation=" + currentOperation + ", operationHistory=" + operationHistory @@ -137,19 +137,19 @@ public class ControlLoopOperationManager implements Serializable { case VM: case VNF: VirtualControlLoopEvent virtualOnset = (VirtualControlLoopEvent) this.onset; - if (this.onset.target.equalsIgnoreCase("vserver.vserver-name")) { - return virtualOnset.AAI.get("vserver.vserver-name"); + if (this.onset.getTarget().equalsIgnoreCase("vserver.vserver-name")) { + return virtualOnset.getAAI().get("vserver.vserver-name"); } - else if (this.onset.target.equalsIgnoreCase("generic-vnf.vnf-id")) { - return virtualOnset.AAI.get("generic-vnf.vnf-id"); + else if (this.onset.getTarget().equalsIgnoreCase("generic-vnf.vnf-id")) { + return virtualOnset.getAAI().get("generic-vnf.vnf-id"); } - else if (this.onset.target.equalsIgnoreCase("generic-vnf.vnf-name")) { + else if (this.onset.getTarget().equalsIgnoreCase("generic-vnf.vnf-name")) { /* * If the onset is enriched with the vnf-id, * we don't need an A&AI response */ - if (virtualOnset.AAI.containsKey("generic-vnf.vnf-id")) { - return virtualOnset.AAI.get("generic-vnf.vnf-id"); + if (virtualOnset.getAAI().containsKey("generic-vnf.vnf-id")) { + return virtualOnset.getAAI().get("generic-vnf.vnf-id"); } /* @@ -256,10 +256,10 @@ public class ControlLoopOperationManager implements Serializable { this.policyResult = null; Operation operation = new Operation(); operation.attempt = ++this.attempts; - operation.operation.actor = this.policy.getActor(); - operation.operation.operation = this.policy.getRecipe(); - operation.operation.target = this.policy.getTarget().toString(); - operation.operation.subRequestId = Integer.toString(operation.attempt); + operation.operation.setActor(this.policy.getActor()); + operation.operation.setOperation(this.policy.getRecipe()); + operation.operation.setTarget(this.policy.getTarget().toString()); + operation.operation.setSubRequestId(Integer.toString(operation.attempt)); // // Now determine which actor we need to construct a request for // @@ -657,16 +657,16 @@ public class ControlLoopOperationManager implements Serializable { OperationsHistoryDbEntry newEntry = new OperationsHistoryDbEntry(); - newEntry.closedLoopName = this.onset.closedLoopControlName; - newEntry.requestId = this.onset.requestID.toString(); - newEntry.actor = this.currentOperation.operation.actor; - newEntry.operation = this.currentOperation.operation.operation; + newEntry.closedLoopName = this.onset.getClosedLoopControlName(); + newEntry.requestId = this.onset.getRequestID().toString(); + newEntry.actor = this.currentOperation.operation.getActor(); + newEntry.operation = this.currentOperation.operation.getOperation(); newEntry.target = this.targetEntity; - newEntry.starttime = Timestamp.from(this.currentOperation.operation.start); - newEntry.subrequestId = this.currentOperation.operation.subRequestId; - newEntry.endtime = new Timestamp(this.currentOperation.operation.end.toEpochMilli()); - newEntry.message = this.currentOperation.operation.message; - newEntry.outcome = this.currentOperation.operation.outcome; + newEntry.starttime = Timestamp.from(this.currentOperation.operation.getStart()); + newEntry.subrequestId = this.currentOperation.operation.getSubRequestId(); + newEntry.endtime = new Timestamp(this.currentOperation.operation.getEnd().toEpochMilli()); + newEntry.message = this.currentOperation.operation.getMessage(); + newEntry.outcome = this.currentOperation.operation.getOutcome(); em.getTransaction().begin(); em.persist(newEntry); @@ -685,9 +685,9 @@ public class ControlLoopOperationManager implements Serializable { } if (this.currentOperation != null) { if (this.currentOperation.attempt == attempt.intValue()) { - this.currentOperation.operation.end = Instant.now(); - this.currentOperation.operation.message = message; - this.currentOperation.operation.outcome = result.toString(); + this.currentOperation.operation.setEnd(Instant.now()); + this.currentOperation.operation.setMessage(message); + this.currentOperation.operation.setOutcome(result.toString()); this.currentOperation.policyResult = result; // // Save it in history @@ -708,9 +708,9 @@ public class ControlLoopOperationManager implements Serializable { } for (Operation op : this.operationHistory) { if (op.attempt == attempt.intValue()) { - op.operation.end = Instant.now(); - op.operation.message = message; - op.operation.outcome = result.toString(); + op.operation.setEnd(Instant.now()); + op.operation.setMessage(message); + op.operation.setOutcome(result.toString()); op.policyResult = result; return; } 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 bc832a907..d4083150d 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 @@ -59,15 +59,15 @@ public class ControlLoopEventManagerTest { private static VirtualControlLoopEvent onset; static { onset = new VirtualControlLoopEvent(); - onset.closedLoopControlName = "ControlLoop-vUSP"; - onset.requestID = UUID.randomUUID(); - onset.target = "VM_NAME"; - onset.closedLoopAlarmStart = Instant.now(); - onset.AAI = new HashMap<String, String>(); - onset.AAI.put("cloud-region.identity-url", "foo"); - onset.AAI.put("vserver.selflink", "bar"); - onset.AAI.put("generic-vnf.vnf-id", "83f674e8-7555-44d7-9a39-bdc3770b0491"); - onset.closedLoopEventStatus = ControlLoopEventStatus.ONSET; + onset.setClosedLoopControlName("ControlLoop-vUSP"); + onset.setRequestID(UUID.randomUUID()); + onset.setTarget("VM_NAME"); + onset.setClosedLoopAlarmStart(Instant.now()); + onset.setAAI(new HashMap<String, String>()); + onset.getAAI().put("cloud-region.identity-url", "foo"); + onset.getAAI().put("vserver.selflink", "bar"); + onset.getAAI().put("generic-vnf.vnf-id", "83f674e8-7555-44d7-9a39-bdc3770b0491"); + onset.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); } @BeforeClass @@ -90,7 +90,7 @@ public class ControlLoopEventManagerTest { @Test public void testAAIVnfInfo() { final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml"); - onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName(); + onset.setClosedLoopControlName(pair.a.getControlLoop().getControlLoopName()); try { AAIGETVnfResponse response = getQueryByVnfID2(PolicyEngine.manager.getEnvironmentProperty("aai.url") + "/aai/v11/network/generic-vnfs/generic-vnf/", PolicyEngine.manager.getEnvironmentProperty("aai.username"), @@ -107,7 +107,7 @@ public class ControlLoopEventManagerTest { @Test public void testAAIVnfInfo2() { final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml"); - onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName(); + onset.setClosedLoopControlName(pair.a.getControlLoop().getControlLoopName()); try { AAIGETVnfResponse response = getQueryByVnfName2(PolicyEngine.manager.getEnvironmentProperty("aai.url") + "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=", PolicyEngine.manager.getEnvironmentProperty("aai.username"), @@ -124,7 +124,7 @@ public class ControlLoopEventManagerTest { @Test public void testAAIVserver() { final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml"); - onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName(); + onset.setClosedLoopControlName(pair.a.getControlLoop().getControlLoopName()); try { AAIGETVserverResponse response = getQueryByVserverName2(PolicyEngine.manager.getEnvironmentProperty("aai.url") + "/aai/v11/nodes/vservers?vserver-name=", PolicyEngine.manager.getEnvironmentProperty("aai.username"), @@ -144,7 +144,7 @@ public class ControlLoopEventManagerTest { // Load up the policy // final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml"); - onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName(); + onset.setClosedLoopControlName(pair.a.getControlLoop().getControlLoopName()); try { logger.info("testIsClosedLoopDisabled --"); @@ -179,12 +179,12 @@ public class ControlLoopEventManagerTest { @Test public void abatemetCheckEventSyntaxTest() { VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.closedLoopControlName = "abatementAAI"; - event.requestID = UUID.randomUUID(); - event.target = "generic-vnf.vnf-id"; - event.closedLoopAlarmStart = Instant.now(); - event.closedLoopEventStatus = ControlLoopEventStatus.ABATED; - ControlLoopEventManager manager = new ControlLoopEventManager(event.closedLoopControlName, event.requestID); + event.setClosedLoopControlName("abatementAAI"); + event.setRequestID(UUID.randomUUID()); + event.setTarget("generic-vnf.vnf-id"); + event.setClosedLoopAlarmStart(Instant.now()); + event.setClosedLoopEventStatus(ControlLoopEventStatus.ABATED); + ControlLoopEventManager manager = new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestID()); assertNull(manager.getVnfResponse()); assertNull(manager.getVserverResponse()); try { @@ -198,8 +198,8 @@ public class ControlLoopEventManagerTest { assertNull(manager.getVserverResponse()); - event.AAI = new HashMap<>(); - event.AAI.put("generic-vnf.vnf-name", "abatementTest"); + event.setAAI(new HashMap<>()); + event.getAAI().put("generic-vnf.vnf-name", "abatementTest"); try { manager.checkEventSyntax(event); } catch (ControlLoopException e) { @@ -215,19 +215,19 @@ public class ControlLoopEventManagerTest { public void subsequentOnsetTest() { UUID requestId = UUID.randomUUID(); VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.closedLoopControlName = "TwoOnsetTest"; - event.requestID = requestId; - event.target = "generic-vnf.vnf-id"; - event.closedLoopAlarmStart = Instant.now(); - event.closedLoopEventStatus = ControlLoopEventStatus.ONSET; - event.AAI = new HashMap<>(); - event.AAI.put("generic-vnf.vnf-name", "onsetOne"); + event.setClosedLoopControlName("TwoOnsetTest"); + event.setRequestID(requestId); + event.setTarget("generic-vnf.vnf-id"); + event.setClosedLoopAlarmStart(Instant.now()); + event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); + event.setAAI(new HashMap<>()); + event.getAAI().put("generic-vnf.vnf-name", "onsetOne"); - ControlLoopEventManager manager = new ControlLoopEventManager(event.closedLoopControlName, event.requestID); + ControlLoopEventManager manager = new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestID()); VirtualControlLoopNotification notification = manager.activate(event); assertNotNull(notification); - assertEquals(ControlLoopNotificationType.ACTIVE, notification.notification); + assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); ControlLoopEventManager.NEW_EVENT_STATUS status = null; try { @@ -244,13 +244,13 @@ public class ControlLoopEventManagerTest { assertNull(manager.getVserverResponse()); VirtualControlLoopEvent event2 = new VirtualControlLoopEvent(); - event2.closedLoopControlName = "TwoOnsetTest"; - event2.requestID = requestId; - event2.target = "generic-vnf.vnf-id"; - event2.closedLoopAlarmStart = Instant.now(); - event2.closedLoopEventStatus = ControlLoopEventStatus.ONSET; - event2.AAI = new HashMap<>(); - event2.AAI.put("generic-vnf.vnf-name", "onsetTwo"); + event2.setClosedLoopControlName("TwoOnsetTest"); + event2.setRequestID(requestId); + event2.setTarget("generic-vnf.vnf-id"); + event2.setClosedLoopAlarmStart(Instant.now()); + event2.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); + event2.setAAI(new HashMap<>()); + event2.getAAI().put("generic-vnf.vnf-name", "onsetTwo"); try { diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java index 1714d3e26..76020b0c9 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java @@ -58,13 +58,13 @@ public class ControlLoopOperationManagerTest { private static VirtualControlLoopEvent onset; static { onset = new VirtualControlLoopEvent(); - onset.requestID = UUID.randomUUID(); - onset.target = "generic-vnf.vnf-name"; - onset.target_type = ControlLoopTargetType.VNF; - onset.closedLoopAlarmStart = Instant.now(); - onset.AAI = new HashMap<>(); - onset.AAI.put("generic-vnf.vnf-name", "testTriggerSource"); - onset.closedLoopEventStatus = ControlLoopEventStatus.ONSET; + onset.setRequestID(UUID.randomUUID()); + onset.setTarget("generic-vnf.vnf-name"); + onset.setTargetType(ControlLoopTargetType.VNF); + onset.setClosedLoopAlarmStart(Instant.now()); + onset.setAAI(new HashMap<>()); + onset.getAAI().put("generic-vnf.vnf-name", "testTriggerSource"); + onset.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); /* Set environment properties */ PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666"); @@ -92,7 +92,7 @@ public class ControlLoopOperationManagerTest { // Load up the policy // final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml"); - onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName(); + onset.setClosedLoopControlName(pair.a.getControlLoop().getControlLoopName()); try { // // Create a processor @@ -101,11 +101,11 @@ public class ControlLoopOperationManagerTest { // // create the manager // - ControlLoopEventManager eventManager = new ControlLoopEventManager(onset.closedLoopControlName, onset.requestID); + ControlLoopEventManager eventManager = new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestID()); VirtualControlLoopNotification notification = eventManager.activate(onset); assertNotNull(notification); - assertEquals(ControlLoopNotificationType.ACTIVE, notification.notification); + assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); ControlLoopEventManager.NEW_EVENT_STATUS status = null; try { @@ -221,7 +221,7 @@ public class ControlLoopOperationManagerTest { // Load up the policy // final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml"); - onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName(); + onset.setClosedLoopControlName(pair.a.getControlLoop().getControlLoopName()); try { // // Create a processor @@ -230,11 +230,11 @@ public class ControlLoopOperationManagerTest { // // create the manager // - ControlLoopEventManager eventManager = new ControlLoopEventManager(onset.closedLoopControlName, onset.requestID); + ControlLoopEventManager eventManager = new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestID()); VirtualControlLoopNotification notification = eventManager.activate(onset); assertNotNull(notification); - assertEquals(ControlLoopNotificationType.ACTIVE, notification.notification); + assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); ControlLoopEventManager.NEW_EVENT_STATUS status = null; try { diff --git a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMRequest.java b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMRequest.java index 51db7fef0..83442d9bf 100644 --- a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMRequest.java +++ b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMRequest.java @@ -42,7 +42,7 @@ public class LCMRequest implements Serializable { private String payload; public LCMRequest() { - + // Create a default LCM request } public LCMCommonHeader getCommonHeader() { diff --git a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMResponseCode.java b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMResponseCode.java index 85427c468..8a7c36d2b 100644 --- a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMResponseCode.java +++ b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMResponseCode.java @@ -33,10 +33,10 @@ public class LCMResponseCode { private Integer code; - private LCMResponseCode(int code) { - this.code = code; + protected LCMResponseCode(final int code) { + this.code = code; } - + public int getCode() { return this.code; } diff --git a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMResponseStatus.java b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMResponseStatus.java index 131e331bf..1db4e8ef7 100644 --- a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMResponseStatus.java +++ b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMResponseStatus.java @@ -25,83 +25,83 @@ import java.io.Serializable; public class LCMResponseStatus implements Serializable { - private static final long serialVersionUID = 974891505135467199L; - - @SerializedName(value="code") - private int code; - - @SerializedName(value="message") - private String message; - - public LCMResponseStatus() { - - } + private static final long serialVersionUID = 974891505135467199L; - /** - * @return the code - */ - public int getCode() { - return code; - } - - /** - * @param code the code to set - */ - public void setCode(int code) { - this.code = code; - } + @SerializedName(value="code") + private int code; - /** - * @return the message - */ - public String getMessage() { - return message; - } + @SerializedName(value="message") + private String message; - /** - * @param message the message to set - */ - public void setMessage(String message) { - this.message = message; - } + public LCMResponseStatus() { + // Create a default LCMResponseStatus instance + } - @Override - public String toString() { - return "ResponseStatus [code=" + code + ", message=" + message + "]"; - } + /** + * @return the code + */ + public int getCode() { + return code; + } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + code; - result = prime * result + ((message == null) ? 0 : message.hashCode()); - return result; - } + /** + * @param code the code to set + */ + public void setCode(int code) { + this.code = code; + } - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - LCMResponseStatus other = (LCMResponseStatus) obj; - if (code != other.code) { - return false; - } - if (message == null) { - if (other.message != null) { - return false; - } - } else if (!message.equals(other.message)) { - return false; - } - return true; - } + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return "ResponseStatus [code=" + code + ", message=" + message + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + code; + result = prime * result + ((message == null) ? 0 : message.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LCMResponseStatus other = (LCMResponseStatus) obj; + if (code != other.code) { + return false; + } + if (message == null) { + if (other.message != null) { + return false; + } + } else if (!message.equals(other.message)) { + return false; + } + return true; + } } diff --git a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMWrapper.java b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMWrapper.java index c9f72c2e2..c70e7423a 100644 --- a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMWrapper.java +++ b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LCMWrapper.java @@ -43,7 +43,7 @@ public class LCMWrapper implements Serializable { private String type; public LCMWrapper() { - + // Create a default LCMWrapper instance } /** diff --git a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/Serialization.java b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/Serialization.java index e41fa3653..5a5e2e2e6 100644 --- a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/Serialization.java +++ b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/Serialization.java @@ -32,88 +32,83 @@ import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; public final class Serialization { + private Serialization() { + } - public static class RequestAdapter implements JsonSerializer<LCMRequest>, JsonDeserializer<LCMRequest> { - - @Override - public JsonElement serialize(LCMRequest src, Type typeOfSrc, JsonSerializationContext context) { - JsonElement requestJson = gsonPretty.toJsonTree(src, LCMRequest.class); - JsonObject input = new JsonObject(); - input.add("input", requestJson); - - return input; - } - - @Override - public LCMRequest deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { - LCMRequest request = gsonPretty.fromJson(json.getAsJsonObject().get("input"), LCMRequest.class); - return request; - } - } - - public static class ResponseAdapter implements JsonSerializer<LCMResponse>, JsonDeserializer<LCMResponse> { - - @Override - public JsonElement serialize(LCMResponse src, Type typeOfSrc, JsonSerializationContext context) { - JsonElement responseJson = gsonPretty.toJsonTree(src, LCMResponse.class); - JsonObject output = new JsonObject(); - output.add("output", responseJson); - return output; - } - - @Override - public LCMResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { - LCMResponse response = gsonPretty.fromJson(json.getAsJsonObject().get("output"), LCMResponse.class); - return response; - } - } - - public static class InstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { - - @Override - public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { - return Instant.parse(json.getAsString()); - } - - @Override - public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { - return new JsonPrimitive(src.toString()); - } - - } - - public static class InstantJunitAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { - - @Override - public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { - return Instant.ofEpochMilli(json.getAsLong()); - } - - @Override - public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { - return new JsonPrimitive(src.toEpochMilli()); - } - - } - - public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .registerTypeAdapter(Instant.class, new InstantAdapter()).create(); - - public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .registerTypeAdapter(LCMRequest.class, new RequestAdapter()) - .registerTypeAdapter(LCMResponse.class, new ResponseAdapter()).create(); - - public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create(); + public static class RequestAdapter implements JsonSerializer<LCMRequest>, JsonDeserializer<LCMRequest> { + + @Override + public JsonElement serialize(LCMRequest src, Type typeOfSrc, JsonSerializationContext context) { + JsonElement requestJson = gsonPretty.toJsonTree(src, LCMRequest.class); + JsonObject input = new JsonObject(); + input.add("input", requestJson); + + return input; + } + + @Override + public LCMRequest deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return gsonPretty.fromJson(json.getAsJsonObject().get("input"), LCMRequest.class); + } + } + + public static class ResponseAdapter implements JsonSerializer<LCMResponse>, JsonDeserializer<LCMResponse> { + + @Override + public JsonElement serialize(LCMResponse src, Type typeOfSrc, JsonSerializationContext context) { + JsonElement responseJson = gsonPretty.toJsonTree(src, LCMResponse.class); + JsonObject output = new JsonObject(); + output.add("output", responseJson); + return output; + } + + @Override + public LCMResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return gsonPretty.fromJson(json.getAsJsonObject().get("output"), LCMResponse.class); + } + } + + public static class InstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return Instant.parse(json.getAsString()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toString()); + } + + } + + public static class InstantJunitAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return Instant.ofEpochMilli(json.getAsLong()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toEpochMilli()); + } + + } + + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(Instant.class, new InstantAdapter()).create(); + + public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(LCMRequest.class, new RequestAdapter()) + .registerTypeAdapter(LCMResponse.class, new ResponseAdapter()).create(); + + public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create(); } diff --git a/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/AppcLcmTest.java b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/AppcLcmTest.java index 41bafe498..2d58bfd99 100644 --- a/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/AppcLcmTest.java +++ b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/AppcLcmTest.java @@ -140,7 +140,7 @@ public class AppcLcmTest { /* * The type of the DMAAP wrapper should be request */ - assertEquals(dmaapRequest.getType(), "request"); + assertEquals("request", dmaapRequest.getType()); /* * The DMAAP wrapper must have a body as that is @@ -160,7 +160,7 @@ public class AppcLcmTest { * set to restart */ assertNotNull(appcRequest.getAction()); - assertEquals(appcRequest.getAction(), "restart"); + assertEquals("restart", appcRequest.getAction()); /* * The action-identifiers should not be null @@ -217,7 +217,7 @@ public class AppcLcmTest { /* * The type of the DMAAP wrapper should be response */ - assertEquals(dmaapResponse.getType(), "response"); + assertEquals("response", dmaapResponse.getType()); /* * The DMAAP wrapper must have a body as that is @@ -237,7 +237,7 @@ public class AppcLcmTest { * status code should be 400 */ assertNotNull(appcResponse.getStatus()); - assertEquals(appcResponse.getStatus().getCode(), 400); + assertEquals(400, appcResponse.getStatus().getCode()); logger.debug("Response as a Java Object: \n" + appcResponse.toString() + "\n\n"); } diff --git a/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMCommonHeader.java b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMCommonHeader.java new file mode 100644 index 000000000..6921068e5 --- /dev/null +++ b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMCommonHeader.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * 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========================================================= + */ + +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * 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.appclcm; + +import static org.junit.Assert.*; + +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.junit.Test; + +public class TestLCMCommonHeader { + + @Test + public void testLCMLCMCommonHeader() { + LCMCommonHeader commonHeader = new LCMCommonHeader(); + assertNotNull(commonHeader); + assertNotNull(new LCMCommonHeader(commonHeader)); + assertNotEquals(0, commonHeader.hashCode()); + + commonHeader.setApiVer("Kansas"); + assertEquals("Kansas", commonHeader.getApiVer()); + + Map<String, String> flagMap = new HashMap<>(); + commonHeader.setFlags(flagMap); + assertEquals(flagMap, commonHeader.getFlags()); + + commonHeader.setOriginatorId("Dorothy"); + assertEquals("Dorothy", commonHeader.getOriginatorId()); + + UUID requestId = UUID.randomUUID(); + commonHeader.setRequestId(requestId); + assertEquals(requestId, commonHeader.getRequestId()); + + commonHeader.setSubRequestId("Can I go home?"); + assertEquals("Can I go home?", commonHeader.getSubRequestId()); + + Instant timestamp = Instant.now(); + commonHeader.setTimeStamp(timestamp); + assertEquals(timestamp, commonHeader.getTimeStamp()); + + assertNotEquals(0, commonHeader.hashCode()); + + assertEquals("CommonHeader [timeStamp=", commonHeader.toString().substring(0, 24)); + + LCMCommonHeader copiedLCMCommonHeader = new LCMCommonHeader(); + copiedLCMCommonHeader.setApiVer(commonHeader.getApiVer()); + copiedLCMCommonHeader.setFlags(commonHeader.getFlags()); + copiedLCMCommonHeader.setOriginatorId(commonHeader.getOriginatorId()); + copiedLCMCommonHeader.setRequestId(commonHeader.getRequestId()); + copiedLCMCommonHeader.setSubRequestId(commonHeader.getSubRequestId()); + copiedLCMCommonHeader.setTimeStamp(commonHeader.getTimeStamp()); + + assertTrue(commonHeader.equals(commonHeader)); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + assertFalse(commonHeader.equals(null)); + assertFalse(commonHeader.equals("Hello")); + + LCMCommonHeader clonedLCMCommonHeader = new LCMCommonHeader(commonHeader); + clonedLCMCommonHeader.setApiVer(commonHeader.getApiVer()); + clonedLCMCommonHeader.setTimeStamp(commonHeader.getTimeStamp()); + + assertTrue(commonHeader.equals(clonedLCMCommonHeader)); + + commonHeader.setApiVer(null); + assertFalse(commonHeader.equals(copiedLCMCommonHeader)); + copiedLCMCommonHeader.setApiVer(null); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + commonHeader.setApiVer("Kansas"); + assertFalse(commonHeader.equals(copiedLCMCommonHeader)); + copiedLCMCommonHeader.setApiVer("Kansas"); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + + commonHeader.setFlags(null); + assertFalse(commonHeader.equals(copiedLCMCommonHeader)); + copiedLCMCommonHeader.setFlags(null); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + commonHeader.setFlags(flagMap); + assertFalse(commonHeader.equals(copiedLCMCommonHeader)); + copiedLCMCommonHeader.setFlags(flagMap); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + + commonHeader.setOriginatorId(null); + assertFalse(commonHeader.equals(copiedLCMCommonHeader)); + copiedLCMCommonHeader.setOriginatorId(null); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + commonHeader.setOriginatorId("Dorothy"); + assertFalse(commonHeader.equals(copiedLCMCommonHeader)); + copiedLCMCommonHeader.setOriginatorId("Dorothy"); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + + commonHeader.setRequestId(null); + assertFalse(commonHeader.equals(copiedLCMCommonHeader)); + copiedLCMCommonHeader.setRequestId(null); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + commonHeader.setRequestId(requestId); + assertFalse(commonHeader.equals(copiedLCMCommonHeader)); + copiedLCMCommonHeader.setRequestId(requestId); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + + commonHeader.setSubRequestId(null); + assertFalse(commonHeader.equals(copiedLCMCommonHeader)); + copiedLCMCommonHeader.setSubRequestId(null); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + commonHeader.setSubRequestId("Can I go home?"); + assertFalse(commonHeader.equals(copiedLCMCommonHeader)); + copiedLCMCommonHeader.setSubRequestId("Can I go home?"); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + + commonHeader.setTimeStamp(null); + assertFalse(commonHeader.equals(copiedLCMCommonHeader)); + copiedLCMCommonHeader.setTimeStamp(null); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + commonHeader.setTimeStamp(timestamp); + assertFalse(commonHeader.equals(copiedLCMCommonHeader)); + copiedLCMCommonHeader.setTimeStamp(timestamp); + assertTrue(commonHeader.equals(copiedLCMCommonHeader)); + } +} diff --git a/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMRequest.java b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMRequest.java new file mode 100644 index 000000000..223e50147 --- /dev/null +++ b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMRequest.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * 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.appclcm; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +public class TestLCMRequest { + + @Test + public void testLCMRequest() { + LCMRequest request = new LCMRequest(); + assertNotNull(request); + assertNotEquals(0, request.hashCode()); + + LCMCommonHeader commonHeader = new LCMCommonHeader(); + + request.setCommonHeader(commonHeader); + assertEquals(commonHeader, request.getCommonHeader()); + + request.setAction("Go to Oz"); + assertEquals("Go to Oz", request.getAction()); + + Map<String, String> actionIdentifiers = new HashMap<>(); + actionIdentifiers.put("North", "Good Witch"); + actionIdentifiers.put("West", "Bad Witch"); + + request.setActionIdentifiers(actionIdentifiers); + assertEquals(actionIdentifiers, request.getActionIdentifiers()); + + request.setPayload("The Emerald City"); + assertEquals("The Emerald City", request.getPayload()); + + assertNotEquals(0, request.hashCode()); + + assertEquals("Request [commonHeader=CommonHeader [timeStamp=", request.toString().substring(0, 46)); + + LCMRequest copiedLCMRequest = new LCMRequest(); + copiedLCMRequest.setCommonHeader(request.getCommonHeader()); + copiedLCMRequest.setAction(request.getAction()); + copiedLCMRequest.setActionIdentifiers(request.getActionIdentifiers()); + copiedLCMRequest.setPayload(request.getPayload()); + + assertTrue(request.equals(request)); + assertTrue(request.equals(copiedLCMRequest)); + assertFalse(request.equals(null)); + assertFalse(request.equals("Hello")); + + request.setCommonHeader(null); + assertFalse(request.equals(copiedLCMRequest)); + copiedLCMRequest.setCommonHeader(null); + assertTrue(request.equals(copiedLCMRequest)); + request.setCommonHeader(commonHeader); + assertFalse(request.equals(copiedLCMRequest)); + copiedLCMRequest.setCommonHeader(commonHeader); + assertTrue(request.equals(copiedLCMRequest)); + + request.setAction(null); + assertFalse(request.equals(copiedLCMRequest)); + copiedLCMRequest.setAction(null); + assertTrue(request.equals(copiedLCMRequest)); + request.setAction("Go to Oz"); + assertFalse(request.equals(copiedLCMRequest)); + copiedLCMRequest.setAction("Go to Oz"); + assertTrue(request.equals(copiedLCMRequest)); + + request.setActionIdentifiers(null); + assertFalse(request.equals(copiedLCMRequest)); + copiedLCMRequest.setActionIdentifiers(null); + assertTrue(request.equals(copiedLCMRequest)); + request.setActionIdentifiers(actionIdentifiers); + assertFalse(request.equals(copiedLCMRequest)); + copiedLCMRequest.setActionIdentifiers(actionIdentifiers); + assertTrue(request.equals(copiedLCMRequest)); + + request.setPayload(null); + assertFalse(request.equals(copiedLCMRequest)); + copiedLCMRequest.setPayload(null); + assertTrue(request.equals(copiedLCMRequest)); + request.setPayload("The Emerald City"); + assertFalse(request.equals(copiedLCMRequest)); + copiedLCMRequest.setPayload("The Emerald City"); + assertTrue(request.equals(copiedLCMRequest)); + } +} diff --git a/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMRequestWrapper.java b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMRequestWrapper.java new file mode 100644 index 000000000..0a5205509 --- /dev/null +++ b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMRequestWrapper.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * 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.appclcm; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestLCMRequestWrapper { + + @Test + public void testLCMRequestWrapperWrapper() { + assertNotNull(new LCMRequestWrapper(new LCMRequest())); + LCMRequestWrapper requestWrapper = new LCMRequestWrapper(); + assertNotNull(requestWrapper); + assertNotEquals(0, requestWrapper.hashCode()); + + LCMRequest request = new LCMRequest(); + + requestWrapper.setBody(request); + assertEquals(request, requestWrapper.getBody()); + + assertNotEquals(0, requestWrapper.hashCode()); + + assertEquals("RequestWrapper [body=Request [commonHeader=nul", requestWrapper.toString().substring(0, 46)); + + LCMRequestWrapper copiedLCMRequestWrapper = new LCMRequestWrapper(); + copiedLCMRequestWrapper.setBody(requestWrapper.getBody()); + + assertTrue(requestWrapper.equals(requestWrapper)); + assertTrue(requestWrapper.equals(copiedLCMRequestWrapper)); + assertFalse(requestWrapper.equals(null)); + assertFalse(requestWrapper.equals("Hello")); + + requestWrapper.setBody(null); + assertFalse(requestWrapper.equals(copiedLCMRequestWrapper)); + copiedLCMRequestWrapper.setBody(null); + assertTrue(requestWrapper.equals(copiedLCMRequestWrapper)); + requestWrapper.setBody(request); + assertFalse(requestWrapper.equals(copiedLCMRequestWrapper)); + copiedLCMRequestWrapper.setBody(request); + assertTrue(requestWrapper.equals(copiedLCMRequestWrapper)); + } +} diff --git a/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMResonseCode.java b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMResonseCode.java new file mode 100644 index 000000000..59606f8b4 --- /dev/null +++ b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMResonseCode.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * 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.appclcm; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestLCMResonseCode { + + @Test + public void testLCMResponseCode() { + assertNull(LCMResponseCode.toResponseValue(0)); + + assertEquals(LCMResponseCode.ACCEPTED, LCMResponseCode.toResponseValue(100)); + assertEquals(LCMResponseCode.ERROR, LCMResponseCode.toResponseValue(200)); + assertEquals(LCMResponseCode.REJECT, LCMResponseCode.toResponseValue(300)); + assertEquals(LCMResponseCode.SUCCESS, LCMResponseCode.toResponseValue(400)); + assertEquals(LCMResponseCode.FAILURE, LCMResponseCode.toResponseValue(450)); + assertEquals(LCMResponseCode.FAILURE, LCMResponseCode.toResponseValue(401)); + assertEquals(LCMResponseCode.FAILURE, LCMResponseCode.toResponseValue(406)); + assertEquals(LCMResponseCode.PARTIAL_SUCCESS, LCMResponseCode.toResponseValue(500)); + assertEquals(LCMResponseCode.PARTIAL_FAILURE, LCMResponseCode.toResponseValue(501)); + assertEquals(LCMResponseCode.PARTIAL_FAILURE, LCMResponseCode.toResponseValue(599)); + + assertEquals("100", new LCMResponseCode(100).toString()); + assertEquals("200", new LCMResponseCode(200).toString()); + assertEquals("300", new LCMResponseCode(300).toString()); + assertEquals("400", new LCMResponseCode(400).toString()); + assertEquals("450", new LCMResponseCode(450).toString()); + assertEquals("500", new LCMResponseCode(500).toString()); + assertEquals("510", new LCMResponseCode(510).toString()); + + assertEquals(300, new LCMResponseCode(300).getCode()); + } +} diff --git a/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMResponseStatus.java b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMResponseStatus.java new file mode 100644 index 000000000..0b6cbcf22 --- /dev/null +++ b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMResponseStatus.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * 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.appclcm; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestLCMResponseStatus { + + @Test + public void testResonseStatus() { + LCMResponseStatus status = new LCMResponseStatus(); + assertNotNull(status); + assertNotEquals(0, status.hashCode()); + + status.setCode(1234); + assertEquals(1234, status.getCode()); + + status.setMessage("The wonderful land of Oz"); + assertEquals("The wonderful land of Oz", status.getMessage()); + + assertEquals("ResponseStatus [code=1234, message=The wonderfu", status.toString().substring(0, 47)); + + LCMResponseStatus copiedStatus = new LCMResponseStatus(); + copiedStatus.setCode(status.getCode()); + copiedStatus.setMessage(status.getMessage()); + + assertTrue(status.equals(status)); + assertTrue(status.equals(copiedStatus)); + assertFalse(status.equals(null)); + assertFalse(status.equals("Hello")); + + status.setCode(-1); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setCode(-1); + assertTrue(status.equals(copiedStatus)); + status.setCode(1234); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setCode(1234); + assertTrue(status.equals(copiedStatus)); + + status.setMessage(null); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setMessage(null); + assertTrue(status.equals(copiedStatus)); + status.setMessage("The wonderful land of Oz"); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setMessage("The wonderful land of Oz"); + assertTrue(status.equals(copiedStatus)); + } +} diff --git a/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMResponseWrapper.java b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMResponseWrapper.java new file mode 100644 index 000000000..d27fbaff3 --- /dev/null +++ b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMResponseWrapper.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * 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.appclcm; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestLCMResponseWrapper { + + @Test + public void testLCMResponseWrapperWrapper() { + LCMResponseWrapper responseWrapper = new LCMResponseWrapper(); + assertNotNull(responseWrapper); + assertNotEquals(0, responseWrapper.hashCode()); + + LCMResponse response = new LCMResponse(); + + responseWrapper.setBody(response); + assertEquals(response, responseWrapper.getBody()); + + assertNotEquals(0, responseWrapper.hashCode()); + + assertEquals("ResponseWrapper [body=Response [commonHeader=n", responseWrapper.toString().substring(0, 46)); + + LCMResponseWrapper copiedLCMResponseWrapper = new LCMResponseWrapper(); + copiedLCMResponseWrapper.setBody(responseWrapper.getBody()); + + assertTrue(responseWrapper.equals(responseWrapper)); + assertTrue(responseWrapper.equals(copiedLCMResponseWrapper)); + assertFalse(responseWrapper.equals(null)); + assertFalse(responseWrapper.equals("Hello")); + + responseWrapper.setBody(null); + assertFalse(responseWrapper.equals(copiedLCMResponseWrapper)); + copiedLCMResponseWrapper.setBody(null); + assertTrue(responseWrapper.equals(copiedLCMResponseWrapper)); + responseWrapper.setBody(response); + assertFalse(responseWrapper.equals(copiedLCMResponseWrapper)); + copiedLCMResponseWrapper.setBody(response); + assertTrue(responseWrapper.equals(copiedLCMResponseWrapper)); + } +} diff --git a/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMWrapper.java b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMWrapper.java new file mode 100644 index 000000000..20baf154d --- /dev/null +++ b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/TestLCMWrapper.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * 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.appclcm; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestLCMWrapper { + + @Test + public void testLCMWrapper() { + LCMWrapper wrapper = new LCMWrapper(); + assertNotNull(wrapper); + assertNotEquals(0, wrapper.hashCode()); + + wrapper.setVersion("19.3.9"); + assertEquals("19.3.9", wrapper.getVersion()); + + wrapper.setCambriaPartition("The Emerald City"); + assertEquals("The Emerald City", wrapper.getCambriaPartition()); + + wrapper.setRpcName("Tornado"); + assertEquals("Tornado", wrapper.getRpcName()); + + wrapper.setCorrelationId("YellowBrickRoad"); + assertEquals("YellowBrickRoad", wrapper.getCorrelationId()); + + wrapper.setType("Munchkin"); + assertEquals("Munchkin", wrapper.getType()); + + assertNotEquals(0, wrapper.hashCode()); + + assertEquals("Wrapper [version=19.3.9, cambriaPartition=The ", wrapper.toString().substring(0, 46)); + + LCMWrapper copiedLCMWrapper = new LCMWrapper(); + copiedLCMWrapper.setVersion(wrapper.getVersion()); + copiedLCMWrapper.setCambriaPartition(wrapper.getCambriaPartition()); + copiedLCMWrapper.setRpcName(wrapper.getRpcName()); + copiedLCMWrapper.setCorrelationId(wrapper.getCorrelationId()); + copiedLCMWrapper.setType(wrapper.getType()); + + assertTrue(wrapper.equals(wrapper)); + assertTrue(wrapper.equals(copiedLCMWrapper)); + assertFalse(wrapper.equals(null)); + assertFalse(wrapper.equals("Hello")); + + wrapper.setVersion(null); + assertFalse(wrapper.equals(copiedLCMWrapper)); + copiedLCMWrapper.setVersion(null); + assertTrue(wrapper.equals(copiedLCMWrapper)); + wrapper.setVersion("19.3.9"); + assertFalse(wrapper.equals(copiedLCMWrapper)); + copiedLCMWrapper.setVersion("19.3.9"); + assertTrue(wrapper.equals(copiedLCMWrapper)); + + wrapper.setCambriaPartition(null); + assertFalse(wrapper.equals(copiedLCMWrapper)); + copiedLCMWrapper.setCambriaPartition(null); + assertTrue(wrapper.equals(copiedLCMWrapper)); + wrapper.setCambriaPartition("The Emerald City"); + assertFalse(wrapper.equals(copiedLCMWrapper)); + copiedLCMWrapper.setCambriaPartition("The Emerald City"); + assertTrue(wrapper.equals(copiedLCMWrapper)); + + wrapper.setRpcName(null); + assertFalse(wrapper.equals(copiedLCMWrapper)); + copiedLCMWrapper.setRpcName(null); + assertTrue(wrapper.equals(copiedLCMWrapper)); + wrapper.setRpcName("Tornado"); + assertFalse(wrapper.equals(copiedLCMWrapper)); + copiedLCMWrapper.setRpcName("Tornado"); + assertTrue(wrapper.equals(copiedLCMWrapper)); + + wrapper.setCorrelationId(null); + assertFalse(wrapper.equals(copiedLCMWrapper)); + copiedLCMWrapper.setCorrelationId(null); + assertTrue(wrapper.equals(copiedLCMWrapper)); + wrapper.setCorrelationId("YellowBrickRoad"); + assertFalse(wrapper.equals(copiedLCMWrapper)); + copiedLCMWrapper.setCorrelationId("YellowBrickRoad"); + assertTrue(wrapper.equals(copiedLCMWrapper)); + + wrapper.setType(null); + assertFalse(wrapper.equals(copiedLCMWrapper)); + copiedLCMWrapper.setType(null); + assertTrue(wrapper.equals(copiedLCMWrapper)); + wrapper.setType("Munchkin"); + assertFalse(wrapper.equals(copiedLCMWrapper)); + copiedLCMWrapper.setType("Munchkin"); + assertTrue(wrapper.equals(copiedLCMWrapper)); + } +} diff --git a/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/applcm/util/TestSerialization.java b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/applcm/util/TestSerialization.java new file mode 100644 index 000000000..c7167f509 --- /dev/null +++ b/controlloop/common/model-impl/appclcm/src/test/java/org/onap/policy/applcm/util/TestSerialization.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * 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.applcm.util; + +import static org.junit.Assert.*; + +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; + +import org.junit.Test; +import org.onap.policy.appclcm.util.Serialization; + +public class TestSerialization { + + @Test + public void test() { + String nameString = "Dorothy"; + String jsonName = Serialization.gsonPretty.toJson(nameString, String.class); + assertEquals("\"Dorothy\"", jsonName); + String jsonInOutName = Serialization.gsonPretty.fromJson(jsonName, String.class); + assertEquals("Dorothy", jsonInOutName); + + Instant instant0 = Instant.ofEpochMilli(1516127215000L); + String instantString0 = Serialization.gsonPretty.toJson(instant0, Instant.class); + assertEquals("\"2018-01-16T18:26:55Z\"", instantString0); + Instant outInstant0 = Serialization.gsonPretty.fromJson(instantString0, Instant.class); + assertEquals(instant0, outInstant0); + + Instant instant1 = Instant.ofEpochMilli(1516127215000L); + String instantString1 = Serialization.gsonJunit.toJson(instant1, Instant.class); + assertEquals("1516127215000", instantString1); + Instant outInstant1 = Serialization.gsonJunit.fromJson(instantString1, Instant.class); + assertEquals(instant1, outInstant1); + + ZonedDateTime zdt = ZonedDateTime.ofInstant(instant0, ZoneId.of("UTC")); + String zdtString = Serialization.gsonPretty.toJson(zdt, ZonedDateTime.class); + assertEquals("{\n \"dateTime\": {\n \"date\":", zdtString.substring(0, 29)); + } +} diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java index df099ed5e..1d85ccb77 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java @@ -27,17 +27,17 @@ public abstract class ControlLoopEvent implements Serializable { private static final long serialVersionUID = 2391252138583119195L; - public String closedLoopControlName; - public String version = "1.0.2"; - public UUID requestID; - public String closedLoopEventClient; - public ControlLoopTargetType target_type; - public String target; - public String from; - public String policyScope; - public String policyName; - public String policyVersion; - public ControlLoopEventStatus closedLoopEventStatus; + private String closedLoopControlName; + private String version = "1.0.2"; + private UUID requestID; + private String closedLoopEventClient; + private ControlLoopTargetType targetType; + private String target; + private String from; + private String policyScope; + private String policyName; + private String policyVersion; + private ControlLoopEventStatus closedLoopEventStatus; public ControlLoopEvent() { @@ -50,7 +50,7 @@ public abstract class ControlLoopEvent implements Serializable { this.closedLoopControlName = event.closedLoopControlName; this.requestID = event.requestID; this.closedLoopEventClient = event.closedLoopEventClient; - this.target_type = event.target_type; + this.targetType = event.targetType; this.target = event.target; this.from = event.from; this.policyScope = event.policyScope; @@ -59,11 +59,95 @@ public abstract class ControlLoopEvent implements Serializable { this.closedLoopEventStatus = event.closedLoopEventStatus; } - public boolean isEventStatusValid() { - if (this.closedLoopEventStatus == null) { - return false; - } - return true; + public boolean isEventStatusValid() { + return this.closedLoopEventStatus != null; + } + + public String getClosedLoopControlName() { + return closedLoopControlName; + } + + public void setClosedLoopControlName(String closedLoopControlName) { + this.closedLoopControlName = closedLoopControlName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public UUID getRequestID() { + return requestID; + } + + public void setRequestID(UUID requestID) { + this.requestID = requestID; + } + + public String getClosedLoopEventClient() { + return closedLoopEventClient; + } + + public void setClosedLoopEventClient(String closedLoopEventClient) { + this.closedLoopEventClient = closedLoopEventClient; + } + + public ControlLoopTargetType getTargetType() { + return targetType; + } + + public void setTargetType(ControlLoopTargetType targetType) { + this.targetType = targetType; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getPolicyScope() { + return policyScope; + } + + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; } + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getPolicyVersion() { + return policyVersion; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + + public ControlLoopEventStatus getClosedLoopEventStatus() { + return closedLoopEventStatus; + } + + public void setClosedLoopEventStatus(ControlLoopEventStatus closedLoopEventStatus) { + this.closedLoopEventStatus = closedLoopEventStatus; + } } diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java index 8e29b1de3..8e7a50fac 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java @@ -31,32 +31,155 @@ public abstract class ControlLoopNotification implements Serializable { private static final long serialVersionUID = 7538596984567127915L; - public String closedLoopControlName; - public String version = "1.0.2"; - public UUID requestID; - public String closedLoopEventClient; - public ControlLoopTargetType target_type; - public String target; - public String from; - public String policyScope; - public String policyName; - public String policyVersion; - public ControlLoopNotificationType notification; - public String message; - public ZonedDateTime notificationTime = ZonedDateTime.now(ZoneOffset.UTC);; - public Integer OPS_CL_timer; - public List<ControlLoopOperation> history = new LinkedList<ControlLoopOperation>(); + private String closedLoopControlName; + private String version = "1.0.2"; + private UUID requestID; + private String closedLoopEventClient; + private ControlLoopTargetType targetType; + private String target; + private String from; + private String policyScope; + private String policyName; + private String policyVersion; + private ControlLoopNotificationType notification; + private String message; + private ZonedDateTime notificationTime = ZonedDateTime.now(ZoneOffset.UTC); + private Integer opsCLTimer; + private List<ControlLoopOperation> history = new LinkedList<>(); public ControlLoopNotification() { } public ControlLoopNotification(ControlLoopEvent event) { - this.closedLoopControlName = event.closedLoopControlName; - this.requestID = event.requestID; - this.closedLoopEventClient = event.closedLoopEventClient; - this.target_type = event.target_type; - this.target = event.target; + if (event == null) { + return; + } + + this.setClosedLoopControlName(event.getClosedLoopControlName()); + this.setRequestID(event.getRequestID()); + this.setClosedLoopEventClient(event.getClosedLoopEventClient()); + this.setTargetType(event.getTargetType()); + this.setTarget(event.getTarget()); + } + + public String getClosedLoopControlName() { + return closedLoopControlName; + } + + public void setClosedLoopControlName(String closedLoopControlName) { + this.closedLoopControlName = closedLoopControlName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public UUID getRequestID() { + return requestID; + } + + public void setRequestID(UUID requestID) { + this.requestID = requestID; + } + + public String getClosedLoopEventClient() { + return closedLoopEventClient; + } + + public void setClosedLoopEventClient(String closedLoopEventClient) { + this.closedLoopEventClient = closedLoopEventClient; + } + + public ControlLoopTargetType getTargetType() { + return targetType; + } + + public void setTargetType(ControlLoopTargetType targetType) { + this.targetType = targetType; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getPolicyScope() { + return policyScope; + } + + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getPolicyVersion() { + return policyVersion; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + + public ControlLoopNotificationType getNotification() { + return notification; + } + + public void setNotification(ControlLoopNotificationType notification) { + this.notification = notification; } + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public ZonedDateTime getNotificationTime() { + return notificationTime; + } + + public void setNotificationTime(ZonedDateTime notificationTime) { + this.notificationTime = notificationTime; + } + + public Integer getOpsCLTimer() { + return opsCLTimer; + } + + public void setOpsCLTimer(Integer opsCLTimer) { + this.opsCLTimer = opsCLTimer; + } + + public List<ControlLoopOperation> getHistory() { + return history; + } + + public void setHistory(List<ControlLoopOperation> history) { + this.history = history; + } } diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperation.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperation.java index ce721b43d..d024b7cec 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperation.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperation.java @@ -30,20 +30,24 @@ public class ControlLoopOperation implements Serializable { */ private static final long serialVersionUID = 8662706581293017099L; - public String actor; - public String operation; - public String target; - public Instant start = Instant.now(); - public Instant end; - public String subRequestId; - public String outcome; - public String message; + private String actor; + private String operation; + private String target; + private Instant start = Instant.now(); + private Instant end; + private String subRequestId; + private String outcome; + private String message; public ControlLoopOperation() { } public ControlLoopOperation(ControlLoopOperation op) { + if (op == null) { + return; + } + this.actor = op.actor; this.operation = op.operation; this.target = op.target; @@ -62,6 +66,70 @@ public class ControlLoopOperation implements Serializable { return "actor="+actor+",operation="+operation+",target="+target+",start="+start+",end="+end+",subRequestId="+subRequestId+",outcome="+outcome+",message="+message; } + public String getActor() { + return actor; + } + + public void setActor(String actor) { + this.actor = actor; + } + + public String getOperation() { + return operation; + } + + public void setOperation(String operation) { + this.operation = operation; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public Instant getStart() { + return start; + } + + public void setStart(Instant start) { + this.start = start; + } + + public Instant getEnd() { + return end; + } + + public void setEnd(Instant end) { + this.end = end; + } + + public String getSubRequestId() { + return subRequestId; + } + + public void setSubRequestId(String subRequestId) { + this.subRequestId = subRequestId; + } + + public String getOutcome() { + return outcome; + } + + public void setOutcome(String outcome) { + this.outcome = outcome; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + @Override public String toString() { return "ControlLoopOperation [actor=" + actor + ", operation=" + operation + ", target=" + target + ", start=" diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperationWrapper.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperationWrapper.java index fb3942b63..f957808d1 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperationWrapper.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperationWrapper.java @@ -24,8 +24,8 @@ import java.util.UUID; public class ControlLoopOperationWrapper { - public UUID requestID; - public ControlLoopOperation operation; + private UUID requestID; + private ControlLoopOperation operation; public ControlLoopOperationWrapper() { @@ -35,4 +35,20 @@ public class ControlLoopOperationWrapper { this.requestID = requestID; this.operation = operation; } + + public UUID getRequestID() { + return requestID; + } + + public void setRequestID(UUID requestID) { + this.requestID = requestID; + } + + public ControlLoopOperation getOperation() { + return operation; + } + + public void setOperation(ControlLoopOperation operation) { + this.operation = operation; + } } diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java index aca072eaa..12ced939e 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java @@ -21,10 +21,6 @@ package org.onap.policy.controlloop; public class PhysicalControlLoopEvent extends ControlLoopEvent { - - /** - * - */ private static final long serialVersionUID = -7282930271094849487L; public PhysicalControlLoopEvent() { @@ -36,6 +32,4 @@ public class PhysicalControlLoopEvent extends ControlLoopEvent { return; } } - - } diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java index c904d6740..9c63665ae 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java @@ -21,10 +21,6 @@ package org.onap.policy.controlloop; public class PhysicalControlLoopNotification extends ControlLoopNotification { - - /** - * - */ private static final long serialVersionUID = 8105197217140032892L; public PhysicalControlLoopNotification() { diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java index 932da84fc..c512b6796 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java @@ -30,9 +30,9 @@ public class VirtualControlLoopEvent extends ControlLoopEvent { * */ private static final long serialVersionUID = -5752405682246066226L; - public Instant closedLoopAlarmStart; - public Instant closedLoopAlarmEnd; - public Map<String, String> AAI = new HashMap<>(); + private Instant closedLoopAlarmStart; + private Instant closedLoopAlarmEnd; + private Map<String, String> aai = new HashMap<>(); public VirtualControlLoopEvent() { } @@ -42,11 +42,34 @@ public class VirtualControlLoopEvent extends ControlLoopEvent { if (event == null) { return; } - if (event.AAI != null) { - this.AAI = new HashMap<>(event.AAI); + if (event.aai != null) { + this.aai = new HashMap<>(event.aai); } this.closedLoopAlarmStart = event.closedLoopAlarmStart; this.closedLoopAlarmEnd = event.closedLoopAlarmEnd; } + public Instant getClosedLoopAlarmStart() { + return closedLoopAlarmStart; + } + + public void setClosedLoopAlarmStart(Instant closedLoopAlarmStart) { + this.closedLoopAlarmStart = closedLoopAlarmStart; + } + + public Instant getClosedLoopAlarmEnd() { + return closedLoopAlarmEnd; + } + + public void setClosedLoopAlarmEnd(Instant closedLoopAlarmEnd) { + this.closedLoopAlarmEnd = closedLoopAlarmEnd; + } + + public Map<String, String> getAAI() { + return aai; + } + + public void setAAI(Map<String, String> aai) { + this.aai = aai; + } } diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopNotification.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopNotification.java index 7415fccf0..c99e3a1b0 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopNotification.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopNotification.java @@ -31,9 +31,9 @@ public class VirtualControlLoopNotification extends ControlLoopNotification { */ private static final long serialVersionUID = 5354756047932144017L; - public Map<String, String> AAI = new HashMap<>(); - public Instant closedLoopAlarmStart; - public Instant closedLoopAlarmEnd; + private Map<String, String> aai = new HashMap<>(); + private Instant closedLoopAlarmStart; + private Instant closedLoopAlarmEnd; public VirtualControlLoopNotification() { } @@ -43,11 +43,34 @@ public class VirtualControlLoopNotification extends ControlLoopNotification { if (event == null) { return; } - if (event.AAI != null) { - this.AAI = new HashMap<>(event.AAI); + if (event.getAAI() != null) { + this.setAAI(new HashMap<>(event.getAAI())); } - this.closedLoopAlarmStart = event.closedLoopAlarmStart; - this.closedLoopAlarmEnd = event.closedLoopAlarmEnd; + this.closedLoopAlarmStart = event.getClosedLoopAlarmStart(); + this.closedLoopAlarmEnd = event.getClosedLoopAlarmEnd(); } + public Map<String, String> getAAI() { + return aai; + } + + public void setAAI(Map<String, String> aAI) { + this.aai = aAI; + } + + public Instant getClosedLoopAlarmStart() { + return closedLoopAlarmStart; + } + + public void setClosedLoopAlarmStart(Instant closedLoopAlarmStart) { + this.closedLoopAlarmStart = closedLoopAlarmStart; + } + + public Instant getClosedLoopAlarmEnd() { + return closedLoopAlarmEnd; + } + + public void setClosedLoopAlarmEnd(Instant closedLoopAlarmEnd) { + this.closedLoopAlarmEnd = closedLoopAlarmEnd; + } } diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java index 858dc82b9..d2a51f770 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java @@ -35,17 +35,15 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; - public final class Serialization { + private Serialization() { + } - public static class notificationTypeAdapter implements JsonSerializer<ControlLoopNotificationType>, JsonDeserializer<ControlLoopNotificationType> { - - + public static class NotificationTypeAdapter implements JsonSerializer<ControlLoopNotificationType>, JsonDeserializer<ControlLoopNotificationType> { @Override public JsonElement serialize(ControlLoopNotificationType src, Type typeOfSrc, JsonSerializationContext context) { @@ -54,14 +52,12 @@ public final class Serialization { @Override public ControlLoopNotificationType deserialize(JsonElement json, Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { + JsonDeserializationContext context) { return ControlLoopNotificationType.toType(json.getAsString()); } - } - - public static class targetTypeAdapter implements JsonSerializer<ControlLoopTargetType>, JsonDeserializer<ControlLoopTargetType> { + public static class TargetTypeAdapter implements JsonSerializer<ControlLoopTargetType>, JsonDeserializer<ControlLoopTargetType> { @Override public JsonElement serialize(ControlLoopTargetType src, Type typeOfSrc, JsonSerializationContext context) { @@ -70,19 +66,17 @@ public final class Serialization { @Override public ControlLoopTargetType deserialize(JsonElement json, Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { + JsonDeserializationContext context) { return ControlLoopTargetType.toType(json.getAsString()); } - } - - public static class gsonUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> { - private static final Logger logger = LoggerFactory.getLogger(gsonUTCAdapter.class); + + public static class GSONUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> { + private static final Logger logger = LoggerFactory.getLogger(GSONUTCAdapter.class); public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); - @Override - public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context) - throws JsonParseException { + @Override + public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context) { try { return ZonedDateTime.parse(element.getAsString(), format); } catch (Exception e) { @@ -91,17 +85,16 @@ public final class Serialization { return null; } - @Override + @Override public JsonElement serialize(ZonedDateTime datetime, Type type, JsonSerializationContext context) { return new JsonPrimitive(datetime.format(format)); } } - - public static class gsonInstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + + public static class GSONInstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { @Override - public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { return Instant.ofEpochMilli(json.getAsLong()); } @@ -109,30 +102,30 @@ public final class Serialization { public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src.toEpochMilli()); } - + } - - final static public Gson gson = new GsonBuilder().disableHtmlEscaping() - .registerTypeAdapter(ZonedDateTime.class, new gsonUTCAdapter()) - .registerTypeAdapter(Instant.class, new gsonInstantAdapter()) - .registerTypeAdapter(ControlLoopNotificationType.class, new notificationTypeAdapter()) - .registerTypeAdapter(ControlLoopTargetType.class, new targetTypeAdapter()) + + public static final Gson gson = new GsonBuilder().disableHtmlEscaping() + .registerTypeAdapter(ZonedDateTime.class, new GSONUTCAdapter()) + .registerTypeAdapter(Instant.class, new GSONInstantAdapter()) + .registerTypeAdapter(ControlLoopNotificationType.class, new NotificationTypeAdapter()) + .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()) .create(); - - final static public Gson gsonPretty = new GsonBuilder().disableHtmlEscaping() + + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping() .setPrettyPrinting() - .registerTypeAdapter(ZonedDateTime.class, new gsonUTCAdapter()) - .registerTypeAdapter(Instant.class, new gsonInstantAdapter()) - .registerTypeAdapter(ControlLoopNotificationType.class, new notificationTypeAdapter()) - .registerTypeAdapter(ControlLoopTargetType.class, new targetTypeAdapter()) + .registerTypeAdapter(ZonedDateTime.class, new GSONUTCAdapter()) + .registerTypeAdapter(Instant.class, new GSONInstantAdapter()) + .registerTypeAdapter(ControlLoopNotificationType.class, new NotificationTypeAdapter()) + .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()) .create(); - - final static public Gson gsonJunit = new GsonBuilder().disableHtmlEscaping() + + public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping() .setPrettyPrinting() - .registerTypeAdapter(ZonedDateTime.class, new gsonUTCAdapter()) - .registerTypeAdapter(Instant.class, new gsonInstantAdapter()) - .registerTypeAdapter(ControlLoopTargetType.class, new targetTypeAdapter()) + .registerTypeAdapter(ZonedDateTime.class, new GSONUTCAdapter()) + .registerTypeAdapter(Instant.class, new GSONInstantAdapter()) + .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()) .create(); } diff --git a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java index c74a75cbe..2540cb27a 100644 --- a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java +++ b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java @@ -22,6 +22,7 @@ package org.onap.policy.rest; import java.io.IOException; import java.util.Map; +import java.util.Map.Entry; import org.apache.http.HttpResponse; import org.apache.http.auth.AuthScope; @@ -39,89 +40,100 @@ import org.slf4j.LoggerFactory; public class RESTManager { - private static final Logger logger = LoggerFactory.getLogger(RESTManager.class); - - public class Pair<A, B> { - public final A a; - public final B b; - - public Pair(A a, B b) { - this.a = a; - this.b = b; - } - } - - public Pair<Integer, String> post(String url, String username, String password, Map<String, String> headers, String contentType, String body) { - CredentialsProvider credentials = new BasicCredentialsProvider(); - credentials.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); - - logger.debug("HTTP REQUEST: {} -> {} {} -> {}", url, username, ((password!=null)?password.length():"-"), contentType); - if (headers != null) { - logger.debug("Headers: "); - headers.forEach((name, value) -> { - logger.debug("{} -> {}", name, value); - }); - } - logger.debug(body); - - try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentials).build()) { - - HttpPost post = new HttpPost(url); - if (headers != null) { - for (String key : headers.keySet()) { - post.addHeader(key, headers.get(key)); - } - } - post.addHeader("Content-Type", contentType); - - StringEntity input = new StringEntity(body); - input.setContentType(contentType); - post.setEntity(input); - - HttpResponse response = client.execute(post); - if (response != null) { - String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8"); - logger.debug("HTTP POST Response Status Code: {}", response.getStatusLine().getStatusCode()); - logger.debug("HTTP POST Response Body:"); - logger.debug(returnBody); - - return new Pair<Integer, String>(response.getStatusLine().getStatusCode(), returnBody); - } else { - logger.error("Response from {} is null", url); - return null; - } - } catch (Exception e) { - logger.error("Failed to POST to {}",url,e); - return null; - } - } - - public Pair<Integer, String> get(String url, String username, String password, Map<String, String> headers) { - - CredentialsProvider credentials = new BasicCredentialsProvider(); - credentials.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); - - try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentials).build()) { - - HttpGet get = new HttpGet(url); - if (headers != null) { - for (String key : headers.keySet()) { - get.addHeader(key, headers.get(key)); - } - } - - HttpResponse response = client.execute(get); - - String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8"); - - logger.debug("HTTP GET Response Status Code: {}", response.getStatusLine().getStatusCode()); - logger.debug("HTTP GET Response Body:"); - logger.debug(returnBody); - - return new Pair<Integer, String>(response.getStatusLine().getStatusCode(), returnBody); - } catch (IOException e) { - logger.error("Failed to GET to {}",url,e); - return null; - } - } + private static final Logger logger = LoggerFactory.getLogger(RESTManager.class); + + public class Pair<A, B> { + public final A a; + public final B b; + + public Pair(A a, B b) { + this.a = a; + this.b = b; + } + } + + public Pair<Integer, String> post(String url, String username, String password, + Map<String, String> headers, String contentType, String body) { + CredentialsProvider credentials = new BasicCredentialsProvider(); + credentials.setCredentials(AuthScope.ANY, + new UsernamePasswordCredentials(username, password)); + + logger.debug("HTTP REQUEST: {} -> {} {} -> {}", url, username, + ((password != null) ? password.length() : "-"), contentType); + if (headers != null) { + logger.debug("Headers: "); + headers.forEach((name, value) -> logger.debug("{} -> {}", name, value)); + } + logger.debug(body); + + try (CloseableHttpClient client = + HttpClientBuilder.create().setDefaultCredentialsProvider(credentials).build()) { + + HttpPost post = new HttpPost(url); + if (headers != null) { + for (Entry<String, String> entry : headers.entrySet()) { + post.addHeader(entry.getKey(), headers.get(entry.getKey())); + } + } + post.addHeader("Content-Type", contentType); + + StringEntity input = new StringEntity(body); + input.setContentType(contentType); + post.setEntity(input); + + HttpResponse response = client.execute(post); + if (response != null) { + String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8"); + logger.debug("HTTP POST Response Status Code: {}", + response.getStatusLine().getStatusCode()); + logger.debug("HTTP POST Response Body:"); + logger.debug(returnBody); + + return new Pair<>(response.getStatusLine().getStatusCode(), + returnBody); + } + else { + logger.error("Response from {} is null", url); + return null; + } + } + catch (Exception e) { + logger.error("Failed to POST to {}", url, e); + return null; + } + } + + public Pair<Integer, String> get(String url, String username, String password, + Map<String, String> headers) { + + CredentialsProvider credentials = new BasicCredentialsProvider(); + credentials.setCredentials(AuthScope.ANY, + new UsernamePasswordCredentials(username, password)); + + try (CloseableHttpClient client = + HttpClientBuilder.create().setDefaultCredentialsProvider(credentials).build()) { + + HttpGet get = new HttpGet(url); + if (headers != null) { + for (Entry<String, String> entry : headers.entrySet()) { + get.addHeader(entry.getKey(), headers.get(entry.getKey())); + } + } + + HttpResponse response = client.execute(get); + + String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8"); + + logger.debug("HTTP GET Response Status Code: {}", + response.getStatusLine().getStatusCode()); + logger.debug("HTTP GET Response Body:"); + logger.debug(returnBody); + + return new Pair<>(response.getStatusLine().getStatusCode(), returnBody); + } + catch (IOException e) { + logger.error("Failed to GET to {}", url, e); + return null; + } + } } diff --git a/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestGet.java b/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestGet.java new file mode 100755 index 000000000..96dec30db --- /dev/null +++ b/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestGet.java @@ -0,0 +1,52 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * rest
+ * ================================================================================
+ *
+ * ================================================================================
+ * 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.rest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.rest.RESTManager.Pair;
+
+public class TestGet {
+
+ @Test(expected = NullPointerException.class)
+ public void testUrlNull() {
+ RESTManager mgr = new RESTManager();
+ mgr.get(null, "user", null, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testUsernameNull() {
+ RESTManager mgr = new RESTManager();
+ mgr.get("nothing", null, null, null);
+ }
+
+ @Test
+ public void testUrlExampleOrg() {
+ RESTManager mgr = new RESTManager();
+
+ Pair<Integer, String> result = mgr.get("http://www.example.org", "user", null, null);
+ assertEquals((Integer)200, result.a);
+ assertTrue(result.b != null);
+ assertTrue(result.b.length() > 0);
+ }
+}
\ No newline at end of file diff --git a/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestPair.java b/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestPair.java new file mode 100755 index 000000000..3ada0a74e --- /dev/null +++ b/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestPair.java @@ -0,0 +1,42 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * rest
+ * ================================================================================
+ *
+ * ================================================================================
+ * 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.rest;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.rest.RESTManager.Pair;
+
+public class TestPair {
+
+ @Test
+ public void testPair() {
+ RESTManager mgr = new RESTManager();
+
+ Pair<Integer, Integer> pii = mgr.new Pair<>(1, 2);
+ assertEquals((Integer) 1, (Integer) pii.a);
+ assertEquals((Integer) 2, (Integer) pii.b);
+
+ Pair<Integer, String> pis = mgr.new Pair<>(1, "test");
+ assertEquals((Integer) 1, (Integer) pis.a);
+ assertEquals("test", pis.b);
+ }
+}
diff --git a/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestPost.java b/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestPost.java new file mode 100755 index 000000000..40f1b3089 --- /dev/null +++ b/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestPost.java @@ -0,0 +1,42 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * rest
+ * ================================================================================
+ *
+ * ================================================================================
+ * 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.rest;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.rest.RESTManager.Pair;
+
+public class TestPost {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testUsernameNull() {
+ RESTManager mgr = new RESTManager();
+ mgr.post("nothing", null, null, null, null, null);
+ }
+
+ @Test
+ public void testBodyNull() {
+ RESTManager mgr = new RESTManager();
+ Pair<Integer, String> result = mgr.post("http://www.example.org", "user", null, null, null, null);
+ assertEquals(null, result);
+ }
+}
diff --git a/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PGRequest.java b/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PGRequest.java index d08d9422e..7bbaf3cbf 100644 --- a/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PGRequest.java +++ b/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PGRequest.java @@ -22,20 +22,19 @@ package org.onap.policy.vnf.trafficgenerator; import java.io.Serializable; - import com.google.gson.annotations.SerializedName; public class PGRequest implements Serializable { - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("pg-streams") - public PGStreams pgStreams; + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; - public PGRequest() { - } + @SerializedName("pg-streams") + public PGStreams pgStreams; + public PGRequest() { + //required by author + } } diff --git a/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PGStream.java b/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PGStream.java index de5a2c37d..a606eee4c 100644 --- a/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PGStream.java +++ b/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PGStream.java @@ -26,17 +26,17 @@ import com.google.gson.annotations.SerializedName; public class PGStream implements Serializable { - /** - * - */ - private static final long serialVersionUID = 5567635677419358210L; - - @SerializedName("id") - public String streamId; - @SerializedName("is-enabled") - public String isEnabled; + /** + * + */ + private static final long serialVersionUID = 5567635677419358210L; - public PGStream() { - } + @SerializedName("id") + public String streamId; + @SerializedName("is-enabled") + public String isEnabled; + public PGStream() { + //required by author + } } diff --git a/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PGStreams.java b/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PGStreams.java index dc0d4084f..2264c20a9 100644 --- a/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PGStreams.java +++ b/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PGStreams.java @@ -28,15 +28,15 @@ import com.google.gson.annotations.SerializedName; public class PGStreams implements Serializable { - /** - * - */ - private static final long serialVersionUID = 5567635677419358210L; - - @SerializedName("pg-stream") - public List<PGStream> pgStream= new LinkedList<PGStream>(); + /** + * + */ + private static final long serialVersionUID = 5567635677419358210L; - public PGStreams() { - } + @SerializedName("pg-stream") + public List<PGStream> pgStream = new LinkedList<>(); + public PGStreams() { + // required by author + } } diff --git a/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/util/Serialization.java b/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/util/Serialization.java index 9bfe2ffe6..3443bfcdf 100644 --- a/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/util/Serialization.java +++ b/controlloop/common/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/util/Serialization.java @@ -25,11 +25,8 @@ import com.google.gson.GsonBuilder; public final class Serialization { - private Serialization(){ - } + public static final Gson gsonPretty = + new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); - final static public Gson gsonPretty = new GsonBuilder().disableHtmlEscaping() - .setPrettyPrinting() -// .registerTypeAdapter(AAIQueryParameters.class, new notificationTypeAdapter()) - .create(); + private Serialization() {} } diff --git a/controlloop/common/model-impl/trafficgenerator/src/test/java/org/onap/policy/vnf/trafficgenerator/TestDemo.java b/controlloop/common/model-impl/trafficgenerator/src/test/java/org/onap/policy/vnf/trafficgenerator/TestDemo.java index 4b3599d43..0ae5f134e 100644 --- a/controlloop/common/model-impl/trafficgenerator/src/test/java/org/onap/policy/vnf/trafficgenerator/TestDemo.java +++ b/controlloop/common/model-impl/trafficgenerator/src/test/java/org/onap/policy/vnf/trafficgenerator/TestDemo.java @@ -30,24 +30,25 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class TestDemo { - private static final Logger logger = LoggerFactory.getLogger(TestDemo.class); - @Test - public void test() { - PGRequest request = new PGRequest(); - request.pgStreams = new PGStreams(); - - PGStream pgStream; - for(int i = 0; i < 5; i++){ - pgStream = new PGStream(); - pgStream.streamId = "fw_udp"+(i+1); - pgStream.isEnabled = "true"; - request.pgStreams.pgStream.add(pgStream); - } - - String body = Serialization.gsonPretty.toJson(request); - logger.debug(body); - - // fail("Not yet implemented"); - } + private static final Logger logger = LoggerFactory.getLogger(TestDemo.class); + + @Test + public void test() { + PGRequest request = new PGRequest(); + request.pgStreams = new PGStreams(); + + PGStream pgStream; + for (int i = 0; i < 5; i++) { + pgStream = new PGStream(); + pgStream.streamId = "fw_udp" + (i + 1); + pgStream.isEnabled = "true"; + request.pgStreams.pgStream.add(pgStream); + } + + String body = Serialization.gsonPretty.toJson(request); + logger.debug(body); + + // fail("Not yet implemented"); + } } diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl index 6d7ecdb89..c09e64abe 100644 --- a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl +++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl @@ -147,7 +147,7 @@ rule "${policyName}.EVENT" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) - not ( ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID ) ) + not ( ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID() ) ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -160,14 +160,14 @@ rule "${policyName}.EVENT" // we create the ControlLoopEventManager. The ControlLoopEventManager // will do extra syntax checking as well check if the closed loop is disabled. // - if ($event.requestID == null) { + if ($event.getRequestID() == null) { VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.notification = ControlLoopNotificationType.REJECTED; - notification.from = "policy"; - notification.message = "Missing requestID"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; + notification.setNotification(ControlLoopNotificationType.REJECTED); + notification.setFrom("policy"); + notification.setMessage("Missing requestID"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); // // Let interested parties know @@ -178,25 +178,25 @@ rule "${policyName}.EVENT" // Retract it from memory // retract($event); - } else if ($event.closedLoopEventStatus != ControlLoopEventStatus.ONSET) { - throw new ControlLoopException($event.closedLoopEventStatus + " received with no prior onset"); + } else if ($event.getClosedLoopEventStatus() != ControlLoopEventStatus.ONSET) { + throw new ControlLoopException($event.getClosedLoopEventStatus() + " received with no prior onset"); } else { // // Create an EventManager // - ControlLoopEventManager manager = new ControlLoopEventManager($params.getClosedLoopControlName(), $event.requestID); + ControlLoopEventManager manager = new ControlLoopEventManager($params.getClosedLoopControlName(), $event.getRequestID()); // // Determine if EventManager can actively process the event (i.e. syntax, is_closed_loop_disabled checks etc.) // VirtualControlLoopNotification notification = manager.activate($params.getControlLoopYaml(), $event); - notification.from = "pdp-0001-controller=controlloop"; // Engine.getInstanceName() - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; + notification.setFrom("pdp-0001-controller=controlloop"); // Engine.getInstanceName() + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); // // Are we actively pursuing this event? // - if (notification.notification == ControlLoopNotificationType.ACTIVE) { + if (notification.getNotification() == ControlLoopNotificationType.ACTIVE) { // // Insert Event Manager into memory, this will now kick off processing. // @@ -209,8 +209,8 @@ rule "${policyName}.EVENT" // Setup the Overall Control Loop timer // ControlLoopTimer clTimer = new ControlLoopTimer(); - clTimer.setClosedLoopControlName($event.closedLoopControlName); - clTimer.setRequestID($event.requestID.toString()); + clTimer.setClosedLoopControlName($event.getClosedLoopControlName()); + clTimer.setRequestID($event.getRequestID().toString()); clTimer.setDelay(manager.getControlLoopTimeout(1500) + "s"); // // Insert it @@ -237,11 +237,11 @@ rule "${policyName}.EVENT" logger.warn("{}: {}", $params.getClosedLoopControlName(), drools.getRule().getName(), e); VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.notification = ControlLoopNotificationType.REJECTED; - notification.message = "Exception occurred: " + e.getMessage(); - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; + notification.setNotification(ControlLoopNotificationType.REJECTED); + notification.setMessage("Exception occurred: " + e.getMessage()); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); // // // @@ -263,8 +263,8 @@ rule "${policyName}.EVENT.MANAGER" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID ) - $clTimer : ControlLoopTimer ( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID() ) + $clTimer : ControlLoopTimer ( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID().toString() ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -310,7 +310,7 @@ rule "${policyName}.EVENT.MANAGER" } logger.debug("{}: {}: target={}", $params.getClosedLoopControlName(), - drools.getRule().getName(), $event.target); + drools.getRule().getName(), $event.getTarget()); // // Now start seeing if we need to process this event // @@ -328,11 +328,11 @@ rule "${policyName}.EVENT.MANAGER" if ($manager.getNumAbatements() > 0) { logger.info("{}: {}: abatement received for {}. Closing the control loop", $params.getClosedLoopControlName(), drools.getRule().getName(), - $event.requestID); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; + $event.getRequestID()); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); // // In this case, we are done // @@ -364,18 +364,18 @@ rule "${policyName}.EVENT.MANAGER" // // Check whether we need to wait for abatement // - if ($manager.getProcessor().getControlLoop().getAbatement() == true && notification.notification == ControlLoopNotificationType.FINAL_SUCCESS) { + if ($manager.getProcessor().getControlLoop().getAbatement() == true && notification.getNotification() == ControlLoopNotificationType.FINAL_SUCCESS) { logger.info("{}: {}: waiting for abatement ..", $params.getClosedLoopControlName(), drools.getRule().getName()); } else { logger.info("{}: {}: no abatement expect for {}. Closing the control loop", $params.getClosedLoopControlName(), drools.getRule().getName(), - $event.requestID); + $event.getRequestID()); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); // // In this case, we are done @@ -424,8 +424,8 @@ rule "${policyName}.EVENT.MANAGER" // insert operation timeout object // OperationTimer opTimer = new OperationTimer(); - opTimer.setClosedLoopControlName($event.closedLoopControlName); - opTimer.setRequestID($event.requestID.toString()); + opTimer.setClosedLoopControlName($event.getClosedLoopControlName()); + opTimer.setRequestID($event.getRequestID().toString()); opTimer.setDelay(operation.getOperationTimeout().toString() + "s"); insert(opTimer); @@ -436,14 +436,14 @@ rule "${policyName}.EVENT.MANAGER" } else { logger.debug("The target resource {} is already processing", - $event.AAI.get($event.target)); + $event.getAAI().get($event.getTarget())); notification = new VirtualControlLoopNotification($event); - notification.notification = ControlLoopNotificationType.REJECTED; - notification.message = "The target " + $event.AAI.get($event.target) + " is already locked"; - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; + notification.setNotification(ControlLoopNotificationType.REJECTED); + notification.setMessage("The target " + $event.getAAI().get($event.getTarget()) + " is already locked"); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); @@ -468,12 +468,12 @@ rule "${policyName}.EVENT.MANAGER" drools.getRule().getName(), e); VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.notification = ControlLoopNotificationType.FINAL_FAILURE; - notification.message = e.getMessage(); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; + notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE); + notification.setMessage(e.getMessage()); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); @@ -493,10 +493,10 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID, "Permit".equalsIgnoreCase(getGuardApprovalStatus()) ) - $lock : TargetLock (requestID == $event.requestID) - $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestID() == $event.getRequestID(), "Permit".equalsIgnoreCase(getGuardApprovalStatus()) ) + $lock : TargetLock (requestID == $event.getRequestID()) + $opTimer : OperationTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID().toString() ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -531,13 +531,13 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" // Tell interested parties we are performing this Operation // VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.notification = ControlLoopNotificationType.OPERATION; - notification.message = $operation.getOperationMessage(); - notification.history = $operation.getHistory(); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; + notification.setNotification(ControlLoopNotificationType.OPERATION); + notification.setMessage($operation.getOperationMessage()); + notification.setHistory($operation.getHistory()); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); @@ -558,7 +558,7 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" if(request instanceof SORequest) { // Call SO. The response will be inserted into memory once it's received - SOActorServiceProvider.sendRequest($event.requestID.toString(), drools.getWorkingMemory(), request); + SOActorServiceProvider.sendRequest($event.getRequestID().toString(), drools.getWorkingMemory(), request); } break; case "VFC": @@ -601,9 +601,9 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID, getGuardApprovalStatus() == "NONE" ) - $lock : TargetLock (requestID == $event.requestID) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestID() == $event.getRequestID(), getGuardApprovalStatus() == "NONE" ) + $lock : TargetLock (requestID == $event.getRequestID()) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -615,13 +615,13 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED" // Sending notification that we are about to query Guard ("DB write - start operation") // VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.notification = ControlLoopNotificationType.OPERATION; - notification.message = "Sending guard query for " + $operation.policy.getActor() + " " + $operation.policy.getRecipe(); - notification.history = $operation.getHistory(); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; + notification.setNotification(ControlLoopNotificationType.OPERATION); + notification.setMessage("Sending guard query for " + $operation.policy.getActor() + " " + $operation.policy.getRecipe()); + notification.setHistory($operation.getHistory()); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); @@ -641,16 +641,16 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED" Thread t = new Thread(new org.onap.policy.guard.CallGuardTask( drools.getWorkingMemory(), - $event.closedLoopControlName, + $event.getClosedLoopControlName(), $operation.policy.getActor().toString(), $operation.policy.getRecipe(), $operation.getTargetEntity(), - $event.requestID.toString() + $event.getRequestID().toString() )); t.start(); } else{ - insert(new PolicyGuardResponse("Permit", $event.requestID, $operation.policy.getRecipe())); + insert(new PolicyGuardResponse("Permit", $event.getRequestID(), $operation.policy.getRecipe())); } end @@ -663,11 +663,11 @@ rule "${policyName}.GUARD.RESPONSE" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID ) - $lock : TargetLock (requestID == $event.requestID) - $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() ) - $guardResponse : PolicyGuardResponse(requestID == $event.requestID, $operation.policy.recipe == operation) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestID() == $event.getRequestID() ) + $lock : TargetLock (requestID == $event.getRequestID()) + $opTimer : OperationTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID().toString() ) + $guardResponse : PolicyGuardResponse(requestID == $event.getRequestID(), $operation.policy.recipe == operation) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -685,13 +685,13 @@ rule "${policyName}.GUARD.RESPONSE" // This notification has Guard result in "message". ("DB write - end operation in case of Guard Deny") // VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.notification = ControlLoopNotificationType.OPERATION; - notification.message = "Guard result for " + $operation.policy.getActor() + " " + $operation.policy.getRecipe() + " is " + $guardResponse.result; - notification.history = $operation.getHistory(); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; + notification.setNotification(ControlLoopNotificationType.OPERATION); + notification.setMessage("Guard result for " + $operation.policy.getActor() + " " + $operation.policy.getRecipe() + " is " + $guardResponse.result); + notification.setHistory($operation.getHistory()); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); @@ -717,7 +717,7 @@ end * This rule responds to APPC Response Events * * I would have like to be consistent and write the Response like this: -* $response : Response( CommonHeader.RequestID == $onset.requestID ) +* $response : Response( CommonHeader.RequestID == $onset.getRequestID() ) * * However, no compile error was given. But a runtime error was given. I think * because drools is confused between the classname CommonHeader vs the property CommonHeader. @@ -727,11 +727,11 @@ rule "${policyName}.APPC.RESPONSE" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID ) - $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() ) - $lock : TargetLock (requestID == $event.requestID) - $response : Response( getCommonHeader().RequestID == $event.requestID ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestID() == $event.getRequestID() ) + $opTimer : OperationTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID().toString() ) + $lock : TargetLock (requestID == $event.getRequestID()) + $response : Response( getCommonHeader().RequestID == $event.getRequestID() ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -751,20 +751,20 @@ rule "${policyName}.APPC.RESPONSE" // This Operation has completed, construct a notification showing our results. (DB write - end operation) // VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; - notification.message = $operation.getOperationHistory(); - notification.history = $operation.getHistory(); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); + notification.setMessage($operation.getOperationHistory()); + notification.setHistory($operation.getHistory()); if (policyResult.equals(PolicyResult.SUCCESS)) { - notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS; + notification.setNotification(ControlLoopNotificationType.OPERATION_SUCCESS); // // Let interested parties know // PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); } else { - notification.notification = ControlLoopNotificationType.OPERATION_FAILURE; + notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE); // // Let interested parties know // @@ -841,11 +841,11 @@ rule "${policyName}.APPC.LCM.RESPONSE" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID ) - $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() ) - $lock : TargetLock (requestID == $event.requestID) - $response : LCMResponseWrapper( getBody().getCommonHeader().getRequestId() == $event.requestID ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestID() == $event.getRequestID() ) + $opTimer : OperationTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID().toString() ) + $lock : TargetLock (requestID == $event.getRequestID()) + $response : LCMResponseWrapper( getBody().getCommonHeader().getRequestId() == $event.getRequestID() ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -867,16 +867,16 @@ rule "${policyName}.APPC.LCM.RESPONSE" // This Operation has completed, construct a notification showing our results. (DB write - end operation) // VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; - notification.message = $operation.getOperationHistory(); - notification.history = $operation.getHistory(); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); + notification.setMessage($operation.getOperationHistory()); + notification.setHistory($operation.getHistory()); if (policyResult.equals(PolicyResult.SUCCESS)) { - notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS; + notification.setNotification(ControlLoopNotificationType.OPERATION_SUCCESS); } else { - notification.notification = ControlLoopNotificationType.OPERATION_FAILURE; + notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE); } PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); // @@ -946,11 +946,11 @@ rule "${policyName}.SO.RESPONSE" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID ) - $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() ) - $lock : TargetLock (requestID == $event.requestID) - $response : SOResponseWrapper(requestID.toString() == $event.requestID.toString() ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestID() == $event.getRequestID() ) + $opTimer : OperationTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID().toString() ) + $lock : TargetLock (requestID == $event.getRequestID()) + $response : SOResponseWrapper(requestID.toString() == $event.getRequestID().toString() ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -971,16 +971,16 @@ rule "${policyName}.SO.RESPONSE" // This Operation has completed, construct a notification showing our results // VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; - notification.message = $operation.getOperationHistory(); - notification.history = $operation.getHistory(); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); + notification.setMessage($operation.getOperationHistory()); + notification.setHistory($operation.getHistory()); if (policyResult.equals(PolicyResult.SUCCESS)) { - notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS; + notification.setNotification(ControlLoopNotificationType.OPERATION_SUCCESS); } else { - notification.notification = ControlLoopNotificationType.OPERATION_FAILURE; + notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE); } PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); @@ -1030,11 +1030,11 @@ rule "${policyName}.VFC.RESPONSE" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID ) - $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() ) - $lock : TargetLock (requestID == $event.requestID) - $response : VFCResponse( requestId.toString() == $event.requestID.toString() ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestID() == $event.getRequestID() ) + $opTimer : OperationTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID().toString() ) + $lock : TargetLock (requestID == $event.getRequestID()) + $response : VFCResponse( requestId.toString() == $event.getRequestID().toString() ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); logger.info("{}: {}", $params.getClosedLoopControlName(), drools.getRule().getName()); @@ -1050,12 +1050,12 @@ rule "${policyName}.VFC.RESPONSE" // This Operation has completed, construct a notification showing our results // VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; - notification.message = $operation.getOperationHistory(); - notification.history = $operation.getHistory(); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); + notification.setMessage($operation.getOperationHistory()); + notification.setHistory($operation.getHistory()); // // Ensure the operation is complete // @@ -1103,10 +1103,10 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.TIMEOUT" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID ) - $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString(), $to : getDelay() ) - $lock : TargetLock (requestID == $event.requestID) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestID() == $event.getRequestID() ) + $opTimer : OperationTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID().toString(), $to : getDelay() ) + $lock : TargetLock (requestID == $event.getRequestID()) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -1123,13 +1123,13 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.TIMEOUT" // Create a notification for it ("DB Write - end operation") // VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; - notification.notification = ControlLoopNotificationType.OPERATION_FAILURE; - notification.message = $operation.getOperationHistory(); - notification.history = $operation.getHistory(); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); + notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE); + notification.setMessage($operation.getOperationHistory()); + notification.setHistory($operation.getHistory()); // // Let interested parties know // @@ -1168,14 +1168,14 @@ rule "${policyName}.EVENT.MANAGER.TIMEOUT" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID ) - $clTimer : ControlLoopTimer ( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString(), $to : getDelay() ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID() ) + $clTimer : ControlLoopTimer ( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID().toString(), $to : getDelay() ) $operations : LinkedList() - from collect( ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID ) ) + from collect( ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestID() == $event.getRequestID() ) ) $opTimers : LinkedList() - from collect( OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() ) ) + from collect( OperationTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestID().toString() ) ) $locks : LinkedList() - from collect( TargetLock (requestID == $event.requestID) ) + from collect( TargetLock (requestID == $event.getRequestID()) ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -1195,10 +1195,10 @@ rule "${policyName}.EVENT.MANAGER.TIMEOUT" // VirtualControlLoopNotification notification = $manager.setControlLoopTimedOut(); if (notification != null) { - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); // // Let interested parties know // diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java index 869a1a6ff..826488691 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java @@ -270,64 +270,64 @@ public class ControlLoopFailureTest implements TopicListener { assertNotNull(obj); if (obj instanceof VirtualControlLoopNotification) { VirtualControlLoopNotification notification = (VirtualControlLoopNotification) obj; - String policyName = notification.policyName; + String policyName = notification.getPolicyName(); if (policyName.endsWith("EVENT")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification)); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.getNotification())); } else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("Sending guard query")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("Sending guard query")); } else if (policyName.endsWith("GUARD.RESPONSE")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.toLowerCase().endsWith("permit")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().toLowerCase().endsWith("permit")); } else if (policyName.endsWith("GUARD_PERMITTED")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("actor=APPC")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("actor=APPC")); } else if (policyName.endsWith("OPERATION.TIMEOUT")) { - logger.debug("Rule Fired: " + notification.policyName); + logger.debug("Rule Fired: " + notification.getPolicyName()); kieSession.halt(); logger.debug("The operation timed out"); fail("Operation Timed Out"); } else if (policyName.endsWith("APPC.LCM.RESPONSE")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("actor=APPC")); - if (requestId.equals(notification.requestID)) { + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("actor=APPC")); + if (requestId.equals(notification.getRequestID())) { sendEvent(pair.a, requestId, ControlLoopEventStatus.ABATED, "vnf01"); } - else if (requestId2.equals(notification.requestID)) { + else if (requestId2.equals(notification.getRequestID())) { sendEvent(pair.a, requestId2, ControlLoopEventStatus.ABATED, "vnf02"); } } else if (policyName.endsWith("EVENT.MANAGER")) { - logger.debug("Rule Fired: " + notification.policyName); - if (requestId3.equals(notification.requestID)) { + logger.debug("Rule Fired: " + notification.getPolicyName()); + if (requestId3.equals(notification.getRequestID())) { /* * The event with the duplicate target should be rejected */ - assertTrue(ControlLoopNotificationType.REJECTED.equals(notification.notification)); + assertTrue(ControlLoopNotificationType.REJECTED.equals(notification.getNotification())); } else { - assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification)); + assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.getNotification())); } if (++eventCount == 3) { kieSession.halt(); } } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) { - logger.debug("Rule Fired: " + notification.policyName); + logger.debug("Rule Fired: " + notification.getPolicyName()); kieSession.halt(); logger.debug("The control loop timed out"); fail("Control Loop Timed Out"); @@ -378,13 +378,13 @@ public class ControlLoopFailureTest implements TopicListener { protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String target) { VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.closedLoopControlName = policy.getControlLoop().getControlLoopName(); - event.requestID = requestID; - event.target = "generic-vnf.vnf-id"; - event.closedLoopAlarmStart = Instant.now(); - event.AAI = new HashMap<>(); - event.AAI.put("generic-vnf.vnf-id", target); - event.closedLoopEventStatus = status; + event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName()); + event.setRequestID(requestID); + event.setTarget("generic-vnf.vnf-id"); + event.setClosedLoopAlarmStart(Instant.now()); + event.setAAI(new HashMap<>()); + event.getAAI().put("generic-vnf.vnf-id", target); + event.setClosedLoopEventStatus(status); kieSession.insert(event); } diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java index c95d558a5..661d8c187 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java @@ -276,55 +276,55 @@ public class VCPEControlLoopTest implements TopicListener { assertNotNull(obj); if (obj instanceof VirtualControlLoopNotification) { VirtualControlLoopNotification notification = (VirtualControlLoopNotification) obj; - String policyName = notification.policyName; + String policyName = notification.getPolicyName(); if (policyName.endsWith("EVENT")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification)); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.getNotification())); } else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("Sending guard query")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("Sending guard query")); } else if (policyName.endsWith("GUARD.RESPONSE")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.toLowerCase().endsWith("permit")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().toLowerCase().endsWith("permit")); } else if (policyName.endsWith("GUARD_PERMITTED")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("actor=APPC")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("actor=APPC")); } else if (policyName.endsWith("OPERATION.TIMEOUT")) { - logger.debug("Rule Fired: " + notification.policyName); + logger.debug("Rule Fired: " + notification.getPolicyName()); kieSession.halt(); logger.debug("The operation timed out"); fail("Operation Timed Out"); } else if (policyName.endsWith("APPC.LCM.RESPONSE")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("actor=APPC")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("actor=APPC")); sendEvent(pair.a, requestID, ControlLoopEventStatus.ABATED); } else if (policyName.endsWith("EVENT.MANAGER")) { - logger.debug("Rule Fired: " + notification.policyName); - if ("getFail".equals(notification.AAI.get("generic-vnf.vnf-name"))) { - assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification); + logger.debug("Rule Fired: " + notification.getPolicyName()); + if ("getFail".equals(notification.getAAI().get("generic-vnf.vnf-name"))) { + assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification()); kieSession.halt(); } else { - assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, notification.notification); + assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, notification.getNotification()); kieSession.halt(); } } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) { - logger.debug("Rule Fired: " + notification.policyName); + logger.debug("Rule Fired: " + notification.getPolicyName()); kieSession.halt(); logger.debug("The control loop timed out"); fail("Control Loop Timed Out"); @@ -366,37 +366,37 @@ public class VCPEControlLoopTest implements TopicListener { */ protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status) { VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.closedLoopControlName = policy.getControlLoop().getControlLoopName(); - event.requestID = requestID; - event.target = "generic-vnf.vnf-name"; - event.closedLoopAlarmStart = Instant.now(); - event.AAI = new HashMap<>(); - event.AAI.put("generic-vnf.vnf-name", "testGenericVnfName"); - event.closedLoopEventStatus = status; + event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName()); + event.setRequestID(requestID); + event.setTarget("generic-vnf.vnf-name"); + event.setClosedLoopAlarmStart(Instant.now()); + event.setAAI(new HashMap<>()); + event.getAAI().put("generic-vnf.vnf-name", "testGenericVnfName"); + event.setClosedLoopEventStatus(status); kieSession.insert(event); } protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String vnfName, boolean isEnriched) { VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.closedLoopControlName = policy.getControlLoop().getControlLoopName(); - event.requestID = requestID; - event.target = "generic-vnf.vnf-name"; - event.target_type = ControlLoopTargetType.VNF; - event.closedLoopAlarmStart = Instant.now(); - event.AAI = new HashMap<>(); - event.AAI.put("generic-vnf.vnf-name", vnfName); + event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName()); + event.setRequestID(requestID); + event.setTarget("generic-vnf.vnf-name"); + event.setTargetType(ControlLoopTargetType.VNF); + event.setClosedLoopAlarmStart(Instant.now()); + event.setAAI(new HashMap<>()); + event.getAAI().put("generic-vnf.vnf-name", vnfName); if (isEnriched) { - event.AAI.put("generic-vnf.in-maint", "false"); - event.AAI.put("generic-vnf.is-closed-loop-disabled", "false"); - event.AAI.put("generic-vnf.orchestration-status", "Created"); - event.AAI.put("generic-vnf.prov-status", "PREPROV"); - event.AAI.put("generic-vnf.resource-version", "1"); - event.AAI.put("generic-vnf.service-id", "e8cb8968-5411-478b-906a-f28747de72cd"); - event.AAI.put("generic-vnf.vnf-id", "63b31229-9a3a-444f-9159-04ce2dca3be9"); - event.AAI.put("generic-vnf.vnf-type", "vCPEInfraService10/vCPEInfraService10 0"); + event.getAAI().put("generic-vnf.in-maint", "false"); + event.getAAI().put("generic-vnf.is-closed-loop-disabled", "false"); + event.getAAI().put("generic-vnf.orchestration-status", "Created"); + event.getAAI().put("generic-vnf.prov-status", "PREPROV"); + event.getAAI().put("generic-vnf.resource-version", "1"); + event.getAAI().put("generic-vnf.service-id", "e8cb8968-5411-478b-906a-f28747de72cd"); + event.getAAI().put("generic-vnf.vnf-id", "63b31229-9a3a-444f-9159-04ce2dca3be9"); + event.getAAI().put("generic-vnf.vnf-type", "vCPEInfraService10/vCPEInfraService10 0"); } - event.closedLoopEventStatus = status; + event.setClosedLoopEventStatus(status); kieSession.insert(event); } diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java index f7e2c3049..25a69b14e 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java @@ -319,56 +319,56 @@ public class VDNSControlLoopTest implements TopicListener { assertNotNull(obj); if (obj instanceof VirtualControlLoopNotification) { VirtualControlLoopNotification notification = (VirtualControlLoopNotification) obj; - String policyName = notification.policyName; + String policyName = notification.getPolicyName(); if (policyName.endsWith("EVENT")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification)); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.getNotification())); } else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("Sending guard query")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("Sending guard query")); } else if (policyName.endsWith("GUARD.RESPONSE")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.toLowerCase().endsWith("permit")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().toLowerCase().endsWith("permit")); } else if (policyName.endsWith("GUARD_PERMITTED")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("actor=SO")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("actor=SO")); } else if (policyName.endsWith("OPERATION.TIMEOUT")) { - logger.debug("Rule Fired: " + notification.policyName); + logger.debug("Rule Fired: " + notification.getPolicyName()); kieSession.halt(); logger.debug("The operation timed out"); fail("Operation Timed Out"); } else if (policyName.endsWith("SO.RESPONSE")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("actor=SO")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("actor=SO")); } else if (policyName.endsWith("EVENT.MANAGER")) { - logger.debug("Rule Fired: " + notification.policyName); - if ("error".equals(notification.AAI.get("vserver.vserver-name"))) { - assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification); + logger.debug("Rule Fired: " + notification.getPolicyName()); + if ("error".equals(notification.getAAI().get("vserver.vserver-name"))) { + assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification()); } - else if ("getFail".equals(notification.AAI.get("vserver.vserver-name"))) { - assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification); + else if ("getFail".equals(notification.getAAI().get("vserver.vserver-name"))) { + assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification()); } else { - assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification)); + assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.getNotification())); } kieSession.halt(); } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) { - logger.debug("Rule Fired: " + notification.policyName); + logger.debug("Rule Fired: " + notification.getPolicyName()); kieSession.halt(); logger.debug("The control loop timed out"); fail("Control Loop Timed Out"); @@ -390,26 +390,26 @@ public class VDNSControlLoopTest implements TopicListener { */ protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status) { VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.closedLoopControlName = policy.getControlLoop().getControlLoopName(); - event.requestID = requestID; - event.target = "vserver.vserver-name"; - event.closedLoopAlarmStart = Instant.now(); - event.AAI = new HashMap<>(); - event.AAI.put("vserver.vserver-name", "dfw1lb01lb01"); - event.AAI.put("vserver.is-closed-loop-disabled", "false"); - event.closedLoopEventStatus = status; + event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName()); + event.setRequestID(requestID); + event.setTarget("vserver.vserver-name"); + event.setClosedLoopAlarmStart(Instant.now()); + event.setAAI(new HashMap<>()); + event.getAAI().put("vserver.vserver-name", "dfw1lb01lb01"); + event.getAAI().put("vserver.is-closed-loop-disabled", "false"); + event.setClosedLoopEventStatus(status); kieSession.insert(event); } protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String vserverName) { VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.closedLoopControlName = policy.getControlLoop().getControlLoopName(); - event.requestID = requestID; - event.target = "vserver.vserver-name"; - event.closedLoopAlarmStart = Instant.now(); - event.AAI = new HashMap<>(); - event.AAI.put("vserver.vserver-name", vserverName); - event.closedLoopEventStatus = status; + event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName()); + event.setRequestID(requestID); + event.setTarget("vserver.vserver-name"); + event.setClosedLoopAlarmStart(Instant.now()); + event.setAAI(new HashMap<>()); + event.getAAI().put("vserver.vserver-name", vserverName); + event.setClosedLoopEventStatus(status); kieSession.insert(event); } diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java index 39dac8131..178b5b29d 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java @@ -192,16 +192,16 @@ public class VFCControlLoopTest implements TopicListener { */ VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.closedLoopControlName = pair.a.getControlLoop().getControlLoopName(); - event.requestID = UUID.randomUUID(); - event.closedLoopEventClient = "tca.instance00009"; - event.target_type = ControlLoopTargetType.VM; - event.target = "vserver.vserver-name"; - event.from = "DCAE"; - event.closedLoopAlarmStart = Instant.now(); - event.AAI = new HashMap<String, String>(); - event.AAI.put("vserver.vserver-name", "nullRequest"); - event.closedLoopEventStatus = ControlLoopEventStatus.ONSET; + event.setClosedLoopControlName(pair.a.getControlLoop().getControlLoopName()); + event.setRequestID(UUID.randomUUID()); + event.setClosedLoopEventClient("tca.instance00009"); + event.setTargetType(ControlLoopTargetType.VM); + event.setTarget("vserver.vserver-name"); + event.setFrom("DCAE"); + event.setClosedLoopAlarmStart(Instant.now()); + event.setAAI(new HashMap<String, String>()); + event.getAAI().put("vserver.vserver-name", "nullRequest"); + event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); kieSession.insert(event); kieSession.fireUntilHalt(); @@ -287,53 +287,53 @@ public class VFCControlLoopTest implements TopicListener { assertNotNull(obj); if (obj instanceof VirtualControlLoopNotification) { VirtualControlLoopNotification notification = (VirtualControlLoopNotification) obj; - String policyName = notification.policyName; + String policyName = notification.getPolicyName(); if (policyName.endsWith("EVENT")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification)); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.getNotification())); } else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("Sending guard query")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("Sending guard query")); } else if (policyName.endsWith("GUARD.RESPONSE")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.toLowerCase().endsWith("permit")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().toLowerCase().endsWith("permit")); } else if (policyName.endsWith("GUARD_PERMITTED")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("actor=VFC")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("actor=VFC")); } else if (policyName.endsWith("OPERATION.TIMEOUT")) { - logger.debug("Rule Fired: " + notification.policyName); + logger.debug("Rule Fired: " + notification.getPolicyName()); kieSession.halt(); logger.debug("The operation timed out"); fail("Operation Timed Out"); } else if (policyName.endsWith("VFC.RESPONSE")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("actor=VFC")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("actor=VFC")); } else if (policyName.endsWith("EVENT.MANAGER")) { - logger.debug("Rule Fired: " + notification.policyName); - if ("nullRequest".equals(notification.AAI.get("vserver.vserver-name"))){ - assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification); + logger.debug("Rule Fired: " + notification.getPolicyName()); + if ("nullRequest".equals(notification.getAAI().get("vserver.vserver-name"))){ + assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification()); } else { - assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, notification.notification); + assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, notification.getNotification()); } kieSession.halt(); } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) { - logger.debug("Rule Fired: " + notification.policyName); + logger.debug("Rule Fired: " + notification.getPolicyName()); kieSession.halt(); logger.debug("The control loop timed out"); fail("Control Loop Timed Out"); @@ -355,20 +355,20 @@ public class VFCControlLoopTest implements TopicListener { */ protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status) { VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.closedLoopControlName = policy.getControlLoop().getControlLoopName(); - event.requestID = UUID.randomUUID(); - event.closedLoopEventClient = "tca.instance00009"; - event.target_type = ControlLoopTargetType.VM; - event.target = "vserver.vserver-name"; - event.from = "DCAE"; - event.closedLoopAlarmStart = Instant.now(); - event.AAI = new HashMap<String, String>(); - event.AAI.put("vserver.vserver-name", "vserver-name-16102016-aai3255-data-11-1"); - event.AAI.put("vserver.vserver-id", "vserver-id-16102016-aai3255-data-11-1"); - event.AAI.put("generic-vnf.vnf-id", "vnf-id-16102016-aai3255-data-11-1"); - event.AAI.put("service-instance.service-instance-id", "service-instance-id-16102016-aai3255-data-11-1"); - event.AAI.put("vserver.is-closed-loop-disabled", "false"); - event.closedLoopEventStatus = ControlLoopEventStatus.ONSET; + event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName()); + event.setRequestID(UUID.randomUUID()); + event.setClosedLoopEventClient("tca.instance00009"); + event.setTargetType(ControlLoopTargetType.VM); + event.setTarget("vserver.vserver-name"); + event.setFrom("DCAE"); + event.setClosedLoopAlarmStart(Instant.now()); + event.setAAI(new HashMap<String, String>()); + event.getAAI().put("vserver.vserver-name", "vserver-name-16102016-aai3255-data-11-1"); + event.getAAI().put("vserver.vserver-id", "vserver-id-16102016-aai3255-data-11-1"); + event.getAAI().put("generic-vnf.vnf-id", "vnf-id-16102016-aai3255-data-11-1"); + event.getAAI().put("service-instance.service-instance-id", "service-instance-id-16102016-aai3255-data-11-1"); + event.getAAI().put("vserver.is-closed-loop-disabled", "false"); + event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); kieSession.insert(event); } diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java index 95737b9c8..156fbbaa8 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java @@ -322,58 +322,58 @@ public class VFWControlLoopTest implements TopicListener { assertNotNull(obj); if (obj instanceof VirtualControlLoopNotification) { VirtualControlLoopNotification notification = (VirtualControlLoopNotification) obj; - String policyName = notification.policyName; + String policyName = notification.getPolicyName(); if (policyName.endsWith("EVENT")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification)); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.getNotification())); } else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("Sending guard query")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("Sending guard query")); } else if (policyName.endsWith("GUARD.RESPONSE")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.toLowerCase().endsWith("permit")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().toLowerCase().endsWith("permit")); } else if (policyName.endsWith("GUARD_PERMITTED")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("actor=APPC")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("actor=APPC")); } else if (policyName.endsWith("OPERATION.TIMEOUT")) { - logger.debug("Rule Fired: " + notification.policyName); + logger.debug("Rule Fired: " + notification.getPolicyName()); kieSession.halt(); logger.debug("The operation timed out"); fail("Operation Timed Out"); } else if (policyName.endsWith("APPC.RESPONSE")) { - logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.notification)); - assertNotNull(notification.message); - assertTrue(notification.message.startsWith("actor=APPC")); + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().startsWith("actor=APPC")); sendEvent(pair.a, requestID, ControlLoopEventStatus.ABATED); } else if (policyName.endsWith("EVENT.MANAGER")) { - logger.debug("Rule Fired: " + notification.policyName); - if ("error".equals(notification.AAI.get("generic-vnf.vnf-name"))) { - assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification); - assertEquals("Target vnf-id could not be found", notification.message); + logger.debug("Rule Fired: " + notification.getPolicyName()); + if ("error".equals(notification.getAAI().get("generic-vnf.vnf-name"))) { + assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification()); + assertEquals("Target vnf-id could not be found", notification.getMessage()); } - else if ("getFail".equals(notification.AAI.get("generic-vnf.vnf-name"))) { - assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification); + else if ("getFail".equals(notification.getAAI().get("generic-vnf.vnf-name"))) { + assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification()); } else { - assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification)); + assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.getNotification())); } kieSession.halt(); } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) { - logger.debug("Rule Fired: " + notification.policyName); + logger.debug("Rule Fired: " + notification.getPolicyName()); kieSession.halt(); logger.debug("The control loop timed out"); fail("Control Loop Timed Out"); @@ -407,13 +407,13 @@ public class VFWControlLoopTest implements TopicListener { */ protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status) { VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.closedLoopControlName = policy.getControlLoop().getControlLoopName(); - event.requestID = requestID; - event.target = "generic-vnf.vnf-name"; - event.closedLoopAlarmStart = Instant.now(); - event.AAI = new HashMap<>(); - event.AAI.put("generic-vnf.vnf-name", "testGenericVnfID"); - event.closedLoopEventStatus = status; + event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName()); + event.setRequestID(requestID); + event.setTarget("generic-vnf.vnf-name"); + event.setClosedLoopAlarmStart(Instant.now()); + event.setAAI(new HashMap<>()); + event.getAAI().put("generic-vnf.vnf-name", "testGenericVnfID"); + event.setClosedLoopEventStatus(status); kieSession.insert(event); } @@ -428,13 +428,13 @@ public class VFWControlLoopTest implements TopicListener { */ protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String vnfId) { VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.closedLoopControlName = policy.getControlLoop().getControlLoopName(); - event.requestID = requestID; - event.target = "generic-vnf.vnf-name"; - event.closedLoopAlarmStart = Instant.now(); - event.AAI = new HashMap<>(); - event.AAI.put("generic-vnf.vnf-name", vnfId); - event.closedLoopEventStatus = status; + event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName()); + event.setRequestID(requestID); + event.setTarget("generic-vnf.vnf-name"); + event.setClosedLoopAlarmStart(Instant.now()); + event.setAAI(new HashMap<>()); + event.getAAI().put("generic-vnf.vnf-name", vnfId); + event.setClosedLoopEventStatus(status); kieSession.insert(event); } |