Skip to content

Commit d036bb0

Browse files
authored
Merge pull request #288 from ripienaar/287
(#287) add choria::kv_buckets and choria::governors
2 parents d747682 + a1977d0 commit d036bb0

File tree

14 files changed

+126
-32
lines changed

14 files changed

+126
-32
lines changed

lib/puppet/provider/choria_governor/choria_governor.rb

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,45 @@ def update(context, name, should)
1919

2020
def run(action, ens, args={})
2121
args.delete(:ensure)
22-
parse_result(Puppet::Util::Execution.execute(make_cmd(action, args), :failonfail => false, :custom_environment => environment), ens)
22+
parse_result(Puppet::Util::Execution.execute(make_cmd(action, args), :failonfail => true, :custom_environment => environment), ens)
23+
end
24+
25+
def config_file
26+
paths = if Process.uid == 0
27+
[
28+
"/etc/choria/server.conf",
29+
"/usr/local/etc/choria/server.conf",
30+
]
31+
else
32+
[
33+
"/etc/choria/client.conf",
34+
"/usr/local/etc/choria/client.conf",
35+
]
36+
end
37+
38+
paths.each do |p|
39+
return p if File.exist?(p)
40+
end
41+
42+
raise("cannot find configuration path")
2343
end
2444

2545
def make_cmd(action, args={})
2646
choria = Puppet::Util.which("choria")
2747
raise("cannot find choria executable") if choria == ""
2848

29-
cmd = [choria, "gov", "api", "--%s" % action]
30-
args.each {|k, v|
31-
cmd << "--%s" % k
32-
cmd << v unless v.is_a?(TrueClass)
33-
}
49+
cmd = [choria, "governor", "api", "--%s" % action, "--config=%s" % config_file]
50+
51+
args.each do |k, v|
52+
k = k.to_s.gsub("_", "-")
53+
if v.is_a?(TrueClass)
54+
cmd << "--%s" % k
55+
elsif v.is_a?(FalseClass)
56+
cmd << "--no-%s" % k
57+
else
58+
cmd << "--%s=%s" % [k, v]
59+
end
60+
end
3461

3562
cmd.join(" ")
3663
end

lib/puppet/provider/choria_kv_bucket/choria_kv_bucket.rb

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,45 @@ def update(context, name, should)
1919

2020
def run(action, ens, args={})
2121
args.delete(:ensure)
22-
parse_result(Puppet::Util::Execution.execute(make_cmd(action, args), :failonfail => false, :custom_environment => environment), ens)
22+
parse_result(Puppet::Util::Execution.execute(make_cmd(action, args), :failonfail => true, :custom_environment => environment), ens)
23+
end
24+
25+
def config_file
26+
paths = if Process.uid == 0
27+
[
28+
"/etc/choria/server.conf",
29+
"/usr/local/etc/choria/server.conf",
30+
]
31+
else
32+
[
33+
"/etc/choria/client.conf",
34+
"/usr/local/etc/choria/client.conf",
35+
]
36+
end
37+
38+
paths.each do |p|
39+
return p if File.exist?(p)
40+
end
41+
42+
raise("cannot find configuration path")
2343
end
2444

2545
def make_cmd(action, args={})
2646
choria = Puppet::Util.which("choria")
2747
raise("cannot find choria executable") if choria == ""
2848

29-
cmd = [choria, "kv", "api", "--%s" % action]
30-
args.each {|k, v|
31-
cmd << "--%s" % k
32-
cmd << v unless v.is_a?(TrueClass)
33-
}
49+
cmd = [choria, "kv", "api", "--%s" % action, "--config=%s" % config_file]
50+
51+
args.each do |k, v|
52+
k = k.to_s.gsub("_", "-")
53+
if v.is_a?(TrueClass)
54+
cmd << "--%s" % k
55+
elsif v.is_a?(FalseClass)
56+
cmd << "--no-%s" % k
57+
else
58+
cmd << "--%s=%s" % [k, v]
59+
end
60+
end
3461

3562
cmd.join(" ")
3663
end

lib/puppet/type/choria_governor.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
expire: {
2424
type: "Integer",
2525
desc: "How long before a slot reservation is forcibly timed out",
26+
default: 0
2627
},
2728

2829
replicas: {
2930
type: "Integer[1,5]",
3031
desc: "In clustered environments this is how many active Replicas of the data and configuration is kept, odd number is best",
32+
default: 1,
3133
},
3234

3335
collective: {

lib/puppet/type/choria_kv_bucket.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
expire: {
2525
type: "Integer",
2626
desc: "How long before a value expires from the bucket, in seconds",
27-
default: -1
27+
default: 0
2828
},
2929

3030
replicas: {

manifests/broker.pp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
# adapters => {
2525
# discovery => {
2626
# stream => {
27-
# type => "nats_stream",
28-
# servers => ["stan1:4222", "stan2:4222"],
29-
# clusterid => "prod",
30-
# topic => "discovery",
27+
# type => "choria_streams",
28+
# servers => ["choria1:4222", "choria2:4222"],
29+
# topic => "choria.node_metadata.%s",
3130
# workers => 10,
3231
# },
3332
# ingest => {

manifests/governors.pp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Adds a series of choria_governor resources
2+
#
3+
# @private
4+
class choria::governors {
5+
assert_private()
6+
7+
require(Class["choria::config"])
8+
9+
$choria::governors.each |$governor, $properties| {
10+
choria_governor{$governor:
11+
* => $properties
12+
}
13+
}
14+
}
15+

manifests/init.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
# @param server_config Configuration for the Choria Server
3535
# @param manage_package_repo Installs the package repositories
3636
# @param nightly_repo Install the nightly package repo as well as the release one
37+
# @param kv_buckets Hash of choria_kv_bucket resources for a node, ideal for use using Hiera
38+
# @param governors Hash of choria_governor resources for a node, ideal for use using Hiera
3739
class choria (
3840
Boolean $manage_package,
3941
Boolean $manage_service,
@@ -72,6 +74,8 @@
7274
Stdlib::Absolutepath $broker_logfile = $logfile,
7375
Stdlib::Absolutepath $server_logfile = $logfile,
7476
Boolean $manage_mcollective = true,
77+
Choria::KVBuckets $kv_buckets = {},
78+
Choria::Governors $governors = {},
7579
) {
7680
if $manage_package_repo {
7781
class{"choria::repo":
@@ -108,4 +112,6 @@
108112
contain choria::install
109113
contain choria::scout_checks
110114
contain choria::scout_metrics
115+
contain choria::kv_buckets
116+
contain choria::governors
111117
}

manifests/kv_buckets.pp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Adds a series of choria_kv_bucket resources
2+
#
3+
# @private
4+
class choria::kv_buckets {
5+
assert_private()
6+
7+
require(Class["choria::config"])
8+
9+
$choria::kv_buckets.each |$bucket, $properties| {
10+
choria_kv_bucket{$bucket:
11+
* => $properties
12+
}
13+
}
14+
}

types/adapters.pp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
type Choria::Adapters = Variant[
2-
Hash[String, Choria::Adapters::NatsStream, 0],
32
Hash[String, Choria::Adapters::ChoriaStreams, 0]
43
]

types/adapters/natsstream.pp

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)