Пример #1
0
int webhdfs_set_replication (webhdfs_t *fs, const char *path, int replication) {
    webhdfs_req_t req;
    yajl_val node, v;

    webhdfs_req_open(&req, fs, path);
    webhdfs_req_set_args(&req, "op=SETREPLICATION&replication=%d", replication);
    char *error = NULL;
    webhdfs_req_exec(&req, WEBHDFS_REQ_PUT, &error);
    if (error) free(error);
    node = webhdfs_req_json_response(&req);
    webhdfs_req_close(&req);

    if ((v = webhdfs_response_exception(node)) != NULL) {
        yajl_tree_free(node);
        return(1);
    }

    if ((v = webhdfs_response_boolean(node)) != NULL) {
        int failure = YAJL_IS_FALSE(v);
        yajl_tree_free(node);
        return(failure);
    }

    yajl_tree_free(node);
    return(2);
}
Пример #2
0
char *webhdfs_home_dir (webhdfs_t *fs) {
    webhdfs_req_t req;
    yajl_val node, v;

    webhdfs_req_open(&req, fs, NULL);
    webhdfs_req_set_args(&req, "op=GETHOMEDIRECTORY");
    char *error = NULL;
    webhdfs_req_exec(&req, WEBHDFS_REQ_GET, &error);
    if (error) free(error);
    node = webhdfs_req_json_response(&req);
    webhdfs_req_close(&req);

    if ((v = webhdfs_response_exception(node)) != NULL) {
        yajl_tree_free(node);
        return(NULL);
    }

    if ((v = webhdfs_response_path(node)) != NULL) {
        char *path = strdup(YAJL_GET_STRING(v));
        yajl_tree_free(node);
        return(path);
    }

    yajl_tree_free(node);
    return(NULL);
}
Пример #3
0
int webhdfs_rename (webhdfs_t *fs, const char *oldname, const char *newname) {
    webhdfs_req_t req;
    yajl_val node, v;

    webhdfs_req_open(&req, fs, oldname);
    webhdfs_req_set_args(&req, "op=RENAME&destination=%s", newname);
    char *error = NULL;
    webhdfs_req_exec(&req, WEBHDFS_REQ_PUT, &error);
    if (error) free(error);
    node = webhdfs_req_json_response(&req);
    webhdfs_req_close(&req);

    if ((v = webhdfs_response_exception(node)) != NULL) {
        yajl_tree_free(node);
        return(1);
    }

    if ((v = webhdfs_response_boolean(node)) != NULL) {
        int failure = YAJL_IS_FALSE(v);
        yajl_tree_free(node);
        return(failure);
    }

    yajl_tree_free(node);
    return(2);
}
Пример #4
0
static int __webhdfs_delete (webhdfs_t *fs, const char *path, int recursive) {
    webhdfs_req_t req;
    yajl_val node, v;

    webhdfs_req_open(&req, fs, path);
    webhdfs_req_set_args(&req, "op=DELETE&recursive=%s",
                               recursive ? "true" : "false");
    char *error = NULL;
    webhdfs_req_exec(&req, WEBHDFS_REQ_DELETE, &error);
    if (error) free(error);
    node = webhdfs_req_json_response(&req);
    webhdfs_req_close(&req);

    if ((v = webhdfs_response_exception(node)) != NULL) {
        yajl_tree_free(node);
        return(1);
    }

    if ((v = webhdfs_response_boolean(node)) != NULL) {
        int failure = YAJL_IS_FALSE(v);
        yajl_tree_free(node);
        return(failure);
    }

    yajl_tree_free(node);
    return(2);
}
Пример #5
0
int webhdfs_set_times (webhdfs_t *fs, const char *path, int mtime, int atime) {
    webhdfs_req_t req;
    yajl_val node, v;

    webhdfs_req_open(&req, fs, path);
    webhdfs_req_set_args(&req, "op=SETTIMES&modificationtime=%d&accesstime=%d",
                               mtime, atime);
    webhdfs_req_exec(&req, WEBHDFS_REQ_PUT);
    node = webhdfs_req_json_response(&req);
    webhdfs_req_close(&req);

    if ((v = webhdfs_response_exception(node)) != NULL) {
        yajl_tree_free(node);
        return(1);
    }

    yajl_tree_free(node);
    return(0);
}
Пример #6
0
webhdfs_dir_t *webhdfs_dir_open (webhdfs_t *fs,
                                 const char *path)
{
    const char *file_status[] = {"FileStatus", NULL};
    webhdfs_dir_t *dir;
    webhdfs_req_t req;
    yajl_val node, v;

    webhdfs_req_open(&req, fs, path);
    webhdfs_req_set_args(&req, "op=LISTSTATUS");
    char *error = NULL;
    webhdfs_req_exec(&req, WEBHDFS_REQ_GET, &error);
    if (error) free(error);
    node = webhdfs_req_json_response(&req);
    webhdfs_req_close(&req);

    if ((v = webhdfs_response_exception(node)) != NULL) {
        yajl_tree_free(node);
        return(NULL);
    }

    if ((v = webhdfs_response_file_statuses(node)) == NULL) {
        yajl_tree_free(node);
        return(NULL);
    }

    if ((v = yajl_tree_get(v, file_status, yajl_t_array)) == NULL) {
        yajl_tree_free(node);
        return(NULL);
    }

    if ((dir = (webhdfs_dir_t *) malloc(sizeof(webhdfs_dir_t))) == NULL) {
        yajl_tree_free(node);
        return(NULL);
    }

    dir->root = node;
    dir->statuses = v;
    dir->current = 0;

    return(dir);
}
Пример #7
0
int webhdfs_chmod (webhdfs_t *fs, const char *path, int permission) {
    webhdfs_req_t req;
    yajl_val node, v;

    webhdfs_req_open(&req, fs, path);
    webhdfs_req_set_args(&req, "op=SETPERMISSION&permission=%o", permission);
    char *error = NULL;
    webhdfs_req_exec(&req, WEBHDFS_REQ_PUT, &error);
    if (error) free(error);
    node = webhdfs_req_json_response(&req);
    webhdfs_req_close(&req);

    if ((v = webhdfs_response_exception(node)) != NULL) {
        yajl_tree_free(node);
        return(1);
    }

    yajl_tree_free(node);
    return(0);
}
Пример #8
0
int webhdfs_chmod (webhdfs_t *fs, const char *path, int permission) {
    webhdfs_req_t req;
    yajl_val node, v;

    webhdfs_req_open(&req, fs, path);

    // the permission must be in radix-8 format and it's maximal value is 777
    int short_permission = permission % (8 * 8 * 8);
    webhdfs_req_set_args(&req, "op=SETPERMISSION&permission=%o", short_permission);
    webhdfs_req_exec(&req, WEBHDFS_REQ_PUT);
    node = webhdfs_req_json_response(&req);
    webhdfs_req_close(&req);

    if ((v = webhdfs_response_exception(node)) != NULL) {
        yajl_tree_free(node);
        return(1);
    }

    yajl_tree_free(node);
    return(0);
}
Пример #9
0
int webhdfs_chown (webhdfs_t *fs,
                   const char *path,
                   const char *user,
                   const char *group)
{
    webhdfs_req_t req;
    yajl_val node, v;

    webhdfs_req_open(&req, fs, path);
    webhdfs_req_set_args(&req, "op=SETOWNER&user=%s&group=%s", user, group);
    webhdfs_req_exec(&req, WEBHDFS_REQ_PUT);
    node = webhdfs_req_json_response(&req);
    webhdfs_req_close(&req);

    if ((v = webhdfs_response_exception(node)) != NULL) {
        yajl_tree_free(node);
        return(1);
    }

    yajl_tree_free(node);
    return(0);
}
Пример #10
0
int webhdfs_rename_snapshot (webhdfs_t *fs, const char *path, const char *oldname, const char *newname) {
    webhdfs_req_t req;
    yajl_val node, v;

    webhdfs_req_open(&req, fs, path);
    webhdfs_req_set_args(&req, "op=RENAMESNAPSHOT&oldsnapshotname=%s&snapshotname=%s", oldname, newname);
    webhdfs_req_exec(&req, WEBHDFS_REQ_PUT);
    node = webhdfs_req_json_response(&req);
    webhdfs_req_close(&req);

    if ((v = webhdfs_response_exception(node)) != NULL) {
        yajl_tree_free(node);
        return(1);
    }

    if ((v = webhdfs_response_boolean(node)) != NULL) {
        int failure = YAJL_IS_FALSE(v);
        yajl_tree_free(node);
        return(failure);
    }

    yajl_tree_free(node);
    return(2);
}
Пример #11
0
int webhdfs_mkdir (webhdfs_t *fs, const char *path, int permission) {
    webhdfs_req_t req;
    yajl_val node, v;

    webhdfs_req_open(&req, fs, path);
    webhdfs_req_set_args(&req, "op=MKDIRS&permission=%o", permission);
    webhdfs_req_exec(&req, WEBHDFS_REQ_PUT);
    node = webhdfs_req_json_response(&req);
    webhdfs_req_close(&req);

    if ((v = webhdfs_response_exception(node)) != NULL) {
        yajl_tree_free(node);
        return(1);
    }

    if ((v = webhdfs_response_boolean(node)) != NULL) {
        int failure = YAJL_IS_FALSE(v);
        yajl_tree_free(node);
        return(failure);
    }

    yajl_tree_free(node);
    return(2);
}
Пример #12
0
webhdfs_fstat_t *webhdfs_stat (webhdfs_t *fs,
                               const char *path,
                               char **error) {
    const char *pathSuffix[] = {"pathSuffix", NULL};
    const char *replication[] = {"replication", NULL};
    const char *permission[] = {"permission", NULL};
    const char *length[] = {"length", NULL};
    const char *group[] = {"group", NULL};
    const char *owner[] = {"owner", NULL};
    const char *type[] = {"type", NULL};
    const char *mtime[] = {"modificationTime", NULL};
    const char *block[] = {"blockSize", NULL};
    const char *atime[] = {"accessTime", NULL};
    yajl_val root, node, v;
    webhdfs_fstat_t *stat;
    webhdfs_req_t req;

    webhdfs_req_open(&req, fs, path);
    webhdfs_req_set_args(&req, "op=GETFILESTATUS");
    char *error2 = NULL;
    int ret = -1;
    if ((ret = webhdfs_req_exec(&req, WEBHDFS_REQ_GET, &error2)) != 0) {
        *error = __strdup(error2);
        free(error2);
        webhdfs_req_close(&req);
        return(NULL);
    }
    root = webhdfs_req_json_response(&req);
    webhdfs_req_close(&req);

    if ((v = webhdfs_response_exception(root)) != NULL) {
//        const char *exceptionNode[] = {"exception", NULL};
//        yajl_val exception = yajl_tree_get(v, exceptionNode , yajl_t_string);
//        YAJL_GET_STRING(exception);
        const char *messageNode[] = {"message", NULL};
        yajl_val message = yajl_tree_get(v, messageNode, yajl_t_string);
        *error = __strdup(YAJL_GET_STRING(message));

        yajl_tree_free(root);
        return(NULL);
    }

    if ((node = webhdfs_response_file_status(root)) == NULL) {
        yajl_tree_free(root);
        return(NULL);
    }

    if ((stat = (webhdfs_fstat_t *) malloc(sizeof(webhdfs_fstat_t))) == NULL) {
        yajl_tree_free(root);
        return(NULL);
    }

    memset(stat, 0, sizeof(webhdfs_fstat_t));

    if ((v = yajl_tree_get(node, atime, yajl_t_number)))
        stat->atime = YAJL_GET_INTEGER(v);

    if ((v = yajl_tree_get(node, mtime, yajl_t_number)))
        stat->mtime = YAJL_GET_INTEGER(v);

    if ((v = yajl_tree_get(node, length, yajl_t_number)))
        stat->length = YAJL_GET_INTEGER(v);

    if ((v = yajl_tree_get(node, block, yajl_t_number)))
        stat->block = YAJL_GET_INTEGER(v);

    if ((v = yajl_tree_get(node, replication, yajl_t_number)))
        stat->replication = YAJL_GET_INTEGER(v);

    if ((v = yajl_tree_get(node, permission, yajl_t_string)))
        stat->permission = strtol(YAJL_GET_STRING(v), NULL, 8);

    if ((v = yajl_tree_get(node, pathSuffix, yajl_t_string)))
        stat->path = __strdup(YAJL_GET_STRING(v));

    if ((v = yajl_tree_get(node, group, yajl_t_string)))
        stat->group = __strdup(YAJL_GET_STRING(v));

    if ((v = yajl_tree_get(node, owner, yajl_t_string)))
        stat->owner = __strdup(YAJL_GET_STRING(v));

    if ((v = yajl_tree_get(node, type, yajl_t_string)))
        stat->type = __strdup(YAJL_GET_STRING(v));

    yajl_tree_free(root);
    return(stat);
}