示例#1
0
def get_job_logs(cluster_name: str, job_name: str, **kwargs):
    # Load details
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details['cloud']['infra'] == 'azure':
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.get_job_logs(job_name=job_name)
示例#2
0
def stop_schedule(cluster_name: str, schedule_name: str, **kwargs):
    # Load details
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details['cloud']['infra'] == 'azure':
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.stop_schedule(schedule_name=schedule_name)
示例#3
0
def start_schedule(cluster_name: str, deployment_path: str, **kwargs):
    # Load details
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details['cloud']['infra'] == 'azure':
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.start_schedule(deployment_path=deployment_path)
示例#4
0
def start_job(cluster_name: str, deployment_path: str, **kwargs):
    # Load details
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details["mode"] in ["grass/azure", "grass/on-premises"]:
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.start_job(deployment_path=deployment_path)
    else:
        raise BadRequestError(f"Unsupported command in mode '{cluster_details['mode']}'.")
示例#5
0
def get_job_logs(cluster_name: str, job_name: str, **kwargs):
    # Load details
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details["mode"] in ["grass/azure", "grass/on-premises"]:
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.get_job_logs(job_name=job_name)
    else:
        raise BadRequestError(f"Unsupported command in mode '{cluster_details['mode']}'.")
示例#6
0
def stop_node(cluster_name: str, replicas: int, node_size: str, **kwargs):
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details["mode"] == "grass/azure":
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.stop_node(replicas=replicas, node_size=node_size)
    else:
        raise BadRequestError(
            f"Unsupported command in mode '{cluster_details['mode']}'.")
示例#7
0
def pull_data(cluster_name: str, local_path: str, remote_path: str, **kwargs):
    cluster_details = load_cluster_details(cluster_name=cluster_name)
    if cluster_details["mode"] in ["grass/azure", "grass/on-premises"]:

        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.pull_data(local_path=local_path, remote_path=remote_path)
    else:
        raise BadRequestError(
            f"Unsupported command in mode '{cluster_details['mode']}'.")
示例#8
0
def status(cluster_name: str, resource_name: str, **kwargs):
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details["mode"] in ["grass/azure", "grass/on-premises"]:
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.status(resource_name=resource_name)
    else:
        raise BadRequestError(
            f"Unsupported command in mode '{cluster_details['mode']}'.")
示例#9
0
def stop_schedule(cluster_name: str, schedule_name: str, **kwargs):
    # Load details
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details["mode"] in ["grass/azure", "grass/on-premises"]:
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.stop_schedule(schedule_name=schedule_name)
    else:
        raise BadRequestError(
            f"Unsupported command in mode '{cluster_details['mode']}'.")
示例#10
0
def push_image(cluster_name: str, image_name: str, image_path: str,
               remote_context_path: str, remote_image_name: str, **kwargs):
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details['cloud']['infra'] == 'azure':
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.push_image(image_name=image_name,
                            image_path=image_path,
                            remote_context_path=remote_context_path,
                            remote_image_name=remote_image_name)
示例#11
0
def clean(cluster_name: str, **kwargs):
    # Load details
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details["mode"] == "grass/azure":
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.clean()
    else:
        raise BadRequestError(
            f"Unsupported command in mode '{cluster_details['mode']}'.")
示例#12
0
def delete(cluster_name: str, **kwargs):
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details["mode"] == "grass/azure":
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.delete()
    elif cluster_details["mode"] == "grass/on-premises":
        executor = GrassOnPremisesExecutor(cluster_name=cluster_name)
        executor.delete()
    else:
        raise BadRequestError(
            f"Unsupported command in mode '{cluster_details['mode']}'.")
示例#13
0
def push_image(cluster_name: str, image_name: str, image_path: str,
               remote_context_path: str, remote_image_name: str, **kwargs):
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details["mode"] in ["grass/azure", "grass/on-premises"]:
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.push_image(image_name=image_name,
                            image_path=image_path,
                            remote_context_path=remote_context_path,
                            remote_image_name=remote_image_name)
    else:
        raise BadRequestError(
            f"Unsupported command in mode '{cluster_details['mode']}'.")
