From: martyntaylor mtaylor@redhat.com
--- src/app/models/task.rb | 8 +++++++- src/app/models/task_observer.rb | 22 ++++++++++++++++++++++ src/db/migrate/20090831140000_create_tasks.rb | 1 + src/spec/models/task_observer_spec.rb | 24 ++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletions(-) create mode 100644 src/app/models/task_observer.rb create mode 100644 src/spec/models/task_observer_spec.rb
diff --git a/src/app/models/task.rb b/src/app/models/task.rb index 6cb907e..9f23ef2 100644 --- a/src/app/models/task.rb +++ b/src/app/models/task.rb @@ -28,6 +28,7 @@ class Task < ActiveRecord::Base # moved associations here so that nested set :include directives work
STATE_QUEUED = "queued" + STATE_PENDING = "pending" STATE_RUNNING = "running" STATE_FINISHED = "finished" STATE_PAUSED = "paused" @@ -35,7 +36,7 @@ class Task < ActiveRecord::Base STATE_CANCELED = "canceled"
COMPLETED_STATES = [STATE_FINISHED, STATE_FAILED, STATE_CANCELED] - WORKING_STATES = [STATE_QUEUED, STATE_RUNNING, STATE_PAUSED] + WORKING_STATES = [STATE_QUEUED, STATE_RUNNING, STATE_PAUSED, STATE_PENDING]
validates_inclusion_of :type, :in => %w( InstanceTask ) @@ -48,6 +49,7 @@ class Task < ActiveRecord::Base # depending on subclass, action, state
TASK_STATES_OPTIONS = [["Queued", Task::STATE_QUEUED], + ["Pending", Task::STATE_PENDING], ["Running", Task::STATE_RUNNING], ["Paused", Task::STATE_PAUSED], ["Finished", Task::STATE_FINISHED], @@ -92,6 +94,10 @@ class Task < ActiveRecord::Base ret_val end
+ def submission_time + time.started - time.submitted + end + def validate errors.add("created_at", "Task started but does not have the creation time set") if time_started and created_at.nil? errors.add("time_started", "Task ends but does not have the start time set") if time_ended and time_started.nil? diff --git a/src/app/models/task_observer.rb b/src/app/models/task_observer.rb new file mode 100644 index 0000000..3e2d803 --- /dev/null +++ b/src/app/models/task_observer.rb @@ -0,0 +1,22 @@ +class TaskObserver < ActiveRecord::Observer + def after_save(a_task) + if a_task.changed? + change = a_task.changes['state'] + if change + update_timestamp(change[0], change[1], a_task) + end + end + end + + def update_timestamp(state_from, state_to, a_task) + puts state_to + if state_to == Task::STATE_RUNNING + a_task.time_started = Time.now + elsif state_to == Task::STATE_PENDING + a_task.time_submitted = Time.now + end + end + +end + +TaskObserver.instance \ No newline at end of file diff --git a/src/db/migrate/20090831140000_create_tasks.rb b/src/db/migrate/20090831140000_create_tasks.rb index a9e099f..2c3e0e2 100644 --- a/src/db/migrate/20090831140000_create_tasks.rb +++ b/src/db/migrate/20090831140000_create_tasks.rb @@ -28,6 +28,7 @@ class CreateTasks < ActiveRecord::Migration t.string :task_target_type t.string :args t.timestamp :created_at + t.timestamp :time_submitted t.timestamp :time_started t.timestamp :time_ended t.text :message diff --git a/src/spec/models/task_observer_spec.rb b/src/spec/models/task_observer_spec.rb new file mode 100644 index 0000000..5d31693 --- /dev/null +++ b/src/spec/models/task_observer_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe TaskObserver do + + before(:each) do + @timestamp = Time.now + @task = InstanceTask.new({}) + end + + it "should set started at timestamp when the task goes to state running" do + @task.state = Task::STATE_RUNNING + @task.save + + @task.time_started.should >= @timestamp + end + + it "should set time submitted timestamp when the task goes to state pending" do + @task.state = Task::STATE_PENDING + @task.save + + @task.time_submitted.should >= @timestamp + end + +end \ No newline at end of file
From: martyntaylor mtaylor@redhat.com
--- src/app/models/instance.rb | 7 +++++ src/app/models/instance_observer.rb | 22 ++++++++++++++++ src/app/models/task_observer.rb | 1 - src/db/migrate/20090804142049_create_instances.rb | 26 ++++++++++-------- src/spec/factories/instance.rb | 4 +++ src/spec/models/instance_observer_spec.rb | 29 +++++++++++++++++++++ 6 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 src/app/models/instance_observer.rb create mode 100644 src/spec/models/instance_observer_spec.rb
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb index fa89844..25d17bd 100644 --- a/src/app/models/instance.rb +++ b/src/app/models/instance.rb @@ -101,5 +101,12 @@ class Instance < ActiveRecord::Base self.realm = provider.realms.find_by_name(realm_name) unless realm_name.nil? end
+ def total_run_time + if state == STATE_RUNNING + acc_run_time + (Time.now - time_last_start) + else + acc_run_time + end + end
end diff --git a/src/app/models/instance_observer.rb b/src/app/models/instance_observer.rb new file mode 100644 index 0000000..81e75ea --- /dev/null +++ b/src/app/models/instance_observer.rb @@ -0,0 +1,22 @@ +class InstanceObserver < ActiveRecord::Observer + + def after_save(an_instance) + if an_instance.changed? + change = an_instance.changes['state'] + if change + update_timestamps(change[0], change[1], an_instance) + end + end + end + + def update_timestamps(state_from, state_to, an_instance) + if state_to == Instance::STATE_RUNNING + an_instance.time_last_start = Time.now + elsif state_from == Instance::STATE_RUNNING && state_to == Instance::STATE_STOPPED + an_instance.acc_run_time = an_instance.acc_run_time + (Time.now - an_instance.time_last_start) + end + end + +end + +InstanceObserver.instance \ No newline at end of file diff --git a/src/app/models/task_observer.rb b/src/app/models/task_observer.rb index 3e2d803..ca11bc1 100644 --- a/src/app/models/task_observer.rb +++ b/src/app/models/task_observer.rb @@ -9,7 +9,6 @@ class TaskObserver < ActiveRecord::Observer end
def update_timestamp(state_from, state_to, a_task) - puts state_to if state_to == Task::STATE_RUNNING a_task.time_started = Time.now elsif state_to == Task::STATE_PENDING diff --git a/src/db/migrate/20090804142049_create_instances.rb b/src/db/migrate/20090804142049_create_instances.rb index 714a7e4..a571b68 100644 --- a/src/db/migrate/20090804142049_create_instances.rb +++ b/src/db/migrate/20090804142049_create_instances.rb @@ -21,18 +21,20 @@
class CreateInstances < ActiveRecord::Migration def self.up - create_table :instances do |t| - t.string :external_key - t.string :name, :null => false, :limit => 1024 - t.integer :hardware_profile_id, :null => false - t.integer :image_id, :null => false - t.integer :realm_id - t.integer :pool_id, :null => false - t.integer :cloud_account_id - t.string :public_address - t.string :private_address - t.string :state - t.integer :lock_version, :default => 0 + create_table :instances do |t| + t.string :external_key + t.string :name, :null => false, :limit => 1024 + t.integer :hardware_profile_id, :null => false + t.integer :image_id, :null => false + t.integer :realm_id + t.integer :pool_id, :null => false + t.integer :cloud_account_id + t.string :public_address + t.string :private_address + t.string :state + t.integer :lock_version, :default => 0 + t.integer :acc_run_time, :default => 0 + t.timestamp :time_last_start t.timestamps end end diff --git a/src/spec/factories/instance.rb b/src/spec/factories/instance.rb index 0cd1ea2..12156ec 100644 --- a/src/spec/factories/instance.rb +++ b/src/spec/factories/instance.rb @@ -6,3 +6,7 @@ Factory.define :instance do |i| i.pool_id 1 i.state "running" end + +Factory.define :pending_instance, :parent => :instance do |pi| + pi.state "pending" +end \ No newline at end of file diff --git a/src/spec/models/instance_observer_spec.rb b/src/spec/models/instance_observer_spec.rb new file mode 100644 index 0000000..65e0d50 --- /dev/null +++ b/src/spec/models/instance_observer_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe InstanceObserver do + + before(:each) do + @timestamp = Time.now + @instance = Factory :pending_instance + end + + it "should set started at timestamp when instance goes to state running" do + @instance.state = Instance::STATE_RUNNING + @instance.save + + @instance.time_last_start.should >= @timestamp + end + + it "should set accumlated run time when instance goes to from state running to state stopped" do + @instance.state = Instance::STATE_RUNNING + @instance.save; + + sleep(2) + + @instance.state = Instance::STATE_STOPPED + @instance.save + + @instance.acc_run_time.should >= 2 + end + +end \ No newline at end of file
From: martyntaylor mtaylor@redhat.com
--- src/app/models/task_observer.rb | 7 ++++++- src/spec/models/task_observer_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/src/app/models/task_observer.rb b/src/app/models/task_observer.rb index ca11bc1..d1834c4 100644 --- a/src/app/models/task_observer.rb +++ b/src/app/models/task_observer.rb @@ -1,5 +1,8 @@ class TaskObserver < ActiveRecord::Observer - def after_save(a_task) + + END_STATES = [ Task::STATE_CANCELED, Task::STATE_FAILED, Task::STATE_FINISHED ] + + def after_save(a_task) if a_task.changed? change = a_task.changes['state'] if change @@ -13,6 +16,8 @@ class TaskObserver < ActiveRecord::Observer a_task.time_started = Time.now elsif state_to == Task::STATE_PENDING a_task.time_submitted = Time.now + elsif END_STATES.include?(state_to) + a_task.time_ended = Time.now end end
diff --git a/src/spec/models/task_observer_spec.rb b/src/spec/models/task_observer_spec.rb index 5d31693..98f899a 100644 --- a/src/spec/models/task_observer_spec.rb +++ b/src/spec/models/task_observer_spec.rb @@ -21,4 +21,25 @@ describe TaskObserver do @task.time_submitted.should >= @timestamp end
+ it "should set ended timestamp when the task has finished" do + @task.state = Task::STATE_FINISHED + @task.save + + @task.time_ended.should >= @timestamp + end + + it "should set ended timestamp when the task is cancelled" do + @task.state = Task::STATE_CANCELED + @task.save + + @task.time_ended.should >= @timestamp + end + + it "should set ended timestamp when the task has failed" do + @task.state = Task::STATE_FAILED + @task.save + + @task.time_ended.should >= @timestamp + end + end \ No newline at end of file
From: martyntaylor mtaylor@redhat.com
--- src/app/models/task.rb | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/src/app/models/task.rb b/src/app/models/task.rb index 9f23ef2..5c5bf34 100644 --- a/src/app/models/task.rb +++ b/src/app/models/task.rb @@ -95,7 +95,11 @@ class Task < ActiveRecord::Base end
def submission_time - time.started - time.submitted + time_started - time_submitted + end + + def runtime + time_ended - time_started end
def validate
From: martyntaylor mtaylor@redhat.com
--- src/app/models/task.rb | 10 ++++++++++ src/db/migrate/20090831140000_create_tasks.rb | 1 + 2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/src/app/models/task.rb b/src/app/models/task.rb index 5c5bf34..f3aaa63 100644 --- a/src/app/models/task.rb +++ b/src/app/models/task.rb @@ -38,6 +38,16 @@ class Task < ActiveRecord::Base COMPLETED_STATES = [STATE_FINISHED, STATE_FAILED, STATE_CANCELED] WORKING_STATES = [STATE_QUEUED, STATE_RUNNING, STATE_PAUSED, STATE_PENDING]
+ # Failures Codes + FAILURE_PROVIDER_NOT_FOUND = "provider_not_found" + FAILURE_PROVIDER_CONTACT_FAILED = "provider_contact_failed" + FAILURE_PROVIDER_RETURNED_FAILED = "provider_returned_failed" + + FAILURE_CODES = [FAILURE_PROVIDER_NOT_FOUND, FAILURE_PROVIDER_CONTACT_FAILED, FAILURE_PROVIDER_RETURNED_FAILED] + + validates_inclusion_of :failure_code, + :in => FAILURE_CODES + [nil] + validates_inclusion_of :type, :in => %w( InstanceTask )
diff --git a/src/db/migrate/20090831140000_create_tasks.rb b/src/db/migrate/20090831140000_create_tasks.rb index 2c3e0e2..612b0b5 100644 --- a/src/db/migrate/20090831140000_create_tasks.rb +++ b/src/db/migrate/20090831140000_create_tasks.rb @@ -32,6 +32,7 @@ class CreateTasks < ActiveRecord::Migration t.timestamp :time_started t.timestamp :time_ended t.text :message + t.string :failure_code t.integer :lock_version, :default => 0 end end
From: martyntaylor mtaylor@redhat.com
--- src/app/models/instance.rb | 49 ++++++++++++-- src/app/models/instance_observer.rb | 22 +++++-- src/db/migrate/20090804142049_create_instances.rb | 10 +++- src/spec/factories/instance.rb | 8 ++- src/spec/models/instance_observer_spec.rb | 70 +++++++++++++++++++-- src/spec/models/instance_spec.rb | 23 +++++++ 6 files changed, 160 insertions(+), 22 deletions(-)
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb index 25d17bd..07d0784 100644 --- a/src/app/models/instance.rb +++ b/src/app/models/instance.rb @@ -52,10 +52,12 @@ class Instance < ActiveRecord::Base STATE_STOPPED = "stopped" STATE_CREATE_FAILED = "create_failed"
- validates_inclusion_of :state, - :in => [STATE_NEW, STATE_PENDING, STATE_RUNNING, + STATES = [STATE_NEW, STATE_PENDING, STATE_RUNNING, STATE_SHUTTING_DOWN, STATE_STOPPED, STATE_CREATE_FAILED]
+ validates_inclusion_of :state, + :in => STATES + def get_action_list(user=nil) # return empty list rather than nil # FIXME: not handling pending state now -- only current state @@ -101,11 +103,44 @@ class Instance < ActiveRecord::Base self.realm = provider.realms.find_by_name(realm_name) unless realm_name.nil? end
- def total_run_time - if state == STATE_RUNNING - acc_run_time + (Time.now - time_last_start) - else - acc_run_time + # Returns the total time that this instance has been in the state + def total_state_time(state) + + if !STATES.include?(state) + return "Error, could not calculate state time: invalid state" + end + + case state + when STATE_PENDING + if self.state == STATE_PENDING + return acc_pending_time + (Time.now - time_last_pending) + else + return acc_pending_time + end + + when STATE_RUNNING + if self.state == STATE_RUNNING + return acc_running_time + (Time.now - time_last_running) + else + return acc_running_time + end + + when STATE_SHUTTING_DOWN + if self.state == STATE_SHUTTING_DOWN + return acc_shutting_down_time + (Time.now - time_last_shutting_down) + else + return acc_shutting_down_time + end + + when STATE_STOPPED + if self.state == STATE_STOPPED + return acc_stopped_time + (Time.now - time_last_stopped) + else + return acc_stopped_time + end + + else + return "Error, could not calculate state time: state is not monitored" end end
diff --git a/src/app/models/instance_observer.rb b/src/app/models/instance_observer.rb index 81e75ea..283991d 100644 --- a/src/app/models/instance_observer.rb +++ b/src/app/models/instance_observer.rb @@ -4,19 +4,29 @@ class InstanceObserver < ActiveRecord::Observer if an_instance.changed? change = an_instance.changes['state'] if change - update_timestamps(change[0], change[1], an_instance) + update_state_timestamps(change[1], an_instance) + update_accumulative_state_time(change[0], an_instance) end end end
- def update_timestamps(state_from, state_to, an_instance) - if state_to == Instance::STATE_RUNNING - an_instance.time_last_start = Time.now - elsif state_from == Instance::STATE_RUNNING && state_to == Instance::STATE_STOPPED - an_instance.acc_run_time = an_instance.acc_run_time + (Time.now - an_instance.time_last_start) + def update_state_timestamps(state_to, an_instance) + case state_to + when Instance::STATE_PENDING then an_instance.time_last_pending = Time.now + when Instance::STATE_RUNNING then an_instance.time_last_running = Time.now + when Instance::STATE_SHUTTING_DOWN then an_instance.time_last_shutting_down = Time.now + when Instance::STATE_STOPPED then an_instance.time_last_stopped = Time.now end end
+ def update_accumulative_state_time(state_from, an_instance) + case state_from + when Instance::STATE_PENDING then an_instance.acc_pending_time += Time.now - an_instance.time_last_pending + when Instance::STATE_RUNNING then an_instance.acc_running_time += Time.now - an_instance.time_last_running + when Instance::STATE_SHUTTING_DOWN then an_instance.acc_shutting_down_time += Time.now - an_instance.time_last_shutting_down + when Instance::STATE_STOPPED then an_instance.acc_stopped_time += Time.now - an_instance.time_last_stopped + end + end end
InstanceObserver.instance \ No newline at end of file diff --git a/src/db/migrate/20090804142049_create_instances.rb b/src/db/migrate/20090804142049_create_instances.rb index a571b68..335b93f 100644 --- a/src/db/migrate/20090804142049_create_instances.rb +++ b/src/db/migrate/20090804142049_create_instances.rb @@ -33,8 +33,14 @@ class CreateInstances < ActiveRecord::Migration t.string :private_address t.string :state t.integer :lock_version, :default => 0 - t.integer :acc_run_time, :default => 0 - t.timestamp :time_last_start + t.integer :acc_pending_time, :default => 0 + t.integer :acc_running_time, :default => 0 + t.integer :acc_shutting_down_time, :default => 0 + t.integer :acc_stopped_time, :default => 0 + t.timestamp :time_last_pending + t.timestamp :time_last_running + t.timestamp :time_last_shutting_down + t.timestamp :time_last_stopped t.timestamps end end diff --git a/src/spec/factories/instance.rb b/src/spec/factories/instance.rb index 12156ec..3a453c3 100644 --- a/src/spec/factories/instance.rb +++ b/src/spec/factories/instance.rb @@ -7,6 +7,10 @@ Factory.define :instance do |i| i.state "running" end
-Factory.define :pending_instance, :parent => :instance do |pi| - pi.state "pending" +Factory.define :pending_instance, :parent => :instance do |i| + i.state Instance::STATE_PENDING +end + +Factory.define :new_instance, :parent => :instance do |i| + i.state Instance::STATE_NEW end \ No newline at end of file diff --git a/src/spec/models/instance_observer_spec.rb b/src/spec/models/instance_observer_spec.rb index 65e0d50..9e3dcc7 100644 --- a/src/spec/models/instance_observer_spec.rb +++ b/src/spec/models/instance_observer_spec.rb @@ -4,26 +4,86 @@ describe InstanceObserver do
before(:each) do @timestamp = Time.now - @instance = Factory :pending_instance + @instance = Factory :new_instance + end + + it "should set started at timestamp when instance goes to state pending" do + @instance.state = Instance::STATE_PENDING + @instance.save + + @instance.time_last_pending.should >= @timestamp end
it "should set started at timestamp when instance goes to state running" do @instance.state = Instance::STATE_RUNNING @instance.save
- @instance.time_last_start.should >= @timestamp + @instance.time_last_running.should >= @timestamp + end + + it "should set started at timestamp when instance goes to state shutting down" do + @instance.state = Instance::STATE_SHUTTING_DOWN + @instance.save + + @instance.time_last_shutting_down.should >= @timestamp + end + + it "should set started at timestamp when instance goes to state stopped" do + @instance.state = Instance::STATE_STOPPED + @instance.save + + @instance.time_last_stopped.should >= @timestamp end
- it "should set accumlated run time when instance goes to from state running to state stopped" do + it "should set accumlated pending time when instance changes state from state pending" do + @instance.state = Instance::STATE_PENDING + @instance.save + + sleep(1) + @instance.state = Instance::STATE_RUNNING + @instance.save + + @instance.acc_pending_time.should >= 1 + @instance.acc_pending_time.should <= 2 + end + + it "should set accumlated running time when instance changes state from state running" do + @instance.state = Instance::STATE_RUNNING + @instance.save + + sleep(1) + + @instance.state = Instance::STATE_SHUTTING_DOWN + @instance.save + + @instance.acc_running_time.should >= 1 + @instance.acc_running_time.should <= 2 + end + + it "should set accumlated shutting down time when instance changes state from state shutting down" do + @instance.state = Instance::STATE_SHUTTING_DOWN @instance.save;
- sleep(2) + sleep(1)
@instance.state = Instance::STATE_STOPPED @instance.save
- @instance.acc_run_time.should >= 2 + @instance.acc_shutting_down_time.should >= 1 + @instance.acc_shutting_down_time.should <= 2 end
+ it "should set accumlated stopped time when instance changes state from state stopped" do + @instance.state = Instance::STATE_STOPPED + @instance.save + + sleep(1) + + @instance.state = Instance::STATE_PENDING + @instance.save + + @instance.acc_stopped_time.should >= 1 + @instance.acc_stopped_time.should <= 2 + end end \ No newline at end of file diff --git a/src/spec/models/instance_spec.rb b/src/spec/models/instance_spec.rb index afdc0e0..0eaf837 100644 --- a/src/spec/models/instance_spec.rb +++ b/src/spec/models/instance_spec.rb @@ -111,5 +111,28 @@ describe Instance do @instance.front_end_realm.should eql('mock2:john doe/different realm') end
+ it "should properly calculate the total time that the instance has been in a monitored state" do + instance = Factory :new_instance + + [ Instance::STATE_PENDING, Instance::STATE_RUNNING, Instance::STATE_SHUTTING_DOWN, Instance::STATE_STOPPED ].each do |s| + # Test when instance is still in the same state + instance.state = s + instance.save + + sleep(2) + + instance.total_state_time(s).should >= 2 + instance.total_state_time(s).should <= 3 + + # Test when instance has changed state + sleep(1) + instance.state = Instance::STATE_NEW + instance.save + sleep(1) + + instance.total_state_time(s).should >= 3 + instance.total_state_time(s).should <= 4 + end + end
end
From: martyntaylor mtaylor@redhat.com
--- src/app/models/instance_observer.rb | 2 +- src/app/models/task_observer.rb | 2 +- src/app/util/taskomatic.rb | 16 +++++++++++----- src/config/environment.rb | 4 +++- 4 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/app/models/instance_observer.rb b/src/app/models/instance_observer.rb index 283991d..fa5b3d2 100644 --- a/src/app/models/instance_observer.rb +++ b/src/app/models/instance_observer.rb @@ -1,6 +1,6 @@ class InstanceObserver < ActiveRecord::Observer
- def after_save(an_instance) + def before_save(an_instance) if an_instance.changed? change = an_instance.changes['state'] if change diff --git a/src/app/models/task_observer.rb b/src/app/models/task_observer.rb index d1834c4..98252b0 100644 --- a/src/app/models/task_observer.rb +++ b/src/app/models/task_observer.rb @@ -2,7 +2,7 @@ class TaskObserver < ActiveRecord::Observer
END_STATES = [ Task::STATE_CANCELED, Task::STATE_FAILED, Task::STATE_FINISHED ]
- def after_save(a_task) + def before_save(a_task) if a_task.changed? change = a_task.changes['state'] if change diff --git a/src/app/util/taskomatic.rb b/src/app/util/taskomatic.rb index e66bb62..22328dc 100644 --- a/src/app/util/taskomatic.rb +++ b/src/app/util/taskomatic.rb @@ -45,8 +45,6 @@ class Taskomatic
def instance_create
- @task.time_started = Time.now - begin client = @task.instance.cloud_account.connect realm = @task.instance.realm.external_key rescue nil @@ -55,9 +53,13 @@ class Taskomatic unless @task.instance.image.provider_image? @task.instance.image = @task.instance.image.provider_images[0] end + unless @task.instance.hardware_profile.provider_hardware_profile? @task.instance.hardware_profile = @task.instance.hardware_profile.provider_hardware_profiles[0] end + + @task.state = Task::STATE_PENDING + @task.save! dcloud_instance = client.create_instance(@task.instance.image.external_key, :flavor => @task.instance.hardware_profile.external_key, :realm => realm, @@ -65,6 +67,11 @@ class Taskomatic if dcloud_instance.class == Net::HTTPInternalServerError @task.instance.state = Instance::STATE_CREATE_FAILED raise "Error creating dcloud instance, returned internal server error." + @task.state = TASK::STATE_FAILED + @task.failure_code = Task::FAILURE_PROVIDER_CONTACT_FAILED + else + @task.state = Task::STATE_RUNNING + @task.save! end
@logger.info "Task instance create completed with key #{dcloud_instance.id} and state #{dcloud_instance.state}" @@ -77,7 +84,7 @@ class Taskomatic else @task.state = Task::STATE_FINISHED end - @task.time_ended = Time.now + @task.save! end
@@ -153,5 +160,4 @@ class Taskomatic end end end -end - +end \ No newline at end of file diff --git a/src/config/environment.rb b/src/config/environment.rb index 141642b..1721126 100644 --- a/src/config/environment.rb +++ b/src/config/environment.rb @@ -40,13 +40,14 @@ Rails::Initializer.run do |config| # config.gem "bj" # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" # config.gem "aws-s3", :lib => "aws/s3" - config.gem "gettext", :lib => "gettext_rails" + config.gem "gettext", :lib => "gettext_rails" config.gem "gettext", :lib => "gettext_activerecord" config.gem "authlogic" config.gem "deltacloud-client", :lib => "deltacloud" config.gem "haml" config.gem "will_paginate"
+ config.active_record.observers = :instance_observer, :task_observer # Only load the plugins named here, in the order given. By default, all plugins # in vendor/plugins are loaded in alphabetical order. # :all can be used as a placeholder for all plugins not explicitly named @@ -75,4 +76,5 @@ Rails::Initializer.run do |config| # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] # config.i18n.default_locale = :de + end
On Fri, May 21, 2010 at 03:46:17PM +0100, mtaylor@redhat.com wrote:
From: martyntaylor mtaylor@redhat.com
src/app/models/instance_observer.rb | 2 +- src/app/models/task_observer.rb | 2 +- src/app/util/taskomatic.rb | 16 +++++++++++----- src/config/environment.rb | 4 +++- 4 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/app/models/instance_observer.rb b/src/app/models/instance_observer.rb index 283991d..fa5b3d2 100644 --- a/src/app/models/instance_observer.rb +++ b/src/app/models/instance_observer.rb @@ -1,6 +1,6 @@ class InstanceObserver < ActiveRecord::Observer
- def after_save(an_instance)
- def before_save(an_instance) if an_instance.changed? change = an_instance.changes['state'] if change
diff --git a/src/app/models/task_observer.rb b/src/app/models/task_observer.rb index d1834c4..98252b0 100644 --- a/src/app/models/task_observer.rb +++ b/src/app/models/task_observer.rb @@ -2,7 +2,7 @@ class TaskObserver < ActiveRecord::Observer
END_STATES = [ Task::STATE_CANCELED, Task::STATE_FAILED, Task::STATE_FINISHED ]
- def after_save(a_task)
- def before_save(a_task) if a_task.changed? change = a_task.changes['state'] if change
diff --git a/src/app/util/taskomatic.rb b/src/app/util/taskomatic.rb index e66bb62..22328dc 100644 --- a/src/app/util/taskomatic.rb +++ b/src/app/util/taskomatic.rb @@ -45,8 +45,6 @@ class Taskomatic
def instance_create
- @task.time_started = Time.now
- begin client = @task.instance.cloud_account.connect realm = @task.instance.realm.external_key rescue nil
@@ -55,9 +53,13 @@ class Taskomatic unless @task.instance.image.provider_image? @task.instance.image = @task.instance.image.provider_images[0] end
unless @task.instance.hardware_profile.provider_hardware_profile? @task.instance.hardware_profile = @task.instance.hardware_profile.provider_hardware_profiles[0] end
@task.state = Task::STATE_PENDING
@task.save! dcloud_instance = client.create_instance(@task.instance.image.external_key, :flavor => @task.instance.hardware_profile.external_key, :realm => realm,
@@ -65,6 +67,11 @@ class Taskomatic if dcloud_instance.class == Net::HTTPInternalServerError @task.instance.state = Instance::STATE_CREATE_FAILED raise "Error creating dcloud instance, returned internal server error."
@task.state = TASK::STATE_FAILED
@task.failure_code = Task::FAILURE_PROVIDER_CONTACT_FAILED
else
@task.state = Task::STATE_RUNNING
@task.save! end @logger.info "Task instance create completed with key #{dcloud_instance.id} and state #{dcloud_instance.state}"
@@ -77,7 +84,7 @@ class Taskomatic else @task.state = Task::STATE_FINISHED end
- @task.time_ended = Time.now
- @task.save! end
@@ -153,5 +160,4 @@ class Taskomatic end end end -end
+end \ No newline at end of file diff --git a/src/config/environment.rb b/src/config/environment.rb index 141642b..1721126 100644 --- a/src/config/environment.rb +++ b/src/config/environment.rb @@ -40,13 +40,14 @@ Rails::Initializer.run do |config| # config.gem "bj" # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" # config.gem "aws-s3", :lib => "aws/s3"
- config.gem "gettext", :lib => "gettext_rails"
config.gem "gettext", :lib => "gettext_rails" config.gem "gettext", :lib => "gettext_activerecord" config.gem "authlogic" config.gem "deltacloud-client", :lib => "deltacloud" config.gem "haml" config.gem "will_paginate"
config.active_record.observers = :instance_observer, :task_observer # Only load the plugins named here, in the order given. By default, all plugins # in vendor/plugins are loaded in alphabetical order. # :all can be used as a placeholder for all plugins not explicitly named
@@ -75,4 +76,5 @@ Rails::Initializer.run do |config| # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] # config.i18n.default_locale = :de
end
1.6.6.1
deltacloud-devel mailing list deltacloud-devel@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/deltacloud-devel
ACK on series 1-7, with replacement 7/7 as sent, once it's all rebased to apply to 'next' :)
Thanks! Steve
deltacloud-devel@lists.fedorahosted.org