Commit 5d5849a4 authored by uncol's avatar uncol
Browse files

add backup column

parent 46e46986
......@@ -42,6 +42,7 @@ class ServiceAPI(API):
"config": get_service_config(None, s["name"])
}]
r[-1]["n_instances"] = sum(n["n_instances"] for n in r[-1]["nodes"])
r[-1]["n_backup_instances"] = sum(n["n_backup_instances"] for n in r[-1]["nodes"])
return r
def get_pool_config(pool):
......@@ -61,6 +62,7 @@ class ServiceAPI(API):
"config": get_service_config(pool, s["name"])
}]
r[-1]["n_instances"] = sum(n["n_instances"] for n in r[-1]["nodes"])
r[-1]["n_backup_instances"] = sum(n["n_backup_instances"] for n in r[-1]["nodes"])
return r
def get_service_nodes(pool, service):
......@@ -95,6 +97,7 @@ class ServiceAPI(API):
for c in Service.select().where(Service.environment == env):
node_cfg[c.pool.id if c.pool else None, c.service, c.node_id] = {
"n_instances": c.n_instances,
"n_backup_instances": c.n_backup_instances,
"loglevel": c.loglevel
}
nodes = []
......@@ -104,6 +107,7 @@ class ServiceAPI(API):
"node_id": n.id,
"node": n.name,
"n_instances": 0,
"n_backup_instances": 0,
"loglevel": "info"
}]
nodes = sorted(nodes, key=lambda x: (x["datacenter"], x["node"]))
......@@ -214,9 +218,10 @@ class ServiceAPI(API):
pool = s.pool.id if s.pool else None
c = ncfg.get((pool, s.service, s.node.id))
if c:
if c["n_instances"] != s.n_instances or c["loglevel"] != s.loglevel:
if c["n_instances"] != s.n_instances or c["loglevel"] != s.loglevel or c["n_backup_instances"] != s.n_backup_instances:
# Changed
s.n_instances = c["n_instances"]
s.n_backup_instances = c["n_backup_instances"]
s.loglevel = c["loglevel"]
s.save()
del ncfg[pool, s.service, s.node.id]
......@@ -231,6 +236,7 @@ class ServiceAPI(API):
service=c["service"],
node=c["node_id"],
n_instances=c["n_instances"],
n_backup_instances=c["n_backup_instances"],
loglevel=c["loglevel"]
).save()
return True
from peewee import IntegerField
def migrate(migrator):
migrator.add_column(
"service",
"n_backup_instances",
IntegerField(default=0)
)
......@@ -26,7 +26,7 @@ class Service(Model):
pool = ForeignKeyField(Pool, null=True)
node = ForeignKeyField(Node)
n_instances = IntegerField(default=0)
#n_backup_services = IntegerField(default=0)
n_backup_instances = IntegerField(default=0)
loglevel = CharField(default="info", choices=[
"notset",
"debug",
......
......@@ -23,7 +23,7 @@ var service_panel = {
scroll: true,
select: true,
navigation: true,
templateItem: "<i class='fa fa-#icon#'></i> #value# <span class='webix_badge'>#n_instances#</span>",
templateItem: "<i class='fa fa-#icon#'></i> #value# <span class='webix_badge' style='background-color: green !important;'>#n_backup_instances#</span><span class='webix_badge'>#n_instances#</span>",
on: {
"onSelectChange": "service_logic.on_select_service"
}
......@@ -66,6 +66,25 @@ var service_panel = {
},
width: 100
},
{
id: "n_backup_instances",
header: "Backup",
editor: "text",
format: function (value) {
if (typeof value === "string") {
value = parseInt(value);
}
switch (value) {
case 0:
return "<i class='fa fa-times'></i>";
case 1:
return "<i class='fa fa-check'></i>";
default:
return value;
}
},
width: 100
},
{
id: "loglevel",
header: "Loglevel",
......
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