Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BigData-radio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ANDRE Quentin
BigData-radio
Commits
1ab38663
Commit
1ab38663
authored
2 years ago
by
Quentin ANDRE
Browse files
Options
Downloads
Patches
Plain Diff
12
parent
ac5fc561
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
planes_producer.py
+2
-2
2 additions, 2 deletions
planes_producer.py
spark_launch.sh
+1
-1
1 addition, 1 deletion
spark_launch.sh
spark_streaming.py
+10
-3
10 additions, 3 deletions
spark_streaming.py
with
13 additions
and
6 deletions
planes_producer.py
+
2
−
2
View file @
1ab38663
...
...
@@ -4,7 +4,7 @@ import json
from
opensky_api
import
OpenSkyApi
from
kafka
import
KafkaProducer
producer
=
KafkaProducer
(
bootstrap_servers
=
"
pi-node07:9092
"
)
producer
=
KafkaProducer
(
bootstrap_servers
=
"
pi-node07:9092
,pi-node07:9093
"
)
api
=
OpenSkyApi
()
while
1
:
...
...
@@ -15,7 +15,7 @@ while 1:
plane
[
key
]
=
getattr
(
state
,
key
)
producer
.
send
(
"
air-traffic
"
,
json
.
dumps
(
plane
).
encode
())
print
(
"
{} Produced {} air traffic records
"
.
format
(
time
(),
len
(
states
.
states
)))
sleep
(
1
0.01
)
sleep
(
1
2
)
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
spark_launch.sh
+
1
−
1
View file @
1ab38663
...
...
@@ -5,7 +5,7 @@ ssh pi@10.29.227.239
start-dfs.sh
$SPARK_HOME
/sbin/start-all.sh
# launch spark_streaming in node 29
spark-submit SparkStreamingRadio/spark_streaming_radio.py
spark-submit
--packages
org.apache.spark:spark-sql-kafka-0-10_2.12:3.2.1
SparkStreamingRadio/spark_streaming_radio.py
# stop
$SPARK_HOME
/sbin/stop-all.sh
...
...
This diff is collapsed.
Click to expand it.
spark_streaming.py
+
10
−
3
View file @
1ab38663
...
...
@@ -18,7 +18,7 @@ def find_country(lat, long):
spark
=
SparkSession
.
builder
.
appName
(
"
Spark Structured Streaming from Kafka
"
).
getOrCreate
()
sdfPlanes
=
spark
.
readStream
.
format
(
"
kafka
"
)
\
.
option
(
"
kafka.bootstrap.servers
"
,
"
pi-node07:9092
"
)
\
.
option
(
"
kafka.bootstrap.servers
"
,
"
pi-node07:9092
, pi-node07:9093
"
)
\
.
option
(
"
subscribe
"
,
"
air-traffic
"
)
\
.
option
(
"
startingOffsets
"
,
"
latest
"
)
\
.
load
().
selectExpr
(
"
CAST(value AS STRING)
"
)
...
...
@@ -59,5 +59,12 @@ def parse_data_from_kafka_message(sdf, schema):
sdf = sdf.withColumn(field.name, col.getItem(idx).cast(field.dataType))
'''
return
sdf
.
withColumn
(
"
value
"
,
from_json
(
"
value
"
,
schema
)).
select
([
field
.
name
for
field
in
schema
])
sdfPlanes
=
parse_data_from_kafka_message
(
sdfPlanes
,
planesSchema
)
sdfPlanes
.
show
()
\ No newline at end of file
#query = parse_data_from_kafka_message(sdfPlanes, planesSchema)
#query.writeStream \
sdfPlanes
.
writeStream
\
.
outputMode
(
"
append
"
)
\
.
format
(
"
console
"
)
\
.
option
(
"
truncate
"
,
False
)
\
.
start
()
\
.
awaitTermination
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment