Exemplo n.º 1
0
def stop_runtime(bot_uuid: str):
    settings = ToolSettings()
    current_environment = settings.get_current_environment()
    robo = get_robo_client(current_environment)

    runtime = robo.assistants.runtimes.get(bot_uuid)
    assert_status_transition(runtime.content.status,
                             AssistantRuntimeStatus.STOPPED, "stopped")

    with loading_indicator("Requesting bot runtime stop..."):
        robo.assistants.runtimes.stop(bot_uuid)

    with loading_indicator("Waiting for the bot runtime to stop..."):
        wait_for_runtime_status(bot_uuid, AssistantRuntimeStatus.STOPPED)
Exemplo n.º 2
0
def get_base_version() -> str:
    """
    Show runtime options to the user.

    Returns:
        base_version (str): selected base version
    """
    with loading_indicator("Loading base version list..."):
        versions = get_supported_base_versions()

    version_choices = [{
        "value": base_version["version"],
        "name": base_version["label"]
    } for base_version in versions]

    questions = [
        {
            "type": "list",
            "name": "base_version",
            "message": "Please select the bot runtime version:",
            "choices": version_choices,
        },
    ]
    answers = prompt(questions)
    base_version = answers["base_version"]

    return base_version
Exemplo n.º 3
0
def command(language: tuple, bot_uuid: str):
    """
    display selected bot runtime logs.

    Args:
        language: language code of the bot to get logs from
        bot_uuid (str): optional argument stating the ID of the bot to get logs from
    """
    validate_robo_session()

    if len(language) == 0:
        bot_dir = abspath('.')
    elif len(language) == 1:
        bot_dir = abspath(join('.', 'languages', language[0]))
    else:
        print_message('Please select only one bot to check the logs.')
        exit(0)

    if not bot_uuid:
        bot_uuid = get_current_bot_uuid(bot_dir)

    # validate_bot(bot_uuid)

    with loading_indicator('Fetching logs from server...'):
        logs = get_runtime_logs(bot_uuid)

    print_info("Displaying logs for bot '{0}'\n".format(bot_uuid))
    print_message(logs + "\n")
Exemplo n.º 4
0
def start_runtime(bot_uuid: str):
    settings = ToolSettings()
    current_environment = settings.get_current_environment()
    robo = get_robo_client(current_environment)

    if not does_the_runtime_exist(bot_uuid):
        raise click.UsageError("The bot runtime does not exist.")

    runtime = robo.assistants.runtimes.get(bot_uuid)
    assert_status_transition(runtime.content.status,
                             AssistantRuntimeStatus.RUNNING, "started")

    with loading_indicator("Requesting bot runtime start..."):
        robo.assistants.runtimes.start(bot_uuid)

    with loading_indicator("Waiting for the bot runtime to start..."):
        wait_for_runtime_status(bot_uuid, AssistantRuntimeStatus.RUNNING)
Exemplo n.º 5
0
def command():
    """
    Clean (remove) the package if this is available in the bot dir.
    """
    print_message("Cleaning the packaging...")
    with loading_indicator("Cleaning package files..."):
        if os.path.isdir(BUILD_DIR):
            shutil.rmtree(BUILD_DIR)
    print_success("Successfully cleaned")
Exemplo n.º 6
0
def get_bot_uuid() -> str:
    """
    Show bot options to the user, returns the selected bot ID.

    Returns:
        bot_uuid (str): ID of the selected bot.
    """
    NEXT_PAGE = "__NEXT_PAGE__"
    PREV_PAGE = "__PREV_PAGE__"
    NONE = "__NONE__"
    META_RESPONSES = [NEXT_PAGE, PREV_PAGE, NONE]

    bot_uuid = NONE
    page = 0
    while bot_uuid in META_RESPONSES:
        if bot_uuid == NEXT_PAGE:
            page += 1

        if bot_uuid == PREV_PAGE:
            page -= 1

        with loading_indicator("Loading bot list..."):
            bots = get_bots(page)
        bot_choices = list(map(get_bot_choice, bots.content))
        page_count = math.ceil(bots.totalElements / bots.size)
        if page < page_count - 1:
            bot_choices.append({"name": "> Next page...", "value": NEXT_PAGE})

        if page > 0:
            bot_choices.append({
                "name": "> Previous page...",
                "value": PREV_PAGE
            })

        questions = [
            {
                "type":
                "list",
                "name":
                "bot_id",
                "message":
                "Please select the bot you would like to implement:",
                "choices": [
                    Choice(title=bot["name"], value=bot["value"]) if
                    (bot["value"] == NEXT_PAGE
                     or bot["value"] == PREV_PAGE) else Choice(
                         title=str(bot["name"] + " (" + bot["value"] + ")"),
                         value=bot["value"],
                     ) for bot in bot_choices
                ],
            },
        ]

        answers = prompt(questions)
        bot_uuid = answers["bot_id"]

    return bot_uuid
