-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (46 loc) · 1.84 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import requests
import json
import logging as log
import glob
from time import sleep
def main():
log.basicConfig(level=log.INFO)
while True:
log.info('Reading connectors')
connectors = []
for definition in glob.glob('/connectors/*.json'):
log.info('Reading connector definition from {}'.format(definition))
with open(definition) as stream:
connectors.append(json.loads(stream.read()))
log.info('Updating Kafka Connect')
for connector in connectors:
log.info('Connector definition: {}'. format(connector))
log.info('Checking if connector is already defined')
try:
resp = requests.get(
'http://localhost:8083/connectors/{}'.format(connector['name']))
except Exception as e:
log.error(e)
continue
log.info('Received: {}'.format(resp.status_code))
if resp.status_code == 200:
log.info('Updating connector definition')
try:
resp = requests.put(
'http://localhost:8083/connectors/{}/config'.format(connector['name']), json=connector['config'])
except Exception as e:
log.error(e)
continue
log.info('Received: {}'.format(resp.status_code))
elif resp.status_code == 404:
log.info('Creating connector')
try:
resp = requests.post(
'http://localhost:8083/connectors', json=connector)
except Exception as e:
log.error(e)
continue
log.info('Received: {}'.format(resp.status_code))
log.info('Sleeping for 60s')
sleep(60)
main()