Skip to content

Commit

Permalink
Merge pull request #1898 from obino/remove-homedir-references
Browse files Browse the repository at this point in the history
Remove homedir references
  • Loading branch information
cdonati committed Jan 8, 2016
2 parents c326b84 + 8a61b92 commit d7fc2dc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 134 deletions.
65 changes: 32 additions & 33 deletions AppController/djinn.rb
Expand Up @@ -258,17 +258,17 @@ class Djinn

# The location on the local filesystem where AppScale-related configuration
# files are written to.
CONFIG_FILE_LOCATION = "/etc/appscale"
APPSCALE_CONFIG_DIR = "/etc/appscale"


# The location on the local filesystem where the AppController periodically
# writes its state to, and recovers its state from if it crashes.
STATE_FILE = "#{CONFIG_FILE_LOCATION}/appcontroller-state.json"
STATE_FILE = "#{APPSCALE_CONFIG_DIR}/appcontroller-state.json"


# The location on the local filesystem where the AppController writes
# the location of all the nodes which are taskqueue nodes.
TASKQUEUE_FILE = "#{CONFIG_FILE_LOCATION}/taskqueue_nodes"
TASKQUEUE_FILE = "#{APPSCALE_CONFIG_DIR}/taskqueue_nodes"


APPSCALE_HOME = ENV['APPSCALE_HOME']
Expand Down Expand Up @@ -711,7 +711,7 @@ def relocate_app(appid, http_port, https_port, secret)
# Finally, the AppServer takes in the port to send Task Queue tasks to
# from a file. Update the file and restart the AppServers so they see
# the new port. Do this in a separate thread to avoid blocking the caller.
port_file = "#{CONFIG_FILE_LOCATION}/port-#{appid}.txt"
port_file = "#{APPSCALE_CONFIG_DIR}/port-#{appid}.txt"
HelperFunctions.write_file(port_file, http_port)

Thread.new {
Expand Down Expand Up @@ -1472,7 +1472,7 @@ def stop_app(app_name, secret)
end
end
}
pid_files = HelperFunctions.shell("ls #{CONFIG_FILE_LOCATION}/xmpp-#{app_name}.pid").split
pid_files = HelperFunctions.shell("ls #{APPSCALE_CONFIG_DIR}/xmpp-#{app_name}.pid").split
unless pid_files.nil? # not an error here - XMPP is optional
pid_files.each { |pid_file|
pid = HelperFunctions.read_file(pid_file)
Expand Down Expand Up @@ -2234,7 +2234,6 @@ def add_nodes(node_info)
def erase_old_data()
Djinn.log_run("rm -rf #{Dir.tmpdir}/h*")
Djinn.log_run("rm -f ~/.appscale_cookies")
Djinn.log_run("rm -f #{APPSCALE_HOME}/.appscale/database_info")

Nginx.clear_sites_enabled()
HAProxy.clear_sites_enabled()
Expand Down Expand Up @@ -2425,13 +2424,13 @@ def get_db_master()
end

def self.get_db_master_ip()
masters_file = File.expand_path("#{CONFIG_FILE_LOCATION}/masters")
masters_file = File.expand_path("#{APPSCALE_CONFIG_DIR}/masters")
master_ip = HelperFunctions.read_file(masters_file)
return master_ip
end

def self.get_db_slave_ips()
slaves_file = File.expand_path("#{CONFIG_FILE_LOCATION}/slaves")
slaves_file = File.expand_path("#{APPSCALE_CONFIG_DIR}/slaves")
slave_ips = File.open(slaves_file).readlines.map { |f| f.chomp! }
slave_ips = [] if slave_ips == [""]
return slave_ips
Expand Down Expand Up @@ -2640,11 +2639,11 @@ def write_database_info()
keyname = @options["keyname"]

tree = { :table => table, :replication => replication, :keyname => keyname }
db_info_path = "#{CONFIG_FILE_LOCATION}/database_info.yaml"
db_info_path = "#{APPSCALE_CONFIG_DIR}/database_info.yaml"
File.open(db_info_path, "w") { |file| YAML.dump(tree, file) }

num_of_nodes = @nodes.length
HelperFunctions.write_file("#{CONFIG_FILE_LOCATION}/num_of_nodes", "#{num_of_nodes}\n")
HelperFunctions.write_file("#{APPSCALE_CONFIG_DIR}/num_of_nodes", "#{num_of_nodes}\n")
end


Expand All @@ -2656,7 +2655,7 @@ def update_firewall()
end
}
all_ips << "\n"
HelperFunctions.write_file("#{CONFIG_FILE_LOCATION}/all_ips", all_ips.join("\n"))
HelperFunctions.write_file("#{APPSCALE_CONFIG_DIR}/all_ips", all_ips.join("\n"))
Djinn.log_debug("Letting the following IPs through the firewall: " +
all_ips.join(', '))

