[dcm] Add deps and log commands
This commit is contained in:
92
bin/dcm
92
bin/dcm
@@ -11,6 +11,43 @@ import os
|
|||||||
import re
|
import re
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from time import time, sleep
|
from time import time, sleep
|
||||||
|
from pprint import PrettyPrinter
|
||||||
|
|
||||||
|
|
||||||
|
class Dependecies:
|
||||||
|
def __init__(self, deps):
|
||||||
|
self.deps = deps
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def load(yaml_filename):
|
||||||
|
deps = {}
|
||||||
|
with open(yaml_filename) as file:
|
||||||
|
dc = yaml.load(file, Loader=yaml.FullLoader)
|
||||||
|
for (name, conf) in dc['services'].items():
|
||||||
|
depends_on = conf.get('depends_on', [])
|
||||||
|
deps[name] = depends_on
|
||||||
|
return deps
|
||||||
|
|
||||||
|
def find(self, service):
|
||||||
|
all = set([service])
|
||||||
|
if service in self.deps:
|
||||||
|
services = self.deps[service]
|
||||||
|
new = set(services) - all
|
||||||
|
if new:
|
||||||
|
print(f"{service}: {new}")
|
||||||
|
all.update(services)
|
||||||
|
del self.deps[service]
|
||||||
|
for one in new:
|
||||||
|
all.update(self.find(one))
|
||||||
|
return all
|
||||||
|
|
||||||
|
|
||||||
|
def echo(text):
|
||||||
|
print(">> " + text)
|
||||||
|
|
||||||
|
|
||||||
|
def system(cmd):
|
||||||
|
return subprocess.call(cmd, shell=True)
|
||||||
|
|
||||||
|
|
||||||
def split(text):
|
def split(text):
|
||||||
@@ -40,8 +77,7 @@ def dc_cmd(args):
|
|||||||
def dc_run(args):
|
def dc_run(args):
|
||||||
cmd = dc_cmd(args)
|
cmd = dc_cmd(args)
|
||||||
print(cmd)
|
print(cmd)
|
||||||
returned_value = subprocess.call(cmd, shell=True)
|
return system(cmd)
|
||||||
exit(returned_value)
|
|
||||||
|
|
||||||
|
|
||||||
def dc_log(args):
|
def dc_log(args):
|
||||||
@@ -60,8 +96,16 @@ def dump_services(files):
|
|||||||
print(service)
|
print(service)
|
||||||
|
|
||||||
|
|
||||||
def service_dependencies(service, dc_files):
|
def dc_deps(dc_files, service):
|
||||||
pass
|
pp = PrettyPrinter(indent=2)
|
||||||
|
for dc_file in dc_files:
|
||||||
|
dep = Dependecies.load(dc_file)
|
||||||
|
if service in dep:
|
||||||
|
all = sorted(Dependecies(dep).find(service))
|
||||||
|
print(all)
|
||||||
|
return
|
||||||
|
print(f"Service {service} not found")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def dump_files(files):
|
def dump_files(files):
|
||||||
@@ -73,7 +117,6 @@ def dump_files(files):
|
|||||||
# AQE: /opt/bin/aqe ping
|
# AQE: /opt/bin/aqe ping
|
||||||
# md-api-new: curl -fs -o /dev/null http://localhost:9008/actuator/health/readiness
|
# md-api-new: curl -fs -o /dev/null http://localhost:9008/actuator/health/readiness
|
||||||
# potgres: s6-setuidgid postgres; /usr/bin/pg_isready
|
# potgres: s6-setuidgid postgres; /usr/bin/pg_isready
|
||||||
# pulsar: curl -fs -o /dev/null http://localhost:8080/admin/v2/tenants/public
|
|
||||||
# redis: /usr/bin/redis-cli ping
|
# redis: /usr/bin/redis-cli ping
|
||||||
# result-cache: curl -fs -o /dev/null http://localhost:9041/actuator/health/readiness
|
# result-cache: curl -fs -o /dev/null http://localhost:9041/actuator/health/readiness
|
||||||
# scan-model: curl -fs -o /dev/null http://localhost:9061/actuator/health/readiness
|
# scan-model: curl -fs -o /dev/null http://localhost:9061/actuator/health/readiness
|
||||||
@@ -82,8 +125,8 @@ def dump_files(files):
|
|||||||
|
|
||||||
def curl_check(uri):
|
def curl_check(uri):
|
||||||
cmd = "curl -f -s -o /dev/null " + uri
|
cmd = "curl -f -s -o /dev/null " + uri
|
||||||
print(cmd)
|
echo(cmd)
|
||||||
return subprocess.call(cmd, shell=True) == 0
|
return system(cmd) == 0
|
||||||
|
|
||||||
|
|
||||||
def check_pulsar():
|
def check_pulsar():
|
||||||
@@ -91,7 +134,7 @@ def check_pulsar():
|
|||||||
|
|
||||||
|
|
||||||
def check_postgres():
|
def check_postgres():
|
||||||
return False
|
return system("/usr/bin/pg_isready") == 0
|
||||||
|
|
||||||
|
|
||||||
def wait_for(check, delay, duration):
|
def wait_for(check, delay, duration):
|
||||||
@@ -99,12 +142,20 @@ def wait_for(check, delay, duration):
|
|||||||
while time() - start < duration:
|
while time() - start < duration:
|
||||||
if check():
|
if check():
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
sleep(delay)
|
echo(f"sleep for {delay} sec")
|
||||||
|
sleep(delay)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def up_and_wait(service, check, delay, duration):
|
def up_and_wait(service, check, delay, duration):
|
||||||
pass
|
dc_run(["up", "-d", service])
|
||||||
|
started = wait_for(check, delay, duration)
|
||||||
|
echo(f"WAIT FOR {service}")
|
||||||
|
if started:
|
||||||
|
echo(f"READY {service}")
|
||||||
|
else:
|
||||||
|
echo(f"BAD {service}")
|
||||||
|
|
||||||
|
|
||||||
def start_tiger():
|
def start_tiger():
|
||||||
@@ -127,6 +178,12 @@ DEFAULT_DCF = ["docker-compose.yaml"]
|
|||||||
DC_FILES = try_load_list("DCF", DEFAULT_DCF)
|
DC_FILES = try_load_list("DCF", DEFAULT_DCF)
|
||||||
DC_FILES_ARGS = dc_files(DC_FILES)
|
DC_FILES_ARGS = dc_files(DC_FILES)
|
||||||
|
|
||||||
|
SERVICES = {
|
||||||
|
"pulsar": lambda: up_and_wait("pulsar", check_pulsar, 10, 120),
|
||||||
|
"postgres": lambda: up_and_wait("postgres", check_postgres, 10, 120),
|
||||||
|
"data-loader": None, # co chci testovat? ze ma Exit code 0
|
||||||
|
}
|
||||||
|
|
||||||
DEFAULT_TIGER_SERVICES = [
|
DEFAULT_TIGER_SERVICES = [
|
||||||
"afm-exec-api",
|
"afm-exec-api",
|
||||||
"metadata-api-new",
|
"metadata-api-new",
|
||||||
@@ -140,8 +197,10 @@ TIGER_SERVICES = try_load_list("SERVICES", DEFAULT_TIGER_SERVICES)
|
|||||||
COMMANDS = {
|
COMMANDS = {
|
||||||
"files": lambda args: dump_files(DC_FILES),
|
"files": lambda args: dump_files(DC_FILES),
|
||||||
"services": lambda args: dump_services(DC_FILES),
|
"services": lambda args: dump_services(DC_FILES),
|
||||||
"log": dc_log
|
"log": dc_log,
|
||||||
# "dep":
|
"deps": lambda args: dc_deps(DC_FILES, args[0]),
|
||||||
|
"wait": None,
|
||||||
|
"up-wait": lambda args: SERVICES[args[0]](),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -151,8 +210,11 @@ def main():
|
|||||||
if action in COMMANDS:
|
if action in COMMANDS:
|
||||||
COMMANDS[action](args[1:])
|
COMMANDS[action](args[1:])
|
||||||
else:
|
else:
|
||||||
dc_run(args)
|
exit(dc_run(args))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
try:
|
||||||
|
main()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user