Class: RestCartridge11

Inherits:
OpenShift::Model
  • Object
show all
Defined in:
app/models/rest_cartridge11.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name, app, url, status_messages, nolinks = false) ⇒ RestCartridge11

Returns a new instance of RestCartridge11.



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
89
90
91
92
93
94
95
# File 'app/models/rest_cartridge11.rb', line 6

def initialize(type, name, app, url, status_messages, nolinks=false)
  self.name = name
  self.type = type
  self.scales_from = 0
  self.scales_to = nil 
  self.supported_scales_from = 0
  self.supported_scales_to = nil 
  self.scales_with = nil
  self.gear_profile = nil
  self.current_scale = 0
  self.collocated_with = []
  self.status_messages = status_messages
  prop_values = nil
  cart = CartridgeCache.find_cartridge(name)
  if app
    if CartridgeCache.cartridge_names('standalone').include? name
      app.comp_instance_map.each { |cname, cinst|
        next if cinst.parent_cart_name!=name
        prop_values = cinst.cart_properties
        break
      }
    else
      prop_values = app.embedded[name] 
    end
    group_component_map = {}
    app.comp_instance_map.each { |ci_name, ci|
      if ci.parent_cart_name==name
        group_component_map[ci.group_instance_name] = ci 
      end
    }
    group_component_map.each { |group_name, component|
      gi = app.group_instance_map[group_name]
      set_scaling_info(component, gi, cart)
    }
  else
    set_scaling_info(nil, nil, cart)
  end
  self.version = cart.version
  self.display_name = cart.display_name
  self.description = cart.description
  self.license = cart.license
  self.license_url = cart.license_url
  self.tags = cart.categories
  self.website = cart.website
  # self.suggests = cart.suggests_feature
  # self.requires = cart.requires_feature
  # self.depends = cart.profiles.map { |p| p.components.map { |c| c.depends_service }.flatten }.flatten.uniq
  # self.conflicts = cart.conflicts_feature
  self.help_topics = cart.help_topics
  
  self.properties = []
  cart.cart_data_def.each do |data_def|
    property = {}
    property["name"] = data_def["Key"]
    property["type"] = data_def["Type"]
    property["description"] = data_def["Description"]
    property["value"] = prop_values[data_def["Key"]] unless prop_values.nil? or prop_values[data_def["Key"]].nil?
    self.properties << property
  end
  
  if app and !nolinks
    domain_id = app.domain.namespace
    app_id = app.name
    if not app_id.nil? and not domain_id.nil?
      self.links = {
        "GET" => Link.new("Get cartridge", "GET", URI::join(url, "domains/#{domain_id}/applications/#{app_id}/cartridges/#{name}")),
        "UPDATE" => Link.new("Update cartridge configuration", "PUT", URI::join(url, "domains/#{domain_id}/applications/#{app_id}/cartridges/#{name}"), nil, [
          OptionalParam.new("additional_gear_storage", "integer", "Additional filesystem storage in gigabytes on each gear having cartridge #{name}"),
          OptionalParam.new("scales_from", "integer", "Minimum number of gears having cartridge #{name}"),
          OptionalParam.new("scales_to", "integer", "Maximum number of gears having cartridge #{name}")
        ])
      }
      self.links.merge!({
        "START" => Link.new("Start embedded cartridge", "POST", URI::join(url, "domains/#{domain_id}/applications/#{app_id}/cartridges/#{name}/events"), [
          Param.new("event", "string", "event", "start")
        ]),
        "STOP" => Link.new("Stop embedded cartridge", "POST", URI::join(url, "domains/#{domain_id}/applications/#{app_id}/cartridges/#{name}/events"), [
          Param.new("event", "string", "event", "stop")
        ]),
        "RESTART" => Link.new("Restart embedded cartridge", "POST", URI::join(url, "domains/#{domain_id}/applications/#{app_id}/cartridges/#{name}/events"), [
          Param.new("event", "string", "event", "restart")
        ]),
        "RELOAD" => Link.new("Reload embedded cartridge", "POST", URI::join(url, "domains/#{domain_id}/applications/#{app_id}/cartridges/#{name}/events"), [
          Param.new("event", "string", "event", "reload")
        ]),
        "DELETE" => Link.new("Delete embedded cartridge", "DELETE", URI::join(url, "domains/#{domain_id}/applications/#{app_id}/cartridges/#{name}"))
      }) if type == "embedded"
    end
  end
