Ejemplo n.º 1
0
 def process_operating_request(self, req):
     """
     process ToCancel/ToSuspend/ToResume/ToExpire request
     """
     try:
         ret_req = self.process_operating_request_real(req)
     except Exception as ex:
         self.logger.error(ex)
         self.logger.error(traceback.format_exc())
         ret_req = {'request_id': req['request_id'],
                    'parameters': {'status': RequestStatus.Failed,
                                   'locking': RequestLocking.Idle,
                                   'errors': {'msg': truncate_string('%s: %s' % (ex, traceback.format_exc()), length=800)}}}
     return ret_req
Ejemplo n.º 2
0
 def process_running_request(self, req):
     """
     process running request
     """
     try:
         if self.release_helper:
             self.release_inputs(req['request_id'])
         ret_req = self.process_running_request_real(req)
     except Exception as ex:
         self.logger.error(ex)
         self.logger.error(traceback.format_exc())
         ret_req = {'request_id': req['request_id'],
                    'parameters': {'status': RequestStatus.Failed,
                                   'locking': RequestLocking.Idle,
                                   'errors': {'msg': truncate_string('%s: %s' % (ex, traceback.format_exc()), length=800)}}}
     return ret_req
Ejemplo n.º 3
0
 def process_running_request_message(self, req, messages):
     """
     process running request message
     """
     try:
         self.logger.info("process_running_request_message: request_id: %s, messages: %s" % (req['request_id'], str(messages) if messages else messages))
         msg = messages[0]
         message = messages[0]['msg_content']
         if message['command'] == 'update_request':
             parameters_temp = message['parameters']
             parameters = {}
             if 'status' not in parameters_temp or parameters_temp['status'] not in [RequestStatus.ToCancel, RequestStatus.ToSuspend, RequestStatus.ToResume]:
                 self.logger.error("process_running_request_message: message %s parameters cannot be accepted: %s" % (msg['msg_id'], parameters_temp))
             else:
                 parameters['status'] = parameters_temp['status']
             parameters['locking'] = RequestLocking.Idle
             ret_req = {'request_id': req['request_id'],
                        'parameters': parameters,
                        'update_messages': [{'msg_id': msg['msg_id'], 'status': MessageStatus.Delivered}]
                        }
         elif message['command'] == 'update_processing':
             parameters = message['parameters']
             update_processing_messages = self.get_update_processing_messages(msg['msg_id'], req['request_id'], parameters)
             ret_req = {'request_id': req['request_id'],
                        'parameters': {'locking': RequestLocking.Idle},
                        'new_messages': update_processing_messages,
                        'update_messages': [{'msg_id': msg['msg_id'], 'status': MessageStatus.Delivered}]
                        }
         else:
             self.logger.error("Unknown message: %s" % str(msg))
             ret_req = {'request_id': req['request_id'],
                        'parameters': {'locking': RequestLocking.Idle},
                        'update_messages': [{'msg_id': msg['msg_id'], 'status': MessageStatus.Failed}]
                        }
     except Exception as ex:
         self.logger.error(ex)
         self.logger.error(traceback.format_exc())
         ret_req = {'request_id': req['request_id'],
                    'parameters': {'status': RequestStatus.Failed,
                                   'locking': RequestLocking.Idle,
                                   'errors': {'msg': truncate_string('%s: %s' % (ex, traceback.format_exc()), length=800)}}}
     return ret_req
