57fe182e1a3e3c0192e0decad71283cf8433b0b7
[policy/apex-pdp.git] / examples / examples-onap-bbs / src / main / resources / logic / GetBBSCloseLoopEventTask.js
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Huawei. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 load("nashorn:mozilla_compat.js");
21
22 executor.logger.info("Begin Execution GetBBSCloseLoopEventTask.js");
23 executor.logger.info(executor.subject.id);
24 executor.logger.info(executor.inFields);
25 var returnValue = executor.isTrue;
26
27 var clEventType = Java.type(
28     "org.onap.policy.controlloop.VirtualControlLoopEvent");
29 var clEvent = executor.inFields.get("VirtualControlLoopEvent");
30 executor.logger.info(clEvent.toString());
31 executor.logger.info(clEvent.getClosedLoopControlName());
32
33 var requestID = clEvent.getRequestId();
34 executor.logger.info("requestID = " + requestID);
35 var attachmentPoint = null;
36 var NomadicONTContext = null;
37 var serviceInstanceId = null;
38
39 if (clEvent.getAai().get("attachmentPoint") != null) {
40     attachmentPoint = clEvent.getAai().get("attachmentPoint");
41     executor.logger.info("attachmentPoint = " + attachmentPoint);
42     NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(
43         attachmentPoint);
44     serviceInstanceId = clEvent.getAai().get(
45         "service-information.hsia-cfs-service-instance-id");
46     executor.logger.info("serviceInstanceId = " + serviceInstanceId);
47
48     if (NomadicONTContext == null) {
49         executor.logger.info(
50             "Creating context information for new ONT Device \"" +
51             attachmentPoint.toString() + "\"");
52
53         NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").getSchemaHelper()
54             .createNewInstance();
55
56         NomadicONTContext.put("closedLoopControlName", clEvent.getClosedLoopControlName());
57         NomadicONTContext.put("closedLoopAlarmStart", clEvent.getClosedLoopAlarmStart()
58             .toEpochMilli());
59         NomadicONTContext.put("closedLoopEventClient", clEvent.getClosedLoopEventClient());
60         NomadicONTContext.put("closedLoopEventStatus", clEvent.getClosedLoopEventStatus()
61             .toString());
62         NomadicONTContext.put("version", clEvent.getVersion());
63         NomadicONTContext.put("requestID", clEvent.getRequestId().toString());
64         NomadicONTContext.put("target_type", clEvent.getTargetType().toString());
65         NomadicONTContext.put("target", clEvent.getTarget());
66         NomadicONTContext.put("from", clEvent.getFrom());
67         NomadicONTContext.put("policyScope", "Nomadic ONT");
68         NomadicONTContext.put("policyName", clEvent.getPolicyName());
69         NomadicONTContext.put("policyVersion", "1.0.0");
70         NomadicONTContext.put("notificationTime", java.lang.System.currentTimeMillis());
71         NomadicONTContext.put("message", "");
72         NomadicONTContext.put("result", "SUCCESS");
73         var aaiInfo = executor.getContextAlbum("NomadicONTContextAlbum").getSchemaHelper()
74             .createNewSubInstance("VCPE_AAI_Type");
75
76         aaiInfo.put("attachmentPoint", clEvent.getAai().get("attachmentPoint"));
77         aaiInfo.put("cvlan", clEvent.getAai().get("cvlan"));
78         aaiInfo.put("service_information_hsia_cfs_service_instance_id", clEvent
79             .getAai().get(
80                 "service-information.hsia-cfs-service-instance-id"));
81         aaiInfo.put("svlan", clEvent.getAai().get("svlan"));
82         aaiInfo.put("remoteId", clEvent.getAai().get("remoteId"));
83
84
85         NomadicONTContext.put("AAI", aaiInfo);
86
87         if (clEvent.getClosedLoopAlarmEnd() != null) {
88             NomadicONTContext.put("closedLoopAlarmEnd", clEvent.getClosedLoopAlarmEnd()
89                 .toEpochMilli());
90         } else {
91             NomadicONTContext.put("closedLoopAlarmEnd", java.lang.Long.valueOf(
92                 0));
93         }
94
95         executor.getContextAlbum("NomadicONTContextAlbum").put(attachmentPoint.toString(),
96             NomadicONTContext);
97         executor.logger.info("Created context information for new vCPE VNF \"" +
98             attachmentPoint.toString() + "\"");
99     }
100
101     executor.outFields.put("requestID", requestID);
102     executor.outFields.put("attachmentPoint", attachmentPoint);
103     executor.outFields.put("serviceInstanceId", serviceInstanceId);
104     executor.logger.info(executor.outFields);
105     executor.logger.info("Event Successfully Received and stored in album");
106 }
107 else
108 {
109     executor.message = "Received NULL attachment-point";
110     returnValue = executor.isFalse;
111 }
112