end

Instance Attribute Details

#additional_gear_storageObject

Returns the value of attribute additional_gear_storage.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def additional_gear_storage
  @additional_gear_storage
end

#base_gear_storageObject

Returns the value of attribute base_gear_storage.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def base_gear_storage
  @base_gear_storage
end

#collocated_withObject

Returns the value of attribute collocated_with.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def collocated_with
  @collocated_with
end

#current_scaleObject

Returns the value of attribute current_scale.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def current_scale
  @current_scale
end

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def description
  @description
end

#display_nameObject

Returns the value of attribute display_name.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def display_name
  @display_name
end

#gear_profileObject

Returns the value of attribute gear_profile.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def gear_profile
  @gear_profile
end

#help_topicsObject

Returns the value of attribute help_topics.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def help_topics
  @help_topics
end

#licenseObject

Returns the value of attribute license.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def license
  @license
end

#license_urlObject

Returns the value of attribute license_url.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def license_url
  @license_url
end

Returns the value of attribute links.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def links
  @links
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def name
  @name
end

#propertiesObject

Returns the value of attribute properties.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def properties
  @properties
end

#scales_fromObject

Returns the value of attribute scales_from.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def scales_from
  @scales_from
end

#scales_toObject

Returns the value of attribute scales_to.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def scales_to
  @scales_to
end

#scales_withObject

Returns the value of attribute scales_with.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def scales_with
  @scales_with
end

#status_messagesObject

Returns the value of attribute status_messages.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def status_messages
  @status_messages
end

#supported_scales_fromObject

Returns the value of attribute supported_scales_from.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def supported_scales_from
  @supported_scales_from
end

#supported_scales_toObject

Returns the value of attribute supported_scales_to.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def supported_scales_to
  @supported_scales_to
end

#tagsObject

Returns the value of attribute tags.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def tags
  @tags
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def type
  @type
end

#versionObject

Returns the value of attribute version.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def version
  @version
end

#websiteObject

Returns the value of attribute website.



2
3
4
# File 'app/models/rest_cartridge11.rb', line 2

def website
  @website
end

Instance Method Details

#set_scaling_info(comp_instance, group_instance, cartridge) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/models/rest_cartridge11.rb', line 98

def set_scaling_info(comp_instance, group_instance, cartridge)
  if group_instance and comp_instance
    app = group_instance.app
    self.current_scale += group_instance.gears.length
    if self.scales_with.nil?
      app.embedded.each { |cart_name, cart_info|
        cart = CartridgeCache::find_cartridge(cart_name)
        if cart.categories.include? "scales"
          self.scales_with = cart.name
          break
        end
      }
    end
    sup_max = group_instance.supported_max
    self.supported_scales_from += group_instance.supported_min
    if self.supported_scales_to.nil? or sup_max==-1
      self.supported_scales_to = sup_max
    else
      self.supported_scales_to += sup_max unless self.supported_scales_to==-1
    end
    self.scales_from += group_instance.min
    if self.scales_to.nil? or group_instance.max == -1
      self.scales_to = group_instance.max
    else
      self.scales_to += group_instance.max unless self.scales_to==-1
    end
    self.base_gear_storage = group_instance.get_cached_min_storage_in_gb
    self.additional_gear_storage = comp_instance.addtl_fs_gb
    self.gear_profile = group_instance.node_profile

    group_instance.component_instances.each { |cname|
      cinst = app.comp_instance_map[cname]
      if cinst.parent_cart_name!=cartridge.name and cinst.parent_cart_name != app.name
        collocated_with << cinst.parent_cart_name unless collocated_with.include? cinst.parent_cart_name
      end
    }
  else
    prof = cartridge.profiles(cartridge.default_profile)
    group = prof.groups()[0]
    self.current_scale = 0
    scaling_cart = CartridgeCache::cartridges.find { |cart| ( cart.categories.include? "scales" and cart.name!=cartridge.name ) }
    self.scales_with = scaling_cart.name unless scaling_cart.nil?
    self.supported_scales_from = group.scaling.min
    self.scales_from = group.scaling.min
    self.supported_scales_to = group.scaling.max
    self.scales_to = group.scaling.max
  end
end

#to_xml(options = {}) ⇒ Object



147
148
149
150
# File 'app/models/rest_cartridge11.rb', line 147

def to_xml(options={})
  options[:tag_name] = "cartridge"
  super(options)
end