Beispiel #1
0
int32_t
Tester::GetInterval()
{
   Object::AttributeMap args;
   MethodResponse result;
   Object::Vector list;

   sm->getObjects(list, "condortriggerservice");
   if (0 < list.size())
   {
      cout << "Retrieving Interval" << endl;
      Object& triggerService = *list.begin();
      triggerService.invokeMethod("GetEvalInterval", args, result);
      cout << "Result: code=" << result.code << " text=" << result.text << endl << endl;
   }
   return atoll(result.arguments.begin()->second->str().c_str());
}
Beispiel #2
0
void
Tester::RemoveTrigger(uint32_t id)
{
   Object::AttributeMap args;
   MethodResponse result;
   Object::Vector list;

   sm->getObjects(list, "condortriggerservice");
   if (0 < list.size())
   {
      cout << "Removing Trigger ID: " << id << endl;
      Object& triggerService = *list.begin();
      args.addUint("TriggerID", id);
      triggerService.invokeMethod("RemoveTrigger", args, result);
      cout << "Result: code=" << result.code << " text=" << result.text << endl << endl;
   }
}
Beispiel #3
0
void
Tester::ChangeTriggerText(uint32_t id, const char* text)
{
   Object::AttributeMap args;
   MethodResponse result;
   Object::Vector list;

   sm->getObjects(list, "condortriggerservice");
   if (0 < list.size())
   {
      cout << "Changing Trigger Text to : " << text << endl;
      Object& triggerService = *list.begin();
      args.addUint("TriggerID", id);
      args.addString("Text", std::string(text));
      triggerService.invokeMethod("SetTriggerText", args, result);
      cout << "Result: code=" << result.code << " text=" << result.text << endl << endl;
   }
}
Beispiel #4
0
void
Tester::SetInterval(int32_t interval)
{
   Object::AttributeMap args;
   MethodResponse result;
   Object::Vector list;

// Hack.  Can safely be removed once qmf is fixed
   sm->getObjects(list, "agent");
   sm->getObjects(list, "condortriggerservice");
   if (0 < list.size())
   {
      cout << "Setting Interval to " << interval << endl;
      Object& triggerService = *list.begin();
      args.addInt("Interval", interval);
      triggerService.invokeMethod("SetEvalInterval", args, result);
      cout << "Result: code=" << result.code << " text=" << result.text << endl << endl;
   }
}
Beispiel #5
0
void
Tester::AddTrigger(const char* name, const char* query, const char* text)
{
   Object::AttributeMap args;
   MethodResponse result;
   Object::Vector list;

   cout << "AddTrigger called" << endl;

   sm->getObjects(list, "condortriggerservice");
   cout << "# of objects: " << list.size() << endl;
   if (0 < list.size())
   {
      cout << "Adding Trigger: " << name << endl;
      Object& triggerService = *list.begin();
      args.addString("Name", std::string(name));
      args.addString("Query", std::string(query));
      args.addString("Text", std::string(text));

      triggerService.invokeMethod("AddTrigger", args, result);
      cout << "Result: code=" << result.code << " text=" << result.text << endl << endl;
   }
}
Beispiel #6
0
list<string>
SimpleConsole::findAbsentNodes()
{
	list<string> missing;
	Object::Vector objs;

	try {
		sessionManager->getObjects(objs, "Node");
	} catch(...) {
		cout << "Failed to get roster of Nodes" << endl;
		return missing;
	}

	cout << "Roster contains " << objs.size() << " nodes" << endl;

	for (Object::Vector::const_iterator obj = objs.begin();
		 objs.end() != obj;
		 obj++) {
		cout << " . " << obj->attrString("name") << endl;
		missing.push_back(obj->attrString("name"));
	}

	try {
		sessionManager->getObjects(objs, "master");
	} catch(...) {
		cout << "Failed to get list of present Nodes" << endl;
		return missing;
	}

	cout << objs.size() << " nodes present" << endl;

	for (Object::Vector::const_iterator obj = objs.begin();
		 objs.end() != obj;
		 obj++) {
		missing.remove(obj->attrString("Name"));
	}

	cout << "Found " << missing.size() << " missing nodes" << endl;

	return missing;
}
Beispiel #7
0
    int run(int argc, char** argv)
    {
        //
        // Tune the settings for this application:  We will operate synchronously only, we don't
        // wish to use the bandwidth needed to aysnchronously receive objects or events.
        //
        SessionManager::Settings sessionSettings;
        sessionSettings.rcvObjects = false;
        sessionSettings.rcvEvents = false;
        sessionSettings.rcvHeartbeats = false;

        SessionManager sm(this, sessionSettings);

        //
        // Connect to the brokers.
        //
        for (int idx = 1; idx < argc; idx++) {
            qpid::client::ConnectionSettings connSettings;
            connSettings.host = "localhost";
            connSettings.port = atoi(argv[idx]);
            Broker* broker = sm.addBroker(connSettings);

            Mutex::ScopedLock l(lock);
            brokerMap[broker] = false; // initially assume broker is disconnected
        }

        //
        // Periodically poll the first connected broker.
        //
        while (!stopping) {
            //
            // Find an operational broker
            //
            Broker* operationalBroker = 0;
            {
                Mutex::ScopedLock l(lock);
                for (map<Broker*, bool>::iterator iter = brokerMap.begin();
                     iter != brokerMap.end(); iter++) {
                    if (iter->second) {
                        operationalBroker = iter->first;
                        break;
                    }
                }
            }

            if (operationalBroker != 0) {
                Object::Vector list;
                sm.getObjects(list, "queue", operationalBroker);
                for (Object::Vector::iterator i = list.begin(); i != list.end(); i++) {
                    cout << "queue: " << i->attrString("name");
                    cout << "  bindingCount=" << i->attrUint64("bindingCount") << endl;
                }
            } else {
                cout << "No operational brokers" << endl;
            }

            qpid::sys::sleep(10);
            if (stopping)
                break;
        }

        {
            //
            //  The following code structure uses the mutex to protect the broker map while
            //  ensuring that sm.delBroker is called without the mutex held (which leads to
            //  a deadlock).
            //
            Mutex::ScopedLock l(lock);
            map<Broker*, bool>::iterator iter = brokerMap.begin();
            while (iter != brokerMap.end()) {
                Broker* broker = iter->first;
                brokerMap.erase(iter);
                {
                    Mutex::ScopedUnlock ul(lock);
                    sm.delBroker(broker);
                }
                iter = brokerMap.begin();
            }
        }

        return 0;
    }
