Class: Jkr::Plan

Inherits:
Object
  • Object
show all
Defined in:
lib/jkr/plan.rb

Defined Under Namespace

Classes: PlanLoader

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jkr_env) ⇒ Plan

Returns a new instance of Plan.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jkr/plan.rb', line 41

def initialize(jkr_env)
  @base_plan = nil
  @used_scripts = []
  @jkr_env = jkr_env
  @metastore = Hash.new

  @title = "no title"
  @desc = "no desc"
  @short_desc = nil
  @plan_name = plan_name

  @params = {}
  @vars = {}
  @routine = nil
  @routine_nr_run = 1
  @prep = nil
  @cleanup = nil
  @param_filters = []

  @src = nil
end

Instance Attribute Details

#analysisObject

Returns the value of attribute analysis.



31
32
33
# File 'lib/jkr/plan.rb', line 31

def analysis
  @analysis
end

#base_planObject

Returns the value of attribute base_plan.



19
20
21
# File 'lib/jkr/plan.rb', line 19

def base_plan
  @base_plan
end

#cleanupObject

Returns the value of attribute cleanup.



28
29
30
# File 'lib/jkr/plan.rb', line 28

def cleanup
  @cleanup
end

#descObject

Returns the value of attribute desc.



11
12
13
# File 'lib/jkr/plan.rb', line 11

def desc
  @desc
end

#exec_time_estimateObject

Returns the value of attribute exec_time_estimate.



33
34
35
# File 'lib/jkr/plan.rb', line 33

def exec_time_estimate
  @exec_time_estimate
end

#file_pathObject

Returns the value of attribute file_path.



37
38
39
# File 'lib/jkr/plan.rb', line 37

def file_path
  @file_path
end

#jkr_envObject (readonly)

Returns the value of attribute jkr_env.



38
39
40
# File 'lib/jkr/plan.rb', line 38

def jkr_env
  @jkr_env
end

#metastoreObject

Returns the value of attribute metastore.



17
18
19
# File 'lib/jkr/plan.rb', line 17

def metastore
  @metastore
end

#param_filtersObject

Returns the value of attribute param_filters.



32
33
34
# File 'lib/jkr/plan.rb', line 32

def param_filters
  @param_filters
end

#paramsObject

Returns the value of attribute params.



15
16
17
# File 'lib/jkr/plan.rb', line 15

def params
  @params
end

#plan_nameObject

Returns the value of attribute plan_name.



13
14
15
# File 'lib/jkr/plan.rb', line 13

def plan_name
  @plan_name
end

#plan_search_pathObject

Returns the value of attribute plan_search_path.



20
21
22
# File 'lib/jkr/plan.rb', line 20

def plan_search_path
  @plan_search_path
end

#prepObject

Proc’s



27
28
29
# File 'lib/jkr/plan.rb', line 27

def prep
  @prep
end

#resultset_dirObject

Returns the value of attribute resultset_dir.



24
25
26
# File 'lib/jkr/plan.rb', line 24

def resultset_dir
  @resultset_dir
end

#routineObject

Returns the value of attribute routine.



29
30
31
# File 'lib/jkr/plan.rb', line 29

def routine
  @routine
end

#routine_nr_runObject

Returns the value of attribute routine_nr_run.



30
31
32
# File 'lib/jkr/plan.rb', line 30

def routine_nr_run
  @routine_nr_run
end

#script_search_pathObject

Returns the value of attribute script_search_path.



21
22
23
# File 'lib/jkr/plan.rb', line 21

def script_search_path
  @script_search_path
end

#short_descObject

Returns the value of attribute short_desc.



12
13
14
# File 'lib/jkr/plan.rb', line 12

def short_desc
  @short_desc
end

#srcObject

Returns the value of attribute src.



35
36
37
# File 'lib/jkr/plan.rb', line 35

def src
  @src
end

#titleObject

Returns the value of attribute title.



10
11
12
# File 'lib/jkr/plan.rb', line 10

def title
  @title
end

#used_scriptsObject

Returns the value of attribute used_scripts.



22
23
24
# File 'lib/jkr/plan.rb', line 22

def used_scripts
  @used_scripts
end

#varsObject

Returns the value of attribute vars.



16
17
18
# File 'lib/jkr/plan.rb', line 16

def vars
  @vars
end

Class Method Details

.create_by_name(jkr_env, plan_name, options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/jkr/plan.rb', line 63

def self.create_by_name(jkr_env, plan_name, options = {})
  plan = new(jkr_env)

  if options[:plan_search_path]
    plan.plan_search_path = options[:plan_search_path]
  else
    plan.plan_search_path = [plan.jkr_env.jkr_plan_dir]
  end

  if options[:script_search_path]
    plan.script_search_path = options[:script_search_path]
  else
    plan.script_search_path = [plan.jkr_env.jkr_script_dir]
  end

  finder = PlanFinder.new(jkr_env)
  plan.file_path = finder.find_by_name(plan_name,
                                       :plan_search_path => plan.plan_search_path)
  unless plan.file_path
    raise ArgumentError.new("No such plan: #{plan_name}")
  end

  PlanLoader.load_plan(plan)

  plan
end

.create_by_result_id(jkr_env, ret_id, options = {}) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/jkr/plan.rb', line 90

def self.create_by_result_id(jkr_env, ret_id, options = {})
  plan = new(jkr_env)
  finder = PlanFinder.new(jkr_env)
  plan.file_path = finder.find_by_result_id(ret_id)

  plan.plan_search_path = [File.expand_path("../plan", plan.file_path)]
  plan.script_search_path = [File.expand_path("../script", plan.file_path),
                             plan.jkr_env.jkr_script_dir]

  unless plan.file_path
    raise ArgumentError.new("Not valid result ID: #{ret_id}")
  end

  resultset_num = sprintf "%05d", ret_id
  dirs = Dir.glob(File.join(plan.jkr_env.jkr_result_dir, resultset_num)+"*")
  if dirs.size == 0
    raise RuntimeError.new("Resultset not found: #{ret_id}")
  elsif dirs.size > 1
    raise RuntimeError.new("Cannot identify result set directory")
  end
  plan.resultset_dir = dirs.first

  PlanLoader.load_plan(plan)

  plan
end

Instance Method Details

#do_analysis(plan = self) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/jkr/plan.rb', line 149

def do_analysis(plan = self)
  if self.analysis.nil?
    self.base_plan.resultset_dir = self.resultset_dir
    self.base_plan.do_analysis(plan)
  else
    Jkr::AnalysisUtils.define_analysis_utils(resultset_dir, self)
    ret = self.analysis.call(plan)
    Jkr::AnalysisUtils.undef_analysis_utils(self)

    ret
  end
end

#do_cleanup(plan = self) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/jkr/plan.rb', line 141

def do_cleanup(plan = self)
  if self.cleanup.nil?
    self.base_plan.do_cleanup(plan)
  else
    self.cleanup.call(plan)
  end
end

#do_prep(plan = self) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/jkr/plan.rb', line 125

def do_prep(plan = self)
  if self.prep.nil?
    self.base_plan.do_prep(plan)
  else
    self.prep.call(plan)
  end
end

#do_routine(plan, params) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/jkr/plan.rb', line 133

def do_routine(plan, params)
  if self.routine.nil?
    self.base_plan.do_routine(plan, params)
  else
    self.routine.call(plan, params)
  end
end

#param_namesObject



117
118
119
# File 'lib/jkr/plan.rb', line 117

def param_names
  @params.keys
end

#var_namesObject



121
122
123
# File 'lib/jkr/plan.rb', line 121

def var_names
  @vars.keys
end