More changes to adapt to ARC 1.0.1
[gp-arc-client-c.git] / ext / arc_submit.cpp
index 3c5fbd8..d2db0d3 100644 (file)
@@ -3,18 +3,14 @@
  *  arcclientc
  *
  *  Created by Tamas Jung on 4/7/10.
- *  Copyright 2010 Interface Kft. All rights reserved.
  *
  */
 
 #include "arc_submit.h"
 #include "logger.h"
-#include "config.h" //TBD: Kell ez?
 // -*- indent-tabs-mode: nil -*-
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+
 #include "logger.h"
 #include <fstream>
 #include <iostream>
@@ -141,9 +137,10 @@ char* arc_submit(int argc, char **argv) {
        }
        
        Arc::TargetGenerator targen(usercfg);
-       targen.GetTargets(0, 1);
+       targen.RetrieveExecutionTargets();
+  
        
-       if (targen.FoundTargets().empty()) {            
+       if (targen.GetExecutionTargets().empty()) {
                logger.msg(Arc::ERROR, "Job submission aborted because no clusters returned any information");
                return NULL;
        }
@@ -158,38 +155,20 @@ char* arc_submit(int argc, char **argv) {
        }
        logger.msg(Arc::INFO, "Broker %s loaded", usercfg.Broker().first);
        
-               
-       ChosenBroker->PreFilterTargets(targen.ModifyFoundTargets(), jobdesc);
-       
-       while (true) {
-               const Arc::ExecutionTarget* target = ChosenBroker->GetBestTarget();
-               
-               if (!target) {
-                       logger.msg(Arc::ERROR, "Job submission failed, no more possible targets");
-                       break;
-               }
-               
-               Arc::Submitter *submitter = target->GetSubmitter(usercfg);
-                               
-               if (dryrun) {
-                       logger.msg(Arc::ERROR, "Dry run, job submission is skipped");
-                       break;
-               }
-               //submit the job
-               Arc::URL jobid = submitter->Submit(jobdesc, *target);
-               if (!jobid) {
-                       logger.msg(Arc::INFO, "Submission to %s failed, trying next target", target->url.str());
-                       continue;
-               }
-               
-               ChosenBroker->RegisterJobsubmission();
-               job_id = new_str(jobid.str().c_str());
-               logger.msg(Arc::DEBUG, "Job submitted with jobid: %s", jobid.str());
-               
-               break;
-       } //end loop over all possible targets
-       
-       return job_id;
+  std::list<Arc::Job> submittedJobs;
+  
+  if (ChosenBroker->Submit(targen.GetExecutionTargets(), jobdesc, submittedJobs.back())) {
+    logger.msg(Arc::DEBUG, "Job submitted with ID: %s", submittedJobs.back().JobID.str());
+  } else {
+    logger.msg(Arc::ERROR, "Job submission failed (ChosenBroker->Submit returned false)");
+    submittedJobs.pop_back();
+  }
+  
+  Arc::Job::WriteJobsToFile(usercfg.JobListFile(), submittedJobs);
+  
+  job_id = new_str(submittedJobs.back().JobID.str().c_str());
+  
+  return job_id;
 }