void ParametricAd::addUserTag ( const std::string& attr_name,  const std::string& attr_value){
	ExprTree* tree = Lookup ( JDL::USERTAGS  ) ;
	if ( tree ==NULL){
		// UserTags attribute has still to be created
		ClassAd ad ;
		ad.InsertAttr ( attr_name , attr_value ) ;
		ExprTree* tmp_expr = ad.Copy();
		Insert ( JDL::USERTAGS  , tmp_expr ) ;
	}else{
		// Already Existing UserTags attribute
		if (  tree->GetKind () == classad::ExprTree::CLASSAD_NODE  )
			((ClassAd*)tree)->InsertAttr ( attr_name , attr_value  ) ;
	}
}
Beispiel #2
0
bool
Compress( ClassAdCollectionServer *server, LocalCollectionQuery *query,
          const References &refs, CompressedAds &comp, list<ClassAd*> &rest )
{
    string                      key, sig;
    References::const_iterator  ritr;
    ClassAd                     *ad;
    CompressedAds::iterator     citr;
    ClassAdBin                  *bin;

    query->ToFirst( );
    query->Current( key );
    while( !query->IsAfterLast( ) ) {
        // get ad
        if( !( ad = server->GetClassAd( key ) ) ) {
            return( false );
        }

        // get signature of current ad
        if( !MakeSignature( ad, refs, sig ) ) {
            // can't make signature --- can't compress
            rest.push_back( (ClassAd*) ad->Copy( ) );
        }

        // get bin
        if( ( citr = comp.find( sig ) ) == comp.end( ) ) {
            // no bin ... make one
            bin = new ClassAdBin;
            bin->count = 1;

            // make a projected classad
            for( ritr=refs.begin( ); ritr!=refs.end( ); ritr++ ) {
                bin->ad->Insert( *ritr, ad->Lookup( *ritr )->Copy( ), false );
            }

            // insert bin into container
            comp[sig] = bin;
        } else {
            // increment membership in bin
            bin = citr->second;
            bin->count++;
        }

        // process next ad
        query->Next( key );
    }

    return( true );
}
Beispiel #3
0
bool ServerTransaction::
Commit( )
{
	bool						undoNeeded = false;
	CollectionOpList::iterator	itr;
	ClassAd						*ad;
	
	printf("in commit");
		// sanity check
	if( !server ) return( false );

		// play all the operations into the data structure
    for( itr = opList.begin( ); itr != opList.end( ); itr++ ) {
			// we're going to write over/destroy an ad; save it first
		if( ( ad = server->GetClassAd( itr->key ) ) ) {
			if( !( itr->backup = (ClassAd *) ad->Copy( ) ) ) {
				xactionErrno = CondorErrno;
				xactionErrMsg = CondorErrMsg;
				xactionErrCause = itr->rec;
				itr->rec = NULL;
				return( false );
			}
		}

			// play the operation on the collection
		if( !server->PlayClassAdOp( itr->op, itr->rec ) ) {
				// if the operation failed, we need to undo the xaction
			xactionErrCause = itr->rec;
			itr->rec = NULL;
			undoNeeded = true;
			break;
		}
    }
	if( !undoNeeded ) return( true );

		// we need to undo the effects of the transaction
	CollectionOpList::iterator	uitr;
	ClassAdTable::iterator		caitr;
	
		// undo all operations upto (not including) the failed operation
	for( uitr = opList.begin( ); uitr != itr; uitr++ ) {
		caitr = server->classadTable.find( uitr->key );	

			// if we have to undo a "remove classad" op ...
		if(uitr->op==ClassAdCollectionInterface::ClassAdCollOp_RemoveClassAd) {
				// try to restore a backup only if we have a backup at all ...
			if( uitr->backup ) {
				ClassAdProxy	proxy;

					// ... re-insert the previous (backed up) classad
				if( !server->viewTree.ClassAdInserted( server, uitr->key,
						uitr->backup ) ) {
						// failure during undo is fatal
					CondorErrno = ERR_FATAL_ERROR;
					CondorErrMsg += "; could not undo failed transaction";
					return( false );
				}
					// put backup into classad table
				proxy.ad = uitr->backup;
				uitr->backup = NULL;
				server->classadTable[uitr->key] = proxy;

			}
		} else {
				// we are undoing an add, update or modify operation
			Value	val;
			ClassAd	*collAd = caitr->second.ad;;

			if( uitr->backup == NULL ) {
					// if the collection did not have an ad in the first 
					// place just delete the new ad from the collection
				server->classadTable.erase( caitr );
				server->viewTree.ClassAdDeleted( server, uitr->key, collAd );
			} else {
					// we need to replace the collAd with the backup
				server->viewTree.ClassAdPreModify( server, collAd );
				server->viewTree.ClassAdModified(server,uitr->key,uitr->backup);
				caitr->second.ad = uitr->backup;
				uitr->backup = NULL;
			}
		}
	}

		// clear out transaction and signal failure
	ClearRecords( );
	CondorErrno = xactionErrno;
	CondorErrMsg = xactionErrMsg;
	return( false );
}