/** ****************************************************************************************************** * Returns data about a particular node in the database depending upon the request string. * * @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 information about a host. ********************************************************************************************************/ PyObject * AerospikeClient_InfoNode(AerospikeClient * self, PyObject * args, PyObject * kwds) { PyObject * py_host = NULL; PyObject * py_policy = NULL; PyObject * py_request = NULL; static char * kwlist[] = {"command", "host", "policy", NULL}; if ( PyArg_ParseTupleAndKeywords(args, kwds, "OO|O:info_node", kwlist, &py_request, &py_host, &py_policy) == false ) { return NULL; } return AerospikeClient_InfoNode_Invoke(self, py_request, py_host, py_policy); }
/** ****************************************************************************************************** * Returns data about the nodes to AerospikeClient_GetNodes. * * @param self AerospikeClient object * * Returns a list containing the details of the nodes. ********************************************************************************************************/ static PyObject * AerospikeClient_GetNodes_Invoke( AerospikeClient * self) { PyObject * response_services_p = NULL; PyObject * response_service_p = NULL; PyObject * nodes_tuple[MAX_HOST_COUNT] = {0}; PyObject * return_value = PyList_New(0); 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; } PyObject * py_req_str = NULL; py_req_str = PyString_FromString("services"); response_services_p = AerospikeClient_InfoNode_Invoke(self, py_req_str, NULL, NULL); Py_DECREF(py_req_str); if(!response_services_p) { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "Services call returned an error"); goto CLEANUP; } py_req_str = PyString_FromString("service"); response_service_p = AerospikeClient_InfoNode_Invoke(self, py_req_str, NULL, NULL); Py_DECREF(py_req_str); if(!response_service_p) { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "Service call returned an error"); goto CLEANUP; } return_value = AerospikeClient_GetNodes_Returnlist(&err, response_service_p, nodes_tuple, return_value, 0, 0); if( return_value ) return_value = AerospikeClient_GetNodes_Returnlist(&err, response_services_p, nodes_tuple, return_value, 1, 1); CLEANUP: if(response_services_p) { Py_DECREF(response_services_p); } if(response_service_p) { Py_DECREF(response_service_p); } 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 return_value; }
/** ****************************************************************************************************** * Iterates over the hosts in the cluster and creates the list to be returned to the python client. * * @param err as_error object * @param command Request string sent from the python client * @param nodes_tuple List containing details of each host * @param return_value List t o be returned back to the python client * @param host_index Index of the list nodes_tuple * @param index Index of the list to be returned. * * Returns information about a host. ********************************************************************************************************/ static PyObject * AerospikeClient_GetNodes_Returnlist(as_error* err, PyObject * command, PyObject * nodes_tuple[], PyObject * return_value, uint32_t host_index, Py_ssize_t index) { char* tok = NULL; char* saved = NULL; PyObject * value_tok = NULL; bool break_flag = false; tok = strtok_r(PyStr_AsString(command), INFO_REQUEST_RESPONSE_DELIMITER, &saved); if (tok == NULL) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Unable to get addr in service"); goto CLEANUP; } while (tok != NULL && (host_index < MAX_HOST_COUNT)) { tok = strtok_r(NULL, IP_PORT_DELIMITER, &saved); #if defined(__APPLE__) if (tok == NULL || saved == NULL) { #else if (tok == NULL || *saved == '\0') { #endif goto CLEANUP; } nodes_tuple[host_index] = PyTuple_New(2); value_tok = PyStr_FromString(tok); PyTuple_SetItem(nodes_tuple[host_index], 0 , value_tok); //Py_DECREF(value_tok); if(strcmp(PyStr_AsString(command),"response_services_p")) { tok = strtok_r(NULL, HOST_DELIMITER, &saved); if (tok == NULL) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Unable to get port"); goto CLEANUP; } if (strstr(tok, INFO_RESPONSE_END)) { tok = strtok_r(tok, INFO_RESPONSE_END, &saved); break_flag = true; } } else { tok = strtok_r(NULL, INFO_RESPONSE_END, &saved); if (tok == NULL) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Unable to get port in service"); goto CLEANUP; } } value_tok = PyInt_FromString(tok, NULL, 10); PyTuple_SetItem(nodes_tuple[host_index], 1 , value_tok); PyList_Insert(return_value, index , nodes_tuple[host_index]); Py_DECREF(nodes_tuple[host_index]); index++; host_index++; if (break_flag == true) { goto CLEANUP; } } CLEANUP: 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 return_value; } /** ****************************************************************************************************** * Returns data about the nodes to AerospikeClient_GetNodes. * * @param self AerospikeClient object * * Returns a list containing the details of the nodes. ********************************************************************************************************/ static PyObject * AerospikeClient_GetNodes_Invoke( AerospikeClient * self) { PyObject * response_services_p = NULL; PyObject * response_service_p = NULL; PyObject * nodes_tuple[MAX_HOST_COUNT] = {0}; PyObject * return_value = PyList_New(0); 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; } PyObject * py_req_str = NULL; py_req_str = PyStr_FromString("services"); response_services_p = AerospikeClient_InfoNode_Invoke(self, py_req_str, NULL, NULL); Py_DECREF(py_req_str); if(!response_services_p) { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "Services call returned an error"); goto CLEANUP; } py_req_str = PyStr_FromString("service"); response_service_p = AerospikeClient_InfoNode_Invoke(self, py_req_str, NULL, NULL); Py_DECREF(py_req_str); if(!response_service_p) { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "Service call returned an error"); goto CLEANUP; } return_value = AerospikeClient_GetNodes_Returnlist(&err, response_service_p, nodes_tuple, return_value, 0, 0); if( return_value ) return_value = AerospikeClient_GetNodes_Returnlist(&err, response_services_p, nodes_tuple, return_value, 1, 1); CLEANUP: if(response_services_p) { Py_DECREF(response_services_p); } if(response_service_p) { Py_DECREF(response_service_p); } 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 return_value; }