Exemple #1
0
    def run(self):
        action_context = self.dart.engine_action_checkout(
            os.environ.get('DART_ACTION_ID'))
        action = action_context.action
        datastore = action_context.datastore

        state = ActionResultState.SUCCESS
        error_message = None
        try:
            action_type_name = action.data.action_type_name
            _logger.info('**** ElasticsearchEngine.run_action: %s',
                         action_type_name)
            assert action_type_name in self._action_handlers, 'unsupported action: %s' % action_type_name
            handler = self._action_handlers[action_type_name]
            handler(self, datastore, action)

        except Exception as e:
            state = ActionResultState.FAILURE
            error_message = '{m}\r\r\r{t}'.format(
                m=str(e.message),
                t=traceback.format_exc(),
            )

        finally:
            self.dart.engine_action_checkin(action.id,
                                            ActionResult(state, error_message))
            self.publish_sns_message(action, error_message, state)
Exemple #2
0
    def run(self):
        action_context = self.dart.engine_action_checkout(
            os.environ.get('DART_ACTION_ID'))
        action = action_context.action
        datastore = action_context.datastore

        state = ActionResultState.SUCCESS
        error_message = None
        try:
            sleep_seconds = datastore.data.args['action_sleep_time_in_seconds']
            _logger.info('sleeping for %s seconds...' % sleep_seconds)
            time.sleep(sleep_seconds)

            if action.data.action_type_name == NoOpActionTypes.action_that_fails.name:
                state = ActionResultState.FAILURE
                error_message = '%s failed as expected' % NoOpActionTypes.action_that_fails.name

            if action.data.action_type_name == NoOpActionTypes.consume_subscription.name:
                subscription_elements = self.dart.get_subscription_elements(
                    action.id)
                _logger.info('consuming subscription, size = %s' %
                             len(list(subscription_elements)))

        except Exception as e:
            state = ActionResultState.FAILURE
            error_message = e.message + '\n\n\n' + traceback.format_exc()

        finally:
            self.dart.engine_action_checkin(action.id,
                                            ActionResult(state, error_message))
Exemple #3
0
    def run(self):
        action_context = self.dart.engine_action_checkout(
            os.environ.get('DART_ACTION_ID'))
        action = action_context.action
        datastore = action_context.datastore

        state = ActionResultState.SUCCESS
        consume_subscription_state = None
        error_message = None
        try:
            action_type_name = action.data.action_type_name
            assert action_type_name in self._action_handlers, 'unsupported action: %s' % action_type_name
            handler = self._action_handlers[action_type_name]
            handler(self, datastore, action)

        except ActionFailedButConsumeSuccessfulException as e:
            state = ActionResultState.FAILURE
            consume_subscription_state = ConsumeSubscriptionResultState.SUCCESS
            error_message = e.message + '\n\n\n' + traceback.format_exc()

        except Exception as e:
            state = ActionResultState.FAILURE
            error_message = e.message + '\n\n\n' + traceback.format_exc()

        finally:
            self.dart.engine_action_checkin(
                action.id,
                ActionResult(state, error_message, consume_subscription_state))
Exemple #4
0
def action_checkin(action):
    """ :type action: dart.model.action.Action """
    results = validate_engine_action(action, ActionState.RUNNING)
    # (error_response, error_response_code, headers)
    if len(results) == 3:
        return results

    action_result = ActionResult.from_dict(request.get_json())
    assert isinstance(action_result, ActionResult)
    action_state = ActionState.COMPLETED if action_result.state == ActionResultState.SUCCESS else ActionState.FAILED
    action = workflow_service().action_checkin(action, action_state, action_result.consume_subscription_state)

    error_message = action.data.error_message
    if action_result.state == ActionResultState.FAILURE:
        error_message = action_result.error_message
    trigger_proxy().complete_action(action.id, action_state, error_message)
    return {'results': 'OK'}
Exemple #5
0
def action_checkin(action):
    """ :type action: dart.model.action.Action """
    results = validate_engine_action(action, ActionState.RUNNING)
    # (error_response, error_response_code, headers)
    if len(results) == 3:
        return results

    action_result = ActionResult.from_dict(request.get_json())
    assert isinstance(action_result, ActionResult)
    action_state = ActionState.COMPLETED if action_result.state == ActionResultState.SUCCESS else ActionState.FAILED
    action = workflow_service().action_checkin(action, action_state, action_result.consume_subscription_state)

    error_message = action.data.error_message
    if action_result.state == ActionResultState.FAILURE:
        error_message = action_result.error_message
    trigger_proxy().complete_action(action.id, action_state, error_message)
    return {'results': 'OK'}
Exemple #6
0
    def run(self):
        action_context = self.dart.engine_action_checkout(os.environ.get('DART_ACTION_ID'))
        action = action_context.action
        datastore = action_context.datastore

        state = ActionResultState.SUCCESS
        error_message = None
        try:
            action_type_name = action.data.action_type_name
            _logger.info("*** S3Engine.run_action: %s", action_type_name)
            assert action_type_name in self._action_handlers, 'unsupported action: %s' % action_type_name
            handler = self._action_handlers[action_type_name]
            handler(self, datastore, action)

        except Exception as e:
            state = ActionResultState.FAILURE
            error_message = e.message + '\n\n\n' + traceback.format_exc()

        finally:
            self.dart.engine_action_checkin(action.id, ActionResult(state, error_message))