From: RehanRaza Date: Wed, 12 May 2021 16:14:46 +0000 (+0200) Subject: First version of apex policy for O-RU and O-DU usecase X-Git-Tag: 2.2.0~40^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=aea0b4bc5c108e5246be09b1afef6ffc4e812840;p=nonrtric.git First version of apex policy for O-RU and O-DU usecase Change-Id: Ic87e324eba8f711bc59932d58111480b94c49be4 Issue-ID: NONRTRIC-501 Signed-off-by: RehanRaza --- diff --git a/test/usecases/LinkMonitor/config/LinkMonitorConfigDmaap2RestJsonEvent.json b/test/usecases/LinkMonitor/config/LinkMonitorConfigDmaap2RestJsonEvent.json new file mode 100644 index 00000000..a2853207 --- /dev/null +++ b/test/usecases/LinkMonitor/config/LinkMonitorConfigDmaap2RestJsonEvent.json @@ -0,0 +1,76 @@ +{ + "engineServiceParameters": { + "name": "LinkMonitorApexEngine", + "version": "0.0.1", + "id": 101, + "instanceCount": 1, + "deploymentPort": 12345, + "engineParameters": { + "executorParameters": { + "JAVASCRIPT": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters" + } + }, + "contextParameters": { + "parameterClassName": "org.onap.policy.apex.context.parameters.ContextParameters", + "schemaParameters": { + "Avro": { + "parameterClassName": "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters" + } + } + } + } + }, + "eventOutputParameters": { + "RestProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://sdnr-sim:9990/rests/data/network-topology:network-topology/topology=topology-netconf/node={OduId}/yang-ext:mount/o-ran-sc-du-hello-world:network-function/du-to-ru-connection={OruId}" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON", + "parameters": { + "pojoField": "LinkFailureOutput" + } + }, + "eventNameFilter": "LinkFailureOutputEvent" + }, + "StdOutProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "standardIo": true + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON", + "parameters": { + "pojoField": "message" + } + }, + "eventNameFilter": "ApexMessageOutputEvent" + } + }, + "eventInputParameters": { + "DMaaPConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://dmaap-mr:3904/events/unauthenticated.SEC_FAULT_OUTPUT/users/link-monitor-nonrtric?timeout=15000&limit=100" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON", + "parameters": { + "versionAlias": "version", + "pojoField": "LinkFailureInput" + } + }, + "eventName": "LinkFailureInputEvent" + } + } +} diff --git a/test/usecases/LinkMonitor/config/o-ru-to-o-du-map.json b/test/usecases/LinkMonitor/config/o-ru-to-o-du-map.json new file mode 100644 index 00000000..a72ed6b1 --- /dev/null +++ b/test/usecases/LinkMonitor/config/o-ru-to-o-du-map.json @@ -0,0 +1,13 @@ +{ + "ERICSSON-O-RU-11220": "HCL-O-DU-1122", + "ERICSSON-O-RU-11221": "HCL-O-DU-1122", + "ERICSSON-O-RU-11222": "HCL-O-DU-1122", + "ERICSSON-O-RU-11223": "HCL-O-DU-1122", + "ERICSSON-O-RU-11223": "HCL-O-DU-1122", + "ERICSSON-O-RU-11224": "HCL-O-DU-1123", + "ERICSSON-O-RU-11225": "HCL-O-DU-1123", + "ERICSSON-O-RU-11226": "HCL-O-DU-1123", + "ERICSSON-O-RU-11227": "HCL-O-DU-1124", + "ERICSSON-O-RU-11228": "HCL-O-DU-1125", + "ERICSSON-O-RU-11229": "HCL-O-DU-1125" +} \ No newline at end of file diff --git a/test/usecases/LinkMonitor/events/LinkClearedEvent.json b/test/usecases/LinkMonitor/events/LinkClearedEvent.json new file mode 100644 index 00000000..782b62eb --- /dev/null +++ b/test/usecases/LinkMonitor/events/LinkClearedEvent.json @@ -0,0 +1,38 @@ +{ + "event": { + "commonEventHeader": { + "domain": "fault", + "eventId": "nt:network-topology/nt:topology/nt:node/nt:node-id", + "eventName": "fault_O-RAN-RU-Fault_Alarms_CUS_Link_Failure", + "eventType": "O-RAN-RU-Fault", + "sequence": 0, + "priority": "Normal", + "reportingEntityId": "SDNR", + "reportingEntityName": "@controllerName@", + "sourceId": "", + "sourceName": "ERICSSON-O-RU-11225", + "startEpochMicrosec": "@timestamp@", + "lastEpochMicrosec": "@timestamp@", + "nfNamingCode": "", + "nfVendorName": "ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/mfg-name", + "timeZoneOffset": "+00:00", + "version": "4.1", + "vesEventListenerVersion": "7.2.1" + }, + "faultFields": { + "faultFieldsVersion": "4.0", + "alarmCondition": "30", + "alarmInterfaceA": "o-ran-fm:alarm-notif/fault-source", + "eventSourceType": "ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/mfg-model or \"O-RU\"", + "specificProblem": "", + "eventSeverity": "NORMAL", + "vfStatus": "Active", + "alarmAdditionalInformation": { + "eventTime": "@eventTime@", + "equipType": "@type@", + "vendor": "@vendor@", + "model": "@model@" + } + } + } +} \ No newline at end of file diff --git a/test/usecases/LinkMonitor/events/LinkFailureEvent.json b/test/usecases/LinkMonitor/events/LinkFailureEvent.json new file mode 100644 index 00000000..f005ead0 --- /dev/null +++ b/test/usecases/LinkMonitor/events/LinkFailureEvent.json @@ -0,0 +1,38 @@ +{ + "event": { + "commonEventHeader": { + "domain": "fault", + "eventId": "nt:network-topology/nt:topology/nt:node/nt:node-id", + "eventName": "fault_O-RAN-RU-Fault_Alarms_CUS_Link_Failure", + "eventType": "O-RAN-RU-Fault", + "sequence": 0, + "priority": "Normal", + "reportingEntityId": "SDNR", + "reportingEntityName": "@controllerName@", + "sourceId": "", + "sourceName": "ERICSSON-O-RU-11225", + "startEpochMicrosec": "@timestamp@", + "lastEpochMicrosec": "@timestamp@", + "nfNamingCode": "", + "nfVendorName": "ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/mfg-name", + "timeZoneOffset": "+00:00", + "version": "4.1", + "vesEventListenerVersion": "7.2.1" + }, + "faultFields": { + "faultFieldsVersion": "4.0", + "alarmCondition": "30", + "alarmInterfaceA": "o-ran-fm:alarm-notif/fault-source", + "eventSourceType": "ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/mfg-model or \"O-RU\"", + "specificProblem": "", + "eventSeverity": "CRITICAL", + "vfStatus": "Active", + "alarmAdditionalInformation": { + "eventTime": "@eventTime@", + "equipType": "@type@", + "vendor": "@vendor@", + "model": "@model@" + } + } + } +} \ No newline at end of file diff --git a/test/usecases/LinkMonitor/events/SomeOtherEvent.json b/test/usecases/LinkMonitor/events/SomeOtherEvent.json new file mode 100644 index 00000000..79770e76 --- /dev/null +++ b/test/usecases/LinkMonitor/events/SomeOtherEvent.json @@ -0,0 +1,38 @@ +{ + "event": { + "commonEventHeader": { + "domain": "fault", + "eventId": "nt:network-topology/nt:topology/nt:node/nt:node-id", + "eventName": "fault_O-RAN-RU-Fault_Alarms_CUS_Link_Failure", + "eventType": "O-RAN-RU-Fault", + "sequence": 0, + "priority": "Normal", + "reportingEntityId": "SDNR", + "reportingEntityName": "@controllerName@", + "sourceId": "", + "sourceName": "ERICSSON-O-RU-11225", + "startEpochMicrosec": "@timestamp@", + "lastEpochMicrosec": "@timestamp@", + "nfNamingCode": "", + "nfVendorName": "ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/mfg-name", + "timeZoneOffset": "+00:00", + "version": "4.1", + "vesEventListenerVersion": "7.2.1" + }, + "faultFields": { + "faultFieldsVersion": "4.0", + "alarmCondition": "1", + "alarmInterfaceA": "o-ran-fm:alarm-notif/fault-source", + "eventSourceType": "ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/mfg-model or \"O-RU\"", + "specificProblem": "", + "eventSeverity": "NORMAL", + "vfStatus": "Active", + "alarmAdditionalInformation": { + "eventTime": "@eventTime@", + "equipType": "@type@", + "vendor": "@vendor@", + "model": "@model@" + } + } + } +} \ No newline at end of file diff --git a/test/usecases/LinkMonitor/models/CreateLinkClearedOutfieldsLogic.js b/test/usecases/LinkMonitor/models/CreateLinkClearedOutfieldsLogic.js new file mode 100644 index 00000000..e521c8e2 --- /dev/null +++ b/test/usecases/LinkMonitor/models/CreateLinkClearedOutfieldsLogic.js @@ -0,0 +1,30 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info("Task Execution: '"+executor.subject.id+"'. Input Fields: '"+executor.inFields+"'"); + +var linkFailureInput = executor.inFields.get("LinkFailureInput"); +var oruId = linkFailureInput.get("event").get("commonEventHeader").get("sourceName"); + +executor.outFields.put("OruId", oruId); + +executor.logger.info(executor.outFields); + +true; diff --git a/test/usecases/LinkMonitor/models/CreateLinkFailureOutfieldsLogic.js b/test/usecases/LinkMonitor/models/CreateLinkFailureOutfieldsLogic.js new file mode 100644 index 00000000..ae753ca7 --- /dev/null +++ b/test/usecases/LinkMonitor/models/CreateLinkFailureOutfieldsLogic.js @@ -0,0 +1,47 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info("Task Execution: '"+executor.subject.id+"'. Input Fields: '"+executor.inFields+"'"); + +var fileReaderClass = java.io.FileReader; +var bufferedReaderClass = java.io.BufferedReader; +var oruOduMap; +try { + var br = new bufferedReaderClass(new fileReaderClass("/home/apexuser/examples/LinkMonitor/config/o-ru-to-o-du-map.json")); + var jsonString = ""; + var line; + while ((line = br.readLine()) != null) { + jsonString += line; + } + oruOduMap = JSON.parse(jsonString); +} catch (err) { + executor.logger.info("Failed to read o-ru-to-o-du-map.json file " + err); +} + +var linkFailureInput = executor.inFields.get("LinkFailureInput"); +var oruId = linkFailureInput.get("event").get("commonEventHeader").get("sourceName"); +var oduId = oruOduMap[oruId]; + +executor.outFields.put("OruId", oruId); +executor.outFields.put("OduId", oduId); + +executor.logger.info(executor.outFields); + +true; diff --git a/test/usecases/LinkMonitor/models/LinkClearedLogic.js b/test/usecases/LinkMonitor/models/LinkClearedLogic.js new file mode 100644 index 00000000..59453edf --- /dev/null +++ b/test/usecases/LinkMonitor/models/LinkClearedLogic.js @@ -0,0 +1,29 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info("Task Execution: '"+executor.subject.id+"'. Input Fields: '"+executor.inFields+"'"); + +var oruId = executor.inFields.get("OruId"); + +executor.outFields.put("message", "CLEARED link failure for O-RU: " + oruId); + +executor.logger.info(executor.outFields); + +true; diff --git a/test/usecases/LinkMonitor/models/LinkFailureLogic.js b/test/usecases/LinkMonitor/models/LinkFailureLogic.js new file mode 100644 index 00000000..16fd06ae --- /dev/null +++ b/test/usecases/LinkMonitor/models/LinkFailureLogic.js @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info("Task Execution: '"+executor.subject.id+"'. Input Fields: '"+executor.inFields+"'"); + +var linkFailureOutput = executor.subject.getOutFieldSchemaHelper("LinkFailureOutput").createNewInstance(); + +var oruId = executor.inFields.get("OruId"); +var oduId = executor.inFields.get("OduId"); + +var unlockMessageArray = new java.util.ArrayList(); +for (var i = 0; i < 1; i++) { + unlockMessageArray.add({ + "name" : oruId, + "administrative_DasH_state" : "UNLOCKED" + }); +} + +linkFailureOutput.put("o_DasH_ran_DasH_sc_DasH_du_DasH_hello_DasH_world_ColoN_du_DasH_to_DasH_ru_DasH_connection", unlockMessageArray); +executor.outFields.put("LinkFailureOutput", linkFailureOutput.toString()); + +executor.getExecutionProperties().setProperty("OduId", oduId); +executor.getExecutionProperties().setProperty("OruId", oruId); + +executor.logger.info(executor.outFields); + +true; diff --git a/test/usecases/LinkMonitor/models/LinkMonitorModelJavascript_0.0.1.apex b/test/usecases/LinkMonitor/models/LinkMonitorModelJavascript_0.0.1.apex new file mode 100644 index 00000000..91e73d18 --- /dev/null +++ b/test/usecases/LinkMonitor/models/LinkMonitorModelJavascript_0.0.1.apex @@ -0,0 +1,132 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2021 Nordix Foundation. +# ================================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= +#------------------------------------------------------------------------------- + +##### Model ##### + +model create name=LinkMonitorModel version=0.0.1 uuid=540226fb-55ee-4f0e-a444-983a0494818e description="This is the Apex Policy Model for link monitoring." + + +##### Schemas ##### + +schema create name=LinkFailureInputSchema flavour=Avro schema=LS +#MACROFILE:"examples/LinkMonitor/schemas/LinkFailureInputSchema.avsc" +LE +schema create name=LinkFailureOutputSchema flavour=Avro schema=LS +#MACROFILE:"examples/LinkMonitor/schemas/LinkFailureOutputSchema.avsc" +LE +schema create name=MessageSchema description="A schema for messages from apex" flavour=Java schema=java.lang.String +schema create name=OruIdSchema description="A schema for O-RU-ID" flavour=Java schema=java.lang.String +schema create name=OduIdSchema description="A schema for O-DU-ID" flavour=Java schema=java.lang.String + + +##### Tasks ##### + +task create name=LinkFailureTask version=0.0.1 uuid=3351b0f4-cf06-4fa2-8823-edf67bd30223 description=LS +This task updates the config for O-RU when link failure is detected. +LE +task inputfield create name=LinkFailureTask fieldName=OruId schemaName=OruIdSchema +task inputfield create name=LinkFailureTask fieldName=OduId schemaName=OduIdSchema +task outputfield create name=LinkFailureTask fieldName=LinkFailureOutput schemaName=LinkFailureOutputSchema +task logic create name=LinkFailureTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"examples/LinkMonitor/models/LinkFailureLogic.js" +LE + +task create name=LinkClearedTask version=0.0.1 uuid=eecfde90-896c-4343-8f9c-2603ced94e2d description=LS +This task sends a message to the output when link failure is cleared. +LE +task inputfield create name=LinkClearedTask fieldName=OruId schemaName=OruIdSchema +task outputfield create name=LinkClearedTask fieldName=message schemaName=MessageSchema +task logic create name=LinkClearedTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"examples/LinkMonitor/models/LinkClearedLogic.js" +LE + +task create name=NoPolicyDefinedTask version=0.0.1 uuid=d48b619e-d00d-4008-b884-02d76ea4350b description=LS +This task sends a message to the output when an event is received for which no policy has been defined. +LE +task inputfield create name=NoPolicyDefinedTask fieldName=LinkFailureInput schemaName=LinkFailureInputSchema +task outputfield create name=NoPolicyDefinedTask fieldName=message schemaName=MessageSchema +task logic create name=NoPolicyDefinedTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"examples/LinkMonitor/models/NoPolicyDefinedLogic.js" +LE + +task create name=CreateLinkClearedOutfieldsTask version=0.0.1 uuid=fd594e88-411d-4a94-b2be-697b3a0d7adf description=LS +This task creates the output fields when link failure is cleared. +LE +task inputfield create name=CreateLinkClearedOutfieldsTask fieldName=LinkFailureInput schemaName=LinkFailureInputSchema +task outputfield create name=CreateLinkClearedOutfieldsTask fieldName=OruId schemaName=OruIdSchema +task logic create name=CreateLinkClearedOutfieldsTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"examples/LinkMonitor/models/CreateLinkClearedOutfieldsLogic.js" +LE + +task create name=CreateLinkFailureOutfieldsTask version=0.0.1 uuid=ac3d9842-80af-4a98-951c-bd79a431c613 description=LS +This task the output fields when link failure is detected. +LE +task inputfield create name=CreateLinkFailureOutfieldsTask fieldName=LinkFailureInput schemaName=LinkFailureInputSchema +task outputfield create name=CreateLinkFailureOutfieldsTask fieldName=OruId schemaName=OruIdSchema +task outputfield create name=CreateLinkFailureOutfieldsTask fieldName=OduId schemaName=OduIdSchema +task logic create name=CreateLinkFailureOutfieldsTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"examples/LinkMonitor/models/CreateLinkFailureOutfieldsLogic.js" +LE + + +##### Events ##### + +event create name=LinkFailureInputEvent version=0.0.1 uuid=c4500941-3f98-4080-a9cc-5b9753ed050b source=DMAAP target=APEX +event parameter create name=LinkFailureInputEvent parName=LinkFailureInput schemaName=LinkFailureInputSchema + +event create name=LinkFailureOutputEvent version=0.0.1 uuid=4f04aa98-e917-4f4a-882a-c75ba5a99374 source="APEX" target="OAM" +event parameter create name=LinkFailureOutputEvent parName=LinkFailureOutput schemaName=LinkFailureOutputSchema + +event create name=ApexMessageOutputEvent version=0.0.1 uuid=cca47d74-7754-4a61-b163-ca31f66b157b source="APEX" target="APEX" +event parameter create name=ApexMessageOutputEvent parName=message schemaName=MessageSchema + +event create name=CreateLinkClearedOutfieldsEvent version=0.0.1 source="APEX" target="APEX" +event parameter create name=CreateLinkClearedOutfieldsEvent parName=OruId schemaName=OruIdSchema + +event create name=CreateLinkFailureOutfieldsEvent version=0.0.1 source="APEX" target="APEX" +event parameter create name=CreateLinkFailureOutfieldsEvent parName=OruId schemaName=OruIdSchema +event parameter create name=CreateLinkFailureOutfieldsEvent parName=OduId schemaName=OduIdSchema + + +##### Policy ##### + +policy create name=LinkMonitorPolicy version=0.0.1 uuid=6c5e410f-489a-46ff-964e-982ce6e8b6d0 template=Freestyle firstState=LinkFailureOrClearedState + + +##### States ##### + +policy state create name=LinkMonitorPolicy stateName=LinkFailureState triggerName=CreateLinkFailureOutfieldsEvent defaultTaskName=LinkFailureTask +policy state output create name=LinkMonitorPolicy stateName=LinkFailureState outputName=LinkFailureLogic_Output_Direct eventName=LinkFailureOutputEvent nextState=NULL +policy state taskref create name=LinkMonitorPolicy stateName=LinkFailureState taskLocalName=LinkFailureTask taskName=LinkFailureTask outputType=DIRECT outputName=LinkFailureLogic_Output_Direct + +policy state create name=LinkMonitorPolicy stateName=LinkClearedState triggerName=CreateLinkClearedOutfieldsEvent defaultTaskName=LinkClearedTask +policy state output create name=LinkMonitorPolicy stateName=LinkClearedState outputName=LinkClearedLogic_Output_Direct eventName=ApexMessageOutputEvent nextState=NULL +policy state taskref create name=LinkMonitorPolicy stateName=LinkClearedState taskLocalName=LinkClearedTask taskName=LinkClearedTask outputType=DIRECT outputName=LinkClearedLogic_Output_Direct + +policy state create name=LinkMonitorPolicy stateName=LinkFailureOrClearedState triggerName=LinkFailureInputEvent defaultTaskName=NoPolicyDefinedTask +policy state output create name=LinkMonitorPolicy stateName=LinkFailureOrClearedState outputName=CreateLinkFailureOutfieldsLogic_Output_Direct eventName=CreateLinkFailureOutfieldsEvent nextState=LinkFailureState +policy state taskref create name=LinkMonitorPolicy stateName=LinkFailureOrClearedState taskLocalName=CreateLinkFailureOutfieldsTask taskName=CreateLinkFailureOutfieldsTask outputType=DIRECT outputName=CreateLinkFailureOutfieldsLogic_Output_Direct +policy state output create name=LinkMonitorPolicy stateName=LinkFailureOrClearedState outputName=CreateLinkClearedOutfieldsLogic_Output_Direct eventName=CreateLinkClearedOutfieldsEvent nextState=LinkClearedState +policy state taskref create name=LinkMonitorPolicy stateName=LinkFailureOrClearedState taskLocalName=CreateLinkClearedOutfieldsTask taskName=CreateLinkClearedOutfieldsTask outputType=DIRECT outputName=CreateLinkClearedOutfieldsLogic_Output_Direct +policy state output create name=LinkMonitorPolicy stateName=LinkFailureOrClearedState outputName=NoPolicyDefinedLogic_Output_Direct eventName=ApexMessageOutputEvent nextState=NULL +policy state taskref create name=LinkMonitorPolicy stateName=LinkFailureOrClearedState taskLocalName=NoPolicyDefinedTask taskName=NoPolicyDefinedTask outputType=DIRECT outputName=NoPolicyDefinedLogic_Output_Direct +policy state selecttasklogic create name=LinkMonitorPolicy version=0.0.1 stateName=LinkFailureOrClearedState logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"examples/LinkMonitor/models/TaskSelectionLogic.js" +LE diff --git a/test/usecases/LinkMonitor/models/NoPolicyDefinedLogic.js b/test/usecases/LinkMonitor/models/NoPolicyDefinedLogic.js new file mode 100644 index 00000000..0378b40b --- /dev/null +++ b/test/usecases/LinkMonitor/models/NoPolicyDefinedLogic.js @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info("Task Execution: '"+executor.subject.id+"'. Input Fields: '"+executor.inFields+"'"); + +executor.outFields.put("message", "No policy defined for this event"); + +executor.logger.info(executor.outFields); + +true; diff --git a/test/usecases/LinkMonitor/models/TaskSelectionLogic.js b/test/usecases/LinkMonitor/models/TaskSelectionLogic.js new file mode 100644 index 00000000..4d0f359a --- /dev/null +++ b/test/usecases/LinkMonitor/models/TaskSelectionLogic.js @@ -0,0 +1,47 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info("Task Selection Execution: '"+executor.subject.id+ + "'. InputFields: '"+executor.inFields+"'"); + +var linkFailureInput = executor.inFields.get("LinkFailureInput"); +var commonEventHeader = linkFailureInput.get("event").get("commonEventHeader"); +var domain = commonEventHeader.get("domain"); + +taskFailure = executor.subject.getTaskKey("CreateLinkFailureOutfieldsTask"); +taskCleared = executor.subject.getTaskKey("CreateLinkClearedOutfieldsTask"); +taskDefault = executor.subject.getDefaultTaskKey(); + +if (domain == "fault") { + var faultFields = linkFailureInput.get("event").get("faultFields"); + var alarmCondition = faultFields.get("alarmCondition"); + var eventSeverity = faultFields.get("eventSeverity"); + if (alarmCondition == "30" && eventSeverity != "NORMAL") { + taskFailure.copyTo(executor.selectedTask); + } else if (alarmCondition == "30" && eventSeverity == "NORMAL") { + taskCleared.copyTo(executor.selectedTask); + } else { + taskDefault.copyTo(executor.selectedTask); + } +} else { + taskDefault.copyTo(executor.selectedTask); +} + +true; diff --git a/test/usecases/LinkMonitor/models/ToscaPolicy.json b/test/usecases/LinkMonitor/models/ToscaPolicy.json new file mode 100644 index 00000000..66a22be4 --- /dev/null +++ b/test/usecases/LinkMonitor/models/ToscaPolicy.json @@ -0,0 +1 @@ +{"tosca_definitions_version":"tosca_simple_yaml_1_1_0","topology_template":{"policies":[{"onap.policies.native.apex.Test":{"type":"onap.policies.native.Apex","type_version":"1.0.0","name":"onap.policies.native.apex.Test","version":"1.0.0","properties":{"engineServiceParameters":{"name":"LinkMonitorApexEngine","version":"0.0.1","id":101,"instanceCount":4,"deploymentPort":12345,"engineParameters":{"executorParameters":{"JAVASCRIPT":{"parameterClassName":"org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"}},"contextParameters":{"parameterClassName":"org.onap.policy.apex.context.parameters.ContextParameters","schemaParameters":{"Avro":{"parameterClassName":"org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"}}}},"policy_type_impl":{"apexPolicyModel":{"key":{"name":"LinkMonitorModel","version":"0.0.1"},"keyInformation":{"key":{"name":"LinkMonitorModel_KeyInfo","version":"0.0.1"},"keyInfoMap":{"entry":[{"key":{"name":"ApexMessageOutputEvent","version":"0.0.1"},"value":{"key":{"name":"ApexMessageOutputEvent","version":"0.0.1"},"UUID":"cca47d74-7754-4a61-b163-ca31f66b157b","description":"Generated description for concept referred to by key \"ApexMessageOutputEvent:0.0.1\""}},{"key":{"name":"CreateLinkClearedOutfieldsEvent","version":"0.0.1"},"value":{"key":{"name":"CreateLinkClearedOutfieldsEvent","version":"0.0.1"},"UUID":"a295d6a3-1b73-387e-abba-b41e9b608802","description":"Generated description for concept referred to by key \"CreateLinkClearedOutfieldsEvent:0.0.1\""}},{"key":{"name":"CreateLinkClearedOutfieldsTask","version":"0.0.1"},"value":{"key":{"name":"CreateLinkClearedOutfieldsTask","version":"0.0.1"},"UUID":"fd594e88-411d-4a94-b2be-697b3a0d7adf","description":"This task creates the output fields when link failure is cleared."}},{"key":{"name":"CreateLinkFailureOutfieldsEvent","version":"0.0.1"},"value":{"key":{"name":"CreateLinkFailureOutfieldsEvent","version":"0.0.1"},"UUID":"02be2b5d-45b7-3c54-ae54-97f2b5c30125","description":"Generated description for concept referred to by key \"CreateLinkFailureOutfieldsEvent:0.0.1\""}},{"key":{"name":"CreateLinkFailureOutfieldsTask","version":"0.0.1"},"value":{"key":{"name":"CreateLinkFailureOutfieldsTask","version":"0.0.1"},"UUID":"ac3d9842-80af-4a98-951c-bd79a431c613","description":"This task the output fields when link failure is detected."}},{"key":{"name":"LinkClearedTask","version":"0.0.1"},"value":{"key":{"name":"LinkClearedTask","version":"0.0.1"},"UUID":"eecfde90-896c-4343-8f9c-2603ced94e2d","description":"This task sends a message to the output when link failure is cleared."}},{"key":{"name":"LinkFailureInputEvent","version":"0.0.1"},"value":{"key":{"name":"LinkFailureInputEvent","version":"0.0.1"},"UUID":"c4500941-3f98-4080-a9cc-5b9753ed050b","description":"Generated description for concept referred to by key \"LinkFailureInputEvent:0.0.1\""}},{"key":{"name":"LinkFailureInputSchema","version":"0.0.1"},"value":{"key":{"name":"LinkFailureInputSchema","version":"0.0.1"},"UUID":"3b3974fc-3012-3b02-9f33-c9d8eefe4dc1","description":"Generated description for concept referred to by key \"LinkFailureInputSchema:0.0.1\""}},{"key":{"name":"LinkFailureOutputEvent","version":"0.0.1"},"value":{"key":{"name":"LinkFailureOutputEvent","version":"0.0.1"},"UUID":"4f04aa98-e917-4f4a-882a-c75ba5a99374","description":"Generated description for concept referred to by key \"LinkFailureOutputEvent:0.0.1\""}},{"key":{"name":"LinkFailureOutputSchema","version":"0.0.1"},"value":{"key":{"name":"LinkFailureOutputSchema","version":"0.0.1"},"UUID":"2d1a7f6e-eb9a-3984-be1f-283d98111b84","description":"Generated description for concept referred to by key \"LinkFailureOutputSchema:0.0.1\""}},{"key":{"name":"LinkFailureTask","version":"0.0.1"},"value":{"key":{"name":"LinkFailureTask","version":"0.0.1"},"UUID":"3351b0f4-cf06-4fa2-8823-edf67bd30223","description":"This task updates the config for O-RU when link failure is detected."}},{"key":{"name":"LinkMonitorModel","version":"0.0.1"},"value":{"key":{"name":"LinkMonitorModel","version":"0.0.1"},"UUID":"540226fb-55ee-4f0e-a444-983a0494818e","description":"This is the Apex Policy Model for link monitoring."}},{"key":{"name":"LinkMonitorModel_Events","version":"0.0.1"},"value":{"key":{"name":"LinkMonitorModel_Events","version":"0.0.1"},"UUID":"27ad3e7e-fe3b-3bd6-9081-718705c2bcea","description":"Generated description for concept referred to by key \"LinkMonitorModel_Events:0.0.1\""}},{"key":{"name":"LinkMonitorModel_KeyInfo","version":"0.0.1"},"value":{"key":{"name":"LinkMonitorModel_KeyInfo","version":"0.0.1"},"UUID":"ea0b5f58-eefd-358a-9660-840c640bf981","description":"Generated description for concept referred to by key \"LinkMonitorModel_KeyInfo:0.0.1\""}},{"key":{"name":"LinkMonitorModel_Policies","version":"0.0.1"},"value":{"key":{"name":"LinkMonitorModel_Policies","version":"0.0.1"},"UUID":"ee9e0b0f-2b7d-3ab7-9a98-c5ec05ed823d","description":"Generated description for concept referred to by key \"LinkMonitorModel_Policies:0.0.1\""}},{"key":{"name":"LinkMonitorModel_Schemas","version":"0.0.1"},"value":{"key":{"name":"LinkMonitorModel_Schemas","version":"0.0.1"},"UUID":"fa5f9b8f-796c-3c70-84e9-5140c958c4bb","description":"Generated description for concept referred to by key \"LinkMonitorModel_Schemas:0.0.1\""}},{"key":{"name":"LinkMonitorModel_Tasks","version":"0.0.1"},"value":{"key":{"name":"LinkMonitorModel_Tasks","version":"0.0.1"},"UUID":"eec592f7-69d5-39a9-981a-e552f787ed01","description":"Generated description for concept referred to by key \"LinkMonitorModel_Tasks:0.0.1\""}},{"key":{"name":"LinkMonitorPolicy","version":"0.0.1"},"value":{"key":{"name":"LinkMonitorPolicy","version":"0.0.1"},"UUID":"6c5e410f-489a-46ff-964e-982ce6e8b6d0","description":"Generated description for concept referred to by key \"LinkMonitorPolicy:0.0.1\""}},{"key":{"name":"MessageSchema","version":"0.0.1"},"value":{"key":{"name":"MessageSchema","version":"0.0.1"},"UUID":"ac4b34ac-39d6-3393-a267-8d5b84854018","description":"A schema for messages from apex"}},{"key":{"name":"NoPolicyDefinedTask","version":"0.0.1"},"value":{"key":{"name":"NoPolicyDefinedTask","version":"0.0.1"},"UUID":"d48b619e-d00d-4008-b884-02d76ea4350b","description":"This task sends a message to the output when an event is received for which no policy has been defined."}},{"key":{"name":"OduIdSchema","version":"0.0.1"},"value":{"key":{"name":"OduIdSchema","version":"0.0.1"},"UUID":"50662174-a88b-3cbd-91bd-8e91b40b2660","description":"A schema for O-DU-ID"}},{"key":{"name":"OruIdSchema","version":"0.0.1"},"value":{"key":{"name":"OruIdSchema","version":"0.0.1"},"UUID":"54daf32b-015f-39cd-8530-a1175c5553e9","description":"A schema for O-RU-ID"}}]}},"policies":{"key":{"name":"LinkMonitorModel_Policies","version":"0.0.1"},"policyMap":{"entry":[{"key":{"name":"LinkMonitorPolicy","version":"0.0.1"},"value":{"policyKey":{"name":"LinkMonitorPolicy","version":"0.0.1"},"template":"Freestyle","state":{"entry":[{"key":"LinkClearedState","value":{"stateKey":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"NULL","localName":"LinkClearedState"},"trigger":{"name":"CreateLinkClearedOutfieldsEvent","version":"0.0.1"},"stateOutputs":{"entry":[{"key":"LinkClearedLogic_Output_Direct","value":{"key":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkClearedState","localName":"LinkClearedLogic_Output_Direct"},"outgoingEvent":{"name":"ApexMessageOutputEvent","version":"0.0.1"},"nextState":{"parentKeyName":"NULL","parentKeyVersion":"0.0.0","parentLocalName":"NULL","localName":"NULL"}}}]},"contextAlbumReference":[],"taskSelectionLogic":{"key":"NULL","logicFlavour":"UNDEFINED","logic":""},"stateFinalizerLogicMap":{"entry":[]},"defaultTask":{"name":"LinkClearedTask","version":"0.0.1"},"taskReferences":{"entry":[{"key":{"name":"LinkClearedTask","version":"0.0.1"},"value":{"key":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkClearedState","localName":"LinkClearedTask"},"outputType":"DIRECT","output":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkClearedState","localName":"LinkClearedLogic_Output_Direct"}}}]}}},{"key":"LinkFailureOrClearedState","value":{"stateKey":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"NULL","localName":"LinkFailureOrClearedState"},"trigger":{"name":"LinkFailureInputEvent","version":"0.0.1"},"stateOutputs":{"entry":[{"key":"CreateLinkClearedOutfieldsLogic_Output_Direct","value":{"key":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkFailureOrClearedState","localName":"CreateLinkClearedOutfieldsLogic_Output_Direct"},"outgoingEvent":{"name":"CreateLinkClearedOutfieldsEvent","version":"0.0.1"},"nextState":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"NULL","localName":"LinkClearedState"}}},{"key":"CreateLinkFailureOutfieldsLogic_Output_Direct","value":{"key":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkFailureOrClearedState","localName":"CreateLinkFailureOutfieldsLogic_Output_Direct"},"outgoingEvent":{"name":"CreateLinkFailureOutfieldsEvent","version":"0.0.1"},"nextState":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"NULL","localName":"LinkFailureState"}}},{"key":"NoPolicyDefinedLogic_Output_Direct","value":{"key":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkFailureOrClearedState","localName":"NoPolicyDefinedLogic_Output_Direct"},"outgoingEvent":{"name":"ApexMessageOutputEvent","version":"0.0.1"},"nextState":{"parentKeyName":"NULL","parentKeyVersion":"0.0.0","parentLocalName":"NULL","localName":"NULL"}}}]},"contextAlbumReference":[],"taskSelectionLogic":{"key":"TaskSelectionLogic","logicFlavour":"JAVASCRIPT","logic":"/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2021 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(\"Task Selection Execution: '\"+executor.subject.id+\n \"'. InputFields: '\"+executor.inFields+\"'\");\n\nvar linkFailureInput = executor.inFields.get(\"LinkFailureInput\");\n\nvar commonEventHeader = linkFailureInput.get(\"event\").get(\"commonEventHeader\");\nvar domain = commonEventHeader.get(\"domain\");\n\ntaskFailure = executor.subject.getTaskKey(\"CreateLinkFailureOutfieldsTask\");\ntaskCleared = executor.subject.getTaskKey(\"CreateLinkClearedOutfieldsTask\");\ntaskDefault = executor.subject.getDefaultTaskKey();\n\nif (domain == \"fault\") {\n var faultFields = linkFailureInput.get(\"event\").get(\"faultFields\");\n var alarmCondition = faultFields.get(\"alarmCondition\");\n var eventSeverity = faultFields.get(\"eventSeverity\");\n \n if (alarmCondition == \"30\" && eventSeverity != \"NORMAL\") {\n taskFailure.copyTo(executor.selectedTask);\n } else if (alarmCondition == \"30\" && eventSeverity == \"NORMAL\") {\n taskCleared.copyTo(executor.selectedTask);\n } else {\n taskDefault.copyTo(executor.selectedTask);\n }\n} else {\n taskDefault.copyTo(executor.selectedTask);\n}\n\ntrue;"},"stateFinalizerLogicMap":{"entry":[]},"defaultTask":{"name":"NoPolicyDefinedTask","version":"0.0.1"},"taskReferences":{"entry":[{"key":{"name":"CreateLinkClearedOutfieldsTask","version":"0.0.1"},"value":{"key":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkFailureOrClearedState","localName":"CreateLinkClearedOutfieldsTask"},"outputType":"DIRECT","output":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkFailureOrClearedState","localName":"CreateLinkClearedOutfieldsLogic_Output_Direct"}}},{"key":{"name":"CreateLinkFailureOutfieldsTask","version":"0.0.1"},"value":{"key":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkFailureOrClearedState","localName":"CreateLinkFailureOutfieldsTask"},"outputType":"DIRECT","output":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkFailureOrClearedState","localName":"CreateLinkFailureOutfieldsLogic_Output_Direct"}}},{"key":{"name":"NoPolicyDefinedTask","version":"0.0.1"},"value":{"key":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkFailureOrClearedState","localName":"NoPolicyDefinedTask"},"outputType":"DIRECT","output":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkFailureOrClearedState","localName":"NoPolicyDefinedLogic_Output_Direct"}}}]}}},{"key":"LinkFailureState","value":{"stateKey":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"NULL","localName":"LinkFailureState"},"trigger":{"name":"CreateLinkFailureOutfieldsEvent","version":"0.0.1"},"stateOutputs":{"entry":[{"key":"LinkFailureLogic_Output_Direct","value":{"key":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkFailureState","localName":"LinkFailureLogic_Output_Direct"},"outgoingEvent":{"name":"LinkFailureOutputEvent","version":"0.0.1"},"nextState":{"parentKeyName":"NULL","parentKeyVersion":"0.0.0","parentLocalName":"NULL","localName":"NULL"}}}]},"contextAlbumReference":[],"taskSelectionLogic":{"key":"NULL","logicFlavour":"UNDEFINED","logic":""},"stateFinalizerLogicMap":{"entry":[]},"defaultTask":{"name":"LinkFailureTask","version":"0.0.1"},"taskReferences":{"entry":[{"key":{"name":"LinkFailureTask","version":"0.0.1"},"value":{"key":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkFailureState","localName":"LinkFailureTask"},"outputType":"DIRECT","output":{"parentKeyName":"LinkMonitorPolicy","parentKeyVersion":"0.0.1","parentLocalName":"LinkFailureState","localName":"LinkFailureLogic_Output_Direct"}}}]}}}]},"firstState":"LinkFailureOrClearedState"}}]}},"tasks":{"key":{"name":"LinkMonitorModel_Tasks","version":"0.0.1"},"taskMap":{"entry":[{"key":{"name":"CreateLinkClearedOutfieldsTask","version":"0.0.1"},"value":{"key":{"name":"CreateLinkClearedOutfieldsTask","version":"0.0.1"},"inputFields":{"entry":[{"key":"LinkFailureInput","value":{"key":"LinkFailureInput","fieldSchemaKey":{"name":"LinkFailureInputSchema","version":"0.0.1"},"optional":false}}]},"outputFields":{"entry":[{"key":"OruId","value":{"key":"OruId","fieldSchemaKey":{"name":"OruIdSchema","version":"0.0.1"},"optional":false}}]},"taskParameters":{"entry":[]},"contextAlbumReference":[],"taskLogic":{"key":"TaskLogic","logicFlavour":"JAVASCRIPT","logic":"/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2021 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(\"Task Execution: '\"+executor.subject.id+\"'. Input Fields: '\"+executor.inFields+\"'\");\n\nvar linkFailureInput = executor.inFields.get(\"LinkFailureInput\");\n\nvar oruId = linkFailureInput.get(\"event\").get(\"commonEventHeader\").get(\"sourceName\");\n\nexecutor.outFields.put(\"OruId\", oruId);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;"}}},{"key":{"name":"CreateLinkFailureOutfieldsTask","version":"0.0.1"},"value":{"key":{"name":"CreateLinkFailureOutfieldsTask","version":"0.0.1"},"inputFields":{"entry":[{"key":"LinkFailureInput","value":{"key":"LinkFailureInput","fieldSchemaKey":{"name":"LinkFailureInputSchema","version":"0.0.1"},"optional":false}}]},"outputFields":{"entry":[{"key":"OduId","value":{"key":"OduId","fieldSchemaKey":{"name":"OduIdSchema","version":"0.0.1"},"optional":false}},{"key":"OruId","value":{"key":"OruId","fieldSchemaKey":{"name":"OruIdSchema","version":"0.0.1"},"optional":false}}]},"taskParameters":{"entry":[]},"contextAlbumReference":[],"taskLogic":{"key":"TaskLogic","logicFlavour":"JAVASCRIPT","logic":"/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2021 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(\"Task Execution: '\"+executor.subject.id+\"'. Input Fields: '\"+executor.inFields+\"'\");\n\n//const oruOduMap = require('/home/apexuser/examples/LinkMonitor/config/o-ru-to-o-du-map.json')\n\nvar fileReaderClass = java.io.FileReader;\nvar bufferedReaderClass = java.io.BufferedReader;\nvar oruOduMap; \ntry {\n var br = new bufferedReaderClass(new fileReaderClass(\"/home/apexuser/examples/LinkMonitor/config/o-ru-to-o-du-map.json\"));\n var jsonString = \"\";\n var line;\n while ((line = br.readLine()) != null) {\n jsonString += line;\n }\n oruOduMap = JSON.parse(jsonString);\n} catch (err) {\n executor.logger.info(\"Failed to retrieve json file \" + err);\n}\n \nvar linkFailureInput = executor.inFields.get(\"LinkFailureInput\");\n\nvar oruId = linkFailureInput.get(\"event\").get(\"commonEventHeader\").get(\"sourceName\");\n\nvar oduId = oruOduMap[oruId];\n\nexecutor.outFields.put(\"OruId\", oruId);\n\nexecutor.outFields.put(\"OduId\", oduId);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;"}}},{"key":{"name":"LinkClearedTask","version":"0.0.1"},"value":{"key":{"name":"LinkClearedTask","version":"0.0.1"},"inputFields":{"entry":[{"key":"OruId","value":{"key":"OruId","fieldSchemaKey":{"name":"OruIdSchema","version":"0.0.1"},"optional":false}}]},"outputFields":{"entry":[{"key":"message","value":{"key":"message","fieldSchemaKey":{"name":"MessageSchema","version":"0.0.1"},"optional":false}}]},"taskParameters":{"entry":[]},"contextAlbumReference":[],"taskLogic":{"key":"TaskLogic","logicFlavour":"JAVASCRIPT","logic":"/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2021 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(\"Task Execution: '\"+executor.subject.id+\"'. Input Fields: '\"+executor.inFields+\"'\");\n\nvar oruId = executor.inFields.get(\"OruId\");\n\nexecutor.outFields.put(\"message\", \"CLEARED link failure for O-RU: \" + oruId);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;"}}},{"key":{"name":"LinkFailureTask","version":"0.0.1"},"value":{"key":{"name":"LinkFailureTask","version":"0.0.1"},"inputFields":{"entry":[{"key":"OduId","value":{"key":"OduId","fieldSchemaKey":{"name":"OduIdSchema","version":"0.0.1"},"optional":false}},{"key":"OruId","value":{"key":"OruId","fieldSchemaKey":{"name":"OruIdSchema","version":"0.0.1"},"optional":false}}]},"outputFields":{"entry":[{"key":"LinkFailureOutput","value":{"key":"LinkFailureOutput","fieldSchemaKey":{"name":"LinkFailureOutputSchema","version":"0.0.1"},"optional":false}}]},"taskParameters":{"entry":[]},"contextAlbumReference":[],"taskLogic":{"key":"TaskLogic","logicFlavour":"JAVASCRIPT","logic":"/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2021 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(\"Task Execution: '\"+executor.subject.id+\"'. Input Fields: '\"+executor.inFields+\"'\");\n\nvar linkFailureOutput = executor.subject.getOutFieldSchemaHelper(\"LinkFailureOutput\").createNewInstance();\n\nvar oruId = executor.inFields.get(\"OruId\");\nvar oduId = executor.inFields.get(\"OduId\");\n\nvar unlockMessageArray = new java.util.ArrayList();\nfor (var i = 0; i < 1; i++) { \n unlockMessageArray.add({ \n \"name\" : oruId,\n \"administrative_DasH_state\" : \"UNLOCKED\"\n });\n}\n\nlinkFailureOutput.put(\"o_DasH_ran_DasH_sc_DasH_du_DasH_hello_DasH_world_ColoN_du_DasH_to_DasH_ru_DasH_connection\", unlockMessageArray);\nexecutor.outFields.put(\"LinkFailureOutput\", linkFailureOutput.toString());\n\nexecutor.getExecutionProperties().setProperty(\"OduId\", oduId);\nexecutor.getExecutionProperties().setProperty(\"OruId\", oruId);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;"}}},{"key":{"name":"NoPolicyDefinedTask","version":"0.0.1"},"value":{"key":{"name":"NoPolicyDefinedTask","version":"0.0.1"},"inputFields":{"entry":[{"key":"LinkFailureInput","value":{"key":"LinkFailureInput","fieldSchemaKey":{"name":"LinkFailureInputSchema","version":"0.0.1"},"optional":false}}]},"outputFields":{"entry":[{"key":"message","value":{"key":"message","fieldSchemaKey":{"name":"MessageSchema","version":"0.0.1"},"optional":false}}]},"taskParameters":{"entry":[]},"contextAlbumReference":[],"taskLogic":{"key":"TaskLogic","logicFlavour":"JAVASCRIPT","logic":"/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2021 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(\"Task Execution: '\"+executor.subject.id+\"'. Input Fields: '\"+executor.inFields+\"'\");\n\nexecutor.outFields.put(\"message\", \"No policy defined for this event\");\n\nexecutor.logger.info(executor.outFields);\n\ntrue;"}}}]}},"events":{"key":{"name":"LinkMonitorModel_Events","version":"0.0.1"},"eventMap":{"entry":[{"key":{"name":"ApexMessageOutputEvent","version":"0.0.1"},"value":{"key":{"name":"ApexMessageOutputEvent","version":"0.0.1"},"nameSpace":"org.onap.policy.apex.auth.clieditor","source":"APEX","target":"APEX","parameter":{"entry":[{"key":"message","value":{"key":"message","fieldSchemaKey":{"name":"MessageSchema","version":"0.0.1"},"optional":false}}]}}},{"key":{"name":"CreateLinkClearedOutfieldsEvent","version":"0.0.1"},"value":{"key":{"name":"CreateLinkClearedOutfieldsEvent","version":"0.0.1"},"nameSpace":"org.onap.policy.apex.auth.clieditor","source":"APEX","target":"APEX","parameter":{"entry":[{"key":"OruId","value":{"key":"OruId","fieldSchemaKey":{"name":"OruIdSchema","version":"0.0.1"},"optional":false}}]}}},{"key":{"name":"CreateLinkFailureOutfieldsEvent","version":"0.0.1"},"value":{"key":{"name":"CreateLinkFailureOutfieldsEvent","version":"0.0.1"},"nameSpace":"org.onap.policy.apex.auth.clieditor","source":"APEX","target":"APEX","parameter":{"entry":[{"key":"OduId","value":{"key":"OduId","fieldSchemaKey":{"name":"OduIdSchema","version":"0.0.1"},"optional":false}},{"key":"OruId","value":{"key":"OruId","fieldSchemaKey":{"name":"OruIdSchema","version":"0.0.1"},"optional":false}}]}}},{"key":{"name":"LinkFailureInputEvent","version":"0.0.1"},"value":{"key":{"name":"LinkFailureInputEvent","version":"0.0.1"},"nameSpace":"org.onap.policy.apex.auth.clieditor","source":"DMAAP","target":"APEX","parameter":{"entry":[{"key":"LinkFailureInput","value":{"key":"LinkFailureInput","fieldSchemaKey":{"name":"LinkFailureInputSchema","version":"0.0.1"},"optional":false}}]}}},{"key":{"name":"LinkFailureOutputEvent","version":"0.0.1"},"value":{"key":{"name":"LinkFailureOutputEvent","version":"0.0.1"},"nameSpace":"org.onap.policy.apex.auth.clieditor","source":"APEX","target":"OAM","parameter":{"entry":[{"key":"LinkFailureOutput","value":{"key":"LinkFailureOutput","fieldSchemaKey":{"name":"LinkFailureOutputSchema","version":"0.0.1"},"optional":false}}]}}}]}},"schemas":{"key":{"name":"LinkMonitorModel_Schemas","version":"0.0.1"},"schemas":{"entry":[{"key":{"name":"LinkFailureInputSchema","version":"0.0.1"},"value":{"key":{"name":"LinkFailureInputSchema","version":"0.0.1"},"schemaFlavour":"Avro","schemaDefinition":"{\n \"type\": \"record\",\n \"name\": \"Link_Failure_Input\",\n \"fields\": [\n {\n \"name\": \"event\",\n \"type\": {\n \"type\": \"record\",\n \"name\": \"Event_Type\",\n \"fields\": [\n {\n \"name\": \"commonEventHeader\",\n \"type\": {\n \"type\": \"record\",\n \"name\": \"Common_Event_Header_Type\",\n \"fields\": [\n {\n \"name\": \"domain\",\n \"type\": \"string\"\n },\n {\n \"name\": \"eventId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"eventName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"eventType\",\n \"type\": \"string\"\n },\n {\n \"name\": \"sequence\",\n \"type\": \"int\"\n },\n {\n \"name\": \"priority\",\n \"type\": \"string\"\n },\n {\n \"name\": \"reportingEntityId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"reportingEntityName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"sourceId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"sourceName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"startEpochMicrosec\",\n \"type\": \"string\"\n },\n {\n \"name\": \"lastEpochMicrosec\",\n \"type\": \"string\"\n },\n {\n \"name\": \"nfNamingCode\",\n \"type\": \"string\"\n },\n {\n \"name\": \"nfVendorName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"timeZoneOffset\",\n \"type\": \"string\"\n },\n {\n \"name\": \"version\",\n \"type\": \"string\"\n },\n {\n \"name\": \"vesEventListenerVersion\",\n \"type\": \"string\"\n }\n ]\n }\n },\n {\n \"name\": \"faultFields\",\n \"type\": {\n \"type\": \"record\",\n \"name\": \"Fault_Fields_Type\",\n \"fields\": [\n {\n \"name\": \"faultFieldsVersion\",\n \"type\": \"string\"\n },\n {\n \"name\": \"alarmCondition\",\n \"type\": \"string\"\n },\n {\n \"name\": \"alarmInterfaceA\",\n \"type\": \"string\"\n },\n {\n \"name\": \"eventSourceType\",\n \"type\": \"string\"\n },\n {\n \"name\": \"specificProblem\",\n \"type\": \"string\"\n },\n {\n \"name\": \"eventSeverity\",\n \"type\": \"string\"\n },\n {\n \"name\": \"vfStatus\",\n \"type\": \"string\"\n },\n {\n \"name\": \"alarmAdditionalInformation\",\n \"type\": {\n \"type\": \"record\",\n \"name\": \"Alarm_Additional_Information_Type\",\n \"fields\": [\n {\n \"name\": \"eventTime\",\n \"type\": \"string\"\n },\n {\n \"name\": \"equipType\",\n \"type\": \"string\"\n },\n {\n \"name\": \"vendor\",\n \"type\": \"string\"\n },\n {\n \"name\": \"model\",\n \"type\": \"string\"\n }\n ]\n }\n }\n ]\n }\n }\n ]\n }\n }\n ]\n}"}},{"key":{"name":"LinkFailureOutputSchema","version":"0.0.1"},"value":{"key":{"name":"LinkFailureOutputSchema","version":"0.0.1"},"schemaFlavour":"Avro","schemaDefinition":"{\n \"type\": \"record\",\n \"name\": \"Link_Failure_Output\",\n \"fields\": [\n {\n \"name\": \"o_DasH_ran_DasH_sc_DasH_du_DasH_hello_DasH_world_ColoN_du_DasH_to_DasH_ru_DasH_connection\",\n \"type\": {\n \t\"type\": \"array\",\n \t\"items\": {\n\t\t \"name\": \"Config_Change_Message\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"name\",\n \"type\": \"string\"\n },\n\t\t\t{\n \"name\": \"administrative_DasH_state\",\n \"type\": \"string\"\n }\n ]\n }\n\t }\n }\n ]\n}"}},{"key":{"name":"MessageSchema","version":"0.0.1"},"value":{"key":{"name":"MessageSchema","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.String"}},{"key":{"name":"OduIdSchema","version":"0.0.1"},"value":{"key":{"name":"OduIdSchema","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.String"}},{"key":{"name":"OruIdSchema","version":"0.0.1"},"value":{"key":{"name":"OruIdSchema","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.String"}}]}}}}},"eventOutputParameters":{"RestProducer":{"carrierTechnologyParameters":{"carrierTechnology":"RESTCLIENT","parameterClassName":"org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters","parameters":{"url":"http://sdnr-sim:9990/rests/data/network-topology:network-topology/topology=topology-netconf/node={OduId}/yang-ext:mount/o-ran-sc-du-hello-world:network-function/du-to-ru-connection={OruId}"}},"eventProtocolParameters":{"eventProtocol":"JSON","parameters":{"pojoField":"LinkFailureOutput"}},"eventNameFilter":"LinkFailureOutputEvent"},"StdOutProducer":{"carrierTechnologyParameters":{"carrierTechnology":"FILE","parameters":{"standardIo":true}},"eventProtocolParameters":{"eventProtocol":"JSON"}}},"eventInputParameters":{"DMaaPConsumer":{"carrierTechnologyParameters":{"carrierTechnology":"RESTCLIENT","parameterClassName":"org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters","parameters":{"url":"http://dmaap-mr:3904/events/unauthenticated.SEC_FAULT_OUTPUT/users/link-monitor-nonrtric?timeout=15000&limit=100"}},"eventProtocolParameters":{"eventProtocol":"JSON","parameters":{"versionAlias":"version","pojoField":"LinkFailureInput"}},"eventName":"LinkFailureInputEvent"}}}}}]}} \ No newline at end of file diff --git a/test/usecases/LinkMonitor/schemas/LinkFailureInputSchema.avsc b/test/usecases/LinkMonitor/schemas/LinkFailureInputSchema.avsc new file mode 100644 index 00000000..258b9fab --- /dev/null +++ b/test/usecases/LinkMonitor/schemas/LinkFailureInputSchema.avsc @@ -0,0 +1,154 @@ +{ + "type": "record", + "name": "Link_Failure_Input", + "fields": [ + { + "name": "event", + "type": { + "type": "record", + "name": "Event_Type", + "fields": [ + { + "name": "commonEventHeader", + "type": { + "type": "record", + "name": "Common_Event_Header_Type", + "fields": [ + { + "name": "domain", + "type": "string" + }, + { + "name": "eventId", + "type": "string" + }, + { + "name": "eventName", + "type": "string" + }, + { + "name": "eventType", + "type": "string" + }, + { + "name": "sequence", + "type": "int" + }, + { + "name": "priority", + "type": "string" + }, + { + "name": "reportingEntityId", + "type": "string" + }, + { + "name": "reportingEntityName", + "type": "string" + }, + { + "name": "sourceId", + "type": "string" + }, + { + "name": "sourceName", + "type": "string" + }, + { + "name": "startEpochMicrosec", + "type": "string" + }, + { + "name": "lastEpochMicrosec", + "type": "string" + }, + { + "name": "nfNamingCode", + "type": "string" + }, + { + "name": "nfVendorName", + "type": "string" + }, + { + "name": "timeZoneOffset", + "type": "string" + }, + { + "name": "version", + "type": "string" + }, + { + "name": "vesEventListenerVersion", + "type": "string" + } + ] + } + }, + { + "name": "faultFields", + "type": { + "type": "record", + "name": "Fault_Fields_Type", + "fields": [ + { + "name": "faultFieldsVersion", + "type": "string" + }, + { + "name": "alarmCondition", + "type": "string" + }, + { + "name": "alarmInterfaceA", + "type": "string" + }, + { + "name": "eventSourceType", + "type": "string" + }, + { + "name": "specificProblem", + "type": "string" + }, + { + "name": "eventSeverity", + "type": "string" + }, + { + "name": "vfStatus", + "type": "string" + }, + { + "name": "alarmAdditionalInformation", + "type": { + "type": "record", + "name": "Alarm_Additional_Information_Type", + "fields": [ + { + "name": "eventTime", + "type": "string" + }, + { + "name": "equipType", + "type": "string" + }, + { + "name": "vendor", + "type": "string" + }, + { + "name": "model", + "type": "string" + } + ] + } + } + ] + } + } + ] + } + } + ] +} \ No newline at end of file diff --git a/test/usecases/LinkMonitor/schemas/LinkFailureOutputSchema.avsc b/test/usecases/LinkMonitor/schemas/LinkFailureOutputSchema.avsc new file mode 100644 index 00000000..fb144a1d --- /dev/null +++ b/test/usecases/LinkMonitor/schemas/LinkFailureOutputSchema.avsc @@ -0,0 +1,26 @@ +{ + "type": "record", + "name": "Link_Failure_Output", + "fields": [ + { + "name": "o_DasH_ran_DasH_sc_DasH_du_DasH_hello_DasH_world_ColoN_du_DasH_to_DasH_ru_DasH_connection", + "type": { + "type": "array", + "items": { + "name": "Config_Change_Message", + "type": "record", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "administrative_DasH_state", + "type": "string" + } + ] + } + } + } + ] +} diff --git a/test/usecases/LinkMonitor/tosca/ToscaTemplate.json b/test/usecases/LinkMonitor/tosca/ToscaTemplate.json new file mode 100644 index 00000000..a22d9a94 --- /dev/null +++ b/test/usecases/LinkMonitor/tosca/ToscaTemplate.json @@ -0,0 +1,17 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", + "topology_template": { + "policies": [ + { + "onap.policies.native.apex.Test": { + "type": "onap.policies.native.Apex", + "type_version": "1.0.0", + "name": "onap.policies.native.apex.Test", + "version": "1.0.0", + "properties": { + } + } + } + ] + } +} \ No newline at end of file