Expand Down Expand Up @@ -2764,9 +2763,9 @@ def restore_appcontroller_state()
# from local files. state_change_lock is a Monitor: no need to
# restore it.
if k == "@my_private_ip"
@my_private_ip = HelperFunctions.read_file("#{CONFIG_FILE_LOCATION}/my_private_ip").chomp
@my_private_ip = HelperFunctions.read_file("#{APPSCALE_CONFIG_DIR}/my_private_ip").chomp
elsif k == "@my_public_ip"
@my_public_ip = HelperFunctions.read_file("#{CONFIG_FILE_LOCATION}/my_public_ip").chomp
@my_public_ip = HelperFunctions.read_file("#{APPSCALE_CONFIG_DIR}/my_public_ip").chomp
elsif k != "@state_change_lock"
instance_variable_set(k, v)
end
Expand Down Expand Up @@ -3279,11 +3278,11 @@ def parse_options

keypath = @options['keyname'] + ".key"
Djinn.log_debug("Keypath is #{keypath}, keyname is #{@options['keyname']}")
my_key_dir = "#{CONFIG_FILE_LOCATION}/keys/#{my_node.cloud}"
my_key_dir = "#{APPSCALE_CONFIG_DIR}/keys/#{my_node.cloud}"
my_key_loc = "#{my_key_dir}/#{keypath}"
Djinn.log_debug("Creating directory #{my_key_dir} for my ssh key #{my_key_loc}")
FileUtils.mkdir_p(my_key_dir)
Djinn.log_run("cp #{CONFIG_FILE_LOCATION}/ssh.key #{my_key_loc}")
Djinn.log_run("cp #{APPSCALE_CONFIG_DIR}/ssh.key #{my_key_loc}")

if is_cloud?
# for euca
Expand All @@ -3292,7 +3291,7 @@ def parse_options
ENV['EC2_URL'] = @options["ec2_url"]

# for ec2
cloud_keys_dir = File.expand_path("#{CONFIG_FILE_LOCATION}/keys/cloud1")
cloud_keys_dir = File.expand_path("#{APPSCALE_CONFIG_DIR}/keys/cloud1")
ENV['EC2_PRIVATE_KEY'] = "#{cloud_keys_dir}/mykey.pem"
ENV['EC2_CERT'] = "#{cloud_keys_dir}/mycert.pem"
end
Expand Down Expand Up @@ -3929,17 +3928,17 @@ def copy_encryption_keys(dest_node)
"~#{user_name}/.ssh/authorized_keys /root/.ssh/authorized_keys.old'")
end

secret_key_loc = "#{CONFIG_FILE_LOCATION}/secret.key"
cert_loc = "#{CONFIG_FILE_LOCATION}/certs/mycert.pem"
key_loc = "#{CONFIG_FILE_LOCATION}/certs/mykey.pem"
secret_key_loc = "#{APPSCALE_CONFIG_DIR}/secret.key"
cert_loc = "#{APPSCALE_CONFIG_DIR}/certs/mycert.pem"
key_loc = "#{APPSCALE_CONFIG_DIR}/certs/mykey.pem"
pub_key = File.expand_path("~/.ssh/id_rsa.pub")

HelperFunctions.scp_file(secret_key_loc, secret_key_loc, ip, ssh_key)
HelperFunctions.scp_file(cert_loc, cert_loc, ip, ssh_key)
HelperFunctions.scp_file(key_loc, key_loc, ip, ssh_key)
scp_ssh_key_to_ip(ip, ssh_key, pub_key)

