Beispiel #1
0
def exerciser1and2(machines):

    # Exerciser 1
    print("")
    print(SEPARATOR)
    print("Exerciser 1: This is a basic exercise that checks if your programs starts properly and run with no failure")
    print(SEPARATOR)
    if len(machines)<1:
        raise Exception(GENERAL_ERROR + "At least one execution machine should be provided for exerciser 1")
    exe_machine = machines[0]
    cm = CommandRunner()
    p_zk = cm.run_shell_command('~/myzk/bin/zkServer.sh start')
    p_fs = cm.run_shell_command('./start_fileserver.sh ' + exe_machine + ' ' + str(ZOOKEEPER_PORT))
    p_jb = cm.run_shell_command('./start_jobtracker.sh ' + exe_machine + ' ' + str(ZOOKEEPER_PORT))
    p_w1 = cm.run_shell_command('./start_worker.sh ' + exe_machine + ' ' + str(ZOOKEEPER_PORT))
    p_w2 = cm.run_shell_command('./start_worker.sh ' + exe_machine + ' ' + str(ZOOKEEPER_PORT))

    print("File server running on process number: " + str(p_fs.pid))
    print("Job tracker running on process number: " + str(p_jb.pid))
    print("Worker 1 running on process number: " + str(p_w1.pid))
    print("Worker 2 running on process number: " + str(p_w2.pid))

    p_zk.wait()
    print("Zookeeper started running on port: " + str(ZOOKEEPER_PORT))

    time.sleep(2)
    check_process_running(p_fs, "File Server")
    check_process_running(p_jb, "Job Tracker")
    check_process_running(p_w1, "Worker 1")
    check_process_running(p_w2, "Worker 2")
    print("Exerciser 1: PASS")

    # Exerciser 2
    print("")
    print(SEPARATOR)
    print("Exerciser 2: This exerciser submits a job to your cluster and check the result")
    print(SEPARATOR)

    in_progress_pattern = re.compile('In progress')
    success_pattern = re.compile('Password found:.*')
    failure_pattern = re.compile('Failed:.*')
    hashcode = '755f85c2723bb39381c7379a604160d8'
    password = '******'
    print("Submitting job to find password for hashcode: " + hashcode)
    submit_result, submit_error = cm.run_shell_command_return('./submit_job.sh ' + exe_machine + ' ' +
                                                              str(ZOOKEEPER_PORT) + ' ' + hashcode)

    print("submit result: " + submit_result)
    print("Getting status of the submitted job...")
    while (True):
        status_result, status_error = cm.run_shell_command_return('./check_job_status.sh ' + exe_machine + ' ' +
                                                                  str(ZOOKEEPER_PORT) + ' ' + hashcode)
        print("Current Status is: " + status_result)
        if in_progress_pattern.match(status_result):
            print('Job running in progress')
        elif success_pattern.match(status_result):
            password_found = status_result.split(':')
            if len(password_found)<2:
                raise('Incorrect format for message when password found. Expecting: "Password found: {password here}" '
                      'without the braces')
            else:
                password_found = password_found[1].strip(' \t\n')
            if password_found != password:
                raise Exception('Incorrect password found: The password you found is ' + password_found +
                                ', the expected password is ' + password)
            else:
                print("successfully found password")
            break
        elif failure_pattern.match(status_result):
            reason = status_result.split(':')
            if len(reason < 2):
                raise Exception('Incorrect format for message when failed to find password. Expecting: "Failed: ' + FAIL_PASSWORD_NO_FOUND + '"')
            else:
                reason = reason[1].strip()
            if reason == FAIL_PASSWORD_NO_FOUND:
                raise Exception("Failed to find password: hash code" + hashcode + " is corresponding to password " + password)
            break
        else:
            raise Exception("Message with incorrect format printed by client driver. Please refer to the handout for format.")
        time.sleep(1)
    print("End of exerciser 2")