/root> #-------------------------------------------------------------------------------
/root> # ============LICENSE_START=======================================================
/root> #  Copyright (C) 2020 Nordix Foundation.
/root> # ================================================================================
/root> # Licensed under the Apache License, Version 2.0 (the "License");
/root> # you may not use this file except in compliance with the License.
/root> # You may obtain a copy of the License at
/root> #
/root> #      http://www.apache.org/licenses/LICENSE-2.0
/root> #
/root> # Unless required by applicable law or agreed to in writing, software
/root> # distributed under the License is distributed on an "AS IS" BASIS,
/root> # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/root> # See the License for the specific language governing permissions and
/root> # limitations under the License.
/root> #
/root> # SPDX-License-Identifier: Apache-2.0
/root> # ============LICENSE_END=========================================================
/root> #-------------------------------------------------------------------------------
/root> 
/root> model create name=ONAPvCPEPolicyModelStandalone
result: SUCCESS

/root> 
/root> schema create name=SimpleStringType  flavour=Java schema=java.lang.String
result: SUCCESS

/root> schema create name=SimpleLongType    flavour=Java schema=java.lang.Long
result: SUCCESS

/root> schema create name=SimpleBooleanType flavour=Java schema=java.lang.Boolean
result: SUCCESS

/root> schema create name=UUIDType          flavour=Java schema=java.util.UUID
result: SUCCESS

