Пример #1
0
    def process_get(self, event_args, ops_counter):
        process_debug_log("Count %d ProcessGetContentResponse node_id %d of user_id %s" % (ops_counter,
                                                                       int(event_args[TraceProcessor.csv_node_id]),
                                                                       int(event_args[TraceProcessor.csv_user_id])))

        user_id = int(event_args[TraceProcessor.csv_user_id])
        node_id = int(event_args[TraceProcessor.csv_node_id])
        friend_id = int(event_args[TraceProcessor.csv_friend_id])

        friend = TraceProcessor.all_users_dict[friend_id]
        oauth = friend.oauth
        is_ss_provider = friend.provider == "SS"
        server_id = None
        url = "NULL"

        start = time.time()
        try:
            server_id = None
            if node_id in friend.node_server_id_dict:
                server_id = friend.node_server_id_dict[node_id]
            if server_id not in friend.workspace_files:
                if len(friend.workspace_files) > 0:
                    server_id = random.sample(friend.workspace_files, 1)[0]
                else:
                    server_id = friend.file0_id

            start = time.time()
            response = get_content(oauth, server_id, is_ss_provider)
            end = time.time()
            url = response.url

            if response.status_code != 200:
                raise ValueError(
                    "Error on response with status_code %d and text %s" % (response.status_code, response.text))
            elapsed = end - start
            if "content-length" not in response.headers:
                size = len(response.content)
                error_msg = "Get without response.headers content length status_code %d %s" % (
                    response.status_code, response)
            else:
                size = response.headers["content-length"]
                error_msg = "NULL"

            process_log(str(ops_counter), str(repr(start)), str(repr(event_args[TraceProcessor.csv_queued_tstamp])),
                        str(user_id), str(event_args[TraceProcessor.csv_user_type]),
                        str(event_args[TraceProcessor.csv_req_type]),
                        str(TraceProcessor.all_users_dict[user_id].provider),
                        str(TraceProcessor.all_users_dict[friend_id].provider), str(friend_id), str(server_id),
                        str(event_args[TraceProcessor.csv_node_type]), str(size), str(elapsed),
                        str(len(TraceProcessor.all_users_dict[user_id].friends_id_factor_dict)),
                        has_error=str("0"), error_msg=error_msg, url=str(url))
            return 0
        except Exception as e:
            trace = event_args
            exception = type(e)
            error_msg = e.message
            args = e.args
            size = "NULL"
            level = "ERROR"
            if server_id is None:
                server_id = node_id

            elapsed = time.time() - start
            process_log(str(ops_counter), str(repr(start)), str(repr(event_args[TraceProcessor.csv_queued_tstamp])),
                        str(user_id), str(event_args[TraceProcessor.csv_user_type]),
                        str(event_args[TraceProcessor.csv_req_type]),
                        str(TraceProcessor.all_users_dict[user_id].provider),
                        str(TraceProcessor.all_users_dict[friend_id].provider), str(friend_id), str(server_id),
                        str(event_args[TraceProcessor.csv_node_type]), str(size), str(elapsed),
                        str(len(TraceProcessor.all_users_dict[user_id].friends_id_factor_dict)),
                        str(TraceProcessor.has_error_code), str(trace), str(exception), str(error_msg), str(args),
                        str(level), url=str(url))
            return TraceProcessor.has_error_code
Пример #2
0
def test_api(current_path):
    is_ss_provider = False
    create_test_user(is_ss_provider)

    user = users_dict.popitem()[1]
    root = user.shared_folder_id

    oauth = user.oauth
    file_name = "file5"
    folder_name = "folder5"
    is_folder = True

    start = time.time()
    response = make(oauth, folder_name, parent_id=root, is_folder=is_folder, is_ss_provider=is_ss_provider)
    end = time.time()
    print "MAKE folder elapsed;", (end - start)
    if response.status_code == 201:
        json_data = json.loads(response.text)
        folder_id = str(json_data["id"])
    elif (response.status_code == 400 or response.status_code == 403) and "already" in response.text:
        response = list_content(oauth, parent_id=root, is_ss_provider=is_ss_provider)
        json_data = response.json()
        content_root = json_data["contents"]
        folder_id = None
        for tuppla in content_root:
            try:
                name = tuppla["filename"]
                is_response_folder = tuppla["is_folder"]
                if name == folder_name and is_folder == is_response_folder:
                    folder_id = tuppla["id"]
                    break
            except KeyError:
                raise ValueError("ERROR MAKE Folder: Failed to extract folder_id form get_content at %s" % (response.url))
    else:
        raise ValueError(
            "ERROR MAKE Folder: response with status_code %d and text {%s}" % (response.status_code, response.text))
    print "Folder_id=", folder_id

    is_folder = False
    start = time.time()
    response = make(oauth, file_name, parent_id=folder_id, is_folder=is_folder, is_ss_provider=is_ss_provider)
    end = time.time()
    print "MAKE file elapsed;", (end - start)
    if response.status_code == 201:
        json_data = json.loads(response.text)
        server_id = str(json_data["id"])
    elif (response.status_code == 400 or response.status_code == 403) and "already" in response.text:
        response = list_content(oauth, parent_id=root, is_ss_provider=is_ss_provider)
        json_data = response.json()
        content_root = json_data["contents"]
        server_id = None
        for tuppla in content_root:
            try:
                name = tuppla["filename"]
                is_response_folder = tuppla["is_folder"]
                if name == folder_name and is_folder == is_response_folder:
                    server_id = tuppla["id"]
                    break
            except KeyError:
                raise ValueError("ERROR MAKE File: Failed to extract file_id form get_content at %s" % (response.url))
    else:
        raise ValueError(
            "ERROR MAKE File: response with status_code %d and text {%s}" % (response.status_code, response.text))
    print "File_id", server_id

    file_path = current_path + "/../README.md"
    start = time.time()
    response = put_content(oauth, server_id, file_path, is_ss_provider=is_ss_provider)
    end = time.time()
    print "PUT file elapsed;", (end - start)
    if not (response.status_code == 200 or response.status_code == 201):
        raise ValueError(
            "ERROR PUT File: response with status_code %d and text {%s}" % (response.status_code, response.text))

    start = time.time()
    response = get_content(oauth, server_id, is_ss_provider=is_ss_provider)
    end = time.time()
    print "GET file elapsed;", (end - start)
    if response.status_code != 200:
        raise ValueError(
            "ERROR GET File: response with status_code %d and text {%s}" % (response.status_code, response.text))

    start = time.time()
    response = unlink(oauth, server_id, is_folder=False, is_ss_provider=is_ss_provider)
    end = time.time()
    print "DELETE file elapsed;", (end - start)
    if response.status_code != 200:
        raise ValueError(
            "ERROR DELETE File: response with status_code %d and text {%s}" % (response.status_code, response.text))

    start = time.time()
    response = unlink(oauth, folder_id, is_folder=True, is_ss_provider=is_ss_provider)
    end = time.time()
    print "DELETE folder elapsed;", (end - start)
    if response.status_code != 200:
        raise ValueError(
            "ERROR DELETE Folder: response with status_code %d and text {%s}" % (response.status_code, response.text))