Class: Dcmgr::NodeModules::Scheduler

Inherits:
Isono::NodeModules::Base
  • Object
show all
Includes:
Logger
Defined in:
lib/dcmgr/node_modules/scheduler.rb

Instance Method Summary collapse

Methods included from Logger

create, default_logdev, included

Instance Method Details

#schedule_instance(instance_id) ⇒ Object



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
# File 'lib/dcmgr/node_modules/scheduler.rb', line 25

def schedule_instance(instance_id)
  instance = Models::Instance[instance_id]
  vol = Models::Volume.find(:instance_id=>instance.id, :boot_dev=>1)
  
  Dcmgr::Scheduler.host_node.schedule(instance)
  Dcmgr::Scheduler.network.schedule(instance)
  lease_ip_address_to_instance(instance)
  instance.save
  
  instance.state = :pending
  instance.save


  case instance.image.boot_dev_type
  when Models::Image::BOOT_DEV_SAN
    Dcmgr::Scheduler.storage_node.schedule(vol)
    vol.state = :pending
    vol.save
    
    commit_transaction
    
    repository_address = Dcmgr::StorageService.repository_address(vol.snapshot.destination_key)
    self.job.submit("sta-handle.#{vol.storage_node.node_id}",
                    'create_volume_and_run_instance', vol.canonical_uuid, instance.canonical_uuid, repository_address)
  when Models::Image::BOOT_DEV_LOCAL
    commit_transaction
    self.job.submit("hva-handle.#{instance.host_node.node_id}",
                    'run_local_store', instance.canonical_uuid)
  else
    raise "Unknown boot type"
  end
  event.publish('instance.scheduled', :args=>[instance.canonical_uuid])
  
rescue ::Exception => e
  rollback_transaction rescue nil
  
  logger.error(e)
  instance.destroy if instance
  vol.destroy if vol
  return
end

#schedule_instance_ha(instance_id, vol) ⇒ Object



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
96
# File 'lib/dcmgr/node_modules/scheduler.rb', line 67

def schedule_instance_ha(instance_id, vol)
  instance = Models::Instance[instance_id]
  
  Dcmgr::Scheduler.host_node_ha.schedule(instance)
  # Don't re-schedule network here.
  # The IP address, MAC address and NIC must be assigned with same address.
  instance.save
  
  instance.state = :pending
  instance.save

  commit_transaction
  case instance.image.boot_dev_type
  when Models::Image::BOOT_DEV_SAN
    self.job.submit("hva-handle.#{instance.host_node.node_id}", 'run_vol_store', instance.canonical_uuid, vol.canonical_uuid)
  when Models::Image::BOOT_DEV_LOCAL
    self.job.submit("hva-handle.#{instance.host_node.node_id}", 'run_local_store', instance.canonical_uuid)
  else
    raise "Unknown boot type"
  end
  event.publish('instance.scheduled', :args=>[instance.canonical_uuid])
  
rescue ::Exception => e
  rollback_transaction rescue nil
  
  logger.error(e)
  instance.destroy if instance
  vol.destroy if vol
  return
end

#schedule_start_instance(instance_id) ⇒ 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
# File 'lib/dcmgr/node_modules/scheduler.rb', line 98

def schedule_start_instance(instance_id)
  instance = Models::Instance[instance_id]
  vol = Models::Volume.find(:instance_id=>instance.id, :boot_dev=>1)
  
  Dcmgr::Scheduler.host_node.schedule(instance)
  lease_ip_address_to_instance(instance)
  instance.save
  
  instance.state = :pending
  instance.save

  commit_transaction
  case instance.image.boot_dev_type
  when Models::Image::BOOT_DEV_SAN
    self.job.submit("hva-handle.#{instance.host_node.node_id}", 'run_vol_store', instance.canonical_uuid, vol.canonical_uuid)
  when Models::Image::BOOT_DEV_LOCAL
    self.job.submit("hva-handle.#{instance.host_node.node_id}", 'run_local_store', instance.canonical_uuid)
  else
    raise "Unknown boot type"
  end
  event.publish('instance.scheduled', :args=>[instance.canonical_uuid])
  
rescue ::Exception => e
  rollback_transaction rescue nil
  
  logger.error(e)
  instance.destroy if instance
  vol.destroy if vol
  return
end

#schedule_volume(volume_id) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/dcmgr/node_modules/scheduler.rb', line 129

def schedule_volume(volume_id)
  volume = Models::Volume[volume_id]
  
  Dcmgr::Scheduler.storage_node.schedule(volume)
  volume.save

  volume.state = :pending
  volume.save
  
  commit_transaction
  
  repository_address = nil
  if volume.snapshot
    repository_address = Dcmgr::StorageService.repository_address(volume.snapshot.destination_key)
  end
        
  self.job.submit("sta-handle.#{volume.storage_node.node_id}",
                  'create_volume', volume.canonical_uuid, repository_address)
rescue ::Exception => e
  rollback_transaction rescue nil

  logger.error(e)
  volume.destroy
end