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"); } }