本文整理汇总了Python中mbs.get_mbs函数的典型用法代码示例。如果您正苦于以下问题:Python get_mbs函数的具体用法?Python get_mbs怎么用?Python get_mbs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_mbs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tick
def tick(self):
try:
self._master.monitor_master()
except Exception, ex:
logger.exception("MbsMasterMonitor error")
get_mbs().notifications.send_event_notification("MbsMasterMonitor error",
str(ex), priority=NotificationPriority.CRITICAL)
示例2: _notify_on_past_due_scheduled_backups
def _notify_on_past_due_scheduled_backups(self):
"""
Send notifications for jobs that has been scheduled for a period
longer than min(half the frequency, 5 hours) of its plan.
If backup does not have a plan (i.e. one off)
then it will check after 60 seconds.
"""
# query for backups whose scheduled date is before current date minus
# than max starvation time
q = {
"state": State.SCHEDULED,
}
past_due_backup_infos = []
for backup in get_mbs().backup_collection.find_iter(q, no_cursor_timeout=True):
if self.is_backup_past_due(backup):
past_due_backup_infos.append("%s (%s)" % (str(backup.id), backup.source.get_source_info()))
if past_due_backup_infos:
msg = ("Backup(s) in SCHEDULED for too long: \n%s" % ", \n".join(past_due_backup_infos))
logger.info(msg)
logger.info("Sending a notification...")
sbj = PAST_DUE_ALERT_SUBJECT
get_mbs().notifications.send_notification(sbj, msg, notification_type=NotificationType.EVENT,
priority=NotificationPriority.CRITICAL)
self._alerting_on_past_due = True
elif self._alerting_on_past_due:
self._clear_past_due_alert()
示例3: schedule_backup_restore
def schedule_backup_restore(self, backup_id, destination_uri,tags=None,
no_index_restore=None, no_users_restore=None, no_roles_restore=None,
source_database_name=None):
backup = get_mbs().backup_collection.get_by_id(backup_id)
destination = build_backup_source(destination_uri)
logger.info("Scheduling a restore for backup '%s'" % backup.id)
restore = Restore()
restore.state = State.SCHEDULED
restore.source_backup = backup
restore.source_database_name = source_database_name
restore.strategy = backup.strategy
restore.strategy.no_index_restore = no_index_restore
restore.strategy.no_users_restore = no_users_restore
restore.strategy.no_roles_restore = no_roles_restore
restore.destination = destination
# resolve tags
tags = tags or restore.source_backup.tags
restore.tags = tags
rc = get_mbs().restore_collection
try:
self._resolve_task_tags(restore)
except Exception, ex:
self._task_failed_to_schedule(restore, rc, ex)
示例4: save_plan
def save_plan(self, plan):
try:
self.debug("Validating plan %s" % plan)
errors = plan.validate()
if errors:
err_msg = ("Plan %s is invalid."
"Please correct the following errors and then try"
" saving again.\n%s" % (plan, errors))
raise BackupSystemError(err_msg)
# set plan created date if its not set
if not plan.created_date:
plan.created_date = date_now()
is_new_plan = not plan.id
if is_new_plan:
self.info("Saving new plan: \n%s" % plan)
plan_doc = plan.to_document()
get_mbs().plan_collection.save_document(plan_doc)
plan.id = plan_doc["_id"]
self.info("Plan saved successfully")
else:
self.info("Updating plan: \n%s" % plan)
self.update_existing_plan(plan)
self.info("Plan updated successfully")
except Exception, e:
raise BackupSystemError("Error while saving plan %s. %s" %
(plan, e))
示例5: run_generator
def run_generator(self, dry_run=False):
try:
if dry_run:
logger.info("----- DRY RUN ------")
logger.info("Running plan generator '%s' " % self.name)
# remove expired plans
for plan in self.get_plans_to_remove():
if not dry_run:
self._backup_system.remove_plan(plan.id)
else:
logger.info("DRY RUN: remove plan '%s' " % plan.id)
# save new plans
for plan in self.get_plans_to_save():
try:
if not dry_run:
self._backup_system.save_plan(plan)
else:
logger.info("DRY RUN: save plan: %s" % plan)
except Exception, ex:
logger.exception("Error while saving plan %s" % plan)
get_mbs().notifications.send_event_notification("Error in saving plan for generator %s" %
self.name,
str(ex), priority=NotificationPriority.CRITICAL)
except Exception, ex:
logger.exception("Error in running plan generator %s" % self.name)
get_mbs().notifications.send_event_notification("Error in running plan generator %s" % self.name,
str(ex), priority=NotificationPriority.CRITICAL)
示例6: _send_audit_report
def _send_audit_report(self, auditor, report):
subject = ("%s Audit Report for %s" %
(auditor.name, datetime_to_string(report.audit_date)))
message = report.summary()
get_mbs().notifications.send_notification(subject, message,
notification_type="audit")
示例7: _save_plan_next_occurrence
def _save_plan_next_occurrence(self, plan):
q = {"_id": plan.id}
u = {
"$set": {
"nextOccurrence": plan.next_occurrence
}
}
get_mbs().plan_collection.update(spec=q, document=u)
示例8: create_backup_plan
def create_backup_plan(self, **kwargs):
try:
plan = BackupPlan()
plan.created_date = date_now()
plan.description = get_validate_arg(kwargs, "description",
expected_type=(str, unicode),
required=False)
plan.strategy = get_validate_arg(kwargs, "strategy",
expected_type=BackupStrategy)
plan.schedule = get_validate_arg(kwargs, "schedule",
expected_type=AbstractSchedule)
plan.source = get_validate_arg(kwargs, "source",
expected_type=BackupSource)
plan.target = get_validate_arg(kwargs, "target",
expected_type=BackupTarget)
plan.retention_policy = get_validate_arg(kwargs, "retention_policy",
expected_type=
RetentionPolicy,
required=False)
plan.priority = get_validate_arg(kwargs, "priority",
expected_type=(int, long,
float, complex),
required=False)
plan.secondary_targets = get_validate_arg(kwargs,
"secondary_targets",
expected_type=list,
required=False)
# tags
plan.tags = get_validate_arg(kwargs, "tags", expected_type=dict,
required=False)
plan_doc = plan.to_document()
get_mbs().plan_collection.save_document(plan_doc)
# set the backup plan id from the saved doc
plan.id = plan_doc["_id"]
self.info("Saved backup plan \n%s" % plan)
# process plan to set next occurrence
self._scheduler._process_plan(plan)
return plan
except Exception, e:
args_str = dict_to_str(kwargs)
msg = ("Failed to create plan. Args:\n %s" % args_str)
logger.error(msg)
logger.error(traceback.format_exc())
raise CreatePlanError(msg=msg, cause=e)
示例9: daily_audit_report
def daily_audit_report(self, audit_date):
logger.info("PlanScheduleAuditor: Generating %s audit report for '%s'"
% (TYPE_PLAN_AUDIT, datetime_to_string(audit_date)))
audit_end_date = date_plus_seconds(audit_date, 3600 * 24)
all_plans_report = PlanScheduleAuditReport()
all_plans_report.audit_date = audit_date
all_plans_report.audit_type = TYPE_PLAN_AUDIT
total_plans = 0
failed_plan_reports = []
all_warned_audits = []
total_warnings = 0
for plan in get_mbs().plan_collection.find_iter(no_cursor_timeout=True):
logger.info("PlanScheduleAuditor: Processing plan %s" % plan.id)
plan_report = self._create_plan_audit_report(plan, audit_date)
if plan_report.has_failures():
failed_plan_reports.append(plan_report)
if plan_report.has_warnings():
# only append to warned audits if report doesn't have failures
if not plan_report.has_failures():
all_warned_audits.extend(plan_report.warned_audits)
total_warnings += 1
total_plans += 1
total_failures = len(failed_plan_reports)
if failed_plan_reports:
all_plans_report.failed_audits = failed_plan_reports
if all_warned_audits:
all_plans_report.warned_audits = all_warned_audits
all_plans_report.total_audits = total_plans
all_plans_report.total_failures = total_failures
all_plans_report.total_success = total_plans - total_failures
all_plans_report.total_warnings = total_warnings
logger.info("PlanScheduleAuditor: Generated report:\n%s " %
all_plans_report)
# alert if failed audits are >= max allowed percent of total
if float(total_failures) / total_plans > self.max_allowed_failures_percentage:
subject = "%s Auditor Failure: Too many failures!!!" % self.name
msg = "There are %s failures out of %s which is > %s%%" % (total_failures, total_plans,
self.max_allowed_failures_percentage * 100)
logger.error(subject)
logger.error(msg)
get_mbs().notifications.send_event_notification(subject, msg, priority=NotificationPriority.CRITICAL)
else:
logger.info("NO ALERT for %s Auditor: There are %s failures out of %s which is < %s%%" %
(self.name,total_failures, total_plans, self.max_allowed_failures_percentage * 100))
return all_plans_report
示例10: tick
def tick(self):
try:
self._process_plans_considered_now(process_max_count=100)
except Exception, e:
logger.error("Caught an error: '%s'.\nStack Trace:\n%s" %
(e, traceback.format_exc()))
subject = "Plan Scheduler Error"
message = ("%s.\n\nStack Trace:\n%s" % (e, traceback.format_exc()))
get_mbs().notifications.send_error_notification(subject, message)
示例11: schedule_backup
def schedule_backup(self, **kwargs):
try:
backup = Backup()
backup.created_date = date_now()
backup.strategy = get_validate_arg(kwargs, "strategy",
expected_type=BackupStrategy)
backup.source = get_validate_arg(kwargs, "source", BackupSource)
backup.target = get_validate_arg(kwargs, "target", BackupTarget)
backup.priority = get_validate_arg(kwargs, "priority",
expected_type=(int, long,
float, complex),
required=False)
backup.plan_occurrence = \
get_validate_arg(kwargs, "plan_occurrence",
expected_type=datetime,
required=False)
backup.plan = get_validate_arg(kwargs, "plan",
expected_type=BackupPlan,
required=False)
backup.secondary_targets = get_validate_arg(kwargs,
"secondary_targets",
expected_type=list,
required=False)
backup.change_state(State.SCHEDULED)
# set tags
tags = get_validate_arg(kwargs, "tags", expected_type=dict,
required=False)
backup.tags = tags
bc = get_mbs().backup_collection
try:
# resolve tags
self._resolve_task_tags(backup)
except Exception, ex:
self._task_failed_to_schedule(backup, bc, ex)
self.set_custom_backup_props(backup)
backup_doc = backup.to_document()
get_mbs().backup_collection.save_document(backup_doc)
# set the backup id from the saved doc
backup.id = backup_doc["_id"]
self.info("Saved backup \n%s" % backup)
if backup.state == State.FAILED:
trigger_task_finished_event(backup, State.FAILED)
return backup
示例12: generate_audit_report
def generate_audit_report(self, auditor, date):
try:
report = auditor.daily_audit_report(date)
logger.info("GlobalAuditor: Saving audit report: \n%s" % report)
self._audit_collection.save_document(report.to_document())
# send audit report
self._send_audit_report(auditor, report)
except Exception, e:
sbj = "Auditor %s Error" % auditor.name
msg = "Auditor %s Error!.\n\nStack Trace:\n%s" % (auditor.name, traceback.format_exc())
get_mbs().notifications.send_error_notification(sbj, msg)
示例13: worker_crashed
def worker_crashed(self, worker):
# page immediately
subject = "Worker crashed for %s %s!" % (worker.task.type_name, worker.task.id)
errmsg = ("Worker crash detected! Worker (id %s, pid %s, %s"
" id '%s') finished with a non-zero exit code '%s'"
% (worker.id, worker.pid, worker.task.type_name, worker.task.id, worker.exit_code))
exception = EngineWorkerCrashedError(errmsg)
get_mbs().notifications.send_error_notification(subject, errmsg)
self.error(errmsg)
self._cleanup_worker_resources(worker)
worker.worker_fail(exception)
示例14: reschedule_restore
def reschedule_restore(self, restore, force=False):
"""
Reschedules the restore IF state is FAILED
"""
if restore.state != State.FAILED:
msg = ("Cannot reschedule restore ('%s', '%s'). Rescheduling is "
"only allowed for restores whose state is '%s'." %
(restore.id, restore.state, State.FAILED))
raise BackupSystemError(msg)
self.info("Rescheduling restore %s" % restore.id)
props = ["state", "tags"]
restore.state = State.SCHEDULED
rc = get_mbs().restore_collection
# if force is set then clear restore log
if force:
restore.logs = []
restore.try_count = 0
restore.engine_guid = None
props.extend(["logs", "tryCount", "engineGuid"])
rc.update_task(restore, properties=props,
event_name=EVENT_STATE_CHANGE,
message="Rescheduling")
示例15: update_backup
def update_backup(backup, properties=None, event_name=None,
event_type=EventType.INFO, message=None, details=None,
error_code=None):
bc = get_mbs().backup_collection
bc.update_task(backup, properties=properties, event_name=event_name,
event_type=event_type, message=message, details=details,
error_code=error_code,
w=1)