Пример #1
0
def print_events(app_name, env_name, follow, platform_arn=None):
    if follow:
        follow_events(app_name, env_name, platform_arn)
    else:
        events = elasticbeanstalk.get_new_events(app_name,
                                                 env_name,
                                                 None,
                                                 platform_arn=platform_arn)

        data = []
        for event in reversed(events):
            data.append(commonops.get_event_string(event, long_format=True))
        io.echo_with_pager(os.linesep.join(data))
Пример #2
0
def follow_events(app_name, env_name, platform_arn=None):
    last_time = None
    streamer = io.get_event_streamer()
    try:
        while True:
            events = elasticbeanstalk.get_new_events(app_name,
                                                     env_name,
                                                     None,
                                                     platform_arn=platform_arn,
                                                     last_event_time=last_time)

            for event in reversed(events):
                message = commonops.get_event_string(event, long_format=True)
                streamer.stream_event(message)
                last_time = event.event_date

            _sleep()
    except EndOfTestError:
        pass
    finally:
        streamer.end_stream()
Пример #3
0
def wait_for_success_events(request_id, timeout_in_minutes=None,
                            sleep_time=5, stream_events=True, can_abort=False,
                            streamer=None, app_name=None, env_name=None, version_label=None,
                            platform_arn=None, timeout_error_message=None):
    if timeout_in_minutes == 0:
        return
    if timeout_in_minutes is None:
        timeout_in_minutes = 10

    start = datetime.utcnow()
    timediff = timedelta(seconds=timeout_in_minutes * 60)

    last_time = start

    if streamer is None:
        streamer = io.get_event_streamer()

    if can_abort:
        streamer.prompt += strings['events.abortmessage']

    events = []

    safe_to_quit = True
    if version_label is not None and request_id is None:
        safe_to_quit = False

    try:
        if request_id:
            while not events:
                events = elasticbeanstalk.get_new_events(
                    app_name,
                    env_name,
                    request_id,
                    last_event_time=None,
                    platform_arn=platform_arn,
                    version_label=version_label
                )

                if len(events) > 0:
                    event = events[-1]
                    app_name = event.app_name
                    env_name = event.environment_name

                    if stream_events:
                        streamer.stream_event(
                            get_event_string(
                                event,
                                long_format=True
                            ),
                            safe_to_quit=safe_to_quit
                        )

                    _raise_if_error_event(event.message)
                    if _is_success_event(event.message):
                        return
                    last_time = event.event_date
                else:
                    _sleep(sleep_time)

        while not _timeout_reached(start, timediff):
            _sleep(sleep_time)

            events = elasticbeanstalk.get_new_events(
                app_name,
                env_name,
                request_id,
                last_event_time=last_time,
                platform_arn=platform_arn,
                version_label=version_label
            )

            if events:
                events = filter_events(
                    events,
                    env_name=env_name,
                    request_id=request_id,
                    version_label=version_label
                )

            for event in reversed(events):
                if stream_events:
                    streamer.stream_event(
                        get_event_string(
                            event,
                            long_format=True
                        ),
                        safe_to_quit=safe_to_quit
                    )
                    last_time = event.event_date

                _raise_if_error_event(event.message)
                if _is_success_event(event.message):
                    return
    finally:
        streamer.end_stream()

    if not timeout_error_message:
        timeout_error_message = strings['timeout.error'].format(timeout_in_minutes=timeout_in_minutes)

    raise TimeoutError(timeout_error_message)
