/*------------------------------------------------------------------------------
 * function: AttrProj::ReadWholeRec
 * Read an entire record (not its projections).
 */
DevStatus
AttrProj::ReadWholeRec(RecId recId, Vector &vector)
{
	DO_DEBUG(printf("AttrProj::ReadWholeRec()\n"));

	DevStatus	result = StatusOk;

	_tDataP->InitGetRecs(recId, recId);

	int			dataSize;
	int			numRecs;

	if (!_tDataP->GetRecs(_recBuf, _recBufSize, recId, numRecs, dataSize))
	{
		result = StatusFailed;
	}
	else
	{
		AttrList *	attrListP = _tDataP->GetAttrList();
		int			attrNum = 0;

		attrListP->InitIterator();
		while (attrListP->More())
		{
			AttrInfo *attrInfoP = attrListP->Next();

			vector.value[attrNum] = AttrToDouble(attrInfoP->type,
				_recBuf + attrInfoP->offset);
			attrNum++;
		}
		attrListP->DoneIterator();
	}

	return result;
}
Exemple #2
0
AttrList USBAddr::getAttrList() const
{
    AttrList attrs;
    if ( !bus->text().isEmpty() )
        attrs.insert("bus", bus->text());
    if ( !port->text().isEmpty() )
        attrs.insert("port", port->text());
    return attrs;
}
float ClassAdCollection::GetClassAdRank(ClassAd* Ad, const MyString& RankExpr)
{
  if (RankExpr.Length()==0) return 0.0;
  AttrList RankingAd;
  RankingAd.AssignExpr( ATTR_RANK, RankExpr.Value() );
  float Rank;
  if (!RankingAd.EvalFloat(ATTR_RANK,Ad,Rank)) Rank=0.0;
  return Rank;
}
AttrList CCIDAddr::getAttrList() const
{
    AttrList attrs;
    if ( !bus->text().isEmpty() )
        attrs.insert("bus", bus->text());
    if ( !slot->text().isEmpty() )
        attrs.insert("slot", slot->text());
    return attrs;
}
AttrList CCWAddr::getAttrList() const
{
    AttrList attrs;
    if ( !machine->text().isEmpty() )
        attrs.insert("machine", machine->text());
    if ( !cssid->text().isEmpty() )
        attrs.insert("cssid", cssid->text());
    attrs.insert("ssid", ssid->text());
    if ( !devno->text().isEmpty() )
        attrs.insert("devno", devno->text());
    return attrs;
}
// [1][a][1]{[1][c][4]}
//  a     b   c     d b
//
// a - name length
// b - attr count
// c - nth attr name length
// d - nth attr type id
void PkgTypeEncoder::Encode(StrView name, const AttrList& attrs) {
  EncodeString(name.Data(), name.Len());
  EncodeByte(attrs.size());

  for (const sym::Attr& attr : attrs) {
    EncodeString(attr.name.Data(), attr.name.Len());
    EncodeType(attr.type);
  }
}
/*------------------------------------------------------------------------------
 * function: AttrProj::ReadRec
 * Read a record from the data source, and project it onto the attribute
 * combinations corresponding to this object.
 */
DevStatus
AttrProj::ReadRec(RecId recId, VectorArray &vecArray)
{
	DO_DEBUG(printf("AttrProj::ReadRec(%d)\n", (int) recId));

	int			dataSize;
	int			numRecs;
	DevStatus	result = StatusOk;

	TData::TDHandle handle = _tDataP->InitGetRecs(recId, recId);

	if (!_tDataP->GetRecs(handle, _recBuf, _recBufSize,
                              recId, numRecs, dataSize))
	{
		result = StatusFailed;
	}
	else
	{
		AttrList *	attrListP = _tDataP->GetAttrList();
		int		projNum = 0;
		Projection * projP = _projList.GetFirstProj();
		while (projP != NULL)
		{
			Vector *	vectorP = vecArray.GetVector(projNum);
			int		projAttrNum;
			for (projAttrNum = 0; projAttrNum < projP->attrCount;
				projAttrNum++)
			{
				int			attrNum = projP->attrList[projAttrNum];
				AttrInfo *	attrInfoP = attrListP->Get(attrNum);

				vectorP->value[projAttrNum] = AttrToDouble(attrInfoP->type,
					_recBuf + attrInfoP->offset);
			}

			projP = _projList.GetNextProj();
			projNum++;
		}
	}

        _tDataP->DoneGetRecs(handle);

	return result;
}
/*------------------------------------------------------------------------------
 * function: AttrProj::GetWholeRecSize
 * Returns information about the size of data that will be produced when
 * an entire record (not its projections) is read.
 */
