def get(self, request, *args, **kwargs): """ 获取工作流初始状态信息,包括状态详情以及允许的transition :param request: :param args: :param kwargs: :return: """ workflow_id = kwargs.get('workflow_id') request_data = request.GET # username = request_data.get('username', '') # 后续会根据username做必要的权限控制 username = request.META.get('HTTP_USERNAME') app_name = request.META.get('HTTP_APPNAME') from service.account.account_base_service import AccountBaseService # 判断是否有工作流的权限 app_permission, msg = AccountBaseService.app_workflow_permission_check( app_name, workflow_id) if not app_permission: return api_response( -1, 'APP:{} have no permission to get this workflow info'.format( app_name), '') if not (workflow_id and username): return api_response(-1, '请提供username', '') state_result, msg = WorkflowStateService.get_workflow_init_state( workflow_id) if state_result is not False: code, msg, data = 0, '', state_result else: code, msg, data = -1, msg, '' return api_response(code, msg, data)
def get(self, request, *args, **kwargs): """ 获取工作流拥有的state列表信息 :param request: :param args: :param kwargs: :return: """ workflow_id = kwargs.get('workflow_id') request_data = request.GET # username = request_data.get('username', '') # 后续会根据username做必要的权限控制 username = request.META.get('HTTP_USERNAME') search_value = request_data.get('search_value', '') per_page = int(request_data.get('per_page', 10)) if request_data.get( 'per_page', 10) else 10 page = int(request_data.get('page', 1)) if request_data.get('page', 1) else 1 # if not username: # return api_response(-1, '请提供username', '') result, msg = WorkflowStateService.get_workflow_states_serialize( workflow_id, per_page, page, search_value) if result is not False: data = dict(value=result, per_page=msg['per_page'], page=msg['page'], total=msg['total']) code, msg, = 0, '' else: code, data = -1, '' return api_response(code, msg, data)
def get(self, request, workflow_id, state_id): state, msg = WorkflowStateService.get_workflow_state_by_id(state_id) if state: result = WorkflowStateSerializer(state).data return format_response.JsonResponse(data=result, code=status.HTTP_200_OK) if state is None: return format_response.JsonResponse(data=[], code=status.HTTP_200_OK) if state is False: return format_response.JsonResponse( data='', code=status.HTTP_500_INTERNAL_SERVER_ERROR, msg=msg)
def get(self, request, workflow_id): states, msg = WorkflowStateService.get_workflow_states(workflow_id) if states is not False: workflow_state_serializer_list = [ WorkflowStateSerializer(state) for state in states ] workflow_state_serializer_list = [ workflow_state_serializer.data for workflow_state_serializer in workflow_state_serializer_list ] return format_response.JsonResponse( data=workflow_state_serializer_list, code=status.HTTP_200_OK) else: return format_response.JsonResponse( data='', code=status.HTTP_500_INTERNAL_SERVER_ERROR, msg=msg)
def delete(self, request, *args, **kwargs): """ 删除状态 :param request: :param args: :param kwargs: :return: """ app_name = request.META.get('HTTP_APPNAME') state_id = kwargs.get('state_id') result, msg = WorkflowStateService.del_workflow_state(state_id) if not result: code, msg, data = -1, msg, {} else: code, msg, data = 0, '', {'workflow_id': result} return api_response(code, msg, data)
def patch(self, request, *args, **kwargs): """ 编辑状态 :param request: :param args: :param kwargs: :return: """ json_str = request.body.decode('utf-8') if not json_str: return api_response(-1, 'post参数为空', {}) request_data_dict = json.loads(json_str) workflow_data = {} app_name = request.META.get('HTTP_APPNAME') username = request.META.get('HTTP_USERNAME') name = request_data_dict.get('name', '') sub_workflow_id = request_data_dict.get('sub_workflow_id', 0) is_hidden = request_data_dict.get('is_hidden', 0) order_id = int(request_data_dict.get('order_id', 0)) type_id = int(request_data_dict.get('type_id', 0)) remember_last_man_enable = int( request_data_dict.get('remember_last_man_enable', 0)) participant_type_id = int( request_data_dict.get('participant_type_id', 0)) participant = request_data_dict.get('participant', '') distribute_type_id = int(request_data_dict.get('distribute_type_id', 1)) state_field_str = request_data_dict.get('state_field_str', '') label = request_data_dict.get('label', '') workflow_id = kwargs.get('workflow_id') state_id = kwargs.get('state_id') result, msg = WorkflowStateService.edit_workflow_state( state_id, workflow_id, name, sub_workflow_id, is_hidden, order_id, type_id, remember_last_man_enable, participant_type_id, participant, distribute_type_id, state_field_str, label, username) if not result: code, msg, data = -1, msg, {} else: code, msg, data = 0, '', {'workflow_id': result} return api_response(code, msg, data)
def get(self, request, *args, **kwargs): """ 获取状态详情 :param request: :param args: :param kwargs: :return: """ state_id = kwargs.get('state_id') request_data = request.GET username = request_data.get('username', '') # 后续会根据username做必要的权限控制 if not username: return api_response(-1, '请提供username', '') result, msg = WorkflowStateService.get_restful_state_info_by_id(state_id) if result is not False: code, data = 0, result else: code, data = -1, '' return api_response(code, msg, data)
def get(self, request, *args, **kwargs): """ 获取工作流初始状态信息,包括状态详情以及允许的transition :param request: :param args: :param kwargs: :return: """ workflow_id = kwargs.get('workflow_id') request_data = request.GET username = request_data.get('username', '') # 后续会根据username做必要的权限控制 if not (workflow_id and username): return api_response(-1, '请提供workflow_id和username', '') state_result, msg = WorkflowStateService.get_workflow_init_state(workflow_id) if state_result is not False: code, msg, data = 0, '', state_result else: code, msg, data = -1, msg, '' return api_response(code, msg, data)
def get_transitions_serialize_by_workflow_id(cls, workflow_id, per_page=10, page=1, query_value=''): if not workflow_id: return False, 'except workflow_id but not provided' query_params = Q(workflow_id=workflow_id, is_deleted=False) if query_value: query_params &= Q(name__contains=query_value) workflow_transitions = Transition.objects.filter(query_params) paginator = Paginator(workflow_transitions, per_page) try: workflow_transitions_result_paginator = paginator.page(page) except PageNotAnInteger: workflow_transitions_result_paginator = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results workflow_transitions_result_paginator = paginator.page( paginator.num_pages) workflow_transitions_object_list = workflow_transitions_result_paginator.object_list workflow_transitions_restful_list = [] for workflow_transitions_object in workflow_transitions_object_list: source_state_info = {} destination_state_info = {} from service.workflow.workflow_state_service import WorkflowStateService source_state_obj, msg = WorkflowStateService.get_workflow_state_by_id( workflow_transitions_object.source_state_id) destination_state_obj, msg = WorkflowStateService.get_workflow_state_by_id( workflow_transitions_object.destination_state_id) if source_state_obj: source_state_info['name'] = source_state_obj.name source_state_info['id'] = source_state_obj.id if destination_state_obj: destination_state_info['name'] = destination_state_obj.name destination_state_info['id'] = destination_state_obj.id result_dict = dict( id=workflow_transitions_object.id, name=workflow_transitions_object.name, creator=workflow_transitions_object.creator, source_state_id=workflow_transitions_object.source_state_id, source_state_info=source_state_info, destination_state_info=destination_state_info, destination_state_id=workflow_transitions_object. destination_state_id, transition_type_id=workflow_transitions_object. transition_type_id, timer=workflow_transitions_object.timer, condition_expression=workflow_transitions_object. condition_expression, attribute_type_id=workflow_transitions_object. attribute_type_id, field_require_check=workflow_transitions_object. field_require_check, alert_enable=workflow_transitions_object.alert_enable, alert_text=workflow_transitions_object.alert_text, gmt_created=str(workflow_transitions_object.gmt_created)[:19]) workflow_transitions_restful_list.append(result_dict) return workflow_transitions_restful_list, dict(per_page=per_page, page=page, total=paginator.count)
ticket_mc = requests.request(method="GET", url=work_url + str(last_flow_log['ticket_id']) + '/', headers=headers).json() ticket_mc = ticket_mc['data']['value'] alarm_level_option = { "0": "未分类", "1": "信息", "2": "警告", "3": "一般严重", "4": "严重", "5": "灾难" } state, msg = WorkflowStateService.get_workflow_state_by_id( ticket_mc['state_id']) if state.name == '运维人员处理': project_id = ticket_mc['to_project']['id'] params = {'to_project': project_id} wechat_list = requests.request(method="GET", url=url, params=params, headers=headers).json() ip_addr = '' alarm_level = '' event_status = '' alarm_id = '' for i in ticket_mc['field_list']: if i['field_key'] == 'host_ip': ip_addr = i['field_value'] elif i['field_key'] == 'event_level':