19 #include <AtrtClient.hpp>
20 #include <NDBT_Output.hpp>
24 AtrtClient::AtrtClient(
const char* _group_suffix)
25 :
DbUtil(
"atrt", _group_suffix)
30 AtrtClient::AtrtClient(
MYSQL* mysql)
36 AtrtClient::~AtrtClient(){
41 AtrtClient::writeCommand(AtrtCommandType _type,
47 sql.
assfmt(
"INSERT command ( ");
52 while((name= iter.next())){
57 sql.
appfmt(
" state, cmd) VALUES (");
61 while((name= iter.next())){
65 args.getTypeOf(name, &t);
67 case PropertiesType_Uint32:
68 args.get(name, &val_i);
71 case PropertiesType_char:
72 args.get(name, val_s);
82 sql.
appfmt(
"'new', %d)", _type);
87 return (
int)mysql_insert_id(m_mysql);
92 AtrtClient::readCommand(uint command_id,
95 args.
put(
"0", command_id);
96 return runQuery(
"SELECT * FROM command WHERE id = ?",
103 AtrtClient::doCommand(AtrtCommandType
type,
106 int running_timeout= 10;
107 int total_timeout= 120;
108 int commandId= writeCommand(type,
110 if (commandId == -1){
111 g_err <<
"Failed to write command" << endl;
118 if (!readCommand(commandId, result))
121 g_err <<
"Failed to read command "<< commandId << endl;
130 if (state ==
"done") {
135 if (!running_timeout--){
136 g_err <<
"Timeout while waiting for command "
137 << commandId <<
" to start run" << endl;
141 else if (!total_timeout--){
142 g_err <<
"Timeout while waiting for result of command "
143 << commandId << endl;
148 NdbSleep_SecSleep(1);
156 AtrtClient::changeVersion(
int process_id,
157 const char* process_args){
159 args.
put(
"process_id", process_id);
160 args.
put(
"process_args", process_args);
161 return doCommand(ATCT_CHANGE_VERSION, args);
166 AtrtClient::resetProc(
int process_id){
168 args.
put(
"process_id", process_id);
169 return doCommand(ATCT_RESET_PROC, args);
174 AtrtClient::getConnectString(
int cluster_id,
SqlResultSet& result){
176 args.
put(
"0", cluster_id);
177 return doQuery(
"SELECT value as connectstring " \
178 "FROM cluster c, process p, host h, options o " \
179 "WHERE c.id=p.cluster_id AND p.host_id=h.id AND " \
180 "p.id=o.process_id AND c.id=? AND " \
181 "o.name='--ndb-connectstring=' AND type='ndb_mgmd'",
190 return runQuery(
"SELECT id, name FROM cluster WHERE name != '.atrt'",
197 AtrtClient::getMgmds(
int cluster_id,
SqlResultSet& result){
199 args.
put(
"0", cluster_id);
200 return runQuery(
"SELECT * FROM process WHERE cluster_id=? and type='ndb_mgmd'",
206 AtrtClient::getNdbds(
int cluster_id,
SqlResultSet& result){
208 args.
put(
"0", cluster_id);
209 return runQuery(
"SELECT * FROM process WHERE cluster_id=? and type='ndbd'",
221 if (NdbEnv_GetEnv(
"ATRT_PID", buf,
sizeof(buf)))