Ejemplo n.º 4
0
    def process_new_request(self, req):
        try:
            self.logger.info("Processing request(%s)" % (req['request_id']))
            workflow = req['request_metadata']['workflow']

            # wf = workflow.copy()
            wf = workflow
            works = wf.get_new_works()
            transforms = []
            for work in works:
                # new_work = work.copy()
                new_work = work
                new_work.add_proxy(wf.get_proxy())
                # new_work.set_request_id(req['request_id'])
                # new_work.create_processing()

                transform = self.generate_transform(req, work)
                transforms.append(transform)
            self.logger.debug("Processing request(%s): new transforms: %s" % (req['request_id'],
                                                                              str(transforms)))
            # processing_metadata = req['processing_metadata']
            # processing_metadata = {'workflow_data': wf.get_running_data()}

            ret_req = {'request_id': req['request_id'],
                       'parameters': {'status': RequestStatus.Transforming,
                                      'locking': RequestLocking.Idle,
                                      'next_poll_at': datetime.datetime.utcnow() + datetime.timedelta(seconds=self.poll_time_period),
                                      # 'processing_metadata': processing_metadata,
                                      'request_metadata': req['request_metadata']},
                       'new_transforms': transforms}
        except Exception as ex:
            self.logger.error(ex)
            self.logger.error(traceback.format_exc())
            ret_req = {'request_id': req['request_id'],
                       'parameters': {'status': RequestStatus.Failed,
                                      'locking': RequestLocking.Idle,
                                      'errors': {'msg': truncate_string('%s: %s' % (ex, traceback.format_exc()), length=800)}}}
        return ret_req
Ejemplo n.º 5
0
    def process_running_request_real(self, req):
        """
        process running request
        """
        self.logger.info("process_running_request: request_id: %s" % req['request_id'])
        wf = req['request_metadata']['workflow']

        # current works
        works = wf.get_all_works()
        # print(works)
        for work in works:
            # print(work.get_work_id())
            tf = core_transforms.get_transform(transform_id=work.get_work_id())
            if tf:
                transform_work = tf['transform_metadata']['work']
                # work_status = WorkStatus(tf['status'].value)
                # work.set_status(work_status)
                work.sync_work_data(status=tf['status'], substatus=tf['substatus'], work=transform_work)
        wf.refresh_works()

        new_transforms = []
        if req['status'] in [RequestStatus.Transforming]:
            # new works
            works = wf.get_new_works()
            for work in works:
                # new_work = work.copy()
                new_work = work
                new_work.add_proxy(wf.get_proxy())
                new_transform = self.generate_transform(req, new_work)
                new_transforms.append(new_transform)
            self.logger.debug("Processing request(%s): new transforms: %s" % (req['request_id'], str(new_transforms)))

        is_operation = False
        if wf.is_terminated():
            if wf.is_finished():
                req_status = RequestStatus.Finished
            elif wf.is_subfinished():
                req_status = RequestStatus.SubFinished
            elif wf.is_expired():
                req_status = RequestStatus.Expired
            elif wf.is_failed():
                req_status = RequestStatus.Failed
            elif wf.is_cancelled():
                req_status = RequestStatus.Cancelled
            elif wf.is_suspended():
                req_status = RequestStatus.Suspended
            else:
                req_status = RequestStatus.Failed
            req_msg = wf.get_terminated_msg()
        else:
            req_msg = None
            if req['status'] in [RequestStatus.ToSuspend, RequestStatus.Suspending]:
                req_status = RequestStatus.Suspending
                is_operation = True
            elif req['status'] in [RequestStatus.ToCancel, RequestStatus.Cancelling]:
                req_status = RequestStatus.Cancelling
                is_operation = True
            elif wf.is_to_expire(req['expired_at'], self.pending_time, request_id=req['request_id']):
                wf.expired = True
                req_status = RequestStatus.ToExpire
                is_operation = True
                req_msg = "Workflow expired"
            else:
                req_status = RequestStatus.Transforming

        # processing_metadata['workflow_data'] = wf.get_running_data()
        if not is_operation:
            next_poll_at = datetime.datetime.utcnow() + datetime.timedelta(seconds=self.poll_time_period)
        else:
            next_poll_at = datetime.datetime.utcnow() + datetime.timedelta(seconds=self.poll_operation_time_period)

        parameters = {'status': req_status,
                      'locking': RequestLocking.Idle,
                      'next_poll_at': next_poll_at,
                      'request_metadata': req['request_metadata'],
                      'errors': {'msg': truncate_string(req_msg, 800)}}

        new_messages = []
        if req_status == RequestStatus.ToExpire:
            # parameters['substatus'] = req_status
            new_message = self.get_message_for_update_request(req, req_status)
            new_messages.append(new_message)

        ret = {'request_id': req['request_id'],
               'parameters': parameters,
               'new_messages': new_messages,
               'new_transforms': new_transforms}   # 'update_transforms': update_transforms}
        return ret