Created
November 4, 2013 19:44
-
-
Save andry1/7308125 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# HOW TO USE: | |
# | |
# $ gem install activerecord | |
# $ irb | |
# irb> require './oozie_db.rb' | |
# irb> coord = Coordinator.find("BIG-LONG-ID-C") | |
# irb> coord.coordinator_actions.map(&:missing_dependencies).select {|d| d != ""} # => Find all actions with missing dependencies | |
# | |
# That last one can be done better by using the ActiveRecord to do the filtering DB-side, but i'm in a hurry | |
gem 'activerecord' | |
gem 'log4r' | |
gem 'activesupport' | |
require 'active_record' | |
require 'log4r' | |
require 'active_support' | |
ActiveRecord::Base.logger = Log4r::Logger.new('OozieDB') | |
ActiveRecord::Base.logger.trace = true | |
ActiveRecord::Base.logger.add(Log4r::Outputter.stderr) | |
ActiveRecord::Base.establish_connection( | |
adapter: 'mysql2', | |
host: 'oj01.ny7.collective-media.net', | |
username: 'oozie', | |
password: 'cruse24{ACTH', | |
database: 'oozie' | |
) | |
class Workflow < ActiveRecord::Base | |
self.table_name = "WF_JOBS" | |
has_many :workflow_actions, :foreign_key => "wf_id" | |
has_many :sla_events, :through => :coordinator_actions | |
belongs_to :coordinator_action, :foreign_key => "parent_id" | |
delegate :coordinator, to: :coordinator_action, allow_nil: true | |
end | |
class WorkflowAction < ActiveRecord::Base | |
self.inheritance_column = "inheritance_type" | |
self.table_name = "WF_ACTIONS" | |
belongs_to :workflow, :foreign_key => "wf_id" | |
has_many :sla_events, :foreign_key => "sla_id" | |
end | |
class Bundle < ActiveRecord::Base | |
self.table_name = "BUNDLE_JOBS" | |
has_many :bundle_actions, :primary_key => "bundle_action_id" | |
end | |
class BundleAction < ActiveRecord::Base | |
self.table_name = "BUNDLE_ACTIONS" | |
self.primary_key = "bundle_action_id" | |
belongs_to :bundle | |
belongs_to :coordinator, :foreign_key => "coord_id" | |
has_many :sla_events, :foreign_key => "sla_id" | |
end | |
class Coordinator < ActiveRecord::Base | |
self.table_name = "COORD_JOBS" | |
has_one :bundle_action, :foreign_key => "coord_id", :primary_key => "bundle_action_id" | |
belongs_to :bundle | |
has_many :coordinator_actions, :foreign_key => "job_id" | |
has_many :sla_events, :through => :coordinator_actions | |
end | |
class CoordinatorAction < ActiveRecord::Base | |
self.table_name = "COORD_ACTIONS" | |
has_one :workflow, :foreign_key => "parent_id" | |
belongs_to :coordinator, :foreign_key => "job_id" | |
delegate :bundle, to: :coordinator, allow_nil: true | |
has_many :sla_events, :foreign_key => "sla_id" | |
end | |
class SlaEvent < ActiveRecord::Base | |
self.primary_key = "event_id" | |
self.table_name = "SLA_EVENTS" | |
belongs_to :coordinator_action, :foreign_key => "sla_id" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment