hotdog 0.31.0 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9919088eda80ed6ec42ab4448a1e9474a8f6b3cf
4
- data.tar.gz: b4659b72b4ee22337f1d74d14dad1d0d686b8bf0
3
+ metadata.gz: 2b24f0d15a198f0128ee1783589bff4f6d5ea013
4
+ data.tar.gz: 2793030c132d22df90fb3ff67bb05cc6c1fd6a35
5
5
  SHA512:
6
- metadata.gz: 6cdebee0eaf5a3c347aa9fb8fae6f589467cf040edcad75d1d220d2b29a7842a7619f1b1149fe58bb1b116e6fc59ae248b48af5291655e03da4866ade02d1005
7
- data.tar.gz: 9af471697553ce75493da82aedfa9f79c59f65de5a74407b7fbf626bc04571dcfb5e29be495021eecea48fd3814cecabf6abd87cb9f8abe3a36550a934f01868
6
+ metadata.gz: 6b563f78db988f5000c455872d1680c6d91d4668c9ad1f033cbfc390501c2f97d421d22afeb236854c6cfbb8425658b5892e7c03af73c2f31deb417d0a3df323
7
+ data.tar.gz: cb5148c263ae888617fb03b6c86a15c2550cf03241e0e60af1556de7b26bb350b7f89f518a545cdd734ce3dfe1ac3bbbf059c004848adecaf157cc0b09ce28c3
@@ -65,6 +65,9 @@ module Hotdog
65
65
  display_search_tags: false,
66
66
  verbose: false,
67
67
  verbosity: VERBOSITY_NULL,
68
+ }.reject { |key, val|
69
+ # reject nil values to declare sensible default later in subcommand
70
+ val.nil?
68
71
  }
69
72
 
70
73
  define_options
@@ -61,7 +61,11 @@ module Hotdog
61
61
 
62
62
  private
63
63
  def default_option(options, key, default_value)
64
- options[key] = default_value
64
+ if options.key?(key)
65
+ options[key]
66
+ else
67
+ options[key] = default_value
68
+ end
65
69
  end
66
70
 
67
71
  def prepare(db, query)
@@ -93,12 +97,12 @@ module Hotdog
93
97
  if @options[:primary_tag]
94
98
  fields = [
95
99
  @options[:primary_tag],
96
- "host",
100
+ "@host",
97
101
  ] + get_fields(host_ids).reject { |tagname| tagname == @options[:primary_tag] }
98
102
  get_hosts_fields(host_ids, fields)
99
103
  else
100
104
  fields = [
101
- "host",
105
+ "@host",
102
106
  ] + get_fields(host_ids)
103
107
  get_hosts_fields(host_ids, fields)
104
108
  end
@@ -106,7 +110,7 @@ module Hotdog
106
110
  if @options[:primary_tag]
107
111
  get_hosts_fields(host_ids, [@options[:primary_tag]])
108
112
  else
109
- get_hosts_fields(host_ids, ["host"])
113
+ get_hosts_fields(host_ids, ["@host"])
110
114
  end
111
115
  end
112
116
  end
@@ -378,14 +382,6 @@ module Hotdog
378
382
  })
379
383
  end
380
384
 
381
- # create virtual `host` tag
382
- execute_db(db, "INSERT OR IGNORE INTO tags (name, value) SELECT 'host', hosts.name FROM hosts;")
383
- execute_db(db,
384
- "INSERT OR REPLACE INTO hosts_tags (host_id, tag_id) " \
385
- "SELECT hosts.id, tags.id FROM hosts " \
386
- "INNER JOIN tags ON tags.name = 'host' AND hosts.name = tags.value;"
387
- )
388
-
389
385
  # create virtual `@host` tag
390
386
  execute_db(db, "INSERT OR IGNORE INTO tags (name, value) SELECT '@host', hosts.name FROM hosts;")
