/**
 *	Check on a background scan running on the server.
 *
 *	~~~~~~~~~~{.c}
 *	uint64_t scan_id = 1234;
 *	as_scan_info scan_info;
 *
 *	if ( aerospike_scan_info(&as, &err, NULL, &scan, scan_id, &scan_info) != AEROSPIKE_OK ) {
 *		fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
 *	}
 *	else {
 *		printf("Scan id=%ll, status=%s", scan_id, scan_info.status);
 *	}
 *	~~~~~~~~~~
 *
 *
 *	@param as			The aerospike instance to use for this operation.
 *	@param err			The as_error to be populated if an error occurs.
 *	@param policy		The policy to use for this operation. If NULL, then the default policy will be used.
 *	@param scan_id		The id for the scan job to check the status of.
 *	@param info			Information about this scan, to be populated by this operation.
 *
 *	@return AEROSPIKE_OK on success. Otherwise an error occurred.
 */
as_status aerospike_scan_info(
	aerospike * as, as_error * err, const as_policy_info * policy,
	uint64_t scan_id, as_scan_info * info
	)
{
	// Initialize the info...
	info->status = AS_SCAN_STATUS_UNDEF;
	info->progress_pct = 0;
	info->records_scanned = 0;

	bg_scan_info bsi;
	bsi.job_id_len = sprintf(bsi.job_id, "job_id=%" PRIu64 ":", scan_id);
	bsi.info = info;

	return aerospike_info_foreach(as, err, policy, "scan-list\n", scan_info_cb, (void *) &bsi);
}
/**
 *******************************************************************************************************
 * Sends an info request to all the nodes in a cluster.
 *
 * @param self                  AerospikeClient object
 * @param args                  The args is a tuple object containing an argument
 *                              list passed from Python to a C function
 * @param kwds                  Dictionary of keywords
 *
 * Returns a server response for the particular request string.
 * In case of error,appropriate exceptions will be raised.
 *******************************************************************************************************
 */
PyObject * AerospikeClient_Info(AerospikeClient * self, PyObject * args, PyObject * kwds)
{
	PyObject * py_req = NULL;
	PyObject * py_policy = NULL;
	PyObject * py_hosts = NULL;
	PyObject * py_nodes = NULL;
	PyObject * py_ustr = NULL;
	foreach_callback_info_udata info_callback_udata;

	static char * kwlist[] = {"command", "hosts", "policy", NULL};

	if ( PyArg_ParseTupleAndKeywords(args, kwds, "O|OO:info", kwlist, &py_req, &py_hosts, &py_policy) == false ) {
		return NULL;
	}

	as_error err;
	as_error_init(&err);

	as_policy_info info_policy;
	as_policy_info* info_policy_p = NULL;
	py_nodes = PyDict_New();
	info_callback_udata.udata_p = py_nodes;
	info_callback_udata.host_lookup_p = py_hosts;
	as_error_init(&info_callback_udata.error);

	if (!self || !self->as) {
		as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
		goto CLEANUP;
	}
	if (!self->is_conn_16) {
		as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster");
		goto CLEANUP;
	}

	// Convert python policy object to as_policy_info
	pyobject_to_policy_info(&err, py_policy, &info_policy, &info_policy_p,
					&self->as->config.policies.info);
	if ( err.code != AEROSPIKE_OK ) {
		goto CLEANUP;
	}
	char * req = NULL;
	if ( PyUnicode_Check(py_req)) {
		py_ustr = PyUnicode_AsUTF8String(py_req);
		req = PyStr_AsString(py_ustr);
	} else if( PyStr_Check(py_req) ) {
		req = PyStr_AsString(py_req);
	} else {
		as_error_update(&err, AEROSPIKE_ERR_PARAM, "Request must be a string");
		goto CLEANUP;
	}
	aerospike_info_foreach(self->as, &err, info_policy_p, req,
					(aerospike_info_foreach_callback)AerospikeClient_Info_each,
					&info_callback_udata);

	if (&info_callback_udata.error.code != AEROSPIKE_OK) {
		as_error_update(&err, err.code, NULL);
		goto CLEANUP;
	}
CLEANUP:
	if (py_ustr) {
		Py_DECREF(py_ustr);
	}
	if ( info_callback_udata.error.code != AEROSPIKE_OK ) {
		PyObject * py_err = NULL;
		error_to_pyobject(&info_callback_udata.error, &py_err);
		PyObject *exception_type = raise_exception(&info_callback_udata.error);
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		if (py_nodes) {
			Py_DECREF(py_nodes);
		}
		return NULL;
	}
	if ( err.code != AEROSPIKE_OK ) {
		PyObject * py_err = NULL;
		error_to_pyobject(&err, &py_err);
		PyObject *exception_type = raise_exception(&err);
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		if (py_nodes) {
			Py_DECREF(py_nodes);
		}
		return NULL;
	}

	return info_callback_udata.udata_p;
}
示例#3
0
 *****************************************************************************/

