// convert list of expressions into a classad // static void printJobIfConstraint(std::vector<std::string> & exprs, const char* constraint, ExprTree *constraintExpr) { if ( ! exprs.size()) return; ClassAd ad; size_t ix; // convert lines vector into classad. while ((ix = exprs.size()) > 0) { const char * pexpr = exprs[ix-1].c_str(); if ( ! ad.Insert(pexpr)) { dprintf(D_ALWAYS,"failed to create classad; bad expr = '%s'\n", pexpr); printf( "\t*** Warning: Bad history file; skipping malformed ad(s)\n" ); exprs.clear(); return; } exprs.pop_back(); } if (!constraint || constraint[0]=='\0' || EvalBool(&ad, constraintExpr)) { printJob(ad); matchCount++; // if control reached here, match has occured } }
ClassAd* getDBNextJobByConstraint(const char* constraint, JobQueueSnapshot *jqSnapshot) { ClassAd *ad; while(jqSnapshot->iterateAllClassAds(ad) != DONE_JOBS_CURSOR) { if ((!constraint || !constraint[0] || EvalBool(ad, constraint))) { return ad; } if (ad != (ClassAd *) 0) { ad->Clear(); delete ad; ad = (ClassAd *) 0; } } return (ClassAd *) 0; }
// Read the history from a single file and print it out. static void readHistoryFromFile(char *JobHistoryFileName, char* constraint, ExprTree *constraintExpr) { int EndFlag = 0; int ErrorFlag = 0; int EmptyFlag = 0; AttrList *ad = NULL; long offset = 0; bool BOF = false; // Beginning Of File MyString buf; FILE* LogFile=safe_fopen_wrapper(JobHistoryFileName,"r"); if (!LogFile) { fprintf(stderr,"History file (%s) not found or empty.\n", JobHistoryFileName); exit(1); } // In case of rotated history files, check if we have already reached the number of // matches specified by the user before reading the next file if (specifiedMatch != 0) { if (matchCount == specifiedMatch) { // Already found n number of matches, cleanup fclose(LogFile); return; } } if (backwards) { offset = findLastDelimiter(LogFile, JobHistoryFileName); } while(!EndFlag) { if (backwards) { // Read history file backwards if (BOF) { // If reached beginning of file break; } offset = findPrevDelimiter(LogFile, JobHistoryFileName, offset); if (offset == -1) { // Unable to match constraint break; } else if (offset != 0) { fseek(LogFile, offset, SEEK_SET); buf.readLine(LogFile); // Read one line to skip delimiter and adjust to actual offset of ad } else { // Offset set to 0 BOF = true; fseek(LogFile, offset, SEEK_SET); } } if( !( ad=new AttrList(LogFile,"***", EndFlag, ErrorFlag, EmptyFlag) ) ){ fprintf( stderr, "Error: Out of memory\n" ); exit( 1 ); } if( ErrorFlag ) { printf( "\t*** Warning: Bad history file; skipping malformed ad(s)\n" ); ErrorFlag=0; if(ad) { delete ad; ad = NULL; } continue; } if( EmptyFlag ) { EmptyFlag=0; if(ad) { delete ad; ad = NULL; } continue; } if (!constraint || EvalBool(ad, constraintExpr)) { if (longformat) { ad->fPrint(stdout); printf("\n"); } else { if (customFormat) { mask.display(stdout, ad); } else { displayJobShort(ad); } } matchCount++; // if control reached here, match has occured if (specifiedMatch != 0) { // User specified a match number if (matchCount == specifiedMatch) { // Found n number of matches, cleanup if (ad) { delete ad; ad = NULL; } fclose(LogFile); return; } } } if(ad) { delete ad; ad = NULL; } } fclose(LogFile); return; }
ALERROR CDockScreenItemList::OnInitList (SInitCtx &Ctx, const SDisplayOptions &Options, CString *retsError) // OnInitList // // Initialize list { DEBUG_TRY // Figure out where to get the data from: either the station // or the player's ship. CSpaceObject *pListSource = EvalListSource(Options.sDataFrom, retsError); if (pListSource == NULL) return ERR_FAIL; // Set the list control m_pItemListControl->SetList(pListSource); // Initialize flags that control what items we will show CString sCriteria; if (!EvalString(Options.sItemCriteria, false, eventNone, &sCriteria)) { *retsError = sCriteria; return ERR_FAIL; } CItem::ParseCriteria(sCriteria, &m_ItemCriteria); m_pItemListControl->SetFilter(m_ItemCriteria); // If we have content, then eval the function (note that this might // re-enter and set the filter) if (!Options.sCode.IsBlank()) { if (!EvalString(Options.sCode, true, eventInitDockScreenList, retsError)) return ERR_FAIL; } // Position the cursor on the next relevant item SelectNextItem(); // Give the screen a chance to start at a different item (other // than the first) if (!Options.sInitialItemCode.IsBlank()) { bool bMore = IsCurrentItemValid(); while (bMore) { bool bResult; if (!EvalBool(Options.sInitialItemCode, &bResult, retsError)) return ERR_FAIL; if (bResult) break; bMore = SelectNextItem(); } } // Done return NOERROR; DEBUG_CATCH }
bool CollectorEngine::ValidateClassAd(int command,ClassAd *clientAd,Sock *sock) { if( !m_collector_requirements ) { // no need to do any of the following checks if the admin has // not configured any COLLECTOR_REQUIREMENTS return true; } char const *ipattr = NULL; switch( command ) { case MERGE_STARTD_AD: case UPDATE_STARTD_AD: case UPDATE_STARTD_AD_WITH_ACK: ipattr = ATTR_STARTD_IP_ADDR; break; case UPDATE_SCHEDD_AD: case UPDATE_SUBMITTOR_AD: ipattr = ATTR_SCHEDD_IP_ADDR; break; case UPDATE_MASTER_AD: ipattr = ATTR_MASTER_IP_ADDR; break; case UPDATE_NEGOTIATOR_AD: ipattr = ATTR_NEGOTIATOR_IP_ADDR; break; case UPDATE_COLLECTOR_AD: ipattr = ATTR_COLLECTOR_IP_ADDR; break; case UPDATE_LICENSE_AD: case UPDATE_CKPT_SRVR_AD: case UPDATE_STORAGE_AD: case UPDATE_HAD_AD: case UPDATE_AD_GENERIC: case UPDATE_GRID_AD: case UPDATE_ACCOUNTING_AD: default: break; } if(ipattr) { MyString my_address; MyString subsys_ipaddr; // Some ClassAds contain two copies of the IP address, // one named "MyAddress" and one named "<SUBSYS>IpAddr". // If the latter exists, then it _must_ match the former, // because people may be filtering in COLLECTOR_REQUIREMENTS // on MyAddress, and we don't want them to have to worry // about filtering on the older cruftier <SUBSYS>IpAddr. if( clientAd->LookupString( ipattr, subsys_ipaddr ) ) { clientAd->LookupString( ATTR_MY_ADDRESS, my_address ); if( my_address != subsys_ipaddr ) { dprintf(D_ALWAYS, "%s VIOLATION: ClassAd from %s advertises inconsistent" " IP addresses: %s=%s, %s=%s\n", COLLECTOR_REQUIREMENTS, (sock ? sock->get_sinful_peer() : "(NULL)"), ipattr, subsys_ipaddr.Value(), ATTR_MY_ADDRESS, my_address.Value()); return false; } } } // Now verify COLLECTOR_REQUIREMENTS bool collector_req_result = false; if( !EvalBool(COLLECTOR_REQUIREMENTS,m_collector_requirements,clientAd,collector_req_result) ) { dprintf(D_ALWAYS,"WARNING: %s did not evaluate to a boolean result.\n",COLLECTOR_REQUIREMENTS); collector_req_result = false; } if( !collector_req_result ) { static int details_shown=0; bool show_details = (details_shown<10) || IsFulldebug(D_FULLDEBUG); dprintf(D_ALWAYS,"%s VIOLATION: requirements do not match ad from %s.%s\n", COLLECTOR_REQUIREMENTS, sock ? sock->get_sinful_peer() : "(null)", show_details ? " Contents of the ClassAd:" : " (turn on D_FULLDEBUG to see details)"); if( show_details ) { details_shown += 1; dPrintAd(D_ALWAYS, *clientAd); } return false; } return true; }
QuillErrCode HistorySnapshot::printResults(SQLQuery *queryhor, SQLQuery *queryver, bool longformat, bool fileformat, bool custForm, AttrListPrintMask *pmask, const char *constraint /* = "" */) { AttrList *ad = 0; QuillErrCode st = QUILL_SUCCESS; // initialize index variables off_t offset = 0, last_line = 0; cur_historyads_hor_index = 0; cur_historyads_ver_index = 0; if (!longformat && !custForm) { short_header(); } ExprTree *tree = NULL; if (constraint) { ParseClassAdRvalExpr(constraint, tree); } while(1) { st = getNextAd_Hor(ad, queryhor); if(st != QUILL_SUCCESS) break; if (longformat || constraint) { st = getNextAd_Ver(ad, queryver); if (constraint && EvalBool(ad, tree) == FALSE) { continue; } // in the case of vertical, we dont want to quit if we run // out of tuples because 1) we want to display whats in the ad // and 2) the horizontal cursor will correctly determine when // to stop - this is because in all cases, we only pull out those // tuples from vertical which join with a horizontal tuple if(st != QUILL_SUCCESS && st != DONE_HISTORY_VER_CURSOR) break; if (fileformat) { // Print out the job ads in history file format, i.e., print the *** delimiters MyString owner, ad_str, temp; int compl_date; ad->sPrint(ad_str); if (!ad->LookupString(ATTR_OWNER, owner)) owner = "NULL"; if (!ad->LookupInteger(ATTR_COMPLETION_DATE, compl_date)) compl_date = 0; temp.formatstr("*** Offset = %ld ClusterId = %d ProcId = %d Owner = \"%s\" CompletionDate = %d\n", offset - last_line, curClusterId_hor, curProcId_hor, owner.Value(), compl_date); offset += ad_str.Length() + temp.Length(); last_line = temp.Length(); fprintf(stdout, "%s", ad_str.Value()); fprintf(stdout, "%s", temp.Value()); } else if (longformat) { ad->fPrint(stdout); printf("\n"); } } if (!longformat) { if (custForm == true) { ASSERT(pmask != NULL); pmask->display(stdout, ad); } else { displayJobShort(ad); } } } if(ad != NULL) { delete ad; ad = NULL; } if(st == FAILURE_QUERY_HISTORYADS_HOR || st == FAILURE_QUERY_HISTORYADS_VER) return st; return QUILL_SUCCESS; }
ALERROR CDockScreenCustomList::OnInitList (SInitCtx &Ctx, CString *retsError) // OnInitList // // Initialize list { // Get the list element CXMLElement *pListData = Ctx.pDesc->GetContentElementByTag(LIST_TAG); if (pListData == NULL) return ERR_FAIL; // See if we define a custom row height CString sRowHeight; if (pListData->FindAttribute(ROW_HEIGHT_ATTRIB, &sRowHeight)) { CString sResult; if (!EvalString(sRowHeight, false, eventNone, &sResult)) { *retsError = sResult; return ERR_FAIL; } int cyRow = strToInt(sResult, -1); if (cyRow > 0) m_pItemListControl->SetRowHeight(cyRow); } // Get the list to show CCodeChain &CC = g_pUniverse->GetCC(); ICCItem *pExp = CC.Link(pListData->GetContentText(0), 0, NULL); // Evaluate the function CCodeChainCtx CCCtx; CCCtx.SetScreen(m_pDockScreen); CCCtx.SaveAndDefineSourceVar(m_pLocation); CCCtx.SaveAndDefineDataVar(m_pData); ICCItem *pResult = CCCtx.Run(pExp); // LATER:Event CCCtx.Discard(pExp); if (pResult->IsError()) { *retsError = pResult->GetStringValue(); return ERR_FAIL; } // Set this expression as the list m_pItemListControl->SetList(CC, pResult); CCCtx.Discard(pResult); // Position the cursor on the next relevant item SelectNextItem(); // Give the screen a chance to start at a different item (other // than the first) CString sInitialItemFunc = pListData->GetAttribute(INITIAL_ITEM_ATTRIB); if (!sInitialItemFunc.IsBlank()) { bool bMore = IsCurrentItemValid(); while (bMore) { bool bResult; if (!EvalBool(sInitialItemFunc, &bResult, retsError)) return ERR_FAIL; if (bResult) break; bMore = SelectNextItem(); } } return NOERROR; }
// Read the history from a single file and print it out. static void readHistoryFromFileOld(const char *JobHistoryFileName, const char* constraint, ExprTree *constraintExpr) { int EndFlag = 0; int ErrorFlag = 0; int EmptyFlag = 0; ClassAd *ad = NULL; long offset = 0; bool BOF = false; // Beginning Of File MyString buf; int flags = 0; if( !backwards ) { // Currently, the file position manipulations used in -backwards // do not work with files > 2GB on platforms with 32-bit file // offsets. flags = O_LARGEFILE; } int LogFd = safe_open_wrapper_follow(JobHistoryFileName,flags,0); if (LogFd < 0) { fprintf(stderr,"Error opening history file %s: %s\n", JobHistoryFileName,strerror(errno)); #ifdef EFBIG if( (errno == EFBIG) && backwards ) { fprintf(stderr,"The -backwards option does not support files this large.\n"); } #endif exit(1); } FILE *LogFile = fdopen(LogFd,"r"); if (!LogFile) { fprintf(stderr,"Error opening history file %s: %s\n", JobHistoryFileName,strerror(errno)); exit(1); } // In case of rotated history files, check if we have already reached the number of // matches specified by the user before reading the next file if (specifiedMatch != 0) { if (matchCount == specifiedMatch) { // Already found n number of matches, cleanup fclose(LogFile); return; } } if (backwards) { offset = findLastDelimiter(LogFile, JobHistoryFileName); } if(longformat && use_xml) { std::string out; AddClassAdXMLFileHeader(out); printf("%s\n", out.c_str()); } while(!EndFlag) { if (backwards) { // Read history file backwards if (BOF) { // If reached beginning of file break; } offset = findPrevDelimiter(LogFile, JobHistoryFileName, offset); if (offset == -1) { // Unable to match constraint break; } else if (offset != 0) { fseek(LogFile, offset, SEEK_SET); buf.readLine(LogFile); // Read one line to skip delimiter and adjust to actual offset of ad } else { // Offset set to 0 BOF = true; fseek(LogFile, offset, SEEK_SET); } } if( !( ad=new ClassAd(LogFile,"***", EndFlag, ErrorFlag, EmptyFlag) ) ){ fprintf( stderr, "Error: Out of memory\n" ); exit( 1 ); } if( ErrorFlag ) { printf( "\t*** Warning: Bad history file; skipping malformed ad(s)\n" ); ErrorFlag=0; if(ad) { delete ad; ad = NULL; } continue; } if( EmptyFlag ) { EmptyFlag=0; if(ad) { delete ad; ad = NULL; } continue; } if (!constraint || constraint[0]=='\0' || EvalBool(ad, constraintExpr)) { if (longformat) { if( use_xml ) { fPrintAdAsXML(stdout, *ad); } else { fPrintAd(stdout, *ad); } printf("\n"); } else { if (customFormat) { mask.display(stdout, ad); } else { displayJobShort(ad); } } matchCount++; // if control reached here, match has occured if (specifiedMatch != 0) { // User specified a match number if (matchCount == specifiedMatch) { // Found n number of matches, cleanup if (ad) { delete ad; ad = NULL; } fclose(LogFile); return; } } } if(ad) { delete ad; ad = NULL; } } if(longformat && use_xml) { std::string out; AddClassAdXMLFileFooter(out); printf("%s\n", out.c_str()); } fclose(LogFile); return; }
void Rooster::poll() { dprintf(D_FULLDEBUG,"C**k-a-doodle-doo! (Time to look for machines to wake up.)\n"); ClassAdList startdAds; CondorQuery unhibernateQuery(STARTD_AD); ExprTree *requirements = NULL; if( ParseClassAdRvalExpr( m_unhibernate_constraint.Value(), requirements )!=0 || requirements==NULL ) { EXCEPT("Invalid expression for ROOSTER_UNHIBERNATE: %s\n", m_unhibernate_constraint.Value()); } unhibernateQuery.addANDConstraint(m_unhibernate_constraint.Value()); CollectorList* collects = daemonCore->getCollectorList(); ASSERT( collects ); QueryResult result; result = collects->query(unhibernateQuery,startdAds); if( result != Q_OK ) { dprintf(D_ALWAYS, "Couldn't fetch startd ads using constraint " "ROOSTER_UNHIBERNATE=%s: %s\n", m_unhibernate_constraint.Value(), getStrQueryResult(result)); return; } dprintf(D_FULLDEBUG,"Got %d startd ads matching ROOSTER_UNHIBERNATE=%s\n", startdAds.MyLength(), m_unhibernate_constraint.Value()); startdAds.Sort(StartdSortFunc,&m_rank_ad); startdAds.Open(); int num_woken = 0; ClassAd *startd_ad; HashTable<MyString,bool> machines_done(MyStringHash); while( (startd_ad=startdAds.Next()) ) { MyString machine; MyString name; startd_ad->LookupString(ATTR_MACHINE,machine); startd_ad->LookupString(ATTR_NAME,name); if( machines_done.exists(machine)==0 ) { dprintf(D_FULLDEBUG, "Skipping %s: already attempted to wake up %s in this cycle.\n", name.Value(),machine.Value()); continue; } // in case the unhibernate expression is time-sensitive, // re-evaluate it now to make sure it still passes if( !EvalBool(startd_ad,requirements) ) { dprintf(D_ALWAYS, "Skipping %s: ROOSTER_UNHIBERNATE is no longer true.\n", name.Value()); continue; } if( wakeUp(startd_ad) ) { machines_done.insert(machine,true); if( ++num_woken >= m_max_unhibernate && m_max_unhibernate > 0 ) { dprintf(D_ALWAYS, "Reached ROOSTER_MAX_UNHIBERNATE=%d in this cycle.\n", m_max_unhibernate); break; } } } startdAds.Close(); delete requirements; requirements = NULL; if( startdAds.MyLength() ) { dprintf(D_FULLDEBUG,"Done sending wakeup calls.\n"); } }
ALERROR CDockScreenItemList::OnInitList (SInitCtx &Ctx, CString *retsError) // OnInitList // // Initialize list { CSpaceObject *pListSource; // Get the list options element CXMLElement *pOptions = Ctx.pDesc->GetContentElementByTag(LIST_OPTIONS_TAG); if (pOptions == NULL) { *retsError = CONSTLIT("<ListOptions> expected."); return ERR_FAIL; } // Figure out where to get the data from: either the station // or the player's ship. pListSource = EvalListSource(pOptions->GetAttribute(DATA_FROM_ATTRIB), retsError); if (pListSource == NULL) return ERR_FAIL; // Set the list control m_pItemListControl->SetList(pListSource); // Initialize flags that control what items we will show CString sCriteria; if (!EvalString(pOptions->GetAttribute(LIST_ATTRIB), false, eventNone, &sCriteria)) { *retsError = sCriteria; return ERR_FAIL; } CItem::ParseCriteria(sCriteria, &m_ItemCriteria); m_pItemListControl->SetFilter(m_ItemCriteria); // If we have content, then eval the function (note that this might // re-enter and set the filter) CString sCode = pOptions->GetContentText(0); if (!sCode.IsBlank()) { if (!EvalString(sCode, true, eventInitDockScreenList, retsError)) return ERR_FAIL; } // Position the cursor on the next relevant item SelectNextItem(); // Give the screen a chance to start at a different item (other // than the first) CString sInitialItemFunc = pOptions->GetAttribute(INITIAL_ITEM_ATTRIB); if (!sInitialItemFunc.IsBlank()) { bool bMore = IsCurrentItemValid(); while (bMore) { bool bResult; if (!EvalBool(sInitialItemFunc, &bResult, retsError)) return ERR_FAIL; if (bResult) break; bMore = SelectNextItem(); } } // Done return NOERROR; }