return model in mongo insert and update commands

This commit is contained in:
Anton Chuchkalov 2015-07-30 01:22:54 +02:00
parent 5203455436
commit 9c8f685f44
5 changed files with 12 additions and 12 deletions

View File

@ -49,7 +49,6 @@ module Output
def create_servers_list def create_servers_list
headers = ['Logical id', 'Physical id'] headers = ['Logical id', 'Physical id']
byebug
rows = @data.map do |resource| rows = @data.map do |resource|
[resource['resource_name'], resource['physical_resource_id']] [resource['resource_name'], resource['physical_resource_id']]
end end

View File

@ -17,7 +17,6 @@ module Devops
def create_stack object def create_stack object
stack_model = Model::StackFactory.create(object['provider'], object) stack_model = Model::StackFactory.create(object['provider'], object)
Devops::Db.connector.stack_insert(stack_model) Devops::Db.connector.stack_insert(stack_model)
stack_model
end end
def stack id def stack id
@ -34,8 +33,6 @@ module Devops
stack = self.stack(id) stack = self.stack(id)
stack.sync_details! stack.sync_details!
Devops::Db.connector.stack_update(stack) Devops::Db.connector.stack_update(stack)
stack
end end
def resources id def resources id
@ -43,7 +40,7 @@ module Devops
stack.resources stack.resources
end end
def resources id, resource_id def resource id, resource_id
stack = Devops::Db.connector.stack(id) stack = Devops::Db.connector.stack(id)
stack.resource(resource_id) stack.resource(resource_id)
end end

View File

@ -44,7 +44,7 @@ module Devops
app.get_with_headers "/stack/:stack_id/resources", :headers => [:accept] do |stack_id| app.get_with_headers "/stack/:stack_id/resources", :headers => [:accept] do |stack_id|
check_privileges("stack", "r") check_privileges("stack", "r")
json Devops::API2_0::Handler::Stack.new(request, params).resources(stack_id, nil) json Devops::API2_0::Handler::Stack.new(request, params).resources(stack_id)
end end
app.get_with_headers "/stack/:stack_id/resources/:resource_id", :headers => [:accept] do |stack_id, resource_id| app.get_with_headers "/stack/:stack_id/resources/:resource_id", :headers => [:accept] do |stack_id, resource_id|

View File

@ -18,6 +18,7 @@ module Connectors
begin begin
record.validate! record.validate!
collection.insert(record.to_mongo_hash) collection.insert(record.to_mongo_hash)
record
rescue Mongo::OperationFailure => e rescue Mongo::OperationFailure => e
if e.message =~ /^11000/ if e.message =~ /^11000/
resource_name = StringHelper.underscore_class(record.class) resource_name = StringHelper.underscore_class(record.class)

View File

@ -14,12 +14,15 @@ module Connectors
end end
def update(record) def update(record)
record.validate! begin
collection.update({"_id" => record.id}, record.to_mongo_hash) record.validate!
rescue Mongo::OperationFailure => e collection.update({"_id" => record.id}, record.to_mongo_hash)
if e.message =~ /^11000/ record
resource_name = StringHelper.underscore_class(record.class) rescue Mongo::OperationFailure => e
raise InvalidRecord.new("Duplicate key error: #{resource_name} with id '#{record.id}'") if e.message =~ /^11000/
resource_name = StringHelper.underscore_class(record.class)
raise InvalidRecord.new("Duplicate key error: #{resource_name} with id '#{record.id}'")
end
end end
end end