Class: Invoracle::SystemsSet

Inherits:
Object
  • Object
show all
Defined in:
lib/invoracle/systems_set.rb

Overview

Invoracle::SystemsSet maintains a group of Invoracle::System objects and their associated cluster UIDs.

Initial use case is to create sets of Invoracle::Systems and then retrieve them by Cluster UID.

Examples

systemsSet = Invoracle::SystemsSet.new
systemsSet.addSystem( system )
systemsSet.getSystem( systemUid )
systemsSet.exists?(   system )

systemsSet.getClusterCount
systemsSet.getSystemCount

systemsSet.getClusterUids

systemsSet.inflateSystems

systemsSet.getSystemsForClusterUid( clusterUid )

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSystemsSet

Returns a new instance of SystemsSet.



28
29
30
31
# File 'lib/invoracle/systems_set.rb', line 28

def initialize()
  @dSystemsBySysUid = {}
  @dSysUidsbyCluUid = {}
end

Instance Attribute Details

#dSystemsBySysUidObject (readonly)

Returns the value of attribute dSystemsBySysUid.



26
27
28
# File 'lib/invoracle/systems_set.rb', line 26

def dSystemsBySysUid
  @dSystemsBySysUid
end

#dSysUidsbyCluUidObject (readonly)

Returns the value of attribute dSysUidsbyCluUid.



27
28
29
# File 'lib/invoracle/systems_set.rb', line 27

def dSysUidsbyCluUid
  @dSysUidsbyCluUid
end

Instance Method Details

#exists?(oSystem = nil) ⇒ Boolean

Given an Invoracle::System, returns true or false if the system is within the set

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/invoracle/systems_set.rb', line 50

def exists?(oSystem=nil)
  unless oSystem.is_a?(Invoracle::System)
    raise ArgumentError, "E_BAD_SYSTEM_OBJECT #{oSystem.class}]"
  end

  sSysUid = oSystem.getAttr(:sSysUid)
  unless sSysUid.kind_of?(String) && sSysUid.length > 0
    raise ArgumentError, 'E_BAD_SYSTEM_UID'
  end

  bHasSys = @dSystemsBySysUid.has_key?(sSysUid) ? true : false

  return bHasSys
end

#getClusterCountObject



33
34
35
# File 'lib/invoracle/systems_set.rb', line 33

def getClusterCount()
  return @dSysUidsbyCluUid.keys.length
end

#getClusterUidsObject



41
42
43
44
45
# File 'lib/invoracle/systems_set.rb', line 41

def getClusterUids()
  aClusterUids = @dSysUidsbyCluUid.keys
  aClusterUids.sort!
  return aClusterUids
end

#getSystem(sSysUid = nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/invoracle/systems_set.rb', line 65

def getSystem(sSysUid=nil)
  unless sSysUid.kind_of?(String) && sSysUid.length > 0
    raise ArgumentError, 'E_BAD_SYSTEM_UID'
  end

  oSystem = @dSystemsBySysUid.has_key( sSysUid ) \
    ? @dSystemsBySysUid[ sSysUid ] : nil

  return oSystem
end

#getSystemCountObject



37
38
39
# File 'lib/invoracle/systems_set.rb', line 37

def getSystemCount()
  return @dSystemsBySysUid.keys.length
end

#getSystemsForClusterUid(sCluUid = nil) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/invoracle/systems_set.rb', line 108

def getSystemsForClusterUid(sCluUid=nil)
  unless sCluUid.kind_of?(String) && sCluUid.length > 0
    raise ArgumentError, 'E_BAD_CLUSTER_UID'
  end

  aSystems = []
  if @dSysUidsbyCluUid.has_key?( sCluUid )
    @dSysUidsbyCluUid[ sCluUid ].keys.each do |sSysUid|
      if @dSystemsBySysUid.has_key?( sSysUid )
        oSystem = @dSystemsBySysUid[ sSysUid ]
        aSystems.push( oSystem )
      end
    end
  end
  return aSystems
end

#inflateSystemsObject

Calls the #inflate method on each system in the set.



102
103
104
105
106
# File 'lib/invoracle/systems_set.rb', line 102

def inflateSystems()
  @dSystemsBySysUid.keys.each do |sSysUid|
    @dSystemsBySysUid[ sSysUid ].inflate
  end
end

#setSystem(oSystem = nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/invoracle/systems_set.rb', line 76

def setSystem(oSystem=nil)
  unless oSystem.is_a?(Invoracle::System)
    raise ArgumentError, 'E_BAD_SYSTEM_OBJECT'
  end

  sSysUid = oSystem.getAttr(:sSysUid)
  unless sSysUid.kind_of?(String)
    raise ArgumentError, 'E_BAD_SYSTEM_UID'
  end

  sSysUid.strip!
  unless sSysUid.length > 0
    raise ArgumentError, 'E_BAD_SYSTEM_UID'
  end

  @dSystemsBySysUid[ sSysUid ] = oSystem

  sCluUid = oSystem.getAttr(:sCluUid)
  if sCluUid.kind_of?(String) && sCluUid.length > 0
    @dSysUidsbyCluUid[ sCluUid ] ||= {}
    @dSysUidsbyCluUid[ sCluUid ][ sSysUid ] = 1
  end
end