summaryrefslogtreecommitdiffstats
path: root/controlloop/common/controller-usecases/src/main/resources
diff options
context:
space:
mode:
authorBruno Sakoto <bruno.sakoto@bell.ca>2019-09-27 16:15:49 -0400
committerBruno Sakoto <bruno.sakoto@bell.ca>2019-10-16 21:48:07 -0400
commit636a1b2fcafa5249cf2bf380dfb6e20f6fe98691 (patch)
tree484d505efe1727cd288c26d353bc2613c2f02bef /controlloop/common/controller-usecases/src/main/resources
parent112d8b48a4515773e769e088df2e5a5ca6f85f63 (diff)
Integrate cds actor service provider
* Add request enrichment with aai service instance id and vnf id * Implement cds grpc request * Implement VfwControlLoopCdsTest Issue-ID: POLICY-2088 Signed-off-by: Bruno Sakoto <bruno.sakoto@bell.ca> Change-Id: Ib44d447d6a3a70ff800a5760032b676fdfa32d9c
Diffstat (limited to 'controlloop/common/controller-usecases/src/main/resources')
-rw-r--r--controlloop/common/controller-usecases/src/main/resources/usecases.drl117
1 files changed, 117 insertions, 0 deletions
diff --git a/controlloop/common/controller-usecases/src/main/resources/usecases.drl b/controlloop/common/controller-usecases/src/main/resources/usecases.drl
index 02161b8c3..4adf74064 100644
--- a/controlloop/common/controller-usecases/src/main/resources/usecases.drl
+++ b/controlloop/common/controller-usecases/src/main/resources/usecases.drl
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Bell Canada.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +21,7 @@
package org.onap.policy.controlloop;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.policy.controlloop.params.ControlLoopParams;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
@@ -35,6 +37,9 @@ import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager.NewEvent
import org.onap.policy.controlloop.eventmanager.ControlLoopOperationManager;
import org.onap.policy.controlloop.utils.ControlLoopUtils;
import org.onap.policy.controlloop.actor.so.SoActorServiceProvider;
+import org.onap.policy.controlloop.actor.cds.CdsActorServiceProvider;
+import org.onap.policy.controlloop.actor.cds.CdsActorServiceProvider.CdsActorServiceManager;
+import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants;
import org.onap.policy.aai.AaiNqResponseWrapper;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.appc.Request;
@@ -45,6 +50,9 @@ import org.onap.policy.appclcm.LcmResponseWrapper;
import org.onap.policy.appclcm.LcmRequest;
import org.onap.policy.appclcm.LcmResponse;
import org.onap.policy.appclcm.LcmCommonHeader;
+import org.onap.policy.cds.CdsResponse;
+import org.onap.policy.cds.client.CdsProcessorGrpcClient;
+import org.onap.policy.cds.properties.CdsServerProperties;
import org.onap.policy.sdnr.PciRequestWrapper;
import org.onap.policy.sdnr.PciResponseWrapper;
import org.onap.policy.sdnr.PciRequest;
@@ -78,6 +86,7 @@ import java.time.Instant;
import java.util.LinkedList;
import java.util.Iterator;
+
import org.onap.policy.drools.system.PolicyEngineConstants;
/*
@@ -621,6 +630,33 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
t.start();
}
break;
+
+ case "CDS":
+
+ if(request instanceof ExecutionServiceInput) {
+
+ // Instantiate cds actor, service manager and grpc properties
+
+ CdsActorServiceProvider cdsActor = new CdsActorServiceProvider();
+ CdsActorServiceProvider.CdsActorServiceManager cdsActorServiceManager = cdsActor.new CdsActorServiceManager();
+
+ CdsServerProperties props = new CdsServerProperties();
+ props.setHost(PolicyEngineConstants.getManager().getEnvironmentProperty("cds.grpcHost"));
+ props.setPort(Integer.parseInt(PolicyEngineConstants.getManager().getEnvironmentProperty("cds.grpcPort")));
+ props.setUsername(PolicyEngineConstants.getManager().getEnvironmentProperty("cds.grpcUsername"));
+ props.setPassword(PolicyEngineConstants.getManager().getEnvironmentProperty("cds.grpcPassword"));
+ props.setTimeout(Integer.parseInt(PolicyEngineConstants.getManager().getEnvironmentProperty("cds.grpcTimeout")));
+
+ // Send cds grpc request
+ try (CdsProcessorGrpcClient client = new CdsProcessorGrpcClient(cdsActorServiceManager, props)) {
+ CdsResponse response =
+ cdsActorServiceManager.sendRequestToCds(client, props, (ExecutionServiceInput) request);
+ logger.info("CDS response: {}", response);
+ insert(response);
+ }
+ }
+ break;
+
}
} else {
//
@@ -1302,6 +1338,87 @@ rule "SDNC.RESPONSE"
end
+
+/**
+ * This rule responds to CDS Response Events
+ */
+rule "${policyName}.CDS.RESPONSE"
+ when
+ $params : ControlLoopParams( $clName : getClosedLoopControlName() )
+ $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(),
+ closedLoopEventStatus == ControlLoopEventStatus.ONSET )
+ $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(),
+ requestId == $event.getRequestId() )
+ $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(),
+ onset.getRequestId() == $event.getRequestId() )
+ $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(),
+ requestId == $event.getRequestId().toString(), timerType == "Operation", !expired )
+ $lock : TargetLock (requestId == $event.getRequestId())
+ $response : CdsResponse( requestId == $event.getRequestId().toString() )
+
+ then
+
+ Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage());
+ logger.info("{}: {}", $params.getClosedLoopControlName(), drools.getRule().getName());
+ logger.debug("{}: {}: event={} manager={} operation={} lock={} opTimer={} response={}",
+ $params.getClosedLoopControlName(), drools.getRule().getName(),
+ $event, $manager, $operation, $lock, $operation, $opTimer, $response);
+
+ // Get the result of the operation
+ PolicyResult policyResult = $operation.onResponse($response);
+
+ if (policyResult != null) {
+ logger.debug("{}: {}: operation finished - result={}",
+ $params.getClosedLoopControlName(), drools.getRule().getName(),
+ policyResult);
+
+ // The operation has completed, construct a notification showing our results
+ VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
+ notification.setFrom("policy");
+ notification.setPolicyName(drools.getRule().getName());
+ notification.setPolicyScope($params.getPolicyScope());
+ notification.setPolicyVersion($params.getPolicyVersion());
+ notification.setMessage($operation.getOperationHistory());
+ notification.setHistory($operation.getHistory());
+ notification.setNotification(
+ ($response != null && CdsActorConstants.SUCCESS.equals($response.getStatus()))
+ ? ControlLoopNotificationType.OPERATION_SUCCESS : ControlLoopNotificationType.OPERATION_FAILURE);
+
+ // Send the notification
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
+
+ // Ensure the operation is complete
+ if ($operation.isOperationComplete()) {
+
+ // It is complete, remove it from memory
+ retract($operation);
+
+ // We must also retract the timer object
+ // NOTE: We could write a Rule to do this
+ retract($opTimer);
+
+ // Complete the operation
+ modify($manager) {finishOperation($operation)};
+
+ } else {
+ // Just doing this will kick off the LOCKED rule again
+ modify($operation) {};
+ }
+ } else {
+ // Its not finished yet (i.e. expecting more Response objects)
+ // Or possibly it is a leftover response that we timed the request out previously
+ logger.info(
+ "policyResult is null"
+ + "\nIt's not finished yet (i.e. expecting more Response objects)"
+ + "\nOr possibly it is a leftover response that we timed the request out previously");
+ }
+
+ // We are going to retract these objects from memory
+ retract($response);
+
+end
+
+/*
/*
*
* This manages a single timer.