37bafa45d25d2a0a31ea7c018f5073998a4d4641
[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 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 =
55             "controllop.cache.transactions.timeout.seconds";
56     public static final long CL_CACHE_TRANS_TIMEOUT_SECONDS_DEFAULT = 1L * 60 * 60;
57
58     @Override
59     public boolean afterShutdown(PolicyController controller) {
60         return false;
61     }
62
63     /**
64      * Logger.
65      */
66     private static Logger logger = LoggerFactory.getLogger(ControlLoopMetricsFeature.class);
67
68     /**
69      * Intercept Control Loop Notifications.
70      *
71      * @param controller - controller
72      * @param protocol - protocol
73      * @param topic - topic
74      * @param event - event object
75      * @return
76      */
77     @Override
78     public boolean beforeDeliver(PolicyController controller, CommInfrastructure protocol, String topic, Object event) {
79         if (event instanceof VirtualControlLoopNotification) {
80             ControlLoopMetrics.manager.transactionEvent(controller, (VirtualControlLoopNotification) event);
81         }
82
83         /* do not take ownership */
84         return false;
85     }
86
87     @Override
88     public int getSequenceNumber() {
89         return FEATURE_SEQUENCE_PRIORITY;
90     }
91
92 }