06b4f18eb49c0d851b22b03adc12db1427b00f33
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / main / java / org / openecomp / dcae / apod / analytics / cdap / tca / flowlet / TCAVESMessageRouterFlowlet.java
1 /*\r
2  * ===============================LICENSE_START======================================\r
3  *  dcae-analytics\r
4  * ================================================================================\r
5  *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  *  Licensed under the Apache License, Version 2.0 (the "License");\r
8  *  you may not use this file except in compliance with the License.\r
9  *   You may obtain a copy of the License at\r
10  *\r
11  *          http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  *  Unless required by applicable law or agreed to in writing, software\r
14  *  distributed under the License is distributed on an "AS IS" BASIS,\r
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  *  See the License for the specific language governing permissions and\r
17  *  limitations under the License.\r
18  *  ============================LICENSE_END===========================================\r
19  */\r
20 \r
21 package org.openecomp.dcae.apod.analytics.cdap.tca.flowlet;\r
22 \r
23 import co.cask.cdap.api.annotation.Output;\r
24 import co.cask.cdap.api.annotation.ProcessInput;\r
25 import co.cask.cdap.api.flow.flowlet.AbstractFlowlet;\r
26 import co.cask.cdap.api.flow.flowlet.OutputEmitter;\r
27 import co.cask.cdap.api.flow.flowlet.StreamEvent;\r
28 import com.google.common.base.Charsets;\r
29 import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;\r
30 import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants;\r
31 \r
32 \r
33 /**\r
34  * TCA Message Router Flowlet emits VES Message to {@link TCAVESThresholdViolationCalculatorFlowlet} instances\r
35  *\r
36  * @author Rajiv Singla . Creation Date: 11/14/2016.\r
37  */\r
38 public class TCAVESMessageRouterFlowlet extends AbstractFlowlet {\r
39 \r
40     /**\r
41      * Emits ves message to TCA Calculator Instances\r
42      */\r
43     @Output(CDAPComponentsConstants.TCA_FIXED_VES_MESSAGE_ROUTER_OUTPUT)\r
44     protected OutputEmitter<String> vesMessageEmitter;\r
45 \r
46 \r
47     @Override\r
48     public void configure() {\r
49         setName(CDAPComponentsConstants.TCA_FIXED_VES_MESSAGE_ROUTER_NAME_FLOWLET);\r
50         setDescription(CDAPComponentsConstants.TCA_FIXED_VES_MESSAGE_ROUTER_DESCRIPTION_FLOWLET);\r
51     }\r
52 \r
53     @ProcessInput\r
54     public void routeVESMessage(StreamEvent vesMessageStreamEvent) {\r
55         final String vesMessage = Charsets.UTF_8.decode(vesMessageStreamEvent.getBody()).toString();\r
56         vesMessageEmitter.emit(\r
57                 vesMessage, AnalyticsConstants.TCA_VES_MESSAGE_ROUTER_PARTITION_KEY, vesMessage.hashCode());\r
58     }\r
59 }\r