diff options
Diffstat (limited to 'controlloop/templates/archetype-cl-amsterdam/src/main/resources')
-rw-r--r-- | controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl | 117 |
1 files changed, 117 insertions, 0 deletions
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 57ebd7089..4cbdd49e5 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 @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2017-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,8 @@ package org.onap.policy.controlloop; +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput; + import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.VirtualControlLoopNotification; import org.onap.policy.controlloop.ControlLoopEventStatus; @@ -32,6 +35,9 @@ import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager; import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager.NewEventStatus; import org.onap.policy.controlloop.eventmanager.ControlLoopOperationManager; 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; @@ -42,6 +48,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; @@ -636,6 +645,34 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" PolicyEngineConstants.getManager().deliver("SDNR-CL", request); } 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 { // @@ -1429,6 +1466,86 @@ rule "${policyName}.SDNC.RESPONSE" end + +/** + * This rule responds to CDS Response Events + */ +rule "${policyName}.CDS.RESPONSE" + when + $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) + $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("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); + 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. |