From 05aceee2186ee6cf05f6963e2435f8b44b389e62 Mon Sep 17 00:00:00 2001 From: Jorge Hernandez Date: Thu, 17 Aug 2017 14:46:36 -0500 Subject: installation improvements and renaming archetype Two changes: - remove hardcoding of the DMaaP hosts, and DCAE topic to make it configurable. - rename archetype to better name. Change-Id: Ic50b9d1f06a138230c76cc6c50ca8072dc5da148 Issue-ID: POLICY-159 Signed-off-by: Jorge Hernandez --- controlloop/packages/artifacts/pom.xml | 2 +- .../packages/basex/src/files/bin/create-cl-legacy | 314 ++++++ .../basex/src/files/bin/create-closed-loop-demo.sh | 315 ------ .../src/files/config/vDNS-controller.properties | 20 +- .../src/files/config/vFW-controller.properties | 20 +- .../archetype-cl-legacy/pom.xml | 57 + .../META-INF/maven/archetype-metadata.xml | 77 ++ .../src/main/resources/archetype-resources/pom.xml | 85 ++ .../config/__artifactId__-controller.properties | 55 + .../config/__artifactId__-controller.rest.json | 37 + .../src/main/config/appc.accepted.json | 1 + .../src/main/config/appc.success.json | 1 + .../src/main/config/dcae.onset.json | 14 + .../ControlLoopDemo__closedLoopControlName__.drl | 1140 ++++++++++++++++++++ .../src/main/resources/META-INF/kmodule.xml | 29 + .../resources/projects/basic/archetype.properties | 50 + .../src/test/resources/projects/basic/goal.txt | 0 .../archetype-closedloop-demo-rules/pom.xml | 57 - .../META-INF/maven/archetype-metadata.xml | 77 -- .../src/main/resources/archetype-resources/pom.xml | 85 -- .../config/__artifactId__-controller.properties | 55 - .../config/__artifactId__-controller.rest.json | 37 - .../src/main/config/appc.accepted.json | 1 - .../src/main/config/appc.success.json | 1 - .../src/main/config/dcae.onset.json | 14 - .../ControlLoopDemo__closedLoopControlName__.drl | 1140 -------------------- .../src/main/resources/META-INF/kmodule.xml | 29 - .../resources/projects/basic/archetype.properties | 50 - .../src/test/resources/projects/basic/goal.txt | 0 controlloop/templates/template.demo.v1.0.0/pom.xml | 21 +- 30 files changed, 1891 insertions(+), 1893 deletions(-) create mode 100644 controlloop/packages/basex/src/files/bin/create-cl-legacy delete mode 100644 controlloop/packages/basex/src/files/bin/create-closed-loop-demo.sh create mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/pom.xml create mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/META-INF/maven/archetype-metadata.xml create mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/pom.xml create mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties create mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json create mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/appc.accepted.json create mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/appc.success.json create mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/dcae.onset.json create mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/resources/ControlLoopDemo__closedLoopControlName__.drl create mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/resources/META-INF/kmodule.xml create mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/test/resources/projects/basic/archetype.properties create mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/test/resources/projects/basic/goal.txt delete mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/pom.xml delete mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/META-INF/maven/archetype-metadata.xml delete mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/pom.xml delete mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties delete mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json delete mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/appc.accepted.json delete mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/appc.success.json delete mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/dcae.onset.json delete mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/resources/ControlLoopDemo__closedLoopControlName__.drl delete mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/resources/META-INF/kmodule.xml delete mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/test/resources/projects/basic/archetype.properties delete mode 100644 controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/test/resources/projects/basic/goal.txt (limited to 'controlloop') diff --git a/controlloop/packages/artifacts/pom.xml b/controlloop/packages/artifacts/pom.xml index cce85c710..27ec28a84 100644 --- a/controlloop/packages/artifacts/pom.xml +++ b/controlloop/packages/artifacts/pom.xml @@ -146,7 +146,7 @@ org.onap.policy.drools-applications - archetype-closedloop-demo-rules + archetype-cl-legacy ${project.version} jar diff --git a/controlloop/packages/basex/src/files/bin/create-cl-legacy b/controlloop/packages/basex/src/files/bin/create-cl-legacy new file mode 100644 index 000000000..9aaa3c875 --- /dev/null +++ b/controlloop/packages/basex/src/files/bin/create-cl-legacy @@ -0,0 +1,314 @@ +#! /bin/bash + +### +# ============LICENSE_START======================================================= +# PDP-D APPS Base Package +# ================================================================================ +# 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========================================================= +### + +# Interactive script to generate a closed loop demo rules artifact +# for testing purposes of standalone PDP-D + +echo "Closed Loop Demo Creator for standalone PDP-D" +echo "----------------------------------------------" +echo + +GROUPID="org.onap.policy.demo.rules" +ARTIFACTID="closed-loop-demo-rules" +VERSION="1.1.0" +PACKAGE="org.onap.policy.demo.rules" +CLOSEDLOOPCONTROLNAME="CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" +POLICYSCOPE="service=test;resource=FRWL;type=configuration" +POLICYNAME="FirewallDemo" +POLICYVERSION="v0.0.1" +ACTOR="APPC" +APPCTOPIC="APPC-CL" +APPCSERVERS="vm1.mr.simpledemo.openecomp.org" +APPCAPIKEY= +APPCAPISECRET= +NOTIFICATIONTOPIC="POLICY-CL-MGT" +NOTIFICATIONSERVERS="vm1.mr.simpledemo.openecomp.org" +NOTIFICATIONAPIKEY= +NOTIFICATIONAPISECRET= +DCAETOPIC="DCAE-CL-EVENT" +DCAESERVERS="vm1.mr.simpledemo.openecomp.org" +DCAEAPIKEY= +DCAEAPISECRET= +AAIURL="http://localhost:7676/aai/test" +AAIUSERNAME="policy" +AAIPASSWORD="policy" +AAINAMEDQUERYUUID=d925ed73-8231-4d02-9545-db4e101fffff +AAIPATTERNMATCH=1 +MSOURL="http://localhost:7677/mso/test" +MSOUSERNAME="policy" +MSOPASSWORD="policy" + +read -e -i "${GROUPID}" -p "Closed Loop Rules Maven Group Id> " GROUP_ID +read -e -i "${ARTIFACTID}" -p "Closed Loop Rules Maven Coordinates Artifact Id> " ARTIFACTID +read -e -i "${VERSION}" -p "Closed Loop Rules Maven Coordinates Version> " VERSION +read -e -i "${PACKAGE}" -p "Closed Loop Rules Package> " PACKAGE +read -e -i "${CLOSEDLOOPCONTROLNAME}" -p "Closed Loop Template Control Name> " CLOSEDLOOPCONTROLNAME +read -e -i "${POLICYSCOPE}" -p "Closed Loop Policy Scope> " POLICYSCOPE +read -e -i "${POLICYNAME}" -p "Closed Loop Policy Name> " POLICYNAME +read -e -i "${POLICYVERSION}" -p "Closed Loop Policy Version> " POLICYVERSION +read -e -i "${ACTOR}" -p "Closed Loop Actor ('APPC' or 'MSO')> " ACTOR +read -e -i "${APPCTOPIC}" -p "Closed Loop APP-C Recipe Topic> " APPCTOPIC +read -e -i "${APPCSERVERS}" -p "Closed Loop APP-C UEB Servers for ${APPCTOPIC} topic> " APPCSERVERS +read -e -i "${APPCAPIKEY}" -p "Closed Loop APP-C UEB API Key for ${APPCTOPIC} topic> " APPCAPIKEY +read -e -i "${APPCAPISECRET}" -p "Closed Loop APP-C UEB API Secret for ${APPCTOPIC} topic> " APPCAPISECRET +read -e -i "${NOTIFICATIONTOPIC}" -p "Closed Loop Ruby Notification Topic> " NOTIFICATIONTOPIC +read -e -i "${NOTIFICATIONSERVERS}" -p "Closed Loop Ruby UEB Servers for ${NOTIFICATIONTOPIC} topic> " NOTIFICATIONSERVERS +read -e -i "${NOTIFICATIONAPIKEY}" -p "Closed Loop Ruby UEB API Key ${NOTIFICATIONTOPIC} topic> " NOTIFICATIONAPIKEY +read -e -i "${NOTIFICATIONAPISECRET}" -p "Closed Loop Ruby UEB API Secret ${NOTIFICATIONTOPIC} topic> " NOTIFICATIONAPISECRET +read -e -i "${DCAETOPIC}" -p "Closed Loop DCAE Topic> " DCAETOPIC +read -e -i "${DCAESERVERS}" -p "Closed Loop DCAE UEB Servers> " DCAESERVERS +read -e -i "${DCAEAPIKEY}" -p "Closed Loop DCAE UEB API Key for ${DCAETOPIC} topic> " DCAEAPIKEY +read -e -i "${DCAEAPISECRET}" -p "Closed Loop DCAE UEB API Secret for ${DCAETOPIC} topic> " DCAEAPISECRET +read -e -i "${AAIURL}" -p "Closed Loop AAI URL> " AAIURL +read -e -i "${AAIUSERNAME}" -p "Closed Loop AAI Username> " AAIUSERNAME +read -e -i "${AAIPASSWORD}" -p "Closed Loop AAI Password> " AAIPASSWORD +read -e -i "${AAINAMEDQUERYUUID}" -p "Closed Loop AAI Named Query UUID> " AAINAMEDQUERYUUID +read -e -i "${AAIPATTERNMATCH}" -p "Closed Loop AAI Pattern Match (1 for vFW, otherwise vDNS)> " AAIPATTERNMATCH +read -e -i "${MSOURL}" -p "Closed Loop MSO URL> " MSOURL +read -e -i "${MSOUSERNAME}" -p "Closed Loop MSO Username> " MSOUSERNAME +read -e -i "${MSOPASSWORD}" -p "Closed Loop MSO Password> " MSOPASSWORD + +echo +echo + +if [ -z "${GROUPID}" ]; then echo "Aborting: Closed Loop Rules Maven Group Id not provided"; exit 1; fi +if [ -z "${ARTIFACTID}" ]; then echo "Aborting: Closed Loop Rules Maven Coordinates Artifact Id not provided"; exit 1; fi +if [ -z "${VERSION}" ]; then echo "Aborting: Closed Loop Rules Maven Coordinates Version not provided"; exit 1; fi +if [ -z "${PACKAGE}" ]; then echo "Aborting: Closed Loop Rules Package not provided"; exit 1; fi +if [ -z "${CLOSEDLOOPCONTROLNAME}" ]; then echo "Aborting: Closed Loop Template Control Name not provided"; exit 1; fi +if [ -z "${POLICYSCOPE}" ]; then echo "Aborting: Closed Loop Template Policy Scope not provided"; exit 1; fi +if [ -z "${POLICYNAME}" ]; then echo "Aborting: Closed Loop Template Policy Name not provided"; exit 1; fi +if [ -z "${POLICYVERSION}" ]; then echo "Aborting: Closed Loop Template Policy Version not provided"; exit 1; fi +if [ -z "${ACTOR}" ]; then echo "Aborting: Closed Loop Template Actor not provided"; exit 1; fi +if [ -z "${APPCTOPIC}" ]; then echo "Aborting: Closed Loop Template APP-C Recipe Topic not provided"; exit 1; fi +if [ -z "${APPCSERVERS}" ]; then echo "Aborting: Closed Loop Template APP-C UEB Servers not provided"; exit 1; fi +if [ -z "${NOTIFICATIONTOPIC}" ]; then echo "Aborting: Closed Loop Template Ruby Notification Topic not provided"; exit 1; fi +if [ -z "${NOTIFICATIONSERVERS}" ]; then echo "Aborting: Closed Loop Template Ruby UEB Servers not provided"; exit 1; fi +if [ -z "${DCAETOPIC}" ]; then echo "Aborting: Closed Loop Template DCAE DMAAP Topic not provided"; exit 1; fi +if [ -z "${DCAESERVERS}" ]; then echo "Aborting: Closed Loop Template DCAE DMAAP Servers not provided"; exit 1; fi +if [ -z "${AAIURL}" ]; then echo "Aborting: Closed Loop Template AAI URL not provided"; exit 1; fi +if [ -z "${AAIUSERNAME}" ]; then echo "Aborting: Closed Loop Template AAI Username not provided"; exit 1; fi +if [ -z "${AAIPASSWORD}" ]; then echo "Aborting: Closed Loop Template AAI Password not provided"; exit 1; fi +if [ -z "${AAINAMEDQUERYUUID}" ]; then echo "Aborting: Closed Loop Template AAI Named Query UUID not provided"; exit 1; fi +if [ -z "${AAIPATTERNMATCH}" ]; then echo "Aborting: Closed Loop Template AAPI Pattern Match not provided"; exit 1; fi +if [ -z "${MSOURL}" ]; then echo "Aborting: Closed Loop Template MSO URL not provided"; exit 1; fi +if [ -z "${MSOUSERNAME}" ]; then echo "Aborting: Closed Loop Template MSO Username not provided"; exit 1; fi +if [ -z "${MSOPASSWORD}" ]; then echo "Aborting: Closed Loop Template MSO Password not provided"; exit 1; fi + +if [ -z "${DCAEAPIKEY}" ]; then DCAEAPIKEY="NULL"; fi +if [ -z "${DCAEAPISECRET}" ]; then DCAEAPISECRET="NULL"; fi +if [ -z "${APPCAPIKEY}" ]; then APPCAPIKEY="NULL"; fi +if [ -z "${APPCAPISECRET}" ]; then APPCAPISECRET="NULL"; fi +if [ -z "${NOTIFICATIONAPIKEY}" ]; then NOTIFICATIONAPIKEY="NULL"; fi +if [ -z "${NOTIFICATIONAPISECRET}" ]; then NOTIFICATIONAPISECRET="NULL"; fi + +if [[ "$VERSION" == *-SNAPSHOT ]]; then + DEPENDENCIES_VERSION="1.1.0-SNAPSHOT" +else + DEPENDENCIES_VERSION="${VERSION}" +fi + +read -e -i "${DEPENDENCIES_VERSION}" -p "Closed Loop Model/PDP-D dependent version(s) (ie: 1.0.0-SNAPSHOT, 1607.31.1-1, or [1607.31.1,)) > " DEPENDENCIES_VERSION +if [ -z "${DEPENDENCIES_VERSION}" ]; then echo "Aborting: Closed Loop Model/PDP-D dependencies not provided"; exit 1; fi + +echo "---------------------------------------------------------------------------------------" +echo "Please review the entered Closed Loop Maven Coordinates and Policy Template Parameters:" +echo +echo "Installation in Local Maven Repository" +echo +echo "Closed Loop Rules Maven Artifact Generation: Group Id: ${GROUP_ID}" +echo "Closed Loop Rules Maven Artifact Generation: Artifact Id: ${ARTIFACTID}" +echo "Closed Loop Rules Maven Artifact Generation: Version: ${VERSION}" +echo "Closed Loop Rules Maven Artifact Generation: Package: ${PACKAGE}" +echo +echo "Closed Loop Template Drools DRL Expansion: Closed Loop Control Name: ${CLOSEDLOOPCONTROLNAME}" +echo "Closed Loop Template Drools DRL Expansion: Closed Loop Policy Scope: ${POLICYSCOPE}" +echo "Closed Loop Template Drools DRL Expansion: Closed Loop Policy Name: ${POLICYNAME}" +echo "Closed Loop Template Drools DRL Expansion: Closed Loop Policy Version: ${POLICYVERSION}" +echo "Closed Loop Template Drools DRL Expansion: Closed Loop Actor: ${ACTOR}" +echo "Closed Loop Template Drools DRL Expansion: Closed Loop Recipe: ${APPC}" +echo "Closed Loop Template Drools DRL Expansion: Closed Loop Recipe Topic: ${APPCTOPIC}" +echo "Closed Loop Template Drools DRL Expansion: Closed Loop Notification Topic: ${NOTIFICATIONTOPIC}" +echo +echo "Closed Loop Controller Configuration: Rules: Group Id: ${GROUP_ID}" +echo "Closed Loop Controller Configuration: Rules: Artifact Id: ${ARTIFACTID}" +echo "Closed Loop Controller Configuration: Rules: Version: ${VERSION}" +echo +echo "Closed Loop Controller Configuration: DCAE UEB Topic: ${DCAETOPIC}" +echo "Closed Loop Controller Configuration: DCAE UEB Servers: ${DCAESERVERS}" +echo "Closed Loop Controller Configuration: DCAE UEB API Key: ${DCAEAPIKEY}" +echo "Closed Loop Controller Configuration: DCAE UEB API Secret: ${DCAEAPISECRET}" +echo +echo "Closed Loop Controller Configuration: APP-C UEB Topic: ${APPCTOPIC}" +echo "Closed Loop Controller Configuration: APP-C UEB Servers: ${APPCSERVERS}" +echo "Closed Loop Controller Configuration: APP-C UEB API Key: ${APPCAPIKEY}" +echo "Closed Loop Controller Configuration: APP-C UEB API Secret: ${APPCAPISECRET}" +echo +echo "Closed Loop Controller Configuration: NOTIFICATION Topic: ${NOTIFICATIONTOPIC}" +echo "Closed Loop Controller Configuration: NOTIFICATION UEB Servers: ${NOTIFICATIONSERVERS}" +echo "Closed Loop Controller Configuration: NOTIFICATION UEB API Key: ${NOTIFICATIONAPIKEY}" +echo "Closed Loop Controller Configuration: NOTIFICATION UEB API Secret: ${NOTIFICATIONAPISECRET}" +echo +echo "Closed Loop Controller Configuration: AAI URL: ${AAIURL}" +echo "Closed Loop Controller Configuration: AAI Username: ${AAIUSERNAME}" +echo "Closed Loop Controller Configuration: AAI Password: ${AAIPASSWORD}" +echo "Closed Loop Controller Configuration: AAI Named Query UUID: ${AAINAMEDQUERYUUID}" +echo "Closed Loop Controller Configuration: AAI Pattern Match: ${AAIPATTERNMATCH}" +echo +echo "Closed Loop Controller Configuration: MSO URL: ${MSOURL}" +echo "Closed Loop Controller Configuration: MSO Username: ${MSOUSERNAME}" +echo "Closed Loop Controller Configuration: MSO Password: ${MSOPASSWORD}" +echo +echo "Closed Loop Model/PDP-D dependent version(s): ${DEPENDENCIES_VERSION}" +echo "---------------------------------------------------------------------------------------" +echo + +HAPPY="Y" +read -e -i "${HAPPY}" -p "Are the previous parameters correct (Y/N)? " HAPPY +if [[ ${HAPPY} != "Y" ]]; then + exit 1 +fi + +echo +DIR_TMP="/tmp" +echo "The Closed Loop Source Rules will be installed at ${DIR_TMP}" +read -e -i "${DIR_TMP}" -p "Do you want to change the Source Rules install directory? " DIR_TMP + +if [ ! -w "${DIR_TMP}" ]; then + echo "Aborting. ${DIR_TMP} is not writable" + exit 1 +fi + +ARCHETYPE_GROUP_ID="org.onap.policy.drools-applications" +ARCHETYPE_ARTIFACT_ID="archetype-cl-legacy" + +if [ -d "${DIR_TMP}/${ARTIFACTID}/" ]; then + if [ "$(ls -A "${DIR_TMP}/${ARTIFACTID}"/)" ]; then + echo "${DIR_TMP} already contains a ${ARTIFACTID}/ directory, saving it to ${DIR_TMP}/${ARTIFACTID}.arch.bak/" + if [ -d "${DIR_TMP}/${ARTIFACTID}.arch.bak"/ ]; then + ( + echo "${DIR_TMP}/${ARTIFACTID}.arch.bak/ also exists, deleting it .." + cd "${DIR_TMP}"/ + rm -fr "${ARTIFACTID}.arch.bak" + ) + fi + /bin/mv --force "${DIR_TMP}/${ARTIFACTID}/" "${DIR_TMP}/${ARTIFACTID}.arch.bak" + if [ "${?}" -ne 0 ]; then + echo + echo + echo "Aborting: ${DIR_TMP}/${ARTIFACTID}/ cannot be moved" + exit 1 + fi + else + ( cd "${DIR_TMP}/" ; rmdir "${DIR_TMP}/${ARTIFACTID}/" ) + fi +fi + +CREATEARTIFACT="Y" +read -e -i "${CREATEARTIFACT}" -p "Create Maven Artifact (Y/N)? " CREATEARTIFACT +if [[ ${CREATEARTIFACT} != "Y" ]]; then + exit 1 +fi + +( +cd "${DIR_TMP}" + +mvn archetype:generate \ + -B \ + -DarchetypeGroupId="${ARCHETYPE_GROUP_ID}" \ + -DarchetypeArtifactId="${ARCHETYPE_ARTIFACT_ID}" \ + -DarchetypeVersion="${VERSION}" \ + -DgroupId="${GROUP_ID}" \ + -DartifactId="${ARTIFACTID}" \ + -Dversion="${VERSION}" \ + -Dpackage="${PACKAGE}" \ + -DclosedLoopControlName="${CLOSEDLOOPCONTROLNAME}" \ + -DpolicyScope="${POLICYSCOPE}" \ + -DpolicyName="${POLICYNAME}" \ + -DpolicyVersion="${POLICYVERSION}" \ + -Dactor="${ACTOR}" \ + -DappcTopic="${APPCTOPIC}" \ + -DappcServers="${APPCSERVERS}" \ + -DappcApiKey="${APPCAPIKEY}" \ + -DappcApiSecret="${APPCAPISECRET}" \ + -DnotificationTopic="${NOTIFICATIONTOPIC}" \ + -DnotificationServers="${NOTIFICATIONSERVERS}" \ + -DnotificationApiKey="${NOTIFICATIONAPIKEY}" \ + -DnotificationApiSecret="${NOTIFICATIONAPISECRET}" \ + -DdcaeTopic="${DCAETOPIC}" \ + -DdcaeServers="${DCAESERVERS}" \ + -DdcaeApiKey="${DCAEAPIKEY}" \ + -DdcaeApiSecret="${DCAEAPISECRET}" \ + -DaaiURL="${AAIURL}" \ + -DaaiUsername="${AAIUSERNAME}" \ + -DaaiPassword="${AAIPASSWORD}" \ + -DaaiNamedQueryUUID="${AAINAMEDQUERYUUID}" \ + -DaaiPatternMatch="${AAIPATTERNMATCH}" \ + -DmsoURL="${MSOURL}" \ + -DmsoUsername="${MSOUSERNAME}" \ + -DmsoPassword="${MSOPASSWORD}" \ + -DdependenciesVersion="${DEPENDENCIES_VERSION}" + +if [ "${?}" -ne 0 ]; then + echo + echo + echo "Aborting: ${ARTIFACTID} has not been successfully generated" + exit 1 +fi + +echo + +cd "${DIR_TMP}/${ARTIFACTID}"/ + +/bin/mv src/main/config/* . + +/bin/sed -i -e "/apiKey=NULL$/d" *-controller.properties +/bin/sed -i -e "/apiSecret=NULL$/d" *-controller.properties + +/bin/sed -i -e "/apiKey.*:.*\"NULL\",/d" *-controller.rest.json +/bin/sed -i -e "/apiSecret.*:.*\"NULL\",/d" *-controller.rest.json + +echo "Closed Loop Rules from templates have been successfully created under ${DIR_TMP}/${ARTIFACTID}/" + +INSTALLREPO="Y" +read -e -i "${INSTALLREPO}" -p "Do you want to deploy ${ARTIFACTID} rules into maven repository (Y/N)? " INSTALLREPO +if [[ ${INSTALLREPO} != "Y" ]]; then + exit 1 +fi + +echo +echo "generating deployable ${ARTIFACTID} maven artifact .." + +mvn install + +if [ "${?}" -ne 0 ]; then + echo + echo + echo "Aborting: ${ARTIFACTID} deployable jar cannot be generated" + exit 1 +fi + + +echo +echo "${ARTIFACTID} has been successfully installed in user's (${USER}) local repository" +echo "Find configuration files at ${DIR_TMP}/${ARTIFACTID}/" +) diff --git a/controlloop/packages/basex/src/files/bin/create-closed-loop-demo.sh b/controlloop/packages/basex/src/files/bin/create-closed-loop-demo.sh deleted file mode 100644 index be9801294..000000000 --- a/controlloop/packages/basex/src/files/bin/create-closed-loop-demo.sh +++ /dev/null @@ -1,315 +0,0 @@ -#! /bin/bash - -### -# ============LICENSE_START======================================================= -# PDP-D APPS Base Package -# ================================================================================ -# 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========================================================= -### - -# Interactive script to generate a closed loop demo rules artifact -# for testing purposes of standalone PDP-D - -echo "Closed Loop Demo Creator for standalone PDP-D" -echo "----------------------------------------------" -echo - -GROUPID="org.onap.policy.demo.rules" -ARTIFACTID="closed-loop-demo-rules" -VERSION="1.1.0" -PACKAGE="org.onap.policy.demo.rules" -CLOSEDLOOPCONTROLNAME="CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" -POLICYSCOPE="service=test;resource=FRWL;type=configuration" -POLICYNAME="FirewallDemo" -POLICYVERSION="v0.0.1" -ACTOR="APPC" -APPCTOPIC="APPC-CL" -APPCSERVERS="vm1.mr.simpledemo.openecomp.org" -APPCAPIKEY= -APPCAPISECRET= -NOTIFICATIONTOPIC="POLICY-CL-MGT" -NOTIFICATIONSERVERS="vm1.mr.simpledemo.openecomp.org" -NOTIFICATIONAPIKEY= -NOTIFICATIONAPISECRET= -DCAETOPIC="DCAE-CL-EVENT" -DCAESERVERS="vm1.mr.simpledemo.openecomp.org" -DCAEAPIKEY= -DCAEAPISECRET= -AAIURL="http://localhost:7676/aai/test" -AAIUSERNAME="policy" -AAIPASSWORD="policy" -AAINAMEDQUERYUUID=d925ed73-8231-4d02-9545-db4e101fffff -AAIPATTERNMATCH=1 -MSOURL="http://localhost:7677/mso/test" -MSOUSERNAME="policy" -MSOPASSWORD="policy" - -read -e -i "${GROUPID}" -p "Closed Loop Rules Maven Group Id> " GROUP_ID -read -e -i "${ARTIFACTID}" -p "Closed Loop Rules Maven Coordinates Artifact Id> " ARTIFACTID -read -e -i "${VERSION}" -p "Closed Loop Rules Maven Coordinates Version> " VERSION -read -e -i "${PACKAGE}" -p "Closed Loop Rules Package> " PACKAGE -read -e -i "${CLOSEDLOOPCONTROLNAME}" -p "Closed Loop Template Control Name> " CLOSEDLOOPCONTROLNAME -read -e -i "${POLICYSCOPE}" -p "Closed Loop Policy Scope> " POLICYSCOPE -read -e -i "${POLICYNAME}" -p "Closed Loop Policy Name> " POLICYNAME -read -e -i "${POLICYVERSION}" -p "Closed Loop Policy Version> " POLICYVERSION -read -e -i "${ACTOR}" -p "Closed Loop Actor ('APPC' or 'MSO')> " ACTOR -read -e -i "${APPCTOPIC}" -p "Closed Loop APP-C Recipe Topic> " APPCTOPIC -read -e -i "${APPCSERVERS}" -p "Closed Loop APP-C UEB Servers for ${APPCTOPIC} topic> " APPCSERVERS -read -e -i "${APPCAPIKEY}" -p "Closed Loop APP-C UEB API Key for ${APPCTOPIC} topic> " APPCAPIKEY -read -e -i "${APPCAPISECRET}" -p "Closed Loop APP-C UEB API Secret for ${APPCTOPIC} topic> " APPCAPISECRET -read -e -i "${NOTIFICATIONTOPIC}" -p "Closed Loop Ruby Notification Topic> " NOTIFICATIONTOPIC -read -e -i "${NOTIFICATIONSERVERS}" -p "Closed Loop Ruby UEB Servers for ${NOTIFICATIONTOPIC} topic> " NOTIFICATIONSERVERS -read -e -i "${NOTIFICATIONAPIKEY}" -p "Closed Loop Ruby UEB API Key ${NOTIFICATIONTOPIC} topic> " NOTIFICATIONAPIKEY -read -e -i "${NOTIFICATIONAPISECRET}" -p "Closed Loop Ruby UEB API Secret ${NOTIFICATIONTOPIC} topic> " NOTIFICATIONAPISECRET -read -e -i "${DCAETOPIC}" -p "Closed Loop DCAE Topic> " DCAETOPIC -read -e -i "${DCAESERVERS}" -p "Closed Loop DCAE UEB Servers> " DCAESERVERS -read -e -i "${DCAEAPIKEY}" -p "Closed Loop DCAE UEB API Key for ${DCAETOPIC} topic> " DCAEAPIKEY -read -e -i "${DCAEAPISECRET}" -p "Closed Loop DCAE UEB API Secret for ${DCAETOPIC} topic> " DCAEAPISECRET -read -e -i "${AAIURL}" -p "Closed Loop AAI URL> " AAIURL -read -e -i "${AAIUSERNAME}" -p "Closed Loop AAI Username> " AAIUSERNAME -read -e -i "${AAIPASSWORD}" -p "Closed Loop AAI Password> " AAIPASSWORD -read -e -i "${AAINAMEDQUERYUUID}" -p "Closed Loop AAI Named Query UUID> " AAINAMEDQUERYUUID -read -e -i "${AAIPATTERNMATCH}" -p "Closed Loop AAI Pattern Match (1 for vFW, otherwise vDNS)> " AAIPATTERNMATCH -read -e -i "${MSOURL}" -p "Closed Loop MSO URL> " MSOURL -read -e -i "${MSOUSERNAME}" -p "Closed Loop MSO Username> " MSOUSERNAME -read -e -i "${MSOPASSWORD}" -p "Closed Loop MSO Password> " MSOPASSWORD - -echo -echo - -if [ -z "${GROUPID}" ]; then echo "Aborting: Closed Loop Rules Maven Group Id not provided"; exit 1; fi -if [ -z "${ARTIFACTID}" ]; then echo "Aborting: Closed Loop Rules Maven Coordinates Artifact Id not provided"; exit 1; fi -if [ -z "${VERSION}" ]; then echo "Aborting: Closed Loop Rules Maven Coordinates Version not provided"; exit 1; fi -if [ -z "${PACKAGE}" ]; then echo "Aborting: Closed Loop Rules Package not provided"; exit 1; fi -if [ -z "${CLOSEDLOOPCONTROLNAME}" ]; then echo "Aborting: Closed Loop Template Control Name not provided"; exit 1; fi -if [ -z "${POLICYSCOPE}" ]; then echo "Aborting: Closed Loop Template Policy Scope not provided"; exit 1; fi -if [ -z "${POLICYNAME}" ]; then echo "Aborting: Closed Loop Template Policy Name not provided"; exit 1; fi -if [ -z "${POLICYVERSION}" ]; then echo "Aborting: Closed Loop Template Policy Version not provided"; exit 1; fi -if [ -z "${ACTOR}" ]; then echo "Aborting: Closed Loop Template Actor not provided"; exit 1; fi -if [ -z "${APPCTOPIC}" ]; then echo "Aborting: Closed Loop Template APP-C Recipe Topic not provided"; exit 1; fi -if [ -z "${APPCSERVERS}" ]; then echo "Aborting: Closed Loop Template APP-C UEB Servers not provided"; exit 1; fi -if [ -z "${NOTIFICATIONTOPIC}" ]; then echo "Aborting: Closed Loop Template Ruby Notification Topic not provided"; exit 1; fi -if [ -z "${NOTIFICATIONSERVERS}" ]; then echo "Aborting: Closed Loop Template Ruby UEB Servers not provided"; exit 1; fi -if [ -z "${DCAETOPIC}" ]; then echo "Aborting: Closed Loop Template DCAE DMAAP Topic not provided"; exit 1; fi -if [ -z "${DCAESERVERS}" ]; then echo "Aborting: Closed Loop Template DCAE DMAAP Servers not provided"; exit 1; fi -if [ -z "${AAIURL}" ]; then echo "Aborting: Closed Loop Template AAI URL not provided"; exit 1; fi -if [ -z "${AAIUSERNAME}" ]; then echo "Aborting: Closed Loop Template AAI Username not provided"; exit 1; fi -if [ -z "${AAIPASSWORD}" ]; then echo "Aborting: Closed Loop Template AAI Password not provided"; exit 1; fi -if [ -z "${AAINAMEDQUERYUUID}" ]; then echo "Aborting: Closed Loop Template AAI Named Query UUID not provided"; exit 1; fi -if [ -z "${AAIPATTERNMATCH}" ]; then echo "Aborting: Closed Loop Template AAPI Pattern Match not provided"; exit 1; fi -if [ -z "${MSOURL}" ]; then echo "Aborting: Closed Loop Template MSO URL not provided"; exit 1; fi -if [ -z "${MSOUSERNAME}" ]; then echo "Aborting: Closed Loop Template MSO Username not provided"; exit 1; fi -if [ -z "${MSOPASSWORD}" ]; then echo "Aborting: Closed Loop Template MSO Password not provided"; exit 1; fi - -if [ -z "${DCAEAPIKEY}" ]; then DCAEAPIKEY="NULL"; fi -if [ -z "${DCAEAPISECRET}" ]; then DCAEAPISECRET="NULL"; fi -if [ -z "${APPCAPIKEY}" ]; then APPCAPIKEY="NULL"; fi -if [ -z "${APPCAPISECRET}" ]; then APPCAPISECRET="NULL"; fi -if [ -z "${NOTIFICATIONAPIKEY}" ]; then NOTIFICATIONAPIKEY="NULL"; fi -if [ -z "${NOTIFICATIONAPISECRET}" ]; then NOTIFICATIONAPISECRET="NULL"; fi - -if [[ "$VERSION" == *-SNAPSHOT ]]; then - DEPENDENCIES_VERSION="1.1.0-SNAPSHOT" -else - DEPENDENCIES_VERSION="${VERSION}" -fi - -read -e -i "${DEPENDENCIES_VERSION}" -p "Closed Loop Model/PDP-D dependent version(s) (ie: 1.0.0-SNAPSHOT, 1607.31.1-1, or [1607.31.1,)) > " DEPENDENCIES_VERSION -if [ -z "${DEPENDENCIES_VERSION}" ]; then echo "Aborting: Closed Loop Model/PDP-D dependencies not provided"; exit 1; fi - -echo "---------------------------------------------------------------------------------------" -echo "Please review the entered Closed Loop Maven Coordinates and Policy Template Parameters:" -echo -echo "Installation in Local Maven Repository" -echo -echo "Closed Loop Rules Maven Artifact Generation: Group Id: ${GROUP_ID}" -echo "Closed Loop Rules Maven Artifact Generation: Artifact Id: ${ARTIFACTID}" -echo "Closed Loop Rules Maven Artifact Generation: Version: ${VERSION}" -echo "Closed Loop Rules Maven Artifact Generation: Package: ${PACKAGE}" -echo -echo "Closed Loop Template Drools DRL Expansion: Closed Loop Control Name: ${CLOSEDLOOPCONTROLNAME}" -echo "Closed Loop Template Drools DRL Expansion: Closed Loop Policy Scope: ${POLICYSCOPE}" -echo "Closed Loop Template Drools DRL Expansion: Closed Loop Policy Name: ${POLICYNAME}" -echo "Closed Loop Template Drools DRL Expansion: Closed Loop Policy Version: ${POLICYVERSION}" -echo "Closed Loop Template Drools DRL Expansion: Closed Loop Actor: ${ACTOR}" -echo "Closed Loop Template Drools DRL Expansion: Closed Loop Recipe: ${APPC}" -echo "Closed Loop Template Drools DRL Expansion: Closed Loop Recipe Topic: ${APPCTOPIC}" -echo "Closed Loop Template Drools DRL Expansion: Closed Loop Notification Topic: ${NOTIFICATIONTOPIC}" -echo -echo "Closed Loop Controller Configuration: Rules: Group Id: ${GROUP_ID}" -echo "Closed Loop Controller Configuration: Rules: Artifact Id: ${ARTIFACTID}" -echo "Closed Loop Controller Configuration: Rules: Version: ${VERSION}" -echo -echo "Closed Loop Controller Configuration: DCAE UEB Topic: ${DCAETOPIC}" -echo "Closed Loop Controller Configuration: DCAE UEB Servers: ${DCAESERVERS}" -echo "Closed Loop Controller Configuration: DCAE UEB API Key: ${DCAEAPIKEY}" -echo "Closed Loop Controller Configuration: DCAE UEB API Secret: ${DCAEAPISECRET}" -echo -echo "Closed Loop Controller Configuration: APP-C UEB Topic: ${APPCTOPIC}" -echo "Closed Loop Controller Configuration: APP-C UEB Servers: ${APPCSERVERS}" -echo "Closed Loop Controller Configuration: APP-C UEB API Key: ${APPCAPIKEY}" -echo "Closed Loop Controller Configuration: APP-C UEB API Secret: ${APPCAPISECRET}" -echo -echo "Closed Loop Controller Configuration: NOTIFICATION Topic: ${NOTIFICATIONTOPIC}" -echo "Closed Loop Controller Configuration: NOTIFICATION UEB Servers: ${NOTIFICATIONSERVERS}" -echo "Closed Loop Controller Configuration: NOTIFICATION UEB API Key: ${NOTIFICATIONAPIKEY}" -echo "Closed Loop Controller Configuration: NOTIFICATION UEB API Secret: ${NOTIFICATIONAPISECRET}" -echo -echo "Closed Loop Controller Configuration: AAI URL: ${AAIURL}" -echo "Closed Loop Controller Configuration: AAI Username: ${AAIUSERNAME}" -echo "Closed Loop Controller Configuration: AAI Password: ${AAIPASSWORD}" -echo "Closed Loop Controller Configuration: AAI Named Query UUID: ${AAINAMEDQUERYUUID}" -echo "Closed Loop Controller Configuration: AAI Pattern Match: ${AAIPATTERNMATCH}" -echo -echo "Closed Loop Controller Configuration: MSO URL: ${MSOURL}" -echo "Closed Loop Controller Configuration: MSO Username: ${MSOUSERNAME}" -echo "Closed Loop Controller Configuration: MSO Password: ${MSOPASSWORD}" -echo -echo "Closed Loop Model/PDP-D dependent version(s): ${DEPENDENCIES_VERSION}" -echo "---------------------------------------------------------------------------------------" -echo - -HAPPY="Y" -read -e -i "${HAPPY}" -p "Are the previous parameters correct (Y/N)? " HAPPY -if [[ ${HAPPY} != "Y" ]]; then - exit 1 -fi - -echo -DIR_TMP="/tmp" -echo "The Closed Loop Source Rules will be installed at ${DIR_TMP}" -read -e -i "${DIR_TMP}" -p "Do you want to change the Source Rules install directory? " DIR_TMP - -if [ ! -w "${DIR_TMP}" ]; then - echo "Aborting. ${DIR_TMP} is not writable" - exit 1 -fi - -ARCHETYPE_GROUP_ID="org.onap.policy.drools-applications" -ARCHETYPE_ARTIFACT_ID="archetype-closedloop-demo-rules" - -if [ -d "${DIR_TMP}/${ARTIFACTID}/" ]; then - if [ "$(ls -A "${DIR_TMP}/${ARTIFACTID}"/)" ]; then - echo "${DIR_TMP} already contains a ${ARTIFACTID}/ directory, saving it to ${DIR_TMP}/${ARTIFACTID}.arch.bak/" - if [ -d "${DIR_TMP}/${ARTIFACTID}.arch.bak"/ ]; then - ( - echo "${DIR_TMP}/${ARTIFACTID}.arch.bak/ also exists, deleting it .." - cd "${DIR_TMP}"/ - rm -fr "${ARTIFACTID}.arch.bak" - ) - fi - /bin/mv --force "${DIR_TMP}/${ARTIFACTID}/" "${DIR_TMP}/${ARTIFACTID}.arch.bak" - if [ "${?}" -ne 0 ]; then - echo - echo - echo "Aborting: ${DIR_TMP}/${ARTIFACTID}/ cannot be moved" - exit 1 - fi - else - ( cd "${DIR_TMP}/" ; rmdir "${DIR_TMP}/${ARTIFACTID}/" ) - fi -fi - -CREATEARTIFACT="Y" -read -e -i "${CREATEARTIFACT}" -p "Create Maven Artifact (Y/N)? " CREATEARTIFACT -if [[ ${CREATEARTIFACT} != "Y" ]]; then - exit 1 -fi - -( -cd "${DIR_TMP}" - -mvn archetype:generate \ - -B \ - -DarchetypeCatalog=local \ - -DarchetypeGroupId="${ARCHETYPE_GROUP_ID}" \ - -DarchetypeArtifactId="${ARCHETYPE_ARTIFACT_ID}" \ - -DarchetypeVersion="${VERSION}" \ - -DgroupId="${GROUP_ID}" \ - -DartifactId="${ARTIFACTID}" \ - -Dversion="${VERSION}" \ - -Dpackage="${PACKAGE}" \ - -DclosedLoopControlName="${CLOSEDLOOPCONTROLNAME}" \ - -DpolicyScope="${POLICYSCOPE}" \ - -DpolicyName="${POLICYNAME}" \ - -DpolicyVersion="${POLICYVERSION}" \ - -Dactor="${ACTOR}" \ - -DappcTopic="${APPCTOPIC}" \ - -DappcServers="${APPCSERVERS}" \ - -DappcApiKey="${APPCAPIKEY}" \ - -DappcApiSecret="${APPCAPISECRET}" \ - -DnotificationTopic="${NOTIFICATIONTOPIC}" \ - -DnotificationServers="${NOTIFICATIONSERVERS}" \ - -DnotificationApiKey="${NOTIFICATIONAPIKEY}" \ - -DnotificationApiSecret="${NOTIFICATIONAPISECRET}" \ - -DdcaeTopic="${DCAETOPIC}" \ - -DdcaeServers="${DCAESERVERS}" \ - -DdcaeApiKey="${DCAEAPIKEY}" \ - -DdcaeApiSecret="${DCAEAPISECRET}" \ - -DaaiURL="${AAIURL}" \ - -DaaiUsername="${AAIUSERNAME}" \ - -DaaiPassword="${AAIPASSWORD}" \ - -DaaiNamedQueryUUID="${AAINAMEDQUERYUUID}" \ - -DaaiPatternMatch="${AAIPATTERNMATCH}" \ - -DmsoURL="${MSOURL}" \ - -DmsoUsername="${MSOUSERNAME}" \ - -DmsoPassword="${MSOPASSWORD}" \ - -DdependenciesVersion="${DEPENDENCIES_VERSION}" - -if [ "${?}" -ne 0 ]; then - echo - echo - echo "Aborting: ${ARTIFACTID} has not been successfully generated" - exit 1 -fi - -echo - -cd "${DIR_TMP}/${ARTIFACTID}"/ - -/bin/mv src/main/config/* . - -/bin/sed -i -e "/apiKey=NULL$/d" *-controller.properties -/bin/sed -i -e "/apiSecret=NULL$/d" *-controller.properties - -/bin/sed -i -e "/apiKey.*:.*\"NULL\",/d" *-controller.rest.json -/bin/sed -i -e "/apiSecret.*:.*\"NULL\",/d" *-controller.rest.json - -echo "Closed Loop Rules from templates have been successfully created under ${DIR_TMP}/${ARTIFACTID}/" - -INSTALLREPO="Y" -read -e -i "${INSTALLREPO}" -p "Do you want to deploy ${ARTIFACTID} rules into maven repository (Y/N)? " INSTALLREPO -if [[ ${INSTALLREPO} != "Y" ]]; then - exit 1 -fi - -echo -echo "generating deployable ${ARTIFACTID} maven artifact .." - -mvn install - -if [ "${?}" -ne 0 ]; then - echo - echo - echo "Aborting: ${ARTIFACTID} deployable jar cannot be generated" - exit 1 -fi - - -echo -echo "${ARTIFACTID} has been successfully installed in user's (${USER}) local repository" -echo "Find configuration files at ${DIR_TMP}/${ARTIFACTID}/" -) diff --git a/controlloop/packages/basex/src/files/config/vDNS-controller.properties b/controlloop/packages/basex/src/files/config/vDNS-controller.properties index 7da128f29..8f1371dc5 100644 --- a/controlloop/packages/basex/src/files/config/vDNS-controller.properties +++ b/controlloop/packages/basex/src/files/config/vDNS-controller.properties @@ -20,16 +20,16 @@ controller.name=vDNS -ueb.source.topics=DCAE-CL-EVENT,APPC-CL +ueb.source.topics=${{DCAE_TOPIC}},APPC-CL -ueb.source.topics.DCAE-CL-EVENT.servers=vm1.mr.simpledemo.openecomp.org -ueb.source.topics.DCAE-CL-EVENT.apiKey= -ueb.source.topics.DCAE-CL-EVENT.apiSecret= -ueb.source.topics.DCAE-CL-EVENT.events=org.onap.policy.controlloop.VirtualControlLoopEvent -ueb.source.topics.DCAE-CL-EVENT.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=closedLoopEventStatus\=.*,closedLoopControlName\=.*DNS.* -ueb.source.topics.DCAE-CL-EVENT.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty +ueb.source.topics.${{DCAE_TOPIC}}.servers=${{DCAE_SERVERS}} +ueb.source.topics.${{DCAE_TOPIC}}.apiKey= +ueb.source.topics.${{DCAE_TOPIC}}.apiSecret= +ueb.source.topics.${{DCAE_TOPIC}}.events=org.onap.policy.controlloop.VirtualControlLoopEvent +ueb.source.topics.${{DCAE_TOPIC}}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=closedLoopEventStatus\=.*,closedLoopControlName\=.*DNS.* +ueb.source.topics.${{DCAE_TOPIC}}.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty -ueb.source.topics.APPC-CL.servers=vm1.mr.simpledemo.openecomp.org +ueb.source.topics.APPC-CL.servers=${{DMAAP_SERVERS}} ueb.source.topics.APPC-CL.apiKey= ueb.source.topics.APPC-CL.apiSecret= ueb.source.topics.APPC-CL.events=org.onap.policy.appc.Response @@ -38,13 +38,13 @@ ueb.source.topics.APPC-CL.events.custom.gson=org.onap.policy.appc.util.Serializa ueb.sink.topics=APPC-CL,POLICY-CL-MGT -ueb.sink.topics.APPC-CL.servers=vm1.mr.simpledemo.openecomp.org +ueb.sink.topics.APPC-CL.servers=${{DMAAP_SERVERS}} ueb.sink.topics.APPC-CL.apiKey= ueb.sink.topics.APPC-CL.apiSecret= ueb.sink.topics.APPC-CL.events=org.onap.policy.appc.Request ueb.sink.topics.APPC-CL.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty -ueb.sink.topics.POLICY-CL-MGT.servers=vm1.mr.simpledemo.openecomp.org +ueb.sink.topics.POLICY-CL-MGT.servers=${{DMAAP_SERVERS}} ueb.sink.topics.POLICY-CL-MGT.apiKey= ueb.sink.topics.POLICY-CL-MGT.apiSecret= ueb.sink.topics.POLICY-CL-MGT.events=org.onap.policy.controlloop.VirtualControlLoopNotification diff --git a/controlloop/packages/basex/src/files/config/vFW-controller.properties b/controlloop/packages/basex/src/files/config/vFW-controller.properties index 8b8587504..10a0bf474 100644 --- a/controlloop/packages/basex/src/files/config/vFW-controller.properties +++ b/controlloop/packages/basex/src/files/config/vFW-controller.properties @@ -20,16 +20,16 @@ controller.name=vFW -ueb.source.topics=DCAE-CL-EVENT,APPC-CL +ueb.source.topics=${{DCAE_TOPIC}},APPC-CL -ueb.source.topics.DCAE-CL-EVENT.servers=vm1.mr.simpledemo.openecomp.org -ueb.source.topics.DCAE-CL-EVENT.apiKey= -ueb.source.topics.DCAE-CL-EVENT.apiSecret= -ueb.source.topics.DCAE-CL-EVENT.events=org.onap.policy.controlloop.VirtualControlLoopEvent -ueb.source.topics.DCAE-CL-EVENT.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=closedLoopEventStatus\=.*,closedLoopControlName\=.*FRWL.* -ueb.source.topics.DCAE-CL-EVENT.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty +ueb.source.topics.${{DCAE_TOPIC}}.servers=${{DCAE_SERVERS}} +ueb.source.topics.${{DCAE_TOPIC}}.apiKey= +ueb.source.topics.${{DCAE_TOPIC}}.apiSecret= +ueb.source.topics.${{DCAE_TOPIC}}.events=org.onap.policy.controlloop.VirtualControlLoopEvent +ueb.source.topics.${{DCAE_TOPIC}}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=closedLoopEventStatus\=.*,closedLoopControlName\=.*FRWL.* +ueb.source.topics.${{DCAE_TOPIC}}.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty -ueb.source.topics.APPC-CL.servers=vm1.mr.simpledemo.openecomp.org +ueb.source.topics.APPC-CL.servers=${{DMAAP_SERVERS}} ueb.source.topics.APPC-CL.apiKey= ueb.source.topics.APPC-CL.apiSecret= ueb.source.topics.APPC-CL.events=org.onap.policy.appc.Response @@ -38,13 +38,13 @@ ueb.source.topics.APPC-CL.events.custom.gson=org.onap.policy.appc.util.Serializa ueb.sink.topics=APPC-CL,POLICY-CL-MGT -ueb.sink.topics.APPC-CL.servers=vm1.mr.simpledemo.openecomp.org +ueb.sink.topics.APPC-CL.servers=${{DMAAP_SERVERS}} ueb.sink.topics.APPC-CL.apiKey= ueb.sink.topics.APPC-CL.apiSecret= ueb.sink.topics.APPC-CL.events=org.onap.policy.appc.Request ueb.sink.topics.APPC-CL.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty -ueb.sink.topics.POLICY-CL-MGT.servers=vm1.mr.simpledemo.openecomp.org +ueb.sink.topics.POLICY-CL-MGT.servers=${{DMAAP_SERVERS}} ueb.sink.topics.POLICY-CL-MGT.apiKey= ueb.sink.topics.POLICY-CL-MGT.apiSecret= ueb.sink.topics.POLICY-CL-MGT.events=org.onap.policy.controlloop.VirtualControlLoopNotification diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/pom.xml b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/pom.xml new file mode 100644 index 000000000..c8691c505 --- /dev/null +++ b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/pom.xml @@ -0,0 +1,57 @@ + + + + + 4.0.0 + + + org.onap.policy.drools-applications + template.demo.v1.0.0 + 1.1.0-SNAPSHOT + + + archetype-cl-legacy + maven-archetype + + archetype-cl-legacy + archetype to generate a control loop rules jar not using yaml + + + + + org.apache.maven.archetype + archetype-packaging + 3.0.1 + + + + + + + maven-archetype-plugin + 3.0.1 + + + + + + diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/META-INF/maven/archetype-metadata.xml b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 000000000..a0b5506fc --- /dev/null +++ b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + src/main/resources + + **/*.xml + + + + src/main/resources + + **/*.drl + + + + src/main/config + + **/*.properties + **/*.json + + + + diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/pom.xml b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 000000000..ee5adc80c --- /dev/null +++ b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,85 @@ + + + + + 4.0.0 + + ${groupId} + ${artifactId} + ${version} + + ${artifactId} + Control Loop Legacy Rules for 1.0.0 + + + 1.8 + 1.8 + + + + + org.onap.policy.drools-applications + events + ${dependenciesVersion} + + + org.onap.policy.drools-applications + rest + ${dependenciesVersion} + + + org.onap.policy.drools-applications + appc + ${dependenciesVersion} + + + org.onap.policy.drools-applications + aai + ${dependenciesVersion} + + + org.onap.policy.drools-applications + mso + ${dependenciesVersion} + + + org.onap.policy.drools-applications + trafficgenerator + ${dependenciesVersion} + + + org.onap.policy.drools-applications + eventmanager + ${dependenciesVersion} + + + org.onap.policy.drools-applications + guard + ${dependenciesVersion} + + + org.onap.policy.drools-applications + policy-yaml + ${dependenciesVersion} + + + diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties new file mode 100644 index 000000000..712bc2946 --- /dev/null +++ b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties @@ -0,0 +1,55 @@ +### +# ============LICENSE_START======================================================= +# archetype-closed-loop-demo-rules +# ================================================================================ +# 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========================================================= +### + +controller.name=${artifactId} + +ueb.source.topics=${dcaeTopic},${appcTopic} + +ueb.source.topics.${dcaeTopic}.servers=${dcaeServers} +ueb.source.topics.${dcaeTopic}.apiKey=${dcaeApiKey} +ueb.source.topics.${dcaeTopic}.apiSecret=${dcaeApiSecret} +ueb.source.topics.${dcaeTopic}.events=org.onap.policy.controlloop.VirtualControlLoopEvent +ueb.source.topics.${dcaeTopic}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=closedLoopEventStatus=.* +ueb.source.topics.${dcaeTopic}.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty + +ueb.source.topics.${appcTopic}.servers=${appcServers} +ueb.source.topics.${appcTopic}.apiKey=${appcApiKey} +ueb.source.topics.${appcTopic}.apiSecret=${appcApiSecret} +ueb.source.topics.${appcTopic}.events=org.onap.policy.appc.Response +ueb.source.topics.${appcTopic}.events.org.onap.policy.appc.Response.filter=CommonHeader=.*,Status=.* +ueb.source.topics.${appcTopic}.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty + +ueb.sink.topics=${appcTopic},${notificationTopic} + +ueb.sink.topics.${appcTopic}.servers=${appcServers} +ueb.sink.topics.${appcTopic}.apiKey=${appcApiKey} +ueb.sink.topics.${appcTopic}.apiSecret=${appcApiSecret} +ueb.sink.topics.${appcTopic}.events=org.onap.policy.appc.Request +ueb.sink.topics.${appcTopic}.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty + +ueb.sink.topics.${notificationTopic}.servers=${notificationServers} +ueb.sink.topics.${notificationTopic}.apiKey=${notificationApiKey} +ueb.sink.topics.${notificationTopic}.apiSecret=${notificationApiSecret} +ueb.sink.topics.${notificationTopic}.events=org.onap.policy.controlloop.VirtualControlLoopNotification +ueb.sink.topics.${notificationTopic}.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty + +rules.groupId=${groupId} +rules.artifactId=${artifactId} +rules.version=${version} diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json new file mode 100644 index 000000000..712cf7034 --- /dev/null +++ b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json @@ -0,0 +1,37 @@ +{ + "controller.name": "${artifactId}", + + "ueb.source.topics": "${dcaeTopic},${appcTopic}", + + "ueb.source.topics.${dcaeTopic}.servers": "${dcaeServers}", + "ueb.source.topics.${dcaeTopic}.apiKey": "${dcaeApiKey}", + "ueb.source.topics.${dcaeTopic}.apiSecret": "${dcaeApiSecret}", + "ueb.source.topics.${dcaeTopic}.events": "org.onap.policy.controlloop.VirtualControlLoopEvent", + "ueb.source.topics.${dcaeTopic}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter": "closedLoopEventStatus=.*", + "ueb.source.topics.${dcaeTopic}.events.custom.gson": "org.onap.policy.controlloop.util.Serialization,gsonPretty", + + "ueb.source.topics.${appcTopic}.servers": "${appcServers}", + "ueb.source.topics.${appcTopic}.apiKey": "${appcApiKey}", + "ueb.source.topics.${appcTopic}.apiSecret": "${appcApiSecret}", + "ueb.source.topics.${appcTopic}.events": "org.onap.policy.appc.Response", + "ueb.source.topics.${appcTopic}.events.org.onap.policy.appc.Response.filter": "CommonHeader=.*,Status=.*", + "ueb.source.topics.${appcTopic}.events.custom.gson": "org.onap.policy.appc.util.Serialization,gsonPretty", + + "ueb.sink.topics": "${appcTopic},${notificationTopic}", + + "ueb.sink.topics.${appcTopic}.servers": "${appcServers}", + "ueb.sink.topics.${appcTopic}.apiKey": "${appcApiKey}", + "ueb.sink.topics.${appcTopic}.apiSecret": "${appcApiSecret}", + "ueb.sink.topics.${appcTopic}.events": "org.onap.policy.appc.Request", + "ueb.sink.topics.${appcTopic}.events.custom.gson": "org.onap.policy.appc.util.Serialization,gsonPretty", + + "ueb.sink.topics.${notificationTopic}.servers": "${notificationServers}", + "ueb.sink.topics.${notificationTopic}.apiKey": "${notificationApiKey}", + "ueb.sink.topics.${notificationTopic}.apiSecret": "${notificationApiSecret}", + "ueb.sink.topics.${notificationTopic}.events": "org.onap.policy.controlloop.VirtualControlLoopNotification", + "ueb.sink.topics.${notificationTopic}.events.custom.gson": "org.onap.policy.controlloop.util.Serialization,gsonPretty", + + "rules.groupId": "${groupId}", + "rules.artifactId": "${artifactId}", + "rules.version": "${version}" +} diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/appc.accepted.json b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/appc.accepted.json new file mode 100644 index 000000000..01be66011 --- /dev/null +++ b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/appc.accepted.json @@ -0,0 +1 @@ +{"Status":{"Value":"ACCEPTED","Code":"100"},"Payload":{"pg-streams":"{\\\"pg-streams\\\": {\\\"pg-stream\\\":[{\\\"id\\\":\\\"fw_udp1\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp2\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp3\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp4\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp5\\\", \\\"is-enabled\\\":\\\"true\\\"}]}}","generic-vnf.vnf-id":"fw0001vm001fw001"},"CommonHeader":{"TimeStamp":"1493841850199","APIver":"1.01","RequestID":"664be3d2-6c12-4f4b-a3e7-c349acced200","SubrequestID":null,"OriginatorID":null}} diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/appc.success.json b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/appc.success.json new file mode 100644 index 000000000..b9ef41f50 --- /dev/null +++ b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/appc.success.json @@ -0,0 +1 @@ +{"Status":{"Value":"SUCCESS","Code":"400"},"Payload":{"pg-streams":"{\\\"pg-streams\\\": {\\\"pg-stream\\\":[{\\\"id\\\":\\\"fw_udp1\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp2\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp3\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp4\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp5\\\", \\\"is-enabled\\\":\\\"true\\\"}]}}","generic-vnf.vnf-id":"fw0001vm001fw001"},"CommonHeader":{"TimeStamp":"1493841850199","APIver":"1.01","RequestID":"664be3d2-6c12-4f4b-a3e7-c349acced200","SubrequestID":null,"OriginatorID":null}} diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/dcae.onset.json b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/dcae.onset.json new file mode 100644 index 000000000..4553faa13 --- /dev/null +++ b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/config/dcae.onset.json @@ -0,0 +1,14 @@ +{ + "closedLoopControlName": "${closedLoopControlName}", + "closedLoopAlarmStart": 1463679805324, + "closedLoopEventClient": "microservice.stringmatcher", + "closedLoopEventStatus": "ONSET", + "requestID": "664be3d2-6c12-4f4b-a3e7-c349acced200", + "target_type": "VF", + "target": "generic-vnf.vnf-id", + "AAI": { + "generic-vnf.vnf-id": "fw0001vm001fw001" + }, + "from": "DCAE", + "version": "1.0.2" +} diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/resources/ControlLoopDemo__closedLoopControlName__.drl b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/resources/ControlLoopDemo__closedLoopControlName__.drl new file mode 100644 index 000000000..ff5d82e5e --- /dev/null +++ b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/resources/ControlLoopDemo__closedLoopControlName__.drl @@ -0,0 +1,1140 @@ +/*- + * ============LICENSE_START======================================================= + * archetype-closed-loop-demo-rules + * ================================================================================ + * 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.controlloop; + +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +import java.util.HashMap; +import java.util.UUID; + +import org.onap.policy.controlloop.VirtualControlLoopEvent; +import org.onap.policy.controlloop.ControlLoopEventStatus; +import org.onap.policy.controlloop.VirtualControlLoopNotification; +import org.onap.policy.controlloop.ControlLoopNotificationType; +import org.onap.policy.controlloop.ControlLoopOperation; +import org.onap.policy.controlloop.ControlLoopOperationWrapper; +import org.onap.policy.controlloop.ControlLoopException; + +import org.onap.policy.aai.AAINQF199.AAINQF199CloudRegion; +import org.onap.policy.aai.AAINQF199.AAINQF199ExtraProperties; +import org.onap.policy.aai.AAINQF199.AAINQF199ExtraProperty; +import org.onap.policy.aai.AAINQF199.AAINQF199GenericVNF; +import org.onap.policy.aai.AAINQF199.AAINQF199InstanceFilters; +import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItem; +import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItems; +import org.onap.policy.aai.AAINQF199.AAINQF199Manager; +import org.onap.policy.aai.AAINQF199.AAINQF199NamedQuery; +import org.onap.policy.aai.AAINQF199.AAINQF199QueryParameters; +import org.onap.policy.aai.AAINQF199.AAINQF199Request; +import org.onap.policy.aai.AAINQF199.AAINQF199RequestWrapper; +import org.onap.policy.aai.AAINQF199.AAINQF199Response; +import org.onap.policy.aai.AAINQF199.AAINQF199ResponseWrapper; +import org.onap.policy.aai.AAINQF199.AAINQF199ServiceInstance; +import org.onap.policy.aai.AAINQF199.AAINQF199Tenant; +import org.onap.policy.aai.AAINQF199.AAINQF199VfModule; +import org.onap.policy.aai.AAINQF199.AAINQF199VServer; +import org.onap.policy.aai.util.Serialization; + +import org.onap.policy.appc.CommonHeader; +import org.onap.policy.appc.Request; +import org.onap.policy.appc.Response; +import org.onap.policy.appc.ResponseCode; +import org.onap.policy.appc.ResponseStatus; +import org.onap.policy.appc.ResponseValue; + +import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager; +import org.onap.policy.vnf.trafficgenerator.PGRequest; +import org.onap.policy.vnf.trafficgenerator.PGStream; +import org.onap.policy.vnf.trafficgenerator.PGStreams; + +import org.onap.policy.mso.MSOManager; +import org.onap.policy.mso.MSORequest; +import org.onap.policy.mso.MSORequestStatus; +import org.onap.policy.mso.MSORequestDetails; +import org.onap.policy.mso.MSOModelInfo; +import org.onap.policy.mso.MSOCloudConfiguration; +import org.onap.policy.mso.MSORequestInfo; +import org.onap.policy.mso.MSORequestParameters; +import org.onap.policy.mso.MSORelatedInstanceListElement; +import org.onap.policy.mso.MSORelatedInstance; +import org.onap.policy.mso.MSOResponse; + +import org.onap.policy.drools.system.PolicyEngine; + +// +// These parameters are required to build the runtime policy +// +declare Params + closedLoopControlName : String + actor : String + aaiURL : String + aaiUsername : String + aaiPassword : String + msoURL : String + msoUsername : String + msoPassword : String + aaiNamedQueryUUID : String + aaiPatternMatch : int + notificationTopic : String + appcTopic : String +end + +/* +* +* Called once and only once to insert the parameters into working memory for this Closed Loop policy. +* NOTE: If this file is to be used as a template to be used with the policy BRMS GW, please comment out this line +* as the BRMS_GW already generates a SETUP rule +* +*/ +rule "${policyName}.SETUP" + when + then + System.out.println("rule SETUP is triggered."); + Params params = new Params(); + params.setClosedLoopControlName("${closedLoopControlName}"); + params.setActor("${actor}"); + params.setAaiURL("${aaiURL}"); + params.setAaiUsername("${aaiUsername}"); + params.setAaiPassword("${aaiPassword}"); + params.setMsoURL("${msoURL}"); + params.setMsoUsername("${msoUsername}"); + params.setMsoPassword("${msoPassword}"); + params.setAaiNamedQueryUUID("${aaiNamedQueryUUID}"); + params.setAaiPatternMatch(${aaiPatternMatch}); + params.setNotificationTopic("${notificationTopic}"); + params.setAppcTopic("${appcTopic}"); + // + // This stays in memory as long as the rule is alive and running + // + insert(params); +end + + +/* +* +* This rule responds to DCAE Events +* +*/ +rule "${policyName}.EVENT" + when + $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) + $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) + not ( ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )) + then + System.out.println("rule EVENT is triggered."); + try { + // + // Check the requestID in the event to make sure it is not null before we create the EventManager. + // The EventManager will do extra syntax checking as well check if the closed loop is disabled/ + // + if ($event.requestID == null) { + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.notification = ControlLoopNotificationType.REJECTED; + notification.from = "policy"; + notification.message = "Missing requestID from DCAE event"; + notification.policyName = drools.getRule().getName(); + notification.policyScope = "${policyScope}"; + notification.policyVersion = "${policyVersion}"; + // + // Let interested parties know + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Can't deliver notification: " + notification); + } + // + // Retract it from memory + // + retract($event); + System.out.println("Event with requestID=null has been retracted."); + } else { + // + // Create an EventManager + // + ControlLoopEventManager manager = new ControlLoopEventManager($params.getClosedLoopControlName(), $event.requestID); + // + // Determine if EventManager can actively process the event (i.e. syntax) + // + VirtualControlLoopNotification notification = manager.activate($event); + notification.from = "policy"; + notification.policyName = drools.getRule().getName(); + notification.policyScope = "${policyScope}"; + notification.policyVersion = "${policyVersion}"; + // + // Are we actively pursuing this event? + // + if (notification.notification == ControlLoopNotificationType.ACTIVE) { + // + // Insert Event Manager into memory, this will now kick off processing. + // + insert(manager); + // + // Let interested parties know + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Can't deliver notification: " + notification); + } + } else { + // + // Let interested parties know + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Can't deliver notification: " + notification); + } + // + // Retract it from memory + // + retract($event); + } + // + // Now that the manager is inserted into Drools working memory, we'll wait for + // another rule to fire in order to continue processing. This way we can also + // then screen for additional ONSET and ABATED events for this same RequestIDs + // and for different RequestIDs but with the same closedLoopControlName and target. + // + } + // + } catch (Exception e) { + e.printStackTrace(); + 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}"; + // + // + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e1) { + System.out.println("Can't deliver notification: " + notification); + e1.printStackTrace(); + } + // + // Retract the event + // + retract($event); + } +end + +/* +* +* This rule happens when we got a valid ONSET, closed loop is enabled and an Event Manager +* is created. We can start the operations for this closed loop. +* +*/ +rule "${policyName}.EVENT.MANAGER" + when + $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) + $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, controlLoopResult == null) + then + System.out.println("rule EVENT.MANAGER is triggered."); + // + // Check which event this is. + // + ControlLoopEventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event); + // + // We only want the initial ONSET event in memory, + // all the other events need to be retracted to support + // cleanup and avoid the other rules being fired for this event. + // + if (eventStatus != ControlLoopEventManager.NEW_EVENT_STATUS.FIRST_ONSET) { + System.out.println("Retracting "+eventStatus+" Event."); + retract($event); + return; + } + // + // Now the event in memory is first onset event + // + try { + // + // Pull the known AAI field from the Event + // + // generic-vnf is needed for vFirewall case + // vserver-name is needed for vLoadBalancer case + // + String genericVNF = $event.AAI.get("generic-vnf.vnf-id"); + String vserver = $event.AAI.get("vserver.vserver-name"); + // + // Check if we are implementing a simple pattern match. + // + if ($params.getAaiPatternMatch() == 1) { + // + // Yes + // + //Basic naming characteristics: + //VF Name (9 char)+VM name (13 char total)+VFC (19 char total) + //Example: + //VF Name (9 characters): cscf0001v + //VM Name(13 characters): cscf0001vm001 + //VFC name(19 characters): cscf0001vm001cfg001 + // + // zdfw1fwl01fwl02 or zdfw1fwl01fwl01 + // replaced with + // zdfw1fwl01pgn02 or zdfw1fwl01pgn01 + // + int index = genericVNF.lastIndexOf("fwl"); + if (index == -1) { + System.err.println("The generic-vnf.vnf-id from DCAE Event is not valid."); + } else { + genericVNF = genericVNF.substring(0, index) + "pgn" + genericVNF.substring(index+"fwl".length()); + } + // + // Construct an APPC request + // + ControlLoopOperation operation = new ControlLoopOperation(); + operation.actor = $params.getActor(); + operation.operation = "ModifyConfig"; + operation.target = $event.target; + // + // Create operationWrapper + // + ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation); + // + // insert operationWrapper into memory + // + insert(operationWrapper); + // + Request request = new Request(); + request.CommonHeader = new CommonHeader(); + request.CommonHeader.RequestID = $event.requestID; + request.Action = operation.operation; + request.Payload = new HashMap(); + // + // Fill in the payload + // + request.Payload.put("generic-vnf.vnf-id", genericVNF); + // + PGRequest pgRequest = new PGRequest(); + pgRequest.pgStreams = new PGStreams(); + + PGStream pgStream; + for(int i = 0; i < 5; i++){ + pgStream = new PGStream(); + pgStream.streamId = "fw_udp"+(i+1); + pgStream.isEnabled = "true"; + pgRequest.pgStreams.pgStream.add(pgStream); + } + request.Payload.put("pg-streams", pgRequest.pgStreams); + + if (request != null) { + // + // Insert request into memory + // + insert(request); + // + // Tell interested parties we are performing this Operation + // + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.notification = ControlLoopNotificationType.OPERATION; + // message and history ?? + notification.from = "policy"; + notification.policyName = drools.getRule().getName(); + notification.policyScope = "${policyScope}"; + notification.policyVersion = "${policyVersion}"; + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + // + // Now send the operation request + // + if (request instanceof Request) { + try { + System.out.println("APPC request sent:"); + System.out.println(Serialization.gsonPretty.toJson(request)); + PolicyEngine.manager.deliver($params.getAppcTopic(), request); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Can't deliver request: " + request); + } + } + } else { + // + // what happens if it is null + // + } + // + } else { + // + // create AAI named-query request with UUID started with "F199" + // + AAINQF199Request aainqf199request = new AAINQF199Request(); + AAINQF199QueryParameters aainqf199queryparam = new AAINQF199QueryParameters(); + AAINQF199NamedQuery aainqf199namedquery = new AAINQF199NamedQuery(); + AAINQF199InstanceFilters aainqf199instancefilter = new AAINQF199InstanceFilters(); + // + // queryParameters + // + aainqf199namedquery.namedQueryUUID = UUID.fromString($params.getAaiNamedQueryUUID()); + aainqf199queryparam.namedQuery = aainqf199namedquery; + aainqf199request.queryParameters = aainqf199queryparam; + // + // instanceFilters + // + Map aainqf199instancefiltermap = new HashMap(); + Map aainqf199instancefiltermapitem = new HashMap(); + aainqf199instancefiltermapitem.put("vserver-name", vserver); + aainqf199instancefiltermap.put("vserver", aainqf199instancefiltermapitem); + aainqf199instancefilter.instanceFilter.add(aainqf199instancefiltermap); + aainqf199request.instanceFilters = aainqf199instancefilter; + // + // print aainqf199request for debug + // + System.out.println("AAI Request sent:"); + System.out.println(Serialization.gsonPretty.toJson(aainqf199request)); + // + // Create AAINQF199RequestWrapper + // + AAINQF199RequestWrapper aainqf199RequestWrapper = new AAINQF199RequestWrapper($event.requestID, aainqf199request); + // + // insert aainqf199request into memory + // + insert(aainqf199RequestWrapper); + } + // + } catch (Exception e) { + e.printStackTrace(); + } +end + +/* +* +* This rule happens when we got a valid ONSET, closed loop is enabled, an Event Manager +* is created, AAI Manager and AAI Request are ready in memory. We can start sending query to AAI and then wait for response. +* +*/ +rule "${policyName}.EVENT.MANAGER.AAINQF199REQUEST" + when + $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) + $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ) + $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID) + then + System.out.println("rule EVENT.MANAGER.AAINQF199REQUEST is triggered."); + // + // send the request + // + AAINQF199Response aainqf199response = AAINQF199Manager.postQuery($params.getAaiURL(), $params.getAaiUsername(), $params.getAaiPassword(), + $aainqf199RequestWrapper.aainqf199request, $event.requestID); + + // + // Check AAI response + // + if (aainqf199response == null) { + System.err.println("Failed to get AAI response"); + // + // Fail and retract everything + // + retract($event); + retract($manager); + retract($aainqf199RequestWrapper); + } else { + // + // Create AAINQF199ResponseWrapper + // + AAINQF199ResponseWrapper aainqf199ResponseWrapper = new AAINQF199ResponseWrapper($event.requestID, aainqf199response); + // + // insert aainqf199ResponseWrapper to memeory + // + insert(aainqf199ResponseWrapper); + } +end + +/* +* +* This rule happens when we got a valid AAI response. We can start sending request to APPC or MSO now. +* +*/ +rule "${policyName}.EVENT.MANAGER.AAINQF199RESPONSE" + when + $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) + $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ) + $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID) + $aainqf199ResponseWrapper : AAINQF199ResponseWrapper(requestID == $event.requestID) + then + System.out.println("rule EVENT.MANAGER.AAINQF199RESPONSE is triggered."); + // + // Extract related fields out of AAINQF199RESPONSE + // + String vnfItemVnfId, vnfItemVnfType, vnfItemPersonaModelId, vnfItemPersonaModelVersion, vnfItemModelName, + vnfItemModelVersion, vnfItemModelNameVersionId, serviceItemServiceInstanceId, serviceItemPersonaModelId, + serviceItemModelName, serviceItemModelType, serviceItemModelVersion, serviceItemModelNameVersionId, + vfModuleItemVfModuleName, vfModuleItemPersonaModelId, vfModuleItemPersonaModelVersion, vfModuleItemModelName, + vfModuleItemModelNameVersionId, tenantItemTenantId, cloudRegionItemCloudRegionId; + try { + // + // vnfItem + // + vnfItemVnfId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfID; + vnfItemVnfType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfType; + vnfItemVnfType = vnfItemVnfType.substring(vnfItemVnfType.lastIndexOf("/")+1); + vnfItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelId; + vnfItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelVersion; + vnfItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue; + vnfItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(2).propertyValue; + vnfItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue; + // + // serviceItem + // + serviceItemServiceInstanceId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.serviceInstanceID; + serviceItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelId; + serviceItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue; + serviceItemModelType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(1).propertyValue; + serviceItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelVersion; + serviceItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue; + // + // Find the index for base vf module and non-base vf module + // + int baseIndex = -1; + int nonBaseIndex = -1; + List inventoryItems = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems; + for (AAINQF199InventoryResponseItem m : inventoryItems) { + if (m.vfModule != null && m.vfModule.isBaseVfModule == true) { + baseIndex = inventoryItems.indexOf(m); + } else if (m.vfModule != null && m.vfModule.isBaseVfModule == false && m.vfModule.orchestrationStatus == null) { + nonBaseIndex = inventoryItems.indexOf(m); + } + // + if (baseIndex != -1 && nonBaseIndex != -1) { + break; + } + } + // + // Report the error if either base vf module or non-base vf module is not found + // + if (baseIndex == -1 || nonBaseIndex == -1) { + System.err.println("Either base or non-base vf module is not found from AAI response."); + retract($aainqf199RequestWrapper); + retract($aainqf199ResponseWrapper); + retract($manager); + retract($event); + return; + } + // + // This comes from the base module + // + vfModuleItemVfModuleName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(baseIndex).vfModule.vfModuleName; + vfModuleItemVfModuleName = vfModuleItemVfModuleName.replace("Vfmodule", "vDNS"); + // + // vfModuleItem - NOT the base module + // + vfModuleItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelId; + vfModuleItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelVersion; + vfModuleItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(0).propertyValue; + vfModuleItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(4).propertyValue; + // + // tenantItem + // + tenantItemTenantId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).tenant.tenantId; + // + // cloudRegionItem + // + cloudRegionItemCloudRegionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).items.inventoryResponseItems.get(0).cloudRegion.cloudRegionId; + // + } catch (Exception e) { + e.printStackTrace(); + 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}"; + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e1) { + System.out.println("Can't deliver notification: " + notification); + e1.printStackTrace(); + } + // + notification.notification = ControlLoopNotificationType.FINAL_FAILURE; + notification.message = "Invalid named-query response from AAI"; + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e1) { + System.out.println("Can't deliver notification: " + notification); + e1.printStackTrace(); + } + // + // Retract everything + // + retract($aainqf199RequestWrapper); + retract($aainqf199ResponseWrapper); + retract($manager); + retract($event); + return; + } + // + // Extracted fields should not be null + // + if ((vnfItemVnfId == null) || (vnfItemVnfType == null) || + (vnfItemPersonaModelId == null) || (vnfItemModelName == null) || + (vnfItemModelVersion == null) || (vnfItemModelNameVersionId == null) || + (serviceItemServiceInstanceId == null) || (serviceItemModelName == null) || + (serviceItemModelType == null) || (serviceItemModelVersion == null) || + (serviceItemModelNameVersionId == null) || (vfModuleItemVfModuleName == null) || + (vfModuleItemPersonaModelId == null) || (vfModuleItemPersonaModelVersion == null) || + (vfModuleItemModelName == null) || (vfModuleItemModelNameVersionId == null) || + (tenantItemTenantId == null) || (cloudRegionItemCloudRegionId == null)) { + // + System.err.println("some fields are missing from AAI response."); + // + // Fail and retract everything + // + retract($aainqf199RequestWrapper); + retract($aainqf199ResponseWrapper); + retract($manager); + retract($event); + return; + } + // + // We don't need them any more + // + retract($aainqf199ResponseWrapper); + retract($aainqf199RequestWrapper); + // + // check the actor of this closed loop + // + switch ($params.getActor()) { + case "APPC": + { + // + // Construct an APPC request + // + ControlLoopOperation operation = new ControlLoopOperation(); + operation.actor = $params.getActor(); + operation.operation = "ModifyConfig"; + operation.target = $event.target; + // + // Create operationWrapper + // + ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation); + // + // insert operationWrapper into memory + // + insert(operationWrapper); + // + Request request = new Request(); + request.CommonHeader = new CommonHeader(); + request.CommonHeader.RequestID = $event.requestID; + request.Action = operation.operation; + request.Payload = new HashMap(); + // + // Fill in the payload + // Hardcode genericVNF for now since AAI has not been ready for vFirewall demo case + // + String genericVNF = "zdfw1fwl01pgn02"; + request.Payload.put("generic-vnf.vnf-id", genericVNF); + // + PGRequest pgRequest = new PGRequest(); + pgRequest.pgStreams = new PGStreams(); + + PGStream pgStream; + for(int i = 0; i < 5; i++){ + pgStream = new PGStream(); + pgStream.streamId = "fw_udp"+(i+1); + pgStream.isEnabled = "true"; + pgRequest.pgStreams.pgStream.add(pgStream); + } + request.Payload.put("pg-streams", pgRequest.pgStreams); + + if (request != null) { + // + // Insert request into memory + // + insert(request); + // + // Tell interested parties we are performing this Operation + // + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.notification = ControlLoopNotificationType.OPERATION; + // message and history ?? + notification.from = "policy"; + notification.policyName = drools.getRule().getName(); + notification.policyScope = "${policyScope}"; + notification.policyVersion = "${policyVersion}"; + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + // + // Now send the operation request + // + if (request instanceof Request) { + try { + System.out.println("APPC request sent:"); + System.out.println(Serialization.gsonPretty.toJson(request)); + PolicyEngine.manager.deliver($params.getAppcTopic(), request); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Can't deliver request: " + request); + } + } + } else { + // + // what happens if it is null + // + } + } + break; + case "MSO": + { + // + // Construct an operation + // + ControlLoopOperation operation = new ControlLoopOperation(); + operation.actor = $params.getActor(); + operation.operation = "createModuleInstance"; + operation.target = $event.target; + // + // Create operationWrapper + // + ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation); + // + // Construct an MSO request + // + MSORequest request = new MSORequest(); + request.requestDetails = new MSORequestDetails(); + request.requestDetails.modelInfo = new MSOModelInfo(); + request.requestDetails.cloudConfiguration = new MSOCloudConfiguration(); + request.requestDetails.requestInfo = new MSORequestInfo(); + request.requestDetails.requestParameters = new MSORequestParameters(); + request.requestDetails.requestParameters.userParams = null; + // + // cloudConfiguration + // + request.requestDetails.cloudConfiguration.lcpCloudRegionId = cloudRegionItemCloudRegionId; + request.requestDetails.cloudConfiguration.tenantId = tenantItemTenantId; + // + // modelInfo + // + request.requestDetails.modelInfo.modelType = "vfModule"; + request.requestDetails.modelInfo.modelInvariantId = vfModuleItemPersonaModelId; + request.requestDetails.modelInfo.modelNameVersionId = vfModuleItemModelNameVersionId; + request.requestDetails.modelInfo.modelName = vfModuleItemModelName; + request.requestDetails.modelInfo.modelVersion = vfModuleItemPersonaModelVersion; + // + // requestInfo + // + request.requestDetails.requestInfo.instanceName = vfModuleItemVfModuleName; + request.requestDetails.requestInfo.source = "POLICY"; + request.requestDetails.requestInfo.suppressRollback = false; + // + // relatedInstanceList + // + MSORelatedInstanceListElement relatedInstanceListElement1 = new MSORelatedInstanceListElement(); + MSORelatedInstanceListElement relatedInstanceListElement2 = new MSORelatedInstanceListElement(); + relatedInstanceListElement1.relatedInstance = new MSORelatedInstance(); + relatedInstanceListElement2.relatedInstance = new MSORelatedInstance(); + // + relatedInstanceListElement1.relatedInstance.instanceId = serviceItemServiceInstanceId; + relatedInstanceListElement1.relatedInstance.modelInfo = new MSOModelInfo(); + relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service"; + relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = serviceItemPersonaModelId; + relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = serviceItemModelNameVersionId; + relatedInstanceListElement1.relatedInstance.modelInfo.modelName = serviceItemModelName; + relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = serviceItemModelVersion; + // + relatedInstanceListElement2.relatedInstance.instanceId = vnfItemVnfId; + relatedInstanceListElement2.relatedInstance.modelInfo = new MSOModelInfo(); + relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = vnfItemPersonaModelId; + relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = vnfItemModelNameVersionId; + relatedInstanceListElement2.relatedInstance.modelInfo.modelName = vnfItemModelName; + relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = vnfItemModelVersion; + relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = vnfItemVnfType; + // + request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1); + request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2); + // + // print MSO request for debug + // + System.out.println("MSO request sent:"); + System.out.println(Serialization.gsonPretty.toJson(request)); + // + // + // + if (request != null) { + // + // Tell interested parties we are performing this Operation + // + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.notification = ControlLoopNotificationType.OPERATION; + notification.from = "policy"; + notification.policyName = drools.getRule().getName(); + notification.policyScope = "${policyScope}"; + notification.policyVersion = "${policyVersion}"; + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + // + // Concatenate serviceItemServiceInstanceId and vnfItemVnfId to msoURL + // + String MSOUrl = $params.getMsoURL() + "/serviceInstances/v2/" + serviceItemServiceInstanceId + "/vnfs/" + vnfItemVnfId + "/vfModules"; + // + // Call MSO + // + MSOResponse response = MSOManager.createModuleInstance(MSOUrl, $params.getMsoURL(), $params.getMsoUsername(), $params.getMsoPassword(), request); + + + if (response != null) { + // + // Assign requestId + // + request.requestId = $event.requestID.toString(); + response.request.requestId = $event.requestID.toString(); + // + // Insert facts + // + insert(operationWrapper); + insert(request); + insert(response); + } else { + // + // MSO request not even accepted + // + notification.message = operationWrapper.operation.toMessage(); + operationWrapper.operation.message = operationWrapper.operation.toMessage(); + operationWrapper.operation.outcome = "FAILURE_EXCEPTION"; + $manager.setControlLoopResult("FAILURE_EXCEPTION"); + notification.history.add(operationWrapper.operation); + notification.notification = ControlLoopNotificationType.OPERATION_FAILURE; + // + // Let interested parties know + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + notification.notification = ControlLoopNotificationType.FINAL_FAILURE; + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + // + // Retract everything + // + retract($event); + retract($manager); + } + } else { + System.err.println("constructed MSO request is invalid."); + } + } + break; + } +end + +/* +* +* This rule responds to APPC Response Events +* +*/ +rule "${policyName}.APPC.RESPONSE" + when + $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) + $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ) + $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID ) + $request : Request( getCommonHeader().RequestID == $event.requestID ) + $response : Response( getCommonHeader().RequestID == $event.requestID ) + then + System.out.println("rule APPC.RESPONSE is triggered."); + if ($response.Status == null) { + $operationWrapper.operation.outcome = "FAILURE_EXCEPTION"; + $manager.setControlLoopResult("FAILURE_EXCEPTION"); + } + // + // Get the Response Code + // + ResponseCode code = ResponseCode.toResponseCode($response.Status.Code); + if (code == null) { + $operationWrapper.operation.outcome = "FAILURE_EXCEPTION"; + $manager.setControlLoopResult("FAILURE_EXCEPTION"); + } + // + // Construct notification + // + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.from = "policy"; + notification.policyName = drools.getRule().getName(); + notification.policyScope = "${policyScope}"; + notification.policyVersion = "${policyVersion}"; + notification.message = $operationWrapper.operation.toMessage(); + $operationWrapper.operation.message = $operationWrapper.operation.toMessage(); + // + // Ok, let's figure out what APP-C's response is + // + switch (code) { + case ACCEPT: + $operationWrapper.operation.outcome = "PROCESSING"; + break; + case ERROR: + case REJECT: + $operationWrapper.operation.outcome = "FAILURE_EXCEPTION"; + $manager.setControlLoopResult("FAILURE_EXCEPTION"); + break; + case SUCCESS: + $operationWrapper.operation.outcome = "SUCCESS"; + $manager.setControlLoopResult("SUCCESS"); + break; + case FAILURE: + $operationWrapper.operation.outcome = "FAILURE"; + $manager.setControlLoopResult("FAILURE"); + break; + } + if ($operationWrapper.operation.outcome.equals("SUCCESS")) { + notification.history.add($operationWrapper.operation); + notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS; + // + // Let interested parties know + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + notification.notification = ControlLoopNotificationType.FINAL_SUCCESS; + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + + // + // We are going to retract these objects from memory + // + System.out.println("Retracting everything"); + retract($operationWrapper); + retract($request); + retract($response); + retract($event); + retract($manager); + } else if ($operationWrapper.operation.outcome.equals("PROCESSING")) { + retract($response); + } else { + notification.history.add($operationWrapper.operation); + notification.notification = ControlLoopNotificationType.OPERATION_FAILURE; + // + // Let interested parties know + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + notification.notification = ControlLoopNotificationType.FINAL_FAILURE; + // + // Let interested parties know + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + // + // We are going to retract these objects from memory + // + System.out.println("Retracting everything"); + retract($operationWrapper); + retract($request); + retract($response); + retract($event); + retract($manager); + } + +end + +/* +* +* This rule is used to clean up APPC response +* +*/ +rule "${policyName}.APPC.RESPONSE.CLEANUP" + when + $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) + $response : Response($id : getCommonHeader().RequestID ) + not ( VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), requestID == $id, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) ) + then + System.out.println("rule APPC.RESPONSE.CLEANUP is triggered."); + retract($response); +end + +/* +* +* This rule responds to MSO Response Events +* +*/ +rule "${policyName}.MSO.RESPONSE" + when + $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) + $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ) + $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID ) + $request : MSORequest( requestId == $event.requestID.toString() ) + $response : MSOResponse( request.requestId == $event.requestID.toString() ) + then + System.out.println("rule MSO.RESPONSE is triggered."); + // + // Construct notification + // + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.from = "policy"; + notification.policyName = drools.getRule().getName(); + notification.policyScope = "${policyScope}"; + notification.policyVersion = "${policyVersion}"; + notification.message = $operationWrapper.operation.toMessage(); + $operationWrapper.operation.message = $operationWrapper.operation.toMessage(); + // + // The operation can either be succeeded or failed + // + if($response.request.requestStatus.requestState.equals("COMPLETE")) { + $operationWrapper.operation.outcome = "SUCCESS"; + $manager.setControlLoopResult("SUCCESS"); + notification.history.add($operationWrapper.operation); + notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS; + // + // Let interested parties know + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + notification.notification = ControlLoopNotificationType.FINAL_SUCCESS; + // + // Let interested parties know + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + // + // We are going to retract these objects from memory + // + System.out.println("Retracting everything"); + retract($operationWrapper); + retract($request); + retract($response); + retract($event); + retract($manager); + } else { + $operationWrapper.operation.outcome = "FAILURE"; + $manager.setControlLoopResult("FAILURE"); + notification.history.add($operationWrapper.operation); + notification.notification = ControlLoopNotificationType.OPERATION_FAILURE; + // + // Let interested parties know + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + notification.notification = ControlLoopNotificationType.FINAL_FAILURE; + // + // Let interested parties know + // + try { + System.out.println(Serialization.gsonPretty.toJson(notification)); + PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); + } catch (Exception e) { + System.out.println("Can't deliver notification: " + notification); + e.printStackTrace(); + } + // + // We are going to retract these objects from memory + // + System.out.println("Retracting everything"); + retract($operationWrapper); + retract($request); + retract($response); + retract($event); + retract($manager); + } +end + +/* + * Sample Queries for illustration with and without arguments + * The results of the query can be introspected (and retracted if desired) + * through REST API. + */ +query "${policyName}.QUERY.EVENT.ONSET" + event : VirtualControlLoopEvent( closedLoopEventStatus == ControlLoopEventStatus.ONSET ) +end + +query "${policyName}.QUERY.MANAGER.RNA" (String aRequestId, Integer numOnsetsLowerBound, Boolean aActivated) + manager : ControlLoopEventManager( closedLoopControlName == "${closedLoopControlName}", + requestID.toString() == aRequestId, + numOnsets > numOnsetsLowerBound, + activated == aActivated ) +end diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/resources/META-INF/kmodule.xml b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/resources/META-INF/kmodule.xml new file mode 100644 index 000000000..8116d880a --- /dev/null +++ b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/main/resources/archetype-resources/src/main/resources/META-INF/kmodule.xml @@ -0,0 +1,29 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/test/resources/projects/basic/archetype.properties b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 000000000..0b077b052 --- /dev/null +++ b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,50 @@ +### +# ============LICENSE_START======================================================= +# archetype-closed-loop-demo-rules +# ================================================================================ +# 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========================================================= +### + +groupId=org.onap.policy.demo.drools +artifactId=closedloop-demo-rules +version=1.0.0-SNAPSHOT +package=org.onap.policy.demo.drools +closedLoopControlName=CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8 +policyScope=service=test;resource=FRWL;type=configuration +policyName=FirewallDemo +policyVersion=v1.0 +actor=APPC +appcTopic=APPC-CL +appcApiKey=NO-API-KEY +appcApiSecret=NO-API-SECRET +appcServers=server1,server2,server3 +notificationTopic=POLICY-CL-MGT +notificationApiKey=NO-API-KEY +notificationApiSecret=NO-API-SECRET +notificationServers=server1,server2,server3 +dcaeTopic=DCAE-CL-EVENT +dcaeServers=server1,server2,server3 +dcaeApiKey=NO-API-KEY +dcaeApiSecret=NO-API-SECRET +dependenciesVersion=1.0.0-SNAPSHOT +aaiURL=http://localhost:8080/TestREST/Test +aaiUsername=policy +aaiPassword=policy +aaiNamedQueryUUID=d925ed73-8231-4d02-9545-db4e101fffff +aaiPatternMatch=false +msoURL=http://localhost:8080/TestREST/Test +msoUsername=policy +msoPassword=policy diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/test/resources/projects/basic/goal.txt b/controlloop/templates/template.demo.v1.0.0/archetype-cl-legacy/src/test/resources/projects/basic/goal.txt new file mode 100644 index 000000000..e69de29bb diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/pom.xml b/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/pom.xml deleted file mode 100644 index 6eae97484..000000000 --- a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/pom.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - 4.0.0 - - - org.onap.policy.drools-applications - template.demo.v1.0.0 - 1.1.0-SNAPSHOT - - - archetype-closedloop-demo-rules - maven-archetype - - archetype-closed-loop-demo-rules - archetype to generate a closed loop demo rules jar - - - - - org.apache.maven.archetype - archetype-packaging - 3.0.1 - - - - - - - maven-archetype-plugin - 3.0.1 - - - - - - diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/META-INF/maven/archetype-metadata.xml b/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/META-INF/maven/archetype-metadata.xml deleted file mode 100644 index a0b5506fc..000000000 --- a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/META-INF/maven/archetype-metadata.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - src/main/resources - - **/*.xml - - - - src/main/resources - - **/*.drl - - - - src/main/config - - **/*.properties - **/*.json - - - - diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/pom.xml b/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/pom.xml deleted file mode 100644 index b0a7639d1..000000000 --- a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/pom.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - 4.0.0 - - ${groupId} - ${artifactId} - ${version} - - ${artifactId} - Closed Loop Demo Rules - - - 1.8 - 1.8 - - - - - org.onap.policy.drools-applications - events - ${dependenciesVersion} - - - org.onap.policy.drools-applications - rest - ${dependenciesVersion} - - - org.onap.policy.drools-applications - appc - ${dependenciesVersion} - - - org.onap.policy.drools-applications - aai - ${dependenciesVersion} - - - org.onap.policy.drools-applications - mso - ${dependenciesVersion} - - - org.onap.policy.drools-applications - trafficgenerator - ${dependenciesVersion} - - - org.onap.policy.drools-applications - eventmanager - ${dependenciesVersion} - - - org.onap.policy.drools-applications - guard - ${dependenciesVersion} - - - org.onap.policy.drools-applications - policy-yaml - ${dependenciesVersion} - - - diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties b/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties deleted file mode 100644 index 712bc2946..000000000 --- a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties +++ /dev/null @@ -1,55 +0,0 @@ -### -# ============LICENSE_START======================================================= -# archetype-closed-loop-demo-rules -# ================================================================================ -# 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========================================================= -### - -controller.name=${artifactId} - -ueb.source.topics=${dcaeTopic},${appcTopic} - -ueb.source.topics.${dcaeTopic}.servers=${dcaeServers} -ueb.source.topics.${dcaeTopic}.apiKey=${dcaeApiKey} -ueb.source.topics.${dcaeTopic}.apiSecret=${dcaeApiSecret} -ueb.source.topics.${dcaeTopic}.events=org.onap.policy.controlloop.VirtualControlLoopEvent -ueb.source.topics.${dcaeTopic}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=closedLoopEventStatus=.* -ueb.source.topics.${dcaeTopic}.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty - -ueb.source.topics.${appcTopic}.servers=${appcServers} -ueb.source.topics.${appcTopic}.apiKey=${appcApiKey} -ueb.source.topics.${appcTopic}.apiSecret=${appcApiSecret} -ueb.source.topics.${appcTopic}.events=org.onap.policy.appc.Response -ueb.source.topics.${appcTopic}.events.org.onap.policy.appc.Response.filter=CommonHeader=.*,Status=.* -ueb.source.topics.${appcTopic}.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty - -ueb.sink.topics=${appcTopic},${notificationTopic} - -ueb.sink.topics.${appcTopic}.servers=${appcServers} -ueb.sink.topics.${appcTopic}.apiKey=${appcApiKey} -ueb.sink.topics.${appcTopic}.apiSecret=${appcApiSecret} -ueb.sink.topics.${appcTopic}.events=org.onap.policy.appc.Request -ueb.sink.topics.${appcTopic}.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty - -ueb.sink.topics.${notificationTopic}.servers=${notificationServers} -ueb.sink.topics.${notificationTopic}.apiKey=${notificationApiKey} -ueb.sink.topics.${notificationTopic}.apiSecret=${notificationApiSecret} -ueb.sink.topics.${notificationTopic}.events=org.onap.policy.controlloop.VirtualControlLoopNotification -ueb.sink.topics.${notificationTopic}.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty - -rules.groupId=${groupId} -rules.artifactId=${artifactId} -rules.version=${version} diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json b/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json deleted file mode 100644 index 712cf7034..000000000 --- a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "controller.name": "${artifactId}", - - "ueb.source.topics": "${dcaeTopic},${appcTopic}", - - "ueb.source.topics.${dcaeTopic}.servers": "${dcaeServers}", - "ueb.source.topics.${dcaeTopic}.apiKey": "${dcaeApiKey}", - "ueb.source.topics.${dcaeTopic}.apiSecret": "${dcaeApiSecret}", - "ueb.source.topics.${dcaeTopic}.events": "org.onap.policy.controlloop.VirtualControlLoopEvent", - "ueb.source.topics.${dcaeTopic}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter": "closedLoopEventStatus=.*", - "ueb.source.topics.${dcaeTopic}.events.custom.gson": "org.onap.policy.controlloop.util.Serialization,gsonPretty", - - "ueb.source.topics.${appcTopic}.servers": "${appcServers}", - "ueb.source.topics.${appcTopic}.apiKey": "${appcApiKey}", - "ueb.source.topics.${appcTopic}.apiSecret": "${appcApiSecret}", - "ueb.source.topics.${appcTopic}.events": "org.onap.policy.appc.Response", - "ueb.source.topics.${appcTopic}.events.org.onap.policy.appc.Response.filter": "CommonHeader=.*,Status=.*", - "ueb.source.topics.${appcTopic}.events.custom.gson": "org.onap.policy.appc.util.Serialization,gsonPretty", - - "ueb.sink.topics": "${appcTopic},${notificationTopic}", - - "ueb.sink.topics.${appcTopic}.servers": "${appcServers}", - "ueb.sink.topics.${appcTopic}.apiKey": "${appcApiKey}", - "ueb.sink.topics.${appcTopic}.apiSecret": "${appcApiSecret}", - "ueb.sink.topics.${appcTopic}.events": "org.onap.policy.appc.Request", - "ueb.sink.topics.${appcTopic}.events.custom.gson": "org.onap.policy.appc.util.Serialization,gsonPretty", - - "ueb.sink.topics.${notificationTopic}.servers": "${notificationServers}", - "ueb.sink.topics.${notificationTopic}.apiKey": "${notificationApiKey}", - "ueb.sink.topics.${notificationTopic}.apiSecret": "${notificationApiSecret}", - "ueb.sink.topics.${notificationTopic}.events": "org.onap.policy.controlloop.VirtualControlLoopNotification", - "ueb.sink.topics.${notificationTopic}.events.custom.gson": "org.onap.policy.controlloop.util.Serialization,gsonPretty", - - "rules.groupId": "${groupId}", - "rules.artifactId": "${artifactId}", - "rules.version": "${version}" -} diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/appc.accepted.json b/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/appc.accepted.json deleted file mode 100644 index 01be66011..000000000 --- a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/appc.accepted.json +++ /dev/null @@ -1 +0,0 @@ -{"Status":{"Value":"ACCEPTED","Code":"100"},"Payload":{"pg-streams":"{\\\"pg-streams\\\": {\\\"pg-stream\\\":[{\\\"id\\\":\\\"fw_udp1\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp2\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp3\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp4\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp5\\\", \\\"is-enabled\\\":\\\"true\\\"}]}}","generic-vnf.vnf-id":"fw0001vm001fw001"},"CommonHeader":{"TimeStamp":"1493841850199","APIver":"1.01","RequestID":"664be3d2-6c12-4f4b-a3e7-c349acced200","SubrequestID":null,"OriginatorID":null}} diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/appc.success.json b/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/appc.success.json deleted file mode 100644 index b9ef41f50..000000000 --- a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/appc.success.json +++ /dev/null @@ -1 +0,0 @@ -{"Status":{"Value":"SUCCESS","Code":"400"},"Payload":{"pg-streams":"{\\\"pg-streams\\\": {\\\"pg-stream\\\":[{\\\"id\\\":\\\"fw_udp1\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp2\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp3\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp4\\\", \\\"is-enabled\\\":\\\"true\\\"},{\\\"id\\\":\\\"fw_udp5\\\", \\\"is-enabled\\\":\\\"true\\\"}]}}","generic-vnf.vnf-id":"fw0001vm001fw001"},"CommonHeader":{"TimeStamp":"1493841850199","APIver":"1.01","RequestID":"664be3d2-6c12-4f4b-a3e7-c349acced200","SubrequestID":null,"OriginatorID":null}} diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/dcae.onset.json b/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/dcae.onset.json deleted file mode 100644 index 4553faa13..000000000 --- a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/config/dcae.onset.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "closedLoopControlName": "${closedLoopControlName}", - "closedLoopAlarmStart": 1463679805324, - "closedLoopEventClient": "microservice.stringmatcher", - "closedLoopEventStatus": "ONSET", - "requestID": "664be3d2-6c12-4f4b-a3e7-c349acced200", - "target_type": "VF", - "target": "generic-vnf.vnf-id", - "AAI": { - "generic-vnf.vnf-id": "fw0001vm001fw001" - }, - "from": "DCAE", - "version": "1.0.2" -} diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/resources/ControlLoopDemo__closedLoopControlName__.drl b/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/resources/ControlLoopDemo__closedLoopControlName__.drl deleted file mode 100644 index ff5d82e5e..000000000 --- a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/resources/ControlLoopDemo__closedLoopControlName__.drl +++ /dev/null @@ -1,1140 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * archetype-closed-loop-demo-rules - * ================================================================================ - * 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.controlloop; - -import java.util.List; -import java.util.LinkedList; -import java.util.Map; -import java.util.HashMap; -import java.util.UUID; - -import org.onap.policy.controlloop.VirtualControlLoopEvent; -import org.onap.policy.controlloop.ControlLoopEventStatus; -import org.onap.policy.controlloop.VirtualControlLoopNotification; -import org.onap.policy.controlloop.ControlLoopNotificationType; -import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.ControlLoopOperationWrapper; -import org.onap.policy.controlloop.ControlLoopException; - -import org.onap.policy.aai.AAINQF199.AAINQF199CloudRegion; -import org.onap.policy.aai.AAINQF199.AAINQF199ExtraProperties; -import org.onap.policy.aai.AAINQF199.AAINQF199ExtraProperty; -import org.onap.policy.aai.AAINQF199.AAINQF199GenericVNF; -import org.onap.policy.aai.AAINQF199.AAINQF199InstanceFilters; -import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItem; -import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItems; -import org.onap.policy.aai.AAINQF199.AAINQF199Manager; -import org.onap.policy.aai.AAINQF199.AAINQF199NamedQuery; -import org.onap.policy.aai.AAINQF199.AAINQF199QueryParameters; -import org.onap.policy.aai.AAINQF199.AAINQF199Request; -import org.onap.policy.aai.AAINQF199.AAINQF199RequestWrapper; -import org.onap.policy.aai.AAINQF199.AAINQF199Response; -import org.onap.policy.aai.AAINQF199.AAINQF199ResponseWrapper; -import org.onap.policy.aai.AAINQF199.AAINQF199ServiceInstance; -import org.onap.policy.aai.AAINQF199.AAINQF199Tenant; -import org.onap.policy.aai.AAINQF199.AAINQF199VfModule; -import org.onap.policy.aai.AAINQF199.AAINQF199VServer; -import org.onap.policy.aai.util.Serialization; - -import org.onap.policy.appc.CommonHeader; -import org.onap.policy.appc.Request; -import org.onap.policy.appc.Response; -import org.onap.policy.appc.ResponseCode; -import org.onap.policy.appc.ResponseStatus; -import org.onap.policy.appc.ResponseValue; - -import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager; -import org.onap.policy.vnf.trafficgenerator.PGRequest; -import org.onap.policy.vnf.trafficgenerator.PGStream; -import org.onap.policy.vnf.trafficgenerator.PGStreams; - -import org.onap.policy.mso.MSOManager; -import org.onap.policy.mso.MSORequest; -import org.onap.policy.mso.MSORequestStatus; -import org.onap.policy.mso.MSORequestDetails; -import org.onap.policy.mso.MSOModelInfo; -import org.onap.policy.mso.MSOCloudConfiguration; -import org.onap.policy.mso.MSORequestInfo; -import org.onap.policy.mso.MSORequestParameters; -import org.onap.policy.mso.MSORelatedInstanceListElement; -import org.onap.policy.mso.MSORelatedInstance; -import org.onap.policy.mso.MSOResponse; - -import org.onap.policy.drools.system.PolicyEngine; - -// -// These parameters are required to build the runtime policy -// -declare Params - closedLoopControlName : String - actor : String - aaiURL : String - aaiUsername : String - aaiPassword : String - msoURL : String - msoUsername : String - msoPassword : String - aaiNamedQueryUUID : String - aaiPatternMatch : int - notificationTopic : String - appcTopic : String -end - -/* -* -* Called once and only once to insert the parameters into working memory for this Closed Loop policy. -* NOTE: If this file is to be used as a template to be used with the policy BRMS GW, please comment out this line -* as the BRMS_GW already generates a SETUP rule -* -*/ -rule "${policyName}.SETUP" - when - then - System.out.println("rule SETUP is triggered."); - Params params = new Params(); - params.setClosedLoopControlName("${closedLoopControlName}"); - params.setActor("${actor}"); - params.setAaiURL("${aaiURL}"); - params.setAaiUsername("${aaiUsername}"); - params.setAaiPassword("${aaiPassword}"); - params.setMsoURL("${msoURL}"); - params.setMsoUsername("${msoUsername}"); - params.setMsoPassword("${msoPassword}"); - params.setAaiNamedQueryUUID("${aaiNamedQueryUUID}"); - params.setAaiPatternMatch(${aaiPatternMatch}); - params.setNotificationTopic("${notificationTopic}"); - params.setAppcTopic("${appcTopic}"); - // - // This stays in memory as long as the rule is alive and running - // - insert(params); -end - - -/* -* -* This rule responds to DCAE Events -* -*/ -rule "${policyName}.EVENT" - when - $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) - $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - not ( ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )) - then - System.out.println("rule EVENT is triggered."); - try { - // - // Check the requestID in the event to make sure it is not null before we create the EventManager. - // The EventManager will do extra syntax checking as well check if the closed loop is disabled/ - // - if ($event.requestID == null) { - VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.notification = ControlLoopNotificationType.REJECTED; - notification.from = "policy"; - notification.message = "Missing requestID from DCAE event"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; - // - // Let interested parties know - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("Can't deliver notification: " + notification); - } - // - // Retract it from memory - // - retract($event); - System.out.println("Event with requestID=null has been retracted."); - } else { - // - // Create an EventManager - // - ControlLoopEventManager manager = new ControlLoopEventManager($params.getClosedLoopControlName(), $event.requestID); - // - // Determine if EventManager can actively process the event (i.e. syntax) - // - VirtualControlLoopNotification notification = manager.activate($event); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; - // - // Are we actively pursuing this event? - // - if (notification.notification == ControlLoopNotificationType.ACTIVE) { - // - // Insert Event Manager into memory, this will now kick off processing. - // - insert(manager); - // - // Let interested parties know - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("Can't deliver notification: " + notification); - } - } else { - // - // Let interested parties know - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("Can't deliver notification: " + notification); - } - // - // Retract it from memory - // - retract($event); - } - // - // Now that the manager is inserted into Drools working memory, we'll wait for - // another rule to fire in order to continue processing. This way we can also - // then screen for additional ONSET and ABATED events for this same RequestIDs - // and for different RequestIDs but with the same closedLoopControlName and target. - // - } - // - } catch (Exception e) { - e.printStackTrace(); - 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}"; - // - // - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e1) { - System.out.println("Can't deliver notification: " + notification); - e1.printStackTrace(); - } - // - // Retract the event - // - retract($event); - } -end - -/* -* -* This rule happens when we got a valid ONSET, closed loop is enabled and an Event Manager -* is created. We can start the operations for this closed loop. -* -*/ -rule "${policyName}.EVENT.MANAGER" - when - $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) - $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, controlLoopResult == null) - then - System.out.println("rule EVENT.MANAGER is triggered."); - // - // Check which event this is. - // - ControlLoopEventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event); - // - // We only want the initial ONSET event in memory, - // all the other events need to be retracted to support - // cleanup and avoid the other rules being fired for this event. - // - if (eventStatus != ControlLoopEventManager.NEW_EVENT_STATUS.FIRST_ONSET) { - System.out.println("Retracting "+eventStatus+" Event."); - retract($event); - return; - } - // - // Now the event in memory is first onset event - // - try { - // - // Pull the known AAI field from the Event - // - // generic-vnf is needed for vFirewall case - // vserver-name is needed for vLoadBalancer case - // - String genericVNF = $event.AAI.get("generic-vnf.vnf-id"); - String vserver = $event.AAI.get("vserver.vserver-name"); - // - // Check if we are implementing a simple pattern match. - // - if ($params.getAaiPatternMatch() == 1) { - // - // Yes - // - //Basic naming characteristics: - //VF Name (9 char)+VM name (13 char total)+VFC (19 char total) - //Example: - //VF Name (9 characters): cscf0001v - //VM Name(13 characters): cscf0001vm001 - //VFC name(19 characters): cscf0001vm001cfg001 - // - // zdfw1fwl01fwl02 or zdfw1fwl01fwl01 - // replaced with - // zdfw1fwl01pgn02 or zdfw1fwl01pgn01 - // - int index = genericVNF.lastIndexOf("fwl"); - if (index == -1) { - System.err.println("The generic-vnf.vnf-id from DCAE Event is not valid."); - } else { - genericVNF = genericVNF.substring(0, index) + "pgn" + genericVNF.substring(index+"fwl".length()); - } - // - // Construct an APPC request - // - ControlLoopOperation operation = new ControlLoopOperation(); - operation.actor = $params.getActor(); - operation.operation = "ModifyConfig"; - operation.target = $event.target; - // - // Create operationWrapper - // - ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation); - // - // insert operationWrapper into memory - // - insert(operationWrapper); - // - Request request = new Request(); - request.CommonHeader = new CommonHeader(); - request.CommonHeader.RequestID = $event.requestID; - request.Action = operation.operation; - request.Payload = new HashMap(); - // - // Fill in the payload - // - request.Payload.put("generic-vnf.vnf-id", genericVNF); - // - PGRequest pgRequest = new PGRequest(); - pgRequest.pgStreams = new PGStreams(); - - PGStream pgStream; - for(int i = 0; i < 5; i++){ - pgStream = new PGStream(); - pgStream.streamId = "fw_udp"+(i+1); - pgStream.isEnabled = "true"; - pgRequest.pgStreams.pgStream.add(pgStream); - } - request.Payload.put("pg-streams", pgRequest.pgStreams); - - if (request != null) { - // - // Insert request into memory - // - insert(request); - // - // Tell interested parties we are performing this Operation - // - VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.notification = ControlLoopNotificationType.OPERATION; - // message and history ?? - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - // - // Now send the operation request - // - if (request instanceof Request) { - try { - System.out.println("APPC request sent:"); - System.out.println(Serialization.gsonPretty.toJson(request)); - PolicyEngine.manager.deliver($params.getAppcTopic(), request); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("Can't deliver request: " + request); - } - } - } else { - // - // what happens if it is null - // - } - // - } else { - // - // create AAI named-query request with UUID started with "F199" - // - AAINQF199Request aainqf199request = new AAINQF199Request(); - AAINQF199QueryParameters aainqf199queryparam = new AAINQF199QueryParameters(); - AAINQF199NamedQuery aainqf199namedquery = new AAINQF199NamedQuery(); - AAINQF199InstanceFilters aainqf199instancefilter = new AAINQF199InstanceFilters(); - // - // queryParameters - // - aainqf199namedquery.namedQueryUUID = UUID.fromString($params.getAaiNamedQueryUUID()); - aainqf199queryparam.namedQuery = aainqf199namedquery; - aainqf199request.queryParameters = aainqf199queryparam; - // - // instanceFilters - // - Map aainqf199instancefiltermap = new HashMap(); - Map aainqf199instancefiltermapitem = new HashMap(); - aainqf199instancefiltermapitem.put("vserver-name", vserver); - aainqf199instancefiltermap.put("vserver", aainqf199instancefiltermapitem); - aainqf199instancefilter.instanceFilter.add(aainqf199instancefiltermap); - aainqf199request.instanceFilters = aainqf199instancefilter; - // - // print aainqf199request for debug - // - System.out.println("AAI Request sent:"); - System.out.println(Serialization.gsonPretty.toJson(aainqf199request)); - // - // Create AAINQF199RequestWrapper - // - AAINQF199RequestWrapper aainqf199RequestWrapper = new AAINQF199RequestWrapper($event.requestID, aainqf199request); - // - // insert aainqf199request into memory - // - insert(aainqf199RequestWrapper); - } - // - } catch (Exception e) { - e.printStackTrace(); - } -end - -/* -* -* This rule happens when we got a valid ONSET, closed loop is enabled, an Event Manager -* is created, AAI Manager and AAI Request are ready in memory. We can start sending query to AAI and then wait for response. -* -*/ -rule "${policyName}.EVENT.MANAGER.AAINQF199REQUEST" - when - $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) - $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ) - $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID) - then - System.out.println("rule EVENT.MANAGER.AAINQF199REQUEST is triggered."); - // - // send the request - // - AAINQF199Response aainqf199response = AAINQF199Manager.postQuery($params.getAaiURL(), $params.getAaiUsername(), $params.getAaiPassword(), - $aainqf199RequestWrapper.aainqf199request, $event.requestID); - - // - // Check AAI response - // - if (aainqf199response == null) { - System.err.println("Failed to get AAI response"); - // - // Fail and retract everything - // - retract($event); - retract($manager); - retract($aainqf199RequestWrapper); - } else { - // - // Create AAINQF199ResponseWrapper - // - AAINQF199ResponseWrapper aainqf199ResponseWrapper = new AAINQF199ResponseWrapper($event.requestID, aainqf199response); - // - // insert aainqf199ResponseWrapper to memeory - // - insert(aainqf199ResponseWrapper); - } -end - -/* -* -* This rule happens when we got a valid AAI response. We can start sending request to APPC or MSO now. -* -*/ -rule "${policyName}.EVENT.MANAGER.AAINQF199RESPONSE" - when - $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) - $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ) - $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID) - $aainqf199ResponseWrapper : AAINQF199ResponseWrapper(requestID == $event.requestID) - then - System.out.println("rule EVENT.MANAGER.AAINQF199RESPONSE is triggered."); - // - // Extract related fields out of AAINQF199RESPONSE - // - String vnfItemVnfId, vnfItemVnfType, vnfItemPersonaModelId, vnfItemPersonaModelVersion, vnfItemModelName, - vnfItemModelVersion, vnfItemModelNameVersionId, serviceItemServiceInstanceId, serviceItemPersonaModelId, - serviceItemModelName, serviceItemModelType, serviceItemModelVersion, serviceItemModelNameVersionId, - vfModuleItemVfModuleName, vfModuleItemPersonaModelId, vfModuleItemPersonaModelVersion, vfModuleItemModelName, - vfModuleItemModelNameVersionId, tenantItemTenantId, cloudRegionItemCloudRegionId; - try { - // - // vnfItem - // - vnfItemVnfId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfID; - vnfItemVnfType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfType; - vnfItemVnfType = vnfItemVnfType.substring(vnfItemVnfType.lastIndexOf("/")+1); - vnfItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelId; - vnfItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelVersion; - vnfItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue; - vnfItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(2).propertyValue; - vnfItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue; - // - // serviceItem - // - serviceItemServiceInstanceId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.serviceInstanceID; - serviceItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelId; - serviceItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue; - serviceItemModelType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(1).propertyValue; - serviceItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelVersion; - serviceItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue; - // - // Find the index for base vf module and non-base vf module - // - int baseIndex = -1; - int nonBaseIndex = -1; - List inventoryItems = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems; - for (AAINQF199InventoryResponseItem m : inventoryItems) { - if (m.vfModule != null && m.vfModule.isBaseVfModule == true) { - baseIndex = inventoryItems.indexOf(m); - } else if (m.vfModule != null && m.vfModule.isBaseVfModule == false && m.vfModule.orchestrationStatus == null) { - nonBaseIndex = inventoryItems.indexOf(m); - } - // - if (baseIndex != -1 && nonBaseIndex != -1) { - break; - } - } - // - // Report the error if either base vf module or non-base vf module is not found - // - if (baseIndex == -1 || nonBaseIndex == -1) { - System.err.println("Either base or non-base vf module is not found from AAI response."); - retract($aainqf199RequestWrapper); - retract($aainqf199ResponseWrapper); - retract($manager); - retract($event); - return; - } - // - // This comes from the base module - // - vfModuleItemVfModuleName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(baseIndex).vfModule.vfModuleName; - vfModuleItemVfModuleName = vfModuleItemVfModuleName.replace("Vfmodule", "vDNS"); - // - // vfModuleItem - NOT the base module - // - vfModuleItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelId; - vfModuleItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelVersion; - vfModuleItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(0).propertyValue; - vfModuleItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(4).propertyValue; - // - // tenantItem - // - tenantItemTenantId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).tenant.tenantId; - // - // cloudRegionItem - // - cloudRegionItemCloudRegionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).items.inventoryResponseItems.get(0).cloudRegion.cloudRegionId; - // - } catch (Exception e) { - e.printStackTrace(); - 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}"; - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e1) { - System.out.println("Can't deliver notification: " + notification); - e1.printStackTrace(); - } - // - notification.notification = ControlLoopNotificationType.FINAL_FAILURE; - notification.message = "Invalid named-query response from AAI"; - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e1) { - System.out.println("Can't deliver notification: " + notification); - e1.printStackTrace(); - } - // - // Retract everything - // - retract($aainqf199RequestWrapper); - retract($aainqf199ResponseWrapper); - retract($manager); - retract($event); - return; - } - // - // Extracted fields should not be null - // - if ((vnfItemVnfId == null) || (vnfItemVnfType == null) || - (vnfItemPersonaModelId == null) || (vnfItemModelName == null) || - (vnfItemModelVersion == null) || (vnfItemModelNameVersionId == null) || - (serviceItemServiceInstanceId == null) || (serviceItemModelName == null) || - (serviceItemModelType == null) || (serviceItemModelVersion == null) || - (serviceItemModelNameVersionId == null) || (vfModuleItemVfModuleName == null) || - (vfModuleItemPersonaModelId == null) || (vfModuleItemPersonaModelVersion == null) || - (vfModuleItemModelName == null) || (vfModuleItemModelNameVersionId == null) || - (tenantItemTenantId == null) || (cloudRegionItemCloudRegionId == null)) { - // - System.err.println("some fields are missing from AAI response."); - // - // Fail and retract everything - // - retract($aainqf199RequestWrapper); - retract($aainqf199ResponseWrapper); - retract($manager); - retract($event); - return; - } - // - // We don't need them any more - // - retract($aainqf199ResponseWrapper); - retract($aainqf199RequestWrapper); - // - // check the actor of this closed loop - // - switch ($params.getActor()) { - case "APPC": - { - // - // Construct an APPC request - // - ControlLoopOperation operation = new ControlLoopOperation(); - operation.actor = $params.getActor(); - operation.operation = "ModifyConfig"; - operation.target = $event.target; - // - // Create operationWrapper - // - ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation); - // - // insert operationWrapper into memory - // - insert(operationWrapper); - // - Request request = new Request(); - request.CommonHeader = new CommonHeader(); - request.CommonHeader.RequestID = $event.requestID; - request.Action = operation.operation; - request.Payload = new HashMap(); - // - // Fill in the payload - // Hardcode genericVNF for now since AAI has not been ready for vFirewall demo case - // - String genericVNF = "zdfw1fwl01pgn02"; - request.Payload.put("generic-vnf.vnf-id", genericVNF); - // - PGRequest pgRequest = new PGRequest(); - pgRequest.pgStreams = new PGStreams(); - - PGStream pgStream; - for(int i = 0; i < 5; i++){ - pgStream = new PGStream(); - pgStream.streamId = "fw_udp"+(i+1); - pgStream.isEnabled = "true"; - pgRequest.pgStreams.pgStream.add(pgStream); - } - request.Payload.put("pg-streams", pgRequest.pgStreams); - - if (request != null) { - // - // Insert request into memory - // - insert(request); - // - // Tell interested parties we are performing this Operation - // - VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.notification = ControlLoopNotificationType.OPERATION; - // message and history ?? - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - // - // Now send the operation request - // - if (request instanceof Request) { - try { - System.out.println("APPC request sent:"); - System.out.println(Serialization.gsonPretty.toJson(request)); - PolicyEngine.manager.deliver($params.getAppcTopic(), request); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("Can't deliver request: " + request); - } - } - } else { - // - // what happens if it is null - // - } - } - break; - case "MSO": - { - // - // Construct an operation - // - ControlLoopOperation operation = new ControlLoopOperation(); - operation.actor = $params.getActor(); - operation.operation = "createModuleInstance"; - operation.target = $event.target; - // - // Create operationWrapper - // - ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation); - // - // Construct an MSO request - // - MSORequest request = new MSORequest(); - request.requestDetails = new MSORequestDetails(); - request.requestDetails.modelInfo = new MSOModelInfo(); - request.requestDetails.cloudConfiguration = new MSOCloudConfiguration(); - request.requestDetails.requestInfo = new MSORequestInfo(); - request.requestDetails.requestParameters = new MSORequestParameters(); - request.requestDetails.requestParameters.userParams = null; - // - // cloudConfiguration - // - request.requestDetails.cloudConfiguration.lcpCloudRegionId = cloudRegionItemCloudRegionId; - request.requestDetails.cloudConfiguration.tenantId = tenantItemTenantId; - // - // modelInfo - // - request.requestDetails.modelInfo.modelType = "vfModule"; - request.requestDetails.modelInfo.modelInvariantId = vfModuleItemPersonaModelId; - request.requestDetails.modelInfo.modelNameVersionId = vfModuleItemModelNameVersionId; - request.requestDetails.modelInfo.modelName = vfModuleItemModelName; - request.requestDetails.modelInfo.modelVersion = vfModuleItemPersonaModelVersion; - // - // requestInfo - // - request.requestDetails.requestInfo.instanceName = vfModuleItemVfModuleName; - request.requestDetails.requestInfo.source = "POLICY"; - request.requestDetails.requestInfo.suppressRollback = false; - // - // relatedInstanceList - // - MSORelatedInstanceListElement relatedInstanceListElement1 = new MSORelatedInstanceListElement(); - MSORelatedInstanceListElement relatedInstanceListElement2 = new MSORelatedInstanceListElement(); - relatedInstanceListElement1.relatedInstance = new MSORelatedInstance(); - relatedInstanceListElement2.relatedInstance = new MSORelatedInstance(); - // - relatedInstanceListElement1.relatedInstance.instanceId = serviceItemServiceInstanceId; - relatedInstanceListElement1.relatedInstance.modelInfo = new MSOModelInfo(); - relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service"; - relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = serviceItemPersonaModelId; - relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = serviceItemModelNameVersionId; - relatedInstanceListElement1.relatedInstance.modelInfo.modelName = serviceItemModelName; - relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = serviceItemModelVersion; - // - relatedInstanceListElement2.relatedInstance.instanceId = vnfItemVnfId; - relatedInstanceListElement2.relatedInstance.modelInfo = new MSOModelInfo(); - relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = vnfItemPersonaModelId; - relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = vnfItemModelNameVersionId; - relatedInstanceListElement2.relatedInstance.modelInfo.modelName = vnfItemModelName; - relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = vnfItemModelVersion; - relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = vnfItemVnfType; - // - request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1); - request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2); - // - // print MSO request for debug - // - System.out.println("MSO request sent:"); - System.out.println(Serialization.gsonPretty.toJson(request)); - // - // - // - if (request != null) { - // - // Tell interested parties we are performing this Operation - // - VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.notification = ControlLoopNotificationType.OPERATION; - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - // - // Concatenate serviceItemServiceInstanceId and vnfItemVnfId to msoURL - // - String MSOUrl = $params.getMsoURL() + "/serviceInstances/v2/" + serviceItemServiceInstanceId + "/vnfs/" + vnfItemVnfId + "/vfModules"; - // - // Call MSO - // - MSOResponse response = MSOManager.createModuleInstance(MSOUrl, $params.getMsoURL(), $params.getMsoUsername(), $params.getMsoPassword(), request); - - - if (response != null) { - // - // Assign requestId - // - request.requestId = $event.requestID.toString(); - response.request.requestId = $event.requestID.toString(); - // - // Insert facts - // - insert(operationWrapper); - insert(request); - insert(response); - } else { - // - // MSO request not even accepted - // - notification.message = operationWrapper.operation.toMessage(); - operationWrapper.operation.message = operationWrapper.operation.toMessage(); - operationWrapper.operation.outcome = "FAILURE_EXCEPTION"; - $manager.setControlLoopResult("FAILURE_EXCEPTION"); - notification.history.add(operationWrapper.operation); - notification.notification = ControlLoopNotificationType.OPERATION_FAILURE; - // - // Let interested parties know - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - notification.notification = ControlLoopNotificationType.FINAL_FAILURE; - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - // - // Retract everything - // - retract($event); - retract($manager); - } - } else { - System.err.println("constructed MSO request is invalid."); - } - } - break; - } -end - -/* -* -* This rule responds to APPC Response Events -* -*/ -rule "${policyName}.APPC.RESPONSE" - when - $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) - $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ) - $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID ) - $request : Request( getCommonHeader().RequestID == $event.requestID ) - $response : Response( getCommonHeader().RequestID == $event.requestID ) - then - System.out.println("rule APPC.RESPONSE is triggered."); - if ($response.Status == null) { - $operationWrapper.operation.outcome = "FAILURE_EXCEPTION"; - $manager.setControlLoopResult("FAILURE_EXCEPTION"); - } - // - // Get the Response Code - // - ResponseCode code = ResponseCode.toResponseCode($response.Status.Code); - if (code == null) { - $operationWrapper.operation.outcome = "FAILURE_EXCEPTION"; - $manager.setControlLoopResult("FAILURE_EXCEPTION"); - } - // - // Construct notification - // - VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; - notification.message = $operationWrapper.operation.toMessage(); - $operationWrapper.operation.message = $operationWrapper.operation.toMessage(); - // - // Ok, let's figure out what APP-C's response is - // - switch (code) { - case ACCEPT: - $operationWrapper.operation.outcome = "PROCESSING"; - break; - case ERROR: - case REJECT: - $operationWrapper.operation.outcome = "FAILURE_EXCEPTION"; - $manager.setControlLoopResult("FAILURE_EXCEPTION"); - break; - case SUCCESS: - $operationWrapper.operation.outcome = "SUCCESS"; - $manager.setControlLoopResult("SUCCESS"); - break; - case FAILURE: - $operationWrapper.operation.outcome = "FAILURE"; - $manager.setControlLoopResult("FAILURE"); - break; - } - if ($operationWrapper.operation.outcome.equals("SUCCESS")) { - notification.history.add($operationWrapper.operation); - notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS; - // - // Let interested parties know - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - notification.notification = ControlLoopNotificationType.FINAL_SUCCESS; - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - - // - // We are going to retract these objects from memory - // - System.out.println("Retracting everything"); - retract($operationWrapper); - retract($request); - retract($response); - retract($event); - retract($manager); - } else if ($operationWrapper.operation.outcome.equals("PROCESSING")) { - retract($response); - } else { - notification.history.add($operationWrapper.operation); - notification.notification = ControlLoopNotificationType.OPERATION_FAILURE; - // - // Let interested parties know - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - notification.notification = ControlLoopNotificationType.FINAL_FAILURE; - // - // Let interested parties know - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - // - // We are going to retract these objects from memory - // - System.out.println("Retracting everything"); - retract($operationWrapper); - retract($request); - retract($response); - retract($event); - retract($manager); - } - -end - -/* -* -* This rule is used to clean up APPC response -* -*/ -rule "${policyName}.APPC.RESPONSE.CLEANUP" - when - $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) - $response : Response($id : getCommonHeader().RequestID ) - not ( VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), requestID == $id, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) ) - then - System.out.println("rule APPC.RESPONSE.CLEANUP is triggered."); - retract($response); -end - -/* -* -* This rule responds to MSO Response Events -* -*/ -rule "${policyName}.MSO.RESPONSE" - when - $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) - $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ) - $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID ) - $request : MSORequest( requestId == $event.requestID.toString() ) - $response : MSOResponse( request.requestId == $event.requestID.toString() ) - then - System.out.println("rule MSO.RESPONSE is triggered."); - // - // Construct notification - // - VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.from = "policy"; - notification.policyName = drools.getRule().getName(); - notification.policyScope = "${policyScope}"; - notification.policyVersion = "${policyVersion}"; - notification.message = $operationWrapper.operation.toMessage(); - $operationWrapper.operation.message = $operationWrapper.operation.toMessage(); - // - // The operation can either be succeeded or failed - // - if($response.request.requestStatus.requestState.equals("COMPLETE")) { - $operationWrapper.operation.outcome = "SUCCESS"; - $manager.setControlLoopResult("SUCCESS"); - notification.history.add($operationWrapper.operation); - notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS; - // - // Let interested parties know - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - notification.notification = ControlLoopNotificationType.FINAL_SUCCESS; - // - // Let interested parties know - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - // - // We are going to retract these objects from memory - // - System.out.println("Retracting everything"); - retract($operationWrapper); - retract($request); - retract($response); - retract($event); - retract($manager); - } else { - $operationWrapper.operation.outcome = "FAILURE"; - $manager.setControlLoopResult("FAILURE"); - notification.history.add($operationWrapper.operation); - notification.notification = ControlLoopNotificationType.OPERATION_FAILURE; - // - // Let interested parties know - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - notification.notification = ControlLoopNotificationType.FINAL_FAILURE; - // - // Let interested parties know - // - try { - System.out.println(Serialization.gsonPretty.toJson(notification)); - PolicyEngine.manager.deliver($params.getNotificationTopic(), notification); - } catch (Exception e) { - System.out.println("Can't deliver notification: " + notification); - e.printStackTrace(); - } - // - // We are going to retract these objects from memory - // - System.out.println("Retracting everything"); - retract($operationWrapper); - retract($request); - retract($response); - retract($event); - retract($manager); - } -end - -/* - * Sample Queries for illustration with and without arguments - * The results of the query can be introspected (and retracted if desired) - * through REST API. - */ -query "${policyName}.QUERY.EVENT.ONSET" - event : VirtualControlLoopEvent( closedLoopEventStatus == ControlLoopEventStatus.ONSET ) -end - -query "${policyName}.QUERY.MANAGER.RNA" (String aRequestId, Integer numOnsetsLowerBound, Boolean aActivated) - manager : ControlLoopEventManager( closedLoopControlName == "${closedLoopControlName}", - requestID.toString() == aRequestId, - numOnsets > numOnsetsLowerBound, - activated == aActivated ) -end diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/resources/META-INF/kmodule.xml b/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/resources/META-INF/kmodule.xml deleted file mode 100644 index 8116d880a..000000000 --- a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/main/resources/archetype-resources/src/main/resources/META-INF/kmodule.xml +++ /dev/null @@ -1,29 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) - - - - - - - - diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/test/resources/projects/basic/archetype.properties b/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/test/resources/projects/basic/archetype.properties deleted file mode 100644 index 0b077b052..000000000 --- a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/test/resources/projects/basic/archetype.properties +++ /dev/null @@ -1,50 +0,0 @@ -### -# ============LICENSE_START======================================================= -# archetype-closed-loop-demo-rules -# ================================================================================ -# 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========================================================= -### - -groupId=org.onap.policy.demo.drools -artifactId=closedloop-demo-rules -version=1.0.0-SNAPSHOT -package=org.onap.policy.demo.drools -closedLoopControlName=CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8 -policyScope=service=test;resource=FRWL;type=configuration -policyName=FirewallDemo -policyVersion=v1.0 -actor=APPC -appcTopic=APPC-CL -appcApiKey=NO-API-KEY -appcApiSecret=NO-API-SECRET -appcServers=server1,server2,server3 -notificationTopic=POLICY-CL-MGT -notificationApiKey=NO-API-KEY -notificationApiSecret=NO-API-SECRET -notificationServers=server1,server2,server3 -dcaeTopic=DCAE-CL-EVENT -dcaeServers=server1,server2,server3 -dcaeApiKey=NO-API-KEY -dcaeApiSecret=NO-API-SECRET -dependenciesVersion=1.0.0-SNAPSHOT -aaiURL=http://localhost:8080/TestREST/Test -aaiUsername=policy -aaiPassword=policy -aaiNamedQueryUUID=d925ed73-8231-4d02-9545-db4e101fffff -aaiPatternMatch=false -msoURL=http://localhost:8080/TestREST/Test -msoUsername=policy -msoPassword=policy diff --git a/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/test/resources/projects/basic/goal.txt b/controlloop/templates/template.demo.v1.0.0/archetype-closedloop-demo-rules/src/test/resources/projects/basic/goal.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/controlloop/templates/template.demo.v1.0.0/pom.xml b/controlloop/templates/template.demo.v1.0.0/pom.xml index 4a746135a..f32ed27bf 100644 --- a/controlloop/templates/template.demo.v1.0.0/pom.xml +++ b/controlloop/templates/template.demo.v1.0.0/pom.xml @@ -24,18 +24,17 @@ 4.0.0 template.demo.v1.0.0 - pom + pom - - org.onap.policy.drools-applications - templates - 1.1.0-SNAPSHOT - - - - archetype-closedloop-demo-rules - template.demo - + + org.onap.policy.drools-applications + templates + 1.1.0-SNAPSHOT + + + archetype-cl-legacy + template.demo + -- cgit 1.2.3-korg