2 * ===============================LICENSE_START======================================
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
21 package org.openecomp.dcae.apod.analytics.cdap.plugins.batch.sink.dmaap;
\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
35 import java.io.IOException;
\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
41 * @author Rajiv Singla . Creation Date: 1/27/2017.
\r
43 public class DMaaPMROutputFormat extends OutputFormat<String, NullWritable> {
\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
55 public void checkOutputSpecs(JobContext context) throws IOException, InterruptedException {
\r
60 public OutputCommitter getOutputCommitter(TaskAttemptContext context) throws IOException, InterruptedException {
\r
61 return new NoOpOutputCommitter();
\r
65 * A dummy implementation for {@link OutputCommitter} that does nothing.
\r
67 protected static class NoOpOutputCommitter extends OutputCommitter {
\r
70 public void setupJob(JobContext jobContext) throws IOException {
\r
75 public void setupTask(TaskAttemptContext taskContext) throws IOException {
\r
80 public boolean needsTaskCommit(TaskAttemptContext taskContext) throws IOException {
\r
85 public void commitTask(TaskAttemptContext taskContext) throws IOException {
\r
90 public void abortTask(TaskAttemptContext taskContext) throws IOException {
\r