Пример #4
0
def wait_for_compose_events(request_id, app_name, grouped_envs, timeout_in_minutes=None,
                            sleep_time=5, stream_events=True,
                            can_abort=False):
    if timeout_in_minutes == 0:
        return
    if timeout_in_minutes is None:
        timeout_in_minutes = 15

    start = datetime.utcnow()
    timediff = timedelta(seconds=timeout_in_minutes * 60)

    last_times = []
    events_matrix = []
    successes = []

    last_time_compose = datetime.utcnow()
    compose_events = []

    for i in range(len(grouped_envs)):
        last_times.append(datetime.utcnow())
        events_matrix.append([])
        successes.append(False)

    streamer = io.get_event_streamer()
    if can_abort:
        streamer.prompt += strings['events.abortmessage']

    try:
        while not _timeout_reached(start, timediff):
            if all(successes):
                return

            compose_events = elasticbeanstalk.get_new_events(app_name=app_name,
                                                             env_name=None,
                                                             request_id=request_id,
                                                             last_event_time=last_time_compose)
            for event in reversed(compose_events):
                if stream_events:
                    streamer.stream_event(get_compose_event_string(event))
                    last_time_compose = event.event_date

            for index in range(len(grouped_envs)):
                if successes[index]:
                    continue

                _sleep(sleep_time)

                events_matrix[index] = elasticbeanstalk.get_new_events(
                    app_name, grouped_envs[index], None,
                    last_event_time=last_times[index]
                )

                for event in reversed(events_matrix[index]):
                    if stream_events:
                        streamer.stream_event(get_env_event_string(event))
                        last_times[index] = event.event_date

                    if _is_success_event(event.message):
                        successes[index] = True
    finally:
        streamer.end_stream()

    io.log_error(strings['timeout.error'])
Пример #5
0
def wait_for_success_events(request_id,
                            timeout_in_minutes=None,
                            sleep_time=5,
                            stream_events=True,
                            can_abort=False,
                            streamer=None,
                            app_name=None,
                            env_name=None,
                            version_label=None,
                            platform_arn=None,
                            timeout_error_message=None):
    if timeout_in_minutes == 0:
        return
    if timeout_in_minutes is None:
        timeout_in_minutes = 10

    start = datetime.utcnow()
    timediff = timedelta(seconds=timeout_in_minutes * 60)

    # default to now, will update if request_id is provided
    last_time = start

    if streamer is None:
        streamer = io.get_event_streamer()

    if can_abort:
        streamer.prompt += strings['events.abortmessage']

    events = []

    # If the even stream is terminated before we finish streaming application version events we will not
    #   be able to continue the command so we must warn the user it is not safe to quit.
    safe_to_quit = True
    if version_label is not None and request_id is None:
        safe_to_quit = False

    try:
        # Get first event in order to get start time
        if request_id:
            while not events:
                events = elasticbeanstalk.get_new_events(
                    app_name,
                    env_name,
                    request_id,
                    last_event_time=None,
                    platform_arn=platform_arn,
                    version_label=version_label)

                if len(events) > 0:
                    event = events[-1]
                    app_name = event.app_name
                    env_name = event.environment_name

                    if stream_events:
                        streamer.stream_event(get_event_string(
                            event, long_format=True),
                                              safe_to_quit=safe_to_quit)

                    _raise_if_error_event(event.message)
                    if _is_success_event(event.message):
                        return
                    last_time = event.event_date
                else:
                    _sleep(sleep_time)

        # Get remaining events
        while not _timeout_reached(start, timediff):
            _sleep(sleep_time)

            events = elasticbeanstalk.get_new_events(
                app_name,
                env_name,
                request_id,
                last_event_time=last_time,
                platform_arn=platform_arn,
                version_label=version_label)

            if events:
                events = filter_events(events,
                                       env_name=env_name,
                                       request_id=request_id,
                                       version_label=version_label)

            for event in reversed(events):
                if stream_events:
                    streamer.stream_event(get_event_string(event,
                                                           long_format=True),
                                          safe_to_quit=safe_to_quit)
                    # We dont need to update last_time if we are not printing.
                    # This can solve timing issues
                    last_time = event.event_date

                _raise_if_error_event(event.message)
                if _is_success_event(event.message):
                    return
    finally:
        streamer.end_stream()
    # We have timed out

    if not timeout_error_message:
        timeout_error_message = strings['timeout.error'].format(
            timeout_in_minutes=timeout_in_minutes)

    raise TimeoutError(timeout_error_message)