Пример #1
0
def execute(args: typing.NamedTuple):
    aztk = Aztk()
    cluster_id = args.cluster_id

    if not args.force:
        confirmation_cluster_id = input(
            "Please confirm the id of the cluster you wish to delete: ")

        if confirmation_cluster_id != cluster_id:
            log.error(
                "Confirmation cluster id does not match. Please try again.")
            return

    if aztk.client.delete_cluster(cluster_id):
        log.info("Deleting cluster %s", cluster_id)
    else:
        log.error("Cluster with id '%s' doesn't exist or was already deleted.",
                  cluster_id)
Пример #2
0
def execute(args: typing.NamedTuple):
    aztk = Aztk()

    log.info('-------------------------------------------')
    log.info('spark cluster id:    {}'.format(args.cluster_id))
    log.info('username:            {}'.format(args.username))
    log.info('-------------------------------------------')

    if args.ssh_key:
        ssh_key = args.ssh_key
    else:
        ssh_key = aztk.client.secrets_config.ssh_pub_key

    ssh_key, password = utils.get_ssh_key_or_prompt(ssh_key, args.username,
                                                    args.password,
                                                    aztk.client.secrets_config)

    aztk.client.create_user(cluster_id=args.cluster_id,
                            username=args.username,
                            password=password,
                            ssh_key=ssh_key)

    if password:
        log.info('password:            %s', '*' * len(password))
    elif ssh_key:
        log.info('ssh public key:      %s', ssh_key)

    log.info('-------------------------------------------')
Пример #3
0
def execute(args: typing.NamedTuple):
    aztk = Aztk()

    # read cluster.yaml configuartion file, overwrite values with args
    cluster_conf = ClusterConfig()

    cluster_conf.merge(
        uid=args.cluster_id,
        size=args.size,
        size_low_pri=args.size_low_pri,
        vm_size=args.vm_size,
        wait=args.wait,
        username=args.username,
        password=args.password,
        docker_repo=args.docker_repo)

    print_cluster_conf(cluster_conf)

    if cluster_conf.custom_scripts:
        custom_scripts = []
        for custom_script in cluster_conf.custom_scripts:
            custom_scripts.append(
                aztk_sdk.spark.models.CustomScript(
                    script=custom_script['script'],
                    run_on=custom_script['runOn']
                )
            )
    else:
        custom_scripts = None

    jars_src = aztk_sdk.utils.constants.DEFAULT_SPARK_JARS_SOURCE

    # create spark cluster
    cluster = aztk.client.create_cluster(
        aztk_sdk.spark.models.ClusterConfiguration(
            cluster_id=cluster_conf.uid,
            vm_count=cluster_conf.size,
            vm_low_pri_count=cluster_conf.size_low_pri,
            vm_size=cluster_conf.vm_size,
            custom_scripts=custom_scripts,
            docker_repo=cluster_conf.docker_repo,
            spark_configuration=aztk_sdk.spark.models.SparkConfiguration(
                spark_defaults_conf=os.path.join(
                    aztk_sdk.utils.constants.DEFAULT_SPARK_CONF_SOURCE, 'spark-defaults.conf'),
                spark_env_sh=os.path.join(
                    aztk_sdk.utils.constants.DEFAULT_SPARK_CONF_SOURCE, 'spark-env.sh'),
                core_site_xml=os.path.join(
                    aztk_sdk.utils.constants.DEFAULT_SPARK_CONF_SOURCE, 'core-site.xml'),
                jars=[
                    os.path.join(jars_src, path) for path in os.listdir(jars_src)
                ]
            )
        ),
        wait=cluster_conf.wait
    )

    if cluster_conf.username:
        ssh_key = aztk.client.secrets_config.ssh_pub_key

        ssh_key, password = utils.get_ssh_key_or_prompt(
            ssh_key, args.username, args.password, aztk.client.secrets_config)

        aztk.client.create_user(
            cluster_id=cluster_conf.uid,
            username=cluster_conf.username,
            password=password,
            ssh_key=ssh_key
        )

    if cluster_conf.wait:
        log.info("Cluster %s created successfully.", cluster.id)
    else:
        log.info("Cluster %s is being provisioned.", cluster.id)
Пример #4
0
def print_cluster_conf(cluster_conf):
    log.info("-------------------------------------------")
    log.info("spark cluster id:        %s", cluster_conf.uid)
    log.info("spark cluster size:      %s",
             cluster_conf.size + cluster_conf.size_low_pri)
    log.info(">        dedicated:      %s", cluster_conf.size)
    log.info(">     low priority:      %s", cluster_conf.size_low_pri)
    log.info("spark cluster vm size:   %s", cluster_conf.vm_size)
    log.info("custom scripts:          %s", cluster_conf.custom_scripts)
    log.info("docker repo name:        %s", cluster_conf.docker_repo)
    log.info("wait for cluster:        %s", cluster_conf.wait)
    log.info("username:                %s", cluster_conf.username)
    if cluster_conf.password:
        log.info("Password: %s", '*' * len(cluster_conf.password))
    log.info("-------------------------------------------")