391
387
  execute_db(db,
@@ -457,14 +453,27 @@ module Hotdog
457
453
 
458
454
  def split_tag(tag)
459
455
  tagname, tagvalue = tag.split(":", 2)
460
- [tagname, tagvalue || ""]
456
+ [rewrite_legacy_tagname(tagname), tagvalue || ""]
461
457
  end
462
458
 
463
459
  def join_tag(tagname, tagvalue)
464
460
  if tagvalue.to_s.empty?
465
- tagname
461
+ rewrite_legacy_tagname(tagname)
462
+ else
463
+ "#{rewrite_legacy_tagname(tagname)}:#{tagvalue}"
464
+ end
465
+ end
466
+
467
+ def rewrite_legacy_tagname(s)
468
+ case s
469
+ when "host"
470
+ # Starting from v0.31.0, hotdog started using _internal_ tags with leading `@` in name.
471
+ #
472
+ # This workaround is to keep legacy `host` tag for backward compatibility by rewriting
473
+ # it as the reference to the internal tag of `@host` without any user action.
474
+ "@#{s}"
466
475
  else
467
- "#{tagname}:#{tagvalue}"
476
+ s
468
477
  end
469
478
  end
470
479
 
@@ -42,8 +42,19 @@ module Hotdog
42
42
  scope.slice("host:".length, scope.length)
43
43
  }
44
44
  if 0 < hosts.length
45
- # refresh all persistent.db to retrieve information about up'd host
46
- remove_db(@db)
45
+ # Try reloading database after error as a workaround for nested transaction.
46
+ with_retry(error_handler: ->(error) { reload }) do
47
+ if open_db
48
+ @db.transaction do
49
+ sqlite_limit_compound_select = options[:sqlite_limit_compound_select] || SQLITE_LIMIT_COMPOUND_SELECT
50
+ hosts.each_slice(sqlite_limit_compound_select - 1) do |hosts|
51
+ execute_db(@db, "DELETE FROM hosts_tags WHERE tag_id IN ( SELECT id FROM tags WHERE name = '@status' ) AND host_id IN ( SELECT id FROM hosts WHERE name IN (%s) );" % hosts.map { "?" }.join(", "), hosts)
52
+ execute_db(@db, "UPDATE hosts SET status = ? WHERE name IN (%s);" % hosts.map { "?" }.join(", "), [STATUS_RUNNING] + hosts)
53
+ end
54
+ associate_tag_hosts(@db, "@status:#{application.status_name(STATUS_RUNNING)}", hosts)
55
+ end
56
+ end
57
+ end
47
58
  end
48
59
  end
49
60
 
@@ -64,77 +64,77 @@ module Hotdog
64
64
  UnaryExpressionNode.new(unary_op, expression)
65
65
  }
66
66
  rule(tagname_regexp: simple(:tagname_regexp), separator: simple(:separator), tagvalue_regexp: simple(:tagvalue_regexp)) {
67
- if "/host/" == tagname_regexp
67
+ if "/@host/" == tagname_regexp or "/host/" == tagname_regexp
68
68
  RegexpHostNode.new(tagvalue_regexp, separator)
69
69
  else
70
70
  RegexpTagNode.new(tagname_regexp, tagvalue_regexp, separator)
71
71
  end
72
72
  }
73
73
  rule(tagname_regexp: simple(:tagname_regexp), separator: simple(:separator)) {
74
- if "/host/" == tagname_regexp
74
+ if "/@host/" == tagname_regexp or "/host/" == tagname_regexp
75
75
  EverythingNode.new()
76
76
  else
77
77
  RegexpTagnameNode.new(tagname_regexp, separator)
78
78
  end
79
79
  }
80
80
  rule(tagname_regexp: simple(:tagname_regexp)) {
81
- if "/host/" == tagname_regexp
81
+ if "/@host/" == tagname_regexp or "/host/" == tagname_regexp
82
82
  EverythingNode.new()
83
83
  else
84
84
  RegexpHostOrTagNode.new(tagname_regexp)
85
85
  end
86
86
  }
87
87
  rule(tagname_glob: simple(:tagname_glob), separator: simple(:separator), tagvalue_glob: simple(:tagvalue_glob)) {
88
- if "host" == tagname_glob
88
+ if "@host" == tagname_glob or "host" == tagname_glob
89
89
  GlobHostNode.new(tagvalue_glob, separator)
90
90
  else
91
91
  GlobTagNode.new(tagname_glob, tagvalue_glob, separator)
92
92
  end
93
93
  }
94
94
  rule(tagname_glob: simple(:tagname_glob), separator: simple(:separator), tagvalue: simple(:tagvalue)) {
95
- if "host" == tagname_glob
95
+ if "@host" == tagname_glob or "host" == tagname_glob
96
96
  GlobHostNode.new(tagvalue, separator)
97
97
  else
98
98
  GlobTagNode.new(tagname_glob, tagvalue, separator)
99
99
  end
100
100
  }
