9d4399f27d37edce131605caf873984de585ac26
[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 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 returnValue = true;
34 if (ifSituation.get("problemID") == "NONE") {
35     logger.trace("-- situation has no problem, selecting <VpnSlaPolicyDecideNoneTask>");
36     executor.subject.getTaskKey("VpnSlaPolicyDecideNoneTask").copyTo(executor.selectedTask);
37 } else if (albumProblemMap.get(ifSituation.get("problemID")).get("status") == "SOLVED") {
38     logger.trace("-- situation is solved, selecting <VpnSlaPolicyDecideSolvedTask>");
39     executor.subject.getTaskKey("VpnSlaPolicyDecideSolvedTask").copyTo(executor.selectedTask);
40 } else if (ifSituation.get("violatedSLAs") != null && ifSituation.get("violatedSLAs").size() > 0) {
41     logger.trace("-- situation is problem with violations, selecting <VpnSlaPolicyDecidePriorityTask>");
42     executor.subject.getTaskKey("VpnSlaPolicyDecidePriorityTask").copyTo(executor.selectedTask);
43 } else if (ifSituation.get("violatedSLAs") != null && ifSituation.get("violatedSLAs").size() == 0) {
44     logger.trace("-- situation is problem without violations, selecting <VpnSlaPolicyDecideSlaTask>");
45     executor.subject.getTaskKey("VpnSlaPolicyDecideSlaTask").copyTo(executor.selectedTask);
46 } else {
47     logger.error("-- detected unknown decision for situation <" + ifSituation.get("problemID") + ">");
48     rootLogger.error(executor.subject.id + " " + "-- detected unknown decision for situation <"
49             + ifSituation.get("problemID") + ">");
50     returnValue = false;
51 }
52
53 logger.trace("finished: " + executor.subject.id);
54 logger.debug(".d-tsl");
55
56 returnValue;