def after_check(): request_json = get_post_request_json(request) info_log(KEY_M_SHARED_STORAGE, "run report scheduler, scheduler id =" + str(request_json)) run_in_background(report_scheduler_services.run_scheduler_now, request_json, request.user) result = ResponseBuilder().get_data() return JsonResponse(data=result)
def parse_child_nodes(self, node): if string_filter(node.path, LATEST_VERSION_PARENT_FOLDER): latest_version = self.connect_obj.get_latest_version(node.path) info_log(self.LOG_CLASS, "latest_version:" + str(latest_version)) child_node_parser = DirNodeParseFilteredObject(self.connect_obj, node, latest_version) elif string_filter(node.path, LATEST_VERSION_GRAND_PARENT_FOLDER): child_node_parser = DirNodeParseLatestVersionParentObject(self.connect_obj, node) else: child_node_parser = DirNodeParseObject(self.connect_obj, node) child_node_parser.parse_nodes()
def parse_node(self, entry, index): node = NodeObject(entry.filename, self.parent_node.environment, self.parent_node, index, entry.st_mode) node.set_size(entry.st_size) node.set_modification_time(entry.st_mtime) node.node_hash_key = hash(node) self.parent_node.add_child_node_list(node) info_log(self.LOG_CLASS, "parse_node , index:" + str(node.index) + ", depth: " + str(node.depth) + ", path: " + node.path) return node
def after_check(): request_json = get_post_request_json(request) info_log(KEY_M_SHARED_STORAGE, "update report scheduler, request json =" + str(request_json)) scheduler_info = report_scheduler_services.update_scheduler( request_json, request.user, request.get_host()) info_data = SharedStorageReportSchedulerBuilder( request.user, scheduler_info).get_data() result = ResponseBuilder(data=info_data).get_data() return JsonResponse(data=result)
def get_path_list_dir(self, path): try: self.sftp.cwd(path) return self.sftp.listdir_attr() except FileNotFoundError as e: if no_such_file(e): raise e except socket.error: info_log(self.LOG_CLASS, "FTP reconnect, get_path_list_dir: " + path) self.connect() return self.get_path_list_dir(path)
def restart_schedulers(): schedulers = SharedStorageReportScheduler.objects.all() if len(schedulers) == 0: return info_log(LOG_CLASS, "restart shared storage report schedulers") for scheduler in schedulers: parser = DBReportSchedulerParser(scheduler) SharedStorageReportScheduler.objects.update_next_proceed_time( parser.task_id, parser.utc_time) add_task_to_scheduler(parser) info_log(LOG_CLASS, "restart success")
def get_path_file(self, file_path, save_path): try: self.sftp.get(file_path, localpath=save_path) f = open(save_path, 'r', encoding='utf-8') file_content = f.read() file_content = file_content.encode('utf-8').decode('utf-8-sig') file_content = file_content.strip() f.close() return file_content except FileNotFoundError as e: if no_such_file(e): raise e except socket.error: info_log(self.LOG_CLASS, "FTP reconnect, get_path_file: " + file_path) self.connect() return self.get_path_file(file_path, save_path)
def restart_schedulers(): try: schedulers = ReportSchedulerInfo.objects.all() if len(schedulers) == 0: return info_log("rulesetReportSchedulerService", "restart all schedulers") for scheduler in schedulers: country_list = scheduler.country_list.values(KEY_ID) mail_content_type_list = scheduler.mail_content_type_list.values( KEY_ID) parser = DBReportSchedulerParser(scheduler, country_list, mail_content_type_list) ReportSchedulerInfo.objects.update_next_proceed_time( parser.task_id, parser.utc_time) add_task_to_scheduler(parser) info_log("rulesetReportSchedulerService", "restart all success") except Exception as e: raise e
def restart_all_scheduler(): try: # clear zip and ruleset file scheduler clear_zip_ruleset_task = ClearRulesetArchivedFilesTask() clear_ruleset_task = ClearRulesetFilesTask() clear_compare_report_task = ClearCompareReportFilesTask() clear_ss_tmp_file_task = ClearTmpFilesTask() clear_ss_compare_result_task = ClearCompareResultTask() info_log(None, "restart clear scheduler") scheduler = CustomJobScheduler() scheduler.add_hours_job_now(clear_ruleset_task.run_task, 24) scheduler.add_hours_job_now(clear_zip_ruleset_task.run_task, 24) scheduler.add_hours_job_now(clear_compare_report_task.run_task, 24) scheduler.add_hours_job_now(clear_ss_tmp_file_task.run_task, 24) scheduler.add_hours_job_now(clear_ss_compare_result_task.run_task, 24) info_log(None, "restart clear scheduler success") report_scheduler.restart_schedulers() sync_scheduler.restart_schedulers() shared_storage_report_scheduler.restart_schedulers() except BaseException as e: error_log(traceback.format_exc()) raise e
def send_report_mail_with_attachment(country_name, base_env_name, compare_env_name, mail_content, receivers, attachment_path=None): current_time = timeUtil.get_format_current_time(YEAR_MONTH_DATE) subject = SEND_RULESET_COMPARE_RESULT_MAIL.get("title") subject = subject + " for " + country_name + " - " + base_env_name + " <> " + compare_env_name mail_sender = MailSender(SEND_RULESET_COMPARE_RESULT_MAIL) if attachment_path: file_name = current_time + "_" + base_env_name + "_" + compare_env_name + "_" + country_name + "_" + "compare_report.zip" mail_sender.add_attachment(attachment_path, file_name, "text") mail_sender.set_receiver(receivers) mail_sender.compose_msg(subject, None, mail_content) mail_sender.send() mail_sender.quit() info_log("ruleset report service", "send report mail success")