Exemple #1
0
uint32_t encodedSize(const Variant::List& values)
{
    uint32_t size = 4/*size field*/ + 4/*count field*/;
    for(Variant::List::const_iterator i = values.begin(); i != values.end(); ++i) {
        size += 1/*typecode*/ + encodedSize(*i);
    }
    return size;
}
Exemple #2
0
void PnData::write(const Variant::List& list)
{
    pn_data_put_list(data);
    pn_data_enter(data);
    for (Variant::List::const_iterator i = list.begin(); i != list.end(); ++i) {
        write(*i);
    }
    pn_data_exit(data);
}
Exemple #3
0
void encode(const Variant::List& list, uint32_t len, qpid::framing::Buffer& buffer)
{
    uint32_t s = buffer.getPosition();
    buffer.putLong(len - 4);//exclusive of the size field itself
    buffer.putLong(list.size());
    for (Variant::List::const_iterator i = list.begin(); i != list.end(); ++i) {
    	encode(*i, buffer);
    }
    (void) s; assert(s + len == buffer.getPosition());
}
qpid::types::Variant::List agocontrol::jsonToVariantList(Json::Value value) {
	Variant::List list;
	try {
		for (Json::ValueIterator it = value.begin(); it != value.end(); it++) {
			if ((*it).size() > 0) {
				// cout << "JSON Type: " << (*it).type() << endl;
				if ((*it).type() == 6) {
					list.push_back(jsonToVariantList((*it)));
				} else if ((*it).type() == 7) {
					list.push_back(jsonToVariantMap((*it)));
				}
			} else {
				if ((*it).isString()) list.push_back( (*it).asString());
				if ((*it).isBool()) list.push_back( (*it).asBool());
				if ((*it).isInt()) list.push_back( (*it).asInt());
				if ((*it).isUInt()) list.push_back( (*it).asUInt());
				if ((*it).isDouble()) list.push_back( (*it).asDouble());
			}
		}
	} catch (const std::exception& error) {
                cout << "ERROR! Exception during JSON->Variant::Map conversion!" << endl;
                stringstream errorstring;
                errorstring << error.what();
		cout << "EXCEPTION: " << errorstring.str() << endl;
        }


	return list;
}
Exemple #5
0
Manageable::status_t
SubmissionObject::GetJobSummaries ( Variant::List &jobs,
                            std::string &text )
{
	ClassAd *ad = NULL;
	MyString constraint;
	// id, timestamp (which?), command, args, ins, outs, state, message
	const char *ATTRS[] = {ATTR_CLUSTER_ID,
			ATTR_PROC_ID,
			ATTR_GLOBAL_JOB_ID,
			ATTR_Q_DATE,
			ATTR_ENTERED_CURRENT_STATUS,
			ATTR_JOB_STATUS,
			ATTR_JOB_CMD,
			ATTR_JOB_ARGUMENTS1,
			ATTR_JOB_ARGUMENTS2,
			ATTR_RELEASE_REASON,
			ATTR_HOLD_REASON,
			NULL
			};

	constraint.sprintf("%s == \"%s\"",
					   ATTR_JOB_SUBMISSION, this->m_name.c_str());

	dprintf(D_FULLDEBUG,"GetJobSummaries for submission: %s\n",constraint.Value());

	Variant::Map job;
	int init_scan = 1;
	while (NULL != (ad = GetNextJobByConstraint(constraint.Value(), init_scan))) {

		// debug
//		if (IsFulldebug(D_FULLDEBUG)) {
//			ad->dPrint(D_FULLDEBUG|D_NOHEADER);
//		}

		for (int i = 0; NULL != ATTRS[i]; i++) {
			if (!AddAttribute(*ad, ATTRS[i], job)) {
				dprintf(D_FULLDEBUG,"Warning: %s attribute not found for job of %s\n",ATTRS[i],constraint.Value());
			}
		}

		jobs.push_back(job);
		init_scan = 0;

		// debug
//		if (IsFulldebug(D_FULLDEBUG)) {
//			std::ostringstream oss;
//			oss << jobs;
//			dprintf(D_FULLDEBUG|D_NOHEADER, "%s\n",oss.str().c_str());
//		}

		FreeJobAd(ad);
		ad = NULL;
	}

	return STATUS_OK;
}
Exemple #6
0
CoreClass::CoreClass(ManagementAgent* _agent, string _name) : name(_name), agent(_agent)
{
    static uint64_t persistId = 0x111222333444555LL;
    mgmtObject = new _qmf::Parent(agent, this, name);

    agent->addObject(mgmtObject);
    mgmtObject->set_state("IDLE");

    Variant::Map args;
    Variant::Map subMap;
    args["first"] = "String data";
    args["second"] = 34;
    subMap["string-data"] = "Text";
    subMap["numeric-data"] = 10000;
    args["map-data"] = subMap;
    mgmtObject->set_args(args);

    Variant::List list;
    list.push_back(20000);
    list.push_back("string-item");
    mgmtObject->set_list(list);
}
Exemple #7
0
void AgentImpl::handleDataIndication(const Variant::List& list, const Message& msg)
{
    Variant::Map::const_iterator aIter;
    const Variant::Map& props(msg.getProperties());
    boost::shared_ptr<SyncContext> context;

    aIter = props.find("qmf.content");
    if (aIter == props.end())
        return;

    string content_type(aIter->second.asString());
    if (content_type != "_event")
        return;

    for (Variant::List::const_iterator lIter = list.begin(); lIter != list.end(); lIter++) {
        const Variant::Map& eventMap(lIter->asMap());
        Data data(new DataImpl(eventMap, this));
        int severity(SEV_NOTICE);
        uint64_t timestamp(0);

        aIter = eventMap.find("_severity");
        if (aIter != eventMap.end())
            severity = int(aIter->second.asInt8());

        aIter = eventMap.find("_timestamp");
        if (aIter != eventMap.end())
            timestamp = aIter->second.asUint64();

        auto_ptr<ConsoleEventImpl> eventImpl(new ConsoleEventImpl(CONSOLE_EVENT));
        eventImpl->setAgent(this);
        eventImpl->addData(data);
        eventImpl->setSeverity(severity);
        eventImpl->setTimestamp(timestamp);
        if (data.hasSchema())
            learnSchemaId(data.getSchemaId());
        session.enqueueEvent(eventImpl.release());
    }
}
Exemple #8
0
void AgentImpl::handleQueryResponse(const Variant::List& list, const Message& msg)
{
    const string& cid(msg.getCorrelationId());
    Variant::Map::const_iterator aIter;
    const Variant::Map& props(msg.getProperties());
    uint32_t correlator;
    bool final(false);
    boost::shared_ptr<SyncContext> context;

    aIter = props.find("partial");
    if (aIter == props.end())
        final = true;

    aIter = props.find("qmf.content");
    if (aIter == props.end())
        return;

    string content_type(aIter->second.asString());
    if (content_type != "_schema" && content_type != "_schema_id" && content_type != "_data")
        return;

    try { correlator = boost::lexical_cast<uint32_t>(cid); }
    catch(const boost::bad_lexical_cast&) { correlator = 0; }

    {
        qpid::sys::Mutex::ScopedLock l(lock);
        map<uint32_t, boost::shared_ptr<SyncContext> >::iterator iter = contextMap.find(correlator);
        if (iter != contextMap.end())
            context = iter->second;
    }

    if (context.get() != 0) {
        //
        // This response is associated with a synchronous request.
        //
        qpid::sys::Mutex::ScopedLock cl(context->lock);
        if (!context->response.isValid())
            context->response = ConsoleEvent(new ConsoleEventImpl(CONSOLE_QUERY_RESPONSE));

        if (content_type == "_data")
            for (Variant::List::const_iterator lIter = list.begin(); lIter != list.end(); lIter++) {
                Data data(new DataImpl(lIter->asMap(), this));
                ConsoleEventImplAccess::get(context->response).addData(data);
                if (data.hasSchema())
                    learnSchemaId(data.getSchemaId());
            }
        else if (content_type == "_schema_id")
            for (Variant::List::const_iterator lIter = list.begin(); lIter != list.end(); lIter++) {
                SchemaId schemaId(new SchemaIdImpl(lIter->asMap()));
                ConsoleEventImplAccess::get(context->response).addSchemaId(schemaId);
                learnSchemaId(schemaId);
            }
        else if (content_type == "_schema")
            for (Variant::List::const_iterator lIter = list.begin(); lIter != list.end(); lIter++) {
                Schema schema(new SchemaImpl(lIter->asMap()));
                schemaCache->declareSchema(schema);
            }

        if (final) {
            ConsoleEventImplAccess::get(context->response).setFinal();
            ConsoleEventImplAccess::get(context->response).setAgent(this);
            context->cond.notify();
        }
    } else {
Manageable::status_t
SubmissionObject::GetJobSummaries ( Variant::List &jobs,
                            std::string &text )
{

    // id, timestamp (which?), command, args, ins, outs, state, message
    // id, time queued, time entered current state, state, command, args, hold reason, release reason

	ClassAd ad;
	Variant::Map job;

    // find all the jobs in their various states...

    //1) Idle
    for ( SubmissionObject::JobSet::const_iterator i = GetIdle().begin();
            GetIdle().end() != i; i++ )
    {
	    (*i)->GetSummary(ad);
	if ( !PopulateVariantMapFromAd ( ad, job ) )
        {
            text = "Error retrieving attributes for Idle job";
            return STATUS_USER + 1;
        }

        jobs.push_back(job);
    }

    //2) Running
    for ( SubmissionObject::JobSet::const_iterator i = GetRunning().begin();
            GetRunning().end() != i;
            i++ )
    {
	    (*i)->GetSummary(ad);
	if ( !PopulateVariantMapFromAd ( ad, job ) )
        {
            text = "Error retrieving attributes for Running job";
            return STATUS_USER + 1;
        }

        jobs.push_back(job);
    }

    //3) Removed
    for ( SubmissionObject::JobSet::const_iterator i = GetRemoved().begin();
            GetRemoved().end() != i; i++ )
    {
	    (*i)->GetSummary(ad);
	if ( !PopulateVariantMapFromAd ( ad, job ) )
        {
            text = "Error retrieving attributes for Removed job";
            return STATUS_USER + 1;
        }

        jobs.push_back(job);
    }

    //4) Completed
    for ( SubmissionObject::JobSet::const_iterator i = GetCompleted().begin();
            GetCompleted().end() != i; i++ )
    {
	    (*i)->GetSummary(ad);
	if ( !PopulateVariantMapFromAd ( ad, job ) )
        {
            text = "Error retrieving attributes for Completed job";
            return STATUS_USER + 1;
        }

        jobs.push_back(job);
    }


    //5) Held
    for ( SubmissionObject::JobSet::const_iterator i = GetHeld().begin();
            GetHeld().end() != i; i++ )
    {
	    (*i)->GetSummary(ad);
	if ( !PopulateVariantMapFromAd ( ad, job ) )
        {
            text = "Error retrieving attributes for Held job";
            return STATUS_USER + 1;
        }

        jobs.push_back(job);
    }

    //6) Transferring Output
    for ( SubmissionObject::JobSet::const_iterator i = GetTransferringOutput().begin();
            GetTransferringOutput().end() != i; i++ )
    {
	    (*i)->GetSummary(ad);
	if ( !PopulateVariantMapFromAd ( ad, job ) )
        {
            text = "Error retrieving attributes for TransferringOutput job";
            return STATUS_USER + 1;
        }

        jobs.push_back(job);
    }

    //7) Suspended
    for ( SubmissionObject::JobSet::const_iterator i = GetSuspended().begin();
            GetSuspended().end() != i; i++ )
    {
	    (*i)->GetSummary(ad);
	if ( !PopulateVariantMapFromAd ( ad, job ) )
        {
            text = "Error retrieving attributes for Suspended job";
            return STATUS_USER + 1;
        }

        jobs.push_back(job);
    }

    return STATUS_OK;
}