Sonar Critical Fix
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-plugins / src / main / java / org / openecomp / dcae / apod / analytics / cdap / plugins / batch / sink / dmaap / DMaaPMROutputFormat.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.plugins.batch.sink.dmaap;\r
22 \r
23 import org.apache.hadoop.conf.Configuration;\r
24 import org.apache.hadoop.io.NullWritable;\r
25 import org.apache.hadoop.mapreduce.JobContext;\r
26 import org.apache.hadoop.mapreduce.OutputCommitter;\r
27 import org.apache.hadoop.mapreduce.OutputFormat;\r
28 import org.apache.hadoop.mapreduce.RecordWriter;\r
29 import org.apache.hadoop.mapreduce.TaskAttemptContext;\r
30 import org.openecomp.dcae.apod.analytics.cdap.plugins.utils.DMaaPSinkConfigMapper;\r
31 import org.openecomp.dcae.apod.analytics.dmaap.DMaaPMRFactory;\r
32 import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig;\r
33 import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher;\r
34 \r
35 import java.io.IOException;\r
36 \r
37 /**\r
38  * DMaaP MR Output format used by DMaaP MR Sink Plugin to create a MR Publisher and pass to custom {@link\r
39  * DMaaPMRRecordWriter}\r
40  * <p>\r
41  * @author Rajiv Singla . Creation Date: 1/27/2017.\r
42  */\r
43 public class DMaaPMROutputFormat extends OutputFormat<String, NullWritable> {\r
44 \r
45     @Override\r
46     public RecordWriter<String, NullWritable> getRecordWriter(TaskAttemptContext context) throws IOException,\r
47             InterruptedException {\r
48         final Configuration configuration = context.getConfiguration();\r
49         final DMaaPMRPublisherConfig publisherConfig = DMaaPSinkConfigMapper.map(configuration);\r
50         final DMaaPMRPublisher publisher = DMaaPMRFactory.create().createPublisher(publisherConfig);\r
51         return new DMaaPMRRecordWriter(publisher);\r
52     }\r
53 \r
54     @Override\r
55     public void checkOutputSpecs(JobContext context) throws IOException, InterruptedException {\r
56         // do nothing\r
57     }\r
58 \r
59     @Override\r
60     public OutputCommitter getOutputCommitter(TaskAttemptContext context) throws IOException, InterruptedException {\r
61         return new NoOpOutputCommitter();\r
62     }\r
63 \r
64     /**\r
65      * A dummy implementation for {@link OutputCommitter} that does nothing.\r
66      */\r
67     protected static class NoOpOutputCommitter extends OutputCommitter {\r
68 \r
69         @Override\r
70         public void setupJob(JobContext jobContext) throws IOException {\r
71             // no op\r
72         }\r
73 \r
74         @Override\r
75         public void setupTask(TaskAttemptContext taskContext) throws IOException {\r
76             // no op\r
77         }\r
78 \r
79         @Override\r
80         public boolean needsTaskCommit(TaskAttemptContext taskContext) throws IOException {\r
81             return false;\r
82         }\r
83 \r
84         @Override\r
85         public void commitTask(TaskAttemptContext taskContext) throws IOException {\r
86             // no op\r
87         }\r
88 \r
89         @Override\r
90         public void abortTask(TaskAttemptContext taskContext) throws IOException {\r
91             // no op\r
92         }\r
93     }\r
94 }\r