Esempio n. 1
0
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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
static void
teardown_buf(void)
{
	hdfs_namenode_delete(h);
	h = NULL;

	free(buf);
	buf = NULL;
	free(rbuf);
	rbuf = NULL;
}
Esempio n. 4
0
/**
 * hdfsDisconnect - Disconnect from the hdfs file system.
 *
 * @param fs The configured filesystem handle.
 * @return Returns 0 on success, -1 on error.
 */
int
hdfsDisconnect(hdfsFS fs)
{
	struct hdfsFS_internal *client = fs;

	hdfs_namenode_delete(client->fs_namenode);
	free(client->fs_cwd);
	free(client->fs_uri);
	free(client);

	return 0;
}
Esempio n. 5
0
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;
}
Esempio n. 6
0
int
main(int argc, char **argv)
{
	int64_t proto_ver;
	struct hdfs_error error;
	struct hdfs_namenode *nn;
	struct hdfs_object *exception = NULL;
	bool success = true;
	Suite *(*suites[])(void) = {
		t_hl_rpc_basics_suite,
		t_hl_rpc2_basics_suite,
		t_datanode_basics_suite,
		t_datanode2_basics_suite,
		t_unit,
	};
	int rc;

	if (!getenv(HDFS_T_ENV))
		errx(EXIT_FAILURE,
		    "Please set %s to an HDFS host before running tests!",
		    HDFS_T_ENV);

	rc = sasl_client_init(NULL);
	assert(rc == SASL_OK);

	H_ADDR = strdup(getenv(HDFS_T_ENV));
	assert(H_ADDR);

	if (getenv(HDFS_T_USER)) {
		H_USER = strdup(getenv(HDFS_T_USER));
		assert(H_USER);
	}

	// Test basic connectivity
	nn = hdfs_namenode_new_version(H_ADDR, "8020", "root", HDFS_NO_KERB,
	    HDFS_NN_v1, &error);
	if (!nn)
		errx(EXIT_FAILURE,
		    "Could not connect to namenode %s: %s",
		    H_ADDR, format_error(error));

	// And verify liveness at a protocol level
	proto_ver = hdfs_getProtocolVersion(nn, HADOOFUS_CLIENT_PROTOCOL_STR,
	    61L, &exception);
	if (exception)
		errx(EXIT_FAILURE,
		    "getProtocolVersion failed: %s",
		    hdfs_exception_get_message(exception));
	if (proto_ver != 61L)
		errx(EXIT_FAILURE,
		    "Got unexpected protocol version: %ld", proto_ver);

	hdfs_namenode_delete(nn);

	// Find and run all tests
	for (size_t i = 0; i < nelem(suites); i++) {
		Suite *s = suites[i]();
		SRunner *sr = srunner_create(s);

		srunner_run_all(sr, CK_NORMAL);

		if (srunner_ntests_failed(sr) > 0)
			success = false;

		srunner_free(sr);
	}

	if (success)
		return EXIT_SUCCESS;
	return EXIT_FAILURE;
}
Esempio n. 7
0
static void
teardown(void)
{
	hdfs_namenode_delete(h);
	h = NULL;
}