int MNodeVMListToXML( mnode_t *N, /* I */ mxml_t *NE) /* I/O (modified,alloc) */ { mln_t *P; /* VM list pointer */ mvm_t *V; mxml_t *VE; if ((N == NULL) || (NE == NULL)) { return(FAILURE); } for (P = N->VMList;P != NULL;P = P->Next) { V = (mvm_t *)P->Ptr; if (V != NULL) { VE = NULL; MXMLCreateE(&VE,(char *)MXO[mxoxVM]); MVMToXML(V,VE,NULL); MXMLAddE(NE,VE); } } /* END for (P) */ return(SUCCESS); } /* END MNodeVMListToXML() */
int MAcctToXML( mgcred_t *A, mxml_t **EP, int *SAList) { int DAList[] = {mcaID, -1}; int aindex; int *AList; char tmpString[MAX_MLINE]; if ((A == NULL) || (EP == NULL)) return (FAILURE); if (SAList != NULL) AList = SAList; else AList = DAList; MXMLCreateE(EP, (char *)MXO[mxoAcct]); for (aindex = 0; AList[aindex] != -1; aindex++) { if ((MCredAToString((void *)A, mxoAcct, AList[aindex], tmpString, 0) == FAILURE) || (tmpString[0] == '\0')) { continue; } MXMLSetAttr(*EP, (char *)MCredAttr[AList[aindex]], tmpString, mdfString); } /* END for (aindex) */ return (SUCCESS); } /* END MAcctToXML() */
void addxmlnode( mxml_t *DE, struct batch_status *pbstat) { mxml_t *NE; mxml_t *AE; struct attrl *pat; NE = NULL; MXMLCreateE(&NE, "Node"); MXMLAddE(DE, NE); /* add nodeid */ AE = NULL; MXMLCreateE(&AE, "name"); MXMLSetVal(AE, pbstat->name, mdfString); MXMLAddE(NE, AE); for (pat = pbstat->attribs;pat;pat = pat->next) { AE = NULL; if (pat->value == NULL) continue; MXMLCreateE(&AE, pat->name); MXMLSetVal(AE, pat->value, mdfString); MXMLAddE(NE, AE); } return; } /* END addxmlnode() */
int MUIRsvCtl( msocket_t *S, /* I */ mbitmap_t *AFlags, /* I credential flags (bitmap of enum MRoleEnum) */ char *Auth) /* I */ { char Command[MMAX_NAME]; char RsvExp[MMAX_LINE]; char FlagString[MMAX_LINE]; char ArgString[MMAX_LINE]; marray_t RsvList; char tmpLine[MMAX_LINE << 3]; char tmpName[MMAX_LINE]; char tmpVal[MMAX_LINE]; enum MRsvCtlCmdEnum CIndex; enum MRsvAttrEnum AIndex; int rc; mrsv_t *R; mrm_t *RM; mgcred_t *U = NULL; mbool_t IsAdmin; mxml_t *RE = NULL; mxml_t *WE = NULL; mxml_t *DE = NULL; int rindex; mbitmap_t Flags; mbool_t UseUIndex = FALSE; mbool_t UseGName = FALSE; mbool_t AppendRsvExp = FALSE; mgcred_t *RU = NULL; mgcred_t *RG = NULL; mgcred_t *RA = NULL; mqos_t *RQ = NULL; enum MFormatModeEnum DFormat = mfmNONE; const char *FName = "MUIRsvCtl"; MDB(2,fUI) MLog("%s(S,%s)\n", FName, (Auth != NULL) ? Auth : "NULL"); if (S == NULL) { return(FAILURE); } /* NOTE: support create, destroy, list, modify */ /* initialize values */ S->WireProtocol = mwpS32; RsvExp[0] = '\0'; /* process request */ switch (S->WireProtocol) { case mwpXML: case mwpS32: { int WTok; /* FORMAT: <Request action="X" object="Y"><Where/></Request> */ char *ptr; if (S->RDE != NULL) { RE = S->RDE; } else if ((S->RPtr != NULL) && ((ptr = strchr(S->RPtr,'<')) != NULL) && (MXMLFromString(&RE,ptr,NULL,NULL) == FAILURE)) { MDB(3,fUI) MLog("WARNING: corrupt command '%100.100s' received\n", S->RBuffer); MUISAddData(S,"ERROR: corrupt command received\n"); return(FAILURE); } S->RDE = RE; if (MXMLGetAttr(RE,MSAN[msanAction],NULL,Command,sizeof(Command)) == FAILURE) { MDB(3,fUI) MLog("WARNING: cannot locate command '%100.100s'\n", S->RBuffer); MUISAddData(S,"ERROR: cannot locate command\n"); return(FAILURE); } WTok = -1; while (MS3GetWhere( RE, &WE, &WTok, tmpName, /* O */ sizeof(tmpName), tmpVal, /* O */ sizeof(tmpVal)) == SUCCESS) { /* process 'where' constraints */ AIndex = (enum MRsvAttrEnum)MUGetIndexCI(tmpName,MRsvAttr,FALSE,mraNONE); if ((AIndex == mraName) || (AIndex == mraUIndex) || (AIndex == mraRsvGroup)) { if (AppendRsvExp == TRUE) { MUStrCat(RsvExp,",",sizeof(RsvExp)); MUStrCat(RsvExp,tmpVal,sizeof(RsvExp)); } else { MUStrCpy(RsvExp,tmpVal,sizeof(RsvExp)); AppendRsvExp = TRUE; } if (AIndex == mraUIndex) UseUIndex = TRUE; else if (AIndex == mraRsvGroup) UseGName = TRUE; } else { switch (AIndex) { case mraAAccount: if (MAcctFind(tmpVal,&RA) == FAILURE) { MUISAddData(S,"ERROR: cannot locate requested account\n"); return(FAILURE); } break; case mraAGroup: if (MGroupFind(tmpVal,&RG) == FAILURE) { MUISAddData(S,"ERROR: cannot locate requested group\n"); return(FAILURE); } break; case mraAQOS: if (MQOSFind(tmpVal,&RQ) == FAILURE) { MUISAddData(S,"ERROR: cannot locate requested qos\n"); return(FAILURE); } break; case mraAUser: if (MUserFind(tmpVal,&RU) == FAILURE) { MUISAddData(S,"ERROR: cannot locate requested user\n"); return(FAILURE); } break; default: MUISAddData(S,"ERROR: incorrect reservation attribute\n"); return(FAILURE); /* NOTREACHED */ break; } /* END switch (AIndex) */ } /* END else */ } /* END while (MXMLGetChild() == SUCCESS) */ if (MXMLGetAttr(RE,MSAN[msanFlags],NULL,FlagString,sizeof(FlagString)) == SUCCESS) { bmfromstring(FlagString,MClientMode,&Flags); if (bmisset(&Flags,mcmXML)) { DFormat = mfmXML; } else { DFormat = mfmNONE; } } MXMLGetAttr(RE,MSAN[msanArgs],NULL,ArgString,sizeof(ArgString)); } /* END BLOCK (case mwpXML/mwpS3) */ break; default: /* not supported */ MUISAddData(S,"ERROR: corrupt command received\n"); return(FAILURE); /*NOTREACHED*/ break; } /* END switch (S->WireProtocol) */ /* process data */ if ((CIndex = (enum MRsvCtlCmdEnum)MUGetIndexCI( Command, MRsvCtlCmds, FALSE, mrcmNONE)) == mrcmNONE) { MDB(3,fUI) MLog("WARNING: unexpected subcommand '%s' received\n", Command); sprintf(tmpLine,"ERROR: unexpected subcommand '%s'\n", Command); MUISAddData(S,tmpLine); return(FAILURE); } MUserAdd(Auth,&U); S->SBuffer[0] = '\0'; switch (CIndex) { case mrcmCreate: { marray_t RList; char Buffer[MMAX_BUFFER]; int rc; Buffer[0] = 0; /* check for unauthorized peers exporting rsv */ if ((Auth != NULL) && (!strncasecmp(Auth,"peer:",strlen("peer:")))) { if (MRMFind(&Auth[strlen("peer:")],&RM) == FAILURE) { /* NYI */ } else if (!bmisset(&RM->Flags,mrmfRsvImport)) { MUISAddData(S,"rsv import not enabled for peer"); return(FAILURE); } } MUArrayListCreate(&RList,sizeof(mrsv_t *),50); rc = MUIRsvCreate( RE, Auth, Buffer, /* O */ sizeof(Buffer), TRUE, FALSE, FALSE, &RList); if (DFormat == mfmXML) { if (MXMLCreateE(&S->SDE,(char *)MSON[msonData]) == FAILURE) { rc = FAILURE; MUISAddData(S,"ERROR: internal error, cannot create response\n"); } else if (rc == SUCCESS) { mrsv_t *R; int rindex; mxml_t *RE; DE = S->SDE; for (rindex = 0;rindex < RList.NumItems;rindex++) { R = (mrsv_t *)MUArrayListGetPtr(&RList,rindex); RE = NULL; MXMLCreateE(&RE,(char *)MXO[mxoRsv]); MXMLSetVal(RE,R->Name,mdfString); MXMLAddE(DE,RE); } } else { MUISAddData(S,Buffer); } } /* END if (DFormat == mfmXML) */ else { MUISAddData(S,Buffer); } MUArrayListFree(&RList); return(rc); } /* END case mrcmCreate: */ case mrcmFlush: { msrsv_t *SR; if (MSRFind(RsvExp,&SR,NULL) == SUCCESS) { int sindex; for (sindex = 0;sindex < MMAX_SRSV_DEPTH;sindex++) { SR->DisabledTimes[sindex] = 0; } snprintf(tmpLine,sizeof(tmpLine),"SR[%s] successfully cleared disabled times\n", SR->Name); MUISAddData(S,tmpLine); return(SUCCESS); } } case mrcmQuery: bmset(&S->Flags,msftReadOnlyCommand); if (!strcasecmp(ArgString,"profile")) { mxml_t *DE; if ((S->SDE == NULL) && (MXMLCreateE(&S->SDE,(char *)MSON[msonData]) == FAILURE)) { MUISAddData(S,"ERROR: cannot create response\n"); return(FAILURE); } DE = S->SDE; return(__MUIRsvProfShow(S,U,RsvExp,&DE,NULL)); } case mrcmList: bmset(&S->Flags,msftReadOnlyCommand); break; default: break; } /* end switch(CIndex) */ MUArrayListCreate(&RsvList,sizeof(mrsv_t *),1); if (UseUIndex == TRUE) { char *ptr; char *TokPtr; /* locate by unique index */ /* FORMAT: <ID>[,<ID>]... */ /* NOTE: rsv id in format '<NAME>.<UID>' */ ptr = MUStrTok(RsvExp,", \t\n:",&TokPtr); while (ptr != NULL) { if (MRsvFind(ptr,&R,mraUIndex) == SUCCESS) { MUArrayListAppendPtr(&RsvList,R); MDB(6,fUI) MLog("INFO: reservation '%s' located by index\n", R->Name); } else { snprintf(tmpLine,sizeof(tmpLine),"ERROR: cannot locate reservation %s\n", ptr); MUISAddData(S,tmpLine); } ptr = MUStrTok(NULL,", \t\n:",&TokPtr); } /* END while (ptr != NULL) */ } /* END if (UseUIndex == TRUE) */ else if (UseGName == TRUE) { rsv_iter RTI; char *ptr; char *TokPtr; /* allow multiple group selection */ /* FORMAT: <GID>[,<GID>]... */ ptr = MUStrTok(RsvExp,", \t:",&TokPtr); while (ptr != NULL) { MRsvIterInit(&RTI); while (MRsvTableIterate(&RTI,&R) == SUCCESS) { if (R->RsvGroup == NULL) continue; if (strcmp(R->RsvGroup,ptr)) continue; MUArrayListAppendPtr(&RsvList,R); MDB(6,fUI) MLog("INFO: reservation '%s' located by group '%s'\n", R->Name, ptr); } /* END while (MRsvTableIterate()) */ ptr = MUStrTok(NULL,", \t:",&TokPtr); } /* END while (ptr != NULL) */ } /* END if (UseGName == TRUE) */ else { if (RsvExp[0] == '\0') { /* no reservation name received */ snprintf(tmpLine,sizeof(tmpLine),"ERROR: no reservation specified\n"); MUISAddData(S,tmpLine); MUArrayListFree(&RsvList); return(FAILURE); } else if ((MUStringIsRE(RsvExp) == TRUE) || (!strcmp(RsvExp,"ALL"))) { /* regular expression or special expression received */ char tmpBuf[MMAX_BUFFER]; tmpBuf[0] = '\0'; if (MUREToList( RsvExp, mxoRsv, NULL, &RsvList, FALSE, tmpBuf, sizeof(tmpBuf)) == FAILURE) { snprintf(tmpLine,sizeof(tmpLine),"ERROR: invalid expression '%s' : %s\n", RsvExp, tmpBuf); MUISAddData(S,tmpLine); MUArrayListFree(&RsvList); return(FAILURE); } } else { /* single reservation specified */ mrsv_t *tmpR = NULL; if (MRsvFind(RsvExp,&tmpR,mraNONE) == FAILURE) { snprintf(tmpLine,sizeof(tmpLine),"ERROR: invalid reservation specified '%s'\n", RsvExp); MUISAddData(S,tmpLine); MUArrayListFree(&RsvList); return(FAILURE); } else { MUArrayListAppendPtr(&RsvList,tmpR); } } /* END else */ if (RsvList.NumItems == 0) { if (!strcmp(RsvExp,"ALL")) { MUArrayListFree(&RsvList); return(SUCCESS); } else { char tmpLine[MMAX_LINE]; snprintf(tmpLine,sizeof(tmpLine),"ERROR: '%s' does not match any reservations\n", RsvExp); MUISAddData(S,tmpLine); MUArrayListFree(&RsvList); return(FAILURE); } } /* END if (RsvList.NumItems == 0) */ } /* END else (UseUIndex == TRUE) */ MDB(2,fUI) MLog("INFO: performing '%s' operation on rsv expression '%s' (%d matches)\n", MRsvCtlCmds[CIndex], RsvExp, RsvList.NumItems); if (RsvList.NumItems <= 0) { /* no reservations found */ sprintf(tmpLine,"ERROR: could not locate any matching reservations\n"); MUISAddData(S,tmpLine); MUArrayListFree(&RsvList); return(FAILURE); } rc = SUCCESS; for (rindex = 0;rindex < RsvList.NumItems;rindex++) { R = (mrsv_t *)MUArrayListGetPtr(&RsvList,rindex); /* if (((RA != NULL) && (J->Cred.A != RA)) || ((RG != NULL) && (J->Cred.G != RG)) || ((RQ != NULL) && (J->Cred.Q != RQ)) || ((RU != NULL) && (J->Cred.U != RU))) { continue; } */ /* get authorization */ if (MUICheckAuthorization( U, NULL, (void *)R, mxoRsv, mcsMRsvCtl, CIndex, &IsAdmin, tmpLine, sizeof(tmpLine)) == FAILURE) { /* NOTE: if rsv list is requested, do not report - 'not authorized' message for each rsv. */ if ((CIndex != mrcmList) && (CIndex != mrcmQuery)) { MUISAddData(S,tmpLine); MUISAddData(S,"\n"); /* allow errno to be set on the command line to indicate error */ rc = FAILURE; } /* If the final request failed, return failure otherwise continue to the next request */ if (RsvList.NumItems - 1 == rindex) { MUArrayListFree(&RsvList); /* last request failed */ if (CIndex == mrcmQuery) { /* Failed just means no reservations reported */ return(SUCCESS); } return(FAILURE); } else { /* failure is recorded but entire request hasn't failed */ continue; } } switch (CIndex) { case mrcmAlloc: { char EMsg[MMAX_LINE] = {0}; char tmpName[MMAX_NAME]; char tmpVal[MMAX_NAME]; char GResType[MMAX_NAME]; int len; GResType[0] = '\0'; /* allocate additional requested resources to specified rsv */ /* FORMAT: mrsvctl -A gres.type=dvd vpc.3 */ /* parse request */ if (MS3GetSet( RE, NULL, NULL, tmpName, sizeof(tmpName), tmpVal, sizeof(tmpVal)) == FAILURE) { sprintf(tmpLine,"ERROR: no allocation resource specified\n"); MUISAddData(S,tmpLine); MUArrayListFree(&RsvList); return(FAILURE); } if (!strcasecmp(tmpName,"resource")) { len = strlen("gres.type="); if (!strncasecmp(tmpVal,"gres.type=",len)) { MUStrCpy(GResType,&tmpVal[len],sizeof(GResType)); } } if (GResType[0] == '\0') { sprintf(tmpLine,"ERROR: no allocation resource specified\n"); MUISAddData(S,tmpLine); MUArrayListFree(&RsvList); return(FAILURE); } /* create pseudo job */ rc = MRsvAllocateGResType(R,GResType,EMsg); MUISAddData(S,EMsg); MUArrayListFree(&RsvList); return(rc); } /* END case mrcmAlloc */ /*NOTREACHED*/ break; case mrcmCreate: { /* should not be reached (handled above) */ rc = FAILURE; sprintf(tmpLine,"ERROR: create failed - internal error\n"); MUISAddData(S,tmpLine); MUArrayListFree(&RsvList); return(rc); } /* END case mrcmCreate */ /*NOTREACHED*/ break; case mrcmDestroy: { char tmpName[MMAX_NAME]; if (bmisset(&R->Flags,mrfStatic)) { sprintf(tmpLine,"ERROR: cannot release 'static' reservation %s\n", R->Name); MUISAddData(S,tmpLine); continue; } if (bmisset(&R->Flags,mrfParentLock)) { sprintf(tmpLine,"ERROR: cannot release 'locked' reservation %s - must remove parent object\n", R->Name); MUISAddData(S,tmpLine); continue; } MUStrCpy(tmpName,R->Name,sizeof(tmpName)); R->CancelIsPending = TRUE; if (bmisset(&R->Flags,mrfStanding)) { int sindex; msrsv_t *SR = NULL; /* set enabletime to the end of this reservation */ if (MSRFind(R->RsvParent,&SR,NULL) == SUCCESS) { for (sindex = 0;sindex < MMAX_SRSV_DEPTH;sindex++) { if ((SR->DisabledTimes[sindex] == 0) || (SR->DisabledTimes[sindex] == 1)) { if (R->EndTime == MMAX_TIME - 1) SR->DisabledTimes[sindex] = MMAX_TIME; else SR->DisabledTimes[sindex] = R->EndTime; break; } } /* END for (sindex) */ } /* END if (MSRFind(R->RsvGroup,&SR) == SUCCESS) */ else { sprintf(tmpLine,"WARNING: cannot locate rsv parent\n"); MUISAddData(S,tmpLine); MDB(3,fUI) MLog("WARNING: cannot locate parent '%s' for rsv '%s'\n", (R->RsvGroup != NULL) ? R->RsvGroup : "NULL", R->Name); } } /* END if (bmisset(&R->Flags,mrfStanding)) */ R->EndTime = MSched.Time - 1; R->ExpireTime = 0; snprintf(tmpLine,sizeof(tmpLine),"reservation %s destroyed by %s", tmpName, Auth); MOWriteEvent(R,mxoRsv,mrelRsvCancel,tmpLine,MStat.eventfp,NULL); if ((long)R->StartTime <= MUIDeadLine) { /* adjust UI phase wake up time */ if (MSched.AdminEventAggregationTime >= 0) MUIDeadLine = MIN(MUIDeadLine,(long)MSched.Time + MSched.AdminEventAggregationTime); } /* remove reservation */ if ((R->Type = mrtJob) && (R->J != NULL)) { /* Expiring job reservations are not released in MRsvCheckStatus(), they are extended. So to remove the reservation you must do it outside MRsvCheckStatus() */ MJobReleaseRsv(R->J,TRUE,TRUE); R = NULL; } else { MRsvCheckStatus(NULL); } MOSSyslog(LOG_INFO,tmpLine); sprintf(tmpLine,"reservation %s successfully released\n", tmpName); } /* END case mrcmDestroy */ MUISAddData(S,tmpLine); continue; /*NOTREACHED*/ break; case mrcmFlush: { msrsv_t *SR; int sindex; if (MSRFind(R->RsvGroup,&SR,NULL) == FAILURE) { sprintf(tmpLine,"reservation '%s' does not belong to a standing reservation\n", R->Name); MUISAddData(S,tmpLine); rc = FAILURE; break; } for (sindex = 0;sindex < MMAX_SRSV_DEPTH;sindex++) { SR->DisabledTimes[0] = 0; } sprintf(tmpLine,"SR[%s] successfully cleared disabled times\n", SR->Name); MUISAddData(S,tmpLine); } break; case mrcmJoin: { char EMsg[MMAX_LINE] = {0}; mrsv_t *CR = NULL; if (MRsvFind(ArgString,&CR,mraNONE) == SUCCESS) { rc = MRsvJoin(R,CR,EMsg); if (rc == FAILURE) { sprintf(tmpLine,"could not join rsv '%s' to rsv '%s' -- %s\n", R->Name, ArgString, EMsg); MUISAddData(S,tmpLine); } else { sprintf(tmpLine,"successfully joined rsv '%s' to rsv '%s'\n", ArgString, R->Name); MHistoryAddEvent(R,mxoRsv); MUISAddData(S,tmpLine); } } else { sprintf(tmpLine,"invalid reservation '%s'\n", ArgString); MUISAddData(S,tmpLine); } } /* END case mrcmJoin */ break; case mrcmSignal: { enum MTrigTypeEnum Signal = (enum MTrigTypeEnum)MUGetIndexCI(ArgString,MTrigType,FALSE,mttNONE); if (Signal == mttNONE) { sprintf(tmpLine,"invalid signal '%s' for rsv '%s'\n", ArgString, R->Name); MUISAddData(S,tmpLine); } else { MOReportEvent((void *)R,NULL,mxoRsv,Signal,MSched.Time,TRUE); sprintf(tmpLine,"signal '%s' successfully sent to rsv '%s'\n", MTrigType[Signal], R->Name); MUISAddData(S,tmpLine); } } /* END BLOCK (case mrcmSignal) */ break; case mrcmList: /* NOTE: only add matching reservations */ /* NOTE: global list handled outside of loop */ MUISAddData(S,R->Name); MUISAddData(S," "); break; case mrcmMigrate: { char EMsg[MMAX_LINE] = {0}; mrsv_t *CR = NULL; if (MRsvFind(ArgString,&CR,mraNONE) == SUCCESS) { rc = MRsvMigrate(R,CR,EMsg); if (rc == FAILURE) { sprintf(tmpLine,"could not migrate rsv '%s' to rsv '%s' -- %s\n", R->Name, ArgString, EMsg); MUISAddData(S,tmpLine); } else { sprintf(tmpLine,"successfully migrated rsv '%s' to rsv '%s'\n", ArgString, R->Name); MHistoryAddEvent(R,mxoRsv); MUISAddData(S,tmpLine); } } else { sprintf(tmpLine,"invalid reservation '%s'\n", ArgString); MUISAddData(S,tmpLine); } } /* END case mrcmJoin */ break; break; case mrcmModify: { char EMsg[MMAX_LINE] = {0}; rc = MUIRsvCtlModify(R,RE,EMsg); MUISAddData(S,EMsg); if (rc == FAILURE) { MUArrayListFree(&RsvList); return rc; } } /* END BLOCK (case mrcmModify) */ break; case mrcmQuery: /* NOTE: "profile" handled above */ bmset(&S->Flags,msftReadOnlyCommand); if (!strcmp(ArgString,"resources")) { /* list allocated resources */ if (!MNLIsEmpty(&R->NL)) { MNLToString( &R->NL, bmisset(&Flags,mcmVerbose), ",", '\0', tmpLine, sizeof(tmpLine)); MUISAddData(S,tmpLine); } MUArrayListFree(&RsvList); return(SUCCESS); } /* END if (!strcmp(ArgString,"resources")) */ else if (!strcmp(ArgString,"export")) { mxml_t *DE; if ((S->SDE == NULL) && (MXMLCreateE(&S->SDE,(char *)MSON[msonData]) == FAILURE)) { MUISAddData(S,"ERROR: cannot create response\n"); MUArrayListFree(&RsvList); return(FAILURE); } DE = S->SDE; if (MUIExportRsvQuery( R, NULL, Auth, DE, 0) == FAILURE) { MUArrayListFree(&RsvList); return(FAILURE); } } else if (!strcmp(ArgString,"wiki")) { mstring_t String(MMAX_LINE); MRsvToWikiString(R,NULL,&String); MUISAddData(S,String.c_str()); } /* END if (!strcmp(ArgString,"wiki")) */ else { /* diagnose/display rsv state/config */ char DiagOpt[MMAX_NAME]; mxml_t *DE = NULL; mxml_t *RE = NULL; const enum MRsvAttrEnum RAList[] = { mraName, mraAAccount, mraAGroup, mraAUser, mraAQOS, mraAllocNodeCount, mraAllocNodeList, mraAllocProcCount, mraAllocTaskCount, mraComment, mraEndTime, mraExpireTime, mraFlags, mraGlobalID, mraHostExp, mraLabel, mraLogLevel, mraOwner, mraPartition, mraProfile, mraReqArch, mraReqFeatureList, mraReqMemory, mraReqNodeCount, mraReqNodeList, mraReqOS, mraReqTaskCount, mraResources, mraRsvGroup, mraRsvParent, mraSID, mraStartTime, mraStatCAPS, mraStatCIPS, mraStatTAPS, mraStatTIPS, mraSubType, mraTrigger, mraType, mraVariables, mraVMList, mraNONE }; MUStrCpy(DiagOpt,R->Name,sizeof(DiagOpt)); /* check to see if the socket's return data xml is initialized */ if (S->SDE == NULL) { if (MXMLCreateE(&S->SDE,(char *)MSON[msonData]) == FAILURE) { MUISAddData(S,"ERROR: cannot create response\n"); MUArrayListFree(&RsvList); return(FAILURE); } } DE = S->SDE; MXMLCreateE(&RE,(char *)MXO[mxoRsv]); MXMLAddE(DE,RE); MRsvToXML(R,&RE,(enum MRsvAttrEnum *)RAList,NULL,TRUE,mcmNONE); /* NOTE: do not return, append data to buffer and continue */ } /* END else() */ break; default: /* NO-OP */ break; } /* END switch (CIndex) */ } /* END for (rindex) */ MUArrayListFree(&RsvList); return(rc); } /* END MUIRsvCtl() */
int MCPStoreResList( mckpt_t *CP, mres_t **RL) { int rindex; mres_t *R; char tmpBuf[MAX_MBUFFER]; mxml_t *E = NULL; const char *FName = "MCPStoreResList"; DBG(3,fCKPT) DPrint("%s(CP,RL)\n", FName); if ((CP == NULL) || (RL == NULL)) { return(FAILURE); } for (rindex = 0;rindex < MAX_MRES;rindex++) { R = RL[rindex]; if ((R == NULL) || (R->Name[0] == '\0')) break; if (R->Name[0] == '\1') { DBG(7,fCKPT) DPrint("INFO: skipping empty reservation[%02d]\n", rindex); continue; } /* ignore job and SR based reservations */ if ((R->Type == mrtJob) || (R->Flags & (1 << mrfStandingRes))) { DBG(6,fCKPT) DPrint("INFO: ignoring reservation[%02d] '%s'\n", rindex, R->Name); continue; } DBG(4,fCKPT) DPrint("INFO: checkpointing Res[%02d] '%s'\n", rindex, R->Name); MXMLCreateE(&E,"res"); MResToXML(R,E,NULL); MXMLToString(E,tmpBuf,MAX_MBUFFER,NULL,TRUE); MXMLDestroyE(&E); MCPStoreObj(CP->fp,mcpRes,R->Name,tmpBuf); } /* END for (rindex) */ return(SUCCESS); } /* END MCPStoreResList() */
int MVCToXML( mvc_t *VC, mxml_t *VE, enum MVCAttrEnum *SAList, mbool_t FullXML) { const enum MVCAttrEnum DAList[] = { mvcaACL, /* ACL */ mvcaCreateTime, /* time VC was created */ mvcaCreator, /* creator */ mvcaDescription, /* description */ mvcaFlags, /* flags (from MVCFlagEnum) */ mvcaJobs, /* names of jobs in VC */ mvcaMessages, /* VC messages */ mvcaName, /* VC name */ mvcaNodes, /* names of nodes in VC */ mvcaOwner, /* VC owner */ mvcaParentVCs, /* names of parent VCs */ mvcaReqStartTime,/* requested start time for guaranteed start time */ mvcaRsvs, /* names of rsvs in VC */ mvcaVariables, /* VC vars */ mvcaVCs, /* sub-VCs */ mvcaVMs, /* names of VMs in VC */ mvcaThrottlePolicies, /* throttling policies attached to VC via mvcctl */ mvcaNONE }; int aindex; enum MVCAttrEnum *AList; mbool_t PrintACL = FALSE; if ((VC == NULL) || (VE == NULL)) { return(FAILURE); } if (SAList != NULL) AList = SAList; else AList = (enum MVCAttrEnum *)DAList; mstring_t tmpBuf(MMAX_LINE); for (aindex = 0;AList[aindex] != mvcaNONE;aindex++) { if (AList[aindex] == mvcaACL) { PrintACL = TRUE; continue; } if ((FullXML == TRUE) && ((AList[aindex] == mvcaJobs) || (AList[aindex] == mvcaNodes) || (AList[aindex] == mvcaRsvs) || (AList[aindex] == mvcaVMs) || (AList[aindex] == mvcaVCs) || (AList[aindex] == mvcaParentVCs))) continue; if (AList[aindex] == mvcaVariables) { MUAddVarsToXML(VE,&VC->Variables); continue; } else if ((AList[aindex] == mvcaMessages) && (VC->MB != NULL)) { /* Use the already existing MMB to XML functionality */ mxml_t *ME = NULL; MXMLCreateE(&ME,(char *)MVCAttr[mvcaMessages]); MMBPrintMessages(VC->MB,mfmXML,TRUE,-1,(char *)ME,0); MXMLAddE(VE,ME); continue; } MVCAToMString(VC,AList[aindex],&tmpBuf); if (!tmpBuf.empty()) { MXMLSetAttr(VE,(char *)MVCAttr[AList[aindex]],tmpBuf.c_str(),mdfString); } } /* END for (aindex) */ if (FullXML) { /* If you specify FullXML, you get all of the children. Don't check AList */ mln_t *tmpL; mxml_t *CE; if (VC->Jobs != NULL) { mjob_t *J; enum MJobAttrEnum JAList[] = { mjaJobID, mjaAccount, mjaArgs, mjaClass, mjaCmdFile, mjaDescription, mjaFlags, mjaGroup, mjaPAL, mjaQOS, mjaRCL, mjaReqAWDuration, mjaReqHostList, /**< requested hosts */ mjaReqNodes, mjaReqReservation, mjaRM, mjaStatPSDed, mjaSysPrio, mjaTemplateFlags, mjaTrigger, mjaUser, mjaVMUsagePolicy, mjaNONE }; for (tmpL = VC->Jobs;tmpL != NULL;tmpL = tmpL->Next) { CE = NULL; J = (mjob_t *)tmpL->Ptr; MJobToXML(J,&CE,JAList,NULL,NULL,FALSE,FALSE); MXMLAddE(VE,CE); } } /* END if (VC->Jobs != NULL) */ if (VC->Nodes != NULL) { mnode_t *N; enum MNodeAttrEnum NAList[] = { mnaNodeID, mnaArch, mnaAvlGRes, mnaCfgGRes, mnaAvlTime, mnaFeatures, mnaHopCount, mnaLoad, mnaNodeState, mnaOS, mnaOSList, mnaProcSpeed, mnaRADisk, mnaRAMem, mnaRAProc, mnaRASwap, mnaRCDisk, mnaRCMem, mnaRCProc, mnaRCSwap, mnaSpeed, mnaVMOSList, mnaNONE }; for (tmpL = VC->Nodes;tmpL != NULL;tmpL = tmpL->Next) { CE = NULL; N = (mnode_t *)tmpL->Ptr; MXMLCreateE(&CE,(char *)MXO[mxoNode]); MNodeToXML(N,CE,NAList,0,FALSE,FALSE,NULL,NULL); MXMLAddE(VE,CE); } } /* END if (VC->Nodes != NULL) */ if (VC->Rsvs != NULL) { mrsv_t *R; for (tmpL = VC->Rsvs;tmpL != NULL;tmpL = tmpL->Next) { CE = NULL; R = (mrsv_t *)tmpL->Ptr; MRsvToXML(R,&CE,NULL,NULL,FALSE,mcmNONE); MXMLAddE(VE,CE); } } /* END if (VC->Rsvs != NULL) */ if (VC->VMs != NULL) { mvm_t *V; for (tmpL = VC->VMs;tmpL != NULL;tmpL = tmpL->Next) { CE = NULL; V = (mvm_t *)tmpL->Ptr; MXMLCreateE(&CE,(char *)MXO[mxoxVM]); MVMToXML(V,CE,NULL); MXMLAddE(VE,CE); } } /* END if (VC->VMs != NULL) */ if (VC->VCs != NULL) { mvc_t *V; for (tmpL = VC->VCs;tmpL != NULL;tmpL = tmpL->Next) { CE = NULL; V = (mvc_t *)tmpL->Ptr; MXMLCreateE(&CE,(char *)MXO[mxoxVC]); MVCToXML(V,CE,SAList,FullXML); MXMLAddE(VE,CE); } } /* END if (VC->VCs != NULL) */ } /* END if (FullXML) */ if ((PrintACL == TRUE) && (!MACLIsEmpty(VC->ACL))) { macl_t *tACL; mxml_t *AE = NULL; for (tACL = VC->ACL;tACL != NULL;tACL = tACL->Next) { AE = NULL; MACLToXML(tACL,&AE,NULL,FALSE); MXMLAddE(VE,AE); } } /* END if ((PrintACL == TRUE) && (!MACLIsEmpty(VC->ACL))) */ return(SUCCESS); } /* END MVCToXML() */
char *MMBPrintMessages( mmb_t *Head, /* I (optional) */ enum MFormatModeEnum DFormat, /* I */ mbool_t ShowVerbose, /* I */ int MinPrio, /* I (only display messages of this priority or higher) */ char *Buf, /* O (optional,char * or mxml_t *) */ int BufSize) /* I */ { mmb_t *mptr; char *BPtr = NULL; int BSpace; char *hptr = NULL; static char tmpMBuf[MMAX_BUFFER]; char tmpLine[MMAX_LINE << 2]; char tmpLine2[MMAX_LINE << 2]; if (Buf != NULL) { BPtr = Buf; BSpace = BufSize; } else { BPtr = tmpMBuf; BSpace = sizeof(tmpMBuf); } hptr = BPtr; switch (DFormat) { case mfmXML: case mfmAVP: /* KLUDGE - use AVP to create packed XML data */ { mxml_t *DE; mxml_t *CE; mxml_t *UE; int count = 0; DE = (mxml_t *)Buf; if (DE == NULL) break; if (Head == NULL) { /* header not required in XML */ break; } /* END if (Head == NULL) */ if (DFormat == mfmAVP) { /* initialize temporary parent XML element */ UE = NULL; } for (mptr = Head;mptr != NULL;mptr = mptr->Next) { if (mptr->Priority < MinPrio) continue; CE = NULL; MXMLCreateE(&CE,"message"); MXMLSetAttr(CE,"index",(void *)&count,mdfInt); MXMLSetAttr(CE,(char *)MMBAttr[mmbaCTime],(void *)&mptr->CTime,mdfLong); if (mptr->Owner != NULL) MXMLSetAttr(CE,(char *)MMBAttr[mmbaOwner],(void *)mptr->Owner,mdfString); MXMLSetAttr(CE,(char *)MMBAttr[mmbaPriority],(void *)&mptr->Priority,mdfInt); MXMLSetAttr(CE,(char *)MMBAttr[mmbaCount],(void *)&mptr->Count,mdfInt); MXMLSetAttr(CE,(char *)MMBAttr[mmbaExpireTime],(void *)&mptr->ExpireTime,mdfLong); MXMLSetAttr(CE,(char *)MMBAttr[mmbaType],(void *)MMBType[mptr->Type],mdfString); if (mptr->Data != NULL) { if (strchr(mptr->Data,'\n') != NULL) { char tmpData[MMAX_BUFFER]; MUStrCpy(tmpData,mptr->Data,sizeof(tmpData)); MUStrReplaceChar(tmpData,'\n',' ',FALSE); MXMLSetAttr(CE,(char *)MMBAttr[mmbaData],(void *)tmpData,mdfString); } else { MXMLSetAttr(CE,(char *)MMBAttr[mmbaData],(void *)mptr->Data,mdfString); } } if (mptr->Label != NULL) MXMLSetAttr(CE,(char *)MMBAttr[mmbaLabel],(void *)mptr->Label,mdfString); if (DFormat == mfmAVP) { /* create/update temporary XML */ if (UE == NULL) MXMLCreateE(&UE,(char*) MSON[msonData]); MXMLAddE(UE,CE); } else { MXMLAddE(DE,CE); } count++; } /* END for (mptr) */ if ((DFormat == mfmAVP) && (UE != NULL)) { /* NOTE: Buf is mxml_t *, do not populate */ MUSNInit(&BPtr,&BSpace,tmpMBuf,sizeof(tmpMBuf)); hptr = BPtr; MXMLToString(UE,tmpLine,sizeof(tmpLine),NULL,TRUE); MXMLDestroyE(&UE); MUStringPack(tmpLine,tmpLine2,sizeof(tmpLine2)); MUSNCat(&BPtr,&BSpace,tmpLine2); } } /* END BLOCK */ break; case mfmHuman: default: { int count = 0; char tmpBuf[MMAX_NAME]; char label[MMAX_NAME]; if (Buf != NULL) MUSNInit(&BPtr,&BSpace,Buf,BufSize); else MUSNInit(&BPtr,&BSpace,tmpMBuf,sizeof(tmpMBuf)); hptr = BPtr; if (Head == NULL) { if (ShowVerbose == TRUE) { MUSNPrintF(&BPtr,&BSpace,"%-7s %10s %10s %8.8s %4.4s %3.3s %s\n", "Label", "CreateTime", "ExpireTime", "Owner", "Prio", "Num", "Message"); } break; } /* END if (Head == NULL) */ for (mptr = Head;mptr != NULL;mptr = mptr->Next) { if (mptr->Priority < MinPrio) continue; if (mptr->Label != NULL) { strncpy(label,mptr->Label,sizeof(label)); } else { sprintf(label,"%d", count); } count++; if (ShowVerbose == TRUE) { char TString[MMAX_LINE]; /* display w/relative time */ MULToTString(mptr->CTime - MSched.Time,TString); strcpy(tmpBuf,TString); MULToTString(mptr->ExpireTime - MSched.Time,TString); MUSNPrintF(&BPtr,&BSpace,"%-8.8s %10s %10s %8.8s %4d %3d %s\n", label, tmpBuf, TString, (mptr->Owner != NULL) ? mptr->Owner : "N/A", mptr->Priority, mptr->Count, (mptr->Data != NULL) ? mptr->Data : "-"); } else { if (mptr->Source != NULL) { MUSNPrintF(&BPtr,&BSpace,"Message[%.8s] (from %s) %s\n", label, mptr->Source, (mptr->Data != NULL) ? mptr->Data : "-"); } else { MUSNPrintF(&BPtr,&BSpace,"Message[%.8s] %s\n", label, (mptr->Data != NULL) ? mptr->Data : "-"); } } } /* END for (mptr) */ } /* END BLOCK (case mfmHuman) */ break; } /* END switch (DFormat) */ return(hptr); } /* END MMBPrintMessages() */
int MUIRsvDiagnose( mbitmap_t *AFlagBM, char *Auth, mrsv_t *SR, mstring_t *String, mpar_t *P, char *DiagOpt, enum MFormatModeEnum DFormat, mbitmap_t *Flags, enum MRsvTypeEnum ResType) { rsv_iter RTI; int nindex; mnode_t *N; mjob_t *J; int TotalRC; int TotalRsvStatePC; int TotalRsvAPC; mrsv_t *R; mxml_t *DE = NULL; mxml_t *RE = NULL; mbool_t IsAdmin; mgcred_t *U; const char *FName = "MUIRsvDiagnose"; MDB(3,fUI) MLog("%s(Auth,String,%s,%s,%s,%s)\n", FName, (P != NULL) ? P->Name : "NULL", DiagOpt, MFormatMode[DFormat], MRsvType[ResType]); if (String == NULL) { return(FAILURE); } /* check all reservations */ MDB(4,fUI) MLog("INFO: diagnosing rsv table (%d slots)\n", MSched.M[mxoRsv]); if (DFormat == mfmXML) { /* NOTE: do not wrap specific rsv requests in Data element */ if (SR == NULL) { DE = NULL; MXMLCreateE(&DE,(char *)MSON[msonData]); } } else { /* create header */ MStringAppend(String,"Diagnosing Reservations\n"); MRsvShowState( NULL, Flags, NULL, String, DFormat); } /* initialize statistics */ TotalRC = 0; TotalRsvAPC = 0; TotalRsvStatePC = 0; for (nindex = 0;nindex < MSched.M[mxoNode];nindex++) { N = MNode[nindex]; if ((N == NULL) || (N->Name[0] == '\0')) break; if (N->Name[0] == '\1') continue; if (N->State == mnsReserved) TotalRsvStatePC += N->CRes.Procs; } /* END for (nindex) */ if (bmisset(AFlagBM,mcalAdmin1) || bmisset(AFlagBM,mcalAdmin2) || bmisset(AFlagBM,mcalAdmin3)) IsAdmin = TRUE; else IsAdmin = FALSE; MUserAdd(Auth,&U); MRsvIterInit(&RTI); while (MRsvTableIterate(&RTI,&R) == SUCCESS) { if ((SR != NULL) && (R != SR)) continue; if ((P != NULL) && (P->Index > 0) && (P->Index != R->PtIndex)) continue; if (strcmp(DiagOpt,NONE) && strcmp(DiagOpt,R->Name)) { if ((R->Label == NULL) || strcmp(DiagOpt,R->Label)) continue; } /* If a ResType is given (-w type=ResType) and it is not equal to this reservation's type, don't print */ if ((ResType != mrtNONE) && (R->Type != ResType)) continue; if (!bmisset(AFlagBM,mcalOwner) && (IsAdmin == FALSE)) { if (MUICheckAuthorization( U, NULL, (void *)R, mxoRsv, mcsDiagnose, mrcmQuery, NULL, NULL, 0) == FAILURE) { /* no authority to diagnose reservation */ continue; } } MDB(6,fUI) MLog("INFO: evaluating Rsv '%s'\n", R->Name); if (DFormat == mfmXML) { RE = NULL; MXMLCreateE(&RE,(char *)MXO[mxoRsv]); if (SR == NULL) MXMLAddE(DE,RE); MRsvShowState( R, Flags, RE, /* O */ NULL, DFormat); } else { MRsvShowState( R, Flags, NULL, String, DFormat); MRsvDiagnoseState( R, Flags, NULL, String, DFormat); } /* END else (DFormat == mfmXML) */ TotalRC++; if ((R->J != NULL) && ((R->Type == mrtJob) || (R->Type == mrtUser))) { /* determine allocated jobs associated with system jobs (user rsv) or regular jobs */ J = R->J; if (MJOBISACTIVE(J)) TotalRsvAPC += R->AllocPC; } if (SR != NULL) break; } /* END while (MRsvTableIterate()) */ if ((!strcmp(DiagOpt,NONE)) && !bmisset(AFlagBM,mcalOwner)) { /* set global diagnostic messages */ if (DFormat != mfmXML) { char *BPtr; int BSpace; char MsgBuf[MMAX_BUFFER]; MUSNInit(&BPtr,&BSpace,MsgBuf,sizeof(MsgBuf)); MStringAppendF(String,"\nActive Reserved Processors: %d\n", TotalRsvAPC); if ((TotalRsvAPC + TotalRsvStatePC) != MPar[0].DRes.Procs) { MStringAppendF(String,"INFO: active procs reserved does not equal active procs utilized (%d != %d)\n", TotalRsvAPC + TotalRsvStatePC, MPar[0].DRes.Procs); } MRsvDiagGrid(BPtr,BSpace,0); MStringAppend(String,MsgBuf); } /* END if (DFormat != mfmXML) */ } /* END if (!strcmp(DiagOpt,NONE) */ if (DFormat == mfmXML) { /* make into XML encoded string */ if (MXMLToMString( (SR == NULL) ? DE : RE, String, NULL, TRUE) == FAILURE) { MDB(2,fUI) MLog("ALERT: could not convert XML to string in %s\n", FName); } MXMLDestroyE( (SR == NULL) ? &DE : &RE); } /* END if (DFormat == mfmXML) */ return(SUCCESS); } /* END MUIRsvDiagnose() */
int MVMToXML( mvm_t *V, /* I */ mxml_t *VE, /* I/O (modified,alloc) */ enum MVMAttrEnum *SAList) /* I (optional,terminated w/mvmaLAST) */ { char tmpString[MMAX_LINE]; enum MVMAttrEnum *AList; /**< VM attribute list */ int aindex; mbitmap_t BM; const enum MVMAttrEnum DAList[] = { mvmaActiveOS, mvmaADisk, mvmaAlias, mvmaAMem, mvmaAProcs, mvmaCDisk, mvmaCMem, mvmaCProcs, mvmaCPULoad, mvmaContainerNode, mvmaDDisk, mvmaDMem, mvmaDProcs, mvmaDescription, mvmaEffectiveTTL, mvmaFlags, mvmaGMetric, mvmaID, mvmaJobID, mvmaLastMigrateTime, mvmaLastSubState, mvmaLastSubStateMTime, mvmaLastUpdateTime, mvmaMigrateCount, mvmaNetAddr, mvmaNextOS, mvmaOSList, mvmaPowerIsEnabled, mvmaPowerState, mvmaProvData, mvmaRackIndex, mvmaSlotIndex, mvmaSovereign, mvmaSpecifiedTTL, mvmaStartTime, mvmaState, mvmaSubState, mvmaStorageRsvNames, mvmaVariables, mvmaLAST }; if ((V == NULL) || (VE == NULL)) { return(FAILURE); } if (SAList != NULL) AList = SAList; else AList = (enum MVMAttrEnum *)DAList; bmset(&BM,mcmXML); for (aindex = 0;AList[aindex] != mvmaLAST;aindex++) { if ((MVMAToString(V,NULL,AList[aindex],tmpString,sizeof(tmpString),&BM) == FAILURE) || (tmpString[0] == '\0')) { continue; } if (AList[aindex] == mvmaVariables) { MUAddVarsToXML(VE,&V->Variables); continue; } MXMLSetAttr(VE,(char *)MVMAttr[AList[aindex]],tmpString,mdfString); } /* END for (aindex) */ /* Set GEvents */ MGEventListToXML(VE,&V->GEventsList); MVMStorageMountsToXML(VE,V); /* Triggers */ if (V->T != NULL) { mtrig_t *T; int tindex; mxml_t *TE = NULL; for (tindex = 0;tindex < V->T->NumItems;tindex++) { T = (mtrig_t *)MUArrayListGetPtr(V->T,tindex); if (MTrigIsReal(T) == FALSE) continue; TE = NULL; MXMLCreateE(&TE,(char *)MXO[mxoTrig]); MTrigToXML(T,TE,NULL); MXMLAddE(VE,TE); } } /* END if (V->T != NULL) */ if (V->Action != NULL) { mln_t *tmpL = NULL; mjob_t *J; mxml_t *AE; /* report pending actions */ for (tmpL = V->Action;tmpL != NULL;tmpL = tmpL->Next) { if ((MJobFind(tmpL->Name,&J,mjsmExtended) == FAILURE) || (J->System == NULL)) { continue; } AE = NULL; MXMLCreateE(&AE,"action"); MXMLSetAttr(AE,"id",(void **)tmpL->Name,mdfString); MXMLSetAttr(AE,"type",(void **)MSysJobType[J->System->JobType],mdfString); if (MJOBISACTIVE(J) == TRUE) MXMLSetAttr(AE,"starttime",(void **)&J->StartTime,mdfLong); else if (J->Rsv != NULL) MXMLSetAttr(AE,"starttime",(void **)&J->Rsv->StartTime,mdfLong); MXMLSetAttr(AE,"duration",(void **)&J->SpecWCLimit[0],mdfLong); switch (J->System->JobType) { case msjtVMMigrate: if (!MNLIsEmpty(&J->Req[0]->NodeList)) { MXMLSetAttr(AE,"destination",(void **)MNLGetNodeName(&J->Req[0]->NodeList,0,NULL),mdfString); } break; case msjtOSProvision: MXMLSetAttr(AE,"os",(void **)MAList[meOpsys][J->System->ICPVar1],mdfString); break; #if 0 case msjtVMCreate: if (J->System->Action != NULL) { char *ptr; if ((ptr = strstr(J->System->Action,"create:")) != NULL) { /* report new VM configuration */ ptr += strlen("create:"); MXMLSetAttr(AE,"config",(void **)ptr,mdfString); } } break; #endif default: /* NO-OP */ break; } /* END switch (J->System->JobType) */ MXMLAddE(VE,AE); } /* END for (tmpL = V->Action) */ } /* END if ((V->Action != NULL) && (V->Action[0] != NULL)) */ /* VMTracking job */ if (V->TrackingJ != NULL) { MXMLSetAttr(VE,"TrackingJob",(void **)V->TrackingJ->Name,mdfString); } return(SUCCESS); } /* END MVMToXML() */
int MRMToXML( mrm_t *R, /* I */ mxml_t **RMEP, /* O */ enum MRMAttrEnum *SAList) /* I (optional) */ { enum MRMAttrEnum DAList[] = { mrmaAuthType, mrmaAuthAList, mrmaAuthCList, mrmaAuthGList, mrmaAuthQList, mrmaAuthUList, mrmaCheckpointSig, mrmaCheckpointTimeout, mrmaClusterQueryURL, mrmaConfigFile, mrmaCredCtlURL, mrmaCSAlgo, mrmaDataRM, mrmaDefDStageInTime, mrmaDefHighSpeedAdapter, mrmaDataRM, mrmaEPort, mrmaFlags, mrmaHost, mrmaJobCount, mrmaJobCounter, mrmaJobStartCount, mrmaLocalDiskFS, /* mrmaMessages, - msgs are currently not safe for XML (need to update like job msgs) */ mrmaMinETime, mrmaName, mrmaNC, mrmaNMPort, mrmaNMServer, mrmaNodeFailureRsvProfile, mrmaNodeList, mrmaOMap, mrmaPartition, mrmaPort, mrmaProcs, mrmaProfile, mrmaResourceType, mrmaSocketProtocol, mrmaSQLData, mrmaState, mrmaStats, mrmaSubmitCmd, mrmaSuspendSig, mrmaTargetUsage, mrmaTimeout, mrmaType, mrmaUpdateTime, mrmaVersion, mrmaVMOwnerRM, mrmaWireProtocol, mrmaWorkloadQueryURL, mrmaNONE }; int aindex; int pindex; enum MRMAttrEnum *AList; char tmpBuffer[MMAX_BUFFER]; mxml_t *RME; if ((R == NULL) || (RMEP == NULL)) { return(FAILURE); } if ((*RMEP == NULL) && (MXMLCreateE(RMEP,(char *)MXO[mxoRM]) == FAILURE)) { return(FAILURE); } RME = *RMEP; if (SAList != NULL) AList = SAList; else AList = DAList; for (aindex = 0;AList[aindex] != mrmaNONE;aindex++) { if ((MRMAToString(R,AList[aindex],tmpBuffer,sizeof(tmpBuffer),0) == FAILURE) || (tmpBuffer[0] == '\0')) { continue; } MXMLSetAttr( RME, (char *)MRMAttr[AList[aindex]], (void *)tmpBuffer, mdfString); } /* END for (aindex) */ /* checkpoint local queue information */ if (bmisset(&R->IFlags,mrmifLocalQueue) && (MSched.LoadAllJobCP == FALSE) && (MUHTIsInitialized(&R->U.S3.JobListIndex) == SUCCESS)) { char *tmpBuf; int tmpBufLen; mhashiter_t JobListIter; char *JobName = NULL; mjob_t *J; mxml_t *QE = NULL; MUHTIterInit(&JobListIter); MXMLCreateE(&QE,(char *)MXO[mxoQueue]); tmpBuf = NULL; tmpBufLen = 0; while (MUHTIterate(&R->U.S3.JobListIndex,&JobName,NULL,NULL,&JobListIter) == SUCCESS) { if (MJobFind(JobName,&J,mjsmBasic) == SUCCESS) { if (MJobShouldCheckpoint(J,R) == FALSE) continue; } MUStrAppend(&tmpBuf,&tmpBufLen,JobName,','); /* consider using MUSNXPrintF to decrease heap fragmentation */ } MXMLSetAttr(QE,(char *)MXO[mxoJob],tmpBuf,mdfString); MXMLAddE(RME,QE); MUFree(&tmpBuf); } /* END if ((bmisset(&R->IFlags,mrmifLocalQueue)) && ...) */ /* create peer interface child */ for (pindex = 0;pindex < MMAX_RMSUBTYPE;pindex++) { mxml_t *PE; if (bmisset(&R->RTypes,mrmrtLicense) || bmisset(&R->RTypes,mrmrtNetwork) || bmisset(&R->RTypes,mrmrtProvisioning) || bmisset(&R->RTypes,mrmrtStorage)) { /* non-compute RM's may not have interface type specified since they may route directly through file or CLI interfaces */ if (R->P[pindex].RespTotalCount[0] <= 0) continue; } else { if (R->P[pindex].Type == mpstNONE) continue; } PE = NULL; MXMLCreateE(&PE,"psi"); MPSIToXML(&R->P[pindex],PE); MXMLAddE(RME,PE); } /* END for (pindex) */ if (bmisset(&R->RTypes,mrmrtLicense)) { int rindex; int IC; double tmpD; double totalCfg; double totalDed; mxml_t *GRE; IC = MAX(1,R->U.Nat.ICount); totalCfg = 0.0; totalDed = 0.0; for (rindex = 0;rindex < MSched.M[mxoxGRes];rindex++) { if ((R->U.Nat.ResName == NULL) || (R->U.Nat.ResName[rindex][0] == '\0')) break; /* Only include license information that applies to this resource manager */ if (MSNLGetIndexCount(&R->U.Nat.ResConfigCount,rindex) == 0) continue; GRE = NULL; MXMLCreateE(&GRE,"license"); MXMLSetAttr(GRE,"name",(void *)R->U.Nat.ResName[rindex],mdfString); MXMLSetAttr(GRE,"ic",(void *)&IC,mdfInt); tmpD = (double)(MSNLGetIndexCount(&R->U.Nat.ResAvailCount,rindex)) / IC; MXMLSetAttr(GRE,"averageAvail",(void *)&tmpD,mdfDouble); tmpD = (double)(MSNLGetIndexCount(&R->U.Nat.ResConfigCount,rindex)) / IC; MXMLSetAttr(GRE,"averageConfig",(void *)&tmpD,mdfDouble); /* NOTE: percentages below are over all iterations since Moab started */ tmpD = (double)(MSNLGetIndexCount(&R->U.Nat.ResFreeICount,rindex)) / IC; MXMLSetAttr(GRE,"percentIdle",(void *)&tmpD,mdfDouble); tmpD = (double)(MSNLGetIndexCount(&R->U.Nat.ResAvailICount,rindex) - MSNLGetIndexCount(&R->U.Nat.ResFreeICount,rindex)) / IC; MXMLSetAttr(GRE,"percentActive",(void *)&tmpD,mdfDouble); tmpD = (double)(R->U.Nat.ICount - MSNLGetIndexCount(&R->U.Nat.ResAvailICount,rindex)) / IC; MXMLSetAttr(GRE,"percentBusy",(void *)&tmpD,mdfDouble); if (R->U.Nat.N != NULL) { mnode_t *GN; GN = (mnode_t *)R->U.Nat.N; tmpD = (double)(MSNLGetIndexCount(&GN->CRes.GenericRes,rindex)); MXMLSetAttr(GRE,"currentConfig",(void *)&tmpD,mdfDouble); tmpD = (double)(MSNLGetIndexCount(&GN->ARes.GenericRes,rindex)); totalCfg += tmpD; MXMLSetAttr(GRE,"currentAvail",(void *)&tmpD,mdfDouble); tmpD = (double)(MSNLGetIndexCount(&GN->DRes.GenericRes,rindex)); MXMLSetAttr(GRE,"currentDedicated",(void *)&tmpD,mdfDouble); tmpD = (double)(MSNLGetIndexCount(&GN->DRes.GenericRes,rindex)); totalDed += tmpD; } MXMLAddE(RME,GRE); } /* END for (rindex) */ tmpD = totalDed / MAX(1.0,totalCfg); MXMLSetAttr(RME,"LOAD",(void *)&tmpD,mdfDouble); } /* END if (bmisset(&R->RTypes,mrmrtLicense)) */ if (bmisset(&R->RTypes,mrmrtNetwork)) { if (!MNLIsEmpty(&R->NL)) { double tmpD; mnode_t *N; int gindex; MNLGetNodeAtIndex(&R->NL,0,&N); gindex = MUMAGetIndex( meGRes, "bandwidth", mVerify); if (gindex > 0) { tmpD = MSNLGetIndexCount(&N->ARes.GenericRes,gindex) / MAX(1.0,MSNLGetIndexCount(&N->CRes.GenericRes,gindex)); tmpD = 1.0 - tmpD; MXMLSetAttr(RME,"LOAD",(void *)&tmpD,mdfDouble); } } } /* END if (bmisset(&R->RTypes,mrmrtNetwork)) */ if (bmisset(&R->RTypes,mrmrtProvisioning)) { /* report ratio of I/O (ie, install) capacity currently in use */ /* NYI */ } if (bmisset(&R->RTypes,mrmrtStorage)) { if (!MNLIsEmpty(&R->NL)) { double tmpD; mnode_t *N; MNLGetNodeAtIndex(&R->NL,0,&N); tmpD = N->ARes.Disk / MAX(1.0,N->CRes.Disk); tmpD = 1.0 - tmpD; MXMLSetAttr(RME,"LOAD",(void *)&tmpD,mdfDouble); } /* END if (bmisset(&R->RTypes,mrmrtStorage)) */ } return(SUCCESS); } /* END MRMToXML() */
int MClassLoadCP( mclass_t *CS, char *Buf) { char tmpHeader[MAX_MNAME]; char CName[MAX_MNAME]; char *ptr; mclass_t *C; long CkTime; mxml_t *E = NULL; const char *FName = "MClassLoadCP"; DBG(4,fCKPT) DPrint("%s(CS,%s)\n", FName, (Buf != NULL) ? Buf : "NULL"); if (Buf == NULL) { return(FAILURE); } /* FORMAT: <HEADER> <GID> <CKTIME> <GSTRING> */ /* load CP header */ sscanf(Buf,"%s %s %ld", tmpHeader, CName, &CkTime); if (((long)MSched.Time - CkTime) > MCP.CPExpirationTime) { return(SUCCESS); } if (CS == NULL) { if (MClassAdd(CName,&C) != SUCCESS) { DBG(5,fCKPT) DPrint("ALERT: cannot load CP class '%s'\n", CName); return(FAILURE); } } else { C = CS; } if ((ptr = strchr(Buf,'<')) == NULL) { return(FAILURE); } MXMLCreateE(&E,(char *)MXO[mxoClass]); MXMLFromString(&E,ptr,NULL,NULL); MOFromXML((void *)C,mxoClass,E); MXMLDestroyE(&E); return(SUCCESS); } /* END MClassLoadCP() */
int __MSysTestXML( char *XMLString) /* I */ { char *tail; FILE *fp; mxml_t *E = NULL; char EMsg[MMAX_LINE]; char buffer[MMAX_BUFFER << 3]; if ((XMLString != NULL) && (XMLString[0] != '\0')) { if (XMLString[0] == '/') { int rc; fp = fopen(XMLString,"r"); rc = fread((void *)buffer,sizeof(buffer),1,fp); XMLString = buffer; fprintf(stdout,"read in %d\n",rc); } fprintf(stdout,"XMLString: '%s'\n\n", XMLString); if (MXMLFromString(&E,XMLString,&tail,EMsg) == FAILURE) { fprintf(stderr,"ERROR: '%s'\n", EMsg); exit(1); } if (tail != NULL) { fprintf(stdout,"tail: '%s'\n\n", XMLString); } exit(0); } MXMLCreateE(&E,"Data"); MXMLSetAttr(E,"Value",(void *)"this >> that",mdfString); MXMLToString(E,EMsg,sizeof(EMsg),NULL,TRUE); fprintf(stdout,"XML = '%s'\n\n", EMsg); MXMLDestroyE(&E); MXMLFromString(&E,EMsg,NULL,NULL); fprintf(stdout,"After MXMLFromString: <Data %s=\"%s\"></Data>\n\n", E->AName[0], E->AVal[0]); EMsg[0] = '\0'; MXMLToString(E,EMsg,sizeof(EMsg),NULL,TRUE); fprintf(stdout,"XML = '%s'\n\n", EMsg); exit(1); /* NOTREACHED */ return(SUCCESS); } /* END __MSysTestXML() */
int MVMTransitionToXML( mtransvm_t *V, mxml_t **VEP, enum MVMAttrEnum *SAList) { char tmpString[MMAX_LINE]; mxml_t *VE; /* element for the VM */ enum MVMAttrEnum *AList; /**< VM attribute list */ int aindex; const enum MVMAttrEnum DAList[] = { mvmaActiveOS, mvmaADisk, mvmaAlias, mvmaAMem, mvmaAProcs, mvmaCDisk, mvmaCMem, mvmaCProcs, mvmaCPULoad, mvmaContainerNode, mvmaDDisk, mvmaDMem, mvmaDProcs, mvmaDescription, mvmaEffectiveTTL, mvmaFlags, mvmaGMetric, mvmaID, mvmaJobID, mvmaLastMigrateTime, mvmaLastSubState, mvmaLastSubStateMTime, mvmaLastUpdateTime, mvmaMigrateCount, mvmaNetAddr, mvmaNextOS, mvmaOSList, mvmaPowerIsEnabled, mvmaPowerState, mvmaProvData, mvmaRackIndex, mvmaSlotIndex, mvmaSovereign, mvmaSpecifiedTTL, mvmaStartTime, mvmaState, mvmaSubState, mvmaStorageRsvNames, mvmaTrackingJob, mvmaVariables, mvmaLAST }; *VEP = NULL; if ((V == NULL) || (VEP == NULL)) { return(FAILURE); } if (MXMLCreateE(VEP,(char *)MXO[mxoxVM]) == FAILURE) { return(FAILURE); } VE = *VEP; if (SAList != NULL) AList = SAList; else AList = (enum MVMAttrEnum *)DAList; for (aindex = 0;AList[aindex] != mvmaLAST;aindex++) { if (AList[aindex] == mvmaVariables) { mxml_t *VarE = NULL; MXMLDupE(V->Variables,&VarE); MXMLAddE(VE,VarE); continue; } if ((MVMTransitionAToString(V,AList[aindex],tmpString,sizeof(tmpString)) == FAILURE) || (tmpString[0] == '\0')) { continue; } MXMLSetAttr(VE,(char *)MVMAttr[AList[aindex]],tmpString,mdfString); } /* END for (aindex) */ return(SUCCESS); } /* END MVMTransitionToXML() */
int MUIShowRes( msocket_t *S, /* I */ mbitmap_t *CFlags, /* I (not used) */ char *Auth) /* I */ { enum MXMLOTypeEnum ObjectType = mxoNONE; char Name[MMAX_NAME]; char tmpName[MMAX_NAME]; char tmpVal[MMAX_LINE]; char FlagLine[MMAX_LINE]; char EMsg[MMAX_LINE] = {0}; mxml_t *RE = NULL; mxml_t *DE; mpar_t *P = NULL; mbitmap_t Flags; const char *FName = "MUIShowRes"; MDB(3,fUI) MLog("%s(S,CFlags,%s)\n", FName, Auth); /* need to get ObjectType, PName, Flags, Name */ switch (S->WireProtocol) { case mwpXML: case mwpS32: { mxml_t *WE; int WTok; /* FORMAT: <Request action="X" object="Y"><Where/></Request> */ char *ptr; if (S->RDE != NULL) { RE = S->RDE; } else if ((S->RPtr != NULL) && ((ptr = strchr(S->RPtr,'<')) != NULL) && (MXMLFromString(&RE,ptr,NULL,NULL) == FAILURE)) { MDB(3,fUI) MLog("WARNING: corrupt command '%100.100s' received\n", S->RBuffer); MUISAddData(S,"ERROR: corrupt command received\n"); return(FAILURE); } WTok = -1; while (MS3GetWhere( RE, &WE, &WTok, tmpName, /* O */ sizeof(tmpName), tmpVal, /* O */ sizeof(tmpVal)) == SUCCESS) { if (!strcasecmp(tmpName,"partition")) { if (MParFind(tmpVal,&P) == FAILURE) { snprintf(EMsg,sizeof(EMsg),"ERROR: invalid partition \"%s\" specified\n", tmpVal); MUISAddData(S,EMsg); return(FAILURE); } } else if (!strcmp(tmpName,MSON[msonObject])) { ObjectType = (enum MXMLOTypeEnum)MUGetIndexCI(tmpVal,MXOC,FALSE,mxoNONE); } } /* END while (MXMLGetChild() == SUCCESS) */ if (MXMLGetAttr(RE,MSAN[msanFlags],NULL,FlagLine,sizeof(FlagLine)) == SUCCESS) { bmfromstring(FlagLine,MClientMode,&Flags); if (strcasestr(FlagLine,"showfree") != NULL) { bmset(&Flags,mcmNonBlock); } } if (MXMLGetAttr(RE,MSAN[msanOp],NULL,Name,sizeof(Name)) == FAILURE) { MUStrCpy(Name,NONE,sizeof(Name)); } } /* END BLOCK (case mwpXML/mwpS3) */ break; default: /* not supported */ MUISAddData(S,"ERROR: corrupt command received\n"); return(FAILURE); /*NOTREACHED*/ break; } /* END switch (S->WireProtocol) */ if (MXMLCreateE(&S->SDE,(char *)MSON[msonData]) == FAILURE) { MUISAddData(S,"ERROR: cannot create response\n"); return(FAILURE); } DE = S->SDE; switch (ObjectType) { case mxoNode: if (MNodeShowRsv(Auth,Name,P,&Flags,DE,EMsg) == FAILURE) { MUISAddData(S,EMsg); return(FAILURE); } break; case mxoJob: if (MUIRsvList(Auth,Name,P,&Flags,DE,EMsg) == FAILURE) { MUISAddData(S,EMsg); return(FAILURE); } break; default: MDB(0,fUI) MLog("ERROR: reservation type '%d' not handled\n", ObjectType); snprintf(EMsg,sizeof(EMsg),"ERROR: reservation type '%d' not handled\n", ObjectType); MUISAddData(S,EMsg); return(FAILURE); break; } /* END switch (ObjectType) */ return(SUCCESS); } /* END MUIShowRes() */
int MXMLFromString( mxml_t **EP, /* O (populate or create) */ char *XMLString, /* I */ char **Tail, /* O (optional) */ char *EMsg, /* O (optional) */ int emsg_size) /* I */ { mxml_t *E; char *ptr; char *tail; int index; mbool_t ElementIsClosed = FALSE; mbool_t DoAppend = FALSE; char tmpNLine[MMAX_LINE + 1]; char tmpVLine[MMAX_XBUFFER + 1]; if (EP != NULL) *EP = NULL; if (EMsg != NULL) EMsg[0] = '\0'; if ((XMLString == NULL) || (EP == NULL)) { if (EMsg != NULL) snprintf(EMsg, emsg_size, "invalid arguments"); return(FAILURE); } if ((ptr = strchr(XMLString, '<')) == NULL) { if (EMsg != NULL) snprintf(EMsg, emsg_size, "no XML in string"); return(FAILURE); } if (ptr[1] == '/') { /* located tail marker */ if (EMsg != NULL) snprintf(EMsg, emsg_size, "premature termination marker"); return(FAILURE); } /* NOTE: should support append/overlay parameter (NYI) */ /* ignore 'meta' elements */ while ((ptr[1] == '?') || (ptr[1] == '!')) { ptr++; /* ignore 'meta' elements */ if (*ptr == '?') { ptr++; if ((ptr = strstr(ptr, "?>")) == NULL) { /* cannot locate end of meta element */ return(FAILURE); } if ((ptr = strchr(ptr, '<')) == NULL) { /* cannot locate next element */ if (EMsg != NULL) snprintf(EMsg, emsg_size, "cannot locate post-meta XML"); return(FAILURE); } } /* END if (*ptr == '?') */ /* ignore 'comment' element */ if (!strncmp(ptr, "!--", 3)) { ptr += 3; if ((ptr = strstr(ptr, "-->")) == NULL) { /* cannot locate end of comment element */ if (EMsg != NULL) snprintf(EMsg, emsg_size, "cannot locate comment termination marker"); return(FAILURE); } if ((ptr = strchr(ptr, '<')) == NULL) { /* cannot locate next element */ if (EMsg != NULL) snprintf(EMsg, emsg_size, "cannot locate post-comment XML"); return(FAILURE); } } /* END if (!strncmp(ptr,"!--",3)) */ } /* END while ((ptr[1] == '?') || (ptr[1] == '!')) */ /* remove whitespace */ while (isspace(*ptr)) ptr++; /* extract root element */ if (*ptr != '<') { /* cannot located start of element */ if (EMsg != NULL) snprintf(EMsg, emsg_size, "cannot locate start of root element"); return(FAILURE); } ptr++; /* ignore '<' */ index = 0; while ((*ptr != ' ') && (*ptr != '>')) { if ((ptr[0] == '/') && (ptr[1] == '>')) { ElementIsClosed = TRUE; break; } tmpNLine[index++] = *(ptr++); if ((index >= MMAX_LINE) || (ptr[0] == '\0')) { if (EMsg != NULL) snprintf(EMsg, emsg_size, "element name is too long - %.10s", tmpNLine); return(FAILURE); } } tmpNLine[index] = '\0'; if ((*EP == NULL) && (MXMLCreateE(EP, tmpNLine) == FAILURE)) { if (EMsg != NULL) snprintf(EMsg, emsg_size, "cannot create XML element '%s'", tmpNLine); return(FAILURE); } E = *EP; if ((E->ACount > 0) || (E->CCount > 0)) { DoAppend = TRUE; } if (ElementIsClosed == TRUE) { ptr += 2; /* skip '/>' */ if (Tail != NULL) *Tail = ptr; return(SUCCESS); } while (*ptr == ' ') ptr++; while (*ptr != '>') { /* extract attributes */ /* FORMAT: <ATTR>="<VAL>" */ index = 0; while ((*ptr != '=') && (*ptr != '\0')) { tmpNLine[index++] = *(ptr++); if (index >= MMAX_LINE) break; } tmpNLine[index] = '\0'; if (*ptr != '\0') ptr++; /* skip '=' */ if (*ptr != '\0') ptr++; /* skip '"' */ if (*ptr == '\0') { if (EMsg != NULL) snprintf(EMsg, emsg_size, "string is corrupt - early termination"); return(FAILURE); } index = 0; while ((*ptr != '"') || ((ptr > XMLString) && (*(ptr - 1) == '\\'))) { tmpVLine[index++] = *(ptr++); if ((index >= MMAX_XBUFFER) || (*ptr == '\0')) { MXMLDestroyE(EP); /* locate tail */ if (Tail != NULL) *Tail = ptr + strlen(ptr); if (EMsg != NULL) { snprintf(EMsg, emsg_size, "attribute name is too long - %.10s", tmpVLine); } return(FAILURE); } } tmpVLine[index] = '\0'; MXMLSetAttr(E,tmpNLine,(void *)tmpVLine,mdfString); ptr++; /* ignore '"' */ while (*ptr == ' ') ptr++; if ((ptr[0] == '/') && (ptr[1] == '>')) { /* element terminator reached */ ptr += 2; /* skip '/>' */ if (Tail != NULL) *Tail = ptr; return(SUCCESS); } } /* END while (*ptr != '>') */ ptr++; /* ignore '>' */ /* skip whitespace */ while (isspace(*ptr)) ptr++; /* extract value */ if (*ptr != '<') { char *ptr2; index = 0; while (*ptr != '<') { tmpVLine[index++] = *(ptr++); if (index >= MMAX_XBUFFER) break; } tmpVLine[index] = '\0'; E->Val = strdup(tmpVLine); if (E->Val == NULL) { if (EMsg != NULL) { snprintf(EMsg, emsg_size, "cannot alloc memory for value - %.10s", tmpVLine); } return(FAILURE); } /* restore '<' symbols */ for (ptr2 = strchr(E->Val,(char)14);ptr2 != NULL;ptr2 = strchr(ptr2,(char)14)) *ptr2 = '<'; } /* END if (*ptr != '<') */ /* extract children */ while (ptr[1] != '/') { mxml_t *C; C = NULL; if (DoAppend == TRUE) { char *ptr2; char tmpCName[MMAX_NAME]; int index; /* FORMAT: <NAME>... */ /* locate name */ ptr2 = ptr + 1; /* ignore '<' */ index = 0; while ((*ptr2 != ' ') && (*ptr2 != '>')) { if ((ptr2[0] == '/') && (ptr2[1] == '>')) { break; } tmpCName[index++] = *(ptr2++); if ((index >= MMAX_LINE) || (ptr2[0] == '\0')) { if (EMsg != NULL) { snprintf(EMsg, emsg_size, "element name is too long - %.10s", tmpCName); } return(FAILURE); } } tmpCName[index] = '\0'; MXMLGetChild(E, tmpCName, NULL, &C); } if ((MXMLFromString(&C, ptr, &tail, EMsg, emsg_size) == FAILURE) || (MXMLAddE(E, C) == FAILURE)) { break; } ptr = tail; if ((ptr == NULL) || (ptr[0] == '\0')) { /* XML is corrupt */ if (Tail != NULL) *Tail = ptr; if ((EMsg != NULL) && (EMsg[0] == '\0')) snprintf(EMsg, emsg_size, "cannot extract child"); return(FAILURE); } } /* END while (ptr[1] != '/') */ /* ignore whitespace */ while (isspace(*ptr)) ptr++; /* process tail */ if (*ptr == '/') { /* process '/>' */ ptr++; /* ignore '/' */ } else { ptr++; /* ignore '<' */ ptr++; /* ignore '/' */ ptr += strlen(E->Name); } ptr++; /* ignore '>' */ if (Tail != NULL) *Tail = ptr; return(SUCCESS); } /* END MXMLFromString() */
int MVMFailuresToXML( mvm_t *V, char *VMID, mxml_t **FDE) { mxml_t *GEE = NULL; char *GEName; mgevent_obj_t *GEvent; mgevent_iter_t GEIter; if (FDE == NULL) return(FAILURE); if ((V == NULL) && (VMID == NULL)) { /* at least one of these must be valid */ return(FAILURE); } if (V == NULL) { if (MVMFind(VMID,&V) == FAILURE) return(FAILURE); } /* cycle through generic events and create failuredetails XML * if one is found! */ MGEventIterInit(&GEIter); while (MGEventItemIterate(&V->GEventsList,&GEName,&GEvent,&GEIter) == SUCCESS) { if (GEvent->GEventMTime <= 0) continue; MXMLCreateE(&GEE,"failuredetails"); /* Not currently part of the spec, but may soon be MXMLSetAttr(GEE,"name",(void *)GEName,mdfString); MXMLSetAttr(GEE,"time",(void *)&GEvent->GEventMTime,mdfLong); MXMLSetAttr(GEE,"vmid",(void *)V->VMID,mdfString); */ MXMLSetVal(GEE,(void *)GEvent->GEventMsg,mdfString); break; } /* END while (MUHTIterate(&V->GEvents...) == SUCCESS) */ if (GEE == NULL) { return(FAILURE); } *FDE = GEE; return(SUCCESS); } /* END MVMFailuresToXML() */
int MVMCRToXML( mvm_req_create_t *VMCR, /* I */ mxml_t **VEP) /* O */ { mxml_t *VE = NULL; if (VMCR == NULL) return(FAILURE); if (*VEP == NULL) { if (MXMLCreateE(VEP,(char *)MXO[mxoxVMCR]) == FAILURE) { MDB(3,fCKPT) MLog("INFO: failed to create xml for VMCR for '%s'\n", VMCR->VMID); return(FAILURE); } } VE = *VEP; if (VMCR->VMID[0] != '\0') { MXMLSetAttr(VE,"ID",(void *)VMCR->VMID,mdfString); } if (VMCR->Vars[0] != '\0') { MXMLSetAttr(VE,"VARS",(void *)VMCR->Vars,mdfString); } if (VMCR->Storage[0] != '\0') { MXMLSetAttr(VE,"STORAGE",(void *)VMCR->Storage,mdfString); } if (VMCR->Aliases[0] != '\0') { MXMLSetAttr(VE,"ALIAS",(void *)VMCR->Aliases,mdfString); } if (VMCR->Triggers[0] != '\0') { MXMLSetAttr(VE,"TRIGGER",(void *)VMCR->Triggers,mdfString); } if (VMCR->N != NULL) { MXMLSetAttr(VE,"HYPERVISOR",(void *)VMCR->N->Name,mdfString); } if (VMCR->JT != NULL) { MXMLSetAttr(VE,"TEMPLATE",(void *)VMCR->JT->Name,mdfString); } if (VMCR->OwnerJob != NULL) { MXMLSetAttr(VE,"OWNERJOB",(void *)VMCR->OwnerJob->Name,mdfString); } if (VMCR->OSIndex != 0) { /* Set to string so that OS loading order doesn't matter */ MXMLSetAttr(VE,"IMAGE",(void *)MAList[meOpsys][VMCR->OSIndex],mdfString); } if (VMCR->TrackingJ[0] != '\0') MXMLSetAttr(VE,"TRACKINGJ",(void *)VMCR->TrackingJ,mdfString); MXMLSetAttr(VE,"WALLTIME",(void *)&VMCR->Walltime,mdfLong); MXMLSetAttr(VE,"SOVEREIGN",(void *)MBool[VMCR->IsSovereign],mdfString); MXMLSetAttr(VE,"ISONETIMEUSE",(void *)MBool[VMCR->IsOneTimeUse],mdfString); /* CRes info */ MXMLSetAttr(VE,"DISK",(void *)&VMCR->CRes.Disk,mdfInt); MXMLSetAttr(VE,"MEM",(void *)&VMCR->CRes.Mem,mdfInt); MXMLSetAttr(VE,"PROCS",(void *)&VMCR->CRes.Procs,mdfInt); return(SUCCESS); } /* END MVMCRToXML() */
int MVMToPendingActionXML( mvm_t *V, /* I */ mxml_t **VEP) /* O (alloc) */ { char tmpLine[MMAX_LINE]; mxml_t *PE; mxml_t *CE; mulong JDuration = 0; mbool_t GEventsSpecified = FALSE; enum MSystemJobTypeEnum PendingActionType = msjtNONE; char PendingActionTypeStr[MMAX_LINE]; if (VEP == NULL) { return(FAILURE); } *VEP = NULL; if (V == NULL) { return(FAILURE); } PE = NULL; /* See if there are any GEvents */ if (MGEventGetItemCount(&V->GEventsList) > 0) { GEventsSpecified = TRUE; } /* NOTE: do not change pending actions strings w/o coordinating with MCM team */ if ((V->NextOS != 0) && (V->NextOS != V->ActiveOS)) { PendingActionType = msjtOSProvision; MUStrCpy(PendingActionTypeStr,(char *)MPendingActionType[mpatVMOSProvision],sizeof(PendingActionTypeStr)); } else if (((V->PowerSelectState == mpowOn) || (V->PowerSelectState == mpowOff)) && (V->PowerState != V->PowerSelectState) && (MSched.Time - V->PowerMTime < MCONST_HOURLEN)) { if (V->PowerSelectState == mpowOn) { PendingActionType = msjtPowerOn; MUStrCpy(PendingActionTypeStr,(char *)MPendingActionType[mpatVMPowerOn],sizeof(PendingActionTypeStr)); } else if (V->PowerSelectState == mpowOff) { PendingActionType = msjtPowerOff; MUStrCpy(PendingActionTypeStr,(char *)MPendingActionType[mpatVMPowerOff],sizeof(PendingActionTypeStr)); } } else { PendingActionType = msjtNONE; } if (PendingActionType == msjtNONE) { /* has no action on it to report as a pending action */ return(FAILURE); } /* create common elements */ if (MXMLCreateE(&PE,(char *)MXO[mxoxPendingAction]) == FAILURE) { return(FAILURE); } snprintf(tmpLine,sizeof(tmpLine),"%s-%ld", V->VMID, V->LastOSModRequestTime); MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaPendingActionID],(void *)tmpLine,mdfString); MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaSched],(void *)MSched.Name,mdfString); if (PendingActionType != msjtNONE) { MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaType],(void *)PendingActionTypeStr,mdfString); if (V->LastOSModRequestTime > 0) { /* Viewpoint only wants positive starttimes reported */ MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaStartTime],(void *)&V->LastOSModRequestTime,mdfLong); } if (MSched.DefProvDuration > 0) JDuration = MSched.DefProvDuration; else JDuration = MDEF_PROVDURATION; MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaMaxDuration],(void *)&JDuration,mdfLong); if (V->N != NULL) MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaHostlist],(void *)V->N->Name,mdfString); MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaState],(void *)MJobState[mjsRunning],mdfString); if (V->LastSubState != NULL) { MXMLSetAttr(PE,(char *)MPendingActionAttr[mpaaSubState],(void *)V->LastSubState,mdfString); } /* now set action specific data */ switch (PendingActionType) { case msjtOSProvision: /* handle re-provisioning of VM's */ MXMLAddChild(PE,PendingActionTypeStr,NULL,&CE); MXMLSetAttr(CE,(char *)MPendingActionAttr[mpaaVMID],(void *)V->VMID,mdfString); MXMLSetAttr(CE,(char *)MPendingActionAttr[mpaaTargetOS],(void *)MAList[meOpsys][V->NextOS],mdfString); break; case msjtPowerOn: case msjtPowerOff: /* handle start/stop */ MXMLAddChild(PE,PendingActionTypeStr,NULL,&CE); MXMLSetAttr(CE,(char *)MPendingActionAttr[mpaaVMID],(void *)V->VMID,mdfString); break; default: /* NO-OP */ break; } /* END switch (PendingActionType) */ } /* END if (PendingActionType != msjtNONE) */ if (GEventsSpecified != FALSE) { mxml_t *GEE; if (MVMFailuresToXML(V,NULL,&GEE) == SUCCESS) MXMLAddE(PE,GEE); } /* END if (GEventsSpecified != FALSE) */ *VEP = PE; return(SUCCESS); } /* END MVMToPendingActionXML() */
int main( int argc, /* I */ char **argv) /* I */ { struct batch_status *bstatus = NULL; int con; char *specified_server = NULL; int errflg = 0; int i; extern char *optarg; extern int optind; char **pa; struct batch_status *pbstat; int flag = ALLI; char *note = NULL; enum note_flags note_flag = unused; char **nodeargs = NULL; int lindex; enum NStateEnum ListType = tnsNONE; /* get default server, may be changed by -s option */ progname = strdup(argv[0]); while ((i = getopt(argc, argv, "acdlopqrs:x-:N:n")) != EOF) { switch (i) { case 'a': flag = ALLI; break; case 'c': flag = CLEAR; break; case 'd': flag = DIAG; break; case 'l': flag = LIST; break; case 'o': flag = OFFLINE; break; case 'p': flag = PURGE; break; case 'q': quiet = 1; break; case 'r': flag = RESET; break; case 's': specified_server = optarg; break; case 'x': flag = ALLI; DisplayXML = TRUE; break; case 'N': /* preserve any previous option other than the default, * to allow -N to be combined with -o, -c, etc */ if (flag == ALLI) flag = NOTE; note = strdup(optarg); if (note == NULL) { perror("Error: strdup() returned NULL"); exit(1); } note_flag = set; /* -N n is the same as -N "" -- it clears the note */ if (!strcmp(note, "n")) *note = '\0'; if (strlen(note) > MAX_NOTE) { fprintf(stderr, "Warning: note exceeds length limit (%d) - server may reject it...\n", MAX_NOTE); } if (strchr(note, '\n') != NULL) fprintf(stderr, "Warning: note contains a newline - server may reject it...\n"); break; case 'n': note_flag = list; break; case '-': if ((optarg != NULL) && !strcmp(optarg, "version")) { fprintf(stderr, "Version: %s\nRevision: %s\n", PACKAGE_VERSION, SVN_VERSION); exit(0); } else if ((optarg != NULL) && !strcmp(optarg, "about")) { TShowAbout_exit(); } errflg = 1; break; case '?': default: errflg = 1; break; } /* END switch (i) */ } /* END while (i = getopt()) */ if ((note_flag == list) && (flag != LIST)) { fprintf(stderr, "Error: -n requires -l\n"); errflg = 1; } for (pa = argv + optind;*pa;pa++) { if (strlen(*pa) == 0) { errflg = 1; } } if (errflg != 0) { if (!quiet) { fprintf(stderr, "usage:\t%s [-{c|d|l|o|p|r}] [-s server] [-n] [-N \"note\"] [-q] node ...\n", progname); fprintf(stderr, "\t%s [-{a|x}] [-s server] [-q] [node]\n", progname); } exit(1); } con = cnt2server(specified_server); if (con <= 0) { if (!quiet) { fprintf(stderr, "%s: cannot connect to server %s, error=%d (%s)\n", progname, (specified_server) ? specified_server : pbs_default(), con * -1, pbs_strerror(con * -1)); } exit(1); } /* if flag is ALLI, LIST, get status of all nodes */ if ((flag == ALLI) || (flag == LIST) || (flag == DIAG)) { if ((flag == ALLI) || (flag == LIST) || (flag == DIAG)) { if (flag == LIST) { /* allow state specification */ if (argv[optind] != NULL) { for (lindex = 1;lindex < tnsLAST;lindex++) { if (!strcasecmp(NState[lindex], argv[optind])) { ListType = lindex; optind++; break; } } } } /* allow node specification (if none, then create an empty list) */ if (argv[optind] != NULL) { nodeargs = argv + optind; } else { nodeargs = calloc(2, sizeof(char **)); nodeargs[0] = strdup(""); nodeargs[1] = '\0'; } } } if ((note_flag == set) && (note != NULL)) { /* set the note attrib string on specified nodes */ for (pa = argv + optind;*pa;pa++) { set_note(con, *pa, note); } } switch (flag) { case DIAG: /* NYI */ break; case CLEAR: /* clear OFFLINE from specified nodes */ for (pa = argv + optind;*pa;pa++) { marknode(con, *pa, ND_offline, DECR, NULL, DECR); } break; case RESET: /* clear OFFLINE, add DOWN to specified nodes */ for (pa = argv + optind;*pa;pa++) { marknode(con, *pa, ND_offline, DECR, ND_down, INCR); } break; case OFFLINE: /* set OFFLINE on specified nodes */ for (pa = argv + optind;*pa;pa++) { marknode(con, *pa, ND_offline, INCR, NULL, INCR); } break; case PURGE: /* remove node record */ /* NYI */ break; case ALLI: if (DisplayXML == TRUE) { char *tmpBuf = NULL, *tail = NULL; int bufsize; mxml_t *DE; DE = NULL; MXMLCreateE(&DE, "Data"); for (lindex = 0;nodeargs[lindex] != '\0';lindex++) { bstatus = statnode(con, nodeargs[lindex]); for (pbstat = bstatus;pbstat;pbstat = pbstat->next) { addxmlnode(DE, pbstat); } /* END for (pbstat) */ pbs_statfree(pbstat); } MXMLToXString(DE, &tmpBuf, &bufsize, INT_MAX, &tail, TRUE); MXMLDestroyE(&DE); fprintf(stdout, "%s\n", tmpBuf); } else { for (lindex = 0;nodeargs[lindex] != '\0';lindex++) { bstatus = statnode(con, nodeargs[lindex]); for (pbstat = bstatus;pbstat;pbstat = pbstat->next) { printf("%s\n", pbstat->name); prt_node_attr(pbstat, 0); putchar('\n'); } /* END for (bpstat) */ pbs_statfree(pbstat); } } break; case LIST: /* list any node that is DOWN, OFFLINE, or UNKNOWN */ for (lindex = 0;nodeargs[lindex] != '\0';lindex++) { bstatus = statnode(con, nodeargs[lindex]); for (pbstat = bstatus;pbstat != NULL;pbstat = pbstat->next) { char *S; S = get_nstate(pbstat); if (filterbystate(pbstat, ListType, S)) { char *n; if ((note_flag == list) && (n = get_note(pbstat))) { printf("%-20.20s %-26.26s %s\n", pbstat->name, S, n); } else { printf("%-20.20s %s\n", pbstat->name, S); } } } pbs_statfree(pbstat); } break; } /* END switch (flag) */ pbs_disconnect(con); return(0); } /* END main() */
int MUIRsvDiagnoseXML( msocket_t *S, /* I (modified) */ mbitmap_t *CFlagBM, /* I enum MRoleEnum bitmap */ char *Auth) /* I */ { rsv_iter RTI; char DiagOpt[MMAX_LINE]; char FlagString[MMAX_LINE]; char RsvID[MMAX_LINE]; mxml_t *DE; mxml_t *RE; mrsv_t *R; mgcred_t *U; mbitmap_t CFlags; /* bitmap of enum MCModeEnum */ const enum MRsvAttrEnum RAList[] = { mraName, mraACL, /**< @see also mraCL */ mraAAccount, mraAGroup, mraAUser, mraAQOS, mraAllocNodeCount, mraAllocNodeList, mraAllocProcCount, mraAllocTaskCount, mraCL, /**< credential list */ mraComment, mraCost, /**< rsv AM lien/charge */ mraCTime, /**< creation time */ mraDuration, mraEndTime, mraExcludeRsv, mraExpireTime, mraFlags, mraGlobalID, mraHostExp, mraHistory, mraLabel, mraLastChargeTime, /* time rsv charge was last flushed */ mraLogLevel, mraMessages, mraOwner, mraPartition, mraPriority, mraProfile, mraReqArch, mraReqFeatureList, mraReqMemory, mraReqNodeCount, mraReqNodeList, mraReqOS, mraReqTaskCount, mraReqTPN, mraResources, mraRsvAccessList, /* list of rsv's and rsv groups which can be accessed */ mraRsvGroup, mraRsvParent, mraSID, mraStartTime, mraStatCAPS, mraStatCIPS, mraStatTAPS, mraStatTIPS, mraSubType, mraTrigger, mraType, mraVariables, mraVMList, mraNONE }; RsvID[0] = '\0'; if (MXMLCreateE(&S->SDE,(char *)MSON[msonData]) == FAILURE) { MUISAddData(S,"ERROR: cannot create response\n"); MCacheJobLock(FALSE,TRUE); return(FAILURE); } DE = S->SDE; /* find the user who issued the request */ MUserAdd(Auth,&U); /* get the argument flags for the request */ if (MXMLGetAttr(S->RDE,MSAN[msanFlags],NULL,FlagString,sizeof(FlagString)) == SUCCESS) bmfromstring(FlagString,MClientMode,&CFlags); /* look for a specified resveration id */ if (MXMLGetAttr(S->RDE,MSAN[msanOp],NULL,DiagOpt,sizeof(DiagOpt)) == SUCCESS) { MUStrCpy(RsvID,DiagOpt,sizeof(RsvID)); } /* loop through all reservations and create an xml element for each, adding * it to the return data element */ MRsvIterInit(&RTI); while (MRsvTableIterate(&RTI,&R)) { if ((!MUStrIsEmpty(RsvID)) && (strcmp(RsvID,R->Name) != 0)) continue; if (MUICheckAuthorization( U, NULL, (void *)R, mxoRsv, mcsDiagnose, mrcmQuery, NULL, NULL, 0) == FAILURE) { /* no authority to diagnose reservation */ continue; } /* END if (MUICheckAuthorization...) */ MDB(6,fUI) MLog("INFO: evaluating MRsv '%s'\n", R->Name); RE = NULL; MXMLCreateE(&RE,(char *)MXO[mxoRsv]); MXMLAddE(DE,RE); MRsvToXML(R,&RE,(enum MRsvAttrEnum *)RAList,NULL,TRUE,mcmNONE); } /* END for (rindex) */ return(SUCCESS); } /* END MUIRsvDiagnoseXML() */