101
101
  rule(tagname_glob: simple(:tagname_glob), separator: simple(:separator)) {
102
- if "host" == tagname_glob
102
+ if "@host" == tagname_glob or "host" == tagname_glob
103
103
  EverythingNode.new()
104
104
  else
105
105
  GlobTagnameNode.new(tagname_glob, separator)
106
106
  end
107
107
  }
108
108
  rule(tagname_glob: simple(:tagname_glob)) {
109
- if "host" == tagname_glob
109
+ if "@host" == tagname_glob or "host" == tagname_glob
110
110
  EverythingNode.new()
111
111
  else
112
112
  GlobHostOrTagNode.new(tagname_glob)
113
113
  end
114
114
  }
115
115
  rule(tagname: simple(:tagname), separator: simple(:separator), tagvalue_glob: simple(:tagvalue_glob)) {
116
- if "host" == tagname
116
+ if "@host" == tagname or "host" == tagname
117
117
  GlobHostNode.new(tagvalue_glob, separator)
118
118
  else
119
119
  GlobTagNode.new(tagname, tagvalue_glob, separator)
120
120
  end
121
121
  }
122
122
  rule(tagname: simple(:tagname), separator: simple(:separator), tagvalue: simple(:tagvalue)) {
123
- if "host" == tagname
123
+ if "@host" == tagname or "host" == tagname
124
124
  StringHostNode.new(tagvalue, separator)
125
125
  else
126
126
  StringTagNode.new(tagname, tagvalue, separator)
127
127
  end
128
128
  }
129
129
  rule(tagname: simple(:tagname), separator: simple(:separator)) {
130
- if "host" == tagname
130
+ if "@host" == tagname or "host" == tagname
131
131
  EverythingNode.new()
132
132
  else
133
133
  StringTagnameNode.new(tagname, separator)
134
134
  end
135
135
  }
136
136
  rule(tagname: simple(:tagname)) {
137
- if "host" == tagname
137
+ if "@host" == tagname or "host" == tagname
138
138
  EverythingNode.new()
139
139
  else
140
140
  StringHostOrTagNode.new(tagname)
@@ -746,7 +746,7 @@ module Hotdog
746
746
 
747
747
  class AnyHostNode < TagExpressionNode
748
748
  def initialize(separator=nil, options={})
749
- super("host", nil, separator, options)
749
+ super("@host", nil, separator, options)
750
750
  end
751
751
 
752
752
  def condition(options={})
@@ -767,7 +767,7 @@ module Hotdog
767
767
 
768
768
  class StringHostNode < StringExpressionNode
769
769
  def initialize(tagvalue, separator=nil, options={})
770
- super("host", tagvalue.to_s, separator, options)
770
+ super("@host", tagvalue.to_s, separator, options)
771
771
  end
772
772
 
773
773
  def condition(options={})
@@ -918,7 +918,7 @@ module Hotdog
918
918
 
919
919
  class GlobHostNode < GlobExpressionNode
920
920
  def initialize(tagvalue, separator=nil, options={})
921
- super("host", tagvalue.to_s, separator, options)
921
+ super("@host", tagvalue.to_s, separator, options)
922
922
  end
923
923
 
924
924
  def condition(options={})
@@ -1073,7 +1073,7 @@ module Hotdog
1073
1073
  when /\A\/(.*)\/\z/
1074
1074
  tagvalue = $1
1075
1075
  end
1076
- super("host", tagvalue, separator, options)
1076
+ super("@host", tagvalue, separator, options)
1077
1077
  end
1078
1078
 
1079
1079
  def condition(options={})
@@ -1,3 +1,3 @@
1
1
  module Hotdog
2
- VERSION = "0.31.0"
2
+ VERSION = "0.32.0"
3
3
  end
@@ -27,7 +27,7 @@ describe "commands" do
27
27
  allow(cmd).to receive(:execute).with("SELECT id FROM hosts WHERE status = ? AND id IN (?, ?, ?);", [Hotdog::STATUS_RUNNING, 1, 2, 3]) {
28
28
  [[1], [2], [3]]
29
29
  }
30
- allow(cmd).to receive(:get_hosts_fields).with([1, 2, 3], ["host"])
30
+ allow(cmd).to receive(:get_hosts_fields).with([1, 2, 3], ["@host"])
31
31
  expect(cmd.__send__(:get_hosts, [1, 2, 3], []))
32
32
  end
33
33
 
@@ -68,7 +68,7 @@ describe "commands" do
68
68
  allow(cmd).to receive(:execute).with(q1.join(" "), [1, 2, 3]) {
69
69
  [["foo"], ["bar"], ["baz"]]
70
70
  }
71
- allow(cmd).to receive(:get_hosts_fields).with([1, 2, 3], ["host", "foo", "bar", "baz"])
71
+ allow(cmd).to receive(:get_hosts_fields).with([1, 2, 3], ["@host", "foo", "bar", "baz"])
72
72
  expect(cmd.__send__(:get_hosts, [1, 2, 3], []))
73
73
  end
74
74
 
@@ -87,7 +87,7 @@ describe "commands" do
87
87
  allow(cmd).to receive(:execute).with(q1.join(" "), [1, 2, 3]) {
88
88
  [["foo"], ["bar"], ["baz"]]
89
89
  }
90
- allow(cmd).to receive(:get_hosts_fields).with([1, 2, 3], ["bar", "host", "foo", "baz"])
90
+ allow(cmd).to receive(:get_hosts_fields).with([1, 2, 3], ["bar", "@host", "foo", "baz"])
91
91
  expect(cmd.__send__(:get_hosts, [1, 2, 3], []))
92
92
  end
93
93
 
@@ -127,15 +127,15 @@ describe "commands" do
127
127
  "WHERE hosts_tags.host_id = ? AND tags.name IN (?, ?, ?)",
128
128
  "GROUP BY tags.name;",
129
129
  ]
