#!/usr/bin/ruby # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'json' require 'emr/common' def run(cmd) if ! system(cmd) then raise "Command failed: #{cmd}" end end def sudo(cmd) run("sudo #{cmd}") end def println(*args) print *args puts end job_flow = Emr::JsonInfoFile.new('job-flow') instance_info = Emr::JsonInfoFile.new('instance') is_master = instance_info['isMaster'].to_s == 'true' $zookeeper = job_flow['masterPrivateDnsName'] def cleanUp(targetDir,runDir,logDir) println "Cleaning up stale directories.. " println "\t#{targetDir}/*drill*" sudo "rm -rf #{targetDir}/*drill*" println "\t/home/hadoop/drill" sudo "rm -rf /home/hadoop/drill" println "\t#{runDir} #{logDir}" sudo "rm -rf #{runDir} #{logDir}" end def writeDrillConfs(runDir,logDir) zookeeperConnect=$zookeeper File.open('/tmp/drill-override.conf', 'w') do |f| f.write(<> /home/hadoop/drill/bin/drill-config.sh && rm /tmp/drill-init-config.sh" File.open('/tmp/drill.conf', 'w') do |f| f.write(</mnt/var/run/drill/run-zookeeper" sudo "echo '1' >/mnt/var/run/drill/run-drill" end def installZookeeper(targetDir, runDir, logDir) zkTarGZUrl="http://beta.elasticmapreduce.s3.amazonaws.com/bootstrap-actions/zookeeper-standalone" zkTarGZ="zookeeper-3.4.5.tar.gz" println "Going to download Zookeeper distribution #{zkTarGZ} from #{zkTarGZUrl}" sudo "curl -L --silent --show-error --fail --connect-timeout 60 --max-time 720 --retry 5 -O #{zkTarGZUrl}/#{zkTarGZ}" println "Installing zookeeper in #{targetDir}" sudo "tar xzf #{zkTarGZ} && rm -f #{zkTarGZ}" sudo "mv *zookeeper* #{targetDir}/" sudo "ln -s `ls -d #{targetDir}/*zookeeper*` /home/hadoop/drill/zookeeper" File.open('/tmp/zoo.cfg', 'w') do |f| f.write(<