From 1a0aea46b80560cb852f8b3c5372e579a1a65052 Mon Sep 17 00:00:00 2001 From: Claudio Fahey Date: Wed, 1 May 2019 14:50:30 -0700 Subject: [PATCH] Issue 187: Cleanup - build.gradle file now uses versions defined in gradle.properties - Removed unneeded wrapper task from build.gradle - Changed package name to io.pravega.example.mqtt - `gradle run` now provides the required command-line argument - Updated documentation Signed-off-by: Claudio Fahey --- gradle.properties | 7 ++++++ scenarios/mqtt-pravega-bridge/README.md | 20 +++++++++++---- scenarios/mqtt-pravega-bridge/build.gradle | 25 ++++++++----------- .../example/mqtt}/ApplicationArguments.java | 2 +- .../example/mqtt}/ApplicationMain.java | 4 +-- .../pravega/example/mqtt}/DataPacket.java | 2 +- .../example/mqtt}/MqttConnectionBuilder.java | 2 +- .../pravega/example/mqtt}/MqttListener.java | 2 +- .../pravega/example/mqtt}/PravegaHelper.java | 2 +- 9 files changed, 40 insertions(+), 26 deletions(-) rename scenarios/mqtt-pravega-bridge/src/main/java/{com/dell/mqtt/pravega => io/pravega/example/mqtt}/ApplicationArguments.java (98%) rename scenarios/mqtt-pravega-bridge/src/main/java/{com/dell/mqtt/pravega => io/pravega/example/mqtt}/ApplicationMain.java (92%) rename scenarios/mqtt-pravega-bridge/src/main/java/{com/dell/mqtt/pravega => io/pravega/example/mqtt}/DataPacket.java (97%) rename scenarios/mqtt-pravega-bridge/src/main/java/{com/dell/mqtt/pravega => io/pravega/example/mqtt}/MqttConnectionBuilder.java (98%) rename scenarios/mqtt-pravega-bridge/src/main/java/{com/dell/mqtt/pravega => io/pravega/example/mqtt}/MqttListener.java (97%) rename scenarios/mqtt-pravega-bridge/src/main/java/{com/dell/mqtt/pravega => io/pravega/example/mqtt}/PravegaHelper.java (98%) diff --git a/gradle.properties b/gradle.properties index 92a68055..1e20ac21 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,6 +11,13 @@ pravegaVersion=0.4.0 flinkConnectorVersion=0.4.0 +#3rd party Versions +guavaVersion=20.0 +junitVersion=4.12 +qosLogbackVersion=1.2.3 +pahoClientMqttv3Version=1.2.0 +slf4jApiVersion=1.7.25 + ### Pravega-samples output library samplesVersion=0.5.0-SNAPSHOT diff --git a/scenarios/mqtt-pravega-bridge/README.md b/scenarios/mqtt-pravega-bridge/README.md index 5ed6555c..8c407d72 100644 --- a/scenarios/mqtt-pravega-bridge/README.md +++ b/scenarios/mqtt-pravega-bridge/README.md @@ -12,8 +12,7 @@ This sample application reads events from MQTT and writes them to a Pravega stre See for more information. -- Pravega Video Demo: This is a simple command-line application that demonstrates how to write video files to Pravega. - It also demonstrates how to read the video files from Pravega and decode them. +- MQTT Pravega Bridge: This sample application reads events from MQTT and writes them to a Pravega stream. - Docker: This demo uses Docker and Docker Compose to greatly simplify the deployment of the various components on Linux and/or Windows servers, desktops, or even laptops. @@ -42,11 +41,15 @@ and . This will run a development instance of Pravega locally. In the command below, replace x.x.x.x with the IP address of a local network interface such as eth0. +You may need to checkout the specific version of Pravega that pravega-samples was built with. +Refer to gradle.properties for the correct version. ``` cd git clone https://github.com/pravega/pravega -cd pravega/docker/compose +cd pravega +git checkout r0.4 +cd docker/compose export HOST_IP=x.x.x.x docker-compose up -d ``` @@ -70,17 +73,24 @@ You can view the stream files stored on HDFS with `docker-compose exec hdfs hdfs to specify your Pravega controller URI (controllerUri) as `tcp://HOST_IP:9090`. -- In IntelliJ, run the class com.dell.mqtt.pravega.ApplicationMain with the following parameters: +- Run the application: + ``` + ../../gradlew run + ``` + +- Alternatively, you may run in IntelliJ. + Run the class ApplicationMain with the following parameters: ``` scenarios/mqtt-pravega-bridge/src/main/dist/conf ``` - Publish a sample MQTT message. + Note that the topic must be formatted as "topic/car_id" as shown below. ``` mosquitto_pub -t center/0001 -m "12,34,56.78" ``` - You should see the following application output: ``` - [MQTT Call: CanDataReader] com.dell.mqtt.pravega.MqttListener: Writing Data Packet: CarID: 0001 Timestamp: 1551671403118 Payload: [B@2813d92f annotation: null + [MQTT Call: CanDataReader] io.pravega.example.mqtt.MqttListener: Writing Data Packet: CarID: 0001 Timestamp: 1551671403118 Payload: [B@2813d92f annotation: null ``` diff --git a/scenarios/mqtt-pravega-bridge/build.gradle b/scenarios/mqtt-pravega-bridge/build.gradle index 8bf3c637..7724cd8a 100644 --- a/scenarios/mqtt-pravega-bridge/build.gradle +++ b/scenarios/mqtt-pravega-bridge/build.gradle @@ -2,21 +2,14 @@ plugins { id 'com.github.johnrengelman.shadow' version '1.2.4' } -group 'com.dell.mqtt' -version = samplesVersion - -task wrapper(type: Wrapper) { - gradleVersion = '3.1' - distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" -} - apply plugin: 'java' apply plugin: "distribution" apply plugin: 'application' +version = samplesVersion sourceCompatibility = 1.8 targetCompatibility = 1.8 -mainClassName = 'com.dell.mqtt.pravega.ApplicationMain' +mainClassName = 'io.pravega.example.mqtt.ApplicationMain' applicationDefaultJvmArgs = ["-Dlog4j.configuration=file:conf/log4j.properties"] archivesBaseName = 'pravega-mqtt-bridge' @@ -31,12 +24,12 @@ repositories { } dependencies { - testCompile group: 'junit', name: 'junit', version: '4.11' - compile "org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0" - compile "org.slf4j:slf4j-api:1.6.6" - compile "ch.qos.logback:logback-classic:1.0.9" - compile "com.google.guava:guava:20.0" + compile "org.eclipse.paho:org.eclipse.paho.client.mqttv3:${pahoClientMqttv3Version}" + compile "org.slf4j:slf4j-api:${slf4jApiVersion}" + compile "ch.qos.logback:logback-classic:${qosLogbackVersion}" + compile "com.google.guava:guava:${guavaVersion}" compile "io.pravega:pravega-client:${pravegaVersion}" + testCompile "junit:junit:${junitVersion}" } shadowJar { @@ -56,3 +49,7 @@ distributions { } } } + +run { + args = ["src/main/dist/conf"] +} diff --git a/scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/ApplicationArguments.java b/scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/ApplicationArguments.java similarity index 98% rename from scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/ApplicationArguments.java rename to scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/ApplicationArguments.java index e62fc782..8bbda46c 100644 --- a/scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/ApplicationArguments.java +++ b/scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/ApplicationArguments.java @@ -1,4 +1,4 @@ -package com.dell.mqtt.pravega; +package io.pravega.example.mqtt; import com.google.common.base.Preconditions; diff --git a/scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/ApplicationMain.java b/scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/ApplicationMain.java similarity index 92% rename from scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/ApplicationMain.java rename to scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/ApplicationMain.java index 35935d08..e7bc937c 100644 --- a/scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/ApplicationMain.java +++ b/scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/ApplicationMain.java @@ -1,4 +1,4 @@ -package com.dell.mqtt.pravega; +package io.pravega.example.mqtt; import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttException; @@ -14,7 +14,7 @@ public class ApplicationMain { public static void main(String ... args) { if (args.length != 1) { - log.error("Missing required arguments. Usage: java com.dell.mqtt.pravega.ApplicationMain "); + log.error("Missing required arguments. Usage: java io.pravega.example.mqtt.ApplicationMain "); return; } diff --git a/scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/DataPacket.java b/scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/DataPacket.java similarity index 97% rename from scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/DataPacket.java rename to scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/DataPacket.java index b798918a..e7a6a849 100644 --- a/scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/DataPacket.java +++ b/scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/DataPacket.java @@ -1,4 +1,4 @@ -package com.dell.mqtt.pravega; +package io.pravega.example.mqtt; import java.io.Serializable; diff --git a/scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/MqttConnectionBuilder.java b/scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/MqttConnectionBuilder.java similarity index 98% rename from scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/MqttConnectionBuilder.java rename to scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/MqttConnectionBuilder.java index 31c02e18..12d3c309 100644 --- a/scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/MqttConnectionBuilder.java +++ b/scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/MqttConnectionBuilder.java @@ -1,4 +1,4 @@ -package com.dell.mqtt.pravega; +package io.pravega.example.mqtt; import com.google.common.base.Preconditions; import org.eclipse.paho.client.mqttv3.MqttCallback; diff --git a/scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/MqttListener.java b/scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/MqttListener.java similarity index 97% rename from scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/MqttListener.java rename to scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/MqttListener.java index 62f34b20..321a6c4e 100644 --- a/scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/MqttListener.java +++ b/scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/MqttListener.java @@ -1,4 +1,4 @@ -package com.dell.mqtt.pravega; +package io.pravega.example.mqtt; import io.pravega.client.stream.EventStreamWriter; import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; diff --git a/scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/PravegaHelper.java b/scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/PravegaHelper.java similarity index 98% rename from scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/PravegaHelper.java rename to scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/PravegaHelper.java index d34d41cf..23d001fc 100644 --- a/scenarios/mqtt-pravega-bridge/src/main/java/com/dell/mqtt/pravega/PravegaHelper.java +++ b/scenarios/mqtt-pravega-bridge/src/main/java/io/pravega/example/mqtt/PravegaHelper.java @@ -1,4 +1,4 @@ -package com.dell.mqtt.pravega; +package io.pravega.example.mqtt; import io.pravega.client.ClientFactory; import io.pravega.client.admin.StreamManager;