[classad-users] Problems with ClassAdCollections-Need help


Date: Fri, 23 Dec 2005 09:29:51 +0530
From: Imran Shaik <imran.sk@xxxxxxxxx>
Subject: [classad-users] Problems with ClassAdCollections-Need help
---------- Forwarded message ----------
From: Imran Shaik <imran.sk@xxxxxxxxx>
Date: Dec 23, 2005 9:29 AM
Subject: Re: [classad-users] Problems with ClassAdCollections-Need help
To: Alain Roy <roy@xxxxxxxxxxx>


Hi Alain,
 I run two programs. I am sending them..

I use program1 to add classads to collection and later do a intialise from log.
First run this program, then program2.

Program1
--------------

#include <classad_distribution.h>
#include <iostream>

using namespace std;
#ifdef WANT_NAMESPACES
using namespace classad;
#endif

string mad_string1=

"["
"Type = \"Machine\";"
"Category=C;"
"Memory = 64M;"
"LoadAvg = 0.22969;"
"Mips = 104;"
"Arch = \"INTEL\";"
"OpSys = \"LINUX\";"
"KFlops = 21893;"
"IP=\"192.168.1.1\";"
"Rank = other.Owner==\"csa0411\" ? 1 : 0;"
"Requirements = other.Type == \"Job\"&& LoadAvg < 0.3 &&
Memory-other.ImageSize>=15M;"
"]";


string mad_string2=
"["
"Type = \"Machine\";"
"Category=S;"
"Disk = 333G;"
"LoadAvg = 0.42969;"
"OpSys = \"LINUX\";"
"IP=\"192.168.1.2\";"
"Rank = other.Owner==\"csa0411\" ? 1 : 0;"
"Requirements = other.Type == \"Job\"&& LoadAvg < 0.3 && Disk>=40G;"
"]";


string mad_string3=
"["
"Type = \"Machine\";"
"Category=V;"
"Disk = 333G;"
"Memory = 64M;"
"LoadAvg = 0.32762;"
"Arch = \"INTEL\";"
"OpSys = \"LINUX\";"
"IP=\"192.168.1.3\";"
"Rank = other.Owner==\"csa0411\" ? 1 : 0;"
"Requirements = other.Type == \"Job\"&& LoadAvg < 0.3 && Memory>=40M;"
"]";


string mad_string4=
"["
"Type = \"Machine\";"
"Category=I;"
"Memory = 64M;"
"LoadAvg = 0.12969;"
"Arch = \"INTEL\";"
"IP=\"192.168.1.4\";"
"Rank = other.Owner==\"csa0411\" ? 1 : 0;"
"Requirements = other.Type == \"Job\"&& LoadAvg < 0.3 && Disk>=40G;"
"]";


int main()
{
ClassAdParser  parser;
       ClassAd *mad1,*mad2,*mad3,*mad4;
       mad1 = parser.ParseClassAd(mad_string1, true);
       mad2 = parser.ParseClassAd(mad_string2, true);
       mad3 = parser.ParseClassAd(mad_string3, true);
       mad4 = parser.ParseClassAd(mad_string4, true);
       ClassAdCollection *cac1=new ClassAdCollection(false);
       bool init_log_retval;
       const string filename="log.log";
       const string storagefile="store.txt";
       unlink(filename.c_str());
       unlink(storagefile.c_str());
       init_log_retval=cac1->InitializeFromLog(filename,storagefile,"");
       cout<<"init_log_retval="<<init_log_retval<<endl;

       bool add_retval=cac1->AddClassAd("C177",mad1);
       cout<<"add_retval="<<add_retval<<endl;


       add_retval=cac1->AddClassAd("V77",mad2);
       cout<<"add_retval="<<add_retval<<endl;


       add_retval=cac1->AddClassAd("S77",mad3);
       cout<<"add_retval="<<add_retval<<endl;


       add_retval=cac1->AddClassAd("I77",mad4);
       cout<<"add_retval="<<add_retval<<endl;


       delete cac1;

}


Program2(this was the program i had sent earlier)
--------------




#include<classad_distribution.h>
#include<iostream>
using namespace std;
#ifdef WANT_NAMESPACES
using namespace classad;
#endif
LocalCollectionQuery *lcq;
ClassAdCollection *cac;

