d62bed60957dd84e17fad483bca671c46b303684
[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 ifCustomerName = executor.inFields["customerName"];
27 var ifLinks = executor.inFields["links"];
28
29 logger.trace("-- got infields, testing existing customer");
30 var ctxtCustomer = executor.getContextAlbum("albumCustomerMap").get(ifCustomerName);
31 if (ctxtCustomer != null) {
32     executor.getContextAlbum("albumCustomerMap").remove(ifCustomerName);
33     logger.trace("-- removed customer: <" + ifCustomerName + ">");
34 }
35
36 logger.trace("-- creating customer: <" + ifCustomerName + ">");
37 var links = new Array();
38 for (var i = 0; i < ifLinks.split(" ").length; i++) {
39     var link = executor.getContextAlbum("albumTopoEdges").get(ifLinks.split(" ")[i]);
40     if (link != null) {
41         logger.trace("-- link: <" + ifLinks.split(" ")[i] + ">");
42         links.push(ifLinks.split(" ")[i]);
43     } else {
44         logger.trace("-- unknown link: <" + ifLinks.split(" ")[i] + "> for customer <" + ifCustomerName + ">");
45     }
46 }
47 logger.trace("-- links: <" + links + ">");
48 ctxtCustomer = "{customerName:" + ifCustomerName + ", dtSLA:" + executor.inFields["dtSLA"] + ", dtYTD:"
49         + executor.inFields["dtYTD"] + ", priority:" + executor.inFields["priority"] + ", satisfaction:"
50         + executor.inFields["satisfaction"] + ", links:[" + links + "]}";
51
52 executor.getContextAlbum("albumCustomerMap").put(ifCustomerName, ctxtCustomer);
53
54 if (logger.isTraceEnabled()) {
55     logger.trace("   >> *** Customers ***");
56     if (executor.getContextAlbum("albumCustomerMap") != null) {
57         for (var i = 0; i < executor.getContextAlbum("albumCustomerMap").values().size(); i++) {
58             logger.trace("   >> >> " + executor.getContextAlbum("albumCustomerMap").values().get(i).get("customerName")
59                     + " : " + "dtSLA=" + executor.getContextAlbum("albumCustomerMap").values().get(i).get("dtSLA")
60                     + " : " + "dtYTD=" + executor.getContextAlbum("albumCustomerMap").values().get(i).get("dtYTD")
61                     + " : " + "links=" + executor.getContextAlbum("albumCustomerMap").values().get(i).get("links")
62                     + " : " + "priority="
63                     + executor.getContextAlbum("albumCustomerMap").values().get(i).get("priority") + " : "
64                     + "satisfaction="
65                     + executor.getContextAlbum("albumCustomerMap").values().get(i).get("satisfaction"));
66         }
67     } else {
68         logger.trace("   >> >> customer album is null");
69     }
70 }
71
72 executor.outFields["report"] = "customer ctxt :: added customer: " + ifCustomerName;
73
74 logger.info("vpnsla: ctxt added customer " + ifCustomerName);
75
76 logger.trace("finished: " + executor.subject.id);
77 logger.debug(".");
78
79 true;