3023c9028fa78035cdac9fb8df9d0f9cafbc007c
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / main / java / org / openecomp / dcae / apod / analytics / cdap / tca / flowlet / TCAVESMessageRouterFlowlet.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
4  * ================================================================================
5  *    Copyright © 2017 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.openecomp.dcae.apod.analytics.cdap.tca.flowlet;
22
23 import co.cask.cdap.api.annotation.Output;
24 import co.cask.cdap.api.annotation.ProcessInput;
25 import co.cask.cdap.api.flow.flowlet.AbstractFlowlet;
26 import co.cask.cdap.api.flow.flowlet.OutputEmitter;
27 import co.cask.cdap.api.flow.flowlet.StreamEvent;
28 import com.google.common.base.Charsets;
29 import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
30
31 import static org.openecomp.dcae.apod.analytics.common.AnalyticsConstants.TCA_VES_MESSAGE_ROUTER_PARTITION_KEY;
32
33
34 /**
35  * TCA Message Router Flowlet emits VES Message to {@link TCAVESThresholdViolationCalculatorFlowlet} instances
36  *
37  * @author Rajiv Singla . Creation Date: 11/14/2016.
38  */
39 public class TCAVESMessageRouterFlowlet extends AbstractFlowlet {
40
41     /**
42      * Emits ves message to TCA Calculator Instances
43      */
44     @Output(CDAPComponentsConstants.TCA_FIXED_VES_MESSAGE_ROUTER_OUTPUT)
45     protected OutputEmitter<String> vesMessageEmitter;
46
47
48     @Override
49     public void configure() {
50         setName(CDAPComponentsConstants.TCA_FIXED_VES_MESSAGE_ROUTER_NAME_FLOWLET);
51         setDescription(CDAPComponentsConstants.TCA_FIXED_VES_MESSAGE_ROUTER_DESCRIPTION_FLOWLET);
52     }
53
54     @ProcessInput
55     public void routeVESMessage(StreamEvent vesMessageStreamEvent) {
56         final String vesMessage = Charsets.UTF_8.decode(vesMessageStreamEvent.getBody()).toString();
57         vesMessageEmitter.emit(vesMessage, TCA_VES_MESSAGE_ROUTER_PARTITION_KEY, vesMessage.hashCode());
58     }
59 }