Ejemplo n.º 1
0
    def start_cluster(self, profile, cluster_id, kernel_id):
        """Start cluster in a separate thread
        
        Args:
            profile (str): Databricks CLI profile string
            cluster_id (str): Cluster ID
            kernel_id (str): Internal jupyter kernel ID
        """
        global_status = KernelHandler.status

        if global_status.installing(profile, cluster_id):
            _logger.info("DbStartHandler cluster %s:%s already starting" %
                         (profile, cluster_id))
        else:
            _logger.info("DbStartHandler cluster %s:%s start triggered" %
                         (profile, cluster_id))
            global_status.set_installing(profile, cluster_id)

            host, token = get_db_config(profile)
            cluster_id, public_ip, cluster_name, dummy = get_cluster(
                profile, host, token, cluster_id, global_status)
            if cluster_name is None:
                global_status.set_status(profile, cluster_id,
                                         "ERROR: Cluster could not be found")
                return

            global_status.set_status(profile, cluster_id, "Configuring SSH")
            prepare_ssh_config(cluster_id, profile, public_ip)
            if not is_reachable(public_dns=public_ip):
                global_status.set_status(profile, cluster_id, "UNREACHABLE")
            else:
                global_status.set_status(profile, cluster_id,
                                         "Installing driver libs")
                result = install_libs(cluster_id, host, token)
                if result[0] == 0:
                    _logger.info("DbStartHandler: installations done")
                else:
                    _logger.error("DbStartHandler: installations failed")
                    global_status.set_status(profile, cluster_id, "ERROR")

                time.sleep(1)
                kernel = self.get_kernel(kernel_id)
                kernel.restart_kernel(now=True)
                global_status.set_status(profile, cluster_id, "Running")
            global_status.unset_installing(profile, cluster_id)
    def test_configure_ssh(self, name, cluster_id):
        cluster_id2, public_ip, cluster_name, _ = get_cluster(
            self.profile, cluster_id)
        assert cluster_id2 == cluster_id
        assert cluster_name == name
        assert public_ip is not None

        prepare_ssh_config(cluster_id, self.profile, public_ip)
        ssh_config = os.path.expanduser("~/.ssh/config")
        sc = SSHConfig.load(ssh_config)
        host = sc.get(cluster_id)
        assert host.get("ConnectTimeout") == "5"
        assert host.get("ServerAliveCountMax") == "5760"
        assert host.get("IdentityFile") == "~/.ssh/id_{}".format(self.profile)

        assert is_reachable(public_dns=public_ip)

        subprocess.check_output([SSH, cluster_id, "hostname"])
Ejemplo n.º 3
0
    def test_configure_ssh(self, name, cluster_id):
        cluster_id2, endpoint, cluster_name, _ = get_cluster(
            self.profile, cluster_id)
        assert cluster_id2 == cluster_id
        assert cluster_name == name
        assert endpoint is not None

        prepare_ssh_config(cluster_id, self.profile, endpoint)
        ssh_config = os.path.expanduser("~/.ssh/config")
        sc = SshConfig(ssh_config)
        host = sc.get_host(cluster_id)
        assert host.get_param("ConnectTimeout").value == "5"
        assert host.get_param("ServerAliveCountMax").value == "5760"
        assert host.get_param("IdentityFile").value == "~/.ssh/id_{}".format(
            self.profile)

        assert is_reachable(endpoint)

        subprocess.check_output([SSH, cluster_id, "hostname"])