lib/rundock/builder/target_builder.rb in rundock-1.1.7 vs lib/rundock/builder/target_builder.rb in rundock-1.2.0

- old
+ new

@@ -1,52 +1,31 @@ module Rundock module Builder class TargetBuilder < Base - TargetNoSupportError = Class.new(NotImplementedError) - TargetGroupNotFoundError = Class.new(StandardError) + DEFAULT_TARGET_TYPE = 'host' - attr_accessor :parsed_node_options - def build(target_name, target_info) - # host type specified if target not found. - if target_info.nil? || - !target_info.key?(target_name.to_sym) || - !target_info[target_name.to_sym].key?(:target_type) || - target_info[target_name.to_sym][:target_type] == 'host' + target_type = DEFAULT_TARGET_TYPE - backend_builder = BackendBuilder.new(@options, target_name, target_info) - backend = backend_builder.build - @parsed_node_options = { target_name.to_sym => backend_builder.parsed_options } + if target_info.nil? || + !target_info.key?(target_name.to_sym) + target_info = { target_name.to_sym => {} } + target_type = DEFAULT_TARGET_TYPE else - raise TargetNoSupportError + target_type = if target_info[target_name.to_sym].key?(:target_type) + target_info[target_name.to_sym][:target_type] + else + DEFAULT_TARGET_TYPE + end end - Node.new(target_name, backend) - end - - def build_group(target_group_name, target_info) - if !target_info.nil? && - target_info.key?(target_group_name.to_sym) && - target_info[target_group_name.to_sym][:target_type] == 'group' && - target_info[target_group_name.to_sym].key?(:targets) && - target_info[target_group_name.to_sym][:targets].is_a?(Array) - - targets = target_info[target_group_name.to_sym][:targets] - nodes = [] - @parsed_node_options = {} - - targets.each do |n| - backend_builder = BackendBuilder.new(@options, n, target_info) - backend = backend_builder.build - - @parsed_node_options[n.to_sym] = backend_builder.parsed_options - nodes << Node.new(n, backend) - end - - nodes - else - raise TargetGroupNotFoundError + begin + target = Rundock::TargetFactory.instance(target_type).create(target_name, target_info[target_name.to_sym]) + rescue Rundock::TargetFactory::TargetNotSupportedError + Logger.error("target type not supported: #{target_type}") end + + target.create_nodes(target_info, @options) end end end end