Exemplo n.º 7
0
def remove_runtime(bot_uuid: str):
    settings = ToolSettings()
    current_environment = settings.get_current_environment()
    robo = get_robo_client(current_environment)

    if not does_the_runtime_exist(bot_uuid):
        print_warning("The bot runtime does not exist.")
        return

    runtime = robo.assistants.runtimes.get(bot_uuid)
    assert_status_transition(runtime.content.status,
                             AssistantRuntimeStatus.REMOVED, "removed")

    with loading_indicator("Requesting bot runtime deletion..."):
        robo.assistants.runtimes.remove(bot_uuid)

    with loading_indicator("Waiting for the bot runtime to be removed..."):
        wait_for_runtime_non_existence(bot_uuid)
Exemplo n.º 8
0
def verify_endpoint_validity(base_url: str,
                             username: str,
                             password: str,
                             env_name: str = None):
    with loading_indicator('Verifying the endpoint validity...') as spinner:
        if not is_endpoint_config_valid(base_url, username, password,
                                        env_name):
            spinner.stop()
            print_error('The endpoint configuration is invalid.\n')
            return
Exemplo n.º 9
0
def validate_bot(bot_uuid: str):
    settings = ToolSettings()
    current_environment = settings.get_current_environment()
    robo = get_robo_client(current_environment)
    try:
        with loading_indicator("Validating bot..."):
            bot = robo.assistants.get_assistant(bot_uuid)
            bot_type = bot.content.assistantService
            if bot_type != SUPPORTED_BOT_TYPE:
                raise click.UsageError(
                    "The selected bot engine is invalid: {0}".format(bot_type))
    except NotFoundError:
        raise click.UsageError("The bot UUID is not valid.")
Exemplo n.º 10
0
def create_runtime(bot_uuid: str, package_file: str, base_version: str):
    settings = ToolSettings()
    current_environment = settings.get_current_environment()
    robo = get_robo_client(current_environment)
    total_file_size = os.path.getsize(package_file)
    with click.progressbar(length=total_file_size,
                           label="Uploading package",
                           show_eta=False) as bar:
        robo.assistants.runtimes.create(bot_uuid,
                                        package_file,
                                        base_version,
                                        progress_callback=lambda bytes_read:
                                        bar.update(bytes_read - bar.pos))

    with loading_indicator(
            "Waiting for the bot runtime to be ready (it may take several minutes)..."
    ):
        wait_for_runtime_status(bot_uuid, AssistantRuntimeStatus.CREATED)

    with loading_indicator("Waiting for the bot runtime to start..."):
        robo.assistants.runtimes.start(bot_uuid)
        wait_for_runtime_status(bot_uuid, AssistantRuntimeStatus.RUNNING)
Exemplo n.º 11
0
def update_runtime(bot_uuid: str, package_file: str, base_version: str):
    settings = ToolSettings()
    current_environment = settings.get_current_environment()
    robo = get_robo_client(current_environment)
    runtime = robo.assistants.runtimes.get(bot_uuid)
    if runtime.content.status == AssistantRuntimeStatus.RUNNING:
        with loading_indicator("The bot runtime is running, stopping..."):
            robo.assistants.runtimes.stop(bot_uuid)
            wait_for_runtime_status(bot_uuid, AssistantRuntimeStatus.STOPPED)

    total_file_size = os.path.getsize(package_file)
    with click.progressbar(length=total_file_size,
                           label="Uploading package",
                           show_eta=False) as bar:
        robo.assistants.runtimes.update(bot_uuid,
                                        package_file,
                                        base_version,
                                        progress_callback=lambda bytes_read:
                                        bar.update(bytes_read - bar.pos))

    with loading_indicator("Waiting for the bot runtime to start..."):
        wait_for_runtime_status(bot_uuid, AssistantRuntimeStatus.RUNNING)
Exemplo n.º 12
0
def command(api_key: str):
    """
    Initialize a new session using a ROBO.AI API key,

    Args:
        api_key (str): API key
    """
    settings = ToolSettings()
    current_environment = settings.get_current_environment(
    )  # this should be an object now
    robo = get_robo_client(current_environment)
    try:
        with loading_indicator('Authenticating...'):
            tokens = robo.oauth.authenticate(api_key)

        current_environment.api_key = api_key
        current_environment.api_auth_token = tokens.access_token
        settings.update_environment(current_environment)
        print_success('Successfully authenticated!\n')

    except InvalidCredentialsError:
        print_error('The API key is invalid.\n')
Exemplo n.º 13
0
def create_bot_manifest(bot_dir: str, bot_uuid: str, base_version: str):
    with loading_indicator("Creating bot manifest file..."):
        manifesto = BotManifest(bot_dir)
        manifesto.set_bot_id(bot_uuid)
        manifesto.set_base_version(base_version)