示例#1
0
int MTraceLoadWorkload(

  char     *Buffer,   /* I */
  int      *TraceLen, /* I (optional,modified) */
  mjob_t   *J,        /* O */
  int       Mode,     /* I */
  int      *Version)  /* O */

  {
  char *tail;
  char *head;

  char *ptr;
  char *ptr2;

  char *tok;
  char *TokPtr;

  char Line[MAX_MLINE << 4];
  char tmpLine[MAX_MLINE];

  char MHostName[MAX_MNAME];
  char MReqHList[MAX_MLINE << 2];
  char Reservation[MAX_MNAME];

  char tmpTaskRequest[MAX_MLINE];
  char tmpSpecWCLimit[MAX_MLINE];
  char tmpState[MAX_WORD];
  char tmpOpsys[MAX_WORD];
  char tmpArch[MAX_WORD];
  char tmpNetwork[MAX_WORD];
  char tmpMemCmp[MAX_WORD];
  char tmpDiskCmp[MAX_WORD];
  char tmpReqNFList[MAX_MLINE];
  char tmpClass[MAX_MLINE];
  char tmpRMName[MAX_MLINE];
  char tmpCmd[MAX_MLINE];
  char tmpRMXString[MAX_MLINE >> 2];
  char tmpParName[MAX_MNAME];
  char tmpJFlags[MAX_MLINE];
  char tmpQReq[MAX_WORD];
  char tmpASString[MAX_MLINE];
  char tmpRMemBuf[MAX_MNAME];
  char tmpRDiskBuf[MAX_MNAME];
  char tmpDSwapBuf[MAX_MNAME];
  char tmpDMemBuf[MAX_MNAME];
  char tmpDDiskBuf[MAX_MNAME];
  char UName[MAX_MNAME];
  char GName[MAX_MNAME];
  char AName[MAX_MNAME];

  char SetString[MAX_MLINE];

  unsigned long tmpQTime;
  unsigned long tmpDTime;
  unsigned long tmpSTime;
  unsigned long tmpCTime;

  unsigned long tmpSQTime;


  unsigned long tmpSDate;
  unsigned long tmpEDate;

  int      TPN;
  int      TasksAllocated;
  int      index;
  int      rc;

  int      tindex;
  int      nindex;

  mqos_t  *QDef;

  mreq_t  *RQ[MAX_MREQ_PER_JOB];

  mnode_t *N;

  long     ReqProcSpeed;

  const char *FName = "MTraceLoadWorkload";

  DBG(5,fSIM) DPrint("%s(Buffer,TraceLen,J,%d,%d)\n",
    FName,
    Mode,
    (Version != NULL) ? *Version : -1);

  if (J == NULL)
    {
    DBG(5,fSIM) DPrint("ALERT:    NULL job pointer passed in %s()\n",
      FName);

    return(FAILURE);
    }

  if (Buffer == NULL)
    {
    return(FAILURE);
    }

  if ((tail = strchr(Buffer,'\n')) == NULL)
    {
    /* assume line is '\0' terminated */

    if (TraceLen != NULL)
      tail = Buffer + *TraceLen;
    else
      tail = Buffer + strlen(Buffer);
    }

  head = Buffer;

  MUStrCpy(Line,head,MIN(tail - head + 1,sizeof(Line)));

  DBG(6,fSIM) DPrint("INFO:     parsing trace line '%s'\n",
    Line);

  if (TraceLen != NULL)
    *TraceLen = (tail - head) + 1;

  /* eliminate comments */

  if ((ptr = strchr(Line,'#')) != NULL)
    {
    DBG(5,fSIM) DPrint("INFO:     detected trace comment line, '%s'\n",
      Line);

    *ptr = '\0';
    }

  if (Line[0] == '\0')
    {
    return(FAILURE);
    }

  /* look for VERSION settings */

  if (!strncmp(Line,TRACE_WORKLOAD_VERSION_MARKER,strlen(TRACE_WORKLOAD_VERSION_MARKER)))
    {
    if (MTraceGetWorkloadVersion(Line,Version) == FAILURE)
      {
      DBG(0,fSIM) DPrint("ALERT:    cannot determine workload trace version\n");

      /* assume default version */

      if (Version != NULL)
        *Version = DEFAULT_WORKLOAD_TRACE_VERSION;
      }
    else
      {
      DBG(3,fSIM) DPrint("INFO:     workload trace version %d detected\n",
        (Version != NULL) ? *Version : -1);
      }

    return(FAILURE);
    }  /* END if (!strncmp(Line,TRACE_WORKLOAD_VERSION_MARKER)) */

  /* set default workload attributes */

  memset(J,0,sizeof(mjob_t));

  if (MReqCreate(J,NULL,&J->Req[0],FALSE) == FAILURE)
    {
    DBG(0,fSIM) DPrint("ALERT:    cannot create job req\n");

    return(FAILURE);
    }

  MRMJobPreLoad(J,NULL,0);

  RQ[0]         = J->Req[0];

  RQ[0]->Index  = 0;

  J->StartCount = 0;
  J->R          = NULL;

  switch(*Version)
    {
    case 230:

      /*                Name NR TReq User Grop WClk Stat Clss QUT DST STT CMT netw Arch Opsy MemC RMem DskC RDsk Feat SQT TA TPN QO MO AC CM CC BP PU Part DPrc DMem DDisk DSwap STARTDATE ENDDATE MNODE RM HL RES RES1 RES2 RES3 OVERFLOW */

      rc = sscanf(Line,"%64s %d %64s %64s %64s %64s %64s %64s %lu %lu %lu %lu %64s %64s %64s %64s %64s %64s %64s %64s %lu %d %d %64s %1024s %64s %1024s %1024s %d %lf %64s %d %64s %64s %64s %lu %lu %1024s %64s %1024s %64s %64s %1024s %s %s",
           J->Name,
           &J->Request.NC,
           tmpTaskRequest,
           UName,
           GName,
           tmpSpecWCLimit,
           tmpState,
           tmpClass,
           &tmpQTime,
           &tmpDTime,
           &tmpSTime,
           &tmpCTime,
           tmpNetwork,
           tmpArch,
           tmpOpsys,
           tmpMemCmp,
           tmpRMemBuf,
           tmpDiskCmp,
           tmpRDiskBuf,
           tmpReqNFList,
           &tmpSQTime,             /* SystemQueueTime */
           &TasksAllocated,        /* allocated task count */
           &TPN,
           tmpQReq,
           tmpJFlags,
           AName,
           tmpCmd,
           tmpRMXString,           /* RM extension string */
           &J->Bypass,             /* Bypass          */
           &J->PSUtilized,         /* PSUtilized      */
           tmpParName,             /* partition used  */
           &RQ[0]->DRes.Procs,
           tmpDMemBuf,
           tmpDDiskBuf,
           tmpDSwapBuf,
           &tmpSDate,
           &tmpEDate,
           MHostName,
           tmpRMName,
           MReqHList,
           Reservation,
           SetString,              /* resource sets required by job */
           tmpASString,            /* application simulator name */
           tmpLine,                /* RES1 */
           tmpLine                 /* check for too many fields */
           );

      /* fail if all fields not read in */

      switch (rc)
        {
        case 43:

          strcpy(MHostName,NONE);

          J->RM = &MRM[0];

          break;

        case 44:

          /* canonical 230 trace */

          if (isdigit(tmpRMName[0]))
            J->RM = &MRM[(int)strtol(tmpRMName,NULL,0)];
          else
            J->RM = &MRM[0];

          break;

        default:

          DBG(1,fSIM) DPrint("ALERT:    version %d workload trace is corrupt '%s' (%d of %d fields read) ignoring line\n",
            *Version,
            Line,
            rc,
            44);

          MJobDestroy(&J);

          return(FAILURE);

          /*NOTREACHED*/

          break;
        }  /* END switch(rc) */

      RQ[0]->RequiredMemory = MURSpecToL(tmpRMemBuf,mvmMega,mvmMega);
      RQ[0]->RequiredDisk   = MURSpecToL(tmpRDiskBuf,mvmMega,mvmMega);

      RQ[0]->DRes.Mem       = MURSpecToL(tmpDMemBuf,mvmMega,mvmMega);
      RQ[0]->DRes.Swap      = MURSpecToL(tmpDSwapBuf,mvmMega,mvmMega);
      RQ[0]->DRes.Disk      = MURSpecToL(tmpDDiskBuf,mvmMega,mvmMega);

      if (Mode != msmProfile)
        {
        ptr  = NULL;
        ptr2 = NULL;

        if (strcmp(tmpASString,NONE))
          {
          if ((ptr = MUStrTok(tmpASString,":",&TokPtr)) != NULL)
            {
            ptr2 = MUStrTok(NULL,"|",&TokPtr);
            }
          }

        if (MASGetDriver((void **)&J->ASFunc,ptr,msdApplication) == SUCCESS)
          {
          (*J->ASFunc)(J,mascCreate,ptr2,NULL);
          }
        }    /* END if (Mode != msmProfile) */

      /* obtain job step number from LL based job name */

      /* FORMAT:  <FROM_HOST>.<CLUSTER>.<PROC> */

      MUStrCpy(tmpLine,J->Name,sizeof(tmpLine));

      if ((ptr = MUStrTok(tmpLine,".",&TokPtr)) != NULL)
        {
        MUStrCpy(J->SubmitHost,ptr,sizeof(J->SubmitHost));

        if ((ptr = MUStrTok(NULL,".",&TokPtr)) != NULL)
          {
          J->Cluster = (int)strtol(ptr,NULL,0);

          if ((ptr = MUStrTok(NULL,".",&TokPtr)) != NULL)
            {
            J->Proc = (int)strtol(ptr,NULL,0);
            }
          }
        }

      /* adjust job flags */

      if (Mode == msmProfile)
        {
        MUStrDup(&J->MasterHostName,MHostName);

        /* NOTE:  flags may be specified as string or number */

        if ((J->SpecFlags = strtol(tmpJFlags,NULL,0)) == 0)
          {
          MUBMFromString(tmpJFlags,MJobFlags,&J->SpecFlags);
          }
        }
      else
        {
        /* simulation mode */

        if ((MSim.Flags & (1 << msimfIgnMode)) ||
            (MSim.Flags & (1 << msimfIgnAll)))
          {
          J->SpecFlags = 0;
          }
        else
          {
          /* NOTE:  flags may be specified as string or number */

          if ((J->SpecFlags = strtol(tmpJFlags,NULL,0)) == 0)
            {
            MUBMFromString(tmpJFlags,MJobFlags,&J->SpecFlags);
            }

          if (J->SysFlags & (1 << mjfBackfill))
            J->SysFlags ^= (1 << mjfBackfill);

          if ((J->SpecFlags & (1 << mjfHostList)) &&
              (MSim.Flags & (1 << msimfIgnHostList)))
            {
            J->SpecFlags ^= (1 << mjfHostList);
            }
          }
        }    /* END else (Mode == msmProfile) */

      /* extract arbitrary job attributes */

      /* FORMAT:  JATTR:<ATTR>[=<VALUE>] */

      {
      char *ptr;
      char *TokPtr;

      ptr = MUStrTok(tmpJFlags,"[]",&TokPtr);

      while (ptr != NULL)
        {
        if (!strncmp(ptr,"JATTR:",strlen("JATTR:")))
          {
          MJobSetAttr(J,mjaGAttr,(void **)(ptr + strlen("JATTR:")),0,mSet);
          }

        ptr = MUStrTok(NULL,"[]",&TokPtr);
        }  /* END while (ptr != NULL) */
      }    /* END BLOCK */

      /* set default flags, remove set 'ignore' flags */

      J->SpecFlags |= MSim.TraceDefaultJobFlags;

      for (index = 0;index < M64.INTBITS;index++)
        {
        if (!(MSim.TraceIgnoreJobFlags & (1 << index)))
          continue;

        if (!(J->SpecFlags & (1 << index)))
          continue;

        J->SpecFlags ^= (1 << index);
        }  /* END for (index) */

      /* load task info */

      if (!strncmp(tmpTaskRequest,"PBS=",strlen("PBS=")))
        {
        char tmpLine[MAX_MLINE];

        tpbsa_t tmpA;
        short   TaskList[MAX_MTASK];

        memset(&tmpA,0,sizeof(tmpA));

        sprintf(tmpLine,"Resource_List,nodes,%s",
          &tmpTaskRequest[strlen("PBS=")]);

        MPBSJobSetAttr(J,NULL,tmpLine,&tmpA,TaskList,0);

        MPBSJobAdjustResources(J,&tmpA,J->RM);
        }
      else
        {
        ptr = MUStrTok(tmpTaskRequest,",",&TokPtr);
        tindex = 1;

        while (ptr != NULL)
          {
          if (strchr(ptr,'-') != NULL)
            {
            /* NOTE:  not handled */
            }
          else
            {
            RQ[0]->TaskRequestList[tindex] = atoi(ptr);
            tindex++;
            }

          ptr = MUStrTok(NULL,",",&TokPtr);
          }

        RQ[0]->TaskRequestList[tindex] = 0;
        RQ[0]->TaskRequestList[0]      = RQ[0]->TaskRequestList[1];

        RQ[0]->TaskCount    = RQ[0]->TaskRequestList[0];

        J->Request.TC   = RQ[0]->TaskRequestList[0];

        RQ[0]->TasksPerNode = MAX(0,TPN);

        if (MPar[0].JobNodeMatch & (1 << nmExactNodeMatch))
          {
          RQ[0]->NodeCount  = RQ[0]->TaskCount;
          J->Request.NC = RQ[0]->TaskCount;
          }

        if (MPar[0].JobNodeMatch & (1 << nmExactProcMatch))
          {
          if (RQ[0]->TasksPerNode >= 1)
            {
            RQ[0]->RequiredProcs = RQ[0]->TasksPerNode;
            RQ[0]->ProcCmp       = mcmpEQ;
            }

          if (RQ[0]->TasksPerNode > J->Request.TC)
            {
            RQ[0]->TasksPerNode = 0;
            }
          }
        }    /* END BLOCK */

      /* process WCLimit constraints */

      ptr = MUStrTok(tmpSpecWCLimit,",:",&TokPtr);
      tindex = 1;

      while (ptr != NULL)
        {
        if (strchr(ptr,'-') != NULL)
          {
          /* NOTE:  not handled */
          }
        else
          {
          J->SpecWCLimit[tindex] = strtol(ptr,NULL,0);

          tindex++;
          }

        ptr = MUStrTok(NULL,",:",&TokPtr);
        }  /* END while (ptr != NULL) */

      J->SpecWCLimit[tindex] = 0;
      J->SpecWCLimit[0]      = J->SpecWCLimit[1];

      J->SubmitTime     = tmpQTime;
      J->DispatchTime   = MAX(tmpDTime,tmpSTime);
      J->StartTime      = MAX(tmpDTime,tmpSTime);
      J->CompletionTime = tmpCTime;

      J->SystemQueueTime = tmpSQTime;

      J->SpecSMinTime   = tmpSDate;
      J->CMaxTime       = tmpEDate;

      /* determine required reservation */

      if (strcmp(Reservation,NONE) &&
          strcmp(Reservation,J->Name))
        {
        J->SpecFlags |= (1 << mjfAdvReservation);

        if (strcmp(Reservation,ALL) != 0)
          {
          strcpy(J->ResName,Reservation);
          }
        }

      /* determine job class */

      if ((MSim.Flags & (1 << msimfIgnClass)) ||
          (MSim.Flags & (1 << msimfIgnAll)))
        {
        mclass_t *C;

        MClassAdd("DEFAULT",&C);

        /* ignore specified classes */

        RQ[0]->DRes.PSlot[0].count = 1;
        RQ[0]->DRes.PSlot[C->Index].count = 1;
        }
      else
        {
        int cindex;

        MUNumListFromString(RQ[0]->DRes.PSlot,tmpClass,eClass);

        for (cindex = 1;cindex < MAX_MCLASS;cindex++)
          {
          if (RQ[0]->DRes.PSlot[cindex].count > 0)
            {
            MClassAdd(MAList[eClass][cindex],NULL);
            }
          }  /* END for (cindex) */
        }

      if (Mode != msmProfile)
        {
        if ((strcmp(MReqHList,NONE) != 0) &&
           !(MSim.Flags & (1 << msimfIgnHostList)) &&
           !(MSim.Flags & (1 << msimfIgnAll)))
          {
          J->SpecFlags |= (1 << mjfHostList);

          ptr = MUStrTok(MReqHList,":",&TokPtr);

          nindex = 0;

          if (J->ReqHList == NULL)
            J->ReqHList = (mnalloc_t *)calloc(1,sizeof(mnalloc_t) * (MAX_MNODE_PER_JOB + 1));

          J->ReqHList[0].N = NULL;

          while (ptr != NULL)
            {
            if (MNodeFind(ptr,&N) == FAILURE)
              {
              if (MSched.DefaultDomain[0] != '\0')
                {
                if ((tail = strchr(ptr,'.')) != NULL)
                  {
                  /* try short name */

                  MUStrCpy(MReqHList,ptr,MIN(sizeof(MReqHList),(tail - ptr + 1)));
                  }
                else
                  {
                  /* append default domain */

                  if (MSched.DefaultDomain[0] == '.')
                    {
                    sprintf(MReqHList,"%s%s",
                      ptr,
                      MSched.DefaultDomain);
                    }
                  else
                    {
                    sprintf(MReqHList,"%s.%s",
                      ptr,
                      MSched.DefaultDomain);
                    }
                  }

                if (MNodeFind(MReqHList,&N) != SUCCESS)
                  {
                  DBG(1,fUI) DPrint("ALERT:    cannot locate node '%s' for job '%s' hostlist\n",
                    ptr,
                    J->Name);

                  N = NULL;
                  }
                }
              else
                {
                DBG(1,fUI) DPrint("ALERT:    cannot locate node '%s' for job '%s' hostlist\n",
                  ptr,
                  J->Name);

                N = NULL;
                }
              }  /* END if (MNodeFind() == FAILURE) */

            if (N != NULL)
              {
              if (J->ReqHList[nindex].N == N)
                {
                J->ReqHList[nindex].TC++;
                }
              else
                {
                if (J->ReqHList[nindex].N != NULL)
                  nindex++;

                J->ReqHList[nindex].N = N;

                J->ReqHList[nindex].TC = 1;
                }
              }

            ptr = MUStrTok(NULL,":",&TokPtr);
            }    /* END while (ptr != NULL) */

          J->ReqHList[nindex + 1].N = NULL;
          }      /* END if (strcmp(MReqHList,NONE)) */
        else if ((J->SpecFlags & (1 << mjfHostList)) &&
                 (J->ReqHList == NULL))
          {
          DBG(1,fSIM) DPrint("ALERT:    job %s requests hostlist but has no hostlist specified\n",
            J->Name);

          J->SpecFlags ^= (1 << mjfHostList);
          }
        }    /* END if (MODE != msmProfile) */

      break;

    default:

      DBG(4,fSIM) DPrint("ALERT:    cannot load version %d workload trace record\n",
        *Version);

      MJobDestroy(&J);

      return(FAILURE);

      /*NOTREACHED*/

      break;
    }    /* END switch(*Version) */

  if (!strcmp(AName,NONE) ||
      !strcmp(AName,"0"))
    {
    AName[0] = '\0';
    }

  if ((strcmp(tmpRMXString,NONE) != 0) && (strcmp(tmpRMXString,"0") != 0))
    {
    MJobSetAttr(J,mjaRMXString,(void **)tmpRMXString,mdfString,0);
    }

  if (RQ[0]->DRes.Procs == 0)
    RQ[0]->DRes.Procs = 1;

  if (J->SpecWCLimit[0] == (unsigned long)-1)
    J->SpecWCLimit[0] = MAX_MTIME;

  MUStrDup(&J->E.Cmd,tmpCmd);

  if (Mode == msmSim)
    {
    J->State           = mjsIdle;
    J->EState          = mjsIdle;
    J->Bypass          = 0;
    J->PSUtilized      = 0.0;

    J->SystemQueueTime = J->SubmitTime;
    J->SimWCTime       = MAX(1,J->CompletionTime - J->StartTime);

    J->StartTime       = 0;
    J->DispatchTime    = 0;
    J->CompletionTime  = 0;

    J->WCLimit         = J->SpecWCLimit[0];
    }
  else
    {
    /* profile mode */

    int tmpI;

    tmpI = (int)strtol(tmpParName,NULL,0);

    if (tmpI > 0) 
      {
      RQ[0]->PtIndex = tmpI;
      }
    else
      {
      mpar_t *P;

      MParFind(tmpParName,&P);

      RQ[0]->PtIndex = P->Index;
      }

    J->TaskCount = TasksAllocated;

    J->PSDedicated = MJobGetProcCount(J) * (J->CompletionTime - J->StartTime);

    J->WCLimit = J->SpecWCLimit[0];

    for (index = 0;MJobState[index] != NULL;index++)
      {
      if (!strcmp(tmpState,MJobState[index]))
        {
        J->State  = index;
        J->EState = index;

        break;
        }
      }    /* END for (index) */
    }

  if (J->State == mjsNotRun)
    {
    DBG(3,fSIM) DPrint("ALERT:    ignoring job '%s' (job never ran, state '%s')\n",
      J->Name,
      MJobState[J->State]);

    MJobDestroy(&J);

    return(FAILURE);
    }

  /* check for timestamp corruption */

  if (Mode == msmProfile)
    {
    /* profiler mode */

    if (MSched.TraceFlags & (1 << tfFixCorruption))
      {
      if (J->StartTime < J->DispatchTime)
        {
        DBG(2,fSIM) DPrint("WARNING:  fixing job '%s' with corrupt dispatch/start times (%ld < %ld)\n",
          J->Name,
          J->DispatchTime,
          J->StartTime);

        J->DispatchTime = J->StartTime;
        }

      if (J->SubmitTime > J->StartTime)
        {
        DBG(2,fSIM) DPrint("WARNING:  fixing job '%s' with corrupt queue/start times (%ld > %ld)\n",
          J->Name,
          J->SubmitTime,
          J->StartTime);

        if (J->SystemQueueTime > 0)
          J->SubmitTime = MIN(J->StartTime,J->SystemQueueTime);
        else
          J->SubmitTime = J->StartTime;
        }

      if (J->SystemQueueTime > J->DispatchTime)
        {
        DBG(2,fSIM) DPrint("WARNING:  fixing job '%s' with corrupt system queue/dispatch times (%ld > %ld)\n",
          J->Name,
          J->SystemQueueTime,
          J->DispatchTime);

        J->SystemQueueTime = J->DispatchTime;
        }

      if (J->SystemQueueTime < J->SubmitTime)
        {
        DBG(2,fSIM) DPrint("WARNING:  fixing job '%s' with corrupt system queue/queue time (%ld < %ld)\n",
          J->Name,
          J->SystemQueueTime,
          J->SubmitTime);

        J->SystemQueueTime = J->SubmitTime;
        }
      }    /* END if (MSched.TraceFlags & (1 << tfFixCorruption)) */

    if ((J->SubmitTime > J->DispatchTime) ||
        (J->DispatchTime > J->CompletionTime))
      {
      DBG(1,fSIM) DPrint("ALERT:    ignoring job '%s' with corrupt queue/start/completion times (%ld > %ld > %ld)\n",
        J->Name,
        J->SubmitTime,
        J->DispatchTime,
        J->CompletionTime);

      MJobDestroy(&J);

      return(FAILURE);
      }
    }    /* END if (Mode != msmSim) */

  if (MJobSetCreds(J,UName,GName,AName) == FAILURE)
    {
    DBG(1,fSTRUCT) DPrint("ALERT:    ignoring job '%s' with invalid authentication info (%s:%s:%s)\n",
      J->Name,
      UName,
      GName,
      AName);

    MJobDestroy(&J);

    return(FAILURE);
    }

  /* determine network */

  if (strstr(tmpNetwork,MAList[eNetwork][0]) == NULL)
    {
    RQ[0]->Network = MUMAGetIndex(eNetwork,tmpNetwork,mAdd);
    }

  if (strstr(tmpOpsys,MAList[eOpsys][0]) == NULL)
    {
    if ((RQ[0]->Opsys = MUMAGetIndex(eOpsys,tmpOpsys,mAdd)) == FAILURE)
      {
      DBG(0,fSIM) DPrint("WARNING:  cannot add opsys '%s' for job '%s'\n",
        tmpOpsys,
        J->Name);
      }
    }

  if (strstr(tmpArch,MAList[eArch][0]) == NULL)
    {
    if ((RQ[0]->Arch = MUMAGetIndex(eArch,tmpArch,mAdd)) == FAILURE)
      {
      DBG(0,fSIM) DPrint("WARNING:  cannot add arch '%s' for job '%s'\n",
        tmpArch,
        J->Name);
      }
    }

  /* load feature values */

  if ((MSched.ProcSpeedFeatureHeader[0] != '\0') &&
      (MSched.ReferenceProcSpeed > 0))
    {
    sprintf(tmpLine,"[%s",
      MSched.ProcSpeedFeatureHeader);

    if ((ptr = strstr(tmpReqNFList,tmpLine)) != NULL)
      {
      ReqProcSpeed = strtol(ptr + strlen(tmpLine),NULL,0);

      J->SimWCTime *= (long)((double)ReqProcSpeed / MSched.ReferenceProcSpeed);
      }
    }

  if ((MSched.Mode != msmSim) || !(MSim.Flags & (1 << msimfIgnFeatures)))
    {
    if (!strstr(tmpReqNFList,MAList[eFeature][0]))
      {
      tok = MUStrTok(tmpReqNFList,"[]",&TokPtr);

      do
        {
        MUGetMAttr(eFeature,tok,mAdd,RQ[0]->ReqFBM,sizeof(RQ[0]->ReqFBM));
        }
      while ((tok = MUStrTok(NULL,"[]",&TokPtr)) != NULL);
      }
    }

  RQ[0]->MemCmp    = MUCmpFromString(tmpMemCmp,NULL);
  RQ[0]->DiskCmp   = MUCmpFromString(tmpDiskCmp,NULL);

  RQ[0]->NAccessPolicy = MSched.DefaultNAccessPolicy;

  RQ[0]->TaskCount = J->Request.TC;
  RQ[0]->NodeCount = J->Request.NC;

  MJobProcessExtensionString(J,J->RMXString);

  if ((MSim.Flags & (1 << msimfIgnQOS)))
    {
    tmpQReq[0] = '\0';
    }

  {
  char *ptr;
  char *TokPtr;

  ptr = MUStrTok(tmpQReq,":",&TokPtr);

  if ((ptr != NULL) &&
      (ptr[0] != '\0') &&
       strcmp(ptr,"-1") &&
       strcmp(ptr,"0") &&
       strcmp(ptr,NONE) &&
       strcmp(ptr,DEFAULT))
    {
    if (MQOSAdd(ptr,&J->QReq) == FAILURE)
      {
      /* cannot locate requested QOS */

      MQOSFind(DEFAULT,&J->QReq);
      }

    if (Mode == msmProfile)
      {
      if ((ptr = MUStrTok(NULL,":",&TokPtr)) != NULL)
        {
        MQOSAdd(ptr,&J->Cred.Q);
        }
      }
    }    /* END if ((ptr != NULL) && ...) */
  }      /* END BLOCK */

  if (Mode == msmSim)
    {
    if ((MQOSGetAccess(J,J->QReq,NULL,&QDef) == FAILURE) ||
        (J->QReq == NULL) ||
        (J->QReq == &MQOS[0]))
      {
      MJobSetQOS(J,QDef,0);
      }
    else
      {
      MJobSetQOS(J,J->QReq,0);
      }
    }    /* END if (Mode == msmSim) */

  if ((SetString[0] != '0') && (strcmp(SetString,NONE)))
    {
    /* FORMAT:  ONEOF,FEATURE[,X:Y:Z] */

    if ((ptr = MUStrTok(SetString,",: \t",&TokPtr)) != NULL)
      {
      /* determine selection type */

      RQ[0]->SetSelection = MUGetIndex(ptr,(const char **)MResSetSelectionType,0,mrssNONE);

      if ((ptr = MUStrTok(NULL,",: \t",&TokPtr)) != NULL)
        {
        /* determine set attribute */

        RQ[0]->SetType = MUGetIndex(ptr,(const char **)MResSetAttrType,0,mrstNONE);

        index = 0;

        if ((ptr = MUStrTok(NULL,", \t",&TokPtr)) != NULL)
          {
          /* determine set list */

          while (ptr != NULL)
            {
            MUStrDup(&RQ[0]->SetList[index],ptr);

            index++;

            ptr = MUStrTok(NULL,", \t",&TokPtr);
            }
          }

        RQ[0]->SetList[index] = NULL;
        }  /* END if ((ptr = MUStrTok(NULL)) != NULL) */
      }    /* END if ((ptr = MUStrTok(SetString)) != NULL) */
    }      /* END if ((SetString[0] != '0') && (strcmp(SetString,NONE))) */

  if (MJobEval(J) == FAILURE)
    {
    /* job not properly formed */

    DBG(1,fSTRUCT) DPrint("ALERT:    ignoring job '%s' with corrupt configuration\n",
      J->Name);

    MJobDestroy(&J);

    return(FAILURE);
    }

  DBG(6,fSIM) DPrint("INFO:     job '%s' loaded.  class: %s  opsys: %s  arch: %s\n",
    J->Name,
    MUCAListToString(RQ[0]->DRes.PSlot,NULL,NULL),
    MAList[eOpsys][RQ[0]->Opsys],
    MAList[eArch][RQ[0]->Arch]);

  return(SUCCESS);
  }  /* END MTraceLoadWorkload() */
示例#2
0
int MTraceLoadComputeNode(

  char    *NodeLine,  /* I */
  mnode_t *N,         /* O */
  int      Version)   /* I */

  {
  char *tok;

  char *TokPtr;

  char   tmpLine[MAX_MLINE];
  char   tmpNLine[MAX_MLINE];

  char   ResourceType[MAX_MNAME];
  char   EventType[MAX_MNAME];
  long   ETime;

  char   Name[MAX_MNAME];
  char   OpsysString[MAX_MNAME];
  char   ArchString[MAX_MNAME];
  char   FeatureString[MAX_MLINE];
  char   ClassString[MAX_MLINE];
  char   NetworkString[MAX_MLINE];
  char   GResString[MAX_MLINE];

  char   tmpSwapBuf[MAX_MNAME];
  char   tmpMemBuf[MAX_MNAME];
  char   tmpDiskBuf[MAX_MNAME];

  int    SlotsUsed;

  char   RMName[MAX_MNAME];

  int    FIndex;
  int    SIndex;
  int    cindex;

  int    rc;

  /* set default resource attributes */

  memset(N,0,sizeof(mnode_t));

  N->Load    = 0.0;
  N->Speed   = 1.0;

  N->PtIndex = 0;

  switch(Version)
    {
    case 230:

      if (strchr(NodeLine,';') != NULL)
        {
        sprintf(tmpNLine,"IFS-;%.*s",
          MAX_MLINE,
          NodeLine);
        }
      else
        {
        MUStrCpy(tmpNLine,NodeLine,sizeof(tmpNLine));
        }

      /* FORMAT:  <RESOURCETYPE> <EVENTTYPE> <EVENTTIME> <NAME> <RMINDEX> <SWAP> <MEMORY> <DISK> <MAXPROCS> <SLOTSUSED> <FRAMEINDEX> <SLOTINDEX> <OPSYS> <ARCH> [<FEATURE>]* [<CLASS>]* [<NETWORK>]* [<GRES>]* <RES1> <RES2> <RES3> */

      rc = MUSScanF(tmpNLine,"%x%s %x%s %ld %x%s %x%s %x%s %x%s %x%s %d %d %d %d %x%s %x%s %x%s %x%s %x%s %x%s %x%s %x%s %x%s %x%s",
         MAX_MNAME,
         ResourceType,
         MAX_MNAME,
         EventType,
         &ETime,
         MAX_MNAME,
         Name,
         MAX_MNAME,
         RMName,
         MAX_MNAME,
         tmpSwapBuf,
         MAX_MNAME,
         tmpMemBuf,
         MAX_MNAME,
         tmpDiskBuf,
         &N->CRes.Procs, 
         &FIndex,
         &SIndex,
         &SlotsUsed,
         MAX_MNAME,
         OpsysString,
         MAX_MNAME,
         ArchString,
         MAX_MLINE,
         FeatureString,
         MAX_MLINE,
         ClassString,
         MAX_MLINE,
         NetworkString,
         MAX_MLINE,
         GResString,
         MAX_MLINE,
         tmpLine,            /* RES1 */
         MAX_MLINE,
         tmpLine,            /* RES2 */
         MAX_MLINE,
         tmpLine,            /* RES3 */
         MAX_MLINE,
         tmpLine             /* check for too many lines */
         );

      if ((rc == EOF) || (rc != 21))
        {
        DBG(3,fSIM) DPrint("ALERT:    resource tracefile corruption (%d of %d fields detected) on line '%s'\n",
          rc,
          21,
          NodeLine);

        return(FAILURE);
        }

      /* process node attributes */

      N->CRes.Swap = MURSpecToL(tmpSwapBuf,mvmMega,mvmMega);
      N->CRes.Mem  = MURSpecToL(tmpMemBuf,mvmMega,mvmMega);
      N->CRes.Disk = MURSpecToL(tmpDiskBuf,mvmMega,mvmMega);

      if (!strcmp(RMName,NONE))
        MRMAdd(RMName,&N->RM);
      else
        MRMAdd(DEFAULT,&N->RM);

      /* load Opsys */

      if (strstr(OpsysString,MAList[eOpsys][0]) == NULL)
        N->ActiveOS = MUMAGetIndex(eOpsys,OpsysString,mAdd);

      /* load Arch */

      if (strstr(ArchString,MAList[eArch][0]) == NULL)
        N->Arch = MUMAGetIndex(eArch,ArchString,mAdd);

      memcpy(&N->ARes,&N->CRes,sizeof(N->ARes));

      strcpy(N->Name,MNodeAdjustName(Name,0));

      /* load classes */

      if (MSim.Flags & ((1 << msimfIgnClass) | (1 << msimfIgnAll)))
        {
        mclass_t *C;

        /* ignore specified classes */

        MClassAdd("DEFAULT",&C);

        N->CRes.PSlot[0].count = N->CRes.Procs;
        N->CRes.PSlot[C->Index].count = N->CRes.Procs;
        }
      else
        {
        MUNumListFromString(N->CRes.PSlot,ClassString,eClass);

        for (cindex = 1;cindex < MAX_MCLASS;cindex++)
          {
          if (N->CRes.PSlot[cindex].count > 0)
            MClassAdd(MAList[eClass][cindex],NULL);
          }
        }

      memcpy(N->ARes.PSlot,N->CRes.PSlot,sizeof(N->ARes.PSlot));

      break;

    default:

      DBG(4,fSIM) DPrint("ALERT:    cannot load version %d resource trace record\n",
        Version);

      return(FAILURE);

      /*NOTREACHED*/

      break;
    }  /* END switch(Version) */

  if ((MSim.Flags & ((1 << msimfIgnFrame) | (1 << msimfIgnAll))) || 
      (FIndex < 0))
    {
    N->FrameIndex = -1;
    N->SlotIndex  = -1;
    }
  else
    {
    MFrameAddNode(&MFrame[FIndex],N,SIndex);
      
    if ((N->FrameIndex > 0) && (N->FrameIndex < MAX_MFRAME) &&
        (N->SlotIndex > 0)  && (N->SlotIndex <= MAX_MSLOTPERFRAME))
      {
      mhost_t *S;
      int      nindex;
  
      S = &MSys[N->FrameIndex][N->SlotIndex];

      S->SlotsUsed = SlotsUsed;

      for (nindex = 0;nindex < MAX_MNETTYPE;nindex++)
        strcpy(S->NetName[nindex],N->Name);

      if (!strstr(ClassString,"NONE"))
        S->Attributes |= (1 << attrBatch);

      S->MTime = MSched.Time;
      }  /* END if ((N->FrameIndex > 0) ... ) */
    }    /* END else if (MSim.Flags & ((1 << msimfIgnFrame) | ...)) */

  /* initialize statistics */

  N->STTime = 0;
  N->SUTime = 0;
  N->SATime = 0;

  /* load state */

  if (N->CRes.Procs <= 0)
    {
    N->State = mnsNone;
    }
  else
    {
    if (!strcmp(EventType,"AVAILABLE"))
      N->State = mnsIdle;
    else if (!strcmp(EventType,"DEFINED"))
      N->State = mnsDown;
    else if (!strcmp(EventType,"DRAINED"))
      N->State = mnsDrained;
    else
      N->State = mnsNONE;
    }  /* END else (N->CRes.Procs <= 0) */

  N->EState = N->State;

  memcpy(&N->ARes,&N->CRes,sizeof(N->ARes));

  /* load features */

  if (strstr(FeatureString,MAList[eFeature][0]) == NULL)
    {
    tok = MUStrTok(FeatureString,"[]",&TokPtr);

    do
      {
      MNodeProcessFeature(N,tok);

      DBG(6,fSIM) DPrint("INFO:     feature '%s' added (%s)\n",
        tok,
        MUMAList(eFeature,N->FBM,sizeof(N->FBM)));
      }
    while ((tok = MUStrTok(NULL,"[]",&TokPtr)) != NULL);
    }

  /* load network adapters */

  if (strstr(NetworkString,MAList[eNetwork][0]) == NULL)
    {
    tok = MUStrTok(NetworkString,"[]",&TokPtr);

    do
      {
      N->Network |= MUMAGetBM(eNetwork,tok,mAdd);

      DBG(6,fSIM) DPrint("INFO:     network '%s' added (%s)\n",
        tok,
        MUListAttrs(eNetwork,N->Network));
      }
    while ((tok = MUStrTok(NULL,"[]",&TokPtr)) != NULL);
    }

  /* load generic resources */

  if (!strcmp(GResString,NONE) != 0)
    {
    MUNumListFromString(N->CRes.GRes,GResString,eGRes);
    }

  DBG(4,fSIM) DPrint("INFO:     node '%s' F:%d/S:%d  %06d %04d %06d %02d %02d %10s %10s %20s %20s\n",
    N->Name,
    N->FrameIndex,
    N->SlotIndex,
    N->CRes.Swap,
    N->CRes.Mem,
    N->CRes.Disk,
    N->CRes.Procs,
    SlotsUsed,
    OpsysString,
    ArchString,
    FeatureString,
    MUCAListToString(N->CRes.PSlot,NULL,NULL));

  return(SUCCESS);
  }  /* END MTraceLoadComputeNode() */
示例#3
0
文件: MVMCRXML.c 项目: dhh1128/cbase
int MVMCRFromXML(

  mvm_req_create_t *VMCR, /* I (modified) */
  mxml_t           *E)    /* I */

  {
  int aindex;

  if ((VMCR == NULL) || (E == NULL))
    {
    return(FAILURE);
    }

  for (aindex = 0;aindex < E->ACount;aindex++)
    {
    if (!strcmp("ID",E->AName[aindex]))
      {
      MUStrCpy(VMCR->VMID,E->AVal[aindex],sizeof(VMCR->VMID));
      }
    else if (!strcmp("VARS",E->AName[aindex]))
      {
      MUStrCpy(VMCR->Vars,E->AVal[aindex],sizeof(VMCR->Vars));
      }
    else if (!strcmp("STORAGE",E->AName[aindex]))
      {
      MUStrCpy(VMCR->Storage,E->AVal[aindex],sizeof(VMCR->Storage));
      }
    else if (!strcmp("ALIAS",E->AName[aindex]))
      {
      MUStrCpy(VMCR->Aliases,E->AVal[aindex],sizeof(VMCR->Aliases));
      }
    else if (!strcmp("TRIGGER",E->AName[aindex]))
      {
      MUStrCpy(VMCR->Triggers,E->AVal[aindex],sizeof(VMCR->Triggers));
      }
    else if (!strcmp("HYPERVISOR",E->AName[aindex]))
      {
      /* Find node for hypervisor */

      MNodeFind(E->AVal[aindex],&VMCR->N);
      }
    else if (!strcmp("TEMPLATE",E->AName[aindex]))
      {
      MJobFind(E->AVal[aindex],&VMCR->JT,mjsmExtended);
      }
    else if (!strcmp("OWNERJOB",E->AName[aindex]))
      {
      MJobFind(E->AVal[aindex],&VMCR->OwnerJob,mjsmExtended);
      }
    else if (!strcmp("IMAGE",E->AName[aindex]))
      {
      VMCR->OSIndex = MUMAGetIndex(meOpsys,E->AVal[aindex],mAdd);
      }
    else if (!strcmp("WALLTIME",E->AName[aindex]))
      {
      VMCR->Walltime = strtol(E->AVal[aindex],NULL,10);
      }
    else if (!strcmp("SOVEREIGN",E->AName[aindex]))
      {
      VMCR->IsSovereign = MUBoolFromString(E->AName[aindex],FALSE);
      }
    else if (!strcmp("ISONETIMEUSE",E->AName[aindex]))
      {
      VMCR->IsOneTimeUse = MUBoolFromString(E->AName[aindex],FALSE);
      }
    else if (!strcmp("DISK",E->AName[aindex]))
      {
      VMCR->CRes.Disk = (int)strtol(E->AVal[aindex],NULL,10);
      }
    else if (!strcmp("MEM",E->AName[aindex]))
      {
      VMCR->CRes.Mem = (int)strtol(E->AVal[aindex],NULL,10);
      }
    else if (!strcmp("PROCS",E->AName[aindex]))
      {
      VMCR->CRes.Procs = (int)strtol(E->AVal[aindex],NULL,10);
      }
    else if (!strcmp("TRACKINGJ",E->AName[aindex]))
      {
      MUStrCpy(VMCR->TrackingJ,E->AVal[aindex],sizeof(VMCR->TrackingJ));
      }
    }  /* END for (aindex = 0;aindex < E->ACount;aindex++) */
    
  return(SUCCESS);
  } /* END MVMCRFromXML() */
