From 245be7789b28833c8d70f1c8c28814a2702fdcc8 Mon Sep 17 00:00:00 2001 From: imotai Date: Fri, 18 Dec 2015 17:10:24 +0800 Subject: [PATCH 1/2] support multi datacenter --- platform/src/bootstrap/settings.py | 7 +- platform/src/bootstrap/urls.py | 4 + platform/src/statics/tpl/agent.tpl | 36 ++++ platform/src/templates/base.html | 8 +- platform/src/templates/cluster.html | 25 +-- platform/src/templates/dc.html | 100 ++++++++++ platform/src/templates/index.html | 15 +- platform/src/templates/job.html | 11 +- platform/src/trace/urls.py | 10 +- platform/src/trace/views.py | 291 ++++++---------------------- 10 files changed, 237 insertions(+), 270 deletions(-) create mode 100644 platform/src/statics/tpl/agent.tpl create mode 100644 platform/src/templates/dc.html diff --git a/platform/src/bootstrap/settings.py b/platform/src/bootstrap/settings.py index a3fc3834..1b112804 100644 --- a/platform/src/bootstrap/settings.py +++ b/platform/src/bootstrap/settings.py @@ -20,7 +20,6 @@ SECRET_KEY = 'pme%=52e+c=_n%gau$6h-=w@+^6l4r8d*-x9a*q5a$ixsk7(^b' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True TEMPLATE_DEBUG = True @@ -97,8 +96,6 @@ os.path.join(BASE_DIR, "statics"), ) -GALAXY_ADDR="" +DEBUG = True LUMIA_ADDR="127.0.0.1:8081" - -TRACE_QUERY_ENGINE="xxxx" -GALAXY_MASTER="xxxx" +LITE_DB_PATH=os.path.join(BASE_DIR, "dc.json") diff --git a/platform/src/bootstrap/urls.py b/platform/src/bootstrap/urls.py index ae141983..cbc03c29 100644 --- a/platform/src/bootstrap/urls.py +++ b/platform/src/bootstrap/urls.py @@ -14,3 +14,7 @@ (r'^trace/', urls.include('trace.urls')), ) +urlpatterns += urls.patterns('', + (r'^dc/', urls.include('dc.urls')), +) + diff --git a/platform/src/statics/tpl/agent.tpl b/platform/src/statics/tpl/agent.tpl new file mode 100644 index 00000000..d77b14a2 --- /dev/null +++ b/platform/src/statics/tpl/agent.tpl @@ -0,0 +1,36 @@ +

{{}}

+ +
+
+
+ {{agent_total}} +
+
+ 机器总数 +
+
+
+
+ {{cpu_total}} +
+
+ 总cpu核数 +
+
+
+
+ {{cpu_total_used}} +
+
+ 总cpu使用核数 +
+
+
+
+ {{cpu_total_assigned}} +
+
+ 已分配cpu数 +
+
+
diff --git a/platform/src/templates/base.html b/platform/src/templates/base.html index ee29b3e4..5cf0af50 100644 --- a/platform/src/templates/base.html +++ b/platform/src/templates/base.html @@ -17,7 +17,13 @@ - + {%block custom-js%}{%endblock%} diff --git a/platform/src/templates/cluster.html b/platform/src/templates/cluster.html index 4daae194..06dd163a 100644 --- a/platform/src/templates/cluster.html +++ b/platform/src/templates/cluster.html @@ -19,9 +19,10 @@ @@ -117,11 +118,11 @@

Agent Stat Stream

