00001 #include "Basis/String.h"
00002 #include "Basis/CmdOptions.h"
00003 #include "Job/Runner.h"
00004
00005
00006 #include "Link/ImpalaLib.cpp"
00007
00008 namespace Impala
00009 {
00010 namespace Application
00011 {
00012
00013 int
00014 mainJobRunner(int argc, char* argv[])
00015 {
00016 CmdOptions& options = CmdOptions::GetInstance();
00017 options.Initialise(false, false, true);
00018 String usageStr = "jobServerAddress \n\n";
00019 options.AddOption(0, "maxJobs", "nr", "0");
00020 options.AddOption(0, "maxIdle", "sec", "0");
00021 options.AddOption(0, "maxJobTime", "min", "0");
00022 options.AddOption(0, "sleepIntervalSec", "sec", "10");
00023 options.AddOption(0, "poisonServer", "", "0");
00024 options.AddOption(0, "stopServer", "", "0");
00025 options.AddOption(0, "cmdLineExtension", "string", "");
00026 if (! options.ParseArgs(argc, argv, usageStr, 1))
00027 return 1;
00028
00029 ILOG_VAR(Impala.Application.mainJobRunner);
00030
00031 String serverAddr = options.GetArg(0);
00032
00033 int colonPos = serverAddr.find(":");
00034 if (colonPos <= 0)
00035 {
00036 ILOG_ERROR("Not a valid server address (port number is missing): " <<
00037 serverAddr);
00038 return 2;
00039 }
00040 int port = atol(serverAddr.substr(colonPos + 1));
00041 serverAddr = serverAddr.substr(0, colonPos);
00042
00043 int maxJobs = options.GetInt("maxJobs");
00044 int maxIdleTimeSec = options.GetInt("maxIdle");
00045 int maxJobTime = options.GetInt("maxJobTime");
00046 int sleepIntervalSec = options.GetInt("sleepIntervalSec");
00047 String passwordFile = options.GetString("passwordFile");
00048 String cmdLineExtension = options.GetString("cmdLineExtension");
00049
00050 bool poisonServer = options.GetBool("poisonServer");
00051 bool stopServer = options.GetBool("stopServer");
00052
00053
00054 Job::Runner jobRunner;
00055 if (jobRunner.Connect(serverAddr, port, passwordFile))
00056 {
00057 if (stopServer)
00058 jobRunner.StopServer();
00059 else if (poisonServer)
00060 jobRunner.PoisonServer();
00061 else
00062 {
00063 jobRunner.RunJobs(maxJobs, maxIdleTimeSec, maxJobTime,
00064 sleepIntervalSec, cmdLineExtension);
00065 jobRunner.Disconnect();
00066 }
00067 }
00068
00069 const std::list<String>& jobsDone = jobRunner.GetJobList();
00070
00071
00072
00073
00074
00075
00076 int jobCount = jobsDone.size();
00077 ILOG_INFO("Jobs run: " << jobCount);
00078 }
00079
00080 }
00081 }
00082
00083 int
00084 main(int argc, char* argv[])
00085 {
00086 return Impala::Application::mainJobRunner(argc, argv);
00087 }