DevStatus
AttrProj::GetWholeRecSize(int &attrCount, int &recSize)
{
	DO_DEBUG(printf("AttrProj::GetWholeRecSize()\n"));

	DevStatus	result = StatusOk;

	attrCount = 0;
	recSize = 0;

	AttrList *attrListP = _tDataP->GetAttrList();

	attrListP->InitIterator();
	while (attrListP->More())
	{
		AttrInfo *attrInfoP = attrListP->Next();
		attrCount++;
		recSize += sizeof(VECTOR_TYPE);
	}
	attrListP->DoneIterator();

	return result;
}
Exemple #9
0
AttrList Load::attrList()
{
  AttrList l;
  l.push_back("filename");
  return l;
}
Exemple #10
0
// Read the history from a single file and print it out. 
static void readHistoryFromFile(char *JobHistoryFileName, char* constraint, ExprTree *constraintExpr)
{
    int EndFlag   = 0;
    int ErrorFlag = 0;
    int EmptyFlag = 0;
    AttrList *ad = NULL;

    long offset = 0;
    bool BOF = false; // Beginning Of File
    MyString buf;
    
    FILE* LogFile=safe_fopen_wrapper(JobHistoryFileName,"r");
    
	if (!LogFile) {
        fprintf(stderr,"History file (%s) not found or empty.\n", JobHistoryFileName);
        exit(1);
    }

	// In case of rotated history files, check if we have already reached the number of 
	// matches specified by the user before reading the next file
	if (specifiedMatch != 0) { 
        if (matchCount == specifiedMatch) { // Already found n number of matches, cleanup  
            fclose(LogFile);
            return;
        }
	}

	if (backwards) {
        offset = findLastDelimiter(LogFile, JobHistoryFileName);	
    }

    while(!EndFlag) {

        if (backwards) { // Read history file backwards
            if (BOF) { // If reached beginning of file
                break;
            }
            
            offset = findPrevDelimiter(LogFile, JobHistoryFileName, offset);
            if (offset == -1) { // Unable to match constraint
                break;
            } else if (offset != 0) {
                fseek(LogFile, offset, SEEK_SET);
                buf.readLine(LogFile); // Read one line to skip delimiter and adjust to actual offset of ad
            } else { // Offset set to 0
                BOF = true;
                fseek(LogFile, offset, SEEK_SET);
            }
        }
      
        if( !( ad=new AttrList(LogFile,"***", EndFlag, ErrorFlag, EmptyFlag) ) ){
            fprintf( stderr, "Error:  Out of memory\n" );
            exit( 1 );
        } 
        if( ErrorFlag ) {
            printf( "\t*** Warning: Bad history file; skipping malformed ad(s)\n" );
            ErrorFlag=0;
            if(ad) {
                delete ad;
                ad = NULL;
            }
            continue;
        } 
        if( EmptyFlag ) {
            EmptyFlag=0;
            if(ad) {
                delete ad;
                ad = NULL;
            }
            continue;
        }
        if (!constraint || EvalBool(ad, constraintExpr)) {
            if (longformat) { 
                ad->fPrint(stdout); printf("\n"); 
            } else {
                if (customFormat) {
                    mask.display(stdout, ad);
                } else {
                    displayJobShort(ad);
                }
            }

            matchCount++; // if control reached here, match has occured

            if (specifiedMatch != 0) { // User specified a match number
                if (matchCount == specifiedMatch) { // Found n number of matches, cleanup  
                    if (ad) {
                        delete ad;
                        ad = NULL;
                    }
                    
                    fclose(LogFile);
                    return;
                }
            }
		}
		
        if(ad) {
            delete ad;
            ad = NULL;
        }
    }
    fclose(LogFile);
    return;
}
AttrList::AttrList (PropertyName n) : (n) {
    value = nil;
    type = nil;
}

