Commit 2a40bac5 authored by Aleksey Shirokih's avatar Aleksey Shirokih
Browse files

Add ct migration details

parent 496432f9
...@@ -114,12 +114,18 @@ def migrate(migrator): ...@@ -114,12 +114,18 @@ def migrate(migrator):
'pgbouncer', 'pgbouncer',
'nsqadmin' 'nsqadmin'
) )
consul_template_depend_srv = (
'clickhouse',
'nsqd',
'nginx'
)
if len(Environment.select()) != 0: if len(Environment.select()) != 0:
for env in Environment.select(): for env in Environment.select():
print("Migrating %s" % env.name) print("Migrating %s" % env.name)
# remove nodes without services # remove nodes without services
promote_nodes = set() noc_promote_nodes = set()
ct_promote_nodes = set()
for srv in Service.select().where(Service.environment == env): for srv in Service.select().where(Service.environment == env):
# remove correlator without pool # remove correlator without pool
if srv.service in moved_to_pooled and not srv.pool_id: if srv.service in moved_to_pooled and not srv.pool_id:
...@@ -132,9 +138,12 @@ def migrate(migrator): ...@@ -132,9 +138,12 @@ def migrate(migrator):
# some services has no config # some services has no config
if not srv.config: if not srv.config:
srv.config = '{}' srv.config = '{}'
if srv.service == "consul-template":
srv.present = True
# rename # rename
if srv.service == "consultemplate": if srv.service == "consultemplate":
srv.service = "consul-template" srv.service = "consul-template"
srv.present = True
if srv.service == "zz_alerta": if srv.service == "zz_alerta":
srv.service = "alerta" srv.service = "alerta"
conf = json.loads(srv.config) conf = json.loads(srv.config)
...@@ -174,17 +183,35 @@ def migrate(migrator): ...@@ -174,17 +183,35 @@ def migrate(migrator):
conf["power"] = "agent" conf["power"] = "agent"
srv.present = True srv.present = True
# look for nodes without noc service
if srv.service in noc_services: if srv.service in noc_services:
promote_nodes.add(srv.node) noc_promote_nodes.add(srv.node)
# look for ct dependent srv without ct on node
if srv.service in consul_template_depend_srv:
ct_promote_nodes.add(srv.node)
conf["loglevel"] = srv.loglevel conf["loglevel"] = srv.loglevel
srv.config = json.dumps(conf, sort_keys=True) srv.config = json.dumps(conf, sort_keys=True)
srv.save() srv.save()
# noc service should be enabled if any noc services was enabled # noc service should be enabled if any noc services was enabled
for n in promote_nodes: for n in noc_promote_nodes:
s = Service.select().where(Service.environment == env.id, Service.node == n, Service.service == "noc") s = Service.select().where(Service.environment == env.id, Service.node == n, Service.service == "noc")
s[0].present = True s[0].present = True
s[0].save() s[0].save()
# add ct to nodes required
for n in ct_promote_nodes:
Service(
environment=env.id,
service="consul-template",
pool=None,
node=n.id,
present=True,
loglevel="info",
config=json.dumps({}, sort_keys=True)
).save()
migrator.drop_column( migrator.drop_column(
"service", "service",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment