This patch contains the rough first pass of dbomatic's implementation. There are various things TBD such as event error handling and making sure all the correct events are collected with all their metadata but what is present should be a rough estimate as to the parsing strategy.
To get condor to yield the neccessary info for dbomatic to parse, add the following to /var/lib/condor/condor_config.local EVENT_LOG=$(LOG)/EventLog EVENT_LOG_USE_XML=True EVENT_LOG_JOB_AD_INFORMATION_ATTRS=Owner,GlobalJobId,Cmd,JobStartDate,JobCurrentStartDate,JobFinishedHookDone Also be sure to set CONDOR_HOST appropriately (I merely set it to 'localhost' in my case). A condor restart is required (eg sudo service condor restart) after these changes. --- src/app/models/instance_event.rb | 30 +++++++ .../20100810221250_create_instance_events.rb | 34 ++++++++ src/dbomatic/dbomatic.rb | 90 ++++++++++++++++++++ 3 files changed, 154 insertions(+), 0 deletions(-) create mode 100644 src/app/models/instance_event.rb create mode 100644 src/db/migrate/20100810221250_create_instance_events.rb create mode 100644 src/dbomatic/dbomatic.rb diff --git a/src/app/models/instance_event.rb b/src/app/models/instance_event.rb new file mode 100644 index 0000000..cc1eaa0 --- /dev/null +++ b/src/app/models/instance_event.rb @@ -0,0 +1,30 @@ +# 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 + + #validates_inclusion_of :event_type, + # :in => TYPES + +end diff --git a/src/db/migrate/20100810221250_create_instance_events.rb b/src/db/migrate/20100810221250_create_instance_events.rb new file mode 100644 index 0000000..22e5191 --- /dev/null +++ b/src/db/migrate/20100810221250_create_instance_events.rb @@ -0,0 +1,34 @@ +# Copyright (C) 2010 Red Hat, Inc. +# Written by Mohammed Morsi <mmo...@redhat.com> +# +# 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.rb b/src/dbomatic/dbomatic.rb new file mode 100644 index 0000000..8b80c81 --- /dev/null +++ b/src/dbomatic/dbomatic.rb @@ -0,0 +1,90 @@ +# Copyright (C) 2010 Red Hat, Inc. +# Written by Mohammed Morsi <mmo...@redhat.com> +# +# 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. + +$: << File.join(File.dirname(__FILE__), "../dutils") +require 'dutils' +require 'nokogiri' + +# Handle the event log's xml +class CondorEventLog < Nokogiri::XML::SAX::Document + attr_accessor :tag, :event_type, :event_cmd, :event_time + + # Store the name of the event log attribute we're looking at + def start_element(element, attributes) + @tag = attributes[1] if element == "a" + end + + # Store the value of the event log attribute we're looking at + def characters(string) + unless string.strip == "" + if @tag == "MyType" + @event_type = string + elsif @tag == "Cmd" + @event_cmd = string + elsif @tag == "EventTime" + @event_time = string + end + end + end + + # Create a new entry for events which we have all the neccessary data for + def end_element(element) + if element == "c" && !...@event_cmd.nil? + inst = Instance.find(:first, :conditions => ['condor_job_id = ?', @event_cmd]) + #puts "Instance event #{inst.name} #...@event_type} #...@event_time}" + InstanceEvent.create! :instance => inst, + :event_type => @event_type, + :event_time => @event_time + @tag = @event_type = @event_cmd = @event_time = nil + end + end +end +parser = Nokogiri::XML::SAX::PushParser.new(CondorEventLog.new) + +# XXX bit of a hack, condor event log doesn't seem to have a top level element +# enclosing everything else in the doc (as standards conforming xml must). +# Create one for parsing purposes. +parser << "<events>" + +# last time the event log was modified +event_log_timestamp = nil + +# last position we've read in the log +event_log_position = 0 + +# set true to terminate dbomatic +terminate = false +until terminate + log_file = File.open("/var/log/condor/EventLog") + + # Condor seems to open / close the event log for every + # entry. Simply poll for new data in the log + unless log_file.mtime == event_log_timestamp + event_log_timestamp = log_file.mtime + log_file.pos = event_log_position + while c = log_file.getc + parser << c.chr + end + event_log_position = log_file.pos + end + + sleep 1 +end + +parser << "</events>" +parser.finish -- 1.7.2 _______________________________________________ deltacloud-devel mailing list deltacloud-devel@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/deltacloud-devel