Class: DataValidators::PbsDataValidator
- Inherits:
-
DataValidator
- Object
- DataValidator
- DataValidators::PbsDataValidator
- Includes:
- DataCompute, DataValidatorHelper, Errors, InputValidator
- Defined in:
- lib/data_validators/pbs_data_validator.rb
Overview
Data validator class for pbs output type
Constant Summary collapse
- COMPLETED =
'6'
Constants included from InputValidator
InputValidator::DECIMAL_RE, InputValidator::NON_ZERO_NUMBER_RE, InputValidator::NUMBER_RE, InputValidator::STRING_RE, InputValidator::URI_RE
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Instance Method Summary collapse
-
#initialize(log = Logger.new(STDOUT)) ⇒ PbsDataValidator
constructor
A new instance of PbsDataValidator.
-
#validate_data(data = nil) ⇒ Object
All possible output fields and their default values:.
Methods included from DataValidatorHelper
Methods included from DataCompute
Methods included from InputValidator
#decimal?, #is?, #non_zero_number?, #number?, #string?, #uri?
Constructor Details
#initialize(log = Logger.new(STDOUT)) ⇒ PbsDataValidator
Returns a new instance of PbsDataValidator.
17 18 19 |
# File 'lib/data_validators/pbs_data_validator.rb', line 17 def initialize(log = Logger.new(STDOUT)) @log = log end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
15 16 17 |
# File 'lib/data_validators/pbs_data_validator.rb', line 15 def log @log end |
Instance Method Details
#validate_data(data = nil) ⇒ Object
All possible output fields and their default values:
valid_data['host'] - required valid_data['pbs_queue'] - required valid_data['realm'] - required valid_data['scratch_type'] - optional, defaults to nil valid_data['vm_uuid'] - required valid_data['machine_name'] - required, defaults to "one-#valid_data['vm_uuid']" valid_data['user_name'] - required valid_data['group_name'] - required valid_data['duration'] - required, defaults to 00:00:00 valid_data['cpu_count'] - required valid_data['memory'] - required valid_data['disk_size'] - optional, defaults to nil valid_data['history'] - set of history records history_record['start_time'] - required history_record['end_time'] - required history_record['state'] - required, either all history records 'U' or last history record with 'E' if vm finished history_record['seq'] - required history_record['hostname'] - required
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/data_validators/pbs_data_validator.rb', line 41 def validate_data(data = nil) unless data fail Errors::ValidationError, 'Skipping a malformed record. '\ 'No data available to validate' end valid_data = data.clone fail_validation 'host' unless string?(data['host']) fail_validation 'queue' unless string?(data['pbs_queue']) fail_validation 'owner' unless string?(data['realm']) fail_validation 'VMUUID' unless string?(data['vm_uuid']) fail_validation 'owner' unless string?(data['user_name']) fail_validation 'group' unless string?(data['group_name']) fail_validation 'ppn' unless number?(data['cpu_count']) fail_validation 'mem' unless number?(data['memory']) fail_validation 'HISTORY_RECORDS' if (!data['history']) || data['history'].empty? history = [] data['history'].each do |h| history_record = h.clone fail_validation 'start' unless non_zero_number?(h['start_time']) history_record['start_time'] = Time.at(h['start_time'].to_i) fail_validation 'end' unless number?(h['end_time']) history_record['end_time'] = Time.at(h['end_time'].to_i) fail_validation 'seq' unless number?(h['seq']) fail_validation 'hostname' unless string?(h['hostname']) history_record['state'] = 'U' history << history_record end history.last['state'] = 'E' if data['status_code'] == COMPLETED valid_data['history'] = history valid_data['machine_name'] = default(data['machine_name'], :string, "one-#{valid_data['vm_uuid']}") duration = sum_rstime(data['history'], data['status_code'] == COMPLETED, valid_data['vm_uuid']) valid_data['duration'] = Time.at(duration) valid_data['disk_size'] = sum_disk_size(data['disks'], valid_data['vm_uuid']) valid_data end |