Esempio n. 1
0
def main():
    file_name, lan_servers, product_servers, user, password, host = param_check(sys.argv)
    session = utility.generate_session_name()
    start = time.time()
    essh = serverlist.get_jump_server()
    print("makeup remote server: " + essh.host)
    ensure_remote_usable(essh, session, user, password, host)

    sha1sum = utility.calc_sha1sum(file_name)
    size = os.path.getsize(file_name)

    tasks = []
    files = []
    if len(lan_servers) != 0:
        print(lan_servers, len(lan_servers))
        client_count = len(lan_servers) + 1
        block_size = size / client_count + client_count
        files = utility.split_file(file_name, str(block_size))

        for index, name in enumerate(lan_servers):
            transfer_file = files[index]
            server_info = serverlist.get_lan_server(name)
            task = threading.Thread(target=remote_upload, args=(transfer_file, server_info, essh, session))
            tasks.append(task)

        task = threading.Thread(target=local_upload, args=(files[len(lan_servers)], essh, session))
        tasks.append(task)
    else:
        task = threading.Thread(target=local_upload, args=(file_name, essh, session))
        tasks.append(task)

    for t in tasks:
        t.setDaemon(True)
        t.start()

    while True:
        time.sleep(1)
        if is_all_task_finished(tasks):
            break

    finish = time.time()

    child = login_server(essh)
    tmp_path = os.path.join(essh.tmpPath, session)
    child.sendline("cd " + tmp_path)
    if len(lan_servers) != 0:
        merge_file(child, files, file_name, sha1sum)

    for f in files:
        os.remove(f)

    print("-----------------File upload success.-----------------------")
    print("Total cost " + str(finish - start))
    print(file_name + ": " + sha1sum)
    print("-----------------Begin dispatch file.-----------------------")

    remote_server_dispatch(child, file_name, product_servers)
    child.close()
Esempio n. 2
0
    def __generateDeployShell():
        shell = ""
        shell += "cd /usr/local/tomcat7/webapps\n"  # todo read config

        shell += "mv recsys-servering.war ~/webappbak/recsys-servering.war."
        shell += utility.generate_session_name()
        shell += "\n"

        shell += "rm -rvf recsys-servering*\n"
        shell += "mv /tmp/recsys-servering.war .\n"  # todo config it
        shell += "mkdir recsys-servering\n"
        shell += "cd recsys-servering\n"
        shell += "cp ../recsys-servering.war .\n"
        shell += "jar -xvf recsys-servering.war\n"
        shell += "rm recsys-servering.war\n"
        shell += "service tomcat restart\n"

        return shell
Esempio n. 3
0
    def __generateDeployShell():
        shell = ""
        shell += "cd /usr/local/tomcat7/webapps\n"  # todo read config

        shell += "mv recsys-servering.war ~/webappbak/recsys-servering.war."
        shell += utility.generate_session_name()
        shell += "\n"

        shell += "rm -rvf recsys-servering*\n"
        shell += "mv /tmp/recsys-servering.war .\n"  # todo config it
        shell += "mkdir recsys-servering\n"
        shell += "cd recsys-servering\n"
        shell += "cp ../recsys-servering.war .\n"
        shell += "jar -xvf recsys-servering.war\n"
        shell += "rm recsys-servering.war\n"
        shell += "service tomcat restart\n"

        return shell
Esempio n. 4
0
def main():
    file_name, lan_servers, product_servers, user, password, host = param_check(
        sys.argv)
    session = utility.generate_session_name()
    start = time.time()
    essh = serverlist.get_jump_server()
    print("makeup remote server: " + essh.host)
    ensure_remote_usable(essh, session, user, password, host)

    sha1sum = utility.calc_sha1sum(file_name)
    size = os.path.getsize(file_name)

    tasks = []
    files = []
    if len(lan_servers) != 0:
        print(lan_servers, len(lan_servers))
        client_count = len(lan_servers) + 1
        block_size = size / client_count + client_count
        files = utility.split_file(file_name, str(block_size))

        for index, name in enumerate(lan_servers):
            transfer_file = files[index]
            server_info = serverlist.get_lan_server(name)
            task = threading.Thread(target=remote_upload,
                                    args=(transfer_file, server_info, essh,
                                          session))
            tasks.append(task)

        task = threading.Thread(target=local_upload,
                                args=(files[len(lan_servers)], essh, session))
        tasks.append(task)
    else:
        task = threading.Thread(target=local_upload,
                                args=(file_name, essh, session))
        tasks.append(task)

    for t in tasks:
        t.setDaemon(True)
        t.start()

    while True:
        time.sleep(1)
        if is_all_task_finished(tasks):
            break

    finish = time.time()

    child = login_server(essh)
    tmp_path = os.path.join(essh.tmpPath, session)
    child.sendline("cd " + tmp_path)
    if len(lan_servers) != 0:
        merge_file(child, files, file_name, sha1sum)

    for f in files:
        os.remove(f)

    print("-----------------File upload success.-----------------------")
    print("Total cost " + str(finish - start))
    print(file_name + ": " + sha1sum)
    print("-----------------Begin dispatch file.-----------------------")

    remote_server_dispatch(child, file_name, product_servers)
    child.close()