From: Jan Provaznik jprovazn@redhat.com
Replaces InstanceEvent model by more general polymorphic model. For now only instances are associated with events. --- src/app/models/event.rb | 26 ++++++++++++++++++++++++++ src/app/models/instance.rb | 1 + src/app/models/instance_event.rb | 26 -------------------------- src/db/migrate/20110201132528_events.rb | 26 ++++++++++++++++++++++++++ src/dbomatic/dbomatic | 6 ++---- 5 files changed, 55 insertions(+), 30 deletions(-) create mode 100644 src/app/models/event.rb delete mode 100644 src/app/models/instance_event.rb create mode 100644 src/db/migrate/20110201132528_events.rb
diff --git a/src/app/models/event.rb b/src/app/models/event.rb new file mode 100644 index 0000000..91c64a2 --- /dev/null +++ b/src/app/models/event.rb @@ -0,0 +1,26 @@ +# Copyright (C) 2010 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html. + +# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers. + +class Event < ActiveRecord::Base + belongs_to :source, :polymorphic => true + + validates_presence_of :source_id + validates_presence_of :source_type +end diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb index b84a596..3ae921d 100644 --- a/src/app/models/instance.rb +++ b/src/app/models/instance.rb @@ -48,6 +48,7 @@ class Instance < ActiveRecord::Base has_many :permissions, :as => :permission_object, :dependent => :destroy, :include => [:role], :order => "permissions.id ASC" + has_many :events, :as => :source, :dependent => :destroy
validates_presence_of :pool_id validates_presence_of :hardware_profile_id diff --git a/src/app/models/instance_event.rb b/src/app/models/instance_event.rb deleted file mode 100644 index 5076f8a..0000000 --- a/src/app/models/instance_event.rb +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (C) 2010 Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -# MA 02110-1301, USA. A copy of the GNU General Public License is -# also available at http://www.gnu.org/copyleft/gpl.html. - -# Filters added to this controller apply to all controllers in the application. -# Likewise, all the methods added will be available for all controllers. - -class InstanceEvent < ActiveRecord::Base - belongs_to :instance - - validates_presence_of :instance_id - validates_presence_of :event_type -end diff --git a/src/db/migrate/20110201132528_events.rb b/src/db/migrate/20110201132528_events.rb new file mode 100644 index 0000000..8af7137 --- /dev/null +++ b/src/db/migrate/20110201132528_events.rb @@ -0,0 +1,26 @@ +class Events < ActiveRecord::Migration + def self.up + drop_table :instance_events + create_table :events do |t| + t.integer :source_id, :null => false + t.string :source_type, :null => false + t.datetime :event_time + t.string :status_code + t.string :summary + t.string :description + t.timestamps + end + end + + def self.down + drop_table :events + create_table :instance_events do |t| + t.integer :instance_id, :null => false + t.string :event_type, :null => false + t.datetime :event_time + t.string :status + t.string :message + t.timestamps + end + end +end diff --git a/src/dbomatic/dbomatic b/src/dbomatic/dbomatic index 8a3e968..bf3a987 100755 --- a/src/dbomatic/dbomatic +++ b/src/dbomatic/dbomatic @@ -163,10 +163,8 @@ class CondorEventLog < Nokogiri::XML::SAX::Document
begin inst.save! - - InstanceEvent.create! :instance => inst, - :event_type => inst.state, - :event_time => @event_time + inst.events.create!(:status_code => inst.state, + :event_time => @event_time) rescue => e @logger.error "#{e.backtrace.shift}: #{e.message}" e.backtrace.each do |step|