#include #include #include #include #include int main (int argc, char* argv[]) { ndb_init(); NdbMgmHandle myHandle = ndb_mgm_create_handle(); //Set the connectstring to connect to mysql-cluster if ( ndb_mgm_set_connectstring(myHandle, "localhost:1186") ) { ndb_mgm_destroy_handle(&myHandle); return ndb_mgm_get_latest_error(myHandle); } //Connecting to ndb if (ndb_mgm_connect(myHandle, 5, 5, 1 )) { ndb_mgm_destroy_handle(&myHandle); return ndb_mgm_get_latest_error(myHandle); } //Getting cluster status ndb_mgm_cluster_state *myCluster = NULL; try { myCluster = ndb_mgm_get_status(myHandle); } catch(...) { ndb_mgm_disconnect(myHandle); ndb_mgm_destroy_handle(&myHandle); return ndb_mgm_get_latest_error(myHandle); } if (myCluster == NULL) { ndb_mgm_disconnect(myHandle); ndb_mgm_destroy_handle(&myHandle); return ndb_mgm_get_latest_error(myHandle); } //To check the status for all nodes into the cluster for(int cc=0; ccno_of_nodes; cc++) { ndb_mgm_node_state estadoNodos = myCluster->node_states[cc]; if (estadoNodos.node_type == NDB_MGM_NODE_TYPE_MGM) { printf("Node type [MGM] id [%d] group [%d] alive [%s]\n", estadoNodos.node_id, estadoNodos.node_group, (estadoNodos.version!=0)?"YES":"NO"); } else if (estadoNodos.node_type == NDB_MGM_NODE_TYPE_NDB) { printf("Node type [NDB] id [%d] group [%d] alive [%s]\n", estadoNodos.node_id, estadoNodos.node_group, (estadoNodos.version!=0)?"YES":"NO"); } else if (estadoNodos.node_type == NDB_MGM_NODE_TYPE_API) { printf("Node type [API] id [%d] group [%d] alive [%s]\n", estadoNodos.node_id, estadoNodos.node_group, (estadoNodos.version!=0)?"YES":"NO"); } } int ver_disc = ndb_mgm_disconnect(myHandle); printf("ver_disc [%d]\n", ver_disc); ndb_mgm_destroy_handle(&myHandle); ndb_end(0); }