string job_classad_text=

"["
"Type = \"Job\";"
"Id = 0;"
"Category=S;"
"Rank = other.KFlops/100 + other.Memory/32;"
"Requirements = true;"
"]";


int fillupClassAd(ClassAd* newad)
{

ClassAdUnParser unp;
ClassAdParser parser;
string   buffer;
PrettyPrint printer;
ClassAdIterator itr;
string          attrName;
const ExprTree  *attrExpr;

printer.Unparse(buffer,newad);
cout<<"fillupClassAd: ClassAd="<<buffer;

//ClassAd Fillup

cout<<"Enter Values for the new ClassAd"<<endl;
itr.Initialize(*newad);
char *attrExpression=new char[200];
ExprTree *expr;
while( !itr.IsAfterLast( ) ) {
       itr.CurrentAttribute( attrName, attrExpr );

               cout<<attrName<<"=";
               cin>>attrExpression;
               string newstringExpr(attrExpression);
               expr=parser.ParseExpression(newstringExpr);
               if(expr==NULL) cout<<"Expression parsing failed!!"<<endl;
       newad->Insert(attrName,expr);
       itr.NextAttribute( attrName, attrExpr );
}
}


int findMatch(ClassAd *jobad)
{

       PrettyPrint printer;
       ExprTree *expr;
       ClassAd *info;
       cac->GetViewInfo("resource",info);
       string infostrg;
       printer.Unparse(infostrg,info);
       cout<<"ViewInfo="<<infostrg<<endl;
       delete info;

       MatchClassAd  match_ad(jobad,NULL);

       bool qry_test=lcq->Query("resource");
       cout<<"qry_test="<<qry_test<<endl;

       lcq->ToFirst();
       string nextkey,currkey;
       int matchcount=0;
       ClassAd *cad1;
       while(!lcq->IsAfterLast())
       {
               lcq->Current(currkey);
               cout<<"Curent Key="<<currkey<<endl;

               cad1=cac->GetClassAd(currkey);

               if(cad1==NULL)
               {
               cout<<"findMatch,228:ClassAd not created,NULL returned"<<endl;
               cout<<"Reason:Out of memory or Emty collection"<<endl;
               }
               string cadstring;
               printer.Unparse(cadstring,cad1);

               match_ad.ReplaceRightAd(cad1);
               bool can_evaluate,ads_match;

               can_evaluate =
match_ad.EvaluateAttrBool("rightMatchesLeft",ads_match);
               if(can_evaluate)
               {
                       if(ads_match)
                       {
                       string classad_text;
                       matchcount++;
                       printer.Unparse(classad_text,cad1);
                       cout<<"Matched Ad:"<<classad_text<<endl;
                       cout<<"Sending match details to resource provider"<<endl;
                       }
               }

       lcq->Next(nextkey);

       }//while loop ends here

       if(matchcount==0)
       {
       cout<<"No match Found , Or Collection empty"<<endl;
       }
       lcq->ToAfterLast();
       //delete lcq;
}

int main()
{



       cac=new ClassAdCollection(false);
       if(cac==NULL)
       {
               cout<<"Match maker failed to initialise"<<endl;
               exit(0);
       }


       const string logfile="log.log";
       const string storefile="store.txt";
       const string chkptfile="chkpt.log";
       bool init_log_retval=cac->InitializeFromLog(logfile,storefile,chkptfile);
       cout<<"init_log_retval="<<init_log_retval<<endl;
       lcq=new LocalCollectionQuery();
       if(lcq==NULL)
       {
               cout<<"LCQ_NULL"<<endl;
               exit(0);
       }
       lcq->Bind(cac);

       bool resourceview_create=cac->CreateSubView("resource", "root",
                          "other.Type==\"Machine\"","","");
       cout<<"resourceview_create="<<resourceview_create<<endl;

       ClassAdParser parser;
       ClassAd* jobad;
       for(int i=0;i<=10;i++)
       {
       jobad=parser.ParseClassAd(job_classad_text,true);
       //fillupClassAd(jobad);
       findMatch(jobad);
       }

       return 0;
}











program-1 ouput
---------------

/home/csa0411/Mygrid/ForAlainRoy/prob1/filler
----------------------------------------------
init_log_retval=1
add_retval=1
add_retval=1
add_retval=1
add_retval=1

