Use lombok in apex-pdp #5
[policy/apex-pdp.git] / examples / examples-aadm / src / main / resources / org / onap / policy / apex / examples / aadm / model / mvel / AADMPolicyActTaskSelectionLogic.mvel
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
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 import org.onap.policy.apex.examples.aadm.concepts.ImsiStatus;
22 import org.onap.policy.apex.examples.aadm.concepts.ENodeBStatus;
23
24 logger.debug(subject.id + ":" + subject.stateName + " execution logic");
25 logger.debug(inFields);
26
27 logger.debug("inFields[SERVICE_REQUEST_COUNT]=" + inFields["SERVICE_REQUEST_COUNT"]);
28
29 ImsiStatus imsiStatus = getContextAlbum("IMSIStatusAlbum").get((String)inFields["IMSI"]);
30
31 if (imsiStatus.getBlockingCount() > 1) {
32     subject.getTaskKey("AADMNoActTask").copyTo(selectedTask);
33     logger.debug("user blacklisted permanently");
34     return false;
35 }
36
37 logger.debug("imsi: " + imsiStatus.getImsi() + " anamalous " + imsiStatus.isAnomalous());
38
39 // check if this is second iteration
40 if (inFields["TCP_UE_SIDE_AVG_THROUGHPUT"] != null && inFields["TCP_UE_SIDE_AVG_THROUGHPUT"] > 100 && imsiStatus.isAnomalous()) {
41     subject.getTaskKey("AADMDoSProvenActTask").copyTo(selectedTask);
42     logger.debug("inside TCP_UE_SIDE_AVG_THROUGHPUT");
43     return true;
44 }
45
46 // Get the status of the ENodeB
47 ENodeBStatus eNodeBStatus = getContextAlbum("ENodeBStatusAlbum").get((String)inFields["ENODEB_ID"]);
48
49 // check if this is first iteration and DoS
50 if (inFields["SERVICE_REQUEST_COUNT"] != null &&
51         inFields["AVG_SUBSCRIBER_SERVICE_REQUEST"] != null &&
52         inFields["SERVICE_REQUEST_COUNT"] > inFields["AVG_SUBSCRIBER_SERVICE_REQUEST"] &&
53         eNodeBStatus != null && eNodeBStatus.getDosCount() > 100 &&
54         inFields["NUM_SUBSCRIBERS"] != null && inFields["NUM_SUBSCRIBERS"]  > 100) {
55     logger.debug("inside NUM_SUBSCRIBERS");
56     subject.getTaskKey("AADMDoSProvenActTask").copyTo(selectedTask);
57     return true;
58 }
59
60 // check if this is first iteration and request probe
61 if (inFields["UE_IP_ADDRESS"] != null) {
62     logger.debug("inside UE_IP_ADDRESS");
63     subject.getTaskKey("AADMDoSSuggestionActTask").copyTo(selectedTask);
64     return true;
65 }
66
67 subject.defaultTaskKey.copyTo(selectedTask);
68 return true;