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 / TCAVESAlertsSinkFlowlet.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.ProcessInput;
24 import co.cask.cdap.api.annotation.Property;
25 import co.cask.cdap.api.dataset.lib.ObjectMappedTable;
26 import co.cask.cdap.api.flow.flowlet.AbstractFlowlet;
27 import co.cask.cdap.api.flow.flowlet.FlowletContext;
28 import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
29 import org.openecomp.dcae.apod.analytics.cdap.common.persistance.tca.TCAVESAlertEntity;
30 import org.openecomp.dcae.apod.analytics.cdap.common.persistance.tca.TCAVESAlertsPersister;
31
32 /**
33  * Saves TCA VES Alert Messages in a Time series Table
34  *
35  * @author Rajiv Singla . Creation Date: 11/15/2016.
36  */
37 public class TCAVESAlertsSinkFlowlet extends AbstractFlowlet {
38
39     @Property
40     private final String tcaVESAlertsTableName;
41
42     private ObjectMappedTable<TCAVESAlertEntity> tcaVESAlertsTable;
43
44     public TCAVESAlertsSinkFlowlet(String tcaVESAlertsTableName) {
45         this.tcaVESAlertsTableName = tcaVESAlertsTableName;
46     }
47
48     @Override
49     public void configure() {
50         setName(CDAPComponentsConstants.TCA_FIXED_VES_ALERTS_SINK_NAME_FLOWLET);
51         setDescription(CDAPComponentsConstants.TCA_FIXED_VES_ALERTS_SINK_DESCRIPTION_FLOWLET);
52     }
53
54     @Override
55     public void initialize(FlowletContext flowletContext) throws Exception {
56         super.initialize(flowletContext);
57         tcaVESAlertsTable = getContext().getDataset(tcaVESAlertsTableName);
58     }
59
60     /**
61      * Saves messages to Alerts table
62      *
63      * @param alertMessage alert message
64      */
65     @ProcessInput(CDAPComponentsConstants.TCA_FIXED_VES_ALERTS_ABATEMENT_NAME_OUTPUT)
66     public void saveAlerts(String alertMessage) {
67         // Saves alert message in alerts table
68         TCAVESAlertsPersister.persist(alertMessage, tcaVESAlertsTable);
69     }
70
71 }