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