示例#1
0
文件: job.py 项目: nasiaa/apel
    def _check_factor(self, sfu, sf):
        '''
        Check for the validity of the ScalingFactorUnit and ScalingFactor fields.
        We accept neither field included or both.  If only one of the fields is 
        included, it doesn't really make sense so we reject it.
    
        We expect that all null values have been converted to the string 'None'.
        '''
        if sf == 'None':
            if sfu != 'None':
                raise InvalidRecordException(
                    'Unit but not value supplied for ScalingFactor.')
            else:
                sfu = 'custom'
                sf = 1
        else:  # sf is present
            if sfu == 'None':
                raise InvalidRecordException(
                    'Unit but not value supplied for ScalingFactor.')
            else:
                if sfu.lower() not in self._valid_slts:
                    raise InvalidRecordException('ScalingFactorUnit ' + sfu +
                                                 ' not valid.')

        return (sfu, sf)
示例#2
0
    def _check_start_end_times(self):
        '''Checks the values of StartTime and EndTime in _record_content.
        StartTime should be less than or equal to EndTime.
        Neither StartTime or EndTime should be zero.
        EndTime should not be in the future.
        
        This is merely factored out for simplicity.
        '''
        try:
            start = int(self._record_content['StartTime'])
            end = int(self._record_content['EndTime'])
            if end < start:
                raise InvalidRecordException("EndTime is before StartTime.")

            if start == 0 or end == 0:
                raise InvalidRecordException(
                    "Epoch times StartTime and EndTime mustn't be 0.")

            now = datetime.now()
            # add two days to prevent timezone problems
            tomorrow = now + timedelta(2)
            if datetime.fromtimestamp(end) > tomorrow:
                raise InvalidRecordException("Epoch time " + str(end) +
                                             " is in the future.")

        except ValueError:
            raise InvalidRecordException(
                "Cannot parse an integer from StartTime or EndTime.")
示例#3
0
    def _check_factor(self, sfu, sf):
        '''
        Check for the validity of the ScalingFactorUnit and ScalingFactor fields.
        We accept neither field included or both.  If only one of the fields is 
        included, it doesn't really make sense so we reject it.

        We expect that:
        - as ServiceLevel is a float field,
          a null ScalingFactor is passed in as the null object None.
        - as ServiceLevelType is a msg field,
          a null ScalingFactorUnit is passed in as the string 'None'.
        '''
        if sf is None:
            if sfu != 'None':
                raise InvalidRecordException(
                    'Unit but not value supplied for ScalingFactor.')
            else:
                sfu = 'custom'
                sf = 1
        else:  # sf is present
            if sfu == 'None':
                raise InvalidRecordException(
                    'Unit but not value supplied for ScalingFactor.')
            else:
                if sfu.lower() not in self._valid_slts:
                    raise InvalidRecordException('ScalingFactorUnit ' + sfu +
                                                 ' not valid.')

        return (sfu, sf)
示例#4
0
 def _check_fields(self):
     '''
     Add extra checks to the ones in the parent class.
     '''
     
     # Call the parent's checks first.
     Record._check_fields(self)
     
     # shorthand 
     rc = self._record_content
     
     month_start = None
     month_end = None
     # For storing the month and year for the subsequent month.
     next_month_year = None
     next_month = None
     
     try:
         # A bit convoluted for finding the first second in the next month.
         if (int(rc['Month']) == 12):
             next_month_year = int(rc['Year']) + 1
             next_month = 1
         else:
             next_month_year = int(rc['Year'])
             next_month = int(rc['Month']) + 1
         
         month_start = datetime(int(rc['Year']), int(rc['Month']), 1)
         month_end = datetime(next_month_year, next_month, 1)
         
     except KeyError:
         raise InvalidRecordException("Invalid values for month and/or year.")
     except TypeError:
         raise InvalidRecordException("Invalid values for month and/or year.")
     except ValueError:
         raise InvalidRecordException("Invalid values for month and/or year.")
     
     
     # Check that the EarliestEndTime and LatestEndTime fall within the right
     # month, and that EET < LET.
     try:
         earliest_end = rc['EarliestEndTime']
         latest_end = rc['LatestEndTime']
         if not (month_start <= earliest_end <= month_end):
             raise InvalidRecordException("EarliestEndTime is not within stated month.") 
         if not (month_start <= latest_end <= month_end):
             raise InvalidRecordException("LatestEndTime is not within stated month.") 
         
         if earliest_end > latest_end:
             raise InvalidRecordException("LatestEndTime is earlier than EarliestEndTime.") 
     except TypeError:
         # These two fields are not compulsory.
         pass
     
     # Check that the month isn't in the future
     now = datetime.now()
     if month_start > now:
         raise InvalidRecordException("Month specified in record is in the future.")
     
     if not 1 <= self._record_content['Month'] <= 12:
         raise InvalidRecordException("Month value is out of range")
     
     if self._record_content['WallDuration'] < 0:
         raise InvalidRecordException("Negative WallDuration")
     if self._record_content['CpuDuration'] < 0:
         raise InvalidRecordException("Negative WallDuration")