def add_hello_failed_events(
        context_builder: ContextBuilder, id_: int, reason: str, details: str):
    context_builder.add_task_scheduled_event(name='Hello', id_=id_)
    context_builder.add_orchestrator_completed_event()
    context_builder.add_orchestrator_started_event()
    context_builder.add_task_failed_event(
        id_=id_, reason=reason, details=details)
def add_completed_event(context_builder: ContextBuilder, id_: int, name: str,
                        result):
    context_builder.add_task_scheduled_event(name=name, id_=id_)
    context_builder.add_orchestrator_completed_event()
    context_builder.add_orchestrator_started_event()
    context_builder.add_task_completed_event(id_=id_,
                                             result=json.dumps(result))
Пример #3
0
def add_failed_http_events(context_builder: ContextBuilder, id_: int,
                           reason: str, details: str):
    context_builder.add_task_scheduled_event(name=HTTP_ACTION_NAME, id_=id_)
    context_builder.add_orchestrator_completed_event()
    context_builder.add_orchestrator_started_event()
    context_builder.add_task_failed_event(id_=id_,
                                          reason=reason,
                                          details=details)
def add_hello_suborch_completed_events(context_builder: ContextBuilder,
                                       id_: int, result: str):
    context_builder.add_sub_orchestrator_started_event(
        name="HelloSubOrchestrator", id_=id_, input_="")
    context_builder.add_orchestrator_completed_event()
    context_builder.add_orchestrator_started_event()
    context_builder.add_sub_orchestrator_completed_event(result=result,
                                                         id_=id_)
Пример #5
0
def add_hello_suborch_failed_events(context_builder: ContextBuilder, id_: int,
                                    reason: str, details: str):
    context_builder.add_sub_orchestrator_started_event(
        name="HelloSubOrchestrator", id_=id_, input_="")
    context_builder.add_orchestrator_completed_event()
    context_builder.add_orchestrator_started_event()
    context_builder.add_sub_orchestrator_failed_event(id_=id_,
                                                      reason=reason,
                                                      details=details)
Пример #6
0
    def _fail_events(context: ContextBuilder,
                     id_counter: int) -> Tuple[ContextBuilder, int]:
        """Add event failed to the context.

        Parameters
        ----------
        context: ContextBuilder
            Orchestration context mock, to which we'll add the event completion events
        id_counter: int
            The current event counter

        Returns
        -------
        Tuple[ContextBuilder, int]:
            The updated context, the updated id_counter
        """
        context.add_orchestrator_started_event()
        for id_ in scheduled_ids:
            context.add_task_failed_event(id_=id_,
                                          reason=REASONS,
                                          details=DETAILS)
            id_counter += 1
        return context, id_counter
Пример #7
0
def add_call_entity_completed_events(
        context_builder: ContextBuilder, op: str, instance_id=str, input_=None):
    context_builder.add_event_sent_event(instance_id)
    context_builder.add_orchestrator_completed_event()
    context_builder.add_orchestrator_started_event()
    context_builder.add_event_raised_event(name="0000", id_=0, input_=input_, is_entity=True)
Пример #8
0
def add_timer_fired_events(context_builder: ContextBuilder, id_: int, timestamp: str,
        is_played: bool = True):
    fire_at: str = context_builder.add_timer_created_event(id_, timestamp)
    context_builder.add_orchestrator_completed_event()
    context_builder.add_orchestrator_started_event()
    context_builder.add_timer_fired_event(id_=id_, fire_at=fire_at, is_played=is_played)
Пример #9
0
def add_completed_http_events(context_builder: ContextBuilder, id_: int,
                              result: str):
    context_builder.add_task_scheduled_event(name=HTTP_ACTION_NAME, id_=id_)
    context_builder.add_orchestrator_completed_event()
    context_builder.add_orchestrator_started_event()
    context_builder.add_task_completed_event(id_=id_, result=result)
Пример #10
0
def add_hello_completed_events(context_builder: ContextBuilder, id_: int,
                               result: str):
    context_builder.add_task_scheduled_event(name='Hello', id_=id_)
    context_builder.add_orchestrator_completed_event()
    context_builder.add_orchestrator_started_event()
    context_builder.add_task_completed_event(id_=id_, result=result)
