Class: Appdynamics::Application

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, application_id, application_name) ⇒ Application

Returns a new instance of Application.



5
6
7
8
9
# File 'lib/appdynamics/application.rb', line 5

def initialize controller, application_id, application_name
    @controller = controller
    @application_name = application_name
    @application_id = application_id
end

Instance Attribute Details

#application_idObject (readonly)

Returns the value of attribute application_id.



3
4
5
# File 'lib/appdynamics/application.rb', line 3

def application_id
  @application_id
end

#application_nameObject (readonly)

Returns the value of attribute application_name.



3
4
5
# File 'lib/appdynamics/application.rb', line 3

def application_name
  @application_name
end

#controllerObject (readonly)

Returns the value of attribute controller.



3
4
5
# File 'lib/appdynamics/application.rb', line 3

def controller
  @controller
end

Class Method Details

.from_hash(hsh, controller) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/appdynamics/application.rb', line 26

def self.from_hash hsh, controller
    application = Application.new controller, hsh['application_id'], hsh['application_name']
    application.metrics = hsh['metrics'] if hsh['metrics']
    application.tiers = hsh['tiers'] if hsh['tiers']
    application.nodes = hsh['nodes'] if hsh['nodes']
    application
end

Instance Method Details

#find_metric_by_name(nam) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/appdynamics/application.rb', line 64

def find_metric_by_name nam
    metric = nil
    metrics.each do |m|
        metric = m.find_by_name nam
        break unless metric.nil?
    end
    metric
end

#find_metric_by_path(path) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/appdynamics/application.rb', line 73

def find_metric_by_path path
    metric = metrics.select{|metric| metric.name == path.first}.first
    return nil unless metric
    path.shift
    path.each do |metric_name|
        metric = metric.child_by_name metric_name
        return nil unless metric
    end
    metric
end

#metricsObject



54
55
56
# File 'lib/appdynamics/application.rb', line 54

def metrics
    @metrics ||= controller.metrics_for self
end

#metrics=(metrics) ⇒ Object



58
59
60
61
62
# File 'lib/appdynamics/application.rb', line 58

def metrics= metrics
    @metrics = metrics.map{|metric|
        Metric.from_hash metric, @controller, self
    }
end

#nameObject



11
12
13
# File 'lib/appdynamics/application.rb', line 11

def name
    @application_name
end

#nodesObject



34
35
36
# File 'lib/appdynamics/application.rb', line 34

def nodes
    @nodes ||= controller.nodes_for self
end

#nodes=(nodes) ⇒ Object



38
39
40
41
42
# File 'lib/appdynamics/application.rb', line 38

def nodes= nodes
    @nodes = nodes.map{|node|
        Node.from_hash node, @controller, self
    }
end

#relative_route(*_) ⇒ Object



84
85
86
# File 'lib/appdynamics/application.rb', line 84

def relative_route *_
    "applications/#{application_id}"
end

#tiersObject



44
45
46
# File 'lib/appdynamics/application.rb', line 44

def tiers
    @tiers ||= controller.tiers_for self
end

#tiers=(tiers) ⇒ Object



48
49
50
51
52
# File 'lib/appdynamics/application.rb', line 48

def tiers= tiers
    @tiers = tiers.map{|tier|
        Tier.from_hash tier, @controller, self
    }
end

#to_hashObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/appdynamics/application.rb', line 15

def to_hash
    hsh = {
        application_name: @application_name,
        application_id: @application_id
    }
    hsh.merge!({nodes: @nodes.map{|node| node.to_hash}}) if @nodes
    hsh.merge!({metrics: @metrics.map{|node| node.to_hash}}) if @metrics
    hsh.merge!({tiers: @tiers.map{|node| node.to_hash}}) if @tiers
    hsh
end