var today = new Date(); var last = new Date(today.getTime() - (3 * 24 * 60 * 60 * 1000)); - var query_cpu_stat = "select time, total_cpu_assigned,total_cpu_millicores,total_cpu_used_millicores from ClusterStat where data_center='yq01' "+ + var query_cpu_stat = "select time, total_cpu_assigned,total_cpu_millicores,total_cpu_used_millicores from ClusterStat where data_center='{{dc}}' "+ " and time >= '" + FormatDate(last) + "' and time <='" + FormatDate(today)+ "'"; - $.getJSON(ROOT_URL+"trace/squery?limit=5000&db=baidu.galaxy&sql="+ encodeURIComponent(query_cpu_stat),function(data){ + $.getJSON(ROOT_URL+"trace/squery?dc={{dc}}&master={{master}}&trace={{trace}}&limit=5000&db=baidu.galaxy&sql="+ encodeURIComponent(query_cpu_stat),function(data){ $('#cluster_cpu_stat').highcharts('StockChart', { title: { text: 'cluster cpu stat' @@ -154,9 +155,9 @@

Agent Stat Stream

series :ProcessCpuStat(data) }); }); - var query_mem_stat = "select time, total_memory_assigned,total_memory,total_memory_used from ClusterStat where data_center='yq01' "+ + var query_mem_stat = "select time, total_memory_assigned,total_memory,total_memory_used from ClusterStat where data_center='{{dc}}' "+ " and time >= '" + FormatDate(last) + "' and time <='" + FormatDate(today)+"'"; - $.getJSON(ROOT_URL+"trace/squery?db=baidu.galaxy&sql="+ encodeURIComponent(query_mem_stat),function(data){ + $.getJSON(ROOT_URL+"trace/squery?dc={{dc}}&master={{master}}&trace={{trace}}&db=baidu.galaxy&sql="+ encodeURIComponent(query_mem_stat),function(data){ $('#cluster_mem_stat').highcharts('StockChart', { title: { text: 'cluster memory stat' @@ -189,9 +190,9 @@

Agent Stat Stream

series :ProcessMemStat(data) }); }); - var query_stable_stat = "select time,total_pod_count,total_node_count, alive_node_count,dead_node_count from ClusterStat where data_center='yq01'"+ + var query_stable_stat = "select time,total_pod_count,total_node_count, alive_node_count,dead_node_count from ClusterStat where data_center='{{dc}}'"+ " and time >= '" + FormatDate(last) + "' and time <='" + FormatDate(today)+"'"; - $.getJSON(ROOT_URL+"trace/squery?limit=5000&db=baidu.galaxy&sql="+ encodeURIComponent(query_stable_stat),function(data){ + $.getJSON(ROOT_URL+"trace/squery?master={{master}}&dc={{dc}}&trace={{trace}}&limit=5000&db=baidu.galaxy&sql="+ encodeURIComponent(query_stable_stat),function(data){ var total_node = new Array; var total_alive = new Array; var total_dead = new Array; @@ -273,7 +274,7 @@

Agent Stat Stream

}); }); var GetCpuStatus = function(){ - $.getJSON(ROOT_URL+"trace/status", function(data){ + $.getJSON(ROOT_URL+"trace/status?master={{master}}&dc={{dc}}&trace={{trace}}", function(data){ $.get(MEDIA_URL +"/tpl/cpu.tpl", function(tpl){ var overused = data.data.status.cpu_used - data.data.status.cpu_assigned; if (overused < 0) { @@ -293,9 +294,9 @@

Agent Stat Stream

GetCpuStatus(); setInterval(GetCpuStatus(), 60 * 1000); var GetAgentEvent = function(){ - var query = "select addr, time, action, data_center from AgentEvent where data_center='yq01' " + + var query = "select addr, ftime, action, data_center,time from AgentEvent where data_center='{{dc}}' " + " and time >= '" + FormatDate(last) + "' and time <='" + FormatDate(today)+"'"; - $.getJSON(ROOT_URL+"trace/squery?limit=5000&db=baidu.galaxy&sql=" + encodeURIComponent(query), function(data) { + $.getJSON(ROOT_URL+"trace/squery?master={{master}}&dc={{dc}}&trace={{trace}}&limit=5000&db=baidu.galaxy&sql=" + encodeURIComponent(query), function(data) { var events = Mustache.render(data.data.tpl, {datas:data.data.datas}); $("#agent-stat").html(events); }); diff --git a/platform/src/templates/dc.html b/platform/src/templates/dc.html new file mode 100644 index 00000000..f5880ef8 --- /dev/null +++ b/platform/src/templates/dc.html @@ -0,0 +1,100 @@ +{%extends "base.html"%} +{%block custom-css%} + + + + +{%endblock%} +{%block main%} + + +
+ +
+ + +
+ + + + + + + + + + + {% for dc in dcs%} + + + + + + + + {%endfor%} +
#namekeymastertrace
{{forloop.counter}}{{dc.name}}{{dc.dc}}{{dc.master}}{{dc.trace}}
+
+{%endblock%} + +{%block custom-js%} + + + +{%endblock%} diff --git a/platform/src/templates/index.html b/platform/src/templates/index.html index 485d1624..00d11740 100644 --- a/platform/src/templates/index.html +++ b/platform/src/templates/index.html @@ -11,9 +11,11 @@ @@ -37,7 +39,7 @@ {% for job in jobs%} {{forloop.counter}} - {{job.jobid}} + {{job.jobid}} {{job.desc.name}} {{job.state}} {{job.running_num}}/{{job.pending_num}}/{{job.deploying_num}} @@ -58,8 +60,7 @@ var len = (String(base || 10).length - String(this).length)+1; return len > 0? new Array(len).join(chr || '0')+this : this; } -var ROOT_URL="{{root_url}}"; -var MEDIA_URL="{{media_url}}"; + $(function(){ var today = new Date(); var last = new Date(today.getTime() - (3 * 24 * 60 * 60 * 1000)); @@ -67,7 +68,7 @@ var end_time = today * 1000; $("#query_btn").bind("click",function(e){ var sql = encodeURIComponent($("#sql_content").val()); - $.getJSON(ROOT_URL+"trace/squery?db=baidu.galaxy&sql="+sql, function(data){ + $.getJSON(ROOT_URL+"trace/squery?dc={{dc}}&master={{master}}&trace={{trace}}&db=baidu.galaxy&sql="+sql, function(data){ var tables = Mustache.render(data.data.tpl,{datas:data.data.datas}); $("#datas").html(tables); }); diff --git a/platform/src/templates/job.html b/platform/src/templates/job.html index 373f3940..90bef3b6 100644 --- a/platform/src/templates/job.html +++ b/platform/src/templates/job.html @@ -20,9 +20,10 @@ @@ -79,7 +80,7 @@

Task Error Stream

var query_task_stat = "select cmd,agent_addr,pod_id,ftime,error,exit_code,internal_error,deploy,main,gc_dir,ttime from TaskEvent where job_id='" + JOB_ID + "'";//"' and " + " time >= '" + FormatDate(last) + "' and time <='" + FormatDate(today)+ "'"; var sql = encodeURIComponent(query_task_stat); - $.getJSON(ROOT_URL+"trace/squery?db=baidu.galaxy&sql="+sql, function(data){ + $.getJSON(ROOT_URL+"trace/squery?master={{master}}&dc={{dc}}&trace={{trace}}&db=baidu.galaxy&sql="+sql, function(data){ var tasks = Mustache.render(data.data.tpl, {datas:data.data.datas}); $("#tasks").html(tasks); }); @@ -104,7 +105,7 @@

Task Error Stream

job_stat_stock.push({name:"pending", data:pending}); return job_stat_stock; } - $.getJSON(ROOT_URL + "trace/squery?db=baidu.galaxy&limit=5000&sql="+encodeURIComponent(query_job), function(data){ + $.getJSON(ROOT_URL + "trace/squery?master={{master}}&dc={{dc}}&trace={{trace}}&db=baidu.galaxy&limit=5000&sql="+encodeURIComponent(query_job), function(data){ $('#stable_stat').highcharts('StockChart', { title: { text: 'job stabiliztion stat' diff --git a/platform/src/trace/urls.py b/platform/src/trace/urls.py index 764f0a38..17813634 100644 --- a/platform/src/trace/urls.py +++ b/platform/src/trace/urls.py @@ -4,18 +4,10 @@ urlpatterns = urls.patterns('trace.views', (r'^job$', 'job_all'), (r'^job/detail', 'job_detail'), - (r'^pod/detail', 'pod_detail'), - (r'^job/stat', 'job_stat'), - (r'^job/event', 'job_event'), - (r'^pod$', 'get_pod'), - (r'^pod/stat', 'pod_stat'), - (r'^pod/event', 'pod_event'), - (r'^pod/task', 'task_event'), - (r'^pod/allevent', 'get_pod_event_by_jobid'), - (r'^query$', 'query'), (r'^squery$', 'squery'), (r'^sql$', 'sql'), (r'^cluster$', 'cluster'), (r'^status$', 'get_real_time_status'), + (r'^dc$', 'get_total_status'), ) diff --git a/platform/src/trace/views.py b/platform/src/trace/views.py index 6121dbd5..f47abf07 100644 --- a/platform/src/trace/views.py +++ b/platform/src/trace/views.py @@ -6,6 +6,7 @@ import datetime import time import urllib +import json from common import util from common import pb2dict from bootstrap import settings @@ -23,7 +24,29 @@ import logging logger = logging.getLogger("console") +def data_center_decorator(func): + def data_center_decorator_wrapper(request, *args, **kwds): + data_center = request.GET.get("dc", None) + request.has_err = False + if not data_center: + request.has_err = True + return func(request, *args, **kwds) + master = request.GET.get("master", None) + if not master: + request.has_err = True + return func(request, *args, **kwds) + trace = request.GET.get("trace", None) + if not trace: + request.has_err = True + return func(request, *args, **kwds) + request.trace = trace + request.data_center = data_center + request.master = master + return func(request, *args, **kwds) + return data_center_decorator_wrapper + def sql_decorator(func): + @data_center_decorator def sql_wrapper(request, *args, **kwds): request.has_err = False db = request.GET.get("db", None) @@ -43,43 +66,6 @@ def sql_wrapper(request, *args, **kwds): return func(request, *args, **kwds) return sql_wrapper -def query_decorator(func): - def query_wrapper(request, *args, **kwds): - start_time = request.GET.get("start", None) - end_time = request.GET.get("end", None) - request.has_err = False - if not end_time or not start_time: - end_time = datetime.datetime.now() - start_time = end_time - datetime.timedelta(hours = 1) - request.start_time = long(time.mktime(start_time.timetuple())) * 1000000 - request.end_time = long(time.mktime(end_time.timetuple())) * 1000000 - else: - request.start_time = long(start_time) - request.end_time = long(end_time) - db = request.GET.get("db", None) - if not db : - request.has_err = True - request.err = "db is required" - return func(request, *args, **kwds) - request.db = db - table = request.GET.get("table", None) - if not table: - request.has_err = True - request.err = "table is required" - return func(request, *args, **kwds) - request.table = table - fields = request.GET.get("fields", None) - if not fields: - request.has_err = True - request.err = "fields is required" - return func(request, *args, **kwds) - request.fields = fields.split(",") - request.reverse = request.GET.get("reverse", None) - limit = request.GET.get("limit", "100") - request.limit = int(limit) - return func(request, *args, **kwds) - return query_wrapper - def data_filter(data, fields = []): new_dict = {} if fields[0] == "*": @@ -171,7 +157,9 @@ def agent_event_processor(resultset, fields=[], limit=100): for data in resultset: for d in data.data_list: agent_event.ParseFromString(d) - stats.append(data_filter(util.pb2dict(agent_event), fields)) + e = util.pb2dict(agent_event) + e['ftime'] = datetime.datetime.fromtimestamp(e['time']/1000000).strftime("%Y-%m-%d %H:%M:%S") + stats.append(data_filter(e , fields)) return stats[0:limit] @@ -186,48 +174,9 @@ def agent_event_processor(resultset, fields=[], limit=100): } } -@query_decorator -def query(request): - builder = http.ResponseBuilder() - if request.has_err: - return builder.error(request.err).build_json() - ftrace = fsdk.FtraceSDK(settings.TRACE_QUERY_ENGINE) - id = request.GET.get("id", None) - jobid = request.GET.get("jobid", None) - podid = request.GET.get("podid", None) - resultset = [] - status = False - if id : - resultset, status = ftrace.simple_query(request.db, - request.table, - id, - request.start_time, - request.end_time, - request.limit) - elif jobid: - resultset, status = ftrace.index_query(request.db, - request.table, - "jobid", - jobid, - request.start_time, - request.end_time, - request.limit) - elif podid: - resultset, status = ftrace.index_query(request.db, - request.table, - "pod_id", - podid, - request.start_time, - request.end_time, - request.limit) - if not status: - return builder.error("fail to make a query").build_json() - proc_func = PROCESSOR_MAP[request.db][request.table] - datas= proc_func(resultset, request.fields, request.limit) - return builder.ok(data = {"datas":datas}).build_json() - +@data_center_decorator def index(request): - return util.render_tpl(request, {}, "index.html") + return util.render_tpl(request, {"dc":request.data_center,"master":request.master,"trace":request.trace}, "index.html") def sql_to_mdt(db, sql, limit): operator_dict = { @@ -277,7 +226,7 @@ def sql_to_mdt(db, sql, limit): def gen_tpl(fields): tpl=""" - +
%(head)s @@ -309,181 +258,61 @@ def squery(request): context, pb_req, ok = sql_to_mdt(request.db, request.sql, request.limit) if not ok: return builder.error("fail to parse sql").build_json() - ftrace = fsdk.FtraceSDK(settings.TRACE_QUERY_ENGINE) + ftrace = fsdk.FtraceSDK(request.trace) resultset, ok = ftrace.make_req(pb_req) if not ok: return builder.error("fail to parse sql").build_json() proc_func = PROCESSOR_MAP[request.db][context["table"]] datas= proc_func(resultset, context["fields"], request.limit) - return builder.ok(data = {"datas":datas, "tpl":gen_tpl(context["fields"])}).build_json() + return builder.ok(data = {"dc":request.data_center,"master":request.master,"trace":request.trace,"datas":datas, "tpl":gen_tpl(context["fields"])}).build_json() +@data_center_decorator def sql(request): - return util.render_tpl(request, {},"sql.html") + return util.render_tpl(request, {"dc":request.data_center,"master":request.master,"trace":request.trace},"sql.html") +@data_center_decorator def cluster(request): - return util.render_tpl(request, {},"cluster.html") - -def job_stat(request): - jobid = request.GET.get("jobid", None) - reverse = request.GET.get("reverse", None) - builder = http.ResponseBuilder() - if not jobid: - return builder.error("jobid is required").build_json() - end_time = datetime.datetime.now() - start_time = end_time - datetime.timedelta(hours = 1) - trace_dao = dao.TraceDao(settings.TRACE_QUERY_ENGINE) - stats, status = trace_dao.get_job_stat(jobid, - time.mktime(start_time.timetuple()), - time.mktime(end_time.timetuple())) - if not status: - return builder.error("fail to get job stat").build_json() - if reverse: - stats = sorted(stats, key=lambda x:x["time"], reverse = True) - return builder.ok(data = {"stats":stats}).build_json() - -def get_pod_event_by_jobid(request): - jobid = request.GET.get("jobid", None) - reverse = request.GET.get("reverse", None) - builder = http.ResponseBuilder() - if not jobid: - return builder.error("jobid is required").build_json() - end_time = datetime.datetime.now() - start_time = end_time - datetime.timedelta(hours = 24) - trace_dao = dao.TraceDao(settings.TRACE_QUERY_ENGINE) - events, status = trace_dao.get_pod_event_by_jobid(jobid, - time.mktime(start_time.timetuple()), - time.mktime(end_time.timetuple()), - limit=50) - if not status: - return builder.error("fail to get pod event").build_json() - filter_events = [] - for e in events: - if e["level"] == "TINFO": - continue - - e["ftime"] = datetime.datetime.fromtimestamp(e['time']/1000000).strftime("%Y-%m-%d %H:%M:%S") - filter_events.append(e) - filter_events = sorted(filter_events, key=lambda x:x["time"], reverse = True) - return builder.ok(data = {"events": filter_events}).build_json() - - -def job_event(request): - jobid = request.GET.get("jobid", None) - builder = http.ResponseBuilder() - if not jobid: - return builder.error("jobid is required").build_json() - end_time = datetime.datetime.now() - start_time = end_time - datetime.timedelta(hours = 1) - trace_dao = dao.TraceDao(settings.TRACE_QUERY_ENGINE) - events, status = trace_dao.get_job_event(jobid, - time.mktime(start_time.timetuple()), - time.mktime(end_time.timetuple())) - if not status: - return builder.error("fail to get job evnets").build_json() - events = sorted(events, key=lambda x:x["time"], reverse = True) - return builder.ok(data = {"events":events}).build_json() - -def get_pod(request): - podid = request.GET.get("podid", None) - if not podid: - return util.render_tpl(request, {}, "404.html") - end_time = datetime.datetime.now() - start_time = end_time - datetime.timedelta(hours = 1) - trace_dao = dao.TraceDao(settings.TRACE_QUERY_ENGINE) - pod_events, status = trace_dao.get_pod_event(podid, - time.mktime(start_time.timetuple()), - time.mktime(end_time.timetuple())) - if not status: - return util.render_tpl(request, {"err":"fail to get trace"}, "500.html") - - task_events, status = trace_dao.get_task_event(podid, - time.mktime(start_time.timetuple()), - time.mktime(end_time.timetuple())) - - return util.render_tpl(request, {"podid":podid, - "pod_events":pod_events, - "task_events":task_events}, - "pod_trace.html") -def pod_event(request): - podid = request.GET.get("podid", None) - builder = http.ResponseBuilder() - if not podid: - return builder.error("podid is required").build_json() - end_time = datetime.datetime.now() - start_time = end_time - datetime.timedelta(hours = 1) - trace_dao = dao.TraceDao(settings.TRACE_QUERY_ENGINE) - events, status = trace_dao.get_pod_event(podid, - time.mktime(start_time.timetuple()), - time.mktime(end_time.timetuple())) - if not status: - return builder.error("fail to get pod event").build_json() - events = sorted(events, key=lambda x:x["time"], reverse = True) - return builder.ok(data = {"events": events}).build_json() - -def task_event(request): - podid = request.GET.get("podid", None) - builder = http.ResponseBuilder() - if not podid: - return builder.error("podid is required").build_json() - - trace_dao = dao.TraceDao(settings.TRACE_QUERY_ENGINE) - end_time = datetime.datetime.now() - start_time = end_time - datetime.timedelta(hours = 1) - task_events, status = trace_dao.get_task_event(podid, - time.mktime(start_time.timetuple()), - time.mktime(end_time.timetuple()), - limit=20) - - if not status: - return builder.error("fail to get task event").build_json() - filter_events = [] - for e in task_events: - if e["level"] == "TINFO": - continue - e["ftime"] = datetime.datetime.fromtimestamp(e['ttime']/1000000).strftime("%Y-%m-%d %H:%M:%S") - filter_events.append(e) - filter_events = sorted(filter_events, key=lambda x:x["ttime"], reverse = True) - return builder.ok(data = {"events": filter_events}).build_json() - -def pod_stat(request): - podid = request.GET.get("podid", None) - builder = http.ResponseBuilder() - if not podid: - return builder.error("podid is required").build_json() - end_time = datetime.datetime.now() - start_time = end_time - datetime.timedelta(hours = 1) - trace_dao = dao.TraceDao(settings.TRACE_QUERY_ENGINE) - stats, status = trace_dao.get_pod_stat(podid, - time.mktime(start_time.timetuple()), - time.mktime(end_time.timetuple())) - if not status: - return builder.error("fail to get pod stat").build_json() - stats = sorted(stats, key=lambda x:x["time"], reverse = True) - return builder.ok(data = {"stats":stats}).build_json() + return util.render_tpl(request, {"dc":request.data_center,"master":request.master, "trace":request.trace},"cluster.html") +@data_center_decorator def job_all(request): - galaxy = sdk.GalaxySDK(settings.GALAXY_MASTER) + galaxy = sdk.GalaxySDK(request.master) jobs, status = galaxy.get_all_job() job_dicts = [] for job in jobs: job_dict = pb2dict.protobuf_to_dict(job) job_dict['state'] = master_pb2.JobState.Name(job_dict['state']) job_dicts.append(job_dict) - return util.render_tpl(request, {"jobs":job_dicts}, "index.html") + return util.render_tpl(request, {"jobs":job_dicts, + "dc":request.data_center, + "master":request.master, + "trace":request.trace}, "index.html") + #return util.render_tpl(request, {}, "index.html") +@data_center_decorator def job_detail(request): - return util.render_tpl(request, {"jobid":request.GET.get("jobid", None)}, + return util.render_tpl(request, {"dc":request.data_center,"master":request.master,"trace":request.trace, "jobid":request.GET.get("jobid", None)}, "job.html") -def pod_detail(request): - return util.render_tpl(request, {"podid":request.GET.get("podid", None), - "time":request.GET.get("time",None)}, - "pod_detail.html") +def get_total_status(request): + dcs = {} + with open(settings.LITE_DB_PATH, "rb") as fd: + dcs = json.load(fd) + datas = [] + for key in dcs: + galaxy = sdk.GalaxySDK(dcs[key]["master"]) + response = galaxy.get_real_time_status() + builder = http.ResponseBuilder() + status = pb2dict.protobuf_to_dict(response) + datas.append(status); + builder = http.ResponseBuilder() + return builder.ok(data = {"status":datas}).build_json() +@data_center_decorator def get_real_time_status(request): - galaxy = sdk.GalaxySDK(settings.GALAXY_MASTER) + galaxy = sdk.GalaxySDK(request.master) response = galaxy.get_real_time_status() builder = http.ResponseBuilder() status = pb2dict.protobuf_to_dict(response) - return builder.ok(data = {"status":status}).build_json() + return builder.ok(data = {"status":status,"dc":request.data_center,"master":request.master}).build_json() From 5742b9c2250d0d31ab2b08d400efb7c5bc6aa504 Mon Sep 17 00:00:00 2001 From: imotai Date: Fri, 18 Dec 2015 17:33:39 +0800 Subject: [PATCH 2/2] fix scheduler deploy step bug --- src/scheduler/scheduler.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/scheduler/scheduler.cc b/src/scheduler/scheduler.cc index 6f480a14..717d0a8d 100644 --- a/src/scheduler/scheduler.cc +++ b/src/scheduler/scheduler.cc @@ -432,18 +432,19 @@ int32_t Scheduler::ChoosePods(std::vector& pending_jobs, } } uint32_t max_deploy_pods = job_pending_pods.size(); - if (job_it->desc().deploy_step() > 0 && - (uint32_t)job_it->desc().deploy_step() < max_deploy_pods) { - max_deploy_pods = job_it->desc().deploy_step(); - } - LOG(INFO, "job %s deploy stat: pending_size %u, deploying_num %u, max_deploy_pods %u", - job_it->jobid().c_str(), job_pending_pods.size(), deploying_num, max_deploy_pods); + LOG(INFO, "job %s deploy stat: pending_size %u, deploying_num %u, max_deploy_pods %u, step size %u", + job_it->jobid().c_str(), job_pending_pods.size(), deploying_num, max_deploy_pods, + job_it->desc().deploy_step()); if (job_pending_pods.size() <= 0 - || deploying_num >= max_deploy_pods) { + || deploying_num >= (uint32_t)job_it->desc().deploy_step()) { continue; } std::vector need_schedule; - for (uint32_t i = 0; i < job_pending_pods.size() && deploying_num < max_deploy_pods; i++) { + for (uint32_t i = 0; + i < job_pending_pods.size() + && deploying_num < (uint32_t)job_it->desc().deploy_step() + && deploying_num < max_deploy_pods; + i++) { need_schedule.push_back(job_pending_pods[i]); deploying_num++; }