Пример #5
0
def execute(args: typing.NamedTuple):
    aztk = Aztk()
    ssh_conf = SshConfig()

    ssh_conf.merge(cluster_id=args.cluster_id,
                   username=args.username,
                   job_ui_port=args.jobui,
                   job_history_ui_port=args.jobhistoryui,
                   web_ui_port=args.webui,
                   jupyter_port=args.jupyter,
                   name_node_ui_port=args.namenodeui,
                   host=args.host,
                   connect=args.connect)

    http_prefix = 'http://localhost:'
    log.info("-------------------------------------------")
    log.info("spark cluster id:    %s", ssh_conf.cluster_id)
    log.info("open webui:          %s%s", http_prefix, ssh_conf.web_ui_port)
    log.info("open jobui:          %s%s", http_prefix, ssh_conf.job_ui_port)
    log.info("open jobhistoryui:   %s%s", http_prefix,
             ssh_conf.job_history_ui_port)
    log.info("open jupyter:        %s%s", http_prefix, ssh_conf.jupyter_port)
    log.info("open jupyter:        %s%s", http_prefix,
             ssh_conf.name_node_ui_port)
    log.info("ssh username:        %s", ssh_conf.username)
    log.info("connect:             %s", ssh_conf.connect)
    log.info("-------------------------------------------")

    # get ssh command
    try:
        ssh_cmd = utils.ssh_in_master(
            client=aztk.client,
            cluster_id=ssh_conf.cluster_id,
            webui=ssh_conf.web_ui_port,
            jobui=ssh_conf.job_ui_port,
            jobhistoryui=ssh_conf.job_history_ui_port,
            namenodeui=ssh_conf.name_node_ui_port,
            jupyter=ssh_conf.jupyter_port,
            username=ssh_conf.username,
            host=ssh_conf.host,
            connect=ssh_conf.connect)

        if not ssh_conf.connect:
            log.info("")
            log.info(
                "Use the following command to connect to your spark head node:"
            )
            log.info("\t%s", ssh_cmd)

    except batch_error.BatchErrorException as e:
        if e.error.code == "PoolNotFound":
            raise aztk_sdk.error.AztkError(
                "The cluster you are trying to connect to does not exist.")
        else:
            raise
Пример #6
0
def execute(args: typing.NamedTuple):
    aztk = Aztk()
    jars = []
    py_files = []
    files = []

    if args.jars is not None:
        jars = args.jars.replace(' ', '').split(',')

    if args.py_files is not None:
        py_files = args.py_files.replace(' ', '').split(',')

    if args.files is not None:
        files = args.files.replace(' ', '').split(',')

    log.info("-------------------------------------------")
    log.info("Spark cluster id:        %s", args.cluster_id)
    log.info("Spark app name:          %s", args.name)
    log.info("Wait for app completion: %s", args.wait)
    if args.main_class is not None:
        log.info("Entry point class:       %s", args.main_class)
    if jars:
        log.info("JARS:                    %s", jars)
    if py_files:
        log.info("PY_Files:                %s", py_files)
    if files:
        log.info("Files:                   %s", files)
    if args.driver_java_options is not None:
        log.info("Driver java options:     %s", args.driver_java_options)
    if args.driver_library_path is not None:
        log.info("Driver library path:     %s", args.driver_library_path)
    if args.driver_class_path is not None:
        log.info("Driver class path:       %s", args.driver_class_path)
    if args.driver_memory is not None:
        log.info("Driver memory:           %s", args.driver_memory)
    if args.executor_memory is not None:
        log.info("Executor memory:         %s", args.executor_memory)
    if args.driver_cores is not None:
        log.info("Driver cores:            %s", args.driver_cores)
    if args.executor_cores is not None:
        log.info("Executor cores:          %s", args.executor_cores)
    log.info("Application:             %s", args.app)
    log.info("Application arguments:   %s", args.app_args)
    log.info("-------------------------------------------")

    aztk.client.submit(cluster_id=args.cluster_id,
                       application=aztk_sdk.spark.models.AppModel(
                           name=args.name,
                           application=args.app,
                           application_args=args.app_args,
                           main_class=args.main_class,
                           jars=jars,
                           py_files=py_files,
                           files=files,
                           driver_java_options=args.driver_java_options,
                           driver_library_path=args.driver_library_path,
                           driver_class_path=args.driver_class_path,
                           driver_memory=args.driver_memory,
                           executor_memory=args.executor_memory,
                           driver_cores=args.driver_cores,
                           executor_cores=args.executor_cores),
                       wait=False)

    if args.wait:
        utils.stream_logs(client=aztk.client,
                          cluster_id=args.cluster_id,
                          application_name=args.name)