2 * ===============================LICENSE_START======================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===========================================
21 package org.openecomp.dcae.apod.analytics.cdap.plugins.batch.sink.dmaap;
23 import org.apache.hadoop.conf.Configuration;
24 import org.apache.hadoop.io.NullWritable;
25 import org.apache.hadoop.mapreduce.JobContext;
26 import org.apache.hadoop.mapreduce.OutputCommitter;
27 import org.apache.hadoop.mapreduce.OutputFormat;
28 import org.apache.hadoop.mapreduce.RecordWriter;
29 import org.apache.hadoop.mapreduce.TaskAttemptContext;
30 import org.openecomp.dcae.apod.analytics.cdap.plugins.utils.DMaaPSinkConfigMapper;
31 import org.openecomp.dcae.apod.analytics.dmaap.DMaaPMRFactory;
32 import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig;
33 import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher;
35 import java.io.IOException;
38 * DMaaP MR Output format used by DMaaP MR Sink Plugin to create a MR Publisher and pass to custom {@link
39 * DMaaPMRRecordWriter}
41 * @author Rajiv Singla . Creation Date: 1/27/2017.
43 public class DMaaPMROutputFormat extends OutputFormat<String, NullWritable> {
46 public RecordWriter<String, NullWritable> getRecordWriter(TaskAttemptContext context) throws IOException,
47 InterruptedException {
48 final Configuration configuration = context.getConfiguration();
49 final DMaaPMRPublisherConfig publisherConfig = DMaaPSinkConfigMapper.map(configuration);
50 final DMaaPMRPublisher publisher = DMaaPMRFactory.create().createPublisher(publisherConfig);
51 return new DMaaPMRRecordWriter(publisher);
55 public void checkOutputSpecs(JobContext context) throws IOException, InterruptedException {
60 public OutputCommitter getOutputCommitter(TaskAttemptContext context) throws IOException, InterruptedException {
61 return new NoOpOutputCommitter();
65 * A dummy implementation for {@link OutputCommitter} that does nothing.
67 protected static class NoOpOutputCommitter extends OutputCommitter {
70 public void setupJob(JobContext jobContext) throws IOException {
75 public void setupTask(TaskAttemptContext taskContext) throws IOException {
80 public boolean needsTaskCommit(TaskAttemptContext taskContext) throws IOException {
85 public void commitTask(TaskAttemptContext taskContext) throws IOException {
90 public void abortTask(TaskAttemptContext taskContext) throws IOException {