boolean AttrList::FindAttr (register PropertyDef& p) {
    register AttrList* a;

    for (a = (AttrList*)next; a != this; a = (AttrList*)a->next) {
	if (a->name == p.name) {
	    p.type = a->type;
	    p.value = a->value;
	    return true;
	}
    }
    return false;
}

/*
 * class DirList
 */

DirList::DirList () {
    info = nil;
}

DirList::DirList (PropertyName n) : (n) {
    info = new PropDir;
}

boolean DirList::FindSubDir (PropertyName n, PropDir*& subdir) {
    register DirList* d;

    for (d = (DirList*)next; d != this; d = (DirList*)d->next) {
	if (d->name == n) {
	    subdir = d->info;
	    return true;
	}
    }
    return false;
}

DirList::~DirList () {
    delete info;
}

/*
 * class PropDir
 */

PropDir::PropDir () {
    parent = nil;
    attrs = new AttrList;
    dirs = new DirList;
    vattrs = new AttrList;
    vdirs = new DirList;
}

PropDir::~PropDir () {
    dirs->DeleteAll();
    delete dirs;
    vdirs->DeleteAll();
    delete vdirs;
    attrs->DeleteAll();
    delete attrs;
    vattrs->DeleteAll();
    delete vattrs;
}

PropDir* PropDir::MakeDirs (const char*& name) {
    register const char* p;
    PropDir* dir;
    DirList* cur, * sub;
    PropertyName n;
    int c;

    dir = this;
    c = '.';
    for (p = name; *p != '\0'; p++) {
	if (*p == '.' || *p == '*') {
	    if (p > name) {
		n = nameTable->Id(name, p - name);
		cur = (c == '*') ? dir->vdirs : dir->dirs;
		if (!cur->FindSubDir(n, dir)) {
		    sub = new DirList(n);
		    sub->info->parent = dir;
		    cur->Append(sub);
		    dir = sub->info;
		}
	    }
	    c = *p;
	    name = p + 1;
	}
    }
    return dir;
}

/*
 * class PropPath
 */

PropPath::PropPath () {
    top = &element[0];
    next = nil;
    prev = nil;
}

/*
 * class PropertySheet
 */

PropertySheet::PropertySheet () {
    cur = new PropDir;
    head = new PropPath;
    tail = head;
    head->element[0].dir = cur;
    head->element[0].sibling = false;
    if (propvalues == nil) {
	propvalues = new StringPool;
    }
}

PropertySheet::~PropertySheet () {
    register PropPath* p, * pnext;

    delete cur;
    for (p = head; p != nil; p = pnext) {
	pnext = p->next;
	delete p;
    }
}

boolean PropertySheet::Get (PropertyDef& prop) {
    register PropPath* p;
    register PropPathElement* i;

    /* look for instance.attr */
    p = tail;
    i = tail->top;
    if (i->dir->attrs->FindAttr(prop)) {
	return true;
    }
    /* look for class.attr (if prev path element is class for instance) */
    if (i->sibling) {
	/* prev path element is class -- look for class.attr */
	--i;
	if (i < &p->element[0]) {
	    i = p->prev->top;
	}
	if (i->dir->attrs->FindAttr(prop)) {
	    return true;
	}
    }
    /* look for path*attr */
    for (p = tail; p != nil; p = p->prev) {
	for (i = p->top; i >= &p->element[0]; i--) {
	    if (i->dir->vattrs->FindAttr(prop)) {
		return true;
	    }
	}
    }
    prop.value = nil;
    return false;
}

