int ReliSock::accept( ReliSock &c ) { int c_sock; if (_state != sock_special || _special_state != relisock_listen || c._state != sock_virgin) { return FALSE; } if (_timeout > 0) { Selector selector; selector.set_timeout( _timeout ); selector.add_fd( _sock, Selector::IO_READ ); selector.execute(); if( selector.timed_out() ) { return FALSE; } else if ( !selector.has_ready() ) { dprintf( D_ALWAYS, "select returns %d, connect failed\n", selector.select_retval() ); return FALSE; } } #ifndef WIN32 /* Unix */ errno = 0; #endif if ((c_sock = condor_accept(_sock, c._who)) < 0) { #ifndef WIN32 /* Unix */ if ( errno == EMFILE ) { _condor_fd_panic ( __LINE__, __FILE__ ); /* This calls dprintf_exit! */ } #endif return FALSE; } c.assign(c_sock); c.enter_connected_state("ACCEPT"); c.decode(); int on = 1; c.setsockopt(SOL_SOCKET, SO_KEEPALIVE, (char*)&on, sizeof(on)); /* Set no delay to disable Nagle, since we buffer all our relisock output and it degrades performance of our various chatty protocols. -Todd T, 9/05 */ c.setsockopt(IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on)); return TRUE; }
void initialize() { char *tmp; string collName; dprintf(D_FULLDEBUG, "AviaryLocatorPlugin: Initializing...\n"); tmp = param("COLLECTOR_NAME"); if (NULL == tmp) { collName = getPoolName(); } else { collName = tmp; free(tmp); tmp = NULL; } string log_name; formatstr(log_name,"aviary_locator.log"); provider = AviaryProviderFactory::create(log_name, getPoolName(),CUSTOM,LOCATOR, "services/locator/"); if (!provider) { EXCEPT("Unable to configure AviaryProvider. Exiting..."); } ReliSock *sock = new ReliSock; if (!sock) { EXCEPT("Failed to allocate transport socket"); } if (!sock->assign(provider->getListenerSocket())) { EXCEPT("Failed to bind transport socket"); } int index; if (-1 == (index = daemonCore->Register_Socket((Stream *) sock, "Aviary Method Socket", (SocketHandlercpp) ( &AviaryLocatorPlugin::handleTransportSocket ), "Handler for Aviary Methods.", this))) { EXCEPT("Failed to register transport socket"); } int pruning_interval = param_integer("AVIARY_LOCATOR_PRUNE_INTERVAL",20); if (-1 == (index = daemonCore->Register_Timer( pruning_interval,pruning_interval*2, (TimerHandlercpp)(&AviaryLocatorPlugin::handleTimerCallback), "Timer for pruning unresponsive endpoints", this))) { EXCEPT("Failed to register pruning timer"); } }
void initialize() { char *tmp; string collName; dprintf(D_FULLDEBUG, "AviaryCollectorPlugin: Initializing...\n"); tmp = param("COLLECTOR_NAME"); if (NULL == tmp) { collName = getPoolName(); } else { collName = tmp; free(tmp); tmp = NULL; } string log_name("aviary_collector.log"); string id_name("collector"); id_name+=SEPARATOR; id_name+=getPoolName(); provider = AviaryProviderFactory::create(log_name, id_name,"COLLECTOR","POOL","services/collector/"); if (!provider) { EXCEPT("Unable to configure AviaryProvider. Exiting..."); } collector = CollectorObject::getInstance(); ReliSock *sock = new ReliSock; if (!sock) { EXCEPT("Failed to allocate transport socket"); } if (!sock->assign(provider->getListenerSocket())) { EXCEPT("Failed to bind transport socket"); } int index; if (-1 == (index = daemonCore->Register_Socket((Stream *) sock, "Aviary Method Socket", (SocketHandlercpp) ( &AviaryCollectorPlugin::handleTransportSocket ), "Handler for Aviary Methods.", this))) { EXCEPT("Failed to register transport socket"); } collector->setMyAddress(daemonCore->publicNetworkIpAddr()); }
void AviaryScheddPlugin::earlyInitialize() { // Since this plugin is registered with multiple // PluginManagers it may be initialized more than once, // and we don't want that static bool skip = false; if (skip) return; skip = true; string log_name("aviary_job.log"); string id_name("job"); id_name+=SEPARATOR; id_name+=getScheddName(); provider = AviaryProviderFactory::create(log_name,id_name, "SCHEDULER","JOB","services/job/"); if (!provider) { EXCEPT("Unable to configure AviaryProvider. Exiting..."); } schedulerObj = SchedulerObject::getInstance(); dirtyJobs = new DirtyJobsType(); isHandlerRegistered = false; ReliSock *sock = new ReliSock; if (!sock) { EXCEPT("Failed to allocate transport socket"); } if (!sock->assign(provider->getListenerSocket())) { EXCEPT("Failed to bind transport socket"); } int index; if (-1 == (index = daemonCore->Register_Socket((Stream *) sock, "Aviary Method Socket", (SocketHandlercpp) ( &AviaryScheddPlugin::handleTransportSocket ), "Handler for Aviary Methods.", this))) { EXCEPT("Failed to register transport socket"); } m_initialized = false; }
void Triggerd::init() { std::string trigger_log; ClassAd* ad; HashKey key; uint32_t key_value; ReliSock* sock; int index; char* host; char* tmp; char* dataDir = NULL; char* username; char* password; char* mechanism; int port, interval; std::string storefile; std::string error_text; std::stringstream int_str; qpid::management::ConnectionSettings settings; bool enable_console = true; dprintf(D_FULLDEBUG, "Triggerd::init called\n"); char* name = param("TRIGGERD_NAME"); if (name) { char* valid_name = build_valid_daemon_name(name); daemonName = valid_name; delete[] name; delete[] valid_name; } else { char* default_name = build_valid_daemon_name("triggerd"); if(default_name) { daemonName = default_name; delete[] default_name; } } port = param_integer("QMF_BROKER_PORT", 5672); if (NULL == (host = param("QMF_BROKER_HOST"))) { host = strdup("localhost"); } if (NULL == (username = param("QMF_BROKER_USERNAME"))) { username = strdup(""); } if (NULL == (mechanism = param("QMF_BROKER_AUTH_MECH"))) { mechanism = strdup("ANONYMOUS"); } tmp = param("QMF_STOREFILE"); if (NULL == tmp) { storefile = ".triggerd_storefile"; } else { storefile = tmp; free(tmp); tmp = NULL; } interval = param_integer("QMF_UPDATE_INTERVAL", 10); password = getBrokerPassword(); dataDir = param("DATA"); ASSERT(dataDir); trigger_log = dataDir; trigger_log += "/triggers.log"; triggerCollection = new ClassAdCollection(NULL, trigger_log.c_str()); free(dataDir); settings.host = std::string(host); settings.port = port; settings.username = std::string(username); settings.password = std::string(password); settings.mechanism = std::string(mechanism); // Initialize the QMF agent singleton = new ManagementAgent::Singleton(); ManagementAgent* agent = singleton->getInstance(); CondorTriggerService::registerSelf(agent); CondorTrigger::registerSelf(agent); EventCondorTriggerNotify::registerSelf(agent); agent->setName("com.redhat.grid","condortriggerservice", daemonName.c_str()); agent->init(settings, interval, true, storefile); mgmtObject = new CondorTriggerService(agent, this); // Initialize the QMF console, if desired enable_console = param_boolean("ENABLE_ABSENT_NODES_DETECTION", false); if (true == enable_console) { console = new TriggerConsole(); console->config(host, port, username, password, mechanism); } free(host); free(username); free(password); free(mechanism); // Initialize the triggers if any already exist triggerCollection->StartIterateAllClassAds(); while(true == triggerCollection->IterateAllClassAds(ad, key)) { key_value = atoll(key.value()); if (triggers.end() == triggers.find(key_value)) { if (STATUS_OK != AddTriggerToCollection(key_value, ad, error_text)) { dprintf(D_ALWAYS, "Triggerd Error: '%s'. Removing trigger\n", error_text.c_str()); int_str << key_value; triggerCollection->DestroyClassAd(int_str.str().c_str()); } } } bool lifetime = param_boolean("QMF_IS_PERSISTENT", true); agent->addObject(mgmtObject, daemonName.c_str(), lifetime); // Create a socket to handle management method calls sock = new ReliSock; if (NULL == sock) { EXCEPT("Failed to create Managment socket"); } if (0 == sock->assign(agent->getSignalFd())) { EXCEPT("Failed to bind Management socket"); } if (-1 == (index = daemonCore->Register_Socket((Stream *) sock, "Management Method Socket", (SocketHandlercpp) &Triggerd::HandleMgmtSocket, "Handler for Management Methods", this))) { EXCEPT("Failed to register Management socket"); } config(); }
void main_init(int /* argc */, char * /* argv */ []) { dprintf(D_ALWAYS, "main_init() called\n"); if (param_boolean("QMF_PUBLISH_SUBMISSIONS", false)) { EXCEPT("Schedd QMF plug-in is configured to publish submissions!"); } consumer = new JobServerJobLogConsumer(); mirror = new JobLogMirror(consumer); mirror->init(); char *host; char *username; char *password; char *mechanism; int port; char *tmp; string storefile,historyfile; singleton = new ManagementAgent::Singleton(); ManagementAgent *agent = singleton->getInstance(); JobServer::registerSelf(agent); Submission::registerSelf(agent); port = param_integer("QMF_BROKER_PORT", 5672); if (NULL == (host = param("QMF_BROKER_HOST"))) { host = strdup("localhost"); } tmp = param("QMF_STOREFILE"); if (NULL == tmp) { storefile = ".job_server_storefile"; } else { storefile = tmp; free(tmp); tmp = NULL; } if (NULL == (username = param("QMF_BROKER_USERNAME"))) { username = strdup(""); } if (NULL == (mechanism = param("QMF_BROKER_AUTH_MECH"))) { mechanism = strdup("ANONYMOUS"); } password = getBrokerPassword(); string jsName = build_valid_daemon_name("jobs@"); jsName += default_daemon_name(); agent->setName("com.redhat.grid","jobserver", jsName.c_str()); agent->init(string(host), port, param_integer("QMF_UPDATE_INTERVAL", 10), true, storefile, username, password, mechanism); free(host); free(username); free(password); free(mechanism); construct_schedd_ref(schedd_oid); job_server = new JobServerObject(agent, jsName.c_str(), *schedd_oid); init_classad(); ReliSock *sock = new ReliSock; if (!sock) { EXCEPT("Failed to allocate Mgmt socket"); } if (!sock->assign(agent->getSignalFd())) { EXCEPT("Failed to bind Mgmt socket"); } int index; if (-1 == (index = daemonCore->Register_Socket((Stream *) sock, "Mgmt Method Socket", (SocketHandler) HandleMgmtSocket, "Handler for Mgmt Methods."))) { EXCEPT("Failed to register Mgmt socket"); } // before doing any job history processing, set the location of the files // TODO: need to test mal-HISTORY values: HISTORY=/tmp/somewhere const char* tmp2 = param ( "HISTORY" ); StatInfo si( tmp2 ); tmp2 = si.DirPath (); if ( !tmp2 ) { dprintf ( D_ALWAYS, "warning: No HISTORY defined - Job Server will not process history jobs\n" ); } else { m_path = tmp2; dprintf ( D_FULLDEBUG, "HISTORY path is %s\n",tmp2 ); // register a timer for processing of historical job files if (-1 == (index = daemonCore->Register_Timer( 0, param_integer("HISTORY_INTERVAL",120), (TimerHandler)ProcessHistoryTimer, "Timer for processing job history files" ))) { EXCEPT("Failed to register history timer"); } } // useful for testing job coalescing // and potentially just useful if (-1 == (index = daemonCore->Register_Signal(SIGUSR1, "Forced Reset Signal", (SignalHandler) HandleResetSignal, "Handler for Reset signals"))) { EXCEPT("Failed to register Reset signal"); } }