Introducing Mm FLaNK... An Apache Flink Stack for Rapid Streaming Development From Edge 2 AI
Published: 2019-11-27 17:07:58

---
title: Introducing Mm FLaNK... An Apache Flink Stack for Rapid Streaming Development From Edge 2 AI
published: true
date: 2019-11-27 01:34:00 UTC
tags: 
canonical_url: 
---

## Introducing Mm FLaNK... 

### An Apache Flink Stack for Rapid Streaming Development From Edge 2 AI


[![](https://1.bp.blogspot.com/-GTnHYP2becs/Xd2Tbr1FsAI/AAAAAAAAY2E/pEdSE1r3wbMuooG-DJkxN4VxFqUi-uNNQCLcBGAsYHQ/s640/flinksquirrel.png)](https://1.bp.blogspot.com/-GTnHYP2becs/Xd2Tbr1FsAI/AAAAAAAAY2E/pEdSE1r3wbMuooG-DJkxN4VxFqUi-uNNQCLcBGAsYHQ/s1600/flinksquirrel.png)
  
  
**Source** :   [https://github.com/tspannhw/MmFLaNK](https://github.com/tspannhw/MmFLaNK)  


**Stateless NiFi:**    [https://www.datainmotion.dev/2019/11/exploring-apache-nifi-110-parameters.html](https://dev.to/tspannhw/exploring-apache-nifi-1-10-parameters-and-stateless-engine-4jph-temp-slug-4119934)  
  
To show an example of using the Mm FLaNK stack we have an Apache NiFi flow that reads IoT data (JSON) and send it to Apache Kafka.   An Apache Flink streaming application running in YARN reads it, validates the data and send it to another Kafka topic.  We monitor and check the data with SMM.    The data from that second topic is read by Apache NiFi and pushed to Apache Kudu tables.  
  
**Mm FLaNK Stack (MXNet, MiNiFi, Flink, NiFi, Kafka, Kudu)**  
  

[![](https://1.bp.blogspot.com/-jFt3HvAbAGM/Xd2e57uBMDI/AAAAAAAAY3Q/4fWvn0iRSi8ltfvZhBqWHVybUwHsDLAjgCLcBGAsYHQ/s640/nifiKafkaKuduFlow.png)](https://1.bp.blogspot.com/-jFt3HvAbAGM/Xd2e57uBMDI/AAAAAAAAY3Q/4fWvn0iRSi8ltfvZhBqWHVybUwHsDLAjgCLcBGAsYHQ/s1600/nifiKafkaKuduFlow.png)
  

  

 First, we rapidly ingest, route, transform, convert, query and process data with Apache **NiFi**.   Once we have transformed it into a client, schema-validated known data type we can stream it to **Kafka** for additional processing.  
  

[![](https://github.com/tspannhw/MmFLaNK/raw/master/nifi.png)](https://github.com/tspannhw/MmFLaNK/raw/master/nifi.png)
  
  
Second, we read from that Kafka topic, **iot** , with a Java Apache Flink application.   We then filter out empty records and then push it to another Kafka topic, **iot-result.**  

[![](https://github.com/tspannhw/MmFLaNK/raw/master/kafka.png)](https://github.com/tspannhw/MmFLaNK/raw/master/kafka.png)
       public static class NotNullFilter implements FilterFunction<String> {                    @Override public boolean filter(String string) throws Exception {                  if ( string == null || string.isEmpty() || string.trim().length() <=0) {                return false;}              
        return true; } }  

> Properties properties = new Properties();  
> properties.setProperty("bootstrap.servers", "cloudera:9092");  
> properties.setProperty("group.id","flinkKafkaGroup");  
> StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();  
> env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);  
> FlinkKafkaConsumer<String> **consumer** = new FlinkKafkaConsumer<>("iot", new SimpleStringSchema(), properties);  
> DataStream<String> **source** = env. **addSource** (consumer).name("Flink IoT Kafka Source");  
> source.print();  
> source. **filter** (new NotNullFilter());  
> source. **addSink** (new FlinkKafkaProducer<>("cloudera:9092", "iot-result",  
> new SimpleStringSchema())).name("Flink Kafka IoT Result Sink");

  

[![](https://github.com/tspannhw/MmFLaNK/raw/master/flink.png)](https://github.com/tspannhw/MmFLaNK/raw/master/flink.png)

  

We compile our Java application with maven and build a big JAR that we will use the **Flink** Client to push to **YARN** on our **CDH** 6.3 cluster.

  

[![](https://1.bp.blogspot.com/-vFx3Pz6gtMI/Xd2e3dH5gOI/AAAAAAAAY20/y9y2svIkxmAbwviwvAcB0AAkgzVY-z5JACLcBGAsYHQ/s640/flinkStartedYarnJob.png)](https://1.bp.blogspot.com/-vFx3Pz6gtMI/Xd2e3dH5gOI/AAAAAAAAY20/y9y2svIkxmAbwviwvAcB0AAkgzVY-z5JACLcBGAsYHQ/s1600/flinkStartedYarnJob.png)

  

  

Once the Flink application is running we can see a lot of metrics, logs and information on our streaming service.  We can browse the logs via **YARN** UI and **Flink** UI.

  

  

From the **Hadoop**  **YARN** UI, you can Link to this application's **Flink** Dashboard.
  

[![](https://1.bp.blogspot.com/-1-PEbKvs-CA/Xd2e4mhoHiI/AAAAAAAAY3A/lwWRtMlpOHYXjWoHnVC0CnhEViCPWu1ugCLcBGAsYHQ/s640/flinkYarn.png)](https://1.bp.blogspot.com/-1-PEbKvs-CA/Xd2e4mhoHiI/AAAAAAAAY3A/lwWRtMlpOHYXjWoHnVC0CnhEViCPWu1ugCLcBGAsYHQ/s1600/flinkYarn.png)
  

[![](https://1.bp.blogspot.com/-QjWI8kVkyo0/Xd2e4J14FiI/AAAAAAAAY28/xVzJXwV-ftIM60i-eiYvjJElf9fdznKWACLcBGAsYHQ/s640/flinkYARNUI.png)](https://1.bp.blogspot.com/-QjWI8kVkyo0/Xd2e4J14FiI/AAAAAAAAY28/xVzJXwV-ftIM60i-eiYvjJElf9fdznKWACLcBGAsYHQ/s1600/flinkYARNUI.png)

  

  

You can easily see logs from various components, your application, containers and various systems.
  

[  
 ![](https://1.bp.blogspot.com/-sLs3nKPUGlY/Xd2e3Zmmo6I/AAAAAAAAY2w/KpMU_7xgIyUk2C_IO0EOcL_Umn3j-tJhwCLcBGAsYHQ/s640/flinkStartupYARN.png)](https://1.bp.blogspot.com/-sLs3nKPUGlY/Xd2e3Zmmo6I/AAAAAAAAY2w/KpMU_7xgIyUk2C_IO0EOcL_Umn3j-tJhwCLcBGAsYHQ/s1600/flinkStartupYARN.png)
  

The **Apache Flink Dashboard** is a very rich easy to navigate to interface for all the information related to your running job.

  

  

[![](https://1.bp.blogspot.com/-g2ymKk9D9JE/Xd2e5H4lvAI/AAAAAAAAY3E/gOHjfxNFsbM_yjqeIMJ_tGSsB9n-7w5sACLcBGAsYHQ/s640/flinkdashboardrecords.png)](https://1.bp.blogspot.com/-g2ymKk9D9JE/Xd2e5H4lvAI/AAAAAAAAY3E/gOHjfxNFsbM_yjqeIMJ_tGSsB9n-7w5sACLcBGAsYHQ/s1600/flinkdashboardrecords.png)
  
You can see and add charts to view various metrics about sources, sinks and a large number of other interesting real-time attributes.  
  

[![](https://1.bp.blogspot.com/-lzT1l-MfLnk/Xd2e28zzwYI/AAAAAAAAY2o/s5zffiwkMMgnxDBW4fg8uV2CsGXW4TjyQCLcBGAsYHQ/s640/flinkMetrics.png)](https://1.bp.blogspot.com/-lzT1l-MfLnk/Xd2e28zzwYI/AAAAAAAAY2o/s5zffiwkMMgnxDBW4fg8uV2CsGXW4TjyQCLcBGAsYHQ/s1600/flinkMetrics.png)

  

There is also an older view that is still available to show a less dynamic interface.
  

[![](https://1.bp.blogspot.com/-YnaCYaLiln0/Xd2e3PDZfEI/AAAAAAAAY2s/hdwVaUHwVIYgD6xNoSHRf14QpaRHrL6zgCLcBGAsYHQ/s640/flinkRunningJobs.png)](https://1.bp.blogspot.com/-YnaCYaLiln0/Xd2e3PDZfEI/AAAAAAAAY2s/hdwVaUHwVIYgD6xNoSHRf14QpaRHrL6zgCLcBGAsYHQ/s1600/flinkRunningJobs.png)
  

You can also dive down into individual task managers with their attributes.
  

[![](https://1.bp.blogspot.com/-0Fo5LyzKYHQ/Xd2e3rnPzpI/AAAAAAAAY24/lg0_m43ofus7TpUt9EaWZQ0DJA7qil8TwCLcBGAsYHQ/s640/flinkTaskManagers.png)](https://1.bp.blogspot.com/-0Fo5LyzKYHQ/Xd2e3rnPzpI/AAAAAAAAY24/lg0_m43ofus7TpUt9EaWZQ0DJA7qil8TwCLcBGAsYHQ/s1600/flinkTaskManagers.png)

  

Logs are easily accessible:

[![](https://1.bp.blogspot.com/-AIJZS02Ry9U/Xd2e5u0zSQI/AAAAAAAAY3M/AdoNGD-r9TA7ni5TMqJSMSvGjHvKasUpQCLcBGAsYHQ/s640/logwritingflinkhadoopyarn.png)](https://1.bp.blogspot.com/-AIJZS02Ry9U/Xd2e5u0zSQI/AAAAAAAAY3M/AdoNGD-r9TA7ni5TMqJSMSvGjHvKasUpQCLcBGAsYHQ/s1600/logwritingflinkhadoopyarn.png)

  

  

Another Apache NiFi flow reads from the **iot-result** topic and does additional processing, could do machine learning / deep learning and then stores to a data store such as **Apache**   **Kudu.   ** If you have attended any of the **CDF Workshops,** you will notice we could integrate machine learning via a **LookupRecord** processor calling **CDSW** Python Machine Learning application via REST.   Data read from Kafka is streaming in with helpful metadata into our provenance data stream including kafka offset, partition, topic and a unique id on the data.

[![](https://1.bp.blogspot.com/-KhSbGobdb0g/Xd2e6MKzhMI/AAAAAAAAY3U/yFeGZRfXMw4RncL9TGuwbwei3BDr_bnRQCLcBGAsYHQ/s400/offsetandpartitions.png)](https://1.bp.blogspot.com/-KhSbGobdb0g/Xd2e6MKzhMI/AAAAAAAAY3U/yFeGZRfXMw4RncL9TGuwbwei3BDr_bnRQCLcBGAsYHQ/s1600/offsetandpartitions.png)
  
  
  
Since we are using Apache Kafka 2.x for a lot of streams, we really need to see what is going on in there.   Fortunately **Cloudera Streams Messaging Manager** gives us full insight into everything.  We can browse brokers, topics, consumers and producers.   We can also setup alerts to notify someone via various methods (email, rest, etc...) if something happens such as consumer lag.   From the below screen we can see that these two consumers are lagging.   This is because I have stopped them so they cannot process the message in their respective topics.  
  

[![](https://1.bp.blogspot.com/-nndHpJ6pwKM/Xd2e1xbE5yI/AAAAAAAAY2c/UE0zW5o_XYMBWa_NvRe3ks2A_-qgcOcqQCLcBGAsYHQ/s640/consumerLag.png)](https://1.bp.blogspot.com/-nndHpJ6pwKM/Xd2e1xbE5yI/AAAAAAAAY2c/UE0zW5o_XYMBWa_NvRe3ks2A_-qgcOcqQCLcBGAsYHQ/s1600/consumerLag.png)

  

I restart my consumers and quickly the lag is gone.    **Flink** and **NiFi** process **Kafka** topics quickly!
  

[![](https://1.bp.blogspot.com/-d1jodQ320LQ/Xd2e2fwMZ7I/AAAAAAAAY2g/oMJKmkUe4ysVNe2TJ-fwmnCnGq2C1aWvQCLcBGAsYHQ/s640/consumerLagGone.png)](https://1.bp.blogspot.com/-d1jodQ320LQ/Xd2e2fwMZ7I/AAAAAAAAY2g/oMJKmkUe4ysVNe2TJ-fwmnCnGq2C1aWvQCLcBGAsYHQ/s1600/consumerLagGone.png)

  

We can see a nice overview of my **FLaNK** application via this screen.   I see my current stats on the source and sink **Kafka** topics I am working with from **NiFi** and **Flink**.
  

[![](https://1.bp.blogspot.com/-_vzag0yihEs/Xd2e5Sho3LI/AAAAAAAAY3I/hfr7474q6jQ93kLw4UKsb7TkJUZmikXfACLcBGAsYHQ/s640/kafkatopics.png)](https://1.bp.blogspot.com/-_vzag0yihEs/Xd2e5Sho3LI/AAAAAAAAY3I/hfr7474q6jQ93kLw4UKsb7TkJUZmikXfACLcBGAsYHQ/s1600/kafkatopics.png)

  

  

[![](https://1.bp.blogspot.com/-1pcSWCra5yg/Xd2e6bfu7rI/AAAAAAAAY3Y/GGAwgwVzgtAqtNKksvPVSVjAvvKC5Zj8gCLcBGAsYHQ/s640/smmTopics.png)](https://1.bp.blogspot.com/-1pcSWCra5yg/Xd2e6bfu7rI/AAAAAAAAY3Y/GGAwgwVzgtAqtNKksvPVSVjAvvKC5Zj8gCLcBGAsYHQ/s1600/smmTopics.png)

I can also dive into a topic (if I have permissions) and see the content of the data.   There's also a link to the **Schema Registry**  for this particular topic and the ability to view various types of Kafka data including Strings and Avro.   As you can see our payloads are JSON IoT data.
  

[![](https://1.bp.blogspot.com/-YpUxQdxjGx0/Xd2e6pmb7yI/AAAAAAAAY3c/H-a04zASoE8tlW2o7-CtKLvtmcqfDCdmQCLcBGAsYHQ/s640/topicDataIotResult.png)](https://1.bp.blogspot.com/-YpUxQdxjGx0/Xd2e6pmb7yI/AAAAAAAAY3c/H-a04zASoE8tlW2o7-CtKLvtmcqfDCdmQCLcBGAsYHQ/s1600/topicDataIotResult.png)

  

Once our **NiFi**  **Kafka** Consumer has acquired the data we use our **PutKudu** processor to auto infer the schema of the JSON data and write to an existing **Kudu** table.  We can query the data via an interface such as **Apache Hue**.   We run a quick **Apache**   **Impala** SQL query to get back data as it arrives.    **Apache**  **NiFi** is inserting data as we stream it through **Apache**   **Kafka** from our **Apache**   **Flink** application.

  

[![](https://github.com/tspannhw/MmFLaNK/raw/master/kudu.png)](https://github.com/tspannhw/MmFLaNK/raw/master/kudu.png)

  

  

  

[![](https://1.bp.blogspot.com/-akVO0csxGAM/Xd2e14g6ytI/AAAAAAAAY2Y/zHVuo23EhY8O8-bht77qjOkTklFfy1q6QCLcBGAsYHQ/s640/KuduRecordsHue.png)](https://1.bp.blogspot.com/-akVO0csxGAM/Xd2e14g6ytI/AAAAAAAAY2Y/zHVuo23EhY8O8-bht77qjOkTklFfy1q6QCLcBGAsYHQ/s1600/KuduRecordsHue.png)
  

  

  

That was easy!   Next up we will expand our Edge piece by utilizing **MiNiFi** deployed by **Cloudera**  **Edge**  **Flow**  **Manager** as well as add our second **M** with **Apache MXNet** with my **Apache**  **MXNet**  **NiFi** processor as well as some Python **GluonCV** , **GluonTS** and more via **Cloudera**  **Data**  **Science**  **Workbench**.  We will also use **Stateless**  **Apache NiFi** 1.10 for some FaaS **Kafka** consuming and producing.

  

More **FLaNK** to come!
  
**Upcoming** :  GluonTS for Forecasting Time Series [https://gluon-ts.mxnet.io/examples/basic\_forecasting\_tutorial/tutorial.html](https://gluon-ts.mxnet.io/examples/basic_forecasting_tutorial/tutorial.html)  
  
**References** :  

- [https://dataworkssummit.com/berlin-2018/session/iot-with-apache-mxnet-and-apache-nifi-and-minifi/](https://dataworkssummit.com/berlin-2018/session/iot-with-apache-mxnet-and-apache-nifi-and-minifi/)
- [https://github.com/tspannhw/nifi-mxnetinference-processor](https://github.com/tspannhw/nifi-mxnetinference-processor)
- [https://community.cloudera.com/t5/Community-Articles/Apache-NiFi-Processor-for-Apache-MXNet-SSD-Single-Shot/ta-p/249240](https://community.cloudera.com/t5/Community-Articles/Apache-NiFi-Processor-for-Apache-MXNet-SSD-Single-Shot/ta-p/249240)
- [https://www.youtube.com/watch?v=5w6rV7562xM](https://www.youtube.com/watch?v=5w6rV7562xM)
- [https://mxnet.apache.org/](https://mxnet.apache.org/)
- [https://www.datainmotion.dev/2019/11/learning-apache-flink-19.html](https://dev.to/tspannhw/learning-apache-flink-1-9-2l6l-temp-slug-4924272)
- [https://mvnrepository.com/artifact/org.apache.nifi](https://mvnrepository.com/artifact/org.apache.nifi)
- [https://github.com/apache/nifi](https://github.com/apache/nifi)
- [https://apachenifi.slack.com/join/shared\_invite](https://apachenifi.slack.com/join/shared_invite)
- [https://hub.docker.com/r/apache/nifi/ ](https://hub.docker.com/r/apache/nifi/%C2%A0)
- [https://www.cloudera.com/products/data-science-and-engineering/data-science-workbench.html](https://www.cloudera.com/products/data-science-and-engineering/data-science-workbench.html)
- [https://www.cloudera.com/products/cdf/cem.html](https://www.cloudera.com/products/cdf/cem.html)
- [https://blog.cloudera.com/smm-1-2-released-with-powerful-new-alerting-and-topic-lifecycle-management-features-with-schema-registry-integration/](https://blog.cloudera.com/smm-1-2-released-with-powerful-new-alerting-and-topic-lifecycle-management-features-with-schema-registry-integration/)