130
- allow(cmd).to receive(:execute).with(q1.join(" "), [1, "foo", "bar", "host"]) {
131
- [["foo", "foo1"], ["bar", "bar1"], ["host", "host1"]]
130
+ allow(cmd).to receive(:execute).with(q1.join(" "), [1, "foo", "bar", "@host"]) {
131
+ [["foo", "foo1"], ["bar", "bar1"], ["@host", "host1"]]
132
132
  }
133
- allow(cmd).to receive(:execute).with(q1.join(" "), [2, "foo", "bar", "host"]) {
134
- [["foo", "foo2"], ["bar", "bar2"], ["host", "host2"]]
133
+ allow(cmd).to receive(:execute).with(q1.join(" "), [2, "foo", "bar", "@host"]) {
134
+ [["foo", "foo2"], ["bar", "bar2"], ["@host", "host2"]]
135
135
  }
136
- allow(cmd).to receive(:execute).with(q1.join(" "), [3, "foo", "bar", "host"]) {
137
- [["foo", "foo3"], ["bar", "bar3"], ["host", "host3"]]
136
+ allow(cmd).to receive(:execute).with(q1.join(" "), [3, "foo", "bar", "@host"]) {
137
+ [["foo", "foo3"], ["bar", "bar3"], ["@host", "host3"]]
138
138
  }
139
- expect(cmd.__send__(:get_hosts_fields, [1, 2, 3], ["foo", "bar", "host"])).to eq([[["foo1", "bar1", "host1"], ["foo2", "bar2", "host2"], ["foo3", "bar3", "host3"]], ["foo", "bar", "host"]])
139
+ expect(cmd.__send__(:get_hosts_fields, [1, 2, 3], ["foo", "bar", "@host"])).to eq([[["foo1", "bar1", "host1"], ["foo2", "bar2", "host2"], ["foo3", "bar3", "host3"]], ["foo", "bar", "@host"]])
140
140
  end
141
141
  end
@@ -24,7 +24,7 @@ describe "tag glob expression" do
24
24
  [[1], [2], [3]]
25
25
  }
26
26
  expect(expr.evaluate(cmd)).to eq([1, 2, 3])
27
- expect(expr.dump).to eq({tagname_glob: "host", separator: ":", tagvalue_glob: "foo*"})
27
+ expect(expr.dump).to eq({tagname_glob: "@host", separator: ":", tagvalue_glob: "foo*"})
28
28
  end
29
29
 
30
30
  it "interprets tag glob with tagname and tagvalue" do
@@ -24,7 +24,7 @@ describe "tag regexp expression" do
24
24
  [[1], [2], [3]]
25
25
  }
26
26
  expect(expr.evaluate(cmd)).to eq([1, 2, 3])
27
- expect(expr.dump).to eq({tagname_regexp: "host", separator: ":", tagvalue_regexp: "foo"})
27
+ expect(expr.dump).to eq({tagname_regexp: "@host", separator: ":", tagvalue_regexp: "foo"})
28
28
  end
29
29
 
30
30
  it "interprets tag regexp with tagname and tagvalue" do
@@ -24,7 +24,7 @@ describe "tag expression" do
24
24
  [[1], [2], [3]]
25
25
  }
