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