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.onap.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.onap.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException;
33 import org.onap.dcae.apod.analytics.cdap.plugins.domain.config.dmaap.DMaaPMRSourcePluginConfig;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * A mock implementation of DMaaP MR Receiver which sends mock ves messages
40 * @author Rajiv Singla . Creation Date: 2/15/2017.
42 @Plugin(type = StreamingSource.PLUGIN_TYPE)
43 @Name("MockDMaaPMRSource")
44 @Description("Fetches DMaaP MR Messages at regular intervals")
45 public class MockDMaaPMRSource extends StreamingSource<StructuredRecord> {
47 private static final Logger LOG = LoggerFactory.getLogger(MockDMaaPMRSource.class);
48 private static final long serialVersionUID = 1L;
50 private final DMaaPMRSourcePluginConfig pluginConfig;
52 public MockDMaaPMRSource(final DMaaPMRSourcePluginConfig pluginConfig) {
53 LOG.debug("Creating DMaaP MR Source plugin with plugin Config: {}", pluginConfig);
54 this.pluginConfig = pluginConfig;
58 public void configurePipeline(PipelineConfigurer pipelineConfigurer) {
59 final Integer pollingInterval = pluginConfig.getPollingInterval();
60 if (pollingInterval == null) {
61 final String errorMessage = "Polling Interval field must be present";
62 throw new CDAPSettingsException(errorMessage, LOG, new IllegalArgumentException(errorMessage));
64 LOG.info("Mock Message will be send every ms: {}", pollingInterval);
69 public JavaDStream<StructuredRecord> getStream(final StreamingContext streamingContext) throws Exception {
70 return streamingContext.getSparkStreamingContext().receiverStream(
71 new MockDMaaPMRReceiver(StorageLevel.MEMORY_ONLY(), pluginConfig));