44767467d85454e43703e0c09957c3c40516acda
[policy/apex-pdp.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. 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
21 load("nashorn:mozilla_compat.js");
22 importClass(org.slf4j.LoggerFactory);
23
24 var logger = executor.logger;
25 logger.trace("start: " + executor.subject.id + " - TSL");
26
27 var rootLogger = LoggerFactory.getLogger(logger.ROOT_LOGGER_NAME);
28
29 var ifSituation = executor.inFields["situation"];
30
31 var albumProblemMap = executor.getContextAlbum("albumProblemMap");
32
33 var returnValueType = Java.type("java.lang.Boolean");
34 if (ifSituation.get("problemID") == "NONE") {
35     logger.trace("-- situation has no problem, selecting <VpnSlaPolicyDecideNoneTask>");
36     executor.subject.getTaskKey("VpnSlaPolicyDecideNoneTask").copyTo(executor.selectedTask);
37     var returnValue = new returnValueType(true);
38 } else if (albumProblemMap.get(ifSituation.get("problemID")).get("status") == "SOLVED") {
39     logger.trace("-- situation is solved, selecting <VpnSlaPolicyDecideSolvedTask>");
40     executor.subject.getTaskKey("VpnSlaPolicyDecideSolvedTask").copyTo(executor.selectedTask);
41     var returnValue = new returnValueType(true);
42 } else if (ifSituation.get("violatedSLAs") != null && ifSituation.get("violatedSLAs").size() > 0) {
43     logger.trace("-- situation is problem with violations, selecting <VpnSlaPolicyDecidePriorityTask>");
44     executor.subject.getTaskKey("VpnSlaPolicyDecidePriorityTask").copyTo(executor.selectedTask);
45     var returnValue = new returnValueType(true);
46 } else if (ifSituation.get("violatedSLAs") != null && ifSituation.get("violatedSLAs").size() == 0) {
47     logger.trace("-- situation is problem without violations, selecting <VpnSlaPolicyDecideSlaTask>");
48     executor.subject.getTaskKey("VpnSlaPolicyDecideSlaTask").copyTo(executor.selectedTask);
49     var returnValue = new returnValueType(true);
50 } else {
51     logger.error("-- detected unknown decision for situation <" + ifSituation.get("problemID") + ">");
52     rootLogger.error(executor.subject.id + " " + "-- detected unknown decision for situation <"
53             + ifSituation.get("problemID") + ">");
54     var returnValue = new returnValueType(false);
55 }
56
57 logger.trace("finished: " + executor.subject.id);
58 logger.debug(".d-tsl");