int main(int argc, char **argv) { int r; int64_t res; struct hdfs_object *exception = NULL, *dl; r = sasl_client_init(NULL); if (r != SASL_OK) { fprintf(stderr, "Error initializing sasl: %d\n", r); return -1; } if (argc > 1) { if (strcmp(argv[1], "-h") == 0) { printf("Usage: ./kerb [host [port [kerb_principal]]]\n"); exit(0); } host = argv[1]; if (argc > 2) { port = argv[2]; if (argc > 3) { user = argv[3]; } } } h = hdfs_namenode_new(host, port, user, HDFS_REQUIRE_KERB, &err); if (!h) goto out; res = hdfs_getProtocolVersion(h, HADOOFUS_CLIENT_PROTOCOL_STR, 61L, &exception); if (exception) { err = exception->ob_val._exception._msg; goto out; } if (res != 61) fprintf(stderr, "protocol version != 61: %zd\n", (intmax_t)res); else fprintf(stderr, "success\n"); dl = hdfs_getListing(h, "/", NULL, &exception); if (exception) { err = exception->ob_val._exception._msg; goto out; } hdfs_object_free(dl); fprintf(stderr, "dl: success\n"); out: if (err) fprintf(stderr, "hadoofus error: %s\n", err); if (h) hdfs_namenode_delete(h); sasl_done(); return 0; }
/** * hdfsConnectAsUser - Connect to a hdfs file system as a specific user * * @param host A string containing either a host name, or an ip address * of the namenode of a hdfs cluster. * @param port The port on which the server is listening. * @param user the user name (this is hadoop domain user). * @return Returns a handle to the filesystem or NULL on error. */ hdfsFS hdfsConnectAsUser(const char* host, tPort port, const char *user) { const char *err = NULL; char sport[40]; bool port_set = false; struct hdfs_namenode *nn; struct hdfsFS_internal *res; if (!host || !strcmp(host, "default")) { char *e_port; host = getenv("HDFS_DEFAULT_HOST"); e_port = getenv("HDFS_DEFAULT_PORT"); if (!host) { ERR(EINVAL, "Set HDFS_DEFAULT_HOST if you want NULL" "/\"default\" to work with libhadoofus"); return NULL; } if (e_port) { strncpy(sport, e_port, nelem(sport)); sport[nelem(sport)-1] = '\0'; port_set = true; } else { port = 8020; } } if (!port_set) sprintf(sport, "%d", port); nn = hdfs_namenode_new(host, sport, user, HDFS_NO_KERB, &err); if (!nn) { ERR(ECONNABORTED, "%s", err); return NULL; } res = malloc(sizeof *res); assert(res); res->fs_namenode = nn; res->fs_cwd = _makehome(user); // libhdfs is a sad, sad API. My hands are tied. (All filenames, at // least for directory listings, need to be in the form: // dfs://<host>:<port>//path/to/file // ^ Yes, that is two slashes. // // fuse_dfs depends on this naming scheme. res->fs_uri = malloc(strlen("dfs://") + strlen(host) + 1 + strlen(sport) + 2); assert(res->fs_uri); strcpy(res->fs_uri, "dfs://"); strcat(res->fs_uri, host); strcat(res->fs_uri, ":"); strcat(res->fs_uri, sport); strcat(res->fs_uri, "/"); return (hdfsFS)res; }
static void setup(void) { const char *err = NULL; h = hdfs_namenode_new(H_ADDR, "8020", H_USER, HDFS_NO_KERB, &err); ck_assert_msg((intptr_t)h, "Could not connect to %s=%s (port 8020): %s", HDFS_T_ENV, H_ADDR, err); }
int main(int argc, char **argv) { int64_t res; struct hdfs_object *exception = NULL; if (argc > 1) { if (strcmp(argv[1], "-h") == 0) { printf("Usage: ./hl-hello [host [port [user]]]\n"); exit(0); } host = argv[1]; if (argc > 2) { port = argv[2]; if (argc > 3) { user = argv[3]; } } } h = hdfs_namenode_new(host, port, user, HDFS_NO_KERB, &error); if (!h) goto out; res = hdfs_getProtocolVersion(h, HADOOFUS_CLIENT_PROTOCOL_STR, 61L, &exception); if (exception) { error = exception->ob_val._exception._msg; goto out; } if (res != 61) fprintf(stderr, "protocol version != 61: %zd\n", (intmax_t)res); else fprintf(stderr, "success\n"); out: if (error) fprintf(stderr, "hadoofus error: %s\n", error); if (h) hdfs_namenode_delete(h); return 0; }
static void setup_buf(void) { const char *err = NULL; buf = malloc(towrite); ck_assert((intptr_t)buf); rbuf = malloc(towrite); ck_assert((intptr_t)rbuf); for (int i = 0; i < towrite; i++) { buf[i] = '0' + (i%10); rbuf[i] = 0; } h = hdfs_namenode_new(H_ADDR, "8020", H_USER, HDFS_NO_KERB, &err); ck_assert_msg((intptr_t)h, "Could not connect to %s=%s (port 8020): %s", HDFS_T_ENV, H_ADDR, err); }