/****************************************************************************** * STATIC FUNCTIONS *****************************************************************************/ static bool is_ldt_enabled() { char* res = NULL; as_error err; int rc = aerospike_info_host(as, &err, NULL, g_host, 3000, INFO_CALL, &res); if (rc == AEROSPIKE_OK) { char *st = strstr(res, "ldt-enabled=true"); free(res); if (st) { return true; } } return false; }
// ---------------------------------------------------------------------------------- // // execute info command // http://www.aerospike.com/docs/reference/info/ // // def info_cmd(cmd) // // params: // cmd - string, info command to execute // // ------ // RETURN: // 1. msg from server // // @TODO options policy // static VALUE info_cmd(VALUE self, VALUE cmd) { rb_aero_TIMED(tm); as_error err; aerospike * as = rb_aero_CLIENT; char * res = NULL; VALUE host = rb_iv_get(self, "@host"); VALUE port = rb_iv_get(self, "@port"); if ( aerospike_info_host(as, &err, NULL, StringValueCStr(host), FIX2INT(port), StringValueCStr(cmd), &res) != AEROSPIKE_OK ) { raise_as_error(err); } VALUE info_res = rb_str_new2(res); free(res); rb_aero_logger(AS_LOG_LEVEL_DEBUG, &tm, 1, rb_str_new2("[Client][info_cmd] done")); return info_res; }
.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; if ( data.actual ) { free(data.actual); } } TEST( info_basics_features , "features" ) { as_error err;
/* {{{ proto int Aerospike::info( string request, string &response [, array host [, array options ]] ) Sends an info command to a cluster node */ PHP_METHOD(Aerospike, info) { as_error err; as_error_init(&err); reset_client_error(getThis()); char* request = NULL; size_t request_len; zval* response_zval = NULL; zval* z_policy = NULL; as_host* host = NULL; char* host_str = NULL; uint16_t port_number; char* response_str = NULL; HashTable* destination_host = NULL; zval* host_zval = NULL; zval* port_zval = NULL; as_policy_info info_policy; as_policy_info* info_policy_p = NULL; AerospikeClient* php_client = NULL; aerospike* as_client = NULL; if (check_object_and_connection(getThis(), &err) != AEROSPIKE_OK) { update_client_error(getThis(), err.code, err.message, err.in_doubt); RETURN_LONG(err.code); } php_client = get_aerospike_from_zobj(Z_OBJ_P(getThis())); as_client = php_client->as_client; host = (as_host *)as_vector_get(as_client->config.hosts, 0); host_str = host->name; port_number = host->port; if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz/|h!z", &request, &request_len, &response_zval, &destination_host, &z_policy) == FAILURE) { update_client_error(getThis(),AEROSPIKE_ERR_PARAM, "Invalid arguments to info", false); RETURN_LONG(AEROSPIKE_ERR_PARAM); } /* Cleanup any thing held by the return parameter */ zval_dtor(response_zval); ZVAL_NULL(response_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.", false); RETURN_LONG(AEROSPIKE_ERR_PARAM); } info_policy_p = &info_policy; } // addr hostname or IP of the node // port /* This should be of the form ['addr'=>'hostname', 'port'=>3000] */ if (destination_host) { host_zval = zend_hash_str_find(destination_host, "addr", strlen("addr")); if (!host_zval) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Host entry must contain an addr"); goto CLEANUP; } if (Z_TYPE_P(host_zval) != IS_STRING) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "addr entry must be a string"); goto CLEANUP; } host_str = Z_STRVAL_P(host_zval); port_zval = zend_hash_str_find(destination_host, "port", strlen("port")); if (!port_zval) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Host entry must contain a port"); goto CLEANUP; } if (Z_TYPE_P(port_zval) != IS_LONG) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "port entry must be an integer"); goto CLEANUP; } port_number = (uint16_t)Z_LVAL_P(port_zval); } if (aerospike_info_host(as_client, &err, info_policy_p, host_str, port_number, request, &response_str) != AEROSPIKE_OK) { goto CLEANUP; } /* It is possible that an empty response will be returned, so only setup the return * if we get one back. */ if (response_str) { ZVAL_STRING(response_zval, response_str); } CLEANUP: if (err.code != AEROSPIKE_OK) { update_client_error(getThis(), err.code, err.message, err.in_doubt); } if (response_str) { free(response_str); } RETURN_LONG(err.code); }
/** ****************************************************************************************************** * Returns data for a particular request string to AerospikeClient_InfoNode * * @param self AerospikeClient object * @param request_str_p Request string sent from the python client * @param py_host Optional host sent from the python client * @param py_policy The policy sent from the python client * * Returns information about a host. ********************************************************************************************************/ static PyObject * AerospikeClient_InfoNode_Invoke( AerospikeClient * self, PyObject * py_request_str, PyObject * py_host, PyObject * py_policy) { PyObject * py_response = NULL; PyObject * py_ustr = NULL; PyObject * py_ustr1 = NULL; as_policy_info info_policy; as_policy_info* info_policy_p = NULL; char* address = (char *) self->as->config.hosts[0].addr; long port_no = self->as->config.hosts[0].port; char* response_p = NULL; as_status status = AEROSPIKE_OK; as_error err; as_error_init(&err); 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; } if (py_policy) { if( PyDict_Check(py_policy) ) { pyobject_to_policy_info(&err, py_policy, &info_policy, &info_policy_p, &self->as->config.policies.info); if (err.code != AEROSPIKE_OK) { goto CLEANUP; } } else { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Policy should be a dictionary"); goto CLEANUP; } } if ( py_host ) { if ( PyTuple_Check(py_host) && PyTuple_Size(py_host) == 2) { PyObject * py_addr = PyTuple_GetItem(py_host,0); PyObject * py_port = PyTuple_GetItem(py_host,1); if ( PyString_Check(py_addr) ) { address = PyString_AsString(py_addr); } else if (PyUnicode_Check(py_addr)) { py_ustr = PyUnicode_AsUTF8String(py_addr); address = PyString_AsString(py_ustr); } if ( PyInt_Check(py_port) ) { port_no = (uint16_t) PyInt_AsLong(py_port); } else if ( PyLong_Check(py_port) ) { port_no = (uint16_t) PyLong_AsLong(py_port); } } else if ( !PyTuple_Check(py_host)){ as_error_update(&err, AEROSPIKE_ERR_PARAM, "Host should be a specified in form of Tuple."); goto CLEANUP; } } char * request_str_p = NULL; if (PyUnicode_Check(py_request_str)) { py_ustr1 = PyUnicode_AsUTF8String(py_request_str); request_str_p = PyString_AsString(py_ustr1); } else if (PyString_Check(py_request_str)) { request_str_p = PyString_AsString(py_request_str); } else { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Request should be of string type"); goto CLEANUP; } status = aerospike_info_host(self->as, &err, info_policy_p, (const char *) address, (uint16_t) port_no, request_str_p, &response_p); if( err.code == AEROSPIKE_OK ) { if (response_p && status == AEROSPIKE_OK){ py_response = PyString_FromString(response_p); free(response_p); } else if ( response_p == NULL){ as_error_update(&err, AEROSPIKE_ERR_CLIENT, "Invalid info operation"); goto CLEANUP; } else if ( status != AEROSPIKE_OK ){ as_error_update(&err, status, "Info operation failed"); goto CLEANUP; } } else { as_error_update(&err, err.code, NULL); goto CLEANUP; } CLEANUP: if (py_ustr) { Py_DECREF(py_ustr); } if (py_ustr1) { Py_DECREF(py_ustr1); } 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); return NULL; } return py_response; }