Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tsm-orchestration
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
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
UFZ TSM
tsm-orchestration
Merge requests
!285
added reparse all script
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
added reparse all script
reparse-all-script
into
main
Overview
3
Commits
3
Pipelines
3
Changes
1
All threads resolved!
Hide all comments
Merged
David Schäfer
requested to merge
reparse-all-script
into
main
1 month ago
Overview
3
Commits
3
Pipelines
3
Changes
1
All threads resolved!
Hide all comments
Expand
Added a script to reparse all files for a given thing.
0
0
Merge request reports
Compare
main
version 2
f0f28292
1 month ago
version 1
f1d960b6
1 month ago
main (base)
and
latest version
latest version
79bb54c3
3 commits,
1 month ago
version 2
f0f28292
2 commits,
1 month ago
version 1
f1d960b6
1 commit,
1 month ago
1 file
+
98
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/run_reparse_thing.py
0 → 100644
+
98
−
0
Options
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import
logging
import
json
from
fnmatch
import
fnmatch
import
click
from
minio
import
Minio
import
paho.mqtt.client
as
mqtt
from
timeio.feta
import
Thing
from
timeio.journaling
import
Journal
logging
.
basicConfig
(
level
=
logging
.
INFO
)
logger
=
logging
.
getLogger
(
"
reprocess-files
"
)
journal
=
Journal
(
"
Reprocessing
"
)
def
setupMQTT
(
host
,
username
,
password
):
host
,
port
=
host
.
split
(
"
:
"
)
port
=
int
(
port
)
client
=
mqtt
.
Client
(
client_id
=
"
reparse-files
"
,
clean_session
=
False
)
if
port
==
8883
:
client
.
tls_set
()
client
.
suppress_exceptions
=
False
client
.
username_pw_set
(
username
,
password
)
client
.
connect
(
host
,
port
,
keepalive
=
60
)
if
not
client
.
is_connected
():
raise
RuntimeError
(
f
"
Couldn
'
t etsablish a connection to
{
host
}
:
{
port
}
"
)
return
client
@click.command
()
@click.option
(
"
--configdb-dsn
"
,
default
=
"
postgresql://configdb:configdb@localhost:5432/postgres
"
,
envvar
=
"
CONFIGDB_DSN
"
,
)
@click.option
(
"
--thing-uuid
"
,
default
=
"
0a308373-ab29-4317-b351-1443e8a1babd
"
,
envvar
=
"
THING_UUID
"
)
@click.option
(
"
--minio-host
"
,
default
=
"
localhost:9000
"
,
envvar
=
"
MINIO_HOST
"
)
@click.option
(
"
--minio-user
"
,
default
=
"
minioadmin
"
,
envvar
=
"
MINIO_USER
"
)
@click.option
(
"
--minio-password
"
,
default
=
"
minioadmin
"
,
envvar
=
"
MINIO_PASSWORD
"
)
@click.option
(
"
--mqtt-host
"
,
default
=
"
localhost:1883
"
,
envvar
=
"
MQTT_HOST
"
)
@click.option
(
"
--mqtt-user
"
,
default
=
"
mqtt
"
,
envvar
=
"
MQTT_USER
"
)
@click.option
(
"
--mqtt-password
"
,
default
=
"
mqtt
"
,
envvar
=
"
MQTT_PASSWORD
"
)
def
main
(
configdb_dsn
,
thing_uuid
,
minio_host
,
minio_user
,
minio_password
,
mqtt_host
,
mqtt_user
,
mqtt_password
,
):
store
=
Thing
.
from_uuid
(
thing_uuid
,
dsn
=
configdb_dsn
).
raw_data_storage
minio
=
Minio
(
endpoint
=
minio_host
,
access_key
=
minio_user
,
secret_key
=
minio_password
,
secure
=
not
minio_host
.
startswith
(
"
localhost
"
),
)
mqtt
=
setupMQTT
(
mqtt_host
,
mqtt_user
,
mqtt_password
)
bucket
=
store
.
bucket
fnpattern
=
store
.
filename_pattern
mqtt
.
loop_start
()
message
=
{
"
EventName
"
:
"
s3:ObjectCreated:Put
"
}
for
i
,
obj
in
enumerate
(
minio
.
list_objects
(
bucket
)):
fname
=
obj
.
object_name
if
fnmatch
(
fname
,
fnpattern
):
message
[
"
Key
"
]
=
f
"
{
bucket
}
/
{
fname
}
"
logging
.
info
(
f
"
republishing file:
{
message
[
'
Key
'
]
}
"
)
result
=
mqtt
.
publish
(
topic
=
"
object_storage_notification
"
,
payload
=
json
.
dumps
(
message
),
qos
=
1
)
if
result
[
0
]
!=
0
:
logger
.
warning
(
f
"
Failed to deliver reprocessing message for file:
{
message
[
'
Key
'
]
}
"
)
mqtt
.
loop_stop
()
mqtt
.
disconnect
()
if
__name__
==
"
__main__
"
:
main
()
Loading