Back to index

nordugrid-arc-nox  1.1.0~rc6
JobDescription.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 <arc/StringConv.h>
00008 
00009 #include "JobDescription.h"
00010 
00011 #include "XRSLParser.h"
00012 #include "JDLParser.h"
00013 #include "ARCJSDLParser.h"
00014 
00015 
00016 #define INTPRINT(X, Y) if ((X) > -1) \
00017   std::cout << IString(#Y ": %d", X) << std::endl;
00018 #define STRPRINT(X, Y) if (!(X).empty()) \
00019   std::cout << IString(#Y ": %s", X) << std::endl;
00020 
00021 
00022 namespace Arc {
00023 
00024   Logger JobDescription::logger(Logger::getRootLogger(), "JobDescription");
00025 
00026   JobDescription::JobDescription(const long int& ptraddr) { *this = *((JobDescription*)ptraddr); }
00027 
00028   void JobDescription::Print(bool longlist) const {
00029 
00030     STRPRINT(Application.Executable.Name, Executable);
00031     STRPRINT(Application.LogDir, Log Directory)
00032     STRPRINT(Identification.JobName, JobName)
00033     STRPRINT(Identification.Description, Description)
00034     STRPRINT(Identification.JobVOName, Virtual Organization)
00035 
00036     switch (Identification.JobType) {
00037     case SINGLE:
00038       std::cout << IString("Job type: single") << std::endl;
00039       break;
00040     case COLLECTIONELEMENT:
00041       std::cout << IString("Job type: collection") << std::endl;
00042       break;
00043     case PARALLELELEMENT:
00044       std::cout << IString("Job type: parallel") << std::endl;
00045       break;
00046     case WORKFLOWNODE:
00047       std::cout << IString("Job type: workflownode") << std::endl;
00048       break;
00049     }
00050 
00051     if (longlist) {
00052       if (!Identification.UserTag.empty()) {
00053         std::list<std::string>::const_iterator iter = Identification.UserTag.begin();
00054         for (; iter != Identification.UserTag.end(); iter++)
00055           std::cout << IString(" UserTag: %s", *iter) << std::endl;
00056       }
00057 
00058       if (!Identification.ActivityOldId.empty()) {
00059         std::list<std::string>::const_iterator iter = Identification.ActivityOldId.begin();
00060         for (; iter != Identification.ActivityOldId.end(); iter++)
00061           std::cout << IString(" Activity Old Id: %s", *iter) << std::endl;
00062       }
00063 
00064       STRPRINT(JobMeta.Author, Author)
00065       if (JobMeta.DocumentExpiration.GetTime() > 0)
00066         std::cout << IString(" DocumentExpiration: %s", JobMeta.DocumentExpiration.str()) << std::endl;
00067 
00068       if (!Application.Executable.Argument.empty()) {
00069         std::list<std::string>::const_iterator iter = Application.Executable.Argument.begin();
00070         for (; iter != Application.Executable.Argument.end(); iter++)
00071           std::cout << IString(" Argument: %s", *iter) << std::endl;
00072       }
00073 
00074       STRPRINT(Application.Input, Input)
00075       STRPRINT(Application.Output, Output)
00076       STRPRINT(Application.Error, Error)
00077 
00078       if (!Application.RemoteLogging.empty()) {
00079         std::list<URL>::const_iterator iter = Application.RemoteLogging.begin();
00080         for (; iter != Application.RemoteLogging.end(); iter++) {
00081           std::cout << IString(" RemoteLogging: %s", iter->fullstr()) << std::endl;
00082         }
00083       }
00084 
00085       if (!Application.Environment.empty()) {
00086         std::list< std::pair<std::string, std::string> >::const_iterator iter = Application.Environment.begin();
00087         for (; iter != Application.Environment.end(); iter++) {
00088           std::cout << IString(" Environment.name: %s", iter->first) << std::endl;
00089           std::cout << IString(" Environment: %s", iter->second) << std::endl;
00090         }
00091       }
00092 
00093       INTPRINT(Application.Rerun, Rerun)
00094 
00095       STRPRINT(Application.Prologue.Name, Prologue)
00096       if (!Application.Prologue.Argument.empty()) {
00097         std::list<std::string>::const_iterator iter = Application.Prologue.Argument.begin();
00098         for (; iter != Application.Prologue.Argument.end(); iter++)
00099           std::cout << IString(" Prologue.Arguments: %s", *iter) << std::endl;
00100       }
00101 
00102       STRPRINT(Application.Epilogue.Name, Epilogue)
00103       if (!Application.Epilogue.Argument.empty()) {
00104         std::list<std::string>::const_iterator iter = Application.Epilogue.Argument.begin();
00105         for (; iter != Application.Epilogue.Argument.end(); iter++)
00106           std::cout << IString(" Epilogue.Arguments: %s", *iter) << std::endl;
00107       }
00108 
00109       INTPRINT(Resources.SessionLifeTime.GetPeriod(), SessionLifeTime)
00110 
00111       if (bool(Application.AccessControl)) {
00112         std::string str;
00113         Application.AccessControl.GetXML(str, true);
00114         std::cout << IString(" AccessControl: %s", str) << std::endl;
00115       }
00116 
00117       if (Application.ProcessingStartTime.GetTime() > 0)
00118         std::cout << IString(" ProcessingStartTime: %s", Application.ProcessingStartTime.str()) << std::endl;
00119 
00120       if (Application.Notification.size() > 0) {
00121         std::cout << IString(" Notify:") << std::endl;
00122         for (std::list<NotificationType>::const_iterator it = Application.Notification.begin();
00123              it != Application.Notification.end(); it++) {
00124           for (std::list<std::string>::const_iterator it2 = it->States.begin();
00125                it2 != it->States.end(); it2++) {
00126             std::cout << " " << *it2;
00127           }
00128           std::cout << ":   " << it->Email << std::endl;
00129         }
00130       }
00131 
00132       if (!Application.CredentialService.empty()) {
00133         std::list<URL>::const_iterator iter = Application.CredentialService.begin();
00134         for (; iter != Application.CredentialService.end(); iter++)
00135           std::cout << IString(" CredentialService: %s", iter->str()) << std::endl;
00136       }
00137 
00138       if (Application.Join)
00139         std::cout << " Join: true" << std::endl;
00140 
00141       INTPRINT(Resources.TotalCPUTime.range.max, TotalCPUTime)
00142       INTPRINT(Resources.IndividualCPUTime.range.max, IndividualCPUTime)
00143       INTPRINT(Resources.TotalWallTime.range.max, TotalWallTime)
00144       INTPRINT(Resources.IndividualWallTime.range.max, IndividualWallTime)
00145 
00146       STRPRINT(Resources.NetworkInfo, NetworkInfo)
00147 
00148       if (!Resources.OperatingSystem.empty()) {
00149         std::cout << IString(" Operating system requirements:") << std::endl;
00150         std::list<Software>::const_iterator itOS = Resources.OperatingSystem.getSoftwareList().begin();
00151         std::list<Software::ComparisonOperator>::const_iterator itCO = Resources.OperatingSystem.getComparisonOperatorList().begin();
00152         for (; itOS != Resources.OperatingSystem.getSoftwareList().end(); itOS++, itCO++) {
00153           if (*itCO != &Software::operator==) std::cout << Software::toString(*itCO) << " ";
00154           std::cout << *itOS << std::endl;
00155         }
00156       }
00157 
00158       STRPRINT(Resources.Platform, Platform)
00159       INTPRINT(Resources.IndividualPhysicalMemory.max, IndividualPhysicalMemory)
00160       INTPRINT(Resources.IndividualVirtualMemory.max, IndividualVirtualMemory)
00161       INTPRINT(Resources.DiskSpaceRequirement.DiskSpace.max, DiskSpace)
00162       INTPRINT(Resources.DiskSpaceRequirement.CacheDiskSpace, CacheDiskSpace)
00163       INTPRINT(Resources.DiskSpaceRequirement.SessionDiskSpace, SessionDiskSpace)
00164 
00165       for (std::list<ResourceTargetType>::const_iterator it = Resources.CandidateTarget.begin();
00166            it != Resources.CandidateTarget.end(); it++) {
00167         if (it->EndPointURL)
00168           std::cout << IString(" EndPointURL: %s", it->EndPointURL.str()) << std::endl;
00169         if (!it->QueueName.empty())
00170           std::cout << IString(" QueueName: %s", it->QueueName) << std::endl;
00171       }
00172 
00173       if (!Resources.CEType.empty()) {
00174         std::cout << IString(" Computing endpoint requirements:") << std::endl;
00175         std::list<Software>::const_iterator itCE = Resources.CEType.getSoftwareList().begin();
00176         std::list<Software::ComparisonOperator>::const_iterator itCO = Resources.CEType.getComparisonOperatorList().begin();
00177         for (; itCE != Resources.CEType.getSoftwareList().end(); itCE++, itCO++) {
00178           if (*itCO != &Software::operator==) std::cout << Software::toString(*itCO) << " ";
00179           std::cout << *itCE << std::endl;
00180         }
00181       }
00182 
00183       switch (Resources.NodeAccess) {
00184       case NAT_INBOUND:
00185         std::cout << IString(" NodeAccess: Inbound") << std::endl;
00186         break;
00187       case NAT_OUTBOUND:
00188         std::cout << IString(" NodeAccess: Outbound") << std::endl;
00189         break;
00190       case NAT_INOUTBOUND:
00191         std::cout << IString(" NodeAccess: Inbound and Outbound") << std::endl;
00192         break;
00193       }
00194 
00195       INTPRINT(Resources.SlotRequirement.NumberOfSlots.max, NumberOfSlots)
00196       INTPRINT(Resources.SlotRequirement.ProcessPerHost.max, ProcessPerHost)
00197       INTPRINT(Resources.SlotRequirement.ThreadsPerProcesses.max, ThreadsPerProcesses)
00198       STRPRINT(Resources.SlotRequirement.SPMDVariation, SPMDVariation)
00199 
00200       if (!Resources.RunTimeEnvironment.empty()) {
00201         std::cout << IString(" Run time environment requirements:") << std::endl;
00202         std::list<Software>::const_iterator itSW = Resources.RunTimeEnvironment.getSoftwareList().begin();
00203         std::list<Software::ComparisonOperator>::const_iterator itCO = Resources.RunTimeEnvironment.getComparisonOperatorList().begin();
00204         for (; itSW != Resources.RunTimeEnvironment.getSoftwareList().end(); itSW++, itCO++) {
00205           if (*itCO != &Software::operator==) std::cout << Software::toString(*itCO) << " ";
00206           std::cout << *itSW << std::endl;
00207         }
00208       }
00209 
00210       if (!DataStaging.File.empty()) {
00211         std::list<FileType>::const_iterator iter = DataStaging.File.begin();
00212         for (; iter != DataStaging.File.end(); iter++) {
00213           std::cout << IString(" File element:") << std::endl;
00214           std::cout << IString("     Name: %s", iter->Name) << std::endl;
00215 
00216           std::list<DataSourceType>::const_iterator itSource = iter->Source.begin();
00217           for (; itSource != iter->Source.end(); itSource++) {
00218             std::cout << IString("     Source.URI: %s", itSource->URI.fullstr()) << std::endl;
00219             INTPRINT(itSource->Threads, Source.Threads)
00220           }
00221 
00222           std::list<DataTargetType>::const_iterator itTarget = iter->Target.begin();
00223           for (; itTarget != iter->Target.end(); itTarget++) {
00224             std::cout << IString("     Target.URI: %s", itTarget->URI.fullstr()) << std::endl;
00225             INTPRINT(itTarget->Threads, Target.Threads)
00226             if (itTarget->Mandatory)
00227               std::cout << IString("     Target.Mandatory: true") << std::endl;
00228             INTPRINT(itTarget->NeededReplica, NeededReplica)
00229           }
00230           if (iter->KeepData)
00231             std::cout << IString("     KeepData: true") << std::endl;
00232           if (iter->IsExecutable)
00233             std::cout << IString("     IsExecutable: true") << std::endl;
00234           if (!iter->DataIndexingService.empty()) {
00235             std::list<URL>::const_iterator itDIS = iter->DataIndexingService.begin();
00236             for (; itDIS != iter->DataIndexingService.end(); itDIS++)
00237               std::cout << IString("     DataIndexingService: %s", itDIS->fullstr()) << std::endl;
00238           }
00239           if (iter->DownloadToCache)
00240             std::cout << IString("     DownloadToCache: true") << std::endl;
00241         }
00242       }
00243 
00244       if (!DataStaging.Directory.empty()) {
00245         std::list<DirectoryType>::const_iterator iter = DataStaging.Directory.begin();
00246         for (; iter != DataStaging.Directory.end(); iter++) {
00247           std::cout << IString(" Directory element:") << std::endl;
00248           std::cout << IString("     Name: %s", iter->Name) << std::endl;
00249 
00250           std::list<DataSourceType>::const_iterator itSource = iter->Source.begin();
00251           for (; itSource != iter->Source.end(); itSource++) {
00252             std::cout << IString("     Source.URI: %s", itSource->URI.fullstr()) << std::endl;
00253             INTPRINT(itSource->Threads, Source.Threads)
00254           }
00255 
00256           std::list<DataTargetType>::const_iterator itTarget = iter->Target.begin();
00257           for (; itTarget != iter->Target.end(); itTarget++) {
00258             std::cout << IString("     Target.URI: %s", itTarget->URI.fullstr()) << std::endl;
00259             INTPRINT(itTarget->Threads, Target.Threads)
00260             if (itTarget->Mandatory)
00261               std::cout << IString("     Target.Mandatory: true") << std::endl;
00262             INTPRINT(itTarget->NeededReplica, NeededReplica)
00263           }
00264           if (iter->KeepData)
00265             std::cout << IString("     KeepData: true") << std::endl;
00266           if (iter->IsExecutable)
00267             std::cout << IString("     IsExecutable: true") << std::endl;
00268           if (!iter->DataIndexingService.empty()) {
00269             std::list<URL>::const_iterator itDIS = iter->DataIndexingService.begin();
00270             for (; itDIS != iter->DataIndexingService.end(); itDIS++)
00271               std::cout << IString("     DataIndexingService: %s", itDIS->fullstr()) << std::endl;
00272           }
00273           if (iter->DownloadToCache)
00274             std::cout << IString("     DownloadToCache: true") << std::endl;
00275         }
00276       }
00277     }
00278 
00279     if (!XRSL_elements.empty()) {
00280       std::map<std::string, std::string>::const_iterator it;
00281       for (it = XRSL_elements.begin(); it != XRSL_elements.end(); it++)
00282         std::cout << IString(" XRSL_elements: [%s], %s", it->first, it->second) << std::endl;
00283     }
00284 
00285     if (!JDL_elements.empty()) {
00286       std::map<std::string, std::string>::const_iterator it;
00287       for (it = JDL_elements.begin(); it != JDL_elements.end(); it++)
00288         std::cout << IString(" JDL_elements: [%s], %s", it->first, it->second) << std::endl;
00289     }
00290 
00291     std::cout << std::endl;
00292   } // end of Print
00293 
00294   bool JobDescription::Parse(const XMLNode& xmlSource)
00295   {
00296     std::string source;
00297     xmlSource.GetXML(source);
00298     return Parse(source);
00299   }
00300 
00301   bool JobDescription::Parse(const std::string& source) {
00302     if (source.empty()) {
00303       logger.msg(ERROR, "Empty job description source string");
00304       return false;
00305     }
00306 
00307     {
00308       logger.msg(VERBOSE, "Try to parse as XRSL");
00309       XRSLParser parser;
00310       parser.SetHints(hints);
00311       *this = parser.Parse(source);
00312       if (*this) {
00313         sourceFormat = "xrsl";
00314         return true;
00315       }
00316     }
00317 
00318     {
00319       logger.msg(VERBOSE, "Try to parse as JDL");
00320       JDLParser parser;
00321       parser.SetHints(hints);
00322       *this = parser.Parse(source);
00323       if (*this) {
00324         sourceFormat = "jdl";
00325         return true;
00326       }
00327     }
00328 
00329     {
00330       logger.msg(VERBOSE, "Try to parse as ARCJSDL");
00331       ARCJSDLParser parser;
00332       parser.SetHints(hints);
00333       *this = parser.Parse(source);
00334       if (*this) {
00335         sourceFormat = "arcjsdl";
00336         return true;
00337       }
00338     }
00339 
00340     logger.msg(ERROR, "The parsing of the job description was unsuccessful");
00341     return false;
00342   }
00343 
00344   // Generate the output in the requested format
00345   std::string JobDescription::UnParse(const std::string& format) const {
00346     std::string product;
00347 
00348     // Generate the output text with the right parser class
00349     if (!*this) {
00350       logger.msg(VERBOSE, "There is no successfully parsed source");
00351       return product;
00352     }
00353 
00354     if (lower(format) == "jdl") {
00355       logger.msg(VERBOSE, "Generate JDL output");
00356       JDLParser parser;
00357       parser.SetHints(hints);
00358       product = parser.UnParse(*this);
00359       if (product.empty())
00360         logger.msg(ERROR, "Generating %s output was unsuccessful", format);
00361     }
00362     else if (lower(format) == "xrsl") {
00363       logger.msg(VERBOSE, "Generate XRSL output");
00364       XRSLParser parser;
00365       parser.SetHints(hints);
00366       product = parser.UnParse(*this);
00367       if (product.empty())
00368         logger.msg(ERROR, "Generating %s output was unsuccessful", format);
00369     }
00370     else if (lower(format) == "arcjsdl") {
00371       logger.msg(VERBOSE, "Generate ARCJSDL output");
00372       ARCJSDLParser parser;
00373       parser.SetHints(hints);
00374       product = parser.UnParse(*this);
00375       if (product.empty())
00376         logger.msg(ERROR, "Generating %s output was unsuccessful", format);
00377     }
00378     else
00379       logger.msg(ERROR, "Unknown output format: %s", format);
00380 
00381     return product;
00382   }
00383 
00384   bool JobDescription::getSourceFormat(std::string& _sourceFormat) const {
00385     if (!*this) {
00386       logger.msg(VERBOSE, "There is no input defined yet or it's format can be determinized.");
00387       return false;
00388     }
00389     else {
00390       _sourceFormat = sourceFormat;
00391       return true;
00392     }
00393   }
00394 
00395   void JobDescription::AddHint(const std::string& key,const std::string& value) {
00396     if(key.empty()) return;
00397     hints[key]=value;
00398   }
00399 
00400 } // namespace Arc