Beispiel #8
0
int main_int(int argc, char** argv)
{
   SessionManager* smgr;
   Tester engine;
   Object::Vector list;
   Object::AttributeMap args;
//   ClassKey ckey;
   MethodResponse result;
   std::string id;
   const char* host = argc>1 ? argv[1] : "127.0.0.1";
   int port = argc>2 ? atoi(argv[2]) : 5672;
   uint32_t trigger_id;
   int32_t interval;
   time_t first_event, second_event;

   engine.init(host, port);
   smgr = engine.GetSessionManager();

   smgr->getObjects(list, "agent");
   smgr->getObjects(list, "condortrigger");
   cout << "Currently installed triggers:" << endl;
   for (Object::Vector::iterator iter = list.begin(); iter != list.end(); iter++)
   {
      cout << "Trigger ID: " << atoll(iter->getIndex().c_str()) << endl;
      iter->invokeMethod("GetTriggerName", args, result);
      cout << "Trigger Name: " << result.arguments.begin()->second->str() << endl;
      iter->invokeMethod("GetTriggerQuery", args, result);
      cout << "Trigger Query: " << result.arguments.begin()->second->str() << endl;
      iter->invokeMethod("GetTriggerText", args, result);
      cout << "Trigger Text: " << result.arguments.begin()->second->str() << endl << endl;
   }

   // Set the evaluation interval to 5 seconds
   engine.SetInterval(5);
   interval = engine.GetInterval();

   if (interval != 5)
   {
      cout << "Error: Interval was not to 5 seconds" << endl;
   }

   // Add a trigger and verify an event is received
   engine.AddTrigger("TestTrigger", "(SlotID == 1)", "$(Machine) has a slot 1");

   while (false == engine.GetEventReceived())
   {
      sleep(1);
   }
   first_event = time(NULL);
   engine.ResetEventReceived();

   while (false == engine.GetEventReceived())
   {
      sleep(1);
   }
   second_event = time(NULL);
   engine.ResetEventReceived();

   if ((second_event - first_event) > 6)
   {
      cout << "Error: Trigger evaluations occurring greater than evey 5 seconds" << endl;
   }
   else
   {
      cout << "Trigger evaluations occurring every 5 seconds" << endl;
   }

   // Retrieve the ID of the trigger added
   smgr->getObjects(list, "agent");
   smgr->getObjects(list, "condortrigger");
   for (Object::Vector::iterator iter = list.begin(); iter != list.end(); iter++)
   {
      iter->invokeMethod("GetTriggerName", args, result);
      if (result.arguments.begin()->second->str() == "TestTrigger")
      {
         cout << "Getting trigger id" << endl;
         trigger_id = atoll(iter->getIndex().c_str());
         break;
      }
   }

   // Change the trigger Name and verify an event is received
   engine.ChangeTriggerName(trigger_id, "Changed Test Trigger");
   while (false == engine.GetEventReceived())
   {
      sleep(1);
   }
   engine.ResetEventReceived();

   // Change the trigger query and text and verify an event is received
   engine.ChangeTriggerQuery(trigger_id, "(SlotID > 0)");
   engine.ChangeTriggerText(trigger_id, "$(Machine) has a slot $(SlotID)");
   while (false == engine.GetEventReceived())
   {
      sleep(1);
   }
   engine.ResetEventReceived();

   // Remove the trigger
   engine.RemoveTrigger(trigger_id);

   return 0;
}