Exemple #1
0
int main_int(int argc, char** argv)
{
    singleton = new ManagementAgent::Singleton();
    const char* host = argc>1 ? argv[1] : "127.0.0.1";
    int port = argc>2 ? atoi(argv[2]) : 5672;

    signal(SIGINT, shutdown);

    // Create the qmf management agent
    ManagementAgent* agent = singleton->getInstance();

    // Register the Qmf_example schema with the agent
    _qmf::Package packageInit(agent);

    // Name the agent.
    agent->setName("apache.org", "qmf-example");

    // Start the agent.  It will attempt to make a connection to the
    // management broker
    agent->init(host, port, 5, false, ".magentdata");

    // Allocate some core objects
    CoreClass core1(agent, "Example Core Object #1");
    CoreClass core2(agent, "Example Core Object #2");
    CoreClass core3(agent, "Example Core Object #3");

    core1.doLoop();

    // done, cleanup and exit
    delete singleton;

    return 0;
}
Exemple #2
0
//==============================================================
// Main program
//==============================================================
int main(int argc, char** argv) {
    int arg;
    int idx = 0;
    bool verbose = false;
    bool daemonize = false;
    bool gssapi = false;
    char *host = NULL;
    char *username = NULL;
    char *service = NULL;
    int port = 5672;

    struct option opt[] = {
        {"help", 0, 0, 'h'},
        {"daemon", 0, 0, 'd'},
        {"broker", 1, 0, 'b'},
        {"gssapi", 0, 0, 'g'},
        {"username", 1, 0, 'u'},
        {"service", 1, 0, 's'},
        {"port", 1, 0, 'p'},
        {0, 0, 0, 0}
    };

    while ((arg = getopt_long(argc, argv, "hdb:gu:s:p:", opt, &idx)) != -1) {
        switch (arg) {
            case 'h':
            case '?':
                print_usage();
                exit(0);
                break;
            case 'd':
                daemonize = true;
                break;
            case 'v':
                verbose = true;
                break;
            case 's':
                if (optarg) {
                    service = strdup(optarg);
                } else {
                    print_usage();
                    exit(1);
                }
                break;
            case 'u':
                if (optarg) {
                    username = strdup(optarg);
                } else {
                    print_usage();
                    exit(1);
                }
                break;
            case 'g':
                gssapi = true;
                break;
            case 'p':
                if (optarg) {
                    port = atoi(optarg);
                } else {
                    print_usage();
                    exit(1);
                }
                break;
            case 'b':
                if (optarg) {
                    host = strdup(optarg);
                } else {
                    print_usage();
                    exit(1);
                }
                break;
            default:
                fprintf(stderr, "unsupported option '-%c'.  See --help.\n", arg);
                print_usage();
                exit(0);
            break;
        }
    }

    if (daemonize == true) {
        if (daemon(0, 0) < 0) {
            fprintf(stderr, "Error daemonizing: %s\n", strerror(errno));
            exit(1);
        }
    }
    openlog("libvirt-qpid", 0, LOG_DAEMON);

    // This prevents us from dying if libvirt disconnects.
    signal(SIGPIPE, SIG_IGN);

    // Create the management agent
    ManagementAgent::Singleton singleton;
    ManagementAgent* agent = singleton.getInstance();

    // Register the schema with the agent
    _qmf::Package packageInit(agent);

    // Start the agent.  It will attempt to make a connection to the
    // management broker.  The third argument is the interval for sending
    // updates to stats/properties to the broker.  The last is set to 'true'
    // to keep this all single threaded.  Otherwise a second thread would be
    // used to implement methods.

    qpid::management::ConnectionSettings settings;
    settings.host = host ? host : "127.0.0.1";
    settings.port = port;

    if (username != NULL) {
        settings.username = username;
    }
    if (service != NULL) {
        settings.service = service;
    }
    if (gssapi == true) {
        settings.mechanism = "GSSAPI";
    }

    agent->setName("Red Hat", "libvirt-qpid");
    agent->init(settings, 3, true);

    while(true) {
        try {
            NodeWrap node(agent, "Libvirt Node");
            node.doLoop();
        } catch (int err) {
        }
        sleep(10);
    }
}
Exemple #3
0
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");
	}
}