/*
 * Special lookup under current directory for .attr  or *attr.
 */

boolean PropertySheet::GetLocal (PropDir* dir, PropertyDef& prop) {
    if (dir->attrs->FindAttr(prop) || dir->vattrs->FindAttr(prop)) {
	return true;
    }
    prop.value = nil;
    return false;
}

/*
 * Add an empty directory to the property sheet.
 */

PropDir* PropertySheet::MakeDir (const char* path) {
    const char* name = path;
    PropDir* dir = cur;
    DirList* d = (name > path && *(name-1) == '*') ? dir->vdirs : dir->dirs;
    PropertyName n = nameTable->Id(name);
    if (!d->FindSubDir(n, dir)) {
	DirList* sub = new DirList(n);
	sub->info->parent = dir;
	d->Append(sub);
	dir = sub->info;
    }
    return dir;
}

/*
 * Put an attribute in the property sheet, starting the path search
 * at a given directory (typically the root).  If the name is already
 * defined and the "override" parameter is false, then do nothing.
 */

void PropertySheet::DoPut (
    PropDir* root, const char* path, const char* value, const char* type,
    boolean override
) {
    const char* name = path;
    boolean newvalue = override;
    PropDir* dir = root->MakeDirs(name);
    AttrList* alist =
	(name > path && *(name-1) == '*') ? dir->vattrs : dir->attrs;
    PropertyName n = nameTable->Id(name);
    register AttrList* a = (AttrList*)alist->Find(n);
    if (a == nil) {
	a = new AttrList(n);
	alist->Append(a);
	newvalue = true;
    }
    if (newvalue) {
	register const char* v;

	for (v = value; isspace(*v); v++);
	a->value = propvalues->Append(v, (int)(strlen(v) + 1));
	a->type = type;
    }
}

/*
 * Look up the path for a subdirectory matching the given name.
 */

PropDir* PropertySheet::Find (PropertyName name) {
    register PropPath* p;
    register PropPathElement* e;
    PropDir* dir;

    dir = nil;
    /* look for path.name */
    if (tail->top->dir->dirs->FindSubDir(name, dir)) {
	return dir;
    }
    /* look for path*name */
    for (p = tail; p != nil; p = p->prev) {
	for (e = p->top; e >= &p->element[0]; e--) {
	    if (e->dir->vdirs->FindSubDir(name, dir)) {
		return dir;
	    }
	}
    }
    return nil;
}

void PropertySheet::Push (PropDir* dir, boolean b) {
    register PropPath* p;
    register PropPathElement* e;

    p = tail;
    e = p->top + 1;
    if (e >= &p->element[pathClusterSize]) {
	p = new PropPath;
	p->prev = tail;
	tail->next = p;
	tail = p;
	e = p->top;
    } else {
	p->top = e;
    }
    e->dir = dir;
    e->sibling = b;
}

void PropertySheet::Pop () {
    register PropPath* p = tail;
    if (p == nil) {
	/* ignore underflow */
    } else if (p->top > &p->element[0]) {
	p->top -= 1;
    } else {
	tail = p->prev;
	tail->next = nil;
	delete p;
    }
}

PropDir* PropertySheet::Root () {
    return cur;
}

static int line;	/* for error handling */

/*
 * Load a single property from a string containing
 * the name and value, terminated by either a newline or null.
 */

class PropSheetBuf {
public:
    PropSheetBuf(int);
    ~PropSheetBuf();

    char* data() { return _data; }
private:
    char* _data;
    char _smallbuf[256];
};

PropSheetBuf::PropSheetBuf(int n) {
    _data = (n < sizeof(_smallbuf)) ? _smallbuf : new char[n + 1];
}

