Skip to content

Instantly share code, notes, and snippets.

@kornypoet
Created July 8, 2014 16:04
Show Gist options
  • Save kornypoet/c778ce7fd4b38f8e97eb to your computer and use it in GitHub Desktop.
Save kornypoet/c778ce7fd4b38f8e97eb to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
$:.unshift '/Users/travis/ics/weavr/lib'
require 'weavr'
require 'yaml'
require 'erb'
cluster_name = ARGV[0]
cluster_action = ARGV[1]
case cluster_action
when 'stop'
cluster = Weavr.connection.cluster cluster_name
puts cluster
requests = cluster.services.map(&:stop)
while requests.any?{ |req| req.id && req.progress_percent != 100.0 }
sleep 1
requests.each{ |req| req.refresh! if req.id }
end
cluster.delete
when 'start'
Weavr.connection.create_cluster cluster_name
cluster = Weavr.connection.cluster cluster_name
@hosts = %w[ hdp0.platform.infochimps hdp1.platform.infochimps hdp2.platform.infochimps ]
cluster.add_hosts *@hosts
cluster.add_services 'HDFS'
cluster.add_components 'HDFS', %w[ NAMENODE DATANODE ]
cluster.assign_host_components('hdp0.platform.infochimps' => 'NAMENODE',
'hdp1.platform.infochimps' => 'DATANODE',
'hdp2.platform.infochimps' => 'DATANODE')
Dir[File.expand_path('../../config/hadoop/*.erb', __FILE__)].each do |conf_file|
template = ERB.new File.read(conf_file)
config = YAML.load template.result(binding)
info = config['Clusters']['desired_config']
cluster.create_config(info['type'], '1', info['properties'])
end
hdfs = cluster.services.find{ |sv| sv.service_name = 'HDFS' }
install_request = hdfs.install
while install_request.id && install_request.progress_percent != 100.0
sleep 1
install_request.refresh!
end
start_request = hdfs.start
while start_request.id && start_request.progress_percent != 100.0
sleep 1
start_request.refresh!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment