bool DCMaster::sendMasterCommand( bool insure_update, int my_cmd ) { CondorError errstack; int master_cmd = my_cmd; dprintf( D_FULLDEBUG, "DCMaster::sendMasterCommand: Just starting... \n"); /* have we located the required master yet? */ if( ! _addr ) { locate(); } if( ! m_master_safesock && ! insure_update ) { m_master_safesock = new SafeSock; m_master_safesock->timeout(20); // years of research... :) if( ! m_master_safesock->connect(_addr) ) { dprintf( D_ALWAYS, "sendMasterCommand: Failed to connect to master " "(%s)\n", _addr ); delete m_master_safesock; m_master_safesock = NULL; return false; } } ReliSock reli_sock; bool result; if( insure_update ) { // For now, if we have to ensure that the update gets // there, we use a ReliSock (TCP). reli_sock.timeout(20); // years of research... :) if( ! reli_sock.connect(_addr) ) { dprintf( D_ALWAYS, "sendMasterCommand: Failed to connect to master " "(%s)\n", _addr ); return false; } result = sendCommand( master_cmd, (Sock*)&reli_sock, 0, &errstack ); } else { result = sendCommand( master_cmd, (Sock*)m_master_safesock, 0, &errstack ); } if( ! result ) { dprintf( D_FULLDEBUG, "Failed to send %d command to master\n",master_cmd ); if( m_master_safesock ) { delete m_master_safesock; m_master_safesock = NULL; } if( errstack.code() != 0 ) { dprintf( D_ALWAYS, "ERROR: %s\n", errstack.getFullText() ); } return false; } return true; }
bool Triggerd::PerformQueries() { ClassAdList result; CondorError errstack; QueryResult status; Trigger* trig = NULL; CondorQuery* query; bool ret_val = true; std::map<uint32_t,Trigger*>::iterator iter; ClassAd* ad = NULL; std::string eventText; char* token = NULL; std::string triggerText; char* queryString = NULL; ExprTree* attr = NULL; std::list<std::string> missing_nodes; size_t pos; size_t prev_pos; bool bad_trigger = false; const char* token_str = NULL; if (0 < triggers.size()) { dprintf(D_FULLDEBUG, "Triggerd: Evaluating %d triggers\n", (int)triggers.size()); query = new CondorQuery(ANY_AD); for (iter = triggers.begin(); iter != triggers.end(); iter++) { // Clear any pre-exhisting custom contraints and add the constraint // for this trigger trig = iter->second; query->clearORCustomConstraints(); query->clearANDCustomConstraints(); queryString = strdup(trig->GetQuery().c_str()); ReplaceAllChars(queryString, '\'', '"'); query->addANDConstraint(queryString); free(queryString); // Perform the query and check the result if (NULL != query_collector) { status = query->fetchAds(result, query_collector->addr(), &errstack); } else { status = collectors->query(*query, result, &errstack); } if (Q_OK != status) { // Problem with the query if (Q_COMMUNICATION_ERROR == status) { dprintf(D_ALWAYS, "Triggerd Error: Error contacting the collecter - %s\n", errstack.getFullText(true).c_str()); if (CEDAR_ERR_CONNECT_FAILED == errstack.code(0)) { dprintf(D_ALWAYS, "Triggerd Error: Couldn't contact the collector on the central manager\n"); } } else { dprintf(D_ALWAYS, "Triggerd Error: Could not retrieve ads - %s\n", getStrQueryResult(status)); } ret_val = false; break; } else { dprintf(D_FULLDEBUG, "Query successful. Parsing results\n"); // Query was successful, so parse the results result.Open(); while ((ad = result.Next())) { if (true == bad_trigger) { // Avoid processing a bad trigger multiple times. Remove // all result ads and reset the flag dprintf(D_FULLDEBUG, "Cleaning up after a bad trigger\n"); result.Delete(ad); while ((ad = result.Next())) { result.Delete(ad); } bad_trigger = false; break; } eventText = ""; triggerText = trig->GetText(); dprintf(D_FULLDEBUG, "Parsing trigger text '%s'\n", triggerText.c_str()); prev_pos = pos = 0; while (prev_pos < triggerText.length()) { pos = triggerText.find("$(", prev_pos, 2); if (std::string::npos == pos) { // Didn't find the start of a varible, so append the // remaining string dprintf(D_FULLDEBUG, "Adding text string to event text\n"); eventText += triggerText.substr(prev_pos, std::string::npos); prev_pos = triggerText.length(); } else { // Found a variable for substitution. Need to add // text before it to the string, grab the variable // to substitute for, and put its value in the text eventText += triggerText.substr(prev_pos, pos - prev_pos); dprintf(D_FULLDEBUG, "Adding text string prior to variable substitution to event text\n"); // Increment the position by 2 to skip the $( prev_pos = pos + 2; pos = triggerText.find(")", prev_pos, 1); if (std::string::npos == pos) { // Uh-oh. We have a start of a variable substitution // but no closing marker. dprintf(D_FULLDEBUG, "Error: Failed to find closing varable substitution marker ')'. Aborting processing of the trigger\n"); bad_trigger = true; break; } else { token_str = triggerText.substr(prev_pos, pos-prev_pos).c_str(); token = RemoveWS(token_str); dprintf(D_FULLDEBUG, "token: '%s'\n", token); if (NULL == token) { dprintf(D_ALWAYS, "Removing whitespace from %s produced unusable name. Aborting processing of the trigger\n", token_str); bad_trigger = true; break; } attr = ad->LookupExpr(token); if (NULL == attr) { // The token isn't found in the classad, so treat it // like a string dprintf(D_FULLDEBUG, "Adding text string to event text\n"); eventText += token; } else { dprintf(D_FULLDEBUG, "Adding classad value to event text\n"); eventText += ExprTreeToString(attr); } if (NULL != token) { free(token); token = NULL; } ++pos; } prev_pos = pos; } } // Remove the trailing space std::string::size_type notwhite = eventText.find_last_not_of(" "); eventText.erase(notwhite+1); // Send the event if (false == bad_trigger) { EventCondorTriggerNotify event(eventText, time(NULL)); singleton->getInstance()->raiseEvent(event); dprintf(D_FULLDEBUG, "Triggerd: Raised event with text '%s'\n", eventText.c_str()); } result.Delete(ad); } bad_trigger = false; result.Close(); } } delete query; } else { dprintf(D_FULLDEBUG, "Triggerd: No triggers to evaluate\n"); } // Look for absent nodes (nodes expected to be in the pool but aren't) if (NULL != console) { missing_nodes = console->findAbsentNodes(); if (0 < missing_nodes.size()) { for (std::list<std::string>::iterator node = missing_nodes.begin(); node != missing_nodes.end(); ++ node) { eventText = node->c_str(); eventText += " is missing from the pool"; EventCondorTriggerNotify event(eventText, time(NULL)); singleton->getInstance()->raiseEvent(event); dprintf(D_FULLDEBUG, "Triggerd: Raised event with text '%s'\n", eventText.c_str()); } } } return ret_val; }
void printClassAd( void ) { printf( "%s = \"%s\"\n", ATTR_VERSION, CondorVersion() ); printf( "%s = True\n", ATTR_IS_DAEMON_CORE ); printf( "%s = True\n", ATTR_HAS_FILE_TRANSFER ); printf( "%s = True\n", ATTR_HAS_PER_FILE_ENCRYPTION ); printf( "%s = True\n", ATTR_HAS_RECONNECT ); printf( "%s = True\n", ATTR_HAS_MPI ); printf( "%s = True\n", ATTR_HAS_TDP ); printf( "%s = True\n", ATTR_HAS_JOB_DEFERRAL ); /* Attributes describing what kinds of Job Info Communicators this starter has. This is mostly for COD, but someday might be useful to other people, too. There's no need to advertise the fact we've got a JICShadow, since all starters always have and will be able to communicate with a shadow... */ printf( "%s = True\n", ATTR_HAS_JIC_LOCAL_CONFIG ); printf( "%s = True\n", ATTR_HAS_JIC_LOCAL_STDIN ); ClassAd *ad = java_detect(); if(ad) { int gotone=0; float mflops; char *str = 0; if(ad->LookupString(ATTR_JAVA_VENDOR,&str)) { printf("%s = \"%s\"\n",ATTR_JAVA_VENDOR,str); free(str); str = 0; gotone++; } if(ad->LookupString(ATTR_JAVA_VERSION,&str)) { printf("%s = \"%s\"\n",ATTR_JAVA_VERSION,str); free(str); str = 0; gotone++; } if(ad->LookupString("JavaSpecificationVersion",&str)) { printf("JavaSpecificationVersion = \"%s\"\n",str); free(str); str = 0; gotone++; } if(ad->LookupFloat(ATTR_JAVA_MFLOPS,mflops)) { printf("%s = %f\n", ATTR_JAVA_MFLOPS,mflops); gotone++; } if(gotone>0) printf( "%s = True\n",ATTR_HAS_JAVA); delete ad; } // VM universe stuff if( VMProc::vm_univ_detect() ) { // This doesn't mean that vm universe is really available. // This just means that starter has codes for vm universe. // Actual testing for vm universe will be // done by vmuniverse manager in startd. // ATTR_HAS_VM may be overwritten by vmuniverse manager in startd printf( "%s = True\n",ATTR_HAS_VM); } // Advertise which file transfer plugins are supported FileTransfer ft; CondorError e; ft.InitializePlugins(e); if (e.code()) { dprintf(D_ALWAYS, "WARNING: Initializing plugins returned: %s\n", e.getFullText().c_str()); } MyString method_list = ft.GetSupportedMethods(); if (!method_list.IsEmpty()) { printf("%s = \"%s\"\n", ATTR_HAS_FILE_TRANSFER_PLUGIN_METHODS, method_list.Value()); } #if defined(WIN32) // Advertise our ability to run jobs as the submitting user printf("%s = True\n", ATTR_HAS_WIN_RUN_AS_OWNER); #endif }