Пример #11
0
def get_context_with_retries(will_fail: bool = False) -> ContextBuilder:
    """Get a ContextBuilder whose history contains retried events.

    Parameters
    ----------
    will_fail: (bool, optional)
        If set to true, returns a context with a history where the orchestrator fails.
        If false, returns a context with a history where events fail but eventually complete.
        Defaults to False.

    Returns
    -------
    ContextBuilder:
        The context whose history contains the requested event sequence.
    """
    context = ContextBuilder()
    num_activities = len(CITIES)

    def _schedule_events(
            context: ContextBuilder,
            id_counter: int) -> Tuple[ContextBuilder, int, List[int]]:
        """Add scheduled events to the context.

        Parameters
        ----------
        context: ContextBuilder
            Orchestration context mock, to which we'll add the event completion events
        id_counter: int
            The current event counter

        Returns
        -------
        Tuple[ContextBuilder, int, List[int]]:
            The updated context, the updated counter, a list of event IDs for each scheduled event
        """
        scheduled_ids: List[int] = []
        for id_ in range(num_activities):
            scheduled_ids.append(id_)
            context.add_task_scheduled_event(name='Hello', id_=id_)
            id_counter += 1
        return context, id_counter, scheduled_ids

    def _fail_events(context: ContextBuilder,
                     id_counter: int) -> Tuple[ContextBuilder, int]:
        """Add event failed to the context.

        Parameters
        ----------
        context: ContextBuilder
            Orchestration context mock, to which we'll add the event completion events
        id_counter: int
            The current event counter

        Returns
        -------
        Tuple[ContextBuilder, int]:
            The updated context, the updated id_counter
        """
        context.add_orchestrator_started_event()
        for id_ in scheduled_ids:
            context.add_task_failed_event(id_=id_,
                                          reason=REASONS,
                                          details=DETAILS)
            id_counter += 1
        return context, id_counter

    def _schedule_timers(
            context: ContextBuilder,
            id_counter: int) -> Tuple[ContextBuilder, int, List[datetime]]:
        """Add timer created events to the context.

        Parameters
        ----------
        context: ContextBuilder
            Orchestration context mock, to which we'll add the event completion events
        id_counter: int
            The current event counter

        Returns
        -------
        Tuple[ContextBuilder, int, List[datetime]]:
            The updated context, the updated counter, a list of timer deadlines
        """
        deadlines: List[datetime] = []
        for _ in range(num_activities):
            deadlines.append(
                (id_counter, context.add_timer_created_event(id_counter)))
            id_counter += 1
        return context, id_counter, deadlines

    def _fire_timer(context: ContextBuilder, id_counter: int,
                    deadlines: List[datetime]) -> Tuple[ContextBuilder, int]:
        """Add timer fired events to the context.

        Parameters
        ----------
        context: ContextBuilder
            Orchestration context mock, to which we'll add the event completion events
        id_counter: int
            The current event counter
        deadlines: List[datetime]
            List of dates at which to fire the timers

        Returns
        -------
        Tuple[ContextBuilder, int]:
            The updated context, the updated id_counter
        """
        for id_, fire_at in deadlines:
            context.add_timer_fired_event(id_=id_, fire_at=fire_at)
            id_counter += 1
        return context, id_counter

    def _complete_event(context: ContextBuilder,
                        id_counter: int) -> Tuple[ContextBuilder, int]:
        """Add event / task completions to the context.

        Parameters
        ----------
        context: ContextBuilder
            Orchestration context mock, to which we'll add the event completion events
        id_counter: int
            The current event counter

        Returns
        -------
        Tuple[ContextBuilder, int]
            The updated context, the updated id_counter
        """
        for id_, city in zip(scheduled_ids, CITIES):
            result = f"\"{RESULT_PREFIX}{city}\""
            context.add_task_completed_event(id_=id_, result=result)
            id_counter += 1
        return context, id_counter

    id_counter = 0

    # Schedule the events
    context, id_counter, scheduled_ids = _schedule_events(context, id_counter)
    context.add_orchestrator_completed_event()

    # Record failures, schedule timers
    context, id_counter = _fail_events(context, id_counter)
    context, id_counter, deadlines = _schedule_timers(context, id_counter)
    context.add_orchestrator_completed_event()

    # Fire timers, re-schedule events
    context.add_orchestrator_started_event()
    context, id_counter = _fire_timer(context, id_counter, deadlines)
    context, id_counter, scheduled_ids = _schedule_events(context, id_counter)
    context.add_orchestrator_completed_event()

    context.add_orchestrator_started_event()

    # Either complete the event or, if we want all failed events, then
    # fail the events, schedule timer, and fire time.
    if will_fail:
        context, id_counter = _fail_events(context, id_counter)
        context, id_counter, deadlines = _schedule_timers(context, id_counter)
        context.add_orchestrator_completed_event()

        context.add_orchestrator_started_event()
        context, id_counter = _fire_timer(context, id_counter, deadlines)
    else:
        context, id_counter = _complete_event(context, id_counter)

    context.add_orchestrator_completed_event()
    return context
Пример #12
0
def add_retry_timer_events(context_builder: ContextBuilder, id_: int):
    fire_at = context_builder.add_timer_created_event(id_)
    context_builder.add_orchestrator_completed_event()
    context_builder.add_orchestrator_started_event()
    context_builder.add_timer_fired_event(id_=id_, fire_at=fire_at)