PropSheetBuf::~PropSheetBuf() {
    if (_data != _smallbuf) {
	delete _data;
    }
}

void PropertySheet::LoadProperty (const char* s) {
    register const char* src;
    register char* dst;
    const char* value;

    for (src = s; *src == ' ' || *src == '\t'; src++);
    if (*src == '#' || *src == '\n' || *src == '\0') {
	return;
    }
    PropSheetBuf buf(strlen(src));
    dst = buf.data();
    value = nil;
    for (; *src != '\n' && *src != '\0'; src++) {
	if (*src == '\\') {
	    ++src;
	    if (*src == 'n') {
		*dst++ = '\n';
	    } else if (*src == '\n') {
		++line;
	    } else {
		*dst++ = *src;
	    }
	} else if (value == nil && *src == ':') {
	    if (dst == buf.data()) {
		fprintf(stderr, "%d: empty path\n", line);
		return;
	    }
	    *dst++ = '\0';
	    value = dst;
	} else {
	    *dst++ = *src;
	}
    }
    *dst = '\0';
    if (value == nil) {
	fprintf(stderr, "%d: missing value for %s\n", line, buf.data());
	return;
    }
    PutLower(buf.data(), value);
}

/*
 * Parse property sheet information from a string.
 */

void PropertySheet::LoadList (const char* data) {
    register const char* p, * start;

    start = data;
    for (p = strchr(data, '\n'); p != nil; p = strchr(p+1, '\n')) {
	if (p > start && *(p-1) != '\\') {
	    LoadProperty(start);
	}
	start = p+1;
    }
}

/*
 * Read a property sheet from a file (e.g., Xdefaults).
 */

boolean PropertySheet::LoadFile (const char* filename) {
    FILE* f;
    char buf[4096];
    register int i;

    if (filename == nil) {
	f = stdin;
    } else {
	f = fopen(filename, "r");
	if (f == nil) {
	    return false;
	}
    }
    line = 0;
    i = 0;
    while (fgets(&buf[i], (int)(sizeof(buf) - i), f) != nil) {
	i = strlen(buf);
	if (buf[i-1] == '\n' && buf[i-2] != '\\') {
	    LoadProperty(buf);
	    i = 0;
	} else {
	    if (i == sizeof(buf)) {
		fprintf(stderr, "%s: %d: line too long\n", filename, line);
		return true;
	    }
	}
    }
    return true;
}
Exemple #12
0
QuillErrCode
HistorySnapshot::printResults(SQLQuery *queryhor, 
							  SQLQuery *queryver, 
							  bool longformat, bool fileformat,
							  bool custForm, 
							AttrListPrintMask *pmask,
							const char *constraint /* = "" */) {
  AttrList *ad = 0;
  QuillErrCode st = QUILL_SUCCESS;

  // initialize index variables
   
  off_t offset = 0, last_line = 0;

  cur_historyads_hor_index = 0;  	
  cur_historyads_ver_index = 0;

  if (!longformat && !custForm) {
	  short_header();
  }

	ExprTree *tree = NULL;

	if (constraint) {
		 ParseClassAdRvalExpr(constraint, tree);
	}

  while(1) {
	  st = getNextAd_Hor(ad, queryhor);

	  if(st != QUILL_SUCCESS) 
		  break;
	  
	  if (longformat || constraint) { 
		  st = getNextAd_Ver(ad, queryver);

		
		  if (constraint && EvalBool(ad, tree) == FALSE) {
			continue;
		  }
		  // in the case of vertical, we dont want to quit if we run
		  // out of tuples because 1) we want to display whats in the ad
		  // and 2) the horizontal cursor will correctly determine when
		  // to stop - this is because in all cases, we only pull out those
          // tuples from vertical which join with a horizontal tuple
		  if(st != QUILL_SUCCESS && st != DONE_HISTORY_VER_CURSOR) 
			  break;
		  if (fileformat) { // Print out the job ads in history file format, i.e., print the *** delimiters
			  MyString owner, ad_str, temp;
			  int compl_date;

			  ad->sPrint(ad_str);
                       if (!ad->LookupString(ATTR_OWNER, owner))
                                 owner = "NULL";
                         if (!ad->LookupInteger(ATTR_COMPLETION_DATE, compl_date))
                                 compl_date = 0;
                         temp.formatstr("*** Offset = %ld ClusterId = %d ProcId = %d Owner = \"%s\" CompletionDate = %d\n",
                                        offset - last_line, curClusterId_hor, curProcId_hor, owner.Value(), compl_date);

                         offset += ad_str.Length() + temp.Length();
                         last_line = temp.Length();
                         fprintf(stdout, "%s", ad_str.Value());
                         fprintf(stdout, "%s", temp.Value());
                 }     else if (longformat) {
                         ad->fPrint(stdout);
                         printf("\n");
                 }

	  } 
	  if (!longformat) {
	  	if (custForm == true) {
			ASSERT(pmask != NULL);
			pmask->display(stdout, ad);
		} else {
			displayJobShort(ad);
		}
	  }
  }

  if(ad != NULL) {
	  delete ad;
	  ad = NULL;
  }

  if(st == FAILURE_QUERY_HISTORYADS_HOR || st == FAILURE_QUERY_HISTORYADS_VER)
	  return st;

  return QUILL_SUCCESS;
}
/*------------------------------------------------------------------------------
 * function: AttrProj::ParseProjection
 * Parse the attribute projection file and build up the corresponding
 * data structures.
 */
