From: Jan Provaznik <[email protected]>

Replaces InstanceEvent model. For now only instances are associated with events.
---
 src/app/models/event.rb                            |   26 ++++++++++++++
 src/app/models/instance.rb                         |    2 +
 src/app/models/instance_event.rb                   |   26 --------------
 src/db/migrate/20100810221250_create_events.rb     |   35 ++++++++++++++++++++
 .../20100810221250_create_instance_events.rb       |   34 -------------------
 src/dbomatic/dbomatic                              |    6 +--
 6 files changed, 65 insertions(+), 64 deletions(-)
 create mode 100644 src/app/models/event.rb
 delete mode 100644 src/app/models/instance_event.rb
 create mode 100644 src/db/migrate/20100810221250_create_events.rb
 delete mode 100644 src/db/migrate/20100810221250_create_instance_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 22069e2..2b890fa 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -35,6 +35,8 @@ class Instance < ActiveRecord::Base
   belongs_to :owner, :class_name => "User", :foreign_key => "owner_id"
   belongs_to :instance_key
 
+  has_many :events, :as => :source, :dependent => :destroy
+
   validates_presence_of :pool_id
   validates_presence_of :hardware_profile_id
   validates_presence_of :template_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/20100810221250_create_events.rb 
b/src/db/migrate/20100810221250_create_events.rb
new file mode 100644
index 0000000..e485f89
--- /dev/null
+++ b/src/db/migrate/20100810221250_create_events.rb
@@ -0,0 +1,35 @@
+# Copyright (C) 2010 Red Hat, Inc.
+# Written by Mohammed Morsi <[email protected]>
+#
+# 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.
+
+class CreateEvents < ActiveRecord::Migration
+  def self.up
+    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
+  end
+end
diff --git a/src/db/migrate/20100810221250_create_instance_events.rb 
b/src/db/migrate/20100810221250_create_instance_events.rb
deleted file mode 100644
index 22e5191..0000000
--- a/src/db/migrate/20100810221250_create_instance_events.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# Copyright (C) 2010 Red Hat, Inc.
-# Written by Mohammed Morsi <[email protected]>
-#
-# 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.
-
-class CreateInstanceEvents < ActiveRecord::Migration
-  def self.up
-    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
-
-  def self.down
-    drop_table :instance_events
-  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|
-- 
1.7.2.3

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to