From 7def855e8f1b7fc50c9074b45dad593c4f3f64f0 Mon Sep 17 00:00:00 2001 From: saheemg Date: Mon, 21 Nov 2016 10:24:53 -0500 Subject: [PATCH 1/7] Update to add an instance_id attribute. zookeeper V3.5.2-alpha dynamically generates a configuration file and updates the configuration file generated by chef to move the ensemble information to the dynamic file. In my chef cookbook, I will generate the dynamic file and stop this cookbook from generating a config file that zookeeper will update. I will do this by not setting the ensemble field. That works but the problem is with my_id. --- libraries/zookeeper_config.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/zookeeper_config.rb b/libraries/zookeeper_config.rb index 78b806b..f7257e7 100644 --- a/libraries/zookeeper_config.rb +++ b/libraries/zookeeper_config.rb @@ -26,6 +26,7 @@ class ZookeeperConfig < Chef::Resource attribute(:group, kind_of: String, default: 'zookeeper') attribute(:instance_name, kind_of: String, required: true) + attribute(:instance_id, kind_of: Integer, required: false) attribute(:data_dir, kind_of: String, default: '/var/lib/zookeeper') attribute(:client_port, kind_of: Integer, default: 2181) attribute(:leader_port, kind_of: Integer, default: 2888) @@ -34,7 +35,11 @@ class ZookeeperConfig < Chef::Resource attribute(:properties, option_collector: true, default: {}) def myid - ensemble.index(instance_name).next.to_s + if instance_id != nil + instance_id.to_s + else + ensemble.index(instance_name).next.to_s + end end # Outputs the +properties+ in the Java Properties file format. This is From 684bda4fd48100627188c2a22112048b780115be Mon Sep 17 00:00:00 2001 From: Saheem Granados Date: Mon, 21 Nov 2016 11:36:33 -0500 Subject: [PATCH 2/7] Added instance_id. --- libraries/zookeeper_config.rb | 7 ++++++- metadata.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/zookeeper_config.rb b/libraries/zookeeper_config.rb index 78b806b..1c58ea5 100644 --- a/libraries/zookeeper_config.rb +++ b/libraries/zookeeper_config.rb @@ -26,6 +26,7 @@ class ZookeeperConfig < Chef::Resource attribute(:group, kind_of: String, default: 'zookeeper') attribute(:instance_name, kind_of: String, required: true) + attribute(:instance_id, kind_of: Integer, required: false) attribute(:data_dir, kind_of: String, default: '/var/lib/zookeeper') attribute(:client_port, kind_of: Integer, default: 2181) attribute(:leader_port, kind_of: Integer, default: 2888) @@ -34,7 +35,11 @@ class ZookeeperConfig < Chef::Resource attribute(:properties, option_collector: true, default: {}) def myid - ensemble.index(instance_name).next.to_s + if instance_id != nil + instance_id.to_s + else + ensemble.index(instance_name).next.to_s + end end # Outputs the +properties+ in the Java Properties file format. This is diff --git a/metadata.rb b/metadata.rb index 0a8decc..0091a3d 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Application cookbook which installs and configures a Zookeeper cluster.' long_description 'Application cookbook which installs and configures a Zookeeper cluster.' -version '1.3.2' +version '1.3.3' supports 'ubuntu', '>= 12.04' supports 'centos', '>= 6.6' From c796fdd1914d8c1553d74b97a59529c929e175b6 Mon Sep 17 00:00:00 2001 From: Saheem Granados Date: Mon, 21 Nov 2016 13:53:53 -0500 Subject: [PATCH 3/7] Update to avoid constant zookeeper restart. --- libraries/zookeeper_config.rb | 27 +++++++++++++++++---------- metadata.rb | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/libraries/zookeeper_config.rb b/libraries/zookeeper_config.rb index 1c58ea5..eb3b642 100644 --- a/libraries/zookeeper_config.rb +++ b/libraries/zookeeper_config.rb @@ -26,7 +26,8 @@ class ZookeeperConfig < Chef::Resource attribute(:group, kind_of: String, default: 'zookeeper') attribute(:instance_name, kind_of: String, required: true) - attribute(:instance_id, kind_of: Integer, required: false) + attribute(:instance_id, kind_of: String, default: lazy { ensemble.index(instance_name).next.to_s }) + alias_method :myid, :instance_id attribute(:data_dir, kind_of: String, default: '/var/lib/zookeeper') attribute(:client_port, kind_of: Integer, default: 2181) attribute(:leader_port, kind_of: Integer, default: 2888) @@ -34,14 +35,6 @@ class ZookeeperConfig < Chef::Resource attribute(:ensemble, kind_of: Array, default: [], required: true) attribute(:properties, option_collector: true, default: {}) - def myid - if instance_id != nil - instance_id.to_s - else - ensemble.index(instance_name).next.to_s - end - end - # Outputs the +properties+ in the Java Properties file format. This is # what Zookeeper daemon consumes to tweak its internal configuration. def to_s @@ -53,6 +46,7 @@ def to_s 'electionPort' => election_port).map { |kv| kv.join('=') }.concat(servers).join("\n") end + action(:create) do notifying_block do directory ::File.dirname(new_resource.path) do @@ -72,9 +66,22 @@ def to_s mode '0644' end - file new_resource.path do + # create zoo.properties.static file and only update + # zoo.properties when static file has changed. + # this is needed to ensure chef won't constantly update + # zoo.properties and force restarts of zookeeper when + # it dynamically updates zoo.properties. + file new_resource.path+".static" do + content new_resource.to_s + mode '0644' + notifies :create, 'file[config_base]', :immediately + end + + file 'config_base' do content new_resource.to_s + path new_resource.path mode '0644' + action :nothing end end end diff --git a/metadata.rb b/metadata.rb index 0091a3d..010a7ea 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Application cookbook which installs and configures a Zookeeper cluster.' long_description 'Application cookbook which installs and configures a Zookeeper cluster.' -version '1.3.3' +version '1.3.4' supports 'ubuntu', '>= 12.04' supports 'centos', '>= 6.6' From 515f9509f774f2432b16267d92be1b3e099ef031 Mon Sep 17 00:00:00 2001 From: Saheem Granados Date: Fri, 7 Apr 2017 09:11:22 -0400 Subject: [PATCH 4/7] Make sure to no include ensemble when using dynamic config. --- libraries/zookeeper_config.rb | 20 ++++++++++++++------ metadata.rb | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/libraries/zookeeper_config.rb b/libraries/zookeeper_config.rb index eb3b642..7e8bcf5 100644 --- a/libraries/zookeeper_config.rb +++ b/libraries/zookeeper_config.rb @@ -38,12 +38,20 @@ class ZookeeperConfig < Chef::Resource # Outputs the +properties+ in the Java Properties file format. This is # what Zookeeper daemon consumes to tweak its internal configuration. def to_s - servers = ensemble.map { |n| "server.#{ensemble.index(n).next}:#{n}:#{leader_port}:#{election_port}" } - properties.merge( - 'dataDir' => data_dir, - 'leaderPort' => leader_port, - 'clientPort' => client_port, - 'electionPort' => election_port).map { |kv| kv.join('=') }.concat(servers).join("\n") + if properties.key?(:dynamicConfigFile) + properties.merge( + 'dataDir' => data_dir, + 'leaderPort' => leader_port, + 'clientPort' => client_port, + 'electionPort' => election_port).map { |kv| kv.join('=') }.join("\n") + else + servers = ensemble.map { |n| "server.#{ensemble.index(n).next}:#{n}:#{leader_port}:#{election_port}" } + properties.merge( + 'dataDir' => data_dir, + 'leaderPort' => leader_port, + 'clientPort' => client_port, + 'electionPort' => election_port).map { |kv| kv.join('=') }.concat(servers).join("\n") + end end diff --git a/metadata.rb b/metadata.rb index 010a7ea..1875dfe 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Application cookbook which installs and configures a Zookeeper cluster.' long_description 'Application cookbook which installs and configures a Zookeeper cluster.' -version '1.3.4' +version '1.3.5' supports 'ubuntu', '>= 12.04' supports 'centos', '>= 6.6' From 08fd2cda1bf6420080e8de4870241f01c8937f01 Mon Sep 17 00:00:00 2001 From: Saheem Granados Date: Fri, 7 Apr 2017 09:30:21 -0400 Subject: [PATCH 5/7] review comment. --- libraries/zookeeper_config.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libraries/zookeeper_config.rb b/libraries/zookeeper_config.rb index 7e8bcf5..f502b83 100644 --- a/libraries/zookeeper_config.rb +++ b/libraries/zookeeper_config.rb @@ -38,20 +38,17 @@ class ZookeeperConfig < Chef::Resource # Outputs the +properties+ in the Java Properties file format. This is # what Zookeeper daemon consumes to tweak its internal configuration. def to_s - if properties.key?(:dynamicConfigFile) - properties.merge( + retval = properties.merge( 'dataDir' => data_dir, 'leaderPort' => leader_port, 'clientPort' => client_port, - 'electionPort' => election_port).map { |kv| kv.join('=') }.join("\n") - else + 'electionPort' => election_port).map { |kv| kv.join('=') } + + if !properties.key?(:dynamicConfigFile) servers = ensemble.map { |n| "server.#{ensemble.index(n).next}:#{n}:#{leader_port}:#{election_port}" } - properties.merge( - 'dataDir' => data_dir, - 'leaderPort' => leader_port, - 'clientPort' => client_port, - 'electionPort' => election_port).map { |kv| kv.join('=') }.concat(servers).join("\n") + retval.concat(servers) end + retval.join("\n") end From aa74d253639eec597b080e9cd3c6f53ff0082747 Mon Sep 17 00:00:00 2001 From: Saheem Granados Date: Fri, 7 Apr 2017 10:09:33 -0400 Subject: [PATCH 6/7] Revert "Make sure to no include ensemble when using dynamic config." --- libraries/zookeeper_config.rb | 17 ++++++----------- metadata.rb | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/libraries/zookeeper_config.rb b/libraries/zookeeper_config.rb index f502b83..eb3b642 100644 --- a/libraries/zookeeper_config.rb +++ b/libraries/zookeeper_config.rb @@ -38,17 +38,12 @@ class ZookeeperConfig < Chef::Resource # Outputs the +properties+ in the Java Properties file format. This is # what Zookeeper daemon consumes to tweak its internal configuration. def to_s - retval = properties.merge( - 'dataDir' => data_dir, - 'leaderPort' => leader_port, - 'clientPort' => client_port, - 'electionPort' => election_port).map { |kv| kv.join('=') } - - if !properties.key?(:dynamicConfigFile) - servers = ensemble.map { |n| "server.#{ensemble.index(n).next}:#{n}:#{leader_port}:#{election_port}" } - retval.concat(servers) - end - retval.join("\n") + servers = ensemble.map { |n| "server.#{ensemble.index(n).next}:#{n}:#{leader_port}:#{election_port}" } + properties.merge( + 'dataDir' => data_dir, + 'leaderPort' => leader_port, + 'clientPort' => client_port, + 'electionPort' => election_port).map { |kv| kv.join('=') }.concat(servers).join("\n") end diff --git a/metadata.rb b/metadata.rb index 1875dfe..010a7ea 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Application cookbook which installs and configures a Zookeeper cluster.' long_description 'Application cookbook which installs and configures a Zookeeper cluster.' -version '1.3.5' +version '1.3.4' supports 'ubuntu', '>= 12.04' supports 'centos', '>= 6.6' From 2bc6d1ef1fc37bf3449eab4f6cc91e46a56ec5c9 Mon Sep 17 00:00:00 2001 From: Saheem Granados Date: Mon, 10 Apr 2017 12:31:55 -0400 Subject: [PATCH 7/7] removed extra space. --- libraries/zookeeper_config.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/zookeeper_config.rb b/libraries/zookeeper_config.rb index eb3b642..0759860 100644 --- a/libraries/zookeeper_config.rb +++ b/libraries/zookeeper_config.rb @@ -46,7 +46,6 @@ def to_s 'electionPort' => election_port).map { |kv| kv.join('=') }.concat(servers).join("\n") end - action(:create) do notifying_block do directory ::File.dirname(new_resource.path) do