From e0a62d88cfb185b758005a526e43608480d2a04e Mon Sep 17 00:00:00 2001 From: amartynov Date: Mon, 10 Aug 2015 13:01:34 +0300 Subject: [PATCH] fixed bootstrap worker --- devops-service/app/api2/handlers/server.rb | 17 +++++++---------- devops-service/commands/server.rb | 3 ++- devops-service/workers/bootstrap_worker.rb | 9 +++++---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/devops-service/app/api2/handlers/server.rb b/devops-service/app/api2/handlers/server.rb index c543138..bf1ab83 100644 --- a/devops-service/app/api2/handlers/server.rb +++ b/devops-service/app/api2/handlers/server.rb @@ -166,14 +166,14 @@ module Devops end def bootstrap_server - s = prepare_bootstrap_server + s, rl, bt = prepare_bootstrap_server dir = DevopsConfig[:report_dir_v2] files = [] uri = URI.parse(@request.url) h = s.to_hash - h["options"] = s.options +# h["options"] = s.options h["_id"] = s.id - jid = BootstrapWorker.perform_async(dir, d.provider, h, parser.current_user, DevopsConfig.config) + jid = BootstrapWorker.perform_async(dir, s.provider, h, bt, parser.current_user, DevopsConfig.config) Worker.set_status jid, Worker::STATUS::IN_QUEUE logger.info "Job '#{jid}' has been started" uri.path = "#{DevopsConfig[:url_prefix]}/v2.0/report/" + jid @@ -188,24 +188,22 @@ module Devops body = parser.bootstrap id = body["instance_id"] name = body["name"] + rl = body["run_list"] + t = body["bootstrap_template"] s = Devops::Db.connector.server_by_instance_id(id) p = Devops::Db.connector.check_project_auth s.project, s.deploy_env, parser.current_user - d = p.deploy_env s.deploy_env + d = p.deploy_env(s.deploy_env) provider = ::Provider::ProviderFactory.get(s.provider) check_chef_node_name(name, provider) unless name.nil? - s.options = { - :run_list => rl || d.run_list, - } unless t.nil? templates = get_templates halt_response("Invalid bootstrap template '#{t}', available values: #{templates.join(", ")}", 400) unless templates.include?(t) - s.options[:bootstrap_template] = t end s.chef_node_name = name || provider.create_default_chef_node_name(s) - s + return s, rl || d.run_list, t end def add_server @@ -225,7 +223,6 @@ module Devops s.remote_user = body["remote_user"] s.private_ip = body["private_ip"] s.public_ip = body["public_ip"] - s.static = true s.id = "static_#{cert.id}-#{Time.now.to_i}" s.key = cert.id Devops::Db.connector.server_insert s diff --git a/devops-service/commands/server.rb b/devops-service/commands/server.rb index 7dd1aff..6568eb9 100644 --- a/devops-service/commands/server.rb +++ b/devops-service/commands/server.rb @@ -6,7 +6,7 @@ require "exceptions/record_not_found" module ServerCommands include DeployCommands - +=begin def create_server_proc lambda do |out, s, provider| mongo = ::Devops::Db.connector @@ -29,6 +29,7 @@ module ServerCommands end end end +=end def create_server project, env, params, user, out provider = ::Provider::ProviderFactory.get(env.provider) diff --git a/devops-service/workers/bootstrap_worker.rb b/devops-service/workers/bootstrap_worker.rb index 8549d05..07d8175 100644 --- a/devops-service/workers/bootstrap_worker.rb +++ b/devops-service/workers/bootstrap_worker.rb @@ -11,11 +11,11 @@ require "db/mongo/models/report" class BootstrapWorker < Worker include ServerCommands - def perform(dir, e_provider, server, owner, conf) + def perform(dir, e_provider, server, bootstrap_template, owner, conf) call(conf, e_provider, dir) do |provider, out, file| mongo = Devops::Db.connector s = Server.new(server) - s.options = convert_config(server["options"]) +# s.options = convert_config(server["options"]) o = { "file" => file, "_id" => jid, @@ -27,8 +27,9 @@ class BootstrapWorker < Worker mongo.save_report(Report.new(o)) key = mongo.key(s.key) - out << "\nBootstrap with run list: #{s.options[:run_list].inspect}" - status = bootstrap(s, out, key.path) +# out << "\nBootstrap with run list: #{s.options[:run_list].inspect}" + status = two_phase_bootstrap s, provider.run_list, bootstrap_template, key.path, out +# status = bootstrap(s, out, key.path) mongo.set_report_server_data(jid, s.chef_node_name, s.public_ip || s.private_ip) status end