ClassAd *ClassAdCollectionInterface:: _CreatePartition( const ViewName &viewName, const ViewName &parentViewName, const string &constraint, const string &rank, const string &partitionExprs, ClassAd *rep ) { ClassAd *rec; string buffer; buffer = "[ ViewName = \""; buffer += viewName; buffer += "\" ; ParentViewName = \""; buffer += parentViewName; buffer += "\" ; Requirements = "; buffer += constraint=="" ? "true" : constraint; buffer += " ; PartitionExprs = "; if (string_is_empty(partitionExprs)) { buffer += "{}"; } else { buffer += partitionExprs; } buffer += " ; Rank = "; if (string_is_empty(rank)) { buffer += "undefied"; } else { buffer += rank; } buffer += " ] ]"; if( !( rec = parser.ParseClassAd( buffer ) ) ) { return( NULL ); } rec->InsertAttr( "OpType", ClassAdCollOp_CreatePartition ); rec->InsertAttr( "Representative", rep ); return( rec ); }
void WMReal_test::test_submit() { std::string jobid_key("edg_jobid"); std::string jobid_value("https://lxb1420.cern.ch:9000/BqXQcCpXqnF92nvj94PZVw"); std::string seqcode_key("LB_sequence_code"); std::string seqcode_value("0000"); std::string type_key("type"); std::string type_value("job"); ClassAd *classad = new ClassAd(); CPPUNIT_ASSERT( classad ); classad->InsertAttr(jobid_key,jobid_value); classad->InsertAttr(seqcode_key,seqcode_value); classad->InsertAttr(type_key,type_value); try{ wm_real->submit(classad); }catch(glite::wms::jdl::CannotGetAttribute att_error){ cerr << "Cannot retrieve " << att_error.reason() << endl; } delete classad; }
bool ClientTransaction:: LogAbort( FILE *fp, ClassAdUnParser *unp ) { if( state != PENDING ) { CondorErrno = ERR_BAD_TRANSACTION_STATE; CondorErrMsg = "transaction expected to be in COMMITTED state"; return( false ); } ClassAd rec; string buf; if(!rec.InsertAttr(ATTR_OP_TYPE, ClassAdCollectionInterface::ClassAdCollOp_AbortTransaction) || !rec.InsertAttr( "XactionName", xactionName.c_str( ) ) ) { CondorErrMsg += "FATAL ERROR: failed to log transaction"; return( false ); } unp->Unparse( buf, &rec ); if( fprintf( fp, "%s\n", buf.c_str( ) ) < 0 ) { CondorErrno = ERR_FILE_WRITE_FAILED; CondorErrMsg = "FATAL ERROR: failed fprintf()"; return( false ); } fsync( fileno( fp ) ); return( true ); }
View:: View( View *parentView ) { Value val; vector<ExprTree*> vec; ClassAd *ad = evalEnviron.GetLeftAd( ); parent = parentView; ExprTree* pExp; ad->InsertAttr( ATTR_REQUIREMENTS, true ); ad->Insert( ATTR_RANK, (pExp=Literal::MakeLiteral( val )) ); ad->Insert( ATTR_PARTITION_EXPRS, (pExp=ExprList::MakeExprList( vec )) ); if( parentView ) { ad->InsertAttr( "ParentViewName", parentView->GetViewName( ) ); } }
ClassAd *ClassAdCollectionInterface:: _DeleteView( const ViewName &viewName ) { ClassAd *rec; if( !( rec = new ClassAd( ) ) ) { CondorErrno = ERR_MEM_ALLOC_FAILED; CondorErrMsg = ""; return( (ClassAd*) NULL ); } if( !rec->InsertAttr( "OpType", ClassAdCollOp_DeleteView ) || !rec->InsertAttr( "ViewName", viewName ) ) { CondorErrMsg += "; failed to make delete view record"; delete rec; return( (ClassAd*) NULL ); } return( rec ); }
bool View:: SetViewName( const ViewName &name ) { ClassAd *ad; viewName = name; if( !(ad=evalEnviron.GetLeftAd( )) || !ad->InsertAttr("ViewName", name) ) { CondorErrno = ERR_FAILED_SET_VIEW_NAME; return( false ); } return( true ); }
ClassAd *ClassAdCollectionInterface:: _RemoveClassAd( const string &xactionName, const string &key ) { ClassAd *rec; if( !( rec = new ClassAd( ) ) ) { CondorErrno = ERR_MEM_ALLOC_FAILED; CondorErrMsg = ""; return( (ClassAd*) NULL ); } if( ( !xactionName.empty( ) && !rec->InsertAttr( ATTR_XACTION_NAME, xactionName ) ) || !rec->InsertAttr( "OpType",ClassAdCollOp_RemoveClassAd )|| !rec->InsertAttr( "Key", key ) ) { CondorErrMsg += "; failed to make delete classad " + key + " record"; delete rec; return( (ClassAd*) NULL ); } return( rec ); }
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 ) ; } }
bool ClientTransaction:: LogCommit( FILE *fp, ClassAdUnParser *unp ) { ClassAd rec; string buf; if(!rec.InsertAttr(ATTR_OP_TYPE, ClassAdCollectionInterface::ClassAdCollOp_CommitTransaction) || !rec.InsertAttr( "XactionName", xactionName ) || !rec.InsertAttr( "ServerAddr", addr ) || !rec.InsertAttr( "ServerPort", port ) ) { CondorErrMsg += "FATAL ERROR: failed to log transaction"; return( false ); } unp->Unparse( buf, &rec ); if( fprintf( fp, "%s\n", buf.c_str( ) ) < 0 ) { CondorErrno = ERR_FILE_WRITE_FAILED; CondorErrMsg = "FATAL ERROR: failed fprintf()"; return( false ); } fsync( fileno( fp ) ); return( true ); }
int classad_put_int_attribute (classad_context *cad, const char *name, int value) { ClassAd *ad; if ((*cad) == NULL) { ad = new ClassAd; (*cad) = (classad_context) ad; } else ad = (ClassAd *)(*cad); if (ad->InsertAttr (name, value)) return C_CLASSAD_NO_ERROR; else return C_CLASSAD_INSERT_FAILED; }
int classad_put_bool_attribute (classad_context *cad, const char *name, int value) { ClassAd *ad; if ((*cad) == NULL) { ad = new ClassAd; (*cad) = (classad_context) ad; } else ad = (ClassAd *)(*cad); bool tmp_value; if (value != 0) tmp_value = true; else tmp_value = false; if (ad->InsertAttr (name, tmp_value)) return C_CLASSAD_NO_ERROR; else return C_CLASSAD_INSERT_FAILED; }
static void test_dirty(void) { ClassAd *classad; ClassAdParser parser; classad = parser.ParseClassAd(dirty_classad_text); cout << "Testing dirty attributes...\n"; if (classad->IsAttributeDirty("A")) { cout << " Failed: A is dirty just after construction.\n"; } else { cout << " OK: A is clean.\n"; } classad->InsertAttr("B", true); if (classad->IsAttributeDirty("A")) { cout << " Failed: A is dirty after inserting B.\n"; } else { cout << " OK: A is still clean.\n"; } if (!classad->IsAttributeDirty("B")) { cout << " Failed: B is not dirty.\n"; } else { cout << " OK: B is dirty.\n"; } ClassAd::dirtyIterator it = classad->dirtyBegin(); if (it == classad->dirtyEnd()) { cout << " Failed: Dirty iterator gives us nothing.\n"; } else { if ((*it) != "B") { cout << " Failed: Dirty iterator is not pointing at B.\n"; } else { cout << " OK: Dirty iterator starts out okay.\n"; it++; if (it != classad->dirtyEnd()) { cout << " Failed: Dirty iterator it not at end.\n"; } else { cout << " OK: Dirty iterator ends okay.\n"; } } } classad->ClearAllDirtyFlags(); if (classad->IsAttributeDirty("B")) { cout << " Failed: B is dirty after clearing flags.\n"; } else { cout << " OK: B is clean.\n"; } classad->MarkAttributeDirty("A"); if (!classad->IsAttributeDirty("A")) { cout << " Failed: A is not dirty.\n"; } else { cout << " OK: A is dirty.\n"; } classad->MarkAttributeClean("A"); if (classad->IsAttributeDirty("A")) { cout << " Failed: A is dirty after cleaning it.\n"; } else { cout << " OK: A is clean.\n"; } return; }
bool View:: DeletePartitionedView( ClassAdCollection *coll, const ViewName &vName ) { PartitionedViews::iterator mi; for( mi = partitionedViews.begin( ); mi != partitionedViews.end( ); mi++ ) { if( mi->second->GetViewName( ) == vName ) { // check if the partition is non-empty ... if( mi->second->Size( ) != 0 ) { // remove all child views and reset view info View *view = mi->second; SubordinateViews::iterator svi; PartitionedViews::iterator pvi; // delete subordinate views for( svi = view->subordinateViews.begin( ); svi != view->subordinateViews.end( ); svi++ ) { (*svi)->DeleteView( coll ); delete (*svi); } view->subordinateViews.clear( ); // delete partitioned views for( pvi = view->partitionedViews.begin( ); pvi != view->partitionedViews.end( ); pvi++ ) { pvi->second->DeleteView( coll ); delete pvi->second; } view->partitionedViews.clear( ); // reset name of view coll->UnregisterView( vName ); coll->RegisterView( viewName + ":" + mi->first, view ); // reset other view info vector<ExprTree*> vec; ExprTree * pExpr=0; ClassAd *ad = new ClassAd( ); if( !ad ) { CondorErrno = ERR_MEM_ALLOC_FAILED; CondorErrMsg = ""; return( false ); } if( !ad->InsertAttr( ATTR_REQUIREMENTS, true ) || !ad->InsertAttr( ATTR_RANK, 0 ) || !ad->Insert(ATTR_PARTITION_EXPRS, (pExpr=ExprList::MakeExprList( vec )) ) || !view->SetViewInfo( coll, ad ) ) { CondorErrMsg += "; failed to delete partition view " + vName; return( false ); } return( true ); } // empty partition ... can just delete it mi->second->DeleteView( coll ); delete mi->second; partitionedViews.erase( mi ); return( true ); } } CondorErrno = ERR_NO_SUCH_VIEW; CondorErrMsg = "no partition child view named " + vName + " in view"; return( false ); }
bool ServerTransaction:: Log( FILE *fp, ClassAdUnParser *unp ) { ClassAd rec; CollectionOpList::iterator itr; string buf; char tmp[16]; if( !fp ) { return( true );}; // write out a "OpenTransaction" record if(!rec.InsertAttr(ATTR_OP_TYPE, ClassAdCollectionInterface::ClassAdCollOp_OpenTransaction)|| !rec.InsertAttr( "XactionName", xactionName ) || ( local && !rec.InsertAttr( "LocalTransaction", true ) ) ) { CondorErrMsg += "; FATAL ERROR: failed to log transaction"; return( false ); } unp->Unparse( buf, &rec ); if( fprintf( fp, "%s\n", buf.c_str( ) ) < 0 ) { sprintf( tmp, "%d", errno ); CondorErrno = ERR_FILE_WRITE_FAILED; CondorErrMsg = "FATAL ERROR: failed fprintf() on log, errno="; CondorErrMsg += tmp; return( false ); } // log all the operations in the transaction for( itr = opList.begin( ); itr != opList.end( ); itr++ ) { buf = ""; unp->Unparse( buf, itr->rec ); if( fprintf( fp, "%s\n", buf.c_str( ) ) < 0 ) { sprintf( tmp, "%d", errno ); CondorErrno = ERR_FILE_WRITE_FAILED; CondorErrMsg = "FATAL ERROR: failed fprintf() on log, errno="; CondorErrMsg += tmp; return( false ); } } // write out a "CommitTransaction" record and flush the sink if(!rec.InsertAttr(ATTR_OP_TYPE, ClassAdCollectionInterface::ClassAdCollOp_CommitTransaction)){ CondorErrMsg += "; FATAL ERROR: failed to log transaction"; return( false ); } buf = ""; unp->Unparse( buf, &rec ); if( fprintf( fp, "%s\n", buf.c_str( ) ) < 0 ) { sprintf( tmp, "%d", errno ); CondorErrno = ERR_FILE_WRITE_FAILED; CondorErrMsg = "FATAL ERROR: failed fprintf() on log, errno="; CondorErrMsg += tmp; return( false ); } // sync ... fflush(fp); /* int status1=fsync( fileno( fp ) ); fflush(fp); */ return( true ); }