34 ClassImp(TCondorSlave);
42 TCondor::TCondor(
const char *pool) : fPool(pool), fState(kFree)
48 TString condorHome = gEnv->GetValue(
"Proof.CondorHome", (
char*)0);
49 if (condorHome !=
"") {
50 TString path = gSystem->Getenv(
"PATH");
51 path = condorHome +
"/bin:" + path;
52 gSystem->Setenv(
"PATH",path);
55 TString condorConf = gEnv->GetValue(
"Proof.CondorConfig", (
char*)0);
56 if (condorConf !=
"") {
57 gSystem->Setenv(
"CONDOR_CONFIG",condorConf);
60 char *loc = gSystem->Which(gSystem->Getenv(
"PATH"),
"condor_cod",
77 PDB(kCondor,1) Info("~TCondor","fState %d", fState );
79 if (fState != kFree) {
89 void TCondor::Print(Option_t * opt)
const
91 std::cout <<
"OBJ: " << IsA()->GetName()
92 <<
"\tPool: \"" << fPool <<
"\""
93 <<
"\tState: " << fState << std::endl;
101 TCondorSlave *TCondor::ClaimVM(
const char *vm,
const char *cmd)
105 TString claimCmd = Form(
"condor_cod request -name %s -timeout 10 2>>%s/condor.proof.%d",
106 vm, gSystem->TempDirectory(), gSystem->GetUid() );
108 PDB(kCondor,2) Info("ClaimVM","command: %s", claimCmd.Data());
109 FILE *pipe = gSystem->OpenPipe(claimCmd, "r");
112 SysError(
"ClaimVM",
"cannot run command: %s", claimCmd.Data());
118 while (line.Gets(pipe)) {
119 PDB(kCondor,3) Info("ClaimVM","line = %s", line.Data());
121 if (line.BeginsWith("ClaimId = \"")) {
122 line.Remove(0, line.Index(
"\"")+1);
125 PDB(kCondor,1) Info("ClaimVM","claim = '%s'", claimId.Data());
126 TRegexp r("[0-9]*$");
127 TString num = line(r);
128 port = 37000 + atoi(num.Data());
129 PDB(kCondor,1) Info("ClaimVM","port = %d", port);
133 Int_t r = gSystem->ClosePipe(pipe);
135 Error(
"ClaimVM",
"command: %s returned %d", claimCmd.Data(), r);
138 PDB(kCondor,1) Info("ClaimVM","command: %s returned %d", claimCmd.Data(), r);
141 TString jobad("jobad");
142 FILE *jf = gSystem->TempFileName(jobad);
144 if (jf == 0) return 0;
147 str.ReplaceAll("$(Port)", Form("%d", port));
152 TString activateCmd = Form("condor_cod activate -
id '%s' -jobad %s",
153 claimId.Data(), jobad.Data() );
155 PDB(kCondor,2) Info("ClaimVM","command: %s", activateCmd.Data());
156 pipe = gSystem->OpenPipe(activateCmd, "r");
159 SysError(
"ClaimVM",
"cannot run command: %s", activateCmd.Data());
163 while (line.Gets(pipe)) {
164 PDB(kCondor,3) Info("ClaimVM","Activate: line = %s", line.Data());
167 r = gSystem->ClosePipe(pipe);
169 Error(
"ClaimVM",
"command: %s returned %d", activateCmd.Data(), r);
171 PDB(kCondor,1) Info("ClaimVM","command: %s returned %d", activateCmd.Data(), r);
174 gSystem->Unlink(jobad);
177 TCondorSlave *claim = new TCondorSlave;
178 claim->fClaimID = claimId;
180 node = node.Remove(0, node.Index("
@")+1);
181 claim->fHostname = node;
183 claim->fPerfIdx = 100; //set performance index to 100 by default
184 claim->fImage = node; //set image to hostname by default
194 TList *TCondor::GetVirtualMachines() const
196 TString poolopt = fPool ? Form("-pool %s", fPool.Data()) : "";
197 TString cmd = Form("condor_status %s -format \"%%s\\n\" Name", poolopt.Data());
199 PDB(kCondor,2) Info("GetVirtualMachines","command: %s", cmd.Data());
201 FILE *pipe = gSystem->OpenPipe(cmd, "r");
204 SysError(
"GetVirtualMachines",
"cannot run command: %s", cmd.Data());
209 TList *l =
new TList;
210 while (line.Gets(pipe)) {
211 PDB(kCondor,3) Info("GetVirtualMachines","line = %s", line.Data());
212 if (line != "") l->Add(new TObjString(line));
215 Int_t r = gSystem->ClosePipe(pipe);
218 Error(
"GetVirtualMachines",
"command: %s returned %d", cmd.Data(), r);
221 PDB(kCondor,1) Info("GetVirtualMachines","command: %s returned %d", cmd.Data(), r);
233 TList *TCondor::Claim(Int_t n, const
char *cmd)
235 if (fState != kFree) {
236 Error(
"Claim",
"not in state Free");
240 TList *vms = GetVirtualMachines();
243 for(Int_t i=0; i < n && (vm = (TObjString*) next()) != 0; i++ ) {
244 TCondorSlave *claim = ClaimVM(vm->GetName(), cmd);
246 if ( !GetVmInfo(vm->GetName(), claim->fImage, claim->fPerfIdx) ) {
265 TCondorSlave *TCondor::Claim(
const char *vmname,
const char *cmd)
267 if (fState != kFree && fState != kActive) {
268 Error(
"Claim",
"not in state Free or Active");
272 TCondorSlave *claim = ClaimVM(vmname, cmd);
285 Bool_t TCondor::SetState(EState state)
287 PDB(kCondor,1) Info("SetState","state: %s (%lld)",
288 state == kSuspended ? "kSuspended" : "kActive", Long64_t(gSystem->Now()));
291 while((claim = (TCondorSlave*) next()) != 0) {
292 TString cmd = Form(
"condor_cod %s -id '%s'",
293 state == kSuspended ?
"suspend" :
"resume",
294 claim->fClaimID.Data());
296 PDB(kCondor,2) Info("SetState","command: %s", cmd.Data());
297 FILE *pipe = gSystem->OpenPipe(cmd, "r");
300 SysError(
"SetState",
"cannot run command: %s", cmd.Data());
305 while (line.Gets(pipe)) {
306 PDB(kCondor,3) Info("SetState","line = %s", line.Data());
309 Int_t r = gSystem->ClosePipe(pipe);
311 Error(
"SetState",
"command: %s returned %d", cmd.Data(), r);
314 PDB(kCondor,1) Info("SetState","command: %s returned %d", cmd.Data(), r);
326 Bool_t TCondor::Suspend()
328 if (fState != kActive) {
329 Error(
"Suspend",
"not in state Active");
333 return SetState(kSuspended);
340 Bool_t TCondor::Resume()
342 if (fState != kSuspended) {
343 Error(
"Suspend",
"not in state Suspended");
347 return SetState(kActive);
354 Bool_t TCondor::Release()
356 if (fState == kFree) {
357 Error(
"Suspend",
"not in state Active or Suspended");
362 while((claim = (TCondorSlave*) fClaims->First()) != 0) {
363 TString cmd = Form(
"condor_cod release -id '%s'", claim->fClaimID.Data());
365 PDB(kCondor,2) Info("SetState","command: %s", cmd.Data());
366 FILE *pipe = gSystem->OpenPipe(cmd, "r");
369 SysError(
"Release",
"cannot run command: %s", cmd.Data());
374 while (line.Gets(pipe)) {
375 PDB(kCondor,3) Info("Release","line = %s", line.Data());
378 Int_t r = gSystem->ClosePipe(pipe);
380 Error(
"Release",
"command: %s returned %d", cmd.Data(), r);
383 PDB(kCondor,1) Info("Release","command: %s returned %d", cmd.Data(), r);
386 fClaims->Remove(claim);
398 Bool_t TCondor::GetVmInfo(const
char *vm, TString &image, Int_t &perfidx)
const
400 TString cmd = Form(
"condor_status -format \"%%d:\" Mips -format \"%%s\\n\" FileSystemDomain "
401 "-const 'Name==\"%s\"'", vm);
403 PDB(kCondor,2) Info("GetVmInfo","command: %s", cmd.Data());
404 FILE *pipe = gSystem->OpenPipe(cmd, "r");
407 SysError(
"GetVmInfo",
"cannot run command: %s", cmd.Data());
412 while (line.Gets(pipe)) {
413 PDB(kCondor,3) Info("GetVmInfo","line = %s", line.Data());
415 TString amips = line(TRegexp(
"^[0-9]*"));
416 perfidx = atoi(amips);
417 image = line(TRegexp(
"[^:]+$"));
422 Int_t r = gSystem->ClosePipe(pipe);
424 Error(
"GetVmInfo",
"command: %s returned %d", cmd.Data(), r);
427 PDB(kCondor,1) Info("GetVmInfo","command: %s returned %d", cmd.Data(), r);
437 TString TCondor::GetImage(const
char *host)
const
439 TString cmd = Form(
"condor_status -direct %s -format \"Image:%%s\\n\" "
440 "FileSystemDomain", host);
442 PDB(kCondor,2) Info("GetImage","command: %s", cmd.Data());
444 FILE *pipe = gSystem->OpenPipe(cmd, "r");
447 SysError(
"GetImage",
"cannot run command: %s", cmd.Data());
453 while (line.Gets(pipe)) {
454 PDB(kCondor,3) Info("GetImage","line = %s", line.Data());
456 image = line(TRegexp(
"[^:]+$"));
461 Int_t r = gSystem->ClosePipe(pipe);
463 Error(
"GetImage",
"command: %s returned %d", cmd.Data(), r);
466 PDB(kCondor,1) Info("GetImage","command: %s returned %d", cmd.Data(), r);
476 void TCondorSlave::Print(Option_t * )
const
478 std::cout <<
"OBJ: " << IsA()->GetName()
479 <<
" " << fHostname <<
":" << fPort
480 <<
" Perf: " << fPerfIdx
481 <<
" Image: " << fImage << std::endl;