26
26
  expect(expr.evaluate(cmd)).to eq([1, 2, 3])
27
- expect(expr.dump).to eq({tagname: "host", separator: ":", tagvalue: "foo"})
27
+ expect(expr.dump).to eq({tagname: "@host", separator: ":", tagvalue: "foo"})
28
28
  end
29
29
 
30
30
  it "interprets tag with tagname and tagvalue" do
@@ -9,7 +9,7 @@ describe "tag glob expression" do
9
9
  it "interprets tag glob with host (#{o})" do
10
10
  expr = Hotdog::Expression::GlobHostNode.new("foo*", ":")
11
11
  expect(optimize_n(o+1, expr).dump).to eq({
12
- tagname_glob: "host",
12
+ tagname_glob: "@host",
13
13
  separator: ":",
14
14
  tagvalue_glob: "foo*",
15
15
  fallback: {
@@ -9,7 +9,7 @@ describe "tag regexp expression" do
9
9
  it "interprets tag regexp with host (#{o})" do
10
10
  expr = Hotdog::Expression::RegexpHostNode.new("foo", ":")
11
11
  expect(optimize_n(o+1, expr).dump).to eq({
12
- tagname_regexp: "host",
12
+ tagname_regexp: "@host",
13
13
  separator: ":",
14
14
  tagvalue_regexp: "foo",
15
15
  })
@@ -9,7 +9,7 @@ describe "tag expression" do
9
9
  it "interprets tag with host (#{o})" do
10
10
  expr = Hotdog::Expression::StringHostNode.new("foo", ":")
11
11
  expect(optimize_n(o+1, expr).dump).to eq({
12
- tagname: "host",
12
+ tagname: "@host",
13
13
  separator: ":",
14
14
  tagvalue: "foo",
15
15
  fallback: {
@@ -104,7 +104,7 @@ describe "unary expression" do
104
104
  ),
105
105
  )
106
106
  expect(optimize_n(o+1, expr).dump).to eq({
107
- tagname: "host",
107
+ tagname: "@host",
108
108
  separator: ":",
109
109
  tagvalue: "foo",
110
110
  fallback: {
@@ -140,7 +140,7 @@ describe "unary expression" do
140
140
  Hotdog::Expression::StringHostNode.new("foo", ":"),
141
141
  )
142
142
  expect(optimize_n(o+1, expr).dump).to eq({
143
- tagname: "host",
143
+ tagname: "@host",
144
144
  separator: ":",
145
145
  tagvalue: "foo",
146
146
  fallback: {
@@ -162,7 +162,7 @@ describe "unary expression" do
162
162
  ),
163
163
  )
164
164
  expect(optimize_n(o+1, expr).dump).to eq({
165
- tagname: "host",
165
+ tagname: "@host",
166
166
  separator: ":",
167
167
  tagvalue: "foo",
168
168
  fallback: {
@@ -187,7 +187,7 @@ describe "unary expression" do
187
187
  ),
188
188
  )
189
189
  expect(optimize_n(o+1, expr).dump).to eq({
190
- tagname: "host",
190
+ tagname: "@host",
191
191
  separator: ":",
192
192
  tagvalue: "foo",
193
193
  fallback: {
@@ -263,7 +263,7 @@ describe "unary expression" do
263
263
  ),
264
264
  )
265
265
  expect(optimize_n(o+1, expr).dump).to eq({
266
- tagname: "host",
266
+ tagname: "@host",
267
267
  separator: ":",
268
268
  tagvalue: "foo",
269
269
  fallback: {
@@ -288,7 +288,7 @@ describe "unary expression" do
288
288
  ),
289
289
  )
290
290
  expect(optimize_n(o+1, expr).dump).to eq({
291
- tagname: "host",
291
+ tagname: "@host",
292
292
  separator: ":",
293
293
  tagvalue: "foo",
294
294
  fallback: {
@@ -313,7 +313,7 @@ describe "unary expression" do
313
313
  ),
314
314
  )
315
315
  expect(optimize_n(o+1, expr).dump).to eq({
316
- tagname: "host",
316
+ tagname: "@host",
317
317
  separator: ":",
318
318
  tagvalue: "foo",
319
319
  fallback: {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotdog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.0
4
+ version: 0.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yamashita Yuu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-27 00:00:00.000000000 Z
11
+ date: 2018-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler