def delete_ci_task(request, task_id): ci_task = CITask.objects.get(int(task_id)) CITaskConfigService.delete_config(ci_task.TaskConfig) CITaskHistoryService.clean_all_history(task_id, True) ci_task.IsActive = 0 ci_task.save() CITaskService.log_delete_activity(request.user, ci_task)
def post(self, request, *args, **kwargs): task_id = int(self.kwargs['task_id']) config_stages = request.data.get('config_stages', None) if config_stages is not None: for stage in config_stages: temp_serializer = self.get_serializer(data=stage) temp_serializer.is_valid() temp_serializer._saving_instances = False instance = CITaskConfigService.task_stage(stage.get('id')) instance = temp_serializer.recursive_save( temp_serializer.validated_data, instance) instance.save() for step in stage.get('steps', []): temp_serializer = ci_step_serializer.CITaskStepSerializer( data=step) temp_serializer.is_valid() temp_serializer._saving_instances = False instance = CITaskConfigService.task_step(step.get('id')) instance = temp_serializer.recursive_save( temp_serializer.validated_data, instance) instance.save() parameter_groups = CITaskParameterService.task_parameter_list( task_id) for group in parameter_groups: CITaskParameterService.save_step_settings(str(group.id)) return Response(config_stages, status=status.HTTP_201_CREATED)
def delete(self, request, *args, **kwargs): stage_id = self.kwargs['stage_id'] CITaskConfigService.delete_steps(stage_id) stage = CITaskConfigService.task_stage(stage_id) parameter_groups = CITaskParameterService.task_parameter_list( stage.task_id) for group in parameter_groups: CITaskParameterService.save_step_settings(str(group.id)) return self.destroy(request, *args, **kwargs)
def get(self, request, *args, **kwargs): result = dict() task_id = int(self.kwargs['task_id']) default_stage = CITaskConfigService.task_default_sage(task_id) default_stage_serializer = ci_serializer.CITaskDefaultStageSerializer( instance=default_stage) queryset = CITaskConfigService.task_stage_list(task_id) serializer = self.get_serializer(queryset, many=True) result['base_info'] = default_stage_serializer.data result['config_stages'] = serializer.data return Response(result)
def copy_ci_task(validate_data, user): task_id = int(validate_data.get('CopyTaskID')) ci_task = CITask.objects.get(int(task_id)) ci_task.TaskName = validate_data.get('TaskName') ci_task.Project = validate_data.get('Project') ci_task.BuildVersion = 0 ci_task.id = None ci_task.Creator = user.id ci_task.save() ci_task.save() CITaskParameterService.copy_parameter_group_form_task( task_id, ci_task.id) CITaskConfigService.copy_task_stage(task_id, ci_task.id) CITaskConfigService.copy_default_stage(task_id, ci_task.id) CITaskService.log_create_activity(user, ci_task) return ci_task
def save_stage_history(task_queue, task_id, history_id): task_stages = CITaskConfigService.task_stage_list(task_id) for stage in task_stages: stage_history = CITaskStageHistory() stage_history.TQUUID = task_queue.TaskUUID stage_history.TaskID = stage.task_id stage_history.StageID = str(stage.id) stage_history.TaskHistoryID = history_id stage_history.Status = 0 stage_history.save()
def is_last_stage(self, obj): result = False task_stages = CITaskConfigService.task_stage_list(obj.TaskID) try: stage_length = len(task_stages) last_stage = task_stages[stage_length - 1] if str(last_stage.id) == obj.StageID: result = True except Exception as ex: SimpleLogger.exception(ex) return result
def create_ci_task(validate_data, user): task_type = int(validate_data.get('TaskType')) ci_task = CITask() if task_type: ci_task = CITask() ci_task = CITaskService.init_ci_task(validate_data, ci_task) ci_task.IsActive = 1 ci_task.Creator = user.id ci_task.TaskConfig = CITaskConfigService.create_config() ci_task.save() else: ci_task = CITaskService.copy_ci_task(validate_data, user) CITaskService.log_create_activity(user, ci_task) return ci_task
def post(self, request, *args, **kwargs): stage_id = self.kwargs.get('stage_id', None) stage = CITaskConfigService.task_stage(stage_id) serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) self.perform_create(serializer) headers = self.get_success_headers(serializer.data) parameter_groups = CITaskParameterService.task_parameter_list( stage.task_id) for group in parameter_groups: CITaskParameterService.save_step_settings(str(group.id)) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
def get_log_content(output,show_content): temp_output = dict() temp_output["id"] = output.id task_step = CITaskConfigService.task_step(output.StepID) if task_step: temp_output["step_name"] = str(task_step.step_config["step_name"]) + " " + str(task_step.purpose_name) else: temp_output["step_name"] = "--" log_file = FileInfo.objects.get(output.ProductID) if (log_file is not None and log_file.FileSize<512) or show_content: contents = CITaskHistoryService.get_big_build_log(output.ProductID) c = contents.read() log_content = c.decode('utf-8').replace("base", "") log_content = CITaskHistoryService.format_build_log(log_content) temp_output["log_content"] = log_content temp_output["show_content"] = True else: temp_output["log_content"] = "日志内容较多,请手动加载" temp_output["show_content"] = False return temp_output
def get_step_name(self,obj): result = "--" task_step = CITaskConfigService.task_step(obj.StepID) if task_step: result = str(task_step.step_config["step_name"])+" "+str(task_step.purpose_name) return result
def save_task_config(request, ci_taskid): ci_task = CITask.objects.get(int(ci_taskid)) CITaskConfigService.save_task_config(request, ci_task) CITaskService.log_change_activity(request.user, ci_task)
def get_AgentFilterType(self, obj): result = 1 default_stage = CITaskConfigService.task_default_sage(obj.id) if default_stage: result = default_stage.agent_filter.filter_type return result
def get_step_name(self,step_id): result = '' task_step = CITaskConfigService.task_step(step_id) if task_step and task_step.purpose_name.strip(): result = task_step.purpose_name return result
def copy_task(request): result=CITaskConfigService.copy_config("586b63f56a3c277a1fb4451f") return HttpResponse(result)
def get_queryset(self): task_id = self.kwargs['task_id'] queryset = CITaskConfigService.task_stage_list(task_id) return queryset
def get_object(self): result = None step_id = self.kwargs.get('step_id', None) if step_id is not None: result = CITaskConfigService.task_step(step_id) return result
def get_AgentTags(self, obj): result = list() default_stage = CITaskConfigService.task_default_sage(obj.id) if default_stage: result = default_stage.agent_filter.agent_tags return result
def __init__(self, config_id): ''' Constructor ''' self.ci_task_config_dict = CITaskConfigService.get_ci_task_config( config_id)
def get_object(self): stage_id = self.kwargs['stage_id'] return CITaskConfigService.task_stage(stage_id)
def get_task_config(request,task_id): ''' index page''' task_config=CITaskConfigService.get_ci_task_config_by_taskid(task_id) json_encoder=JSONEncoder() return HttpResponse(json_encoder.encode(str(task_config)))
def get_AgentID(self, obj): result = 0 default_stage = CITaskConfigService.task_default_sage(obj.id) if default_stage: result = default_stage.agent_filter.agent_id return result
def destroy(self, request, *args, **kwargs): instance = self.get_object() self.perform_destroy(instance) CITaskConfigService.delete_task_stage(instance.id) return Response(status=status.HTTP_204_NO_CONTENT)
def get_StageName(self,obj): result = "" stage = CITaskConfigService.task_stage(obj.StageID) if stage is not None: result = stage.stage_title return result