Class: Cloudscale::Plugins::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudscale/plugins/plugin.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlugin



26
27
28
# File 'lib/cloudscale/plugins/plugin.rb', line 26

def initialize()
  @rest_client = RestClientWrapper.instance
end

Instance Attribute Details

#logObject

Returns the value of attribute log.



18
19
20
# File 'lib/cloudscale/plugins/plugin.rb', line 18

def log
  @log
end

#pluginsObject

Returns the value of attribute plugins.



18
19
20
# File 'lib/cloudscale/plugins/plugin.rb', line 18

def plugins
  @plugins
end

#rest_clientObject

Returns the value of attribute rest_client.



18
19
20
# File 'lib/cloudscale/plugins/plugin.rb', line 18

def rest_client
  @rest_client
end

Class Method Details

.inherited(klass) ⇒ Object



92
93
94
# File 'lib/cloudscale/plugins/plugin.rb', line 92

def self.inherited(klass)
  @plugins << klass
end

.pluginsObject



88
89
90
# File 'lib/cloudscale/plugins/plugin.rb', line 88

def self.plugins
  @plugins
end

.remove(agentInstanceId) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/cloudscale/plugins/plugin.rb', line 42

def self.remove(agentInstanceId)
  reset(agentInstanceId)

  resetRestEndpoint('components', agentInstanceId, 'Components')
  resetRestEndpoint('agentInstanceMenus', agentInstanceId, 'Agent Insntance Menus')

  Constants::AgentInstance.remove()
end

.remove_agenInstance(agentInstanceId) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cloudscale/plugins/plugin.rb', line 66

def self.remove_agenInstance(agentInstanceId)
  rest_client = RestClientWrapper.instance
  puts "Removing AgentInstance completely:\n\n"

  agent_instance = rest_client.searchOne('agentInstances',
          'findByAgentInstanceId', { :id => agentInstanceId })

  rest_client.delete('agentInstances', RestClientWrapper.load_entity_id(agent_instance))

  puts "    Deleting AgentInstance was successful \n\n"
end

.remove_measurements(agentInstanceId) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/cloudscale/plugins/plugin.rb', line 78

def self.remove_measurements(agentInstanceId)
  rest_client = RestClientWrapper.instance
  puts "Removing Measurement elements for Agent (#{agentInstanceId}):\n\n"
  puts "    Starting to delete all elements..."

  rest_client.customDelete("measurements", "removeByAgentInstanceId", { :agentInstanceId => agentInstanceId })

  puts "    Deleting all elements was successful \n\n"
end

.reset(agentInstanceId) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cloudscale/plugins/plugin.rb', line 30

def self.reset(agentInstanceId)
  resetRestEndpoint('coredatas', agentInstanceId, 'Coredata')
  resetRestEndpoint('tables', agentInstanceId, 'Table')
  resetRestEndpoint('charts', agentInstanceId, 'Chart')

  Monitor::InitCharts.remove_charts()
  Monitor::InitMenus.remove_menus()

  remove_measurements(agentInstanceId)
  remove_agenInstance(agentInstanceId)
end

.resetRestEndpoint(entityRel, agentInstanceId, entityName) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cloudscale/plugins/plugin.rb', line 51

def self.resetRestEndpoint(entityRel, agentInstanceId, entityName)
  rest_client = RestClientWrapper.instance
  entities = rest_client.searchAny(entityRel,"findByAgentInstanceId",
                  { :agentInstanceId => agentInstanceId })

  puts "Found #{entityName} elements for Agent (#{agentInstanceId}): #{entities["content"].length.to_s}"
  puts "    Starting to delete all elements..."

  entities["content"].each do  | entity |
    rest_client.delete(entityRel, RestClientWrapper.load_entity_id(entity))
  end

  puts "    Deleting all elements was successful \n\n"
end