EXPORT_SYM struct hdfs_namenode * hdfs_namenode_new_version(const char *host, const char *port, const char *username, enum hdfs_kerb kerb_pref, enum hdfs_namenode_proto vers, const char **error_out) { const char *error; struct hdfs_namenode *h; h = hdfs_namenode_allocate(); hdfs_namenode_init(h, kerb_pref); hdfs_namenode_set_version(h, vers); error = hdfs_namenode_connect(h, host, port); if (error) goto out; error = hdfs_namenode_authenticate(h, username); if (error) goto out; out: if (error) { hdfs_namenode_delete(h); h = NULL; *error_out = error; } return h; }
int main(int argc, char **argv) { const char *error, *host = "localhost", *port = "8020"; struct hdfs_namenode namenode; #define NTHR 100 pthread_t threads[NTHR]; unsigned i; int rc; if (argc > 1) { if (strcmp(argv[1], "-h") == 0) { printf("Usage: ./helloworld [host [port]]\n"); exit(0); } host = argv[1]; if (argc > 2) port = argv[2]; } // Initialize the connection object and connect to the local namenode hdfs_namenode_init(&namenode, HDFS_NO_KERB); error = hdfs_namenode_connect(&namenode, host, port); if (error) goto out; // Pretend to be the user "root" error = hdfs_namenode_authenticate(&namenode, "root"); if (error) goto out; for (i = 0; i < NTHR; i++) { int rc; rc = pthread_create(&threads[i], NULL, athread, &namenode); if (rc != 0) { errno = rc; err(1, "pthread_create"); } } for (i = 0; i < NTHR; i++) { rc = pthread_join(threads[i], NULL); if (rc != 0) { errno = rc; err(1, "pthread_join"); } } out: if (error) fprintf(stderr, "hdfs error: %s\n", error); // Destroy any resources used by the connection hdfs_namenode_destroy(&namenode, NULL); return 0; }
int main(int argc, char **argv) { const char *err, *host = "localhost", *port = "8020"; struct hdfs_namenode namenode; struct hdfs_object *rpc; struct hdfs_rpc_response_future future; struct hdfs_object *object; if (argc > 1) { if (strcmp(argv[1], "-h") == 0) { printf("Usage: ./helloworld [host [port]]\n"); exit(0); } host = argv[1]; if (argc > 2) port = argv[2]; } // Initialize the connection object and connect to the local namenode hdfs_namenode_init(&namenode, HDFS_NO_KERB); err = hdfs_namenode_connect(&namenode, host, port); if (err) goto out; // Pretend to be the user "mapred" err = hdfs_namenode_authenticate(&namenode, "mapred"); if (err) goto out; // Call getProtocolVersion(61) future = HDFS_RPC_RESPONSE_FUTURE_INITIALIZER; rpc = hdfs_rpc_invocation_new( "getProtocolVersion", hdfs_string_new(HADOOFUS_CLIENT_PROTOCOL_STR), hdfs_long_new(61), NULL); err = hdfs_namenode_invoke(&namenode, rpc, &future); hdfs_object_free(rpc); if (err) goto out; // Get the response (should be long(61)) hdfs_future_get(&future, &object); if (object->ob_type == H_LONG && object->ob_val._long._val == 61L) printf("success\n"); else printf("bad result\n"); hdfs_object_free(object); out: if (err) fprintf(stderr, "hdfs error: %s\n", err); // Destroy any resources used by the connection hdfs_namenode_destroy(&namenode, NULL); return 0; }