示例#1
0
int CollectorEngine::remove (AdTypes t_AddType, const ClassAd & c_query, bool *query_contains_hash_key)
{
	int iRet = 0;
	AdNameHashKey hk;
	CollectorHashTable * table;  
	HashFunc makeKey;
	MyString hkString;

	if( query_contains_hash_key ) {
		*query_contains_hash_key = false;
	}

	// making it generic so any would be invalid query can contain these params.
	if ( LookupByAdType (t_AddType, table, makeKey) )
	{
		ClassAd * pAd=0;
		// try to create a hk from the query ad if it is possible.
		if ( (*makeKey) (hk, &c_query) ) {
			if( query_contains_hash_key ) {
				*query_contains_hash_key = true;
			}
			if( table->lookup(hk, pAd) != -1 )
			{
				hk.sprint( hkString );
				iRet = !table->remove(hk);
				dprintf (D_ALWAYS,"\t\t**** Removed(%d) ad(s): \"%s\"\n", iRet, hkString.Value() );
				delete pAd;
			}
		}
	}

	return ( iRet );
}
示例#2
0
int
CollectorEngine::invalidateAds(AdTypes adType, ClassAd &query)
{
	CollectorHashTable *table=0;
	CollectorEngine::HashFunc func;
	if (!LookupByAdType(adType, table, func)) {
		dprintf (D_ALWAYS, "Unknown type %d\n", adType);
		return 0;
	}

	int count = 0;
	ClassAd  *ad;
	AdNameHashKey  hk;
	MyString hkString;
	(*table).startIterations();
	while ((*table).iterate (ad)) {
		if (IsAHalfMatch(&query, ad)) {
			(*table).getCurrentKey(hk);
			hk.sprint(hkString);
			if ((*table).remove(hk) == -1) {
				dprintf(D_ALWAYS,
						"\t\tError while removing ad: \"%s\"\n",
						hkString.Value());
			} else {
				dprintf(D_ALWAYS,
						"\t\t**** Invalidating ad: \"%s\"\n",
						hkString.Value());
				delete ad;
				count++;
			}
		}
	}

	return count;
}
示例#3
0
int CollectorEngine::
invokeHousekeeper (AdTypes adType)
{
	time_t now;

	(void) time (&now);
	if (now == (time_t) -1)
	{
		dprintf (D_ALWAYS, "Error in reading system time --- aborting\n");
		return 0;
	}

	CollectorHashTable *table=0;
	CollectorEngine::HashFunc func;
	if (LookupByAdType(adType, table, func)) {
		cleanHashTable(*table, now, func);
	} else {
		if (GENERIC_AD == adType) {
			CollectorHashTable *cht=0;
			GenericAds.startIterations();
			while (GenericAds.iterate(cht)) {
				cleanHashTable (*cht, now, makeGenericAdHashKey);
			}
		} else {
			return 0;
		}
	}

	return 1;
}
示例#4
0
int CollectorEngine::
remove (AdTypes adType, AdNameHashKey &hk)
{
	CollectorHashTable *table;
	CollectorEngine::HashFunc func;
	if (!LookupByAdType(adType, table, func)) {
		return 0;
	}
	return !table->remove(hk);
}
int CollectorEngine::
walkHashTable (AdTypes adType, int (*scanFunction)(ClassAd *))
{
	//int retval = 1;

	if (GENERIC_AD == adType) {
		return walkGenericTables(scanFunction);
	} else if (ANY_AD == adType) {
		return
			StorageAds.walk(scanFunction) &&
			CkptServerAds.walk(scanFunction) &&
			LicenseAds.walk(scanFunction) &&
			CollectorAds.walk(scanFunction) &&
			StartdAds.walk(scanFunction) &&
			ScheddAds.walk(scanFunction) &&
			MasterAds.walk(scanFunction) &&
			SubmittorAds.walk(scanFunction) &&
			NegotiatorAds.walk(scanFunction) &&
#ifdef HAVE_EXT_POSTGRESQL
			QuillAds.walk(scanFunction) &&
#endif
			HadAds.walk(scanFunction) &&
			GridAds.walk(scanFunction) &&
			XferServiceAds.walk(scanFunction) &&
			LeaseManagerAds.walk(scanFunction) &&
			walkGenericTables(scanFunction);
	}

	CollectorHashTable *table;
	CollectorEngine::HashFunc func;
	if (!LookupByAdType(adType, table, func)) {
		dprintf (D_ALWAYS, "Unknown type %d\n", adType);
		return 0;
	}

	// walk the hash table
	ClassAd *ad;
	(*table).startIterations ();
	while ((*table).iterate (ad))
	{
		// call scan function for each ad
		if (!scanFunction (ad))
		{
			//retval = 0;
			break;
		}
	}

	return 1;
}
示例#6
0
ClassAd *CollectorEngine::
lookup (AdTypes adType, AdNameHashKey &hk)
{
	ClassAd *val;

	CollectorHashTable *table;
	CollectorEngine::HashFunc func;
	if (!LookupByAdType(adType, table, func)) {
		return 0;
	}
	if (table->lookup(hk, val) == -1) {
		return 0;
	}

	return val;
}
示例#7
0
int CollectorEngine::expire( AdTypes adType, const ClassAd & query, bool * queryContainsHashKey ) {
    int rVal = 0;
    if( queryContainsHashKey ) { * queryContainsHashKey = false; }

    HashFunc hFunc;
    CollectorHashTable * hTable;
    if( LookupByAdType( adType, hTable, hFunc ) ) {
        AdNameHashKey hKey;
        if( (* hFunc)( hKey, & query ) ) {
            if( queryContainsHashKey ) { * queryContainsHashKey = true; }

            ClassAd * cAd = NULL;
            if( hTable->lookup( hKey, cAd ) != -1 ) {
                cAd->Assign( ATTR_LAST_HEARD_FROM, 1 );
                
                if( CollectorDaemon::offline_plugin_.expire( * cAd ) == true ) {
                    return rVal;
                }
                
                rVal = hTable->remove( hKey );
                if( rVal == -1 ) {
                    dprintf( D_ALWAYS, "\t\t Error removing ad\n" );
                    return 0;
                }
                rVal = (! rVal);
                
                MyString hkString;
                hKey.sprint( hkString );                
                dprintf( D_ALWAYS, "\t\t**** Removed(%d) stale ad(s): \"%s\"\n", rVal, hkString.Value() );

                delete cAd;
            }
        }
    }

	return rVal;
}