----------------------------------------------
Program exited successfully with errcode (0)
Press the Enter key to close this terminal ...



program2 -output
------------------------

init_log_retval=1
resourceview_create=1
ViewInfo=
   [
       Requirements = other.Type == "Machine";
       SubordinateViews =
          {
          };
       PartitionExprs =
          {
          };
       NumMembers = 4;
       Rank = undefined;
       PartitionedViews =
          {
          };
       ParentViewName = "root";
       ViewName = "resource"
   ]
qry_test=1
Curent Key=C177
Matched Ad:
   [
       Requirements = other.Type == "Job" && LoadAvg <
3.000000000000000E-01 && Memory - other.ImageSize >= 15;
       OpSys = "LINUX";
       LoadAvg = 2.296900000000000E-01;
       Mips = 104;
       IP = "192.168.1.1";
       Category = C;
       Memory = 64;
       Arch = "INTEL";
       Rank = other.Owner == "csa0411" ? 1 : 0;
       Type = "Machine";
       KFlops = 21893
   ]
Sending match details to resource provider
Curent Key=V77
Matched Ad:
   [
       Requirements = other.Type == "Job" && LoadAvg <
3.000000000000000E-01 && Disk >= 40;
       OpSys = "LINUX";
       LoadAvg = 4.296900000000000E-01;
       Disk = 333;
       IP = "192.168.1.2";
       Category = S;
       Rank = other.Owner == "csa0411" ? 1 : 0;
       Type = "Machine"
   ]
Sending match details to resource provider
Curent Key=S77
Matched Ad:
   [
       Requirements = other.Type == "Job" && LoadAvg <
3.000000000000000E-01 && Memory >= 40;
       OpSys = "LINUX";
       LoadAvg = 3.276200000000000E-01;
       Disk = 333;
       IP = "192.168.1.3";
       Category = V;
       Memory = 64;
       Arch = "INTEL";
       Rank = other.Owner == "csa0411" ? 1 : 0;
       Type = "Machine"
   ]
Sending match details to resource provider
Curent Key=I77
Matched Ad:
   [
       Requirements = other.Type == "Job" && LoadAvg <
3.000000000000000E-01 && Disk >= 40;
       LoadAvg = 1.296900000000000E-01;
       IP = "192.168.1.4";
       Category = I;
       Memory = 64;
       Arch = "INTEL";
       Rank = other.Owner == "csa0411" ? 1 : 0;
       Type = "Machine"
   ]
Sending match details to resource provider
ViewInfo=
   [
       Requirements = other.Type == "Machine";
       SubordinateViews =
          {
          };
       PartitionExprs =
          {
          };
       NumMembers = 4;
       Rank = undefined;
       PartitionedViews =
          {
          };
       ParentViewName = "root";
       ViewName = "resource"
   ]
qry_test=1
Curent Key=C177

----------------------------------------------
Program has been terminated receiving signal 11 (Segmentation fault)
Press the Enter key to close this terminal ...


Stack trace
-----------------


Program received signal SIGSEGV, Segmentation fault.
0x08064b86 in ExprTree::SetParentScope (this=0x80e7770, scope=0x0) at
exprTree.C:73
73              _SetParentScope( scope );
(gdb) bt
#0  0x08064b86 in ExprTree::SetParentScope (this=0x80e7770, scope=0x0)
at exprTree.C:73
#1  0x0805c092 in ClassAdCollection::GetClassAd (this=0x80e3568,
key=@0xbfffecf0) at collectionBase.C:1300
#2  0x0804aea0 in findMatch (jobad=0x80f01b8) at matchtester.cc:81
#3  0x0804ba45 in main () at matchtester.cc:155




----------------------------


May be some problem with the first program. I didnt expect earlier. I
think i gave complete inoformation this time.Pls help me from this seg
fault.


Awaiting for your reply....


Regards,
Imran



On 12/21/05, Alain Roy <roy@xxxxxxxxxxx> wrote:
> I ran your program and didn't get a segmentation fault. What version
> of ClassAds are you using?
>
> -alain
>
> Condor Classads Info:
> http://www.cs.wisc.edu/condor/classad/
>


--
Yours,
Imran


--
Yours,
Imran

[← Prev in Thread] Current Thread [Next in Thread→]