DevStatus
AttrProj::ParseProjection(char *attrProjFile)
{
	DO_DEBUG(printf("AttrProj::ParseProjection()\n"));

	DevStatus	result = StatusOk;

	FILE *		file = fopen(attrProjFile, "r");
	if (file == NULL)
	{
		fprintf(stderr, "Can't open attribute projection file\n");
		result = StatusFailed;
	}
	else
	{
		const int	bufSize = 4096;
		char		buf[bufSize];
		char		separators[] = " \t";

		/* Get each line in the attribute projection file. */
		while (fgets(buf, bufSize, file) != NULL)
		{
			DOASSERT(buf[strlen(buf)-1] == '\n',
				"Projection file line too long");

			/* TEMPTEMP -- we should look for some kind of comment char. */

			StripTrailingNewline(buf);
			DO_DEBUG(printf("%s\n", buf));

			Projection	projection;
			char *		token = strtok(buf, separators);
			if (token == NULL) continue;
			projection.attrCount = atoi(token);
			DO_DEBUG(printf("projection.attrCount = %d\n",
				projection.attrCount));
			projection.attrList = new int[projection.attrCount];

			AttrList *	attrListP = _tDataP->GetAttrList();
			int			attrCount = attrListP->NumAttrs();
			int			projAttrNum = 0;

			/* Find each attribute specified for this projection. */
			while ((token = strtok(NULL, separators)) != NULL)
			{
				projection.attrList[projAttrNum] = illegalAttr;
				DO_DEBUG(printf("  token = %s", token));

				int			attrNum;

				/* Now find the attribute in the TData corresponding to
				 * the name specified in the projection. */
				for (attrNum = 0; attrNum < attrCount; attrNum++)
				{
					AttrInfo *	attrInfoP = attrListP->Get(attrNum);

					if (!strcmp(token, attrInfoP->name))
					{
						DO_DEBUG(printf(" attrNum = %d\n", attrNum));
						projection.attrList[projAttrNum] = attrNum;
						break;
					}
				}
				DOASSERT(projection.attrList[projAttrNum] != illegalAttr,	
					"Illegal attribute name in attribute projection file");
				projAttrNum++;
			}
			DOASSERT(projAttrNum == projection.attrCount,
				"Incorrect number of attributes in projection file");


			_projList.AddProjection(projection);

		}

		fclose(file);
	}

	return result;
}