cloud_keys_dir = File.expand_path("#{CONFIG_FILE_LOCATION}/keys/cloud1")
cloud_keys_dir = File.expand_path("#{APPSCALE_CONFIG_DIR}/keys/cloud1")
make_dir = "mkdir -p #{cloud_keys_dir}"

cloud_private_key = "#{cloud_keys_dir}/mykey.pem"
Expand All @@ -3954,8 +3953,8 @@ def copy_encryption_keys(dest_node)
# nodes need to attach persistent disks.
return if @options["infrastructure"] != "gce"

client_secrets = "#{CONFIG_FILE_LOCATION}/client_secrets.json"
gce_oauth = "#{CONFIG_FILE_LOCATION}/oauth2.dat"
client_secrets = "#{APPSCALE_CONFIG_DIR}/client_secrets.json"
gce_oauth = "#{APPSCALE_CONFIG_DIR}/oauth2.dat"

if File.exists?(client_secrets)
HelperFunctions.scp_file(client_secrets, client_secrets, ip, ssh_key)
Expand Down Expand Up @@ -4042,21 +4041,21 @@ def setup_config_files()
Djinn.log_debug("Master is at #{master_ip}, slaves are at #{slave_ips.join(', ')}")

my_public = my_node.public_ip
HelperFunctions.write_file("#{CONFIG_FILE_LOCATION}/my_public_ip", "#{my_public}\n")
HelperFunctions.write_file("#{APPSCALE_CONFIG_DIR}/my_public_ip", "#{my_public}\n")

my_private = my_node.private_ip
HelperFunctions.write_file("#{CONFIG_FILE_LOCATION}/my_private_ip", "#{my_private}\n")
HelperFunctions.write_file("#{APPSCALE_CONFIG_DIR}/my_private_ip", "#{my_private}\n")

head_node_ip = get_public_ip(@options['hostname'])
HelperFunctions.write_file("#{CONFIG_FILE_LOCATION}/head_node_ip", "#{head_node_ip}\n")
HelperFunctions.write_file("#{APPSCALE_CONFIG_DIR}/head_node_ip", "#{head_node_ip}\n")

login_ip = get_login.public_ip
HelperFunctions.write_file("#{CONFIG_FILE_LOCATION}/login_ip", "#{login_ip}\n")
HelperFunctions.write_file("#{APPSCALE_CONFIG_DIR}/login_ip", "#{login_ip}\n")

login_private_ip = get_login.private_ip
HelperFunctions.write_file("#{CONFIG_FILE_LOCATION}/login_private_ip", "#{login_private_ip}\n")
HelperFunctions.write_file("#{APPSCALE_CONFIG_DIR}/login_private_ip", "#{login_private_ip}\n")

HelperFunctions.write_file("#{CONFIG_FILE_LOCATION}/masters", "#{master_ip}\n")
HelperFunctions.write_file("#{APPSCALE_CONFIG_DIR}/masters", "#{master_ip}\n")

