current_progress
This commit is contained in:
parent
58e0f4d118
commit
344514d08e
@ -22,6 +22,7 @@ class StackPreset < Handler
|
|||||||
output
|
output
|
||||||
when :apply
|
when :apply
|
||||||
apply_handler
|
apply_handler
|
||||||
|
output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ class StackPreset < Handler
|
|||||||
filepath = options[:parameters_file] || enter_parameter(I18n.t('handler.stack_preset.create.parameters_file'))
|
filepath = options[:parameters_file] || enter_parameter(I18n.t('handler.stack_preset.create.parameters_file'))
|
||||||
params[:parameters] = JSON.parse(File.read(filepath))
|
params[:parameters] = JSON.parse(File.read(filepath))
|
||||||
|
|
||||||
result = post_body("/stack_presets/#{params[:id]}/apply", JSON.pretty_generate(params))
|
@list = post_body("/stack_presets/#{params[:id]}/apply", JSON.pretty_generate(params))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -19,6 +19,8 @@ class StackPresetOptions < CommonOptions
|
|||||||
|
|
||||||
parser.recognize_option_value(:provider, 'stack_preset')
|
parser.recognize_option_value(:provider, 'stack_preset')
|
||||||
parser.recognize_option_value(:stack, 'stack_preset')
|
parser.recognize_option_value(:stack, 'stack_preset')
|
||||||
|
parser.recognize_option_value(:project, 'stack_preset')
|
||||||
|
parser.recognize_option_value(:deploy_env, 'stack_preset')
|
||||||
parser.recognize_option_value(:parameters_file, 'stack_preset')
|
parser.recognize_option_value(:parameters_file, 'stack_preset')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,14 +3,15 @@ require "devops-client/output/base"
|
|||||||
module Output
|
module Output
|
||||||
class StackPreset < Base
|
class StackPreset < Base
|
||||||
|
|
||||||
def table
|
def table
|
||||||
if outputting_list?
|
if outputting_list?
|
||||||
title = I18n.t("output.title.stack_preset.list")
|
title = I18n.t("output.title.stack_preset.list")
|
||||||
headers, rows = create_list
|
headers, rows = create_list
|
||||||
create_table headers, rows, title, with_num?
|
|
||||||
else
|
else
|
||||||
@data["id"] + "\n" + @data["template_preset_body"]
|
title = I18n.t("output.title.stack.show", id: @data["id"])
|
||||||
|
headers, rows = create_apply
|
||||||
end
|
end
|
||||||
|
create_table headers, rows, title, with_num?
|
||||||
end
|
end
|
||||||
|
|
||||||
def csv
|
def csv
|
||||||
@ -36,5 +37,9 @@ module Output
|
|||||||
headers_and_rows(@data, fields_to_output)
|
headers_and_rows(@data, fields_to_output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_apply
|
||||||
|
headers_and_rows([@data], %w(id deploy_env stack_template cloud_stack_id stack_status))
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
23
devops-service/commands/stack.rb
Normal file
23
devops-service/commands/stack.rb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
module StackCommands
|
||||||
|
|
||||||
|
def sync_stack_till_not_in_progress_proc
|
||||||
|
lambda do |out, stack, mongo|
|
||||||
|
begin
|
||||||
|
10.times do |i|
|
||||||
|
sleep 10
|
||||||
|
out << "Syncing stack '#{stack.id}'..."
|
||||||
|
stack.sync_details!
|
||||||
|
if stack.stack_status != 'CREATE_IN_PROGRESS'
|
||||||
|
mongo.stack_update(stack)
|
||||||
|
out << "Stack '#{stack.id}' status is now #{stack.stack_status}"
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue StandardError => e
|
||||||
|
logger.error e.message
|
||||||
|
return 5
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@ -1,6 +1,7 @@
|
|||||||
require "providers/provider_factory"
|
require "providers/provider_factory"
|
||||||
require "db/exceptions/invalid_record"
|
require "db/exceptions/invalid_record"
|
||||||
require "json"
|
require "json"
|
||||||
|
require 'db/validators/all'
|
||||||
|
|
||||||
module Devops
|
module Devops
|
||||||
module Model
|
module Model
|
||||||
|
|||||||
@ -9,6 +9,7 @@ module Devops
|
|||||||
SERVER_TYPE = 2
|
SERVER_TYPE = 2
|
||||||
BOOTSTRAP_TYPE = 3
|
BOOTSTRAP_TYPE = 3
|
||||||
PROJECT_TEST_TYPE = 4
|
PROJECT_TEST_TYPE = 4
|
||||||
|
STACK_TYPE = 5
|
||||||
|
|
||||||
attr_accessor :id, :file, :created_at, :created_by, :project, :deploy_env, :type
|
attr_accessor :id, :file, :created_at, :created_by, :project, :deploy_env, :type
|
||||||
|
|
||||||
|
|||||||
@ -67,6 +67,18 @@ module Devops
|
|||||||
Devops::Api2.settings.mongo.stack_template(stack_template).template_body
|
Devops::Api2.settings.mongo.stack_template(stack_template).template_body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stack_status
|
||||||
|
raise 'override me'
|
||||||
|
end
|
||||||
|
|
||||||
|
def stack_statuses
|
||||||
|
# maybe they differ in different providers, so use method instead of hardcoding
|
||||||
|
{
|
||||||
|
in_progress: 'CREATE_IN_PROGRESS',
|
||||||
|
complete: 'CREATE_COMPLETE'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :provider
|
attr_accessor :provider
|
||||||
|
|
||||||
@ -77,6 +89,7 @@ module Devops
|
|||||||
def create(attrs)
|
def create(attrs)
|
||||||
model = new(attrs)
|
model = new(attrs)
|
||||||
model.create_stack_in_cloud!
|
model.create_stack_in_cloud!
|
||||||
|
model.sync_details!
|
||||||
model
|
model
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
require 'json'
|
require 'json'
|
||||||
require 'lib/stack_presets/factory'
|
require 'lib/stack_presets/factory'
|
||||||
|
require 'workers/stack_sync_worker'
|
||||||
|
|
||||||
module Devops
|
module Devops
|
||||||
module Version2_0
|
module Version2_0
|
||||||
@ -30,6 +31,21 @@ module Devops
|
|||||||
stack = preset.create_stack_from_preset(attrs)
|
stack = preset.create_stack_from_preset(attrs)
|
||||||
settings.mongo.stack_insert(stack)
|
settings.mongo.stack_insert(stack)
|
||||||
|
|
||||||
|
|
||||||
|
jid = StackSyncWorker.perform_async(
|
||||||
|
DevopsConfig[:report_dir_v2],
|
||||||
|
stack.id,
|
||||||
|
request.env['REMOTE_USER'], # owner
|
||||||
|
DevopsConfig.config
|
||||||
|
)
|
||||||
|
Worker.set_status jid, Worker::STATUS::IN_QUEUE
|
||||||
|
logger.info "Job '#{jid}' has been started"
|
||||||
|
uri = URI.parse(request.url)
|
||||||
|
uri.path = "#{DevopsConfig[:url_prefix]}/v2.0/report/" + jid
|
||||||
|
file = uri.to_s
|
||||||
|
|
||||||
|
puts "Syncing report is located here: #{file}"
|
||||||
|
|
||||||
create_response 'Created', stack.to_hash, 201
|
create_response 'Created', stack.to_hash, 201
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@ -101,7 +101,7 @@ module Sinatra
|
|||||||
# Can client works with JSON?
|
# Can client works with JSON?
|
||||||
def accept_json
|
def accept_json
|
||||||
types = request.accept_media_types
|
types = request.accept_media_types
|
||||||
unless types.include?('application/json')# or types.include?("*/*")
|
unless types.include?('application/json') or types.include?("*/*")
|
||||||
response.headers['Accept'] = 'application/json'
|
response.headers['Accept'] = 'application/json'
|
||||||
halt_response("Accept header should contains 'application/json' type", 406)
|
halt_response("Accept header should contains 'application/json' type", 406)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -4,6 +4,7 @@ require File.join(root, "create_server_worker")
|
|||||||
require File.join(root, "deploy_worker")
|
require File.join(root, "deploy_worker")
|
||||||
require File.join(root, "bootstrap_worker")
|
require File.join(root, "bootstrap_worker")
|
||||||
require File.join(root, "project_test_worker")
|
require File.join(root, "project_test_worker")
|
||||||
|
require File.join(root, "stack_sync_worker")
|
||||||
|
|
||||||
config = {}
|
config = {}
|
||||||
#require File.join(root, "../proxy")
|
#require File.join(root, "../proxy")
|
||||||
|
|||||||
30
devops-service/workers/stack_sync_worker.rb
Normal file
30
devops-service/workers/stack_sync_worker.rb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#root = File.join(File.dirname(__FILE__), "..")
|
||||||
|
#$LOAD_PATH.push root unless $LOAD_PATH.include? root
|
||||||
|
|
||||||
|
# require File.join(File.dirname(__FILE__), "workers")
|
||||||
|
require "providers/provider_factory"
|
||||||
|
require "commands/stack"
|
||||||
|
require "db/mongo/models/stack/stack_factory"
|
||||||
|
require "db/mongo/models/report"
|
||||||
|
|
||||||
|
class StackSyncWorker < Worker
|
||||||
|
include StackCommands
|
||||||
|
|
||||||
|
def perform(dir, stack_id, owner, conf)
|
||||||
|
call(conf, nil, dir) do |mongo, useless, out, file|
|
||||||
|
stack = mongo.stack(stack_id)
|
||||||
|
o = {
|
||||||
|
"file" => file,
|
||||||
|
"_id" => jid,
|
||||||
|
"created_by" => owner,
|
||||||
|
"project" => stack.project,
|
||||||
|
"deploy_env" => stack.deploy_env,
|
||||||
|
"type" => Report::STACK_TYPE
|
||||||
|
}
|
||||||
|
mongo.save_report(Report.new(o))
|
||||||
|
|
||||||
|
status = sync_stack_till_not_in_progress_proc.call(out, stack, mongo)
|
||||||
|
status
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user