示例#14
0
def clean(cluster_name: str, **kwargs):
    # Late import.
    from maro.cli.grass.executors.grass_azure_executor import GrassAzureExecutor
    from maro.cli.utils.details_reader import DetailsReader
    from maro.utils.exception.cli_exception import BadRequestError

    cluster_details = DetailsReader.load_cluster_details(
        cluster_name=cluster_name)

    if cluster_details["mode"] == "grass/azure":
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.clean()
    else:
        raise BadRequestError(
            f"Unsupported operation in mode '{cluster_details['mode']}'.")
示例#15
0
def pull_data(cluster_name: str, local_path: str, remote_path: str, **kwargs):
    # Late import.
    from maro.cli.grass.executors.grass_azure_executor import GrassAzureExecutor
    from maro.cli.grass.executors.grass_on_premises_executor import GrassOnPremisesExecutor
    from maro.cli.utils.details_reader import DetailsReader
    from maro.utils.exception.cli_exception import BadRequestError

    cluster_details = DetailsReader.load_cluster_details(cluster_name=cluster_name)

    if cluster_details["mode"] == "grass/azure":
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.pull_data(local_path=local_path, remote_path=remote_path)
    elif cluster_details["mode"] == "grass/on-premises":
        executor = GrassOnPremisesExecutor(cluster_name=cluster_name)
        executor.pull_data(local_path=local_path, remote_path=remote_path)
    else:
        raise BadRequestError(f"Unsupported operation in mode '{cluster_details['mode']}'.")
示例#16
0
def create(deployment_path: str, **kwargs):
    with open(deployment_path, 'r') as fr:
        create_deployment = yaml.safe_load(fr)

    try:
        if create_deployment['mode'] == 'grass':
            if create_deployment['cloud']['infra'] == 'azure':
                GrassAzureExecutor.build_cluster_details(
                    create_deployment=create_deployment)
                executor = GrassAzureExecutor(
                    cluster_name=create_deployment['name'])
                executor.create()
            else:
                raise ParsingError(
                    f"Deployment is broken: Invalid infra: {create_deployment['cloud']['infra']}"
                )
        else:
            raise ParsingError(
                f"Deployment is broken: Invalid mode: {create_deployment['mode']}"
            )
    except KeyError as e:
        raise ParsingError(f"Deployment is broken: Missing key: '{e.args[0]}'")
示例#17
0
def load_executor(cluster_name):
    if cluster_name == "process":
        from maro.cli.process.executor import ProcessExecutor
        executor = ProcessExecutor()
        cluster_type = DashboardType.PROCESS
    else:
        from maro.cli.utils.details_reader import DetailsReader
        cluster_details = DetailsReader.load_cluster_details(
            cluster_name=cluster_name)
        if cluster_details["mode"] == "grass/azure":
            from maro.cli.grass.executors.grass_azure_executor import GrassAzureExecutor
            executor = GrassAzureExecutor(cluster_name=cluster_name)
            cluster_type = DashboardType.AZURE
        elif cluster_details["mode"] == "grass/on-premises":
            from maro.cli.grass.executors.grass_on_premises_executor import GrassOnPremisesExecutor
            executor = GrassOnPremisesExecutor(cluster_name=cluster_name)
            cluster_type = DashboardType.ONPREMISES
        elif cluster_details["mode"] == "grass/local":
            from maro.cli.grass.executors.grass_local_executor import GrassLocalExecutor
            executor = GrassLocalExecutor(cluster_name=cluster_name)
            cluster_type = DashboardType.LOCAL
    return executor, cluster_type
