#include #include #include int main() { ndb_mgm_node_state *ns; ndb_mgm_cluster_state *cs; ndb_mgm_node_type *types; int i, no = 0; int *nodes; int notypes = 0, nonodes = 0; // Not checking for errors, connect to localhost:1186 NdbMgmHandle handle = ndb_mgm_create_handle(); ndb_mgm_set_timeout(handle, 500); ndb_mgm_connect(handle, 0, 0, 0); // Get status from both data nodes and management nodes notypes = 1; types = (ndb_mgm_node_type*)malloc(sizeof(ndb_mgm_node_type)*notypes+1); types[0] = NDB_MGM_NODE_TYPE_NDB; //types[1] = NDB_MGM_NODE_TYPE_MGM; types[notypes] = NDB_MGM_NODE_TYPE_UNKNOWN; // We only stop 1 data node, in this case NodeId=2 nonodes = 1; nodes = (int*)malloc(sizeof(int)*nonodes); nodes[0] = 2; // Test: get status, stop node, get status again printf("Getting status\n"); cs = ndb_mgm_get_status2(handle, types); if (cs == NULL) { printf("%s (%d)\n", ndb_mgm_get_latest_error_msg(handle), ndb_mgm_get_latest_error(handle)); } else { for( i=0; i < cs->no_of_nodes; i++ ) { ns = cs->node_states + i; printf("Node ID: %d status:%d\n", ns->node_id, ns->node_status); } } printf("Stopping data node\n"); no = ndb_mgm_stop(handle, nonodes, nodes); printf("Stopped %d data node(s)\n", no); printf("Getting status\n"); cs = ndb_mgm_get_status2(handle, types); if (cs == NULL) { printf("%s (%d)\n", ndb_mgm_get_latest_error_msg(handle), ndb_mgm_get_latest_error(handle)); } else { for( i=0; i < cs->no_of_nodes; i++ ) { ns = cs->node_states + i; printf("Node ID: %d status:%d\n", ns->node_id, ns->node_status); } } free(nodes); free(types); ndb_mgm_disconnect(handle); ndb_end(0); }