Skip to content

Commit

Permalink
Add batch validator
Browse files Browse the repository at this point in the history
  • Loading branch information
srisco committed Jun 18, 2019
1 parent ba201ec commit 0df9047
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions scar/providers/aws/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,18 @@ def validate_lambda(cls, lambda_properties):
if 'memory' in lambda_properties:
cls.validate_memory(lambda_properties['memory'])
if 'time' in lambda_properties:
cls.validate_time(lambda_properties['time'])

cls.validate_time(lambda_properties['time'])

@classmethod
def validate_batch(cls, batch_properties):
if 'vcpus' in batch_properties:
cls.validate_batch_vcpus(batch_properties['vcpus'])
if 'memory' in batch_properties:
cls.validate_batch_memory(batch_properties['memory'])
if 'compute_resources' in batch_properties and \
'comp_type' in batch_properties['compute_resources']:
cls.validate_batch_comp_type(batch_properties['compute_resources']['comp_type'])

@staticmethod
def validate_time(lambda_time):
if (lambda_time <= 0) or (lambda_time > 300):
Expand Down Expand Up @@ -86,5 +96,22 @@ def validate_http_payload_size(file_path, async_call=False):
elif async_call and file_size > MAX_POST_BODY_SIZE_ASYNC:
filesize = '{0:.2f}KB'.format(file_size/KB)
maxsize = '{0:.2f}KB'.format(MAX_POST_BODY_SIZE_ASYNC/KB)
raise InvocationPayloadError(file_size=filesize, max_size=maxsize)

raise InvocationPayloadError(file_size=filesize, max_size=maxsize)

@staticmethod
def validate_batch_vcpus(batch_vcpus):
if batch_vcpus < 1:
error_msg = 'Please, set at least one vCPU.'
raise ValidatorError(parameter='batch_vcpus', parameter_value=batch_vcpus, error_msg=error_msg)

@staticmethod
def validate_batch_memory(batch_memory):
if batch_memory < 4:
error_msg = 'Please, set a value greater than 4.'
raise ValidatorError(parameter='batch_memory', parameter_value=batch_memory, error_msg=error_msg)

@staticmethod
def validate_batch_comp_type(batch_comp_type):
if batch_comp_type not in ['SPOT', 'EC2']:
error_msg = 'Please, set a valid compute environment type ("EC2" or "SPOT")'
raise ValidatorError(parameter='batch_comp_type', parameter_value=batch_comp_type, error_msg=error_msg)

0 comments on commit 0df9047

Please sign in to comment.