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