ArgoUserJob.py 4.7 KB
Newer Older
jtchilders's avatar
jtchilders committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 85 86 87 88
import sys,logging,copy
import Serializer
logger = logging.getLogger(__name__)


class ArgoUserSubJob:
   def __init__(self,
                site                      = '',
                job_id                    = 0,
                job_name                  = '',
                job_description           = '',
                queue_id                  = 0,
                project_id                = 0,
                wall_time_minutes         = 0,
                num_nodes                 = 0,
                processes_per_node        = 0,
                scheduler_config_id       = 0,
                task_id                   = 0,
                task_input_file           = '',
               ):
      self.site                           = site
      self.job_id                         = job_id
      self.job_name                       = job_name
      self.job_description                = job_description
      self.queue_id                       = queue_id
      self.project_id                     = project_id
      self.wall_time_minutes              = wall_time_minutes
      self.num_nodes                      = num_nodes
      self.processes_per_node             = processes_per_node
      self.scheduler_config_id            = scheduler_config_id
      self.task_id                        = task_id
      self.task_input_file                = task_input_file

   def serialize(self):
      return Serializer.serialize(self.__dict__)
   @staticmethod
   def deserialize(text):
      tmp = ArgoUserSubJob()
      tmp.__dict__ = Serializer.deserialize(text)

      # convert unicode strings to strings
      tmp.site             = Serializer.convert_unicode_string(tmp.site)
      tmp.job_id           = Serializer.convert_unicode_string(tmp.job_id)
      tmp.job_description  = Serializer.convert_unicode_string(tmp.job_description)
      tmp.task_input_file  = Serializer.convert_unicode_string(tmp.task_input_file)

      return tmp
      

class ArgoUserJob:
   def __init__(self,
                job_id                    = 0,
                job_name                  = '',
                job_description           = '',
                group_identifier          = '',

                username                  = '',
                email_address             = '',

                input_url                 = '',
                output_url                = '',

                job_status_routing_key    = '',
                subjobs                   = [],
               ):
      self.job_id                         = job_id
      self.job_name                       = job_name
      self.job_description                = job_description
      self.group_identifier               = group_identifier

      self.username                       = username
      self.email_address                  = email_address

      self.input_url                      = input_url
      self.output_url                     = output_url

      self.job_status_routing_key         = job_status_routing_key
      self.subjobs                        = subjobs
      
   def serialize(self):
      try:
         # loop over sub jobs and serialize each one
         serial_subjobs = []
         for subjob in self.subjobs:
            serial_subjobs.append(subjob.serialize())
         tmp = copy.deepcopy(self)
         tmp.subjobs = serial_subjobs
         return Serializer.serialize(tmp.__dict__)
89
      except Exception as e:
jtchilders's avatar
jtchilders committed
90 91 92 93 94 95 96 97 98 99 100 101 102
         raise Exception('Exception received while serializing ArgoUserJob: ' + str(e))

   @staticmethod
   def deserialize(text):
      # fill tmp with json dictionary
      tmp = ArgoUserJob()
      try:
         tmp.__dict__ = Serializer.deserialize(text)
         subjobs = []
         for subjob in self.subjobs:
            tmp = ArgoUserSubJob.deserialize(subjob)
            subjobs.append(tmp)
         tmp.subjobs = subjobs
103
      except Exception as e:
jtchilders's avatar
jtchilders committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
         raise Exception('Exception received while deserializing ArgoUserJob: ' + str(e))

      # convert unicode strings to strings
      tmp.job_name                    = Serializer.convert_unicode_string(self.job_name)
      tmp.job_description             = Serializer.convert_unicode_string(self.job_description)
      tmp.group_identifier            = Serializer.convert_unicode_string(self.group_identifier)
      tmp.username                    = Serializer.convert_unicode_string(self.username)
      tmp.email_address               = Serializer.convert_unicode_string(self.email_address)
      tmp.input_url                   = Serializer.convert_unicode_string(self.input_url)
      tmp.output_url                  = Serializer.convert_unicode_string(self.output_url)
      tmp.job_status_routing_key      = Serializer.convert_unicode_string(self.job_status_routing_key)

      return tmp