/notify_user/pymodules/python2.7/lib/python/saga_python-0.18-py2.7.egg/saga/resource/description.py

https://gitlab.com/pooja043/Globus_Docker_4
Python | 246 lines | 208 code | 23 blank | 15 comment | 18 complexity | 7d75a17e8e8f7b280020420063f2dcfd MD5 | raw file
  1. __author__ = "Andre Merzky, Ole Weidner"
  2. __copyright__ = "Copyright 2012-2013, The SAGA Project"
  3. __license__ = "MIT"
  4. import radical.utils.signatures as rus
  5. import saga.attributes as sa
  6. import saga.exceptions as se
  7. import constants as const
  8. #-------------------------------------------------------------------------------
  9. #
  10. class Description (sa.Attributes) :
  11. """
  12. The resource description class.
  13. Resource descriptions are used for two purposes:
  14. * an application can pass a description instances to a
  15. :class:`saga.resource.Manager` instance, to request control
  16. over the resource slice described in the description;
  17. * an application can request a resource's description for
  18. inspection of resource properties.
  19. There are three specific types of descriptions:
  20. * :class:`saga.resource.ComputeDescription` for the description of
  21. resources with compute capabilities;
  22. * :class:`saga.resource.StorageDescription` for the description of
  23. resources with data storage capabilities;
  24. * :class:`saga.resource.NetworkDescription` for the description of
  25. resources with communication capabilities.
  26. There is at this point no notion of resources which combine different
  27. capabilities.
  28. For all these capabilities, the following attributes are supported:
  29. * `RType` : `Enum`, describing the capabilities of the resource
  30. (`COMPUTE`, `STORAGE` or `NETWORK`)
  31. * `Template` : `String`, a backend specific resource class with some
  32. pre-defined hardware properties to apply to the resource.
  33. * `Image` : `String`, a backend specific resource class with some
  34. pre-defined software properties to apply to the resource.
  35. * `Dynamic` : `Boolean, if `True` signifies that the resource may
  36. dynamically change its properties at runtime
  37. * `Start` : `Integer (seconds) since epoch when the resource is
  38. expected to enter / when the resource entered `ACTIVE`
  39. state.
  40. * `End` : `Integer (seconds) since epoch when the resource is
  41. expected to enter / when the resource entered a `FINAL`
  42. state.
  43. * `Duration` : `Integer`, seconds for which the resource is expected to
  44. remain / the resource remained in `ACTIVE` state.
  45. * `MachineOS` : `String`, for `COMPUTE` resources, specifies the
  46. operating system type running on that resource.
  47. * `MachineArch : `String`, for `COMPUTE` resources, specifies the
  48. machine architecture of that resource.
  49. * `Size` : `Integer`, for `COMPUTE` resources, specifies the
  50. number of process slots provided, for `STORAGE` resource
  51. specifies the number of bytes, of the resource.
  52. * `Memory` : `Integer`, for `COMPUTE` resources, specifies the
  53. number of bytes provided as memory.
  54. * `Access` : `String`, usually an URL, which specifies the contact
  55. point for the resource capability interface / service
  56. interface.
  57. """
  58. # --------------------------------------------------------------------------
  59. #
  60. @rus.takes ('Description',
  61. rus.optional (dict))
  62. @rus.returns (rus.nothing)
  63. def __init__ (self, d=None):
  64. """
  65. __init__()
  66. Create a new Description instance.
  67. """
  68. # set attribute interface properties
  69. self._attributes_extensible (False)
  70. self._attributes_camelcasing (True)
  71. # register properties with the attribute interface
  72. self._attributes_register (const.RTYPE , None , sa.ENUM , sa.SCALAR, sa.WRITEABLE)
  73. self._attributes_register (const.TEMPLATE , None , sa.STRING, sa.SCALAR, sa.WRITEABLE)
  74. self._attributes_register (const.IMAGE , None , sa.STRING, sa.SCALAR, sa.WRITEABLE)
  75. self._attributes_register (const.DYNAMIC , False, sa.BOOL , sa.SCALAR, sa.WRITEABLE)
  76. self._attributes_register (const.START , None , sa.TIME , sa.SCALAR, sa.WRITEABLE)
  77. self._attributes_register (const.END , None , sa.TIME , sa.SCALAR, sa.WRITEABLE)
  78. self._attributes_register (const.DURATION , None , sa.TIME , sa.SCALAR, sa.WRITEABLE)
  79. self._attributes_register (const.MACHINE_OS , None , sa.STRING, sa.SCALAR, sa.WRITEABLE)
  80. self._attributes_register (const.MACHINE_ARCH, None , sa.STRING, sa.SCALAR, sa.WRITEABLE)
  81. self._attributes_register (const.SIZE , 1 , sa.INT , sa.SCALAR, sa.WRITEABLE)
  82. self._attributes_register (const.MEMORY , None , sa.STRING, sa.SCALAR, sa.WRITEABLE)
  83. self._attributes_register (const.ACCESS , None , sa.STRING, sa.SCALAR, sa.WRITEABLE)
  84. self._attributes_set_enums (const.RTYPE, [const.COMPUTE ,
  85. const.STORAGE ,
  86. const.NETWORK ])
  87. # FIXME: initialization should be done in Attributes: initialization
  88. # from dict or from other attributable
  89. #
  90. if d :
  91. for key in d.list_attributes () :
  92. self.set_attribute (key, d.get_attribute (key))
  93. # --------------------------------------------------------------------------
  94. #
  95. @rus.takes ('Description',
  96. 'Description')
  97. @rus.returns ('Description')
  98. def __deepcopy__ (self, other) :
  99. """
  100. An alias for `clone()`.
  101. """
  102. return self.clone (other)
  103. # --------------------------------------------------------------------------
  104. #
  105. @rus.takes ('Description',
  106. rus.optional ('Description'))
  107. @rus.returns ('Description')
  108. def clone (self, other=None) :
  109. """
  110. clone()
  111. Implements deep copy.
  112. Unlike the default python assignment (copy object reference),
  113. a deep copy will create a new object instance with the same state --
  114. after a deep copy, a change on one instance will not affect the other.
  115. """
  116. # a job description only has attributes - so create a new instance,
  117. # clone the attribs, and done.
  118. if not other :
  119. other = Description ()
  120. return self._attributes_deep_copy (other)
  121. # ------------------------------------------------------------------------------
  122. #
  123. class ComputeDescription (Description) :
  124. """
  125. A `ComputeDescription` is a specific description for a resource which
  126. provides compute capabilities, i.e. the ability to run application
  127. executables / code.
  128. """
  129. # --------------------------------------------------------------------------
  130. #
  131. @rus.takes ('ComputeDescription',
  132. rus.optional (dict))
  133. @rus.returns (rus.nothing)
  134. def __init__ (self, d=None) :
  135. if d :
  136. if const.RTYPE in d and d[const.RTYPE] != const.COMPUTE :
  137. raise se.BadParameter ("Cannot create ComputeResource with type '%s'" \
  138. % d[const.RTYPE])
  139. self._descr = super (ComputeDescription, self)
  140. self._descr.__init__ (d)
  141. self.rtype = const.COMPUTE
  142. # ------------------------------------------------------------------------------
  143. #
  144. class StorageDescription (Description) :
  145. """
  146. A `StorageDescription` is a specific description for a resource which
  147. provides storage capabilities, i.e. the ability to persistently store,
  148. organize and retrieve data files.
  149. """
  150. # --------------------------------------------------------------------------
  151. #
  152. @rus.takes ('StorageDescription',
  153. rus.optional (dict))
  154. @rus.returns (rus.nothing)
  155. def __init__ (self, d=None) :
  156. if d :
  157. if const.RTYPE in d and d[const.RTYPE] != const.STORAGE :
  158. raise se.BadParameter ("Cannot create StorageResource with type '%s'" \
  159. % d[const.RTYPE])
  160. self._descr = super (StorageDescription, self)
  161. self._descr.__init__ (d)
  162. self.rtype = const.STORAGE
  163. # ------------------------------------------------------------------------------
  164. #
  165. class NetworkDescription (Description) :
  166. """
  167. A `NetworkDescription` is a specific description for a resource which
  168. provides network capabilities.
  169. """
  170. # --------------------------------------------------------------------------
  171. #
  172. @rus.takes ('NetworkDescription',
  173. rus.optional (dict))
  174. @rus.returns (rus.nothing)
  175. def __init__ (self, d=None) :
  176. if d :
  177. if const.RTYPE in d and d[const.RTYPE] != const.NETWORK :
  178. raise se.BadParameter ("Cannot create NetworkResource with type '%s'" \
  179. % d[const.RTYPE])
  180. self._descr = super (NetworkDescription, self)
  181. self._descr.__init__ ()
  182. self.rtype = const.NETWORK