示例#4
0
文件: MLocal.c 项目: dhh1128/cbase
int MDISAGetRsvCost(

  mrsv_t *R,
  mulong  StartTime,
  int     DayCount,
  double *Cost)       /* NOT INITIALIZED HERE!!! */

  {

  long DayStart;
  long DayEnd;

  int hindex;
  int dindex;

  int RsvStartMonth;
  int RsvEndMonth;
  int Month;

  int Days;

  int SAN;

  mhistory_t *History;

  long NextHistoryStart;

  enum DISAVMSizeEnum {
    disa1proc1gb,
    disa1proc2gb,
    disa1proc3gb,
    disa1proc4gb,
    disa2proc2gb,
    disa2proc3gb,
    disa2proc4gb,
    disa4proc4gb,
    disa4proc8gb,
    disaSAN,
    disaLAST };

  enum DISAVMSizeEnum DSize;

  const char *DISAVMSize[] = {
    "1 Proc 1GB",
    "1 Proc 2GB",
    "1 Proc 3GB",
    "1 Proc 4GB",
    "2 Proc 2GB",
    "2 Proc 3GB",
    "2 Proc 4GB",
    "4 Proc 4GB",
    "4 Proc 8GB",
    "SAN",
    NULL };

  double DISASizeCost[disaLAST] = {500.0, 862.0, 1293.0, 1724.0, 1000.0, 1293.0, 1724.0, 2000.0, 3448.0,2.82};

  MDB(5,fSCHED) MLog("INFO:     DISA2 charging rsv '%s' starting at %ld for %d days\n",
    R->Name,
    StartTime,
    DayCount);

  SAN = MUMAGetIndex(meGRes,"SAN",mVerify);

  MUTimeGetDay(R->StartTime,&RsvStartMonth,NULL);
  MUTimeGetDay(R->EndTime,&RsvEndMonth,NULL);

  /* for each day we are charging find out the size of the reservation on that day and
     what the daily charge should be */

  hindex = 0;

  if (R->History == NULL)
    {
    return(FAILURE);
    }

  History = (mhistory_t *)MUArrayListGet(R->History,hindex++);

  if (hindex < R->History->NumItems)
    {
    mhistory_t *tmpH = (mhistory_t *)MUArrayListGet(R->History,hindex);

    NextHistoryStart = tmpH->Time;
    }   /* END if (R->History->NumItems >= hindex) */
  else
    {
    NextHistoryStart = MMAX_TIME;
    }

  for (dindex = 0;dindex < DayCount;dindex++)
    {
    /* get boundaries of the day */

    MUGetPeriodRange(StartTime + (dindex * MCONST_DAYLEN),0,0,mpDay,&DayStart,&DayEnd,NULL);

    /* MUGetPeriodRange() returns exactly midnight for DayEnd, which is technically the next
       day, so subtract one second and use that */

    DayEnd--;

    MDB(5,fSCHED) MLog("INFO:     DISA2 evaluating rsv '%s' on day ending '%ld'\n",
      R->Name,
      DayEnd);

    /* find history of the rsv on that day */

    while (DayEnd > NextHistoryStart)
      {
      /* loop until the end of the day we are looking fits in the reservation
         history */

      History = (mhistory_t *)MUArrayListGet(R->History,hindex++);
     
      if (hindex < R->History->NumItems)
        {
        mhistory_t *tmpH = (mhistory_t *)MUArrayListGet(R->History,hindex);
     
        NextHistoryStart = tmpH->Time;
        }   /* END if (R->History->NumItems >= hindex) */
      else
        {
        NextHistoryStart = MMAX_TIME;
        }
      }    /* END while (DayEnd > NextHistoryStart) */

    MDB(5,fSCHED) MLog("INFO:     DISA2 using history from rsv '%s' that ends before %ld\n",
      R->Name,
      NextHistoryStart);

    /* get reservation size category based off of history */

    DSize = disa1proc1gb;

    switch (History->Res.Procs)
      {
      default:
      case 1:
      
        if (History->Res.Mem < 1500)
          {
          DSize = disa1proc1gb;
          }
        else if ((History->Res.Mem >= 1500) && (History->Res.Mem < 2500))
          {
          DSize = disa1proc2gb;
          }
        else if ((History->Res.Mem >=2500) && (History->Res.Mem < 3500))
          {
          DSize = disa1proc3gb;
          }
        else
          {
          DSize = disa1proc4gb;
          }

        break;
   
      case 2:
   
        if (History->Res.Mem < 2500)
          {
          DSize = disa2proc2gb;
          }
        else if ((History->Res.Mem >= 2500) && (History->Res.Mem < 3500))
          {
          DSize = disa2proc3gb;
          }
        else
          {
          DSize = disa2proc4gb;
          }

        break;
 
      case 4:
   
        if (History->Res.Mem < 4500)
          {
          DSize = disa4proc4gb;
          }
        else
          {
          DSize = disa4proc8gb;
          }

        break;

      case 0:

        if (MSNLGetIndexCount(&History->Res.GenericRes,SAN) > 0)
          {
          DSize = disaSAN;
          }

        break;
      }  /* END switch (R->AllocPC) */

    MDB(5,fSCHED) MLog("INFO:     DISA2 rsv '%s' was size '%s' before %ld\n",
      R->Name,
      DISAVMSize[DSize],
      NextHistoryStart);

    MUTimeGetDay(DayEnd,&Month,NULL);

    if ((Month != RsvStartMonth) &&
        (Month != RsvEndMonth))
      {
      /* month is unique so we will charge based Months Days */

      Days = MUGetNumDaysInMonth(DayEnd);
      }
    else
      {
      Days = MUGetNumDaysInMonth(R->StartTime);
      }

    if (DSize == disaSAN)
      {
      /* daily cost of SAN is per gigabyte */

      /* find number of vm rsvs and subtract 60 for each one */
      int TotalSAN = MAX(0,MSNLGetIndexCount(&History->Res.GenericRes,SAN) - (History->ElementCount * 60));

      MDB(5,fSCHED) MLog("INFO:     DISA2 rsv '%s' on %ld using month days %d (day cost '%.04f')\n",
        R->Name,
        NextHistoryStart,
        Days,
        DISASizeCost[DSize] * TotalSAN);

      *Cost += (DISASizeCost[DSize] * TotalSAN) / Days;
      }
    else
      {
      MDB(5,fSCHED) MLog("INFO:     DISA2 rsv '%s' on %ld using month days %d (day cost '%.04f')\n",
        R->Name,
        NextHistoryStart,
        Days,
        DISASizeCost[DSize] / Days);


      *Cost += DISASizeCost[DSize] / Days;
      }
    }    /* END for (dindex) */

  return(SUCCESS);
  }  /* END MDISAGetRsvCost() */