示例#18
0
def get_job_logs(cluster_name: str, job_name: str, **kwargs):
    # Late import.
    from maro.cli.grass.executors.grass_azure_executor import GrassAzureExecutor
    from maro.cli.grass.executors.grass_local_executor import GrassLocalExecutor
    from maro.cli.grass.executors.grass_on_premises_executor import GrassOnPremisesExecutor
    from maro.cli.utils.details_reader import DetailsReader
    from maro.utils.exception.cli_exception import BadRequestError

    cluster_details = DetailsReader.load_cluster_details(
        cluster_name=cluster_name)

    if cluster_details["mode"] == "grass/azure":
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.get_job_logs(job_name=job_name)
    elif cluster_details["mode"] == "grass/local":
        executor = GrassLocalExecutor(cluster_name=cluster_name)
        executor.get_job_logs(job_name=job_name)
    elif cluster_details["mode"] == "grass/on-premises":
        executor = GrassOnPremisesExecutor(cluster_name=cluster_name)
        executor.get_job_logs(job_name=job_name)
    else:
        raise BadRequestError(
            f"Unsupported operation in mode '{cluster_details['mode']}'.")
示例#19
0
def create(deployment_path: str, **kwargs):
    try:
        with open(deployment_path, "r") as fr:
            create_deployment = yaml.safe_load(fr)
        if create_deployment["mode"] == "grass/azure":
            GrassAzureExecutor.build_cluster_details(
                create_deployment=create_deployment)
            executor = GrassAzureExecutor(
                cluster_name=create_deployment["name"])
            executor.create()
        elif create_deployment["mode"] == "grass/on-premises":
            GrassOnPremisesExecutor.build_cluster_details(
                create_deployment=create_deployment)
            executor = GrassOnPremisesExecutor(
                cluster_name=create_deployment["name"])
            executor.create()
        else:
            raise BadRequestError(
                f"Unsupported command in mode '{create_deployment['mode']}'.")
    except KeyError as e:
        raise InvalidDeploymentTemplateError(f"Missing key '{e.args[0]}'.")
    except FileNotFoundError:
        raise FileOperationError("Invalid template file path.")
示例#20
0
def start_schedule(cluster_name: str, deployment_path: str, **kwargs):
    # Late import.
    from maro.cli.grass.executors.grass_azure_executor import GrassAzureExecutor
    from maro.cli.grass.executors.grass_local_executor import GrassLocalExecutor
    from maro.cli.grass.executors.grass_on_premises_executor import GrassOnPremisesExecutor
    from maro.cli.utils.details_reader import DetailsReader
    from maro.utils.exception.cli_exception import BadRequestError

    # Load details
    cluster_details = DetailsReader.load_cluster_details(
        cluster_name=cluster_name)

    if cluster_details["mode"] == "grass/azure":
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.start_schedule(deployment_path=deployment_path)
    elif cluster_details["mode"] == "grass/local":
        executor = GrassLocalExecutor(cluster_name=cluster_name)
        executor.start_schedule(deployment_path=deployment_path)
    elif cluster_details["mode"] == "grass/on-premises":
        executor = GrassOnPremisesExecutor(cluster_name=cluster_name)
        executor.start_schedule(deployment_path=deployment_path)
    else:
        raise BadRequestError(
            f"Unsupported operation in mode '{cluster_details['mode']}'.")
示例#21
0
def list_node(cluster_name: str, **kwargs):
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details['cloud']['infra'] == 'azure':
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.list_node()
示例#22
0
def stop_node(cluster_name: str, replicas: int, node_size: str, **kwargs):
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details['cloud']['infra'] == 'azure':
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.stop_node(replicas=replicas, node_size=node_size)
示例#23
0
def status(cluster_name: str, resource_name: str, **kwargs):
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details['cloud']['infra'] == 'azure':
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.status(resource_name=resource_name)
示例#24
0
def list_node(cluster_name: str, **kwargs):
    cluster_details = load_cluster_details(cluster_name=cluster_name)

    if cluster_details["mode"] in ["grass/azure", "grass/on-premises"]:
        executor = GrassAzureExecutor(cluster_name=cluster_name)
        executor.list_node()