@@ -24,7 +24,7 @@ module AgentControllerConcern |
||
24 | 24 |
end |
25 | 25 |
|
26 | 26 |
def control! |
27 |
- targets.active.each { |target| |
|
27 |
+ control_targets.active.each { |target| |
|
28 | 28 |
begin |
29 | 29 |
case control_action |
30 | 30 |
when 'run' |
@@ -162,7 +162,7 @@ module DotHelper |
||
162 | 162 |
|
163 | 163 |
[ |
164 | 164 |
*agent.receivers, |
165 |
- *(agent.targets if agent.can_control_other_agents?) |
|
165 |
+ *(agent.control_targets if agent.can_control_other_agents?) |
|
166 | 166 |
].each { |receiver| |
167 | 167 |
agent_edge(agent, receiver) if agents.include?(receiver) |
168 | 168 |
} |
@@ -25,7 +25,7 @@ class Agent < ActiveRecord::Base |
||
25 | 25 |
|
26 | 26 |
EVENT_RETENTION_SCHEDULES = [["Forever", 0], ["1 day", 1], *([2, 3, 4, 5, 7, 14, 21, 30, 45, 90, 180, 365].map {|n| ["#{n} days", n] })] |
27 | 27 |
|
28 |
- attr_accessible :options, :memory, :name, :type, :schedule, :controller_ids, :target_ids, :disabled, :source_ids, :scenario_ids, :keep_events_for, :propagate_immediately |
|
28 |
+ attr_accessible :options, :memory, :name, :type, :schedule, :controller_ids, :control_target_ids, :disabled, :source_ids, :scenario_ids, :keep_events_for, :propagate_immediately |
|
29 | 29 |
|
30 | 30 |
json_serialize :options, :memory |
31 | 31 |
|
@@ -33,7 +33,7 @@ class Agent < ActiveRecord::Base |
||
33 | 33 |
validates_inclusion_of :keep_events_for, :in => EVENT_RETENTION_SCHEDULES.map(&:last) |
34 | 34 |
validate :sources_are_owned |
35 | 35 |
validate :controllers_are_owned |
36 |
- validate :targets_are_owned |
|
36 |
+ validate :control_targets_are_owned |
|
37 | 37 |
validate :scenarios_are_owned |
38 | 38 |
validate :validate_schedule |
39 | 39 |
validate :validate_options |
@@ -56,9 +56,9 @@ class Agent < ActiveRecord::Base |
||
56 | 56 |
has_many :sources, :through => :links_as_receiver, :class_name => "Agent", :inverse_of => :receivers |
57 | 57 |
has_many :receivers, :through => :links_as_source, :class_name => "Agent", :inverse_of => :sources |
58 | 58 |
has_many :chains_as_controller, dependent: :delete_all, foreign_key: 'controller_id', class_name: 'Chain', inverse_of: :controller |
59 |
- has_many :chains_as_target, dependent: :delete_all, foreign_key: 'target_id', class_name: 'Chain', inverse_of: :target |
|
60 |
- has_many :controllers, through: :chains_as_target, class_name: "Agent", inverse_of: :targets |
|
61 |
- has_many :targets, through: :chains_as_controller, class_name: "Agent", inverse_of: :controllers |
|
59 |
+ has_many :chains_as_control_target, dependent: :delete_all, foreign_key: 'control_target_id', class_name: 'Chain', inverse_of: :control_target |
|
60 |
+ has_many :controllers, through: :chains_as_control_target, class_name: "Agent", inverse_of: :control_targets |
|
61 |
+ has_many :control_targets, through: :chains_as_controller, class_name: "Agent", inverse_of: :controllers |
|
62 | 62 |
has_many :scenario_memberships, :dependent => :destroy, :inverse_of => :agent |
63 | 63 |
has_many :scenarios, :through => :scenario_memberships, :inverse_of => :agents |
64 | 64 |
|
@@ -233,8 +233,8 @@ class Agent < ActiveRecord::Base |
||
233 | 233 |
errors.add(:controllers, "must be owned by you") unless controllers.all? {|s| s.user == user } |
234 | 234 |
end |
235 | 235 |
|
236 |
- def targets_are_owned |
|
237 |
- errors.add(:targets, "must be owned by you") unless targets.all? {|s| s.user == user } |
|
236 |
+ def control_targets_are_owned |
|
237 |
+ errors.add(:control_targets, "must be owned by you") unless control_targets.all? {|s| s.user == user } |
|
238 | 238 |
end |
239 | 239 |
|
240 | 240 |
def scenarios_are_owned |
@@ -423,7 +423,7 @@ class AgentDrop |
||
423 | 423 |
:receivers, |
424 | 424 |
:schedule, |
425 | 425 |
:controllers, |
426 |
- :targets, |
|
426 |
+ :control_targets, |
|
427 | 427 |
:disabled, |
428 | 428 |
:keep_events_for, |
429 | 429 |
:propagate_immediately, |
@@ -3,5 +3,5 @@ class Chain < ActiveRecord::Base |
||
3 | 3 |
attr_accessible :controller_id, :target_id |
4 | 4 |
|
5 | 5 |
belongs_to :controller, class_name: 'Agent', inverse_of: :chains_as_controller |
6 |
- belongs_to :target, class_name: 'Agent', inverse_of: :chains_as_target |
|
6 |
+ belongs_to :control_target, class_name: 'Agent', inverse_of: :chains_as_control_target |
|
7 | 7 |
end |
@@ -61,11 +61,11 @@ |
||
61 | 61 |
<div class="chain-region" data-can-control-other-agents="<%= @agent.can_control_other_agents? %>"> |
62 | 62 |
<div class="can-control-other-agents"> |
63 | 63 |
<div class="form-group"> |
64 |
- <%= f.label :targets %> |
|
65 |
- <% eventTargets = current_user.agents.select(&:can_be_scheduled?) %> |
|
66 |
- <%= f.select(:target_ids, |
|
67 |
- options_for_select(eventTargets.map {|s| [s.name, s.id] }, |
|
68 |
- @agent.target_ids), |
|
64 |
+ <%= f.label :control_targets %> |
|
65 |
+ <% eventControlTargets = current_user.agents.select(&:can_be_scheduled?) %> |
|
66 |
+ <%= f.select(:control_target_ids, |
|
67 |
+ options_for_select(eventControlTargets.map {|s| [s.name, s.id] }, |
|
68 |
+ @agent.control_target_ids), |
|
69 | 69 |
{}, { multiple: true, size: 5, class: 'select2 form-control' }) %> |
70 | 70 |
</div> |
71 | 71 |
</div> |
@@ -136,8 +136,8 @@ |
||
136 | 136 |
|
137 | 137 |
<% if @agent.can_control_other_agents? %> |
138 | 138 |
<p> |
139 |
- <b>Targets:</b> |
|
140 |
- <% if (agents = @agent.targets).length > 0 %> |
|
139 |
+ <b>Control Targets:</b> |
|
140 |
+ <% if (agents = @agent.control_targets).length > 0 %> |
|
141 | 141 |
<%= agents.map { |agent| link_to(agent.name, agent_path(agent)) }.to_sentence.html_safe %> |
142 | 142 |
<% else %> |
143 | 143 |
None |
@@ -1,4 +1,5 @@ |
||
1 | 1 |
class RenameTargetIdToControlTargetId < ActiveRecord::Migration |
2 | 2 |
def change |
3 |
+ rename_column :chains, :target_id, :control_target_id |
|
3 | 4 |
end |
4 | 5 |
end |
@@ -11,10 +11,7 @@ |
||
11 | 11 |
# |
12 | 12 |
# It's strongly recommended that you check this file into your version control system. |
13 | 13 |
|
14 |
-ActiveRecord::Schema.define(version: 20140822085519) do |
|
15 |
- |
|
16 |
- # These are extensions that must be enabled in order to support this database |
|
17 |
- enable_extension "plpgsql" |
|
14 |
+ActiveRecord::Schema.define(version: 20140829081212) do |
|
18 | 15 |
|
19 | 16 |
create_table "agent_logs", force: true do |t| |
20 | 17 |
t.integer "agent_id", null: false |
@@ -38,14 +35,14 @@ ActiveRecord::Schema.define(version: 20140822085519) do |
||
38 | 35 |
t.integer "last_checked_event_id" |
39 | 36 |
t.datetime "created_at" |
40 | 37 |
t.datetime "updated_at" |
41 |
- t.text "memory" |
|
38 |
+ t.text "memory", limit: 2147483647 |
|
42 | 39 |
t.datetime "last_web_request_at" |
43 |
- t.integer "keep_events_for", default: 0, null: false |
|
40 |
+ t.integer "keep_events_for", default: 0, null: false |
|
44 | 41 |
t.datetime "last_event_at" |
45 | 42 |
t.datetime "last_error_log_at" |
46 |
- t.boolean "propagate_immediately", default: false, null: false |
|
47 |
- t.boolean "disabled", default: false, null: false |
|
48 |
- t.string "guid", null: false |
|
43 |
+ t.boolean "propagate_immediately", default: false, null: false |
|
44 |
+ t.boolean "disabled", default: false, null: false |
|
45 |
+ t.string "guid", null: false |
|
49 | 46 |
t.integer "service_id" |
50 | 47 |
end |
51 | 48 |
|
@@ -56,18 +53,18 @@ ActiveRecord::Schema.define(version: 20140822085519) do |
||
56 | 53 |
|
57 | 54 |
create_table "chains", force: true do |t| |
58 | 55 |
t.integer "controller_id" |
59 |
- t.integer "target_id" |
|
56 |
+ t.integer "control_target_id" |
|
60 | 57 |
t.datetime "created_at" |
61 | 58 |
t.datetime "updated_at" |
62 | 59 |
end |
63 | 60 |
|
64 |
- add_index "chains", ["controller_id", "target_id"], name: "index_chains_on_controller_id_and_target_id", unique: true, using: :btree |
|
65 |
- add_index "chains", ["target_id"], name: "index_chains_on_target_id", using: :btree |
|
61 |
+ add_index "chains", ["control_target_id"], name: "index_chains_on_control_target_id", using: :btree |
|
62 |
+ add_index "chains", ["controller_id", "control_target_id"], name: "index_chains_on_controller_id_and_control_target_id", unique: true, using: :btree |
|
66 | 63 |
|
67 | 64 |
create_table "delayed_jobs", force: true do |t| |
68 |
- t.integer "priority", default: 0 |
|
69 |
- t.integer "attempts", default: 0 |
|
70 |
- t.text "handler" |
|
65 |
+ t.integer "priority", default: 0 |
|
66 |
+ t.integer "attempts", default: 0 |
|
67 |
+ t.text "handler", limit: 16777215 |
|
71 | 68 |
t.text "last_error" |
72 | 69 |
t.datetime "run_at" |
73 | 70 |
t.datetime "locked_at" |
@@ -83,9 +80,9 @@ ActiveRecord::Schema.define(version: 20140822085519) do |
||
83 | 80 |
create_table "events", force: true do |t| |
84 | 81 |
t.integer "user_id" |
85 | 82 |
t.integer "agent_id" |
86 |
- t.decimal "lat", precision: 15, scale: 10 |
|
87 |
- t.decimal "lng", precision: 15, scale: 10 |
|
88 |
- t.text "payload" |
|
83 |
+ t.decimal "lat", precision: 15, scale: 10 |
|
84 |
+ t.decimal "lng", precision: 15, scale: 10 |
|
85 |
+ t.text "payload", limit: 16777215 |
|
89 | 86 |
t.datetime "created_at" |
90 | 87 |
t.datetime "updated_at" |
91 | 88 |
t.datetime "expires_at" |
@@ -508,15 +508,15 @@ describe Agent do |
||
508 | 508 |
agent.should have(0).errors_on(:controllers) |
509 | 509 |
end |
510 | 510 |
|
511 |
- it "should not allow target agents owned by other people" do |
|
511 |
+ it "should not allow control target agents owned by other people" do |
|
512 | 512 |
agent = Agents::CannotBeScheduled.new(:name => "something") |
513 | 513 |
agent.user = users(:bob) |
514 |
- agent.target_ids = [agents(:bob_weather_agent).id] |
|
515 |
- agent.should have(0).errors_on(:targets) |
|
516 |
- agent.target_ids = [agents(:jane_weather_agent).id] |
|
517 |
- agent.should have(1).errors_on(:targets) |
|
514 |
+ agent.control_target_ids = [agents(:bob_weather_agent).id] |
|
515 |
+ agent.should have(0).errors_on(:control_targets) |
|
516 |
+ agent.control_target_ids = [agents(:jane_weather_agent).id] |
|
517 |
+ agent.should have(1).errors_on(:control_targets) |
|
518 | 518 |
agent.user = users(:jane) |
519 |
- agent.should have(0).errors_on(:targets) |
|
519 |
+ agent.should have(0).errors_on(:control_targets) |
|
520 | 520 |
end |
521 | 521 |
|
522 | 522 |
it "should not allow scenarios owned by other people" do |
@@ -89,29 +89,29 @@ describe Agents::SchedulerAgent do |
||
89 | 89 |
|
90 | 90 |
describe "check!" do |
91 | 91 |
it "should control targets" do |
92 |
- targets = [agents(:bob_website_agent), agents(:bob_weather_agent)] |
|
93 |
- @agent.targets = targets |
|
92 |
+ control_targets = [agents(:bob_website_agent), agents(:bob_weather_agent)] |
|
93 |
+ @agent.control_targets = control_targets |
|
94 | 94 |
@agent.save! |
95 | 95 |
|
96 |
- target_ids = targets.map(&:id) |
|
96 |
+ control_target_ids = control_targets.map(&:id) |
|
97 | 97 |
stub(Agent).async_check(anything) { |id| |
98 |
- target_ids.delete(id) |
|
98 |
+ control_target_ids.delete(id) |
|
99 | 99 |
} |
100 | 100 |
|
101 | 101 |
@agent.check! |
102 |
- target_ids.should be_empty |
|
102 |
+ control_target_ids.should be_empty |
|
103 | 103 |
|
104 | 104 |
@agent.options['action'] = 'disable' |
105 | 105 |
@agent.save! |
106 | 106 |
|
107 | 107 |
@agent.check! |
108 |
- targets.all? { |target| target.disabled? } |
|
108 |
+ control_targets.all? { |control_target| control_target.disabled? } |
|
109 | 109 |
|
110 | 110 |
@agent.options['action'] = 'enable' |
111 | 111 |
@agent.save! |
112 | 112 |
|
113 | 113 |
@agent.check! |
114 |
- targets.all? { |target| !target.disabled? } |
|
114 |
+ control_targets.all? { |control_target| !control_target.disabled? } |
|
115 | 115 |
end |
116 | 116 |
end |
117 | 117 |
end |