6ab79269390cd8c55175fde2e39e02cd5119066c
[policy/apex-pdp.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 var logger = executor.logger;
23 logger.trace("start: " + executor.subject.id);
24 logger.trace("-- infields: " + executor.inFields);
25
26 var ifDecision = executor.inFields["decision"];
27 var ifMatchStart = executor.inFields["matchStart"];
28
29 var albumCustomerMap = executor.getContextAlbum("albumCustomerMap");
30 var albumProblemMap = executor.getContextAlbum("albumProblemMap");
31
32 switch (ifDecision.get("decision").toString()) {
33 case "NONE":
34     executor.outFields["edgeName"] = "";
35     executor.outFields["action"] = "";
36     break;
37 case "IMPEDE":
38     for (var i = 0; i < ifDecision.get("customers").size(); i++) {
39         customer = albumCustomerMap.get(ifDecision.get("customers").get(i).toString());
40         executor.outFields["edgeName"] = customer.get("links").get(0);
41         executor.outFields["action"] = "firewall";
42     }
43     break;
44 case "REBUILD":
45     // finally solved, remove problem
46     albumProblemMap.remove(ifDecision.get("problemID"));
47     executor.outFields["edgeName"] = "L10"; // this is ###static###
48     executor.outFields["action"] = "rebuild"; // this is ###static###
49     break;
50 default:
51
52 }
53
54 if (executor.outFields["action"] != "") {
55     logger.info("vpnsla: action is to " + executor.outFields["action"] + " " + executor.outFields["edgeName"]);
56 } else {
57     logger.info("vpnsla: no action required");
58 }
59
60 logger.trace("-- outfields: " + executor.outFields);
61 logger.trace("finished: " + executor.subject.id);
62 logger.debug(".a");
63
64 var now = new Date().getTime();
65 logger.info("VPN SLA finished in " + (now - ifMatchStart) + " ms");
66
67 true;