/root> 
/root> schema create name=VirtualControlLoopEventType flavour=Avro schema=LS
{
    "type": "record",
    "name": "VirtualControlLoopEvent",
    "fields": [
        {
            "name": "requestID",
            "type": "string"
        },
        {
            "name": "target_type",
            "type": "string"
        },
        {
            "name": "closedLoopControlName",
            "type": "string"
        },
        {
            "name": "version",
            "type": "string"
        },
        {
            "name": "closedLoopEventClient",
            "type": "string"
        },
        {
            "name": "target",
            "type": "string"
        },
        {
            "name": "from",
            "type": "string"
        },
        {
            "name": "policyScope",
            "type": "string"
        },
        {
            "name": "policyName",
            "type": "string"
        },
        {
            "name": "policyVersion",
            "type": "string"
        },
        {
            "name": "closedLoopEventStatus",
            "type": "string"
        },
        {
            "name": "additionalEventParams",
            "type": {
                "type": "map",
                "values": "string"
            }
        },
        {
            "name": "AAI",
            "type": {
                "type": "map",
                "values": "string"
            }
        },
        {
            "name": "payload",
            "type": "string"
        },
        {
            "name": "closedLoopAlarmStart",
            "type": "long"
        },
        {
            "name": "closedLoopAlarmEnd",
            "type": "long"
        }
    ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=VirtualControlLoopNotificationType flavour=Avro schema=LS
{
    "type": "record",
    "name": "VirtualControlLoopNotification",
    "fields": [
        {
            "name": "closedLoopControlName",
            "type": "string"
        },
        {
            "name": "version",
            "type": "string"
        },
        {
            "name": "requestID",
            "type": "string"
        },
        {
            "name": "closedLoopEventClient",
            "type": "string"
        },
        {
            "name": "targetType",
            "type": "string"
        },
        {
            "name": "target",
            "type": "string"
        },
        {
            "name": "from",
            "type": "string"
        },
        {
            "name": "policyScope",
            "type": "string"
        },
        {
            "name": "policyName",
            "type": "string"
        },
        {
            "name": "policyVersion",
            "type": "string"
        },
        {
            "name": "notification",
            "type": "string"
        },
        {
            "name": "message",
            "type": "string"
        },
        {
            "name": "notificationTime",
            "type": "long"
        },
        {
            "name": "opsClTimer",
            "type": "int"
        },
        {
            "name": "AAI",
            "type": {
                "type": "map",
                "values": "string"
            }
        },
        {
            "name": "closedLoopAlarmStart",
            "type": "long"
        },
        {
            "name": "closedLoopAlarmEnd",
            "type": "long"
        }
    ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=ControllerRequestType flavour=Avro schema=LS
{
    "type": "record",
    "name": "VCPEClosedLoopStatus",
    "fields": [
        {
            "name": "version",
            "type": "string"
        },
        {
            "name": "rpc_DasH_name",
            "type": "string"
        },
        {
            "name": "correlation_DasH_id",
            "type": "string"
        },
        {
            "name": "type",
            "type": "string"
        },
        {
            "name": "body",
            "type": {
                "type": "record",
                "name": "Controller_Body_Type",
                "namespace": "org.onap.policy.apex.onap.vcpe",
                "fields": [
                    {
                        "name": "input",
                        "type": {
                            "type": "record",
                            "name": "Controller_Body_Type_Input",
                            "namespace": "org.onap.policy.apex.onap.vcpe",
                            "fields": [
                                {
                                    "name": "action",
                                    "type": "string"
                                },
                                {
                                    "name": "action_DasH_identifiers",
                                    "type": {
                                        "type": "map",
                                        "values": "string"
                                    }
                                },
                                {
                                    "name": "common_DasH_header",
                                    "type": {
                                        "type": "record",
                                        "name": "Controller_Body_Type_Common_Header",
                                        "namespace": "org.onap.policy.apex.onap.vcpe",
                                        "fields": [
                                            {
                                                "name": "timestamp",
                                                "type": "long"
                                            },
                                            {
                                                "name": "api_DasH_ver",
                                                "type": "string"
                                            },
                                            {
                                                "name": "originator_DasH_id",
                                                "type": "string"
                                            },
                                            {
                                                "name": "request_DasH_id",
                                                "type": "string"
                                            },
                                            {
                                                "name": "sub_DasH_request_DasH_id",
                                                "type": "string"
                                            },
                                            {
                                                "name": "flags",
                                                "type": {
                                                    "type": "map",
                                                    "values": "string"
                                                }
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=ControllerResponseType flavour=Avro schema=LS
{
    "type": "record",
    "name": "VCPEClosedLoopStatus",
    "fields": [
        {
            "name": "version",
            "type": "string"
        },
        {
            "name": "rpc_DasH_name",
            "type": "string"
        },
        {
            "name": "correlation_DasH_id",
            "type": "string"
        },
        {
            "name": "type",
            "type": "string"
        },
        {
            "name": "body",
            "type": {
                "type": "record",
                "name": "Controller_Body_Type",
                "namespace": "org.onap.policy.apex.onap.vcpe",
                "fields": [
                    {
                        "name": "output",
                        "type": {
                            "type": "record",
                            "name": "Controller_Body_Type_Output",
                            "namespace": "org.onap.policy.apex.onap.vcpe",
                            "fields": [
                                {
                                    "name": "payload",
                                    "type": "string"
                                },
                                {
                                    "name": "common_DasH_header",
                                    "type": {
                                        "type": "record",
                                        "name": "Controller_Body_Type_Common_Header",
                                        "namespace": "org.onap.policy.apex.onap.vcpe",
                                        "fields": [
                                            {
                                                "name": "timestamp",
                                                "type": "long"
                                            },
                                            {
                                                "name": "api_DasH_ver",
                                                "type": "string"
                                            },
                                            {
                                                "name": "originator_DasH_id",
                                                "type": "string"
                                            },
                                            {
                                                "name": "request_DasH_id",
                                                "type": "string"
                                            },
                                            {
                                                "name": "sub_DasH_request_DasH_id",
                                                "type": "string"
                                            },
                                            {
                                                "name": "flags",
                                                "type": {
                                                    "type": "map",
                                                    "values": "string"
                                                }
                                            }
                                        ]
                                    }
                                },
                                {
                                    "name": "status",
                                    "type": {
                                        "type": "record",
                                        "name": "Controller_Body_Type_Output_Status",
                                        "namespace": "org.onap.policy.apex.onap.vcpe",
                                        "fields": [
                                            {
                                                "name": "code",
                                                "type": "int"
                                            },
                                            {
                                                "name": "message",
                                                "type": "string"
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=ControlLoopStatusType flavour=Avro schema=LS
{
    "type": "record",
    "name": "VCPEClosedLoopStatus",
    "fields": [
        {
            "name": "AAI",
            "type": {
                "type": "record",
                "name": "VCPE_AAI_Type",
                "namespace": "org.onap.policy.apex.onap.vcpe",
                "fields": [
                    {
                        "name": "genericVnfResourceVersion",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfVnfName",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfProvStatus",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfIsClosedLoopDisabled",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfOrchestrationStatus",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfVnfType",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfInMaint",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfServiceId",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfVnfId",
                        "type": "string"
                    },
                    {
                        "name": "vserverIsClosedLoopDisabled",
                        "type": "string"
                    },
                    {
                        "name": "vserverName",
                        "type": "string"
                    },
                    {
                        "name": "vserverProvStatus",
                        "type": "string"
                    }
                ]
            }
        },
        {
            "name": "closedLoopAlarmStart",
            "type": "long"
        },
        {
            "name": "closedLoopAlarmEnd",
            "type": "long"
        },
        {
            "name": "closedLoopControlName",
            "type": "string"
        },
        {
            "name": "version",
            "type": "string"
        },
        {
            "name": "requestID",
            "type": "string"
        },
        {
            "name": "closedLoopEventClient",
            "type": "string"
        },
        {
            "name": "closedLoopEventStatus",
            "type": "string"
        },
        {
            "name": "target_type",
            "type": "string"
        },
        {
            "name": "target",
            "type": "string"
        },
        {
            "name": "from",
            "type": "string"
        },
        {
            "name": "policyScope",
            "type": "string"
        },
        {
            "name": "policyName",
            "type": "string"
        },
        {
            "name": "policyVersion",
            "type": "string"
        },
        {
            "name": "notification",
            "type": "string"
        },
        {
            "name": "notificationTime",
            "type": "long"
        },
        {
            "name": "message",
            "type": "string"
        }
    ]
}
LE
result: SUCCESS

/root> 
/root> schema create name=ActionEventListType flavour=Java schema=org.onap.policy.apex.service.engine.event.ApexEventList
result: SUCCESS

/root> 
/root> album create name=ControlLoopStatusAlbum scope=policy writable=true schemaName=ControlLoopStatusType
result: SUCCESS

/root> 
/root> album create name=RequestIDVNFIDAlbum scope=policy writable=true schemaName=UUIDType
result: SUCCESS

/root> 
/root> album create name=VnfIdWhiteBlackListAlbum scope=policy writable=true schemaName=SimpleBooleanType
result: SUCCESS

/root> album create name=ServiceIdWhiteBlackListAlbum scope=policy writable=true schemaName=SimpleBooleanType
result: SUCCESS

/root> album create name=VServerIdWhiteBlackListAlbum scope=policy writable=true schemaName=SimpleBooleanType
result: SUCCESS

/root> 
/root> event create name=VirtualControlLoopEvent version=1.0.2 nameSpace=org.onap.policy.apex.onap.vcpe source=Analytics target=APEX
result: SUCCESS

/root> event parameter create name=VirtualControlLoopEvent parName=VirtualControlLoopEvent schemaName=VirtualControlLoopEventType
result: SUCCESS

/root> 
/root> event create name=EntityStateUpdatedEvent nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=EntityStateUpdatedEvent parName=requestID schemaName=UUIDType
result: SUCCESS

/root> event parameter create name=EntityStateUpdatedEvent parName=vnfID     schemaName=UUIDType
result: SUCCESS

/root> event parameter create name=EntityStateUpdatedEvent parName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS

/root> 
/root> event create name=ActionEventListEvent nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=ActionEventListEvent parName=ActionEventList schemaName=ActionEventListType
result: SUCCESS

/root> 
/root> event create name=ActionEvent nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=ActionEvent parName=action   schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=ActionEvent parName=requestID schemaName=UUIDType
result: SUCCESS

/root> event parameter create name=ActionEvent parName=vnfID     schemaName=UUIDType
result: SUCCESS

/root> event parameter create name=ActionEvent parName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS

/root> 
/root> event create name=ControllerRequestEvent version="2.0.0" nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=Controller
result: SUCCESS

/root> event parameter create name=ControllerRequestEvent parName=ControllerRequest schemaName=ControllerRequestType
result: SUCCESS

/root> 
/root> event create name=ControllerResponseEvent version="2.0.0" nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APPC
result: SUCCESS

/root> event parameter create name=ControllerResponseEvent parName=ControllerResponse schemaName=ControllerResponseType
result: SUCCESS

/root> 
/root> event create name=ControlLoopLogEvent nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=ControlLoopLogEvent parName=VirtualControlLoopNotification schemaName=VirtualControlLoopNotificationType
result: SUCCESS

/root> 
/root> event create name=ConfigureBlackWhiteListEvent nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=ConfigureBlackWhiteListEvent parName=targetType schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=ConfigureBlackWhiteListEvent parName=target schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=ConfigureBlackWhiteListEvent parName=black schemaName=SimpleBooleanType
result: SUCCESS

/root> 
/root> event create name=ConfigureBlackWhiteListResultEvent nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=ConfigureBlackWhiteListResultEvent parName=targetType schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=ConfigureBlackWhiteListResultEvent parName=target schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=ConfigureBlackWhiteListResultEvent parName=black schemaName=SimpleBooleanType
result: SUCCESS

/root> 
/root> task create name=GetEntityStateTask
result: SUCCESS

/root> 
/root> task inputfield create name=GetEntityStateTask fieldName=VirtualControlLoopEvent schemaName=VirtualControlLoopEventType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=GetEntityStateTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=GetEntityStateTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=GetEntityStateTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=GetEntityStateTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> task contextref create name=GetEntityStateTask albumName=RequestIDVNFIDAlbum
result: SUCCESS

/root> 
/root> task logic create name=GetEntityStateTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 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.
 *
 * Note: The incoming closedloop message can be ONSET with both VNF-name and VNF-ID
 *       or ABATED with only VNF-name. So need to handle differently. For ABATED case,
 *       since we still keep the RequireIDVNFID context album, we can get it from there.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);

var utf8Type = org.apache.avro.util.Utf8;
var uuidType = java.util.UUID;

var clEvent = executor.inFields.get("VirtualControlLoopEvent");

executor.logger.info(clEvent.toString());
executor.logger.info(clEvent.get("closedLoopControlName"));

var requestID = uuidType.fromString(clEvent.get("requestID"));
executor.logger.info("requestID = " + requestID);
var vnfID = null;
var vcpeClosedLoopStatus = null;

if (clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id")) != null) {
    vnfID = uuidType.fromString(clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id")));
    executor.logger.info("vnfID = " + vnfID);
    vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfID);

    if (vcpeClosedLoopStatus == null) {
        executor.logger.info("Creating context information for new vCPE VNF \"" + vnfID.toString() + "\"");

        vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewInstance();

        vcpeClosedLoopStatus.put("closedLoopControlName", clEvent.get("closedLoopControlName"));
        vcpeClosedLoopStatus.put("closedLoopAlarmStart", clEvent.get("closedLoopAlarmStart"));
        vcpeClosedLoopStatus.put("closedLoopEventClient", clEvent.get("closedLoopEventClient"));
        vcpeClosedLoopStatus.put("closedLoopEventStatus", clEvent.get("closedLoopEventStatus"));
        vcpeClosedLoopStatus.put("version", clEvent.get("version"));
        vcpeClosedLoopStatus.put("requestID", clEvent.get("requestID"));
        vcpeClosedLoopStatus.put("target_type", clEvent.get("target_type"));
        vcpeClosedLoopStatus.put("target", clEvent.get("target"));
        vcpeClosedLoopStatus.put("from", clEvent.get("from"));
        vcpeClosedLoopStatus.put("policyScope", "vCPE");
        vcpeClosedLoopStatus.put("policyName", "ONAPvCPEPolicyModel");
        vcpeClosedLoopStatus.put("policyVersion", "0.0.1");
        vcpeClosedLoopStatus.put("notification", "ACTIVE");
        vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));
        vcpeClosedLoopStatus.put("message", "");

        var aaiInfo = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewSubInstance(
                "VCPE_AAI_Type");

        aaiInfo.put("genericVnfResourceVersion", new utf8Type(clEvent.get("AAI").get(
                new utf8Type("generic_DasH_vnf_DoT_resource_DasH_version"))));
        aaiInfo.put("genericVnfVnfName", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_name")));
        aaiInfo.put("genericVnfProvStatus", clEvent.get("AAI").get(
                new utf8Type("generic_DasH_vnf_DoT_prov_DasH_status")));
        aaiInfo.put("genericVnfIsClosedLoopDisabled", clEvent.get("AAI").get(
                new utf8Type("generic_DasH_vnf_DoT_is_DasH_closed_DasH_loop_DasH_disabled")));
        aaiInfo.put("genericVnfOrchestrationStatus", clEvent.get("AAI").get(
                new utf8Type("generic_DasH_vnf_DoT_orchestration_DasH_status")));
        aaiInfo.put("genericVnfVnfType", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_type")));
        aaiInfo.put("genericVnfInMaint", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_in_DasH_maint")));
        aaiInfo.put("genericVnfServiceId", clEvent.get("AAI")
               .get(new utf8Type("generic_DasH_vnf_DoT_service_DasH_id")));
        aaiInfo.put("genericVnfVnfId", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id")));
        aaiInfo.put("vserverIsClosedLoopDisabled", clEvent.get("AAI").get(
                new utf8Type("vserver_DoT_is_DasH_closed_DasH_loop_DasH_disabled")));
        aaiInfo.put("vserverProvStatus", clEvent.get("AAI").get(new utf8Type("vserver_DoT_prov_DasH_status")));
        aaiInfo.put("vserverName", clEvent.get("AAI").get(new utf8Type("vserver_DoT_vserver_DasH_name")));

        vcpeClosedLoopStatus.put("AAI", aaiInfo);

        if (clEvent.get("closedLoopAlarmEnd") != null) {
            vcpeClosedLoopStatus.put("closedLoopAlarmEnd", clEvent.get("closedLoopAlarmEnd"));
        } else {
            vcpeClosedLoopStatus.put("closedLoopAlarmEnd", java.lang.Long.valueOf(0));
        }

        executor.getContextAlbum("ControlLoopStatusAlbum").put(vnfID.toString(), vcpeClosedLoopStatus);

        // Test of stringify
        executor.logger.info(new java.lang.String("vcpeClosedLoopStatus as JSON:"));
        executor.logger.info(executor.stringify2Json(vcpeClosedLoopStatus,
            executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper()));

        executor.logger.info("Created context information for new vCPE VNF \"" + vnfID.toString() + "\"");
    }

    executor.outFields.put("requestID", requestID);
    executor.outFields.put("vnfID", vnfID);

    executor.logger.info(executor.outFields);
} else {
    executor.logger.info("No vnf-id in VirtualControlLoopEvent, status:"
            + clEvent.get("closedLoopEventStatus").toString());
    var vnfName = clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_name"));
    executor.logger.info("No vnf-id in VirtualControlLoopEvent for " + vnfName);

    vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfName);

    if (vcpeClosedLoopStatus == null) {
        executor.logger.info("Creating context information for new vCPE VNF \"" + vnfName + "\"");

        vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewInstance();

        vcpeClosedLoopStatus.put("closedLoopControlName", clEvent.get("closedLoopControlName"));
        vcpeClosedLoopStatus.put("closedLoopAlarmStart", clEvent.get("closedLoopAlarmStart"));
        vcpeClosedLoopStatus.put("closedLoopEventClient", clEvent.get("closedLoopEventClient"));
        vcpeClosedLoopStatus.put("closedLoopEventStatus", clEvent.get("closedLoopEventStatus("));
        vcpeClosedLoopStatus.put("version", clEvent.get("version"));
        vcpeClosedLoopStatus.put("requestID", clEvent.get("requestID"));
        vcpeClosedLoopStatus.put("target_type", clEvent.get("targetType"));
        vcpeClosedLoopStatus.put("target", clEvent.get("target"));
        vcpeClosedLoopStatus.put("from", clEvent.get("from"));
        vcpeClosedLoopStatus.put("policyScope", "vCPE");
        vcpeClosedLoopStatus.put("policyName", "ONAPvCPEPolicyModel");
        vcpeClosedLoopStatus.put("policyVersion", "0.0.1");
        vcpeClosedLoopStatus.put("notification", "ACTIVE");
        vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));
        vcpeClosedLoopStatus.put("message", "");

        var aaiInfo = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewSubInstance(
                "VCPE_AAI_Type");

        aaiInfo.put("genericVnfVnfName", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_name")));
        vcpeClosedLoopStatus.put("AAI", aaiInfo);

        if (clEvent.get("closedLoopAlarmEnd") != null) {
            vcpeClosedLoopStatus.put("closedLoopAlarmEnd", clEvent.get("closedLoopAlarmEnd"));
        } else {
            vcpeClosedLoopStatus.put("closedLoopAlarmEnd", java.lang.Long.valueOf(0));
        }

        executor.getContextAlbum("ControlLoopStatusAlbum").put(vnfName, vcpeClosedLoopStatus);

        executor.logger.info("Created context information for new vCPE VNF \"" + vnfName + "\"");
    }
    executor.outFields.put("requestID", requestID);
    executor.outFields.put("vnfName", vnfName);
    executor.logger.info(executor.outFields);
}

true;


LE
result: SUCCESS

/root> 
/root> task create name=CheckVNFIdTask
result: SUCCESS

/root> 
/root> task inputfield create name=CheckVNFIdTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=CheckVNFIdTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=CheckVNFIdTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=CheckVNFIdTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=CheckVNFIdTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=CheckVNFIdTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=CheckVNFIdTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> task contextref create name=CheckVNFIdTask albumName=VnfIdWhiteBlackListAlbum
result: SUCCESS

/root> 
/root> task logic create name=CheckVNFIdTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var vnfId = executor.inFields.get("vnfID").toString();
var blackFlag = executor.getContextAlbum("VnfIdWhiteBlackListAlbum").get(vnfId);

executor.logger.info("vnfId=" + vnfId + ", blackFlag=" + blackFlag);

if (blackFlag != null && blackFlag == true) {
    var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfId);
    vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));
    vcpeClosedLoopStatus.put("notification", "BLACKLIST");
    var message = vcpeClosedLoopStatus.get("message");

    if (message != null) {
        vcpeClosedLoopStatus.put("message", message + ":VNF ID blacklisted");
    }
    else {
        vcpeClosedLoopStatus.put("message", "VNF ID blacklisted");
    }
}

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=CheckServiceIdTask
result: SUCCESS

/root> 
/root> task inputfield create name=CheckServiceIdTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=CheckServiceIdTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=CheckServiceIdTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=CheckServiceIdTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=CheckServiceIdTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=CheckServiceIdTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=CheckServiceIdTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> task contextref create name=CheckServiceIdTask albumName=ServiceIdWhiteBlackListAlbum
result: SUCCESS

/root> 
/root> task logic create name=CheckServiceIdTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var vnfId = executor.inFields.get("vnfID").toString();
var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfId);
var serviceId = vcpeClosedLoopStatus.get("AAI").get("genericVnfServiceId");
var blackFlag = executor.getContextAlbum("ServiceIdWhiteBlackListAlbum").get(serviceId.toString());

executor.logger.info("vnfId=" + vnfId + ", serviceId=" + serviceId + ", blackFlag=" + blackFlag);

if (blackFlag != null && blackFlag == true) {
    vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));
    vcpeClosedLoopStatus.put("notification", "BLACKLIST");
    var message = vcpeClosedLoopStatus.get("message");

    if (message != null) {
        vcpeClosedLoopStatus.put("message", message + ":Service ID blacklisted");
    }
    else {
        vcpeClosedLoopStatus.put("message", "Service ID blacklisted");
    }
}

executor.logger.info(executor.outFields);

true;


LE
result: SUCCESS

/root> 
/root> task create name=CheckVServerIdTask
result: SUCCESS

/root> 
/root> task inputfield create name=CheckVServerIdTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=CheckVServerIdTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=CheckVServerIdTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=CheckVServerIdTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=CheckVServerIdTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=CheckVServerIdTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=CheckVServerIdTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> task contextref create name=CheckVServerIdTask albumName=VServerIdWhiteBlackListAlbum
result: SUCCESS

/root> 
/root> task logic create name=CheckVServerIdTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var vnfId = executor.inFields.get("vnfID").toString();
var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfId);
var vServerId = vcpeClosedLoopStatus.get("AAI").get("vserverName");
var blackFlag = executor.getContextAlbum("VServerIdWhiteBlackListAlbum").get(vServerId.toString());

executor.logger.info("vnfId=" + vnfId + ", vServerId=" + vServerId + ", blackFlag=" + blackFlag);

if (blackFlag != null && blackFlag == true) {
    vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));
    vcpeClosedLoopStatus.put("notification", "BLACKLIST");
    var message = vcpeClosedLoopStatus.get("message");

    if (message != null) {
        vcpeClosedLoopStatus.put("message", message + ":VServer ID blacklisted");
    }
    else {
        vcpeClosedLoopStatus.put("message", "VServer ID blacklisted");
    }
}

executor.logger.info(executor.outFields);

true;


LE
result: SUCCESS

/root> 
/root> task create name=StopAndLogTask
result: SUCCESS

/root> 
/root> task inputfield create name=StopAndLogTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=StopAndLogTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=StopAndLogTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=StopAndLogTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=StopAndLogTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=StopAndLogTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=StopAndLogTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> task logic create name=StopAndLogTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var vcpeClosedLoopStatus = null;
if (executor.inFields.get("vnfID") == null) {
    executor.logger.info("AbatedTask: vnfID is null");
    var vnfName = executor.inFields.get("vnfName");
    vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum")
            .get(executor.inFields.get("vnfName"));
} else {
    vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum")
            .get(executor.inFields.get("vnfID").toString());
}

vcpeClosedLoopStatus.put("notificationTime", java.lang.Long.valueOf(Date.now()));

var message = vcpeClosedLoopStatus.get("message");
if (message == null || message == "") {
    vcpeClosedLoopStatus.put("message", "situation has been abated");
}
else {
    vcpeClosedLoopStatus.put("notification", "FINAL_FAILURE");
}

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=InitiateActionsTask
result: SUCCESS

/root> 
/root> task inputfield create name=InitiateActionsTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=InitiateActionsTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=InitiateActionsTask fieldName=ActionEventList schemaName=ActionEventListType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=InitiateActionsTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> task logic create name=InitiateActionsTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(
        executor.inFields.get("vnfID").toString());

var eventList = executor.subject.getOutFieldSchemaHelper("ActionEventList").createNewInstance();

var eventType = org.onap.policy.apex.service.engine.event.ApexEvent;

var controllerRequestActionEvent = new eventType("ActionEvent", "0.0.1", "org.onap.policy.apex.onap.vcpe", "APEX",
        "APEX");

controllerRequestActionEvent.put("action", "ControllerRequestAction");
controllerRequestActionEvent.put("requestID", executor.inFields.get("requestID"));
controllerRequestActionEvent.put("vnfID", executor.inFields.get("vnfID"));
controllerRequestActionEvent.put("vnfName", executor.inFields.get("vnfName"));

eventList.add(controllerRequestActionEvent);

var logActionEvent = new eventType("ActionEvent", "0.0.1", "org.onap.policy.apex.onap.vcpe", "APEX", "APEX");

logActionEvent.put("action", "LogAction");
logActionEvent.put("requestID", executor.inFields.get("requestID"));
logActionEvent.put("vnfID", executor.inFields.get("vnfID"));
logActionEvent.put("vnfName", executor.inFields.get("vnfName"));

eventList.add(logActionEvent);

executor.outFields.put("ActionEventList", eventList);

executor.logger.info(executor.outFields);

true;


LE
result: SUCCESS

/root> 
/root> task create name=DoControllerRequestActionTask
result: SUCCESS

/root> 
/root> task inputfield create name=DoControllerRequestActionTask fieldName=action   schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=DoControllerRequestActionTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=DoControllerRequestActionTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=DoControllerRequestActionTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=DoControllerRequestActionTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=DoControllerRequestActionTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=DoControllerRequestActionTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> task logic create name=DoControllerRequestActionTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

// Pass through to the log state

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=DoLogActionTask
result: SUCCESS

/root> 
/root> task inputfield create name=DoLogActionTask fieldName=action   schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=DoLogActionTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=DoLogActionTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=DoLogActionTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=DoLogActionTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=DoLogActionTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=DoLogActionTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> task logic create name=DoLogActionTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

// Pass through to the log state

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=ControllerRequestTask
result: SUCCESS

/root> 
/root> task inputfield create name=ControllerRequestTask fieldName=action    schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=ControllerRequestTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=ControllerRequestTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=ControllerRequestTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=ControllerRequestTask fieldName=ControllerRequest schemaName=ControllerRequestType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=ControllerRequestTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> task contextref create name=ControllerRequestTask albumName=RequestIDVNFIDAlbum
result: SUCCESS

/root> 
/root> task logic create name=ControllerRequestTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var controllerRequest = executor.subject.getOutFieldSchemaHelper("ControllerRequest").createNewInstance();

var controllerRequestBody = executor.subject.getOutFieldSchemaHelper("ControllerRequest").createNewSubInstance(
        "Controller_Body_Type");

var controllerRequestBodyInput = executor.subject.getOutFieldSchemaHelper("ControllerRequest").createNewSubInstance(
        "Controller_Body_Type_Input");

var controllerRequestBodyInputCommonHeader = executor.subject.getOutFieldSchemaHelper("ControllerRequest")
        .createNewSubInstance("Controller_Body_Type_Common_Header");

var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(
        executor.inFields.get("vnfID").toString());

controllerRequest.put("version", "2.0.0");
controllerRequest.put("rpc_DasH_name", "restart");
controllerRequest.put("correlation_DasH_id", executor.inFields.get("requestID").toString());
controllerRequest.put("type", "request");

controllerRequestBodyInput.put("action", "Restart");
controllerRequestBodyInput.put("action_DasH_identifiers", new java.util.HashMap());
controllerRequestBodyInput.get("action_DasH_identifiers").put("vnf-id", executor.inFields.get("vnfID").toString());

controllerRequestBodyInputCommonHeader.put("timestamp",  java.lang.Long.valueOf(Date.now()));
controllerRequestBodyInputCommonHeader.put("api_DasH_ver", "2.00");
controllerRequestBodyInputCommonHeader.put("originator_DasH_id", executor.inFields.get("requestID").toString());
controllerRequestBodyInputCommonHeader.put("request_DasH_id", executor.inFields.get("requestID").toString());
controllerRequestBodyInputCommonHeader.put("sub_DasH_request_DasH_id", "1");
controllerRequestBodyInputCommonHeader.put("flags", new java.util.HashMap());
controllerRequestBodyInputCommonHeader.get("flags").put("ttl", "10000");
controllerRequestBodyInputCommonHeader.get("flags").put("force", "TRUE");
controllerRequestBodyInputCommonHeader.get("flags").put("mode", "EXCLUSIVE");

controllerRequestBodyInput.put("common_DasH_header", controllerRequestBodyInputCommonHeader);
controllerRequestBody.put("input", controllerRequestBodyInput);
controllerRequest.put("body", controllerRequestBody);

executor.getContextAlbum("RequestIDVNFIDAlbum").put(executor.inFields.get("requestID").toString(),
        executor.inFields.get("vnfID"));

vcpeClosedLoopStatus.put("notification", "OPERATION");
vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));

executor.outFields.put("ControllerRequest", controllerRequest);

executor.logger.info(executor.outFields);

true;


LE
result: SUCCESS

/root> 
/root> task create name=ControllerResponseTask
result: SUCCESS

/root> 
/root> task inputfield create name=ControllerResponseTask fieldName=ControllerResponse schemaName=ControllerResponseType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=ControllerResponseTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=ControllerResponseTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=ControllerResponseTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> task contextref create name=ControllerResponseTask albumName=RequestIDVNFIDAlbum
result: SUCCESS

/root> 
/root> task logic create name=ControllerResponseTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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.
 *
 * APPC LCM Response code: 100 ACCEPTED
 *                         200 ERROR UNEXPECTED ERROR means failure
 *                         312 REJECTED DUPLICATE REQUEST
 *                         400 SUCCESS
 *
 * Note: Sometimes the corelationId has a -1 at the tail, need to get rid of it when present.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);

var controllerResponse = executor.inFields.get("ControllerResponse");

var requestIDString = new java.lang.String(controllerResponse.get("correlation_DasH_id"));
executor.logger.info("requestIDString =\"" + requestIDString + "\"");
var vnfID = executor.getContextAlbum("RequestIDVNFIDAlbum").get(requestIDString);
executor.logger.info("vnfID = " + vnfID);

var returnValue = true

if (vnfID != null) {
    var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfID.toString());
    var requestId = java.util.UUID.fromString(vcpeClosedLoopStatus.get("requestID"));

    vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));

    var returnedCode = controllerResponse.get("body").get("output").get("status").get("code");
    var responseStatus = null;

    if (returnedCode == 100) {
        responseStatus = "ACCEPTED";
    } else if (returnedCode == 200) {
        responseStatus = "ERROR";
    } else if (returnedCode >= 300 && returnedCode <= 316) {
        responseStatus = "REJECT";
    } else if (returnedCode == 400) {
        responseStatus = "SUCCESS";
    } else if (returnedCode == 450 || (returnedCode >= 401 && returnedCode <= 406)) {
        responseStatus = "FAILURE";
    } else if (returnedCode == 500) {
        responseStatus = "PARTIAL_SUCCESS";
    } else if (returnedCode >= 501 && returnedCode <= 599) {
        responseStatus = "PARTIAL_FAILURE";
    } else {
        responseStatus = "SYSTEM_ERROR";
    }

    executor.logger.info("Got from APPC code: " + responseStatus);

    if (responseStatus == "SUCCESS") {
        vcpeClosedLoopStatus.put("notification", "OPERATION_SUCCESS");
        vcpeClosedLoopStatus.put("message", "vCPE restarted");
        executor.getContextAlbum("RequestIDVNFIDAlbum").remove(requestIDString);
    } else if (responseStatus == "ACCEPTED" || responseStatus == "REJECT") {
        executor.logger.info("Got ACCEPTED 100 or REJECT 312, keep the context, wait for next response. Code is: "
                + responseStatus);
    } else {
        executor.getContextAlbum("RequestIDVNFIDAlbum").remove(requestIDString);
        vcpeClosedLoopStatus.put("notification", "OPERATION_FAILURE");
        vcpeClosedLoopStatus.put("message", "vCPE restart failed, code is " + responseStatus + ", message is "
                + controllerResponse.get("body").get("output").get("status").get("message"));
    }

    executor.outFields.put("requestID", requestId);
    executor.outFields.put("vnfID", vnfID);
} else {
    executor.message = "VNF ID not found in context album for request ID " + requestIDString;
    returnValue = false;
}

executor.logger.info(executor.outFields);

returnValue;

LE
result: SUCCESS

/root> 
/root> task create name=ControlLoopLogTask
result: SUCCESS

/root> 
/root> task inputfield create name=ControlLoopLogTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=ControlLoopLogTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=ControlLoopLogTask fieldName=VirtualControlLoopNotification schemaName=VirtualControlLoopNotificationType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=ControlLoopLogTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> task logic create name=ControlLoopLogTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var vnfID = executor.inFields.get("vnfID");
if (vnfID == null) {
    vnfID = executor.inFields.get("vnfName");
}
executor.logger.info("vnfID=" + vnfID);

var controlLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfID.toString());

executor.logger.info("Logging context information for VNF \"" + vnfID + "\"");

var clNotification = executor.subject.getOutFieldSchemaHelper("VirtualControlLoopNotification").createNewInstance();

clNotification.put("requestID",             executor.inFields.get("requestID").toString());
clNotification.put("closedLoopControlName", controlLoopStatus.get("closedLoopControlName"));
clNotification.put("closedLoopAlarmStart",  controlLoopStatus.get("closedLoopAlarmStart"));
clNotification.put("closedLoopAlarmEnd",    controlLoopStatus.get("closedLoopAlarmEnd"));
clNotification.put("closedLoopEventClient", controlLoopStatus.get("closedLoopEventClient"));
clNotification.put("version",               controlLoopStatus.get("version"));
clNotification.put("targetType",            controlLoopStatus.get("target_type"));
clNotification.put("target",                controlLoopStatus.get("target"));
clNotification.put("from",                  controlLoopStatus.get("from"));
clNotification.put("policyScope",           controlLoopStatus.get("policyScope"));
clNotification.put("policyName",            controlLoopStatus.get("policyName"));
clNotification.put("policyVersion",         controlLoopStatus.get("policyVersion"));
clNotification.put("notification",          controlLoopStatus.get("notification"));
clNotification.put("message",               controlLoopStatus.get("message"));
clNotification.put("notificationTime",      controlLoopStatus.get("notificationTime"));
clNotification.put("opsClTimer",            0);

var aaiInfo = controlLoopStatus.get("AAI");

var aaiInfoOut = new java.util.HashMap();

aaiInfoOut.put("generic-vnf.resource-version", aaiInfo.get("genericVnfResourceVersion"));
aaiInfoOut.put("generic-vnf.vnf-name", aaiInfo.get("genericVnfVnfName"));
aaiInfoOut.put("generic-vnf.prov-status", aaiInfo.get("genericVnfProvStatus"));
aaiInfoOut.put("generic-vnf.is-closed-loop-disabled", aaiInfo.get("genericVnfIsClosedLoopDisabled"));
aaiInfoOut.put("generic-vnf.orchestration-status", aaiInfo.get("genericVnfOrchestrationStatus"));
aaiInfoOut.put("generic-vnf.vnf-type", aaiInfo.get("genericVnfVnfType"));
aaiInfoOut.put("generic-vnf.in-maint", aaiInfo.get("genericVnfInMaint"));
aaiInfoOut.put("generic-vnf.service-id", aaiInfo.get("genericVnfServiceId"));
if (vnfID != null) {
    aaiInfoOut.put("generic-vnf.vnf-id", aaiInfo.get("genericVnfVnfId"));
}

clNotification.put("AAI", aaiInfoOut);

executor.outFields.put("VirtualControlLoopNotification", clNotification);

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=ConfigureBlackWhiteListTask
result: SUCCESS

/root> 
/root> task inputfield create name=ConfigureBlackWhiteListTask fieldName=targetType schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=ConfigureBlackWhiteListTask fieldName=black schemaName=SimpleBooleanType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=ConfigureBlackWhiteListTask fieldName=target schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=ConfigureBlackWhiteListTask fieldName=targetType schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=ConfigureBlackWhiteListTask fieldName=black schemaName=SimpleBooleanType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=ConfigureBlackWhiteListTask fieldName=target schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=ConfigureBlackWhiteListTask albumName=VnfIdWhiteBlackListAlbum
result: SUCCESS

/root> task contextref create name=ConfigureBlackWhiteListTask albumName=ServiceIdWhiteBlackListAlbum
result: SUCCESS

/root> task contextref create name=ConfigureBlackWhiteListTask albumName=VServerIdWhiteBlackListAlbum
result: SUCCESS

/root> 
/root> task logic create name=ConfigureBlackWhiteListTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

// Pass through to the log state

executor.logger.info(executor.outFields);

var targetType = executor.inFields.get("targetType");
var target = executor.inFields.get("target");
var black = executor.inFields.get("black");

var returnValue = true;

if (targetType == "VNF") {
    executor.getContextAlbum("VnfIdWhiteBlackListAlbum").put(target, black);
    executor.logger.info("added VNF ID \"" + target + "\" with black flag \"" + black + "\" to VNF ID list");
}
else if (targetType == "Service") {
    executor.getContextAlbum("ServiceIdWhiteBlackListAlbum").put(target, black);
    executor.logger.info("added Service ID \"" + target + "\" with black flag \"" + black + "\" to Service ID list");
}
else if (targetType == "VServer") {
    executor.getContextAlbum("VServerIdWhiteBlackListAlbum").put(target, black);
    executor.logger.info("added VServer ID \"" + target + "\" with black flag \"" + black + "\" to VServer ID list");
}
else {
    executor.logger.warn("unknown target type \"" + targetType + "\" specified");
    returnValue = false;
}

returnValue;


LE
result: SUCCESS

/root> 
/root> #
/root> # ReceiveEventPolicy
/root> #
/root> policy create name=ReceiveEventPolicy template=Freestyle firstState=GetEntityState
result: SUCCESS

/root> 
/root> policy state create name=ReceiveEventPolicy stateName=LogAndStopState triggerName=EntityStateUpdatedEvent defaultTaskName=ControlLoopLogTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=LogAndStopState outputName=AbatedOutput eventName=ControlLoopLogEvent
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=LogAndStopState taskName=ControlLoopLogTask outputType=DIRECT outputName=AbatedOutput
result: SUCCESS

/root> 
/root> policy state create name=ReceiveEventPolicy stateName=ExecuteOrLogState triggerName=EntityStateUpdatedEvent defaultTaskName=StopAndLogTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=ExecuteOrLogState outputName=ExecuteOutput eventName=ActionEventListEvent
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=ExecuteOrLogState taskName=InitiateActionsTask outputType=DIRECT outputName=ExecuteOutput
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=ExecuteOrLogState outputName=StopAndLogOutput eventName=EntityStateUpdatedEvent nextState=LogAndStopState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=ExecuteOrLogState taskName=StopAndLogTask outputType=DIRECT outputName=StopAndLogOutput
result: SUCCESS

/root> 
/root> policy state contextref create name=ReceiveEventPolicy stateName=ExecuteOrLogState albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> policy state selecttasklogic create name=ReceiveEventPolicy stateName=ExecuteOrLogState logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var returnValue = true;

if( executor.inFields.get("vnfID") == null) {
   executor.logger.info("ControlLoopStatusAlbum: vnfID is null");
   var vnfName = executor.inFields.get("vnfName");
   var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(
        executor.inFields.get("vnfName"));
} else {
   var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(
        executor.inFields.get("vnfID").toString());
}

var status = vcpeClosedLoopStatus.get("closedLoopEventStatus").toString();
var notification = vcpeClosedLoopStatus.get("notification");

if (notification != null && notification == "BLACKLIST") {
    executor.subject.getTaskKey("StopAndLogTask").copyTo(executor.selectedTask);
}
else {
    if (status == "ONSET") {
        executor.subject.getTaskKey("InitiateActionsTask").copyTo(executor.selectedTask);
    } else if (status == "ABATED") {
        executor.subject.getTaskKey("StopAndLogTask").copyTo(executor.selectedTask);
    } else {
        executor.message = "closedLoopEventStatus is \"" + status + "\", it must be either \"ONSET\" or \"ABATED\"";
        returnValue = false;
    }
}

executor.logger.info("ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:" + executor.selectedTask);

returnValue;

LE
result: SUCCESS

/root> 
/root> policy state create name=ReceiveEventPolicy stateName=CheckVNFIdState triggerName=EntityStateUpdatedEvent defaultTaskName=CheckVNFIdTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=CheckVNFIdState outputName=CheckVNFIdOutput eventName=EntityStateUpdatedEvent nextState=ExecuteOrLogState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CheckVNFIdState taskName=CheckVNFIdTask outputType=DIRECT outputName=CheckVNFIdOutput
result: SUCCESS

/root> 
/root> policy state create name=ReceiveEventPolicy stateName=CheckVServerIdState triggerName=EntityStateUpdatedEvent defaultTaskName=CheckVServerIdTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=CheckVServerIdState outputName=CheckVServerIdOutput eventName=EntityStateUpdatedEvent nextState=CheckVNFIdState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CheckVServerIdState taskName=CheckVServerIdTask outputType=DIRECT outputName=CheckVServerIdOutput
result: SUCCESS

/root> 
/root> policy state create name=ReceiveEventPolicy stateName=CheckServiceIdState triggerName=EntityStateUpdatedEvent defaultTaskName=CheckServiceIdTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=CheckServiceIdState outputName=CheckServiceIdOutput eventName=EntityStateUpdatedEvent nextState=CheckVServerIdState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CheckServiceIdState taskName=CheckServiceIdTask outputType=DIRECT outputName=CheckServiceIdOutput
result: SUCCESS

/root> 
/root> policy state create name=ReceiveEventPolicy stateName=GetEntityState triggerName=VirtualControlLoopEvent defaultTaskName=GetEntityStateTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=GetEntityState outputName=GetEntityStateOutput eventName=EntityStateUpdatedEvent nextState=CheckServiceIdState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=GetEntityState taskName=GetEntityStateTask outputType=DIRECT outputName=GetEntityStateOutput
result: SUCCESS

/root> 
/root> policy state contextref create name=ReceiveEventPolicy stateName=GetEntityState albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> #
/root> # ExecuteActionsPolicy
/root> #
/root> policy create name=ExecuteActionsPolicy template=Freestyle firstState=ActionState
result: SUCCESS

/root> 
/root> policy state create name=ExecuteActionsPolicy stateName=ControllerRequestActionState triggerName=ActionEvent defaultTaskName=ControllerRequestTask
result: SUCCESS

/root> policy state output create name=ExecuteActionsPolicy stateName=ControllerRequestActionState outputName=ControllerRequestOutput eventName=ControllerRequestEvent
result: SUCCESS

/root> policy state taskref create name=ExecuteActionsPolicy stateName=ControllerRequestActionState taskName=ControllerRequestTask outputType=DIRECT outputName=ControllerRequestOutput
result: SUCCESS

/root> 
/root> policy state create name=ExecuteActionsPolicy stateName=LogActionState triggerName=EntityStateUpdatedEvent defaultTaskName=ControlLoopLogTask
result: SUCCESS

/root> policy state output create name=ExecuteActionsPolicy stateName=LogActionState outputName=ResponseLogOutput eventName=ControlLoopLogEvent
result: SUCCESS

/root> policy state taskref create name=ExecuteActionsPolicy stateName=LogActionState taskName=ControlLoopLogTask outputType=DIRECT outputName=ResponseLogOutput
result: SUCCESS

/root> 
/root> policy state create name=ExecuteActionsPolicy stateName=ActionState triggerName=ActionEvent defaultTaskName=DoLogActionTask
result: SUCCESS

/root> policy state output create name=ExecuteActionsPolicy stateName=ActionState outputName=LogActionOutput eventName=EntityStateUpdatedEvent nextState=LogActionState
result: SUCCESS

/root> policy state taskref create name=ExecuteActionsPolicy stateName=ActionState taskName=DoLogActionTask outputType=DIRECT outputName=LogActionOutput
result: SUCCESS

/root> policy state output create name=ExecuteActionsPolicy stateName=ActionState outputName=ControllerRequestActionOutput eventName=ActionEvent nextState=ControllerRequestActionState
result: SUCCESS

/root> policy state taskref create name=ExecuteActionsPolicy stateName=ActionState taskName=DoControllerRequestActionTask outputType=DIRECT outputName=ControllerRequestActionOutput
result: SUCCESS

/root> 
/root> policy state contextref create name=ExecuteActionsPolicy stateName=ActionState albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> policy state selecttasklogic create name=ExecuteActionsPolicy stateName=ActionState logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var status = null;

if (executor.inFields.get("action") == "ControllerRequestAction") {
    executor.subject.getTaskKey("DoControllerRequestActionTask").copyTo(executor.selectedTask);
} else {
    executor.subject.getTaskKey("DoLogActionTask").copyTo(executor.selectedTask);
}

executor.logger.info("ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:" + executor.selectedTask);

true;

LE
result: SUCCESS

/root> 
/root> #
/root> # ControllerResponsePolicy
/root> #
/root> policy create name=ControllerResponsePolicy template=Freestyle firstState=ControllerResponseState
result: SUCCESS

/root> 
/root> policy state create name=ControllerResponsePolicy stateName=ResponseLogState triggerName=EntityStateUpdatedEvent defaultTaskName=ControlLoopLogTask
result: SUCCESS

/root> policy state output create name=ControllerResponsePolicy stateName=ResponseLogState outputName=ResponseLogOutput eventName=ControlLoopLogEvent
result: SUCCESS

/root> policy state taskref create name=ControllerResponsePolicy stateName=ResponseLogState taskName=ControlLoopLogTask outputType=DIRECT outputName=ResponseLogOutput
result: SUCCESS

/root> 
/root> policy state create name=ControllerResponsePolicy stateName=ControllerResponseState triggerName=ControllerResponseEvent defaultTaskName=ControllerResponseTask
result: SUCCESS

/root> policy state output create name=ControllerResponsePolicy stateName=ControllerResponseState outputName=ControllerResponseOutput eventName=EntityStateUpdatedEvent nextState=ResponseLogState
result: SUCCESS

/root> policy state taskref create name=ControllerResponsePolicy stateName=ControllerResponseState taskName=ControllerResponseTask outputType=DIRECT outputName=ControllerResponseOutput
result: SUCCESS

/root> 
/root> #
/root> # ConfigureBlackWhiteListPolicy
/root> #
/root> policy create name=ConfigureBlackWhiteListPolicy template=Freestyle firstState=ConfigureBlackWhiteListState
result: SUCCESS

/root> 
/root> policy state create name=ConfigureBlackWhiteListPolicy stateName=ConfigureBlackWhiteListState triggerName=ConfigureBlackWhiteListEvent defaultTaskName=ConfigureBlackWhiteListTask
result: SUCCESS

/root> policy state output create name=ConfigureBlackWhiteListPolicy stateName=ConfigureBlackWhiteListState outputName=ConfigureBlackWhiteListOutput eventName=ConfigureBlackWhiteListResultEvent
result: SUCCESS

/root> policy state taskref create name=ConfigureBlackWhiteListPolicy stateName=ConfigureBlackWhiteListState taskName=ConfigureBlackWhiteListTask outputType=DIRECT outputName=ConfigureBlackWhiteListOutput
result: SUCCESS

/root> 
/root> validate
result: SUCCESS
{
  "name": "ONAPvCPEPolicyModelStandalone",
  "version": "0.0.1"
}
***validation of model successful***

/root> /root> #-------------------------------------------------------------------------------
/root> # ============LICENSE_START=======================================================
/root> #  Copyright (C) 2020 Nordix Foundation.
/root> # ================================================================================
/root> # Licensed under the Apache License, Version 2.0 (the "License");
/root> # you may not use this file except in compliance with the License.
/root> # You may obtain a copy of the License at
/root> #
/root> #      http://www.apache.org/licenses/LICENSE-2.0
/root> #
/root> # Unless required by applicable law or agreed to in writing, software
/root> # distributed under the License is distributed on an "AS IS" BASIS,
/root> # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/root> # See the License for the specific language governing permissions and
/root> # limitations under the License.
/root> #
/root> # SPDX-License-Identifier: Apache-2.0
/root> # ============LICENSE_END=========================================================
/root> #-------------------------------------------------------------------------------
/root> 
/root> model create name=ONAPvCPEPolicyModelStandalone
result: SUCCESS

/root> 
/root> schema create name=SimpleStringType  flavour=Java schema=java.lang.String
result: SUCCESS

/root> schema create name=SimpleLongType    flavour=Java schema=java.lang.Long
result: SUCCESS

/root> schema create name=SimpleBooleanType flavour=Java schema=java.lang.Boolean
result: SUCCESS

/root> schema create name=UUIDType          flavour=Java schema=java.util.UUID
result: SUCCESS

/root> 
/root> schema create name=VirtualControlLoopEventType flavour=Avro schema=LS
{
    "type": "record",
    "name": "VirtualControlLoopEvent",
    "fields": [
        {
            "name": "requestID",
            "type": "string"
        },
        {
            "name": "target_type",
            "type": "string"
        },
        {
            "name": "closedLoopControlName",
            "type": "string"
        },
        {
            "name": "version",
            "type": "string"
        },
        {
            "name": "closedLoopEventClient",
            "type": "string"
        },
        {
            "name": "target",
            "type": "string"
        },
        {
            "name": "from",
            "type": "string"
        },
        {
            "name": "policyScope",
            "type": "string"
        },
        {
            "name": "policyName",
            "type": "string"
        },
        {
            "name": "policyVersion",
            "type": "string"
        },
        {
            "name": "closedLoopEventStatus",
            "type": "string"
        },
        {
            "name": "additionalEventParams",
            "type": {
                "type": "map",
                "values": "string"
            }
        },
        {
            "name": "AAI",
            "type": {
                "type": "map",
                "values": "string"
            }
        },
        {
            "name": "payload",
            "type": "string"
        },
        {
            "name": "closedLoopAlarmStart",
            "type": "long"
        },
        {
            "name": "closedLoopAlarmEnd",
            "type": "long"
        }
    ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=VirtualControlLoopNotificationType flavour=Avro schema=LS
{
    "type": "record",
    "name": "VirtualControlLoopNotification",
    "fields": [
        {
            "name": "closedLoopControlName",
            "type": "string"
        },
        {
            "name": "version",
            "type": "string"
        },
        {
            "name": "requestID",
            "type": "string"
        },
        {
            "name": "closedLoopEventClient",
            "type": "string"
        },
        {
            "name": "targetType",
            "type": "string"
        },
        {
            "name": "target",
            "type": "string"
        },
        {
            "name": "from",
            "type": "string"
        },
        {
            "name": "policyScope",
            "type": "string"
        },
        {
            "name": "policyName",
            "type": "string"
        },
        {
            "name": "policyVersion",
            "type": "string"
        },
        {
            "name": "notification",
            "type": "string"
        },
        {
            "name": "message",
            "type": "string"
        },
        {
            "name": "notificationTime",
            "type": "long"
        },
        {
            "name": "opsClTimer",
            "type": "int"
        },
        {
            "name": "AAI",
            "type": {
                "type": "map",
                "values": "string"
            }
        },
        {
            "name": "closedLoopAlarmStart",
            "type": "long"
        },
        {
            "name": "closedLoopAlarmEnd",
            "type": "long"
        }
    ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=ControllerRequestType flavour=Avro schema=LS
{
    "type": "record",
    "name": "VCPEClosedLoopStatus",
    "fields": [
        {
            "name": "version",
            "type": "string"
        },
        {
            "name": "rpc_DasH_name",
            "type": "string"
        },
        {
            "name": "correlation_DasH_id",
            "type": "string"
        },
        {
            "name": "type",
            "type": "string"
        },
        {
            "name": "body",
            "type": {
                "type": "record",
                "name": "Controller_Body_Type",
                "namespace": "org.onap.policy.apex.onap.vcpe",
                "fields": [
                    {
                        "name": "input",
                        "type": {
                            "type": "record",
                            "name": "Controller_Body_Type_Input",
                            "namespace": "org.onap.policy.apex.onap.vcpe",
                            "fields": [
                                {
                                    "name": "action",
                                    "type": "string"
                                },
                                {
                                    "name": "action_DasH_identifiers",
                                    "type": {
                                        "type": "map",
                                        "values": "string"
                                    }
                                },
                                {
                                    "name": "common_DasH_header",
                                    "type": {
                                        "type": "record",
                                        "name": "Controller_Body_Type_Common_Header",
                                        "namespace": "org.onap.policy.apex.onap.vcpe",
                                        "fields": [
                                            {
                                                "name": "timestamp",
                                                "type": "long"
                                            },
                                            {
                                                "name": "api_DasH_ver",
                                                "type": "string"
                                            },
                                            {
                                                "name": "originator_DasH_id",
                                                "type": "string"
                                            },
                                            {
                                                "name": "request_DasH_id",
                                                "type": "string"
                                            },
                                            {
                                                "name": "sub_DasH_request_DasH_id",
                                                "type": "string"
                                            },
                                            {
                                                "name": "flags",
                                                "type": {
                                                    "type": "map",
                                                    "values": "string"
                                                }
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=ControllerResponseType flavour=Avro schema=LS
{
    "type": "record",
    "name": "VCPEClosedLoopStatus",
    "fields": [
        {
            "name": "version",
            "type": "string"
        },
        {
            "name": "rpc_DasH_name",
            "type": "string"
        },
        {
            "name": "correlation_DasH_id",
            "type": "string"
        },
        {
            "name": "type",
            "type": "string"
        },
        {
            "name": "body",
            "type": {
                "type": "record",
                "name": "Controller_Body_Type",
                "namespace": "org.onap.policy.apex.onap.vcpe",
                "fields": [
                    {
                        "name": "output",
                        "type": {
                            "type": "record",
                            "name": "Controller_Body_Type_Output",
                            "namespace": "org.onap.policy.apex.onap.vcpe",
                            "fields": [
                                {
                                    "name": "payload",
                                    "type": "string"
                                },
                                {
                                    "name": "common_DasH_header",
                                    "type": {
                                        "type": "record",
                                        "name": "Controller_Body_Type_Common_Header",
                                        "namespace": "org.onap.policy.apex.onap.vcpe",
                                        "fields": [
                                            {
                                                "name": "timestamp",
                                                "type": "long"
                                            },
                                            {
                                                "name": "api_DasH_ver",
                                                "type": "string"
                                            },
                                            {
                                                "name": "originator_DasH_id",
                                                "type": "string"
                                            },
                                            {
                                                "name": "request_DasH_id",
                                                "type": "string"
                                            },
                                            {
                                                "name": "sub_DasH_request_DasH_id",
                                                "type": "string"
                                            },
                                            {
                                                "name": "flags",
                                                "type": {
                                                    "type": "map",
                                                    "values": "string"
                                                }
                                            }
                                        ]
                                    }
                                },
                                {
                                    "name": "status",
                                    "type": {
                                        "type": "record",
                                        "name": "Controller_Body_Type_Output_Status",
                                        "namespace": "org.onap.policy.apex.onap.vcpe",
                                        "fields": [
                                            {
                                                "name": "code",
                                                "type": "int"
                                            },
                                            {
                                                "name": "message",
                                                "type": "string"
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=ControlLoopStatusType flavour=Avro schema=LS
{
    "type": "record",
    "name": "VCPEClosedLoopStatus",
    "fields": [
        {
            "name": "AAI",
            "type": {
                "type": "record",
                "name": "VCPE_AAI_Type",
                "namespace": "org.onap.policy.apex.onap.vcpe",
                "fields": [
                    {
                        "name": "genericVnfResourceVersion",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfVnfName",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfProvStatus",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfIsClosedLoopDisabled",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfOrchestrationStatus",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfVnfType",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfInMaint",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfServiceId",
                        "type": "string"
                    },
                    {
                        "name": "genericVnfVnfId",
                        "type": "string"
                    },
                    {
                        "name": "vserverIsClosedLoopDisabled",
                        "type": "string"
                    },
                    {
                        "name": "vserverName",
                        "type": "string"
                    },
                    {
                        "name": "vserverProvStatus",
                        "type": "string"
                    }
                ]
            }
        },
        {
            "name": "closedLoopAlarmStart",
            "type": "long"
        },
        {
            "name": "closedLoopAlarmEnd",
            "type": "long"
        },
        {
            "name": "closedLoopControlName",
            "type": "string"
        },
        {
            "name": "version",
            "type": "string"
        },
        {
            "name": "requestID",
            "type": "string"
        },
        {
            "name": "closedLoopEventClient",
            "type": "string"
        },
        {
            "name": "closedLoopEventStatus",
            "type": "string"
        },
        {
            "name": "target_type",
            "type": "string"
        },
        {
            "name": "target",
            "type": "string"
        },
        {
            "name": "from",
            "type": "string"
        },
        {
            "name": "policyScope",
            "type": "string"
        },
        {
            "name": "policyName",
            "type": "string"
        },
        {
            "name": "policyVersion",
            "type": "string"
        },
        {
            "name": "notification",
            "type": "string"
        },
        {
            "name": "notificationTime",
            "type": "long"
        },
        {
            "name": "message",
            "type": "string"
        }
    ]
}
LE
result: SUCCESS

/root> 
/root> schema create name=ActionEventListType flavour=Java schema=org.onap.policy.apex.service.engine.event.ApexEventList
result: SUCCESS

/root> 
/root> album create name=ControlLoopStatusAlbum scope=policy writable=true schemaName=ControlLoopStatusType
result: SUCCESS

/root> 
/root> album create name=RequestIDVNFIDAlbum scope=policy writable=true schemaName=UUIDType
result: SUCCESS

/root> 
/root> album create name=VnfIdWhiteBlackListAlbum scope=policy writable=true schemaName=SimpleBooleanType
result: SUCCESS

/root> album create name=ServiceIdWhiteBlackListAlbum scope=policy writable=true schemaName=SimpleBooleanType
result: SUCCESS

/root> album create name=VServerIdWhiteBlackListAlbum scope=policy writable=true schemaName=SimpleBooleanType
result: SUCCESS

/root> 
/root> event create name=VirtualControlLoopEvent version=1.0.2 nameSpace=org.onap.policy.apex.onap.vcpe source=Analytics target=APEX
result: SUCCESS

/root> event parameter create name=VirtualControlLoopEvent parName=VirtualControlLoopEvent schemaName=VirtualControlLoopEventType
result: SUCCESS

/root> 
/root> event create name=EntityStateUpdatedEvent nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=EntityStateUpdatedEvent parName=requestID schemaName=UUIDType
result: SUCCESS

/root> event parameter create name=EntityStateUpdatedEvent parName=vnfID     schemaName=UUIDType
result: SUCCESS

/root> event parameter create name=EntityStateUpdatedEvent parName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS

/root> 
/root> event create name=ActionEventListEvent nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=ActionEventListEvent parName=ActionEventList schemaName=ActionEventListType
result: SUCCESS

/root> 
/root> event create name=ActionEvent nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=ActionEvent parName=action   schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=ActionEvent parName=requestID schemaName=UUIDType
result: SUCCESS

/root> event parameter create name=ActionEvent parName=vnfID     schemaName=UUIDType
result: SUCCESS

/root> event parameter create name=ActionEvent parName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS

/root> 
/root> event create name=ControllerRequestEvent version="2.0.0" nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=Controller
result: SUCCESS

/root> event parameter create name=ControllerRequestEvent parName=ControllerRequest schemaName=ControllerRequestType
result: SUCCESS

/root> 
/root> event create name=ControllerResponseEvent version="2.0.0" nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APPC
result: SUCCESS

/root> event parameter create name=ControllerResponseEvent parName=ControllerResponse schemaName=ControllerResponseType
result: SUCCESS

/root> 
/root> event create name=ControlLoopLogEvent nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=ControlLoopLogEvent parName=VirtualControlLoopNotification schemaName=VirtualControlLoopNotificationType
result: SUCCESS

/root> 
/root> event create name=ConfigureBlackWhiteListEvent nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=ConfigureBlackWhiteListEvent parName=targetType schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=ConfigureBlackWhiteListEvent parName=target schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=ConfigureBlackWhiteListEvent parName=black schemaName=SimpleBooleanType
result: SUCCESS

/root> 
/root> event create name=ConfigureBlackWhiteListResultEvent nameSpace=org.onap.policy.apex.onap.vcpe source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=ConfigureBlackWhiteListResultEvent parName=targetType schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=ConfigureBlackWhiteListResultEvent parName=target schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=ConfigureBlackWhiteListResultEvent parName=black schemaName=SimpleBooleanType
result: SUCCESS

/root> 
/root> task create name=GetEntityStateTask
result: SUCCESS

/root> 
/root> task inputfield create name=GetEntityStateTask fieldName=VirtualControlLoopEvent schemaName=VirtualControlLoopEventType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=GetEntityStateTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=GetEntityStateTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=GetEntityStateTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=GetEntityStateTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> task contextref create name=GetEntityStateTask albumName=RequestIDVNFIDAlbum
result: SUCCESS

/root> 
/root> task logic create name=GetEntityStateTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 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.
 *
 * Note: The incoming closedloop message can be ONSET with both VNF-name and VNF-ID
 *       or ABATED with only VNF-name. So need to handle differently. For ABATED case,
 *       since we still keep the RequireIDVNFID context album, we can get it from there.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);

var utf8Type = org.apache.avro.util.Utf8;
var uuidType = java.util.UUID;

var clEvent = executor.inFields.get("VirtualControlLoopEvent");

executor.logger.info(clEvent.toString());
executor.logger.info(clEvent.get("closedLoopControlName"));

var requestID = uuidType.fromString(clEvent.get("requestID"));
executor.logger.info("requestID = " + requestID);
var vnfID = null;
var vcpeClosedLoopStatus = null;

if (clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id")) != null) {
    vnfID = uuidType.fromString(clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id")));
    executor.logger.info("vnfID = " + vnfID);
    vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfID);

    if (vcpeClosedLoopStatus == null) {
        executor.logger.info("Creating context information for new vCPE VNF \"" + vnfID.toString() + "\"");

        vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewInstance();

        vcpeClosedLoopStatus.put("closedLoopControlName", clEvent.get("closedLoopControlName"));
        vcpeClosedLoopStatus.put("closedLoopAlarmStart", clEvent.get("closedLoopAlarmStart"));
        vcpeClosedLoopStatus.put("closedLoopEventClient", clEvent.get("closedLoopEventClient"));
        vcpeClosedLoopStatus.put("closedLoopEventStatus", clEvent.get("closedLoopEventStatus"));
        vcpeClosedLoopStatus.put("version", clEvent.get("version"));
        vcpeClosedLoopStatus.put("requestID", clEvent.get("requestID"));
        vcpeClosedLoopStatus.put("target_type", clEvent.get("target_type"));
        vcpeClosedLoopStatus.put("target", clEvent.get("target"));
        vcpeClosedLoopStatus.put("from", clEvent.get("from"));
        vcpeClosedLoopStatus.put("policyScope", "vCPE");
        vcpeClosedLoopStatus.put("policyName", "ONAPvCPEPolicyModel");
        vcpeClosedLoopStatus.put("policyVersion", "0.0.1");
        vcpeClosedLoopStatus.put("notification", "ACTIVE");
        vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));
        vcpeClosedLoopStatus.put("message", "");

        var aaiInfo = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewSubInstance(
                "VCPE_AAI_Type");

        aaiInfo.put("genericVnfResourceVersion", new utf8Type(clEvent.get("AAI").get(
                new utf8Type("generic_DasH_vnf_DoT_resource_DasH_version"))));
        aaiInfo.put("genericVnfVnfName", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_name")));
        aaiInfo.put("genericVnfProvStatus", clEvent.get("AAI").get(
                new utf8Type("generic_DasH_vnf_DoT_prov_DasH_status")));
        aaiInfo.put("genericVnfIsClosedLoopDisabled", clEvent.get("AAI").get(
                new utf8Type("generic_DasH_vnf_DoT_is_DasH_closed_DasH_loop_DasH_disabled")));
        aaiInfo.put("genericVnfOrchestrationStatus", clEvent.get("AAI").get(
                new utf8Type("generic_DasH_vnf_DoT_orchestration_DasH_status")));
        aaiInfo.put("genericVnfVnfType", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_type")));
        aaiInfo.put("genericVnfInMaint", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_in_DasH_maint")));
        aaiInfo.put("genericVnfServiceId", clEvent.get("AAI")
               .get(new utf8Type("generic_DasH_vnf_DoT_service_DasH_id")));
        aaiInfo.put("genericVnfVnfId", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id")));
        aaiInfo.put("vserverIsClosedLoopDisabled", clEvent.get("AAI").get(
                new utf8Type("vserver_DoT_is_DasH_closed_DasH_loop_DasH_disabled")));
        aaiInfo.put("vserverProvStatus", clEvent.get("AAI").get(new utf8Type("vserver_DoT_prov_DasH_status")));
        aaiInfo.put("vserverName", clEvent.get("AAI").get(new utf8Type("vserver_DoT_vserver_DasH_name")));

        vcpeClosedLoopStatus.put("AAI", aaiInfo);

        if (clEvent.get("closedLoopAlarmEnd") != null) {
            vcpeClosedLoopStatus.put("closedLoopAlarmEnd", clEvent.get("closedLoopAlarmEnd"));
        } else {
            vcpeClosedLoopStatus.put("closedLoopAlarmEnd", java.lang.Long.valueOf(0));
        }

        executor.getContextAlbum("ControlLoopStatusAlbum").put(vnfID.toString(), vcpeClosedLoopStatus);

        // Test of stringify
        executor.logger.info(new java.lang.String("vcpeClosedLoopStatus as JSON:"));
        executor.logger.info(executor.stringify2Json(vcpeClosedLoopStatus,
            executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper()));

        executor.logger.info("Created context information for new vCPE VNF \"" + vnfID.toString() + "\"");
    }

    executor.outFields.put("requestID", requestID);
    executor.outFields.put("vnfID", vnfID);

    executor.logger.info(executor.outFields);
} else {
    executor.logger.info("No vnf-id in VirtualControlLoopEvent, status:"
            + clEvent.get("closedLoopEventStatus").toString());
    var vnfName = clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_name"));
    executor.logger.info("No vnf-id in VirtualControlLoopEvent for " + vnfName);

    vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfName);

    if (vcpeClosedLoopStatus == null) {
        executor.logger.info("Creating context information for new vCPE VNF \"" + vnfName + "\"");

        vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewInstance();

        vcpeClosedLoopStatus.put("closedLoopControlName", clEvent.get("closedLoopControlName"));
        vcpeClosedLoopStatus.put("closedLoopAlarmStart", clEvent.get("closedLoopAlarmStart"));
        vcpeClosedLoopStatus.put("closedLoopEventClient", clEvent.get("closedLoopEventClient"));
        vcpeClosedLoopStatus.put("closedLoopEventStatus", clEvent.get("closedLoopEventStatus("));
        vcpeClosedLoopStatus.put("version", clEvent.get("version"));
        vcpeClosedLoopStatus.put("requestID", clEvent.get("requestID"));
        vcpeClosedLoopStatus.put("target_type", clEvent.get("targetType"));
        vcpeClosedLoopStatus.put("target", clEvent.get("target"));
        vcpeClosedLoopStatus.put("from", clEvent.get("from"));
        vcpeClosedLoopStatus.put("policyScope", "vCPE");
        vcpeClosedLoopStatus.put("policyName", "ONAPvCPEPolicyModel");
        vcpeClosedLoopStatus.put("policyVersion", "0.0.1");
        vcpeClosedLoopStatus.put("notification", "ACTIVE");
        vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));
        vcpeClosedLoopStatus.put("message", "");

        var aaiInfo = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewSubInstance(
                "VCPE_AAI_Type");

        aaiInfo.put("genericVnfVnfName", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_name")));
        vcpeClosedLoopStatus.put("AAI", aaiInfo);

        if (clEvent.get("closedLoopAlarmEnd") != null) {
            vcpeClosedLoopStatus.put("closedLoopAlarmEnd", clEvent.get("closedLoopAlarmEnd"));
        } else {
            vcpeClosedLoopStatus.put("closedLoopAlarmEnd", java.lang.Long.valueOf(0));
        }

        executor.getContextAlbum("ControlLoopStatusAlbum").put(vnfName, vcpeClosedLoopStatus);

        executor.logger.info("Created context information for new vCPE VNF \"" + vnfName + "\"");
    }
    executor.outFields.put("requestID", requestID);
    executor.outFields.put("vnfName", vnfName);
    executor.logger.info(executor.outFields);
}

true;


LE
result: SUCCESS

/root> 
/root> task create name=CheckVNFIdTask
result: SUCCESS

/root> 
/root> task inputfield create name=CheckVNFIdTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=CheckVNFIdTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=CheckVNFIdTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=CheckVNFIdTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=CheckVNFIdTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=CheckVNFIdTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=CheckVNFIdTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> task contextref create name=CheckVNFIdTask albumName=VnfIdWhiteBlackListAlbum
result: SUCCESS

/root> 
/root> task logic create name=CheckVNFIdTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var vnfId = executor.inFields.get("vnfID").toString();
var blackFlag = executor.getContextAlbum("VnfIdWhiteBlackListAlbum").get(vnfId);

executor.logger.info("vnfId=" + vnfId + ", blackFlag=" + blackFlag);

if (blackFlag != null && blackFlag == true) {
    var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfId);
    vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));
    vcpeClosedLoopStatus.put("notification", "BLACKLIST");
    var message = vcpeClosedLoopStatus.get("message");

    if (message != null) {
        vcpeClosedLoopStatus.put("message", message + ":VNF ID blacklisted");
    }
    else {
        vcpeClosedLoopStatus.put("message", "VNF ID blacklisted");
    }
}

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=CheckServiceIdTask
result: SUCCESS

/root> 
/root> task inputfield create name=CheckServiceIdTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=CheckServiceIdTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=CheckServiceIdTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=CheckServiceIdTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=CheckServiceIdTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=CheckServiceIdTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=CheckServiceIdTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> task contextref create name=CheckServiceIdTask albumName=ServiceIdWhiteBlackListAlbum
result: SUCCESS

/root> 
/root> task logic create name=CheckServiceIdTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var vnfId = executor.inFields.get("vnfID").toString();
var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfId);
var serviceId = vcpeClosedLoopStatus.get("AAI").get("genericVnfServiceId");
var blackFlag = executor.getContextAlbum("ServiceIdWhiteBlackListAlbum").get(serviceId.toString());

executor.logger.info("vnfId=" + vnfId + ", serviceId=" + serviceId + ", blackFlag=" + blackFlag);

if (blackFlag != null && blackFlag == true) {
    vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));
    vcpeClosedLoopStatus.put("notification", "BLACKLIST");
    var message = vcpeClosedLoopStatus.get("message");

    if (message != null) {
        vcpeClosedLoopStatus.put("message", message + ":Service ID blacklisted");
    }
    else {
        vcpeClosedLoopStatus.put("message", "Service ID blacklisted");
    }
}

executor.logger.info(executor.outFields);

true;


LE
result: SUCCESS

/root> 
/root> task create name=CheckVServerIdTask
result: SUCCESS

/root> 
/root> task inputfield create name=CheckVServerIdTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=CheckVServerIdTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=CheckVServerIdTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=CheckVServerIdTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=CheckVServerIdTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=CheckVServerIdTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=CheckVServerIdTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> task contextref create name=CheckVServerIdTask albumName=VServerIdWhiteBlackListAlbum
result: SUCCESS

/root> 
/root> task logic create name=CheckVServerIdTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var vnfId = executor.inFields.get("vnfID").toString();
var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfId);
var vServerId = vcpeClosedLoopStatus.get("AAI").get("vserverName");
var blackFlag = executor.getContextAlbum("VServerIdWhiteBlackListAlbum").get(vServerId.toString());

executor.logger.info("vnfId=" + vnfId + ", vServerId=" + vServerId + ", blackFlag=" + blackFlag);

if (blackFlag != null && blackFlag == true) {
    vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));
    vcpeClosedLoopStatus.put("notification", "BLACKLIST");
    var message = vcpeClosedLoopStatus.get("message");

    if (message != null) {
        vcpeClosedLoopStatus.put("message", message + ":VServer ID blacklisted");
    }
    else {
        vcpeClosedLoopStatus.put("message", "VServer ID blacklisted");
    }
}

executor.logger.info(executor.outFields);

true;


LE
result: SUCCESS

/root> 
/root> task create name=StopAndLogTask
result: SUCCESS

/root> 
/root> task inputfield create name=StopAndLogTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=StopAndLogTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=StopAndLogTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=StopAndLogTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=StopAndLogTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=StopAndLogTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=StopAndLogTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> task logic create name=StopAndLogTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var vcpeClosedLoopStatus = null;
if (executor.inFields.get("vnfID") == null) {
    executor.logger.info("AbatedTask: vnfID is null");
    var vnfName = executor.inFields.get("vnfName");
    vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum")
            .get(executor.inFields.get("vnfName"));
} else {
    vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum")
            .get(executor.inFields.get("vnfID").toString());
}

vcpeClosedLoopStatus.put("notificationTime", java.lang.Long.valueOf(Date.now()));

var message = vcpeClosedLoopStatus.get("message");
if (message == null || message == "") {
    vcpeClosedLoopStatus.put("message", "situation has been abated");
}
else {
    vcpeClosedLoopStatus.put("notification", "FINAL_FAILURE");
}

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=InitiateActionsTask
result: SUCCESS

/root> 
/root> task inputfield create name=InitiateActionsTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=InitiateActionsTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=InitiateActionsTask fieldName=ActionEventList schemaName=ActionEventListType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=InitiateActionsTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> task logic create name=InitiateActionsTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(
        executor.inFields.get("vnfID").toString());

var eventList = executor.subject.getOutFieldSchemaHelper("ActionEventList").createNewInstance();

var eventType = org.onap.policy.apex.service.engine.event.ApexEvent;

var controllerRequestActionEvent = new eventType("ActionEvent", "0.0.1", "org.onap.policy.apex.onap.vcpe", "APEX",
        "APEX");

controllerRequestActionEvent.put("action", "ControllerRequestAction");
controllerRequestActionEvent.put("requestID", executor.inFields.get("requestID"));
controllerRequestActionEvent.put("vnfID", executor.inFields.get("vnfID"));
controllerRequestActionEvent.put("vnfName", executor.inFields.get("vnfName"));

eventList.add(controllerRequestActionEvent);

var logActionEvent = new eventType("ActionEvent", "0.0.1", "org.onap.policy.apex.onap.vcpe", "APEX", "APEX");

logActionEvent.put("action", "LogAction");
logActionEvent.put("requestID", executor.inFields.get("requestID"));
logActionEvent.put("vnfID", executor.inFields.get("vnfID"));
logActionEvent.put("vnfName", executor.inFields.get("vnfName"));

eventList.add(logActionEvent);

executor.outFields.put("ActionEventList", eventList);

executor.logger.info(executor.outFields);

true;


LE
result: SUCCESS

/root> 
/root> task create name=DoControllerRequestActionTask
result: SUCCESS

/root> 
/root> task inputfield create name=DoControllerRequestActionTask fieldName=action   schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=DoControllerRequestActionTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=DoControllerRequestActionTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=DoControllerRequestActionTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=DoControllerRequestActionTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=DoControllerRequestActionTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=DoControllerRequestActionTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> task logic create name=DoControllerRequestActionTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

// Pass through to the log state

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=DoLogActionTask
result: SUCCESS

/root> 
/root> task inputfield create name=DoLogActionTask fieldName=action   schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=DoLogActionTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=DoLogActionTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=DoLogActionTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=DoLogActionTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=DoLogActionTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=DoLogActionTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> task logic create name=DoLogActionTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

// Pass through to the log state

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=ControllerRequestTask
result: SUCCESS

/root> 
/root> task inputfield create name=ControllerRequestTask fieldName=action    schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=ControllerRequestTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=ControllerRequestTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=ControllerRequestTask fieldName=vnfName   schemaName=SimpleStringType optional=true
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=ControllerRequestTask fieldName=ControllerRequest schemaName=ControllerRequestType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=ControllerRequestTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> task contextref create name=ControllerRequestTask albumName=RequestIDVNFIDAlbum
result: SUCCESS

/root> 
/root> task logic create name=ControllerRequestTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var controllerRequest = executor.subject.getOutFieldSchemaHelper("ControllerRequest").createNewInstance();

var controllerRequestBody = executor.subject.getOutFieldSchemaHelper("ControllerRequest").createNewSubInstance(
        "Controller_Body_Type");

var controllerRequestBodyInput = executor.subject.getOutFieldSchemaHelper("ControllerRequest").createNewSubInstance(
        "Controller_Body_Type_Input");

var controllerRequestBodyInputCommonHeader = executor.subject.getOutFieldSchemaHelper("ControllerRequest")
        .createNewSubInstance("Controller_Body_Type_Common_Header");

var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(
        executor.inFields.get("vnfID").toString());

controllerRequest.put("version", "2.0.0");
controllerRequest.put("rpc_DasH_name", "restart");
controllerRequest.put("correlation_DasH_id", executor.inFields.get("requestID").toString());
controllerRequest.put("type", "request");

controllerRequestBodyInput.put("action", "Restart");
controllerRequestBodyInput.put("action_DasH_identifiers", new java.util.HashMap());
controllerRequestBodyInput.get("action_DasH_identifiers").put("vnf-id", executor.inFields.get("vnfID").toString());

controllerRequestBodyInputCommonHeader.put("timestamp",  java.lang.Long.valueOf(Date.now()));
controllerRequestBodyInputCommonHeader.put("api_DasH_ver", "2.00");
controllerRequestBodyInputCommonHeader.put("originator_DasH_id", executor.inFields.get("requestID").toString());
controllerRequestBodyInputCommonHeader.put("request_DasH_id", executor.inFields.get("requestID").toString());
controllerRequestBodyInputCommonHeader.put("sub_DasH_request_DasH_id", "1");
controllerRequestBodyInputCommonHeader.put("flags", new java.util.HashMap());
controllerRequestBodyInputCommonHeader.get("flags").put("ttl", "10000");
controllerRequestBodyInputCommonHeader.get("flags").put("force", "TRUE");
controllerRequestBodyInputCommonHeader.get("flags").put("mode", "EXCLUSIVE");

controllerRequestBodyInput.put("common_DasH_header", controllerRequestBodyInputCommonHeader);
controllerRequestBody.put("input", controllerRequestBodyInput);
controllerRequest.put("body", controllerRequestBody);

executor.getContextAlbum("RequestIDVNFIDAlbum").put(executor.inFields.get("requestID").toString(),
        executor.inFields.get("vnfID"));

vcpeClosedLoopStatus.put("notification", "OPERATION");
vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));

executor.outFields.put("ControllerRequest", controllerRequest);

executor.logger.info(executor.outFields);

true;


LE
result: SUCCESS

/root> 
/root> task create name=ControllerResponseTask
result: SUCCESS

/root> 
/root> task inputfield create name=ControllerResponseTask fieldName=ControllerResponse schemaName=ControllerResponseType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=ControllerResponseTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=ControllerResponseTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=ControllerResponseTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> task contextref create name=ControllerResponseTask albumName=RequestIDVNFIDAlbum
result: SUCCESS

/root> 
/root> task logic create name=ControllerResponseTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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.
 *
 * APPC LCM Response code: 100 ACCEPTED
 *                         200 ERROR UNEXPECTED ERROR means failure
 *                         312 REJECTED DUPLICATE REQUEST
 *                         400 SUCCESS
 *
 * Note: Sometimes the corelationId has a -1 at the tail, need to get rid of it when present.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);

var controllerResponse = executor.inFields.get("ControllerResponse");

var requestIDString = new java.lang.String(controllerResponse.get("correlation_DasH_id"));
executor.logger.info("requestIDString =\"" + requestIDString + "\"");
var vnfID = executor.getContextAlbum("RequestIDVNFIDAlbum").get(requestIDString);
executor.logger.info("vnfID = " + vnfID);

var returnValue = true

if (vnfID != null) {
    var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfID.toString());
    var requestId = java.util.UUID.fromString(vcpeClosedLoopStatus.get("requestID"));

    vcpeClosedLoopStatus.put("notificationTime",  java.lang.Long.valueOf(Date.now()));

    var returnedCode = controllerResponse.get("body").get("output").get("status").get("code");
    var responseStatus = null;

    if (returnedCode == 100) {
        responseStatus = "ACCEPTED";
    } else if (returnedCode == 200) {
        responseStatus = "ERROR";
    } else if (returnedCode >= 300 && returnedCode <= 316) {
        responseStatus = "REJECT";
    } else if (returnedCode == 400) {
        responseStatus = "SUCCESS";
    } else if (returnedCode == 450 || (returnedCode >= 401 && returnedCode <= 406)) {
        responseStatus = "FAILURE";
    } else if (returnedCode == 500) {
        responseStatus = "PARTIAL_SUCCESS";
    } else if (returnedCode >= 501 && returnedCode <= 599) {
        responseStatus = "PARTIAL_FAILURE";
    } else {
        responseStatus = "SYSTEM_ERROR";
    }

    executor.logger.info("Got from APPC code: " + responseStatus);

    if (responseStatus == "SUCCESS") {
        vcpeClosedLoopStatus.put("notification", "OPERATION_SUCCESS");
        vcpeClosedLoopStatus.put("message", "vCPE restarted");
        executor.getContextAlbum("RequestIDVNFIDAlbum").remove(requestIDString);
    } else if (responseStatus == "ACCEPTED" || responseStatus == "REJECT") {
        executor.logger.info("Got ACCEPTED 100 or REJECT 312, keep the context, wait for next response. Code is: "
                + responseStatus);
    } else {
        executor.getContextAlbum("RequestIDVNFIDAlbum").remove(requestIDString);
        vcpeClosedLoopStatus.put("notification", "OPERATION_FAILURE");
        vcpeClosedLoopStatus.put("message", "vCPE restart failed, code is " + responseStatus + ", message is "
                + controllerResponse.get("body").get("output").get("status").get("message"));
    }

    executor.outFields.put("requestID", requestId);
    executor.outFields.put("vnfID", vnfID);
} else {
    executor.message = "VNF ID not found in context album for request ID " + requestIDString;
    returnValue = false;
}

executor.logger.info(executor.outFields);

returnValue;

LE
result: SUCCESS

/root> 
/root> task create name=ControlLoopLogTask
result: SUCCESS

/root> 
/root> task inputfield create name=ControlLoopLogTask fieldName=requestID schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=ControlLoopLogTask fieldName=vnfID     schemaName=UUIDType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=ControlLoopLogTask fieldName=VirtualControlLoopNotification schemaName=VirtualControlLoopNotificationType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=ControlLoopLogTask albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> task logic create name=ControlLoopLogTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var vnfID = executor.inFields.get("vnfID");
if (vnfID == null) {
    vnfID = executor.inFields.get("vnfName");
}
executor.logger.info("vnfID=" + vnfID);

var controlLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfID.toString());

executor.logger.info("Logging context information for VNF \"" + vnfID + "\"");

var clNotification = executor.subject.getOutFieldSchemaHelper("VirtualControlLoopNotification").createNewInstance();

clNotification.put("requestID",             executor.inFields.get("requestID").toString());
clNotification.put("closedLoopControlName", controlLoopStatus.get("closedLoopControlName"));
clNotification.put("closedLoopAlarmStart",  controlLoopStatus.get("closedLoopAlarmStart"));
clNotification.put("closedLoopAlarmEnd",    controlLoopStatus.get("closedLoopAlarmEnd"));
clNotification.put("closedLoopEventClient", controlLoopStatus.get("closedLoopEventClient"));
clNotification.put("version",               controlLoopStatus.get("version"));
clNotification.put("targetType",            controlLoopStatus.get("target_type"));
clNotification.put("target",                controlLoopStatus.get("target"));
clNotification.put("from",                  controlLoopStatus.get("from"));
clNotification.put("policyScope",           controlLoopStatus.get("policyScope"));
clNotification.put("policyName",            controlLoopStatus.get("policyName"));
clNotification.put("policyVersion",         controlLoopStatus.get("policyVersion"));
clNotification.put("notification",          controlLoopStatus.get("notification"));
clNotification.put("message",               controlLoopStatus.get("message"));
clNotification.put("notificationTime",      controlLoopStatus.get("notificationTime"));
clNotification.put("opsClTimer",            0);

var aaiInfo = controlLoopStatus.get("AAI");

var aaiInfoOut = new java.util.HashMap();

aaiInfoOut.put("generic-vnf.resource-version", aaiInfo.get("genericVnfResourceVersion"));
aaiInfoOut.put("generic-vnf.vnf-name", aaiInfo.get("genericVnfVnfName"));
aaiInfoOut.put("generic-vnf.prov-status", aaiInfo.get("genericVnfProvStatus"));
aaiInfoOut.put("generic-vnf.is-closed-loop-disabled", aaiInfo.get("genericVnfIsClosedLoopDisabled"));
aaiInfoOut.put("generic-vnf.orchestration-status", aaiInfo.get("genericVnfOrchestrationStatus"));
aaiInfoOut.put("generic-vnf.vnf-type", aaiInfo.get("genericVnfVnfType"));
aaiInfoOut.put("generic-vnf.in-maint", aaiInfo.get("genericVnfInMaint"));
aaiInfoOut.put("generic-vnf.service-id", aaiInfo.get("genericVnfServiceId"));
if (vnfID != null) {
    aaiInfoOut.put("generic-vnf.vnf-id", aaiInfo.get("genericVnfVnfId"));
}

clNotification.put("AAI", aaiInfoOut);

executor.outFields.put("VirtualControlLoopNotification", clNotification);

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=ConfigureBlackWhiteListTask
result: SUCCESS

/root> 
/root> task inputfield create name=ConfigureBlackWhiteListTask fieldName=targetType schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=ConfigureBlackWhiteListTask fieldName=black schemaName=SimpleBooleanType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=ConfigureBlackWhiteListTask fieldName=target schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=ConfigureBlackWhiteListTask fieldName=targetType schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=ConfigureBlackWhiteListTask fieldName=black schemaName=SimpleBooleanType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=ConfigureBlackWhiteListTask fieldName=target schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=ConfigureBlackWhiteListTask albumName=VnfIdWhiteBlackListAlbum
result: SUCCESS

/root> task contextref create name=ConfigureBlackWhiteListTask albumName=ServiceIdWhiteBlackListAlbum
result: SUCCESS

/root> task contextref create name=ConfigureBlackWhiteListTask albumName=VServerIdWhiteBlackListAlbum
result: SUCCESS

/root> 
/root> task logic create name=ConfigureBlackWhiteListTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

// Pass through to the log state

executor.logger.info(executor.outFields);

var targetType = executor.inFields.get("targetType");
var target = executor.inFields.get("target");
var black = executor.inFields.get("black");

var returnValue = true;

if (targetType == "VNF") {
    executor.getContextAlbum("VnfIdWhiteBlackListAlbum").put(target, black);
    executor.logger.info("added VNF ID \"" + target + "\" with black flag \"" + black + "\" to VNF ID list");
}
else if (targetType == "Service") {
    executor.getContextAlbum("ServiceIdWhiteBlackListAlbum").put(target, black);
    executor.logger.info("added Service ID \"" + target + "\" with black flag \"" + black + "\" to Service ID list");
}
else if (targetType == "VServer") {
    executor.getContextAlbum("VServerIdWhiteBlackListAlbum").put(target, black);
    executor.logger.info("added VServer ID \"" + target + "\" with black flag \"" + black + "\" to VServer ID list");
}
else {
    executor.logger.warn("unknown target type \"" + targetType + "\" specified");
    returnValue = false;
}

returnValue;


LE
result: SUCCESS

/root> 
/root> #
/root> # ReceiveEventPolicy
/root> #
/root> policy create name=ReceiveEventPolicy template=Freestyle firstState=GetEntityState
result: SUCCESS

/root> 
/root> policy state create name=ReceiveEventPolicy stateName=LogAndStopState triggerName=EntityStateUpdatedEvent defaultTaskName=ControlLoopLogTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=LogAndStopState outputName=AbatedOutput eventName=ControlLoopLogEvent
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=LogAndStopState taskName=ControlLoopLogTask outputType=DIRECT outputName=AbatedOutput
result: SUCCESS

/root> 
/root> policy state create name=ReceiveEventPolicy stateName=ExecuteOrLogState triggerName=EntityStateUpdatedEvent defaultTaskName=StopAndLogTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=ExecuteOrLogState outputName=ExecuteOutput eventName=ActionEventListEvent
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=ExecuteOrLogState taskName=InitiateActionsTask outputType=DIRECT outputName=ExecuteOutput
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=ExecuteOrLogState outputName=StopAndLogOutput eventName=EntityStateUpdatedEvent nextState=LogAndStopState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=ExecuteOrLogState taskName=StopAndLogTask outputType=DIRECT outputName=StopAndLogOutput
result: SUCCESS

/root> 
/root> policy state contextref create name=ReceiveEventPolicy stateName=ExecuteOrLogState albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> policy state selecttasklogic create name=ReceiveEventPolicy stateName=ExecuteOrLogState logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var returnValue = true;

if( executor.inFields.get("vnfID") == null) {
   executor.logger.info("ControlLoopStatusAlbum: vnfID is null");
   var vnfName = executor.inFields.get("vnfName");
   var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(
        executor.inFields.get("vnfName"));
} else {
   var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(
        executor.inFields.get("vnfID").toString());
}

var status = vcpeClosedLoopStatus.get("closedLoopEventStatus").toString();
var notification = vcpeClosedLoopStatus.get("notification");

if (notification != null && notification == "BLACKLIST") {
    executor.subject.getTaskKey("StopAndLogTask").copyTo(executor.selectedTask);
}
else {
    if (status == "ONSET") {
        executor.subject.getTaskKey("InitiateActionsTask").copyTo(executor.selectedTask);
    } else if (status == "ABATED") {
        executor.subject.getTaskKey("StopAndLogTask").copyTo(executor.selectedTask);
    } else {
        executor.message = "closedLoopEventStatus is \"" + status + "\", it must be either \"ONSET\" or \"ABATED\"";
        returnValue = false;
    }
}

executor.logger.info("ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:" + executor.selectedTask);

returnValue;

LE
result: SUCCESS

/root> 
/root> policy state create name=ReceiveEventPolicy stateName=CheckVNFIdState triggerName=EntityStateUpdatedEvent defaultTaskName=CheckVNFIdTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=CheckVNFIdState outputName=CheckVNFIdOutput eventName=EntityStateUpdatedEvent nextState=ExecuteOrLogState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CheckVNFIdState taskName=CheckVNFIdTask outputType=DIRECT outputName=CheckVNFIdOutput
result: SUCCESS

/root> 
/root> policy state create name=ReceiveEventPolicy stateName=CheckVServerIdState triggerName=EntityStateUpdatedEvent defaultTaskName=CheckVServerIdTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=CheckVServerIdState outputName=CheckVServerIdOutput eventName=EntityStateUpdatedEvent nextState=CheckVNFIdState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CheckVServerIdState taskName=CheckVServerIdTask outputType=DIRECT outputName=CheckVServerIdOutput
result: SUCCESS

/root> 
/root> policy state create name=ReceiveEventPolicy stateName=CheckServiceIdState triggerName=EntityStateUpdatedEvent defaultTaskName=CheckServiceIdTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=CheckServiceIdState outputName=CheckServiceIdOutput eventName=EntityStateUpdatedEvent nextState=CheckVServerIdState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CheckServiceIdState taskName=CheckServiceIdTask outputType=DIRECT outputName=CheckServiceIdOutput
result: SUCCESS

/root> 
/root> policy state create name=ReceiveEventPolicy stateName=GetEntityState triggerName=VirtualControlLoopEvent defaultTaskName=GetEntityStateTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=GetEntityState outputName=GetEntityStateOutput eventName=EntityStateUpdatedEvent nextState=CheckServiceIdState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=GetEntityState taskName=GetEntityStateTask outputType=DIRECT outputName=GetEntityStateOutput
result: SUCCESS

/root> 
/root> policy state contextref create name=ReceiveEventPolicy stateName=GetEntityState albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> #
/root> # ExecuteActionsPolicy
/root> #
/root> policy create name=ExecuteActionsPolicy template=Freestyle firstState=ActionState
result: SUCCESS

/root> 
/root> policy state create name=ExecuteActionsPolicy stateName=ControllerRequestActionState triggerName=ActionEvent defaultTaskName=ControllerRequestTask
result: SUCCESS

/root> policy state output create name=ExecuteActionsPolicy stateName=ControllerRequestActionState outputName=ControllerRequestOutput eventName=ControllerRequestEvent
result: SUCCESS

/root> policy state taskref create name=ExecuteActionsPolicy stateName=ControllerRequestActionState taskName=ControllerRequestTask outputType=DIRECT outputName=ControllerRequestOutput
result: SUCCESS

/root> 
/root> policy state create name=ExecuteActionsPolicy stateName=LogActionState triggerName=EntityStateUpdatedEvent defaultTaskName=ControlLoopLogTask
result: SUCCESS

/root> policy state output create name=ExecuteActionsPolicy stateName=LogActionState outputName=ResponseLogOutput eventName=ControlLoopLogEvent
result: SUCCESS

/root> policy state taskref create name=ExecuteActionsPolicy stateName=LogActionState taskName=ControlLoopLogTask outputType=DIRECT outputName=ResponseLogOutput
result: SUCCESS

/root> 
/root> policy state create name=ExecuteActionsPolicy stateName=ActionState triggerName=ActionEvent defaultTaskName=DoLogActionTask
result: SUCCESS

/root> policy state output create name=ExecuteActionsPolicy stateName=ActionState outputName=LogActionOutput eventName=EntityStateUpdatedEvent nextState=LogActionState
result: SUCCESS

/root> policy state taskref create name=ExecuteActionsPolicy stateName=ActionState taskName=DoLogActionTask outputType=DIRECT outputName=LogActionOutput
result: SUCCESS

/root> policy state output create name=ExecuteActionsPolicy stateName=ActionState outputName=ControllerRequestActionOutput eventName=ActionEvent nextState=ControllerRequestActionState
result: SUCCESS

/root> policy state taskref create name=ExecuteActionsPolicy stateName=ActionState taskName=DoControllerRequestActionTask outputType=DIRECT outputName=ControllerRequestActionOutput
result: SUCCESS

/root> 
/root> policy state contextref create name=ExecuteActionsPolicy stateName=ActionState albumName=ControlLoopStatusAlbum
result: SUCCESS

/root> 
/root> policy state selecttasklogic create name=ExecuteActionsPolicy stateName=ActionState logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 *  Modifications Copyright (C) 2020 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(executor.subject.id);
executor.logger.info(executor.inFields);

var status = null;

if (executor.inFields.get("action") == "ControllerRequestAction") {
    executor.subject.getTaskKey("DoControllerRequestActionTask").copyTo(executor.selectedTask);
} else {
    executor.subject.getTaskKey("DoLogActionTask").copyTo(executor.selectedTask);
}

executor.logger.info("ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:" + executor.selectedTask);

true;

LE
result: SUCCESS

/root> 
/root> #
/root> # ControllerResponsePolicy
/root> #
/root> policy create name=ControllerResponsePolicy template=Freestyle firstState=ControllerResponseState
result: SUCCESS

/root> 
/root> policy state create name=ControllerResponsePolicy stateName=ResponseLogState triggerName=EntityStateUpdatedEvent defaultTaskName=ControlLoopLogTask
result: SUCCESS

/root> policy state output create name=ControllerResponsePolicy stateName=ResponseLogState outputName=ResponseLogOutput eventName=ControlLoopLogEvent
result: SUCCESS

/root> policy state taskref create name=ControllerResponsePolicy stateName=ResponseLogState taskName=ControlLoopLogTask outputType=DIRECT outputName=ResponseLogOutput
result: SUCCESS

/root> 
/root> policy state create name=ControllerResponsePolicy stateName=ControllerResponseState triggerName=ControllerResponseEvent defaultTaskName=ControllerResponseTask
result: SUCCESS

/root> policy state output create name=ControllerResponsePolicy stateName=ControllerResponseState outputName=ControllerResponseOutput eventName=EntityStateUpdatedEvent nextState=ResponseLogState
result: SUCCESS

/root> policy state taskref create name=ControllerResponsePolicy stateName=ControllerResponseState taskName=ControllerResponseTask outputType=DIRECT outputName=ControllerResponseOutput
result: SUCCESS

/root> 
/root> #
/root> # ConfigureBlackWhiteListPolicy
/root> #
/root> policy create name=ConfigureBlackWhiteListPolicy template=Freestyle firstState=ConfigureBlackWhiteListState
result: SUCCESS

/root> 
/root> policy state create name=ConfigureBlackWhiteListPolicy stateName=ConfigureBlackWhiteListState triggerName=ConfigureBlackWhiteListEvent defaultTaskName=ConfigureBlackWhiteListTask
result: SUCCESS

/root> policy state output create name=ConfigureBlackWhiteListPolicy stateName=ConfigureBlackWhiteListState outputName=ConfigureBlackWhiteListOutput eventName=ConfigureBlackWhiteListResultEvent
result: SUCCESS

/root> policy state taskref create name=ConfigureBlackWhiteListPolicy stateName=ConfigureBlackWhiteListState taskName=ConfigureBlackWhiteListTask outputType=DIRECT outputName=ConfigureBlackWhiteListOutput
result: SUCCESS

/root> 
/root> validate
result: SUCCESS
{
  "name": "ONAPvCPEPolicyModelStandalone",
  "version": "0.0.1"
}
***validation of model successful***

/root> 