if @nodes.length == 1
Djinn.log_info("Only saw one machine, therefore my node is " +
Expand All @@ -4065,7 +4064,7 @@ def setup_config_files()
end

slave_ips_newlined = slave_ips.join("\n")
HelperFunctions.write_file("#{CONFIG_FILE_LOCATION}/slaves", "#{slave_ips_newlined}\n")
HelperFunctions.write_file("#{APPSCALE_CONFIG_DIR}/slaves", "#{slave_ips_newlined}\n")

# Invoke datastore helper function
setup_db_config_files(master_ip, slave_ips, Integer(@options["replication"]))
Expand Down Expand Up @@ -4094,7 +4093,7 @@ def write_memcache_locations()
memcache_contents = memcache_ips.join("\n")
# We write the file only if something changed.
if memcache_contents != @memcache_contents
memcache_file = "#{CONFIG_FILE_LOCATION}/memcache_ips"
memcache_file = "#{APPSCALE_CONFIG_DIR}/memcache_ips"
HelperFunctions.write_file(memcache_file, memcache_contents)
@memcache_contents = memcache_contents
Djinn.log_debug("Updated memcache servers to #{memcache_ips.join(', ')}")
Expand All @@ -4108,7 +4107,7 @@ def write_memcache_locations()
# to access this IP address, we use the public IP here instead of the
# private IP.
def write_apploadbalancer_location()
login_file = "#{CONFIG_FILE_LOCATION}/appdashboard_public_ip"
login_file = "#{APPSCALE_CONFIG_DIR}/appdashboard_public_ip"
login_ip = get_login.public_ip()
HelperFunctions.write_file(login_file, login_ip)
end
Expand Down Expand Up @@ -4139,7 +4138,7 @@ def find_nearest_taskqueue()

Djinn.log_debug("AppServers on this node will connect to TaskQueue " +
"at #{rabbitmq_ip}")
rabbitmq_file = "#{CONFIG_FILE_LOCATION}/rabbitmq_ip"
rabbitmq_file = "#{APPSCALE_CONFIG_DIR}/rabbitmq_ip"
rabbitmq_contents = rabbitmq_ip
HelperFunctions.write_file(rabbitmq_file, rabbitmq_contents)
end
Expand Down Expand Up @@ -4698,7 +4697,7 @@ def setup_appengine_application(app, state)
https_port = @app_info_map[app]['nginx_https']
proxy_port = @app_info_map[app]['haproxy']

port_file = "#{CONFIG_FILE_LOCATION}/port-#{app}.txt"
port_file = "#{APPSCALE_CONFIG_DIR}/port-#{app}.txt"
if my_node.is_login?
HelperFunctions.write_file(port_file, "#{@app_info_map[app]['nginx']}")
Djinn.log_debug("App #{app} will be using nginx port #{nginx_port}, " +
Expand Down
94 changes: 2 additions & 92 deletions AppController/lib/helperfunctions.rb
Expand Up @@ -175,7 +175,7 @@ def self.read_json_file(location)

# Extracts the version from the VERSION file.
def self.get_appscale_version
version_contents = self.read_file(APPSCALE_HOME + '/VERSION')
version_contents = self.read_file(APPSCALE_CONFIG_DIR + '/VERSION')
version_line = version_contents[/AppScale version (.*)/]
version_line.sub! 'AppScale version', ''
return version_line.strip()
Expand Down Expand Up @@ -639,83 +639,14 @@ def self.get_optimal_spot_price(instance_type)
end


def self.set_options_in_env(options, cloud_num)
ENV['EC2_JVM_ARGS'] = nil

options.each_pair { |k, v|
next unless k =~ /\ACLOUD/
env_key = k.scan(/\ACLOUD_(.*)\Z/).flatten.to_s
ENV[env_key] = v
}

# note that key and cert vars are set wrong - they refer to
# the location on the user's machine where the key is
# thus, let's fix that

cloud_keys_dir = File.expand_path("#{APPSCALE_HOME}/.appscale/keys/cloud#{cloud_num}")
ENV['EC2_PRIVATE_KEY'] = "#{cloud_keys_dir}/mykey.pem"
ENV['EC2_CERT'] = "#{cloud_keys_dir}/mycert.pem"

Djinn.log_debug("Setting private key to #{cloud_keys_dir}/mykey.pem, cert to #{cloud_keys_dir}/mycert.pem")
end

def self.spawn_hybrid_vms(options, nodes)
info = "Spawning hybrid vms with options #{self.obscure_options(options).inspect} and nodes #{nodes.inspect}"
Djinn.log_debug(info)

cloud_info = []

cloud_num = 1
loop {
cloud_type = options["CLOUD#{cloud_num}_TYPE"]
break if cloud_type.nil?

self.set_options_in_env(options, cloud_num)

if cloud_type == "euca"
machine = options["CLOUD#{cloud_num}_EMI"]
elsif cloud_type == "ec2"
machine = options["CLOUD#{cloud_num}_AMI"]
else
self.log_and_crash("Cloud type was #{cloud_type}, which is not a supported value.")
end

num_of_vms = 0
jobs_needed = []
nodes.each_pair { |k, v|
if k =~ /\Acloud#{cloud_num}-\d+\Z/
num_of_vms += 1
jobs_needed << v
end
}

instance_type = "m1.large"
keyname = options["keyname"]
cloud = "cloud#{cloud_num}"
group = options["group"]

this_cloud_info = self.spawn_vms(num_of_vms, jobs_needed, machine,
instance_type, keyname, cloud_type, cloud, group)

Djinn.log_debug("Cloud#{cloud_num} reports the following info: #{this_cloud_info.join(', ')}")

cloud_info += this_cloud_info
cloud_num += 1
}

Djinn.log_debug("Hybrid cloud spawning reports the following info: #{cloud_info.join(', ')}")

return cloud_info
end

def self.spawn_vms(num_of_vms_to_spawn, job, image_id, instance_type, keyname,
infrastructure, cloud, group, spot=false)

start_time = Time.now

return [] if num_of_vms_to_spawn < 1

ssh_key = File.expand_path("#{APPSCALE_HOME}/.appscale/keys/#{cloud}/#{keyname}.key")
ssh_key = File.expand_path("#{APPSCALE_CONFIG_DIR}/keys/#{cloud}/#{keyname}.key")
Djinn.log_debug("About to spawn VMs, expecting to find a key at #{ssh_key}")

self.log_obscured_env
Expand Down Expand Up @@ -891,27 +822,6 @@ def self.terminate_vms(nodes, infrastructure)
self.shell("#{infrastructure}-terminate-instances #{instances.join(' ')}")
end

def self.terminate_hybrid_vms(options)
# TODO: kill my own cloud last
# otherwise could orphan other clouds

cloud_num = 1
loop {
key = "CLOUD#{cloud_num}_TYPE"
cloud_type = options[key]
break if cloud_type.nil?

self.set_options_in_env(options, cloud_num)

keyname = options["keyname"]
Djinn.log_debug("Killing Cloud#{cloud_num}'s machines, of type #{cloud_type} and with keyname #{keyname}")
self.terminate_all_vms(cloud_type, keyname)

cloud_num += 1
}

end

def self.terminate_all_vms(infrastructure, keyname)
self.log_obscured_env
desc_instances = `#{infrastructure}-describe-instances`
Expand Down
13 changes: 6 additions & 7 deletions AppController/terminate.rb
@@ -1,5 +1,5 @@
$:.unshift File.join(File.dirname(__FILE__), "lib")
APPSCALE_HOME = ENV['APPSCALE_HOME']
APPSCALE_CONFIG_DIR = "/etc/appscale"

module TerminateHelper

Expand All @@ -9,20 +9,19 @@ module TerminateHelper
# TODO: Use FileUtils.rm_rf instead of backticks throughout this
# method.
def self.erase_appscale_state
`rm -f #{APPSCALE_HOME}/.appscale/secret.key`
`rm -f #{APPSCALE_HOME}/.appscale/database_info`
`rm -f #{APPSCALE_CONFIG_DIR}/secret.key`
`rm -f /tmp/uploaded-apps`
`rm -f ~/.appscale_cookies`
`rm -f /var/appscale/*.pid`
`rm -f /etc/nginx/sites-enabled/*.conf`
`rm -f /etc/monit/conf.d/appscale*.cfg`
`rm -f /etc/monit/conf.d/controller-17443.cfg`
`service monit restart`
`rm -f /etc/appscale/port-*.txt`
`rm -f /etc/appscale/search_ip`
`rm -f #{APPSCALE_CONFIG_DIR}/port-*.txt`
`rm -f #{APPSCALE_CONFIG_DIR}/search_ip`

# TODO: Use the constant in djinn.rb (ZK_LOCATIONS_FILE)
`rm -rf /etc/appscale/zookeeper_locations.json`
`rm -rf #{APPSCALE_CONFIG_DIR}/zookeeper_locations.json`
`rm -f /opt/appscale/appcontroller-state.json`
`rm -f /opt/appscale/appserver-state.json`
end
Expand All @@ -37,7 +36,7 @@ def self.erase_appscale_full_state
# TODO: It may be wise to save the apps for when AppScale starts up
# later.
`rm -rf /var/apps/`
`rm -rf #{APPSCALE_HOME}/.appscale/*.pid`
`rm -rf #{APPSCALE_CONFIG_DIR}/*.pid`
`rm -rf /tmp/ec2/*`
`rm -rf /tmp/*started`
end
Expand Down

0 comments on commit d7fc2dc

Please sign in to comment.