def trends_summary(req, choice, stats_title, is_summary): if choice == 'this_month': format = 'month_year' elif choice == 'this_year': format = 'year' else: format = 'date' info = get_default_date(choice, req.zato.user_profile, format) try: n = int(req.GET.get('n', 10)) except ValueError: n = 10 _compare_to = compare_to[choice] return_data = { 'utc_start': info.utc_start, 'utc_stop': info.utc_stop, 'user_start': info.user_start, 'user_stop': info.user_stop, 'n': n, 'choice': choice, 'label': info.label, 'n_form': NForm(initial={'n':n}), 'compare_to': _compare_to, 'zato_clusters': req.zato.clusters, 'cluster_id': req.zato.cluster_id, 'choose_cluster_form':req.zato.choose_cluster_form, 'sample_dt': get_sample_dt(req.zato.user_profile), 'stats_title': stats_title, 'step': info.step, 'needs_stop': choice == 'last_hour', } return_data.update(get_js_dt_format(req.zato.user_profile)) return TemplateResponse(req, 'zato/stats/trends_summary.html', return_data)
def trends_summary(req, choice, stats_title, is_summary): if choice == 'this_month': format = 'month_year' elif choice == 'this_year': format = 'year' else: format = 'date' info = get_default_date(choice, req.zato.user_profile, format) try: n = int(req.GET.get('n', 10)) except ValueError: n = 10 _compare_to = compare_to[choice] return_data = { 'utc_start': info.utc_start, 'utc_stop': info.utc_stop, 'user_start': info.user_start, 'user_stop': info.user_stop, 'n': n, 'choice': choice, 'label': info.label, 'n_form': NForm(initial={'n': n}), 'compare_to': _compare_to, 'zato_clusters': req.zato.clusters, 'cluster_id': req.zato.cluster_id, 'search_form': req.zato.search_form, 'sample_dt': get_sample_dt(req.zato.user_profile), 'stats_title': stats_title, 'step': info.step, 'needs_stop': choice == 'last_hour', } return_data.update(get_js_dt_format(req.zato.user_profile)) return TemplateResponse(req, 'zato/stats/trends_summary.html', return_data)
def index(req): try: jobs = [] # Build a list of schedulers for a given Zato cluster. if req.zato.cluster_id and req.method == 'GET': # We have a server to pick the schedulers from, try to invoke it now. response = req.zato.client.invoke( 'zato.scheduler.job.get-list', {'cluster_id': req.zato.cluster_id}) if response.has_data: for job_elem in response.data: id = job_elem.id name = job_elem.name is_active = job_elem.is_active job_type = job_elem.job_type start_date = job_elem.start_date service_name = job_elem.service_name extra = job_elem.extra job_type_friendly = job_type_friendly_names[job_type] job = Job(id, name, is_active, job_type, from_utc_to_user(start_date + '+00:00', req.zato.user_profile), extra, service_name=service_name, job_type_friendly=job_type_friendly) if job_type == SCHEDULER.JOB_TYPE.ONE_TIME: definition_text = _one_time_job_def( req.zato.user_profile, start_date) elif job_type == SCHEDULER.JOB_TYPE.INTERVAL_BASED: definition_text = _interval_based_job_def( req.zato.user_profile, _get_start_date(job_elem.start_date), job_elem.repeats, job_elem.weeks, job_elem.days, job_elem.hours, job_elem.minutes, job_elem.seconds) weeks = job_elem.weeks or '' days = job_elem.days or '' hours = job_elem.hours or '' minutes = job_elem.minutes or '' seconds = job_elem.seconds or '' repeats = job_elem.repeats or '' ib_job = IntervalBasedJob(None, None, weeks, days, hours, minutes, seconds, repeats) job.interval_based = ib_job elif job_type == SCHEDULER.JOB_TYPE.CRON_STYLE: cron_definition = job_elem.cron_definition or '' definition_text = _cron_style_job_def( req.zato.user_profile, start_date, cron_definition) cs_job = CronStyleJob(None, None, cron_definition) job.cron_style = cs_job else: msg = 'Unrecognized job type, name:[{0}], type:[{1}]'.format( name, job_type) logger.error(msg) raise ZatoException(msg) job.definition_text = definition_text jobs.append(job) else: logger.info('No jobs found, response:[{}]'.format(response)) if req.method == 'POST': action = req.POST.get('zato_action', '') if not action: msg = 'req.POST contains no [zato_action] parameter.' logger.error(msg) return HttpResponseServerError(msg) job_type = req.POST.get('job_type', '') if action != 'execute' and not job_type: msg = 'req.POST contains no [job_type] parameter.' logger.error(msg) return HttpResponseServerError(msg) job_name = req.POST['{0}-{1}-name'.format(action, job_type)] # Try to match the action and a job type with an action handler.. handler_name = '_' + action if action != 'execute': handler_name += '_' + job_type handler = globals().get(handler_name) if not handler: msg = ('No handler found for action [{0}], job_type:[{1}], ' 'req.POST:[{2}], req.GET:[{3}].'.format( action, job_type, pprint(req.POST), pprint(req.GET))) logger.error(msg) return HttpResponseServerError(msg) # .. invoke the action handler. try: response = handler(req.zato.client, req.zato.user_profile, req.zato.cluster, req.POST) response = response if response else '' if response: response['message'] = _get_success_message( action, job_type, job_name) response = dumps(response) return HttpResponse(response, content_type='application/javascript') except Exception, e: msg = ('Could not invoke action [%s], job_type:[%s], e:[%s]' 'req.POST:[%s], req.GET:[%s]') % ( action, job_type, format_exc(), pprint( req.POST), pprint(req.GET)) logger.error(msg) return HttpResponseServerError(msg) return_data = { 'zato_clusters': req.zato.clusters, 'cluster_id': req.zato.cluster_id, 'choose_cluster_form': req.zato.choose_cluster_form, 'jobs': jobs, 'friendly_names': job_type_friendly_names.items(), 'create_one_time_form': OneTimeSchedulerJobForm(create_one_time_prefix, req), 'create_interval_based_form': IntervalBasedSchedulerJobForm(create_interval_based_prefix, req), 'create_cron_style_form': CronStyleSchedulerJobForm(create_cron_style_prefix, req), 'edit_one_time_form': OneTimeSchedulerJobForm(edit_one_time_prefix, req), 'edit_interval_based_form': IntervalBasedSchedulerJobForm(edit_interval_based_prefix, req), 'edit_cron_style_form': CronStyleSchedulerJobForm(edit_cron_style_prefix, req), 'sample_dt': get_sample_dt(req.zato.user_profile), } return_data.update(get_js_dt_format(req.zato.user_profile)) return TemplateResponse(req, 'zato/scheduler.html', return_data)
def index(req): try: jobs = [] # Build a list of schedulers for a given Zato cluster. if req.zato.cluster_id and req.method == 'GET': # We have a server to pick the schedulers from, try to invoke it now. response = req.zato.client.invoke('zato.scheduler.job.get-list', {'cluster_id': req.zato.cluster_id}) if response.has_data: for job_elem in response.data: id = job_elem.id name = job_elem.name is_active = job_elem.is_active job_type = job_elem.job_type start_date = job_elem.start_date service_name = job_elem.service_name extra = job_elem.extra job_type_friendly = job_type_friendly_names[job_type] job = Job(id, name, is_active, job_type, from_utc_to_user(start_date+'+00:00', req.zato.user_profile), extra, service_name=service_name, job_type_friendly=job_type_friendly) if job_type == SCHEDULER.JOB_TYPE.ONE_TIME: definition_text=_one_time_job_def(req.zato.user_profile, start_date) elif job_type == SCHEDULER.JOB_TYPE.INTERVAL_BASED: definition_text = _interval_based_job_def(req.zato.user_profile, _get_start_date(job_elem.start_date), job_elem.repeats, job_elem.weeks, job_elem.days, job_elem.hours, job_elem.minutes, job_elem.seconds) weeks = job_elem.weeks or '' days = job_elem.days or '' hours = job_elem.hours or '' minutes = job_elem.minutes or '' seconds = job_elem.seconds or '' repeats = job_elem.repeats or '' ib_job = IntervalBasedJob(None, None, weeks, days, hours, minutes, seconds, repeats) job.interval_based = ib_job elif job_type == SCHEDULER.JOB_TYPE.CRON_STYLE: cron_definition = job_elem.cron_definition or '' definition_text=_cron_style_job_def(req.zato.user_profile, start_date, cron_definition) cs_job = CronStyleJob(None, None, cron_definition) job.cron_style = cs_job else: msg = 'Unrecognized job type, name:[{0}], type:[{1}]'.format(name, job_type) logger.error(msg) raise ZatoException(msg) job.definition_text = definition_text jobs.append(job) else: logger.info('No jobs found, response:[{}]'.format(response)) if req.method == 'POST': action = req.POST.get('zato_action', '') if not action: msg = 'req.POST contains no [zato_action] parameter.' logger.error(msg) return HttpResponseServerError(msg) job_type = req.POST.get('job_type', '') if action != 'execute' and not job_type: msg = 'req.POST contains no [job_type] parameter.' logger.error(msg) return HttpResponseServerError(msg) job_name = req.POST['{0}-{1}-name'.format(action, job_type)] # Try to match the action and a job type with an action handler.. handler_name = '_' + action if action != 'execute': handler_name += '_' + job_type handler = globals().get(handler_name) if not handler: msg = ('No handler found for action [{0}], job_type:[{1}], ' 'req.POST:[{2}], req.GET:[{3}].'.format(action, job_type, pprint(req.POST), pprint(req.GET))) logger.error(msg) return HttpResponseServerError(msg) # .. invoke the action handler. try: response = handler(req.zato.client, req.zato.user_profile, req.zato.cluster, req.POST) response = response if response else '' if response: response['message'] = _get_success_message(action, job_type, job_name) response = dumps(response) return HttpResponse(response, mimetype='application/javascript') except Exception, e: msg = ('Could not invoke action [%s], job_type:[%s], e:[%s]' 'req.POST:[%s], req.GET:[%s]') % (action, job_type, format_exc(), pprint(req.POST), pprint(req.GET)) logger.error(msg) return HttpResponseServerError(msg) return_data = {'zato_clusters':req.zato.clusters, 'cluster_id':req.zato.cluster_id, 'choose_cluster_form':req.zato.choose_cluster_form, 'jobs':jobs, 'friendly_names':job_type_friendly_names.items(), 'create_one_time_form':OneTimeSchedulerJobForm(create_one_time_prefix, req), 'create_interval_based_form':IntervalBasedSchedulerJobForm(create_interval_based_prefix, req), 'create_cron_style_form':CronStyleSchedulerJobForm(create_cron_style_prefix, req), 'edit_one_time_form':OneTimeSchedulerJobForm(edit_one_time_prefix, req), 'edit_interval_based_form':IntervalBasedSchedulerJobForm(edit_interval_based_prefix, req), 'edit_cron_style_form':CronStyleSchedulerJobForm(edit_cron_style_prefix, req), 'sample_dt': get_sample_dt(req.zato.user_profile), } return_data.update(get_js_dt_format(req.zato.user_profile)) return TemplateResponse(req, 'zato/scheduler.html', return_data)