Ejemplo n.º 1
0
void printStatus(JobStatus &stat, int level) {
	std::vector<pair<JobStatus::Attr, JobStatus::AttrType> > attrList = stat.getAttrs();
        cout << "\nJob Status Information:\n - Current Status =  " << stat.name() << "\n   ---" << endl<< flush ;
	if (level>0)
	   for (unsigned i=0; i < attrList.size(); i++ ) {
		cout << stat.getAttrName(attrList[i].first) << " == " ;
		switch (attrList[i].second) {
			case JobStatus::INT_T     :
				cout << stat.getValInt(attrList[i].first) << endl<<flush;
				break;
			case JobStatus::STRING_T  :
				cout << stat.getValString(attrList[i].first) << endl<<flush;
				break;
			case JobStatus::TIMEVAL_T    :{
				timeval t = stat.getValTime(attrList[i].first);
				cout << t.tv_sec << "." << t.tv_usec << " s " << endl<<flush;}
				break;
			case JobStatus::BOOL_T    :
				cout << stat.getValBool(attrList[i].first) << endl<<flush;
				break;
			case JobStatus::JOBID_T    :{
				if(((glite::wmsutils::jobid::JobId)stat.getValJobId(attrList[i].first)).isSet())
				cout << stat.getValJobId(attrList[i].first).toString() << endl<<flush;
				}
		break;
			case JobStatus::STSLIST_T    :{
				std::vector<JobStatus> v = stat.getValJobStatusList(attrList[i].first);
				for(unsigned int i=0; i < v.size(); i++) ; //TBD
			}
			break ;
			case JobStatus::TAGLIST_T :{
				std::vector<std::pair<std::string,std::string> >  v = stat.getValTagList(  attrList[i].first ) ;
				for (unsigned int i = 0 ; i < v.size() ; i++ )
					cout << v[i].first  << " - " << v[i].second << " ;   " << flush ;
				}
			break;
			case JobStatus::INTLIST_T    :{
				std::vector<int> v = stat.getValIntList(attrList[i].first);
				for(unsigned int j=0; j < v.size(); j++)
					cout << "  " << v[j]  << flush ;
				cout << endl<<flush;
			}
			break;
			case JobStatus::STRLIST_T    :{
				std::vector<std::string> v = stat.getValStringList(attrList[i].first);
				for(unsigned int j=0; j < v.size(); j++)
					cout << v[j] ;
				cout << endl<<flush;
			}
			break ;
			default : /* something is wrong */
				break;
		}
	}
	cout << endl<<flush;
}
Ejemplo n.º 2
0
void
getSandboxBulkDestURI(getSandboxBulkDestURIResponse& getSandboxBulkDestURI_response,
                      const string& jid, const string& protocol)
{
   GLITE_STACK_TRY("getSandboxBulkDestURI()");
   edglog_fn("wmpoperations::getSandboxBulkDestURI");

   edglog(debug) << "getSandboxBulkDestURI requested for job: " << jid << endl;
   initWMProxyOperation("getSandboxBulkDestURI");
   security::do_authZ_jobid("getSandboxBulkDestURI", jid);
   // Initializing logger
   WMPEventLogger wmplogger(wmputilities::getEndpoint());
   wmplogger.setLBProxy(conf.isLBProxyAvailable(), wmputilities::getDN_SSL());
   JobId jobid(jid);
   wmplogger.setUserProxy(wmputilities::getJobDelegatedProxyPath(jobid));
   wmplogger.init_and_set_logging_job("", 0, &jobid);

   DestURIsStructType *destURIsStruct = new DestURIsStructType();
   destURIsStruct->Item = new vector<DestURIStructType*>(0);

   // Getting job status to get children number
   JobStatus status = wmplogger.getStatus(true);
   vector<string> jids = status.getValStringList(JobStatus::CHILDREN);
   edglog(debug)<<"Children count: "<<status.getValInt(JobStatus::CHILDREN_NUM)<<endl;
   vector<string>::iterator jidsiterator = jids.begin();
   jids.insert(jidsiterator, 1, jid);

   vector<string>::iterator iter = jids.begin();
   vector<string>::iterator const end = jids.end();
   for (; iter != end; ++iter) {
      vector<string> *uris = getJobDirectoryURIsVector(conf.getProtocols(),
                             conf.getDefaultProtocol(), conf.getDefaultPort(), conf.getHTTPSPort(),
                             *iter, protocol, "input");

      DestURIStructType *destURIStruct = new DestURIStructType();
      destURIStruct->id = *iter;
      destURIStruct->destURIs = uris;
      destURIsStruct->Item->push_back(destURIStruct);
   }
   getSandboxBulkDestURI_response.destURIsStruct = destURIsStruct;

   GLITE_STACK_CATCH();
}
Ejemplo n.º 3
0
void
getOutputFileList(getOutputFileListResponse& getOutputFileList_response,
                  const string& jid, const string& protocol)
{
   int fd = -1;
   try {
      edglog_fn("wmpoperations::getOutputFileList");
      edglog(debug) << "getOutputFileList requested for job: " << jid << endl;
      initWMProxyOperation("getOutputFileList");
      // do not need a valid delegated credential to retrieve the output
      security::do_authZ("getOutputFileList");

      // File descriptor for operation lock system:
      // During jobPurge operation, a check to getOutputFileList lock file is done
      // If a getOutputFileList is requested, jobPurge operation is aborted
      JobId jobid(jid);
      fd = wmputilities::operationLock(
              wmputilities::getGetOutputFileListLockFilePath(jobid),
              "getOutputFileList");

      string jobdirectory = wmputilities::getJobDirectoryPath(jobid);

	// bug 98113
	// wmputilities::readTextFile(wmputilities::getJobJDLExistingStartPath(jid)
	// turn into classad
	// get VO and VOMS_FQAN attributes
	// compare with wmputilities::getGridsiteVO()
	// build a set from this vector of strings wmputilities::getGridsiteFQANs()
	// and check that VOMS_FQAN is in that set
	//ClassAd        *classad;
	//ClassAdParser  parser;
	//classad = parser.ParseClassAd(wmputilities::getJobJDLExistingStartPath(jid), true);
	//ad.EvaluateAttr( "foo", val )
	//JDLPrivate::VOMS_FQAN
	//JDL::VIRTUAL_ORGANISATION


      // Checking for maradona file, created if and only if the job is in DONE state
      // isn't the check on the status already done in the client?
      edglog(info)<<"Searching for MARADONA file: "<<jobdirectory + FILE_SEPARATOR
                   + MARADONA_FILE<<endl;
      if (!wmputilities::fileExists(jobdirectory + FILE_SEPARATOR + MARADONA_FILE)) {
         // MARADONA file NOT found
         // Initializing logger
         WMPEventLogger wmplogger(wmputilities::getEndpoint());
         wmplogger.setLBProxy(conf.isLBProxyAvailable(), wmputilities::getDN_SSL());
         wmplogger.init_and_set_logging_job("", 0, &jobid);

         string userProxyJob =  wmputilities::getJobDelegatedProxyPath(jobid);
       
         long timeleft = 0;
         try {
           security::getProxyTimeLeft(userProxyJob);
         } catch (glite::wmsutils::exception::Exception& ex) {
         }

         // Setting user proxy, checks whether the user proxy is still valid,
         // switching to the host proxy if the user proxy expired
         if ( timeleft <= 1) {
            string hostProxy = configuration::Configuration::instance()->common()->host_proxy_file();
            wmplogger.setUserProxy(hostProxy); // throws
         } else {
            wmplogger.setUserProxy(userProxyJob); // throws
         }

         // Getting job status to check if is a job and its status
         JobStatus status = wmplogger.getStatus(false);
         if (status.getValInt(JobStatus::CHILDREN_NUM) != 0) {
            string msg = "getOutputFileList operation not allowed for dag or collection type";
            edglog(error)<<msg<<": "<<jobid.toString()<<endl;
            throw JobOperationException(__FILE__, __LINE__, "getOutputFileList()",
                                        wmputilities::WMS_OPERATION_NOT_ALLOWED, msg);
         }
         // getOutputFileList allowed when:
         // STATUS is eithr Done (yet done_code!= FAILED) or Aborted
         if (((status.status == JobStatus::DONE)
               &&(status.getValInt(JobStatus::DONE_CODE) == JobStatus::DONE_CODE_FAILED))
               || ((status.status != JobStatus::DONE) && (status.status != JobStatus::ABORTED))) {
            edglog(error)<<
                         "Job current status doesn't allow getOutputFileList operation"<<endl;
            throw JobOperationException(__FILE__, __LINE__,
                                        "getOutputFileList()", wmputilities::WMS_OPERATION_NOT_ALLOWED,
                                        "Job current status doesn't allow getOutputFileList operation");
         }
      }  // else ...... If MARADONA file is found, output files are definitely present on WMS
      string outputpath = wmputilities::getOutputSBDirectoryPath(jid);
      vector<string> *jobdiruris = getJobDirectoryURIsVector(conf.getProtocols(),
                                   conf.getDefaultProtocol(), conf.getDefaultPort(), conf.getHTTPSPort(),
                                   jid, protocol, "output");
      unsigned int jobdirsize = jobdiruris->size();

      // Searching files inside directory
      const boost::filesystem::path p(outputpath, boost::filesystem::native);
      std::vector<std::string> found;
      glite::wms::wmproxy::commands::list_files(p, found);
      edglog(debug)<<"List size is (hidden files included): "
                   <<found.size()<<endl;

      // Creating the list
      StringAndLongList *list = new StringAndLongList();
      vector<StringAndLongType*> *file = new vector<StringAndLongType*>;
      StringAndLongType *item = NULL;
      string filename;
      long filesize;

      vector<string>::iterator iter = found.begin();
      vector<string>::iterator const end = found.end();
      for (; iter != end; ++iter) {
         // Checking for hidden files
         filename = wmputilities::getFileName(string(*iter));
         if ((filename != MARADONA_FILE) && (filename
                                             != security::GaclManager::WMPGACL_DEFAULT_FILE)) {
            filesize = wmputilities::computeFileSize(*iter);
            edglog(debug)<<"Inserting file name: " <<filename<<endl;
            edglog(debug)<<"Inserting file size: " <<filesize<<endl;
            for (unsigned int i = 0; i < jobdirsize; i++) {
               item = new StringAndLongType();
               item->name = (*jobdiruris)[i] + FILE_SEPARATOR + filename;
               item->size = filesize;
               file->push_back(item);
            }
         }
      }
      list->file = file;
      getOutputFileList_response.OutputFileAndSizeList = list;
      edglog(debug)<<"Successfully retrieved files: "<<found.size()<<endl;
      edglog(debug)<<"Removing lock..."<<std::endl;
      wmputilities::operationUnlock(fd);
   } catch (glite::wmsutils::exception::Exception const& e) {
      edglog(debug)<<"Removing lock..."<<std::endl;
      wmputilities::operationUnlock(fd);
      edglog(debug) << "wmsutils::Exception: " << e.what() << std::endl;
      throw e;
   } catch (exception& ex) {
      edglog(debug)<<"Removing lock..."<<std::endl;
      wmputilities::operationUnlock(fd);
      edglog(debug)<<"std::exception: "<<ex.what()<<std::endl;
      throw ex;
   }
}