示例#5
0
int MVMSetAttr(

  mvm_t                  *VM,      /* I * (modified) */
  enum MVMAttrEnum        AIndex, /* I */
  void const             *Value,  /* I */
  enum MDataFormatEnum    Format, /* I */
  enum MObjectSetModeEnum Mode)   /* I */

  {
  const char *FName = "MVMSetAttr";

  char const *ValAsString = (char const *)Value;

  MDB(6,fSTRUCT) MLog("%s(%s,%s,Value,%s,%s)\n",
    FName,
    (VM != NULL) ? VM->VMID : "NULL",
    MVMAttr[AIndex],
    MFormatMode[Format],
    MObjOpType[Mode]);

  if (VM == NULL)
    {
    return(FAILURE);
    }

  switch (AIndex)
    {
    case mvmaActiveOS:

      {
      int OS = MUMAGetIndex(meOpsys,ValAsString,mSet);

      if (OS != 0)
        VM->ActiveOS = OS;

      /*TODO: what if OS is not in VM's OSList? */
      }

      break;

    case mvmaADisk:

      VM->ARes.Disk = strtol(ValAsString,NULL,0);

      break;

    case mvmaAlias:

      {
      if (Mode != mClear)
        {
        mvoid_t *Element;

        if (MUHTGet(&MNetworkAliasesHT,ValAsString,NULL,NULL) == SUCCESS)
          {
          /* Specified alias is already in use.  Do not allow */

          return(FAILURE);
          }

        /* Add to table now */
        /* Done as mvoid_t so that node aliases work as well */

        Element = (mvoid_t *)MUCalloc(1,sizeof(mvoid_t));
        Element->Ptr = (void *)VM;
        Element->PtrType = mxoxVM;
        MUStrCpy(Element->Name,VM->VMID,sizeof(Element->Name));

        MUHTAdd(&MNetworkAliasesHT,ValAsString,(void *)Element,NULL,MUFREE);
        }

      if ((Mode == mSet) || (Mode == mClear))
        {
        /* Clear list, remove from global table */

        mln_t *freePtr = NULL;

        while (MULLIterate(VM->Aliases,&freePtr) == SUCCESS)
          {
          MUHTRemove(&MNetworkAliasesHT,freePtr->Name,MUFREE);
          }

        /* TODO: send out signal to outside system to free alias */

        MULLFree(&VM->Aliases,MUFREE);
        }

      if ((Mode == mSet) || (Mode == mAdd))
        {
        /* Set has already been cleared, treat as add */
        /* These must be added one at a time */

        if (VM->Aliases == NULL)
          {
          MULLCreate(&VM->Aliases);
          }

        if (MULLAdd(&VM->Aliases,ValAsString,NULL,NULL,MUFREE) == FAILURE)
          return(FAILURE);

        /* TODO: send out signal to outside system to set alias */
        }
      } /* END BLOCK mvmaAlias */

      break;

    case mvmaAMem:

      VM->ARes.Mem = strtol(ValAsString,NULL,0);

      break;

    case mvmaAProcs:

      /* NOTE:  set ARes.Procs to 0 if VM is not available */

      if (MNSISUP(VM->State) && (VM->State != mnsUnknown))
        {
        VM->ARes.Procs = strtol(ValAsString,NULL,0);
        }
      else
        {
        VM->ARes.Procs = 0;
        }

      break;

    case mvmaCDisk:

      VM->CRes.Disk = strtol(ValAsString,NULL,0);

      break;

    case mvmaCMem:

      VM->CRes.Mem = strtol(ValAsString,NULL,0);

      break;

    case mvmaCProcs:

      VM->CRes.Procs = strtol(ValAsString,NULL,0);

      break;

    case mvmaCPULoad:

      VM->CPULoad = strtod(ValAsString,NULL);

      break;

    case mvmaDescription:

      MUStrDup(&VM->Description,ValAsString);

      break;

    case mvmaEffectiveTTL:

      VM->EffectiveTTL = strtol(ValAsString,NULL,10);

      break;

    case mvmaFlags:

      bmfromstring((char *)Value,MVMFlags,&VM->Flags);

      break;

    case mvmaGMetric:

      {
      char *GMTok;
      char *GMName;
      char *GMVal;
      char *TokPtr = NULL;

      char *TokPtr2 = NULL;

      int   gmindex;

      /* generic metrics */

      /* FORMAT:  <GMETRIC>{:=}<VAL>[,<GMETRIC>{:=}<VAL>]... */

      GMTok = MUStrTok((char *)Value,", \t\n",&TokPtr);

      while (GMTok != NULL)
        {
        GMName = MUStrTok(GMTok,"=:",&TokPtr2);
        GMVal  = MUStrTok(NULL,"=:",&TokPtr2);

        GMTok = MUStrTok(NULL,", \t\n",&TokPtr);

        if ((GMName == NULL) || (GMVal == NULL))
          {
          /* mal-formed value, ignore */

          continue;
          }

        gmindex = MUMAGetIndex(meGMetrics,GMName,mAdd);

        if ((gmindex <= 0) || (gmindex >= MSched.M[mxoxGMetric]))
          continue;

        /* valid gmetric located */

        MVMSetGMetric(VM,gmindex,GMVal);
        }  /* END while (GMTok != NULL) */
      }    /* END BLOCK (case mvmaGMetric) */

      break;


    case mvmaID:

      MUStrCpy(VM->VMID,ValAsString,sizeof(VM->VMID));

      break;

    case mvmaLastMigrateTime:

      VM->LastMigrationTime = (mulong)strtol(ValAsString,NULL,10);

      break;

    case mvmaLastSubState:

      MUStrDup(&VM->LastSubState,ValAsString);

      break;

    case mvmaLastSubStateMTime:

      VM->LastSubStateMTime = (mulong)strtol(ValAsString,NULL,10);

      break;

    case mvmaMigrateCount:

      VM->MigrationCount = (int)strtol(ValAsString,NULL,10);

      break;

    case mvmaNextOS:

      {
      int OS = MUMAGetIndex(meOpsys,ValAsString,mSet);

      if (OS != 0)
        VM->NextOS = OS;

      /*TODO: what if OS is not in VM's OSList? */
      }

    case mvmaNodeTemplate:
    case mvmaOSList:
    case mvmaSlotIndex:
    case mvmaState:

      break;

    case mvmaSovereign:

      {
      mbool_t WasSovereign = bmisset(&VM->Flags,mvmfSovereign);
      mbool_t NewVal = MUBoolFromString(ValAsString,FALSE);

      if (NewVal == TRUE)
        bmset(&VM->Flags,mvmfSovereign);
      else
        bmunset(&VM->Flags,mvmfSovereign);

      if ((!bmisset(&VM->Flags,mvmfSovereign)) && (WasSovereign == TRUE))
        {
        if (VM->J != NULL)
          {
          /* is this how to handle previously sovereign VMs correctly? */

          bmset(&VM->J->IFlags,mjifCancel);
          }
        }
      }

      break;

    case mvmaSpecifiedTTL:

      VM->SpecifiedTTL = strtol(ValAsString,NULL,10);

      break;

    case mvmaStartTime:

      VM->StartTime = (mulong)strtol(ValAsString,NULL,10);

      break;

    case mvmaSubState:

      if (ValAsString == NULL)
        {
        MUFree(&VM->SubState);
        }
      else
        {
        MUStrDup(&VM->SubState,(char *)ValAsString);
        }

      break;

    case mvmaStorageRsvNames:

      MUStrDup(&VM->StorageRsvNames,(char *)ValAsString);

      break;

    case mvmaVariables:

      if (Mode == mSet)
        {
        /* Clear the current attrs */

        MUHTClear(&VM->Variables,TRUE,(mfree_t)MUFree);
        }

      /* FORMAT:  attr:value[+attr:value]... */
      /*     value is a string (alphanumeric and '_') */

      if ((Mode == mAdd) || (Mode == mSet))
        {
        char *ptr;
        char *TokPtr = NULL;

        char *TokPtr2 = NULL;

        ptr = MUStrTok((char *)ValAsString,"+",&TokPtr);

        while (ptr != NULL)
          {
          char *AName;
          char *AVal;
          char *MallocVal = NULL;
          char ANameNoQuotes[MMAX_LINE];

          AName = MUStrTok(ptr,":",&TokPtr2);
          AVal = MUStrTok(NULL,":",&TokPtr2);

          MUStrReplaceStr(AName,"\"","",ANameNoQuotes,sizeof(ANameNoQuotes));

          if (AVal != NULL)
            {
            int AValLen = (strlen(AVal) * sizeof(char)) + 1;
            MallocVal = (char *)MUMalloc(AValLen);
            MUStrReplaceStr(AVal,"\"","",MallocVal,strlen(AVal) + 1);
            }

          MUHTAdd(&VM->Variables,ANameNoQuotes,(void *)MallocVal,NULL,MUFREE);

          ptr = MUStrTok(NULL,"+",&TokPtr);
          } /* END while (ptr != NULL) */
        } /* END if ((Mode == mAdd) || (Mode == mSet)) */

      break;

    case mvmaTrigger:

      if (Format == mdfString)
        {
        mtrig_t *T;

        marray_t TList;

        int tindex;

        MUArrayListCreate(&TList,sizeof(mtrig_t *),10);

        if (MTrigLoadString(
              &VM->T,
              (char *)Value,
              TRUE,
              FALSE,
              mxoxVM,
              VM->VMID,
              &TList,
              NULL) == FAILURE)
          {
          return(FAILURE);
          }

        for (tindex = 0; tindex < TList.NumItems;tindex++)
          {
          T = (mtrig_t *)MUArrayListGetPtr(&TList,tindex);

          if (MTrigIsValid(T) == FALSE)
            continue;

          MTrigInitialize(T);

          MOAddTrigPtr(&VM->T,T);
          } /* END for (tindex) */

        return(SUCCESS);
        } /* END if (Format == mdfString) */

      /* END BLOCK mvmaTrigger */

      break;

    case mvmaNONE:
    case mvmaLAST:
    default:

      break;
    }  /* END switch (AIndex) */

  return(SUCCESS);
  } /* END MVMSetAttr() */
示例#6
0
文件: MRM_XML.c 项目: dhh1128/cbase
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() */