Add support for ABATED alerts within CDAP TCA
[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 import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants;
31
32
33 /**
34  * TCA Message Router Flowlet emits VES Message to {@link TCAVESThresholdViolationCalculatorFlowlet} instances
35  *
36  * @author Rajiv Singla . Creation Date: 11/14/2016.
37  */
38 public class TCAVESMessageRouterFlowlet extends AbstractFlowlet {
39
40     /**
41      * Emits ves message to TCA Calculator Instances
42      */
43     @Output(CDAPComponentsConstants.TCA_FIXED_VES_MESSAGE_ROUTER_OUTPUT)
44     protected OutputEmitter<String> vesMessageEmitter;
45
46
47     @Override
48     public void configure() {
49         setName(CDAPComponentsConstants.TCA_FIXED_VES_MESSAGE_ROUTER_NAME_FLOWLET);
50         setDescription(CDAPComponentsConstants.TCA_FIXED_VES_MESSAGE_ROUTER_DESCRIPTION_FLOWLET);
51     }
52
53     @ProcessInput
54     public void routeVESMessage(StreamEvent vesMessageStreamEvent) {
55         final String vesMessage = Charsets.UTF_8.decode(vesMessageStreamEvent.getBody()).toString();
56         vesMessageEmitter.emit(
57                 vesMessage, AnalyticsConstants.TCA_VES_MESSAGE_ROUTER_PARTITION_KEY, vesMessage.hashCode());
58     }
59 }