Class: Qubell::Application

Inherits:
Base
  • Object
show all
Defined in:
lib/qubell/application.rb

Overview

Qubell application class

Instance Attribute Summary collapse

Attributes inherited from Base

#id, #name

Instance Method Summary collapse

Methods inherited from Base

#==, #to_hash, #to_json, #to_s

Constructor Details

#initialize(args) ⇒ Application

Returns a new instance of Application.



17
18
19
20
# File 'lib/qubell/application.rb', line 17

def initialize(args)
  super
  @organization = args[:organization]
end

Instance Attribute Details

#organizationObject (readonly)

Returns the value of attribute organization.



15
16
17
# File 'lib/qubell/application.rb', line 15

def organization
  @organization
end

Instance Method Details

#instancesArray<Qubell::Instance>

Get list of all instances for given application.

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/qubell/application.rb', line 32

def instances
  # Qubell public API is too enterprise for just getting list of instances
  # by application ID. Actually there is no method for this yet.
  # So, store ID of organization in Application class and to get a list of
  # instances we init new organization class, get all environments in this
  # organization, get all instances in this environment and finally
  # filter them by application.
  # Like in one russian fairytail: "his death is at the end of the needle,
  # that needle is in the egg, then egg is in a duck, that duck is in a
  # hare, the hare is in the trunk, and the trunk stands on a high oak"
  Qubell::Organization.new(id: @organization).environments
                      .map(&:instances).flatten.select do |instance|
    instance.instance_of_app?(self)
  end
end

#launch(args) ⇒ Qubell::Instance

Launch new instance of given application.

Parameters:

  • args (Hash<String => String>)

    map of configuration parameters

Returns:



62
63
64
65
66
67
68
69
# File 'lib/qubell/application.rb', line 62

def launch(args)
  id = Qubell::APICall.put("/applications/#{@id}/launch",
                           args.to_json,
                           content_type: 'application/json')[:id]
  instances.select { |instance| instance.id == id }.first
rescue Qubell::ExecutionError
  raise Qubell::FormatError, 'currect manifest is incorrect'
end

#revisionsArray<Qubell::Revision>

Get list of all revisions for given application.

Returns:



24
25
26
27
28
# File 'lib/qubell/application.rb', line 24

def revisions
  Qubell::APICall.get("/applications/#{@id}/revisions").map do |rev|
    Qubell::Revision.new(rev)
  end
end

#update(content) ⇒ String

Get the application instance status.

Parameters:

  • content (String)

    new manifest content

Returns:

  • (String)

    instances status info



51
52
53
54
55
56
57
# File 'lib/qubell/application.rb', line 51

def update(content)
  Qubell::APICall.put("/applications/#{@id}/manifest",
                      content,
                      content_type: 'application/x-yaml')[:version]
rescue Qubell::ExecutionError
  raise Qubell::FormatError, 'currect manifest is incorrect'
end