21 #include <AtrtClient.hpp>
28 for (
size_t i = 0;
i<config.m_clusters.size();
i++)
30 if (strcmp(config.m_clusters[
i]->m_name.c_str(),
".atrt") == 0)
32 cluster = config.m_clusters[
i];
34 for (
size_t i = 0;
i<cluster->m_processes.size();
i++)
36 if (cluster->m_processes[
i]->m_type == atrt_process::AP_CLIENT)
45 return &f_mysqld->m_mysql;
57 ack_command(
AtrtClient& atrtdb,
int command_id,
const char* state)
60 sql.
assfmt(
"UPDATE command SET state = '%s' WHERE id = %d",
62 return atrtdb.doQuery(sql);
80 for (
int i=0;
i < assignmentCount;
i++)
83 int termCount = assignments[
i].split(terms,
BaseString(
"="));
87 if (strcmp(name.
c_str(), terms[0].c_str()) == 0)
115 uint process_id= command.columnAsInt(
"process_id");
116 const char* process_args= command.column(
"process_args");
118 g_logger.
info(
"Change version for process: %d, args: %s",
119 process_id, process_args);
122 if (process_id > config.m_processes.size()){
123 g_logger.
critical(
"Invalid process id %d", process_id);
128 const char* new_prefix= g_prefix1 ? g_prefix1 : g_prefix;
129 const char* old_prefix= g_prefix;
130 const char *start= strstr(proc.m_proc.m_path.
c_str(), old_prefix);
136 if (strstr(proc.m_proc.m_path.
c_str(), new_prefix))
142 g_logger.
info(
"Process already upgraded");
146 g_logger.
critical(
"Could not find '%s' in '%s'",
147 old_prefix, proc.m_proc.m_path.
c_str());
152 if (proc.m_save.m_saved ==
false)
154 proc.m_save.m_proc= proc.m_proc;
155 proc.m_save.m_saved=
true;
158 g_logger.
info(
"stopping process...");
159 if (!stop_process(proc))
161 BaseString newEnv = set_env_var(proc.m_proc.m_env,
164 proc.m_proc.m_env.
assign(newEnv);
167 if (process_args && strlen(process_args))
170 proc.m_proc.m_args.
append(
" ");
171 proc.m_proc.m_args.
append(process_args);
174 ndbout << proc << endl;
176 g_logger.
info(
"starting process...");
177 if (!start_process(proc))
187 uint process_id= command.columnAsInt(
"process_id");
188 g_logger.
info(
"Reset process: %d", process_id);
191 if (process_id > config.m_processes.size()){
192 g_logger.
critical(
"Invalid process id %d", process_id);
197 g_logger.
info(
"stopping process...");
198 if (!stop_process(proc))
201 if (proc.m_save.m_saved)
203 ndbout <<
"before: " << proc << endl;
205 proc.m_proc= proc.m_save.m_proc;
206 proc.m_save.m_saved=
false;
207 proc.m_proc.m_id= -1;
209 ndbout <<
"after: " << proc << endl;
214 ndbout <<
"process has not changed" << endl;
217 g_logger.
info(
"starting process...");
218 if (!start_process(proc))
231 MYSQL* mysql= find_atrtdb_client(config);
237 if (!atrtdb.doQuery(
"SELECT * FROM command " \
238 "WHERE state = 'new' ORDER BY id LIMIT 1", command)){
243 if (command.numRows() == 0)
246 uint
id= command.columnAsInt(
"id");
247 uint cmd= command.columnAsInt(
"cmd");
248 g_logger.
info(
"Got command, id: %d, cmd: %d",
id, cmd);
252 if (!ack_command(atrtdb,
id,
"running"))
256 case AtrtClient::ATCT_CHANGE_VERSION:
257 if (!do_change_version(config, command, atrtdb))
261 case AtrtClient::ATCT_RESET_PROC:
262 if (!do_reset_proc(config, command, atrtdb))
268 g_logger.
error(
"got unknown command: %d", cmd);
273 if (!ack_command(atrtdb,
id,
"done"))
276 g_logger.
info(
"done!");