Back to index

nordugrid-arc-nox  1.1.0~rc6
JobControllerCREAM.cpp
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include <config.h>
00005 #endif
00006 
00007 #include <glib.h>
00008 
00009 #include <arc/Logger.h>
00010 #include <arc/StringConv.h>
00011 #include <arc/URL.h>
00012 #include <arc/UserConfig.h>
00013 #include <arc/message/MCC.h>
00014 
00015 #include "CREAMClient.h"
00016 #include "JobControllerCREAM.h"
00017 
00018 namespace Arc {
00019 
00020   Logger JobControllerCREAM::logger(JobController::logger, "CREAM");
00021 
00022   JobControllerCREAM::JobControllerCREAM(const UserConfig& usercfg)
00023     : JobController(usercfg, "CREAM") {}
00024 
00025   JobControllerCREAM::~JobControllerCREAM() {}
00026 
00027   Plugin* JobControllerCREAM::Instance(PluginArgument *arg) {
00028     JobControllerPluginArgument *jcarg =
00029       dynamic_cast<JobControllerPluginArgument*>(arg);
00030     if (!jcarg)
00031       return NULL;
00032     return new JobControllerCREAM(*jcarg);
00033   }
00034 
00035   void JobControllerCREAM::GetJobInformation() {
00036 
00037     MCCConfig cfg;
00038     usercfg.ApplyToConfig(cfg);
00039     for (std::list<Job>::iterator iter = jobstore.begin();
00040          iter != jobstore.end(); iter++) {
00041       PathIterator pi(iter->JobID.Path(), true);
00042       URL url(iter->JobID);
00043       url.ChangePath(*pi);
00044       CREAMClient gLiteClient(url, cfg, usercfg.Timeout());
00045       if (!gLiteClient.stat(pi.Rest(), (*iter)))
00046         logger.msg(INFO, "Failed retrieving job information for job: %s", iter->JobID.str());
00047     }
00048   }
00049 
00050   bool JobControllerCREAM::GetJob(const Job& job,
00051                                   const std::string& downloaddir) {
00052 
00053     logger.msg(VERBOSE, "Downloading job: %s", job.JobID.str());
00054 
00055     std::string path = job.JobID.Path();
00056     std::string::size_type pos = path.rfind('/');
00057     std::string jobidnum = path.substr(pos + 1);
00058 
00059     std::list<std::string> files = GetDownloadFiles(job.OSB);
00060 
00061     URL src(job.OSB);
00062     URL dst(downloaddir.empty() ? jobidnum : downloaddir + G_DIR_SEPARATOR_S + jobidnum);
00063 
00064     std::string srcpath = src.Path();
00065     std::string dstpath = dst.Path();
00066 
00067     if (srcpath.empty() || (srcpath[srcpath.size() - 1] != '/'))
00068       srcpath += '/';
00069     if (dstpath.empty() || (dstpath[dstpath.size() - 1] != G_DIR_SEPARATOR))
00070       dstpath += G_DIR_SEPARATOR_S;
00071 
00072     bool ok = true;
00073 
00074     for (std::list<std::string>::iterator it = files.begin();
00075          it != files.end(); it++) {
00076       src.ChangePath(srcpath + *it);
00077       dst.ChangePath(dstpath + *it);
00078       if (!ARCCopyFile(src, dst)) {
00079         logger.msg(INFO, "Failed dowloading %s to %s", src.str(), dst.str());
00080         ok = false;
00081       }
00082     }
00083 
00084     return ok;
00085   }
00086 
00087   bool JobControllerCREAM::CleanJob(const Job& job, bool force) {
00088 
00089     MCCConfig cfg;
00090     usercfg.ApplyToConfig(cfg);
00091     PathIterator pi(job.JobID.Path(), true);
00092     URL url(job.JobID);
00093     url.ChangePath(*pi);
00094     CREAMClient gLiteClient(url, cfg, usercfg.Timeout());
00095     if (!gLiteClient.purge(pi.Rest())) {
00096       logger.msg(INFO, "Failed cleaning job: %s", job.JobID.str());
00097       return false;
00098     }
00099     PathIterator pi2(job.InfoEndpoint.Path(), true);
00100     URL url2(job.InfoEndpoint);
00101     url2.ChangePath(*pi2);
00102     CREAMClient gLiteClient2(url2, cfg, usercfg.Timeout());
00103     if (!gLiteClient2.destroyDelegation(pi2.Rest())) {
00104       logger.msg(INFO, "Failed destroying delegation credentials for job: %s", job.JobID.str());
00105       return false;
00106     }
00107     return true;
00108   }
00109 
00110   bool JobControllerCREAM::CancelJob(const Job& job) {
00111 
00112     MCCConfig cfg;
00113     usercfg.ApplyToConfig(cfg);
00114     PathIterator pi(job.JobID.Path(), true);
00115     URL url(job.JobID);
00116     url.ChangePath(*pi);
00117     CREAMClient gLiteClient(url, cfg, usercfg.Timeout());
00118     if (!gLiteClient.cancel(pi.Rest())) {
00119       logger.msg(INFO, "Failed canceling job: %s", job.JobID.str());
00120       return false;
00121     }
00122     return true;
00123   }
00124 
00125   bool JobControllerCREAM::RenewJob(const Job& job) {
00126     logger.msg(INFO, "Renewal of CREAM jobs is not supported");
00127     return false;
00128   }
00129 
00130   bool JobControllerCREAM::ResumeJob(const Job& job) {
00131     logger.msg(INFO, "Resumation of CREAM jobs is not supported");
00132     return false;
00133   }
00134 
00135   URL JobControllerCREAM::GetFileUrlForJob(const Job& job,
00136                                            const std::string& whichfile) { return URL(); }
00137   bool JobControllerCREAM::GetJobDescription(const Job& job, std::string& desc_str) { return false; }
00138 
00139 } // namespace Arc