TEST( info_basics_help , "help" ) {

	as_error err;
	as_error_reset(&err);

	info_data data = {
		.actual = NULL,
		.matches = 0,
		.count = 0
	};

	as_status rc = AEROSPIKE_OK;

	rc = aerospike_info_foreach(as, &err, NULL, "help", info_compare, &data);
	
	assert_int_eq( rc, AEROSPIKE_OK );
	assert( data.count > 0 );
	assert( data.matches > 0 );
	assert( data.count == data.matches );

	char * res = NULL;

	rc = aerospike_info_host(as, &err, NULL, g_host, 3000, "help", &res);
	
	assert_not_null( res );
	assert_string_eq(res, data.actual);

	free(res);
	res = NULL;
示例#4
0
/* {{{ proto array Aerospike::infoMany( string request, [, array config [, array options ]] )
    Sends an info command to several or all cluster nodes */
PHP_METHOD(Aerospike, infoMany) {

	as_error err;
	as_error_init(&err);
	reset_client_error(getThis());

	char* request = NULL;
	size_t request_len;
	zval* z_policy = NULL;
	HashTable* filter_hosts = NULL;
	zval* cb_filter_zval = NULL;
	HashTable* cb_filter_hosts = NULL;

	as_policy_info info_policy;
	as_policy_info* info_policy_p = NULL;
	AerospikeClient* php_client = NULL;
	aerospike* as_client = NULL;

	info_each_cb_data cb_data;

	if (check_object_and_connection(getThis(), &err) != AEROSPIKE_OK) {
		update_client_error(getThis(), err.code, err.message, err.in_doubt);
		RETURN_NULL();
	}
	php_client = get_aerospike_from_zobj(Z_OBJ_P(getThis()));
	as_client = php_client->as_client;


	if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|h!z", &request,
			&request_len, &filter_hosts, &z_policy ) == FAILURE) {
		update_client_error(getThis(), AEROSPIKE_ERR_PARAM, "Invalid parameters for infoMany.", false);
		RETURN_NULL();
	}

	if (filter_hosts) {
		if (!is_valid_hosts_list(filter_hosts)) {
			update_client_error(getThis(), AEROSPIKE_ERR_PARAM, "Invalid list of hosts.", false);
			RETURN_NULL();
		}
		cb_filter_zval = zend_hash_str_find(filter_hosts, "hosts", strlen("hosts"));
		if (!cb_filter_zval || Z_TYPE_P(cb_filter_zval) != IS_ARRAY) {
			update_client_error(getThis(), AEROSPIKE_ERR_PARAM, "Invalid list of hosts.", false);
			RETURN_NULL();
		}
		cb_filter_hosts = Z_ARRVAL_P(cb_filter_zval);
	}

	if (z_policy){
		if (zval_to_as_policy_info(z_policy, &info_policy,
				&info_policy_p, &as_client->config.policies.info) != AEROSPIKE_OK) {
			update_client_error(getThis(), AEROSPIKE_ERR_PARAM, "Invalid policy for infoMany.", false);
			RETURN_NULL();
		}
		info_policy_p = &info_policy;
	}

	array_init(return_value);
	cb_data.err = &err;
	cb_data.response_array = return_value;
	cb_data.filter_hosts = cb_filter_hosts;

	aerospike_info_foreach(as_client, &err, info_policy_p, request,
			(aerospike_info_foreach_callback)AerospikeClient_Info_each, (void*)&cb_data);

	if (err.code != AEROSPIKE_OK) {
		update_client_error(getThis(), err.code, err.message, err.in_doubt);
		zval_dtor(return_value);
		RETURN_NULL();
	}
	return;
}
示例#5
0
static PyObject * AerospikeClient_InfoAll_Invoke(AerospikeClient * self, PyObject* py_request, PyObject* py_policy) {
	PyObject * py_nodes = NULL;
	PyObject * py_ustr = NULL;
	foreach_callback_info_udata info_callback_udata;

	as_error err;
	as_error_init(&err);

	as_policy_info info_policy;
	as_policy_info* info_policy_p = NULL;
	py_nodes = PyDict_New();
	info_callback_udata.udata_p = py_nodes;
	info_callback_udata.host_lookup_p = NULL;
	as_error_init(&info_callback_udata.error);

	if (!self || !self->as) {
		as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
		goto CLEANUP;
	}
	if (!self->is_conn_16) {
		as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster");
		goto CLEANUP;
	}

	// Convert python policy object to as_policy_info
	pyobject_to_policy_info(&err, py_policy, &info_policy, &info_policy_p,
					&self->as->config.policies.info);
	if (err.code != AEROSPIKE_OK) {
		goto CLEANUP;
	}

	char * request = NULL;
	if (PyUnicode_Check(py_request)) {
		py_ustr = PyUnicode_AsUTF8String(py_request);
		request = PyBytes_AsString(py_ustr);
	} else if (PyString_Check(py_request)) {
		request = PyString_AsString(py_request);
	} else {
		as_error_update(&err, AEROSPIKE_ERR_PARAM, "Request must be a string");
		goto CLEANUP;
	}

	Py_BEGIN_ALLOW_THREADS
	aerospike_info_foreach(self->as, &err, info_policy_p, request,
					(aerospike_info_foreach_callback)AerospikeClient_InfoAll_each,
					&info_callback_udata);
	Py_END_ALLOW_THREADS

	if (&info_callback_udata.error.code != AEROSPIKE_OK) {
		as_error_update(&err, err.code, NULL);
		goto CLEANUP;
	}
CLEANUP:
	if (py_ustr) {
		Py_DECREF(py_ustr);
	}
	if (info_callback_udata.error.code != AEROSPIKE_OK) {
		PyObject * py_err = NULL;
		error_to_pyobject(&info_callback_udata.error, &py_err);
		PyObject *exception_type = raise_exception(&info_callback_udata.error);
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		if (py_nodes) {
			Py_DECREF(py_nodes);
		}
		return NULL;
	}
	if (err.code != AEROSPIKE_OK) {
		PyObject * py_err = NULL;
		error_to_pyobject(&err, &py_err);
		PyObject *exception_type = raise_exception(&err);
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		if (py_nodes) {
			Py_DECREF(py_nodes);
		}
		return NULL;
	}

	return info_callback_udata.udata_p;
}