259925324788dc9002f155ab62524a742946cd2e
[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.common.endpoints.event.comm.Topic.CommInfrastructure;
24 import org.onap.policy.controlloop.VirtualControlLoopNotification;
25 import org.onap.policy.drools.features.PolicyControllerFeatureAPI;
26 import org.onap.policy.drools.system.PolicyController;
27
28 /**
29  * Feature that tracks Transactions by observing Notification Patterns.
30  */
31 public class ControlLoopMetricsFeature implements PolicyControllerFeatureAPI {
32
33     /**
34      * Feature Sequence Priority.
35      */
36     public static final int FEATURE_SEQUENCE_PRIORITY = 100000;
37
38     /**
39      * Properties Configuration Name.
40      */
41     public static final String CONFIGURATION_PROPERTIES_NAME = "feature-controlloop-trans";
42
43     /**
44      * Maximum number of transaction cache entries.
45      */
46     public static final String CL_CACHE_TRANS_SIZE_PROPERTY = "controlloop.cache.transactions.size";
47     public static final int CL_CACHE_TRANS_SIZE_DEFAULT = 100;
48
49     /**
50      * Transaction timeout in minutes.
51      */
52     public static final String CL_CACHE_TRANS_TIMEOUT_SECONDS_PROPERTY =
53             "controllop.cache.transactions.timeout.seconds";
54     public static final long CL_CACHE_TRANS_TIMEOUT_SECONDS_DEFAULT = 1L * 60 * 60;
55
56     @Override
57     public boolean afterShutdown(PolicyController controller) {
58         return false;
59     }
60
61     /**
62      * Intercept Control Loop Notifications.
63      *
64      * @param controller - controller
65      * @param protocol - protocol
66      * @param topic - topic
67      * @param event - event object
68      * @return false do not take ownership else true
69      */
70     @Override
71     public boolean beforeDeliver(PolicyController controller, CommInfrastructure protocol, String topic, Object event) {
72         if (event instanceof VirtualControlLoopNotification) {
73             ControlLoopMetrics.manager.transactionEvent(controller, (VirtualControlLoopNotification) event);
74         }
75
76         /* do not take ownership */
77         return false;
78     }
79
80     @Override
81     public int getSequenceNumber() {
82         return FEATURE_SEQUENCE_PRIORITY;
83     }
84
85 }