Class: Wakame::MasterManagers::ClusterManager

Inherits:
Object
  • Object
show all
Includes:
Wakame::MasterManager
Defined in:
lib/wakame/master_managers/cluster_manager.rb

Defined Under Namespace

Classes: ClusterConfigLoader

Instance Attribute Summary

Attributes included from Wakame::MasterManager

#master

Instance Method Summary collapse

Methods included from Wakame::MasterManager

#start, #stop

Instance Method Details

#clustersObject



99
100
101
# File 'lib/wakame/master_managers/cluster_manager.rb', line 99

def clusters
  Models::ServiceClusterPool.all.map{|r| r.service_cluster_id }
end

#initObject



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
# File 'lib/wakame/master_managers/cluster_manager.rb', line 44

def init
  # Periodical cluster status updater
  @status_check_timer = EM::PeriodicTimer.new(5) {
    StatusDB.pass {
      clusters.each { |cluster_id|
        Service::ServiceCluster.find(cluster_id).update_cluster_status
      }
    }
  }
  
  # Event based cluster status updater
  @check_event_tickets = []
  [Event::ServiceOnline, Event::ServiceOffline, Event::ServiceFailed].each { |evclass|
    @check_event_tickets << EventDispatcher.subscribe(evclass) { |event|
      StatusDB.pass {
        clusters.each { |cluster_id|
          Service::ServiceCluster.find(cluster_id).update_cluster_status
        }
      }
    }
  }
 
  @check_event_tickets << EventDispatcher.subscribe(Event::ServiceStatusChanged) { |event|
    svc = Service::ServiceInstance.find(event.instance_id)
    case svc.status
    when Service::STATUS_ENTERING
      EM.defer {
        # Refresh the monitoring conf on the agent
        svc.cloud_host.live_monitors.each { |path, conf|
          Wakame.log.debug("#{self.class}: Refreshing monitoring setting on #{svc.cloud_host.agent_id} (on enter): #{path} => #{conf.inspect}")
          Master.instance.actor_request(svc.cloud_host.agent_id, '/monitor/reload', path, conf).request.wait
        }
      }
    when Service::STATUS_QUITTING
      EM.defer {
        # Refresh the monitoring conf on the agent
        svc.cloud_host.live_monitors.each { |path, conf|
          Wakame.log.debug("#{self.class}: Refreshing monitoring setting on #{svc.cloud_host.agent_id} (on quit): #{path} => #{conf.inspect}")
          Master.instance.actor_request(svc.cloud_host.agent_id, '/monitor/reload', path, conf).request.wait
        }
      }
    end
  }
end

#load_config_clusterObject



112
113
114
115
116
117
# File 'lib/wakame/master_managers/cluster_manager.rb', line 112

def load_config_cluster
  ClusterConfigLoader.new.load.each { |name, id|
    Models::ServiceClusterPool.register_cluster(name)
  }
  resolve_template_vm_attr
end

#register(cluster) ⇒ Object

Raises:

  • (ArgumentError)


103
104
105
106
# File 'lib/wakame/master_managers/cluster_manager.rb', line 103

def register(cluster)
  raise ArgumentError unless cluster.is_a?(Service::ServiceCluster)
  Models::ServiceClusterPool.register_cluster(cluster.name)
end

#reloadObject



89
90
# File 'lib/wakame/master_managers/cluster_manager.rb', line 89

def reload
end

#terminateObject



92
93
94
95
96
97
# File 'lib/wakame/master_managers/cluster_manager.rb', line 92

def terminate
  @status_check_timer.cancel
  @check_event_tickets.each { |t|
    EventDispatcher.unsubscribe(t)
  }
end

#unregister(cluster_id) ⇒ Object



108
109
110
# File 'lib/wakame/master_managers/cluster_manager.rb', line 108

def unregister(cluster_id)
  @clusters.delete(cluster_id)
end