adopt to arc1.0.1
[gp-arc-client-c.git] / ext / arc_submit.cpp
index f9333d8..6686ac7 100644 (file)
@@ -3,19 +3,15 @@
  *  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>
 #include <list>
 #include "arc_libs.h"
 
 
-submit_result_t* arc_submit(int argc, char **argv) {
+char* arc_submit(int argc, char **argv) {
        
        
-       submit_result_t* result = (submit_result_t*)malloc(sizeof(submit_result_t));
-       if (!result) {
-               return NULL;//TBD: throw sth?
-       }
-       result->message = NULL;
-       result->job_id = NULL;
+  char* job_id = NULL;
        
        
 
@@ -111,8 +102,8 @@ submit_result_t* arc_submit(int argc, char **argv) {
        
        Arc::UserConfig usercfg(conffile, joblist);
        if (!usercfg) {
-               result->message = new_str("Failed configuration initialization");
-               return result;  
+               logger.msg(Arc::ERROR, "Failed configuration initialization");
+               return NULL;    
        }
        
        if (timeout > 0)
@@ -131,32 +122,26 @@ submit_result_t* arc_submit(int argc, char **argv) {
                usercfg.AddServices(indexurls, Arc::INDEX);
        
        if (jobdescriptionstring.empty()) {
-               result->message = new_str("No job description input specified");
-               return result;
+               logger.msg(Arc::ERROR, "No job description input specified");
+               return NULL;
        }
-       
-       
-
                
        Arc::JobDescription jobdesc;
        
        jobdesc.Parse(jobdescriptionstring);
        
        if (!jobdesc){
-               std::ostringstream sstr;
-               sstr << "Invalid JobDescription:";
-               sstr << jobdescriptionstring;
-               result->message = ostringstream2cstring(sstr);
-               return result;
+               
+               logger.msg(Arc::ERROR, "Invalid JobDescription");
+               return NULL;
        }
        
        Arc::TargetGenerator targen(usercfg);
        targen.GetTargets(0, 1);
        
-       if (targen.FoundTargets().empty()) {
-               
-               result->message = new_str("Job submission aborted because no clusters returned any information");
-               return result;
+       if (targen.FoundTargets().empty()) {            
+               logger.msg(Arc::ERROR, "Job submission aborted because no clusters returned any information");
+               return NULL;
        }
        
        
@@ -164,10 +149,8 @@ submit_result_t* arc_submit(int argc, char **argv) {
        Arc::BrokerLoader loader;
        Arc::Broker *ChosenBroker = loader.load(usercfg.Broker().first, usercfg);
        if (!ChosenBroker) {
-               std::ostringstream sstream;
-               sstream << "Unable to load broker " << usercfg.Broker().first;
-               result->message = ostringstream2cstring(sstream);
-               return result;
+         logger.msg(Arc::ERROR, "Unable to load broker %s", usercfg.Broker().first);
+               return NULL;
        }
        logger.msg(Arc::INFO, "Broker %s loaded", usercfg.Broker().first);
        
@@ -178,14 +161,14 @@ submit_result_t* arc_submit(int argc, char **argv) {
                const Arc::ExecutionTarget* target = ChosenBroker->GetBestTarget();
                
                if (!target) {
-                       result->message = new_str("Job submission failed, no more possible targets");
+                       logger.msg(Arc::ERROR, "Job submission failed, no more possible targets");
                        break;
                }
                
                Arc::Submitter *submitter = target->GetSubmitter(usercfg);
                                
                if (dryrun) {
-                       result->message = new_str("Dry run, job submission is skipped");
+                       logger.msg(Arc::ERROR, "Dry run, job submission is skipped");
                        break;
                }
                //submit the job
@@ -196,13 +179,13 @@ submit_result_t* arc_submit(int argc, char **argv) {
                }
                
                ChosenBroker->RegisterJobsubmission();
-               result->job_id = new_str(jobid.str().c_str());
+               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 result;
+       return job_id;
 }