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.streaming.dmaap;
\r
23 import co.cask.cdap.api.annotation.Description;
\r
24 import co.cask.cdap.api.annotation.Name;
\r
25 import co.cask.cdap.api.annotation.Plugin;
\r
26 import co.cask.cdap.api.data.format.StructuredRecord;
\r
27 import co.cask.cdap.etl.api.PipelineConfigurer;
\r
28 import co.cask.cdap.etl.api.streaming.StreamingContext;
\r
29 import co.cask.cdap.etl.api.streaming.StreamingSource;
\r
30 import org.apache.spark.storage.StorageLevel;
\r
31 import org.apache.spark.streaming.api.java.JavaDStream;
\r
32 import org.openecomp.dcae.apod.analytics.cdap.common.utils.ValidationUtils;
\r
33 import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.dmaap.DMaaPMRSourcePluginConfig;
\r
34 import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.schema.dmaap.DMaaPSourceOutputSchema;
\r
35 import org.openecomp.dcae.apod.analytics.cdap.plugins.validator.DMaaPMRSourcePluginConfigValidator;
\r
36 import org.slf4j.Logger;
\r
37 import org.slf4j.LoggerFactory;
\r
40 * DMaaP MR Source Plugin which polls DMaaP MR topic at frequent intervals
\r
42 * @author Rajiv Singla . Creation Date: 1/18/2017.
\r
44 @Plugin(type = StreamingSource.PLUGIN_TYPE)
\r
45 @Name("DMaaPMRSource")
\r
46 @Description("Fetches DMaaP MR Messages at regular intervals")
\r
47 public class DMaaPMRSource extends StreamingSource<StructuredRecord> {
\r
49 private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRSource.class);
\r
50 private static final long serialVersionUID = 1L;
\r
52 private final DMaaPMRSourcePluginConfig pluginConfig;
\r
54 public DMaaPMRSource(final DMaaPMRSourcePluginConfig pluginConfig) {
\r
55 LOG.debug("Creating DMaaP MR Source plugin with plugin Config: {}", pluginConfig);
\r
56 this.pluginConfig = pluginConfig;
\r
60 public void configurePipeline(PipelineConfigurer pipelineConfigurer) {
\r
61 ValidationUtils.validateSettings(pluginConfig, new DMaaPMRSourcePluginConfigValidator());
\r
62 pipelineConfigurer.getStageConfigurer().setOutputSchema(DMaaPSourceOutputSchema.getSchema());
\r
66 public JavaDStream<StructuredRecord> getStream(final StreamingContext streamingContext) throws Exception {
\r
67 return streamingContext.getSparkStreamingContext().receiverStream(
\r
68 new DMaaPMRReceiver(StorageLevel.MEMORY_ONLY(), pluginConfig, streamingContext.getMetrics()));
\r