29630e33c171e0454888a5c976990fda4dc57c5d
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.drools.apps.controlloop.feature.trans;
22
23 import org.onap.policy.controlloop.VirtualControlLoopNotification;
24 import org.onap.policy.drools.event.comm.Topic.CommInfrastructure;
25 import org.onap.policy.drools.features.PolicyControllerFeatureAPI;
26 import org.onap.policy.drools.system.PolicyController;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * Feature that tracks Transactions by observing Notification Patterns.
32  */
33 public class ControlLoopMetricsFeature implements PolicyControllerFeatureAPI {
34
35     /**
36      * Feature Sequence Priority
37      */
38     public final static int FEATURE_SEQUENCE_PRIORITY = 100000;
39
40     /**
41      * Properties Configuration Name
42      */
43     public static final String CONFIGURATION_PROPERTIES_NAME = "feature-controlloop-trans";
44
45     /**
46      * maximum number of transaction cache entries
47      */
48     public static final String CL_CACHE_TRANS_SIZE_PROPERTY = "controlloop.cache.transactions.size";
49     public static final int CL_CACHE_TRANS_SIZE_DEFAULT = 100;
50
51     /**
52      * transaction timeout in minutes
53      */
54     public static final String CL_CACHE_TRANS_TIMEOUT_SECONDS_PROPERTY = "controllop.cache.transactions.timeout.seconds";
55     public static final long CL_CACHE_TRANS_TIMEOUT_SECONDS_DEFAULT = 1L * 60 * 60;
56
57     @Override
58     public boolean afterShutdown(PolicyController controller) {
59         return false;
60     }
61
62     /**
63      * Logger
64      */
65     private static Logger logger = LoggerFactory.getLogger(ControlLoopMetricsFeature.class);
66
67     /**
68      * Intercept Control Loop Notifications
69      *
70      * @param controller - controller
71      * @param protocol - protocol
72      * @param topic - topic
73      * @param event - event object
74      * @return
75      */
76     @Override
77     public boolean beforeDeliver(PolicyController controller, CommInfrastructure protocol, String topic, Object event) {
78         if (event instanceof VirtualControlLoopNotification)
79             ControlLoopMetrics.manager.transactionEvent(controller, (VirtualControlLoopNotification) event);
80
81         /* do not take ownership */
82         return false;
83     }
84
85     @Override
86     public int getSequenceNumber() {
87         return FEATURE_SEQUENCE_PRIORITY;
88     }
89
90 }