process.py 2.26 KB
Newer Older
1
2
3
from api.kafka import KafkaTopics
from api.helm import all_charts
from api.kubernetes import ConfigMap
4
import json
5
import logging
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20


class ImportProcess:

    def __init__(self, **kwargs):
        self.process_id = kwargs['global']['processId']
        self.config_maps = [ConfigMap(**cm) for cm in kwargs['config-maps']]
        with open('./configurations/kafka.json', mode='r') as fp:
            self.topics = KafkaTopics(self.process_id, kwargs['steps'], **json.load(fp))
        self.charts = filter(lambda x: x.name in kwargs['steps'], all_charts)
        self.values = kwargs

    def start(self):
        self.topics.create()
        for config_map in self.config_maps:
21
22
23
24
25
26
            completed_process = config_map.create(self.process_id)
            if completed_process.returncode:
                logging.error(completed_process.stderr.decode('utf-8'))
                exit(1)
            else:
                logging.info(f"Deployed config map {self.process_id}-{config_map.name}.")
Jonas Waeber's avatar
Jonas Waeber committed
27
        values = dict()
28
        for chart in self.charts:
Jonas Waeber's avatar
Jonas Waeber committed
29
30
31
            values.clear()
            for key in self.values['global']:
                values[key] = self.values['global'][key]
32
            if chart.name in self.values:
33
34
35
36
37
38
39
40
                for key in self.values[chart.name]:
                    values[key] = self.values[chart.name][key]
            completed_process = chart.install(self.process_id, values)
            if completed_process.returncode:
                logging.error(completed_process.stderr.decode('utf-8'))
                exit(1)
            else:
                logging.info(f"Installed chart {chart.name}.")
41
42
43

    def remove(self):
        for chart in self.charts:
Jonas Waeber's avatar
Jonas Waeber committed
44
45
46
47
48
            completed_process = chart.uninstall(self.process_id)
            if completed_process.returncode:
                logging.error(completed_process.stderr.decode('utf-8'))
            else:
                logging.info(f"Uninstalled chart {chart.name}.")
49
        for config_map in self.config_maps:
Jonas Waeber's avatar
Jonas Waeber committed
50
51
52
53
54
            completed_process = config_map.delete(self.process_id)
            if completed_process.returncode:
                logging.error(completed_process.stderr.decode('utf-8'))
            else:
                logging.info(f"Deleted config map {self.process_id}-{config_map.name}.")
55
        self.topics.delete()