Example #1
0
void *
athread(void *v)
{
	struct hdfs_namenode *nn;

	struct hdfs_object *rpc;
	struct hdfs_object *object;

	const char *error;

	struct hdfs_rpc_response_future futures[100];
	unsigned i;

	bool ok;

	nn = v;

	// getProtocolVersion(61)
	rpc = hdfs_rpc_invocation_new(
	    "getProtocolVersion",
	    hdfs_string_new(HADOOFUS_CLIENT_PROTOCOL_STR),
	    hdfs_long_new(61),
	    NULL);

	for (i = 0; i < 100; i++) {
		futures[i] = HDFS_RPC_RESPONSE_FUTURE_INITIALIZER;
		error = hdfs_namenode_invoke(nn, rpc, &futures[i]);
		if (error) {
			warnx("namenode_invoke: %s", error);
			goto out;
		}
	}

	for (i = 0; i < 100; i++) {
		// Get the response (should be long(61))
		ok = hdfs_future_get_timeout(&futures[i], &object, 2000/*ms*/);
		if (!ok) {
			warnx("timeout waiting for result from NN server");
			continue;
		}

		if (object->ob_type != H_LONG ||
		    object->ob_val._long._val != 61L)
			printf("bad result\n");

		hdfs_object_free(object);
	}

out:
	hdfs_object_free(rpc);
	return NULL;
}
Example #2
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;
}