Skip to content

Commit

Permalink
MCO-138 revert "18663 - should be internationalized"
Browse files Browse the repository at this point in the history
This reverts commits c6b9451 and 6d52920.

The i18n based around the i18n gem was incomplete and a little hard to deal
with.  For now we're pulling this implementation out for the stable series and
will revisit it in a topic branch until we have something more mature.
  • Loading branch information
richardc committed Jan 8, 2014
1 parent 4c0ff93 commit 16b027d
Show file tree
Hide file tree
Showing 125 changed files with 134 additions and 5,447 deletions.
40 changes: 0 additions & 40 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,43 +107,3 @@ task :website => :clean do
safe_system("tar -cvzf marionette-collective-org-#{Time.now.to_i}.tgz marionette-collective.org")
end
end

desc "Update the website error code reference based on current local"
task :update_msgweb do
mcollective_dir = File.join(File.dirname(__FILE__))

$:.insert(0, File.join(mcollective_dir, "lib"))

require 'mcollective'

messages = YAML.load_file(File.join(mcollective_dir, "lib", "mcollective", "locales", "en.yml"))

webdir = File.join(mcollective_dir, "website", "messages")

I18n.load_path = Dir[File.join(mcollective_dir, "lib", "mcollective", "locales", "*.yml")]
I18n.locale = :en

messages["en"].keys.each do |msg_code|
md_file = File.join(webdir, "#{msg_code}.md")

puts "....writing %s" % md_file

File.open(md_file, "w") do |md|
md.puts "---"
md.puts "layout: default"
md.puts "title: Message detail for %s" % msg_code
md.puts "toc: false"
md.puts "---"
md.puts
md.puts "Example Message"
md.puts "---------------"
md.puts
md.puts " %s" % (MCollective::Util.t("%s.example" % msg_code, :raise => true) rescue MCollective::Util.t("%s.pattern" % msg_code))
md.puts
md.puts "Additional Information"
md.puts "----------------------"
md.puts
md.puts MCollective::Util.t("%s.expanded" % msg_code, :raise => true)
end
end
end
11 changes: 0 additions & 11 deletions etc/msg-help.erb

This file was deleted.

18 changes: 15 additions & 3 deletions lib/mcollective.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
require 'rbconfig'
require 'tempfile'
require 'tmpdir'
require 'mcollective/exception'
require 'mcollective/monkey_patches'
require "mcollective/translatable"
require 'mcollective/cache'

# == The Marionette Collective
Expand All @@ -24,9 +22,23 @@
# and allow you to run agents matching discovery criteria.
#
# For an overview of the idea behind this and what it enables please see:
#
# http://www.devco.net/archives/2009/10/18/middleware_for_systems_administration.php
module MCollective
# Exceptions for the RPC system
class DDLValidationError<RuntimeError;end
class ValidatorError<RuntimeError; end
class MsgDoesNotMatchRequestID < RuntimeError; end
class MsgTTLExpired<RuntimeError;end
class NotTargettedAtUs<RuntimeError;end
class RPCError<StandardError;end
class SecurityValidationFailed<RuntimeError;end

class InvalidRPCData<RPCError;end
class MissingRPCData<RPCError;end
class RPCAborted<RPCError;end
class UnknownRPCAction<RPCError;end
class UnknownRPCError<RPCError;end

autoload :Agent, "mcollective/agent"
autoload :Agents, "mcollective/agents"
autoload :Aggregate, "mcollective/aggregate"
Expand Down
17 changes: 3 additions & 14 deletions lib/mcollective/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,10 @@ def application_failure(e, err_dest=STDERR)
raise(e)
end

if e.is_a?(CodedError)
err_dest.puts "\nThe %s application failed to run: %s: %s\n" % [ Util.colorize(:bold, $0), Util.colorize(:bold, e.code), Util.colorize(:red, e.to_s)]

err_dest.puts
if options[:verbose]
err_dest.puts "Use the 'mco doc %s' command for details about this error" % e.code
else
err_dest.puts "Use the 'mco doc %s' command for details about this error, use -v for full error backtrace details" % e.code
end
if options[:verbose]
err_dest.puts "\nThe %s application failed to run: %s\n" % [ Util.colorize(:bold, $0), Util.colorize(:red, e.to_s)]
else
if options[:verbose]
err_dest.puts "\nThe %s application failed to run: %s\n" % [ Util.colorize(:bold, $0), Util.colorize(:red, e.to_s)]
else
err_dest.puts "\nThe %s application failed to run, use -v for full error backtrace details: %s\n" % [ Util.colorize(:bold, $0), Util.colorize(:red, e.to_s)]
end
err_dest.puts "\nThe %s application failed to run, use -v for full error backtrace details: %s\n" % [ Util.colorize(:bold, $0), Util.colorize(:red, e.to_s)]
end

if options.nil? || options[:verbose]
Expand Down
30 changes: 13 additions & 17 deletions lib/mcollective/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ module MCollective
# end
#
module Cache
extend Translatable

# protects access to @cache_locks and top level @cache
@locks_mutex = Mutex.new

Expand All @@ -67,20 +65,16 @@ def self.setup(cache_name, ttl=300)
true
end

def self.check_cache!(cache_name)
raise_code(:PLMC13, "Could not find a cache called '%{cache_name}'", :debug, :cache_name => cache_name) unless has_cache?(cache_name)
end

def self.has_cache?(cache_name)
@locks_mutex.synchronize do
@cache.include?(cache_name)
end
end

def self.delete!(cache_name)
check_cache!(cache_name)

@locks_mutex.synchronize do
raise("No cache called '%s'" % cache_name) unless @cache_locks.include?(cache_name)

@cache_locks.delete(cache_name)
@cache.delete(cache_name)
end
Expand All @@ -89,7 +83,7 @@ def self.delete!(cache_name)
end

def self.write(cache_name, key, value)
check_cache!(cache_name)
raise("No cache called '%s'" % cache_name) unless @cache.include?(cache_name)

@cache_locks[cache_name].synchronize do
@cache[cache_name][key] ||= {}
Expand All @@ -101,43 +95,45 @@ def self.write(cache_name, key, value)
end

def self.read(cache_name, key)
check_cache!(cache_name)
raise("No cache called '%s'" % cache_name) unless @cache.include?(cache_name)

unless ttl(cache_name, key) > 0
raise_code(:PLMC11, "Cache expired on '%{cache_name}' key '%{item}'", :debug, :cache_name => cache_name, :item => key)
Log.debug("Cache expired on '%s' key '%s'" % [cache_name, key])
raise("Cache for item '%s' on cache '%s' has expired" % [key, cache_name])
end

log_code(:PLMC12, "Cache hit on '%{cache_name}' key '%{item}'", :debug, :cache_name => cache_name, :item => key)
Log.debug("Cache hit on '%s' key '%s'" % [cache_name, key])

@cache_locks[cache_name].synchronize do
@cache[cache_name][key][:value]
end
end

def self.ttl(cache_name, key)
check_cache!(cache_name)
raise("No cache called '%s'" % cache_name) unless @cache.include?(cache_name)

@cache_locks[cache_name].synchronize do
unless @cache[cache_name].include?(key)
raise_code(:PLMC15, "No item called '%{item}' for cache '%{cache_name}'", :debug, :cache_name => cache_name, :item => key)
Log.debug("Cache miss on '%s' key '%s'" % [cache_name, key])
raise("No item called '%s' for cache '%s'" % [key, cache_name])
end

@cache[cache_name][:max_age] - (Time.now - @cache[cache_name][key][:cache_create_time])
end
end

def self.synchronize(cache_name)
check_cache!(cache_name)
raise("No cache called '%s'" % cache_name) unless @cache.include?(cache_name)

raise_code(:PLMC14, "No block supplied to synchronize on cache '%{cache_name}'", :debug, :cache_name => cache_name) unless block_given?
raise ("No block supplied to synchronize") unless block_given?

@cache_locks[cache_name].synchronize do
yield
end
end

def self.invalidate!(cache_name, key)
check_cache!(cache_name)
raise("No cache called '%s'" % cache_name) unless @cache.include?(cache_name)

@cache_locks[cache_name].synchronize do
return false unless @cache[cache_name].include?(key)
Expand Down
5 changes: 1 addition & 4 deletions lib/mcollective/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ def loadconfig(configfile)

raise('The %s config file does not specify a libdir setting, cannot continue' % configfile) if @libdir.empty?

I18n.load_path = Dir[File.expand_path(File.join(File.dirname(__FILE__), "locales", "*.yml"))]
I18n.locale = :en

read_plugin_config_dir("#{@configdir}/plugin.d")

raise 'Identities can only match /\w\.\-/' unless @identity.match(/^[\w\.\-]+$/)
Expand All @@ -147,7 +144,7 @@ def loadconfig(configfile)
PluginManager.loadclass("Mcollective::Audit::#{@rpcauditprovider}") if @rpcaudit
PluginManager << {:type => "global_stats", :class => RunnerStats.new}

Log.logmsg(:PLMC1, "The Marionette Collective version %{version} started by %{name} using config file %{config}", :info, :version => MCollective::VERSION, :name => $0, :config => configfile)
Log.info("The Marionette Collective version #{MCollective::VERSION} started by #{$0} using config file #{configfile}")
else
raise("Cannot find config file '#{configfile}'")
end
Expand Down
6 changes: 3 additions & 3 deletions lib/mcollective/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ def self.ddl_validate(ddl, argument)
name = ddl.meta[:name]
query = ddl.entities[:data]

DDL.validation_fail!(:PLMC31, "No dataquery has been defined in the DDL for data plugin '%{plugin}'", :error, :plugin => name) unless query
raise DDLValidationError, "No dataquery has been defined in the DDL for data plugin #{name}" unless query

input = query.fetch(:input, {})
output = query.fetch(:output, {})

DDL.validation_fail!(:PLMC32, "No output has been defined in the DDL for data plugin %{plugin}", :error, :plugin => name) if output.keys.empty?
raise DDLValidationError, "No output has been defined in the DDL for data plugin #{name}" if output.keys.empty?

if input[:query]
return true if argument.nil? && input[:query][:optional]

ddl.validate_input_argument(input, :query, argument)
else
DDL.validation_fail!(:PLMC33, "No data plugin argument was declared in the '%{plugin}' DDL but an input was supplied", :error, :plugin => name) if argument
raise("No data plugin argument was declared in the %s DDL but an input was supplied" % name) if argument
return true
end
end
Expand Down
15 changes: 2 additions & 13 deletions lib/mcollective/ddl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ module DDL
autoload :DataDDL, "mcollective/ddl/dataddl"
autoload :DiscoveryDDL, "mcollective/ddl/discoveryddl"

extend Translatable

# There used to be only one big nasty DDL class with a bunch of mashed
# together behaviors. It's been around for ages and we would rather not
# ask all the users to change their DDL.new calls to some other factory
Expand Down Expand Up @@ -99,7 +97,7 @@ def self.string_to_boolean(val)
return true if ["true", "t", "yes", "y", "1"].include?(val.downcase)
return false if ["false", "f", "no", "n", "0"].include?(val.downcase)

raise_code(:PLMC17, "%{value} does not look like a boolean argument", :debug, :value => val)
raise "#{val} does not look like a boolean argument"
end

# a generic string to number function, if a number looks like a float
Expand All @@ -109,16 +107,7 @@ def self.string_to_number(val)
return val.to_f if val =~ /^\d+\.\d+$/
return val.to_i if val =~ /^\d+$/

raise_code(:PLMC16, "%{value} does not look like a numeric value", :debug, :value => val)
end

# Various DDL implementations will validate and raise on error, this is a
# utility method to correctly setup a DDLValidationError exceptions and raise them
def self.validation_fail!(code, default, level, args={})
exception = DDLValidationError.new(code, default, level, args)
exception.set_backtrace caller

raise exception
raise "#{val} does not look like a number"
end
end
end
12 changes: 6 additions & 6 deletions lib/mcollective/ddl/agentddl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ def summarize(&block)

# Sets the aggregate array for the given action
def aggregate(function, format = {:format => nil})
DDL.validation_fail!(:PLMC28, "Formats supplied to aggregation functions should be a hash", :error) unless format.is_a?(Hash)
DDL.validation_fail!(:PLMC27, "Formats supplied to aggregation functions must have a :format key", :error) unless format.keys.include?(:format)
DDL.validation_fail!(:PLMC26, "Functions supplied to aggregate should be a hash", :error) unless function.is_a?(Hash)
raise(DDLValidationError, "Formats supplied to aggregation functions should be a hash") unless format.is_a?(Hash)
raise(DDLValidationError, "Formats supplied to aggregation functions must have a :format key") unless format.keys.include?(:format)
raise(DDLValidationError, "Functions supplied to aggregate should be a hash") unless function.is_a?(Hash)

unless (function.keys.include?(:args)) && function[:args]
DDL.validation_fail!(:PLMC25, "aggregate method for action '%{action}' missing a function parameter", :error, :action => entities[@current_entity][:action])
raise DDLValidationError, "aggregate method for action '%s' missing a function parameter" % entities[@current_entity][:action]
end

entities[@current_entity][:aggregate] ||= []
Expand Down Expand Up @@ -178,15 +178,15 @@ def set_default_input_arguments(action, arguments)
def validate_rpc_request(action, arguments)
# is the action known?
unless actions.include?(action)
DDL.validation_fail!(:PLMC29, "Attempted to call action %{action} for %{plugin} but it's not declared in the DDL", :debug, :action => action, :plugin => @pluginname)
raise DDLValidationError, "Attempted to call action #{action} for #{@pluginname} but it's not declared in the DDL"
end

input = action_interface(action)[:input] || {}

input.keys.each do |key|
unless input[key][:optional]
unless arguments.keys.include?(key)
DDL.validation_fail!(:PLMC30, "Action '%{action}' needs a '%{key}' argument", :debug, :action => action, :key => key)
raise DDLValidationError, "Action #{action} needs a #{key} argument"
end
end

Expand Down
16 changes: 7 additions & 9 deletions lib/mcollective/ddl/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ module DDL
# plugin DDL then add a PlugintypeDDL class here and add your
# specific behaviors to those.
class Base
include Translatable

attr_reader :meta, :entities, :pluginname, :plugintype, :usage, :requirements

def initialize(plugin, plugintype=:agent, loadddl=true)
Expand Down Expand Up @@ -82,7 +80,7 @@ def loadddlfile
if ddlfile = findddlfile
instance_eval(File.read(ddlfile), ddlfile, 1)
else
raise_code(:PLMC40, "Can't find DDL for %{type} plugin '%{name}'", :debug, :type => @plugintype, :name => @pluginname)
raise("Can't find DDL for #{@plugintype} plugin '#{@pluginname}'")
end
end

Expand All @@ -93,7 +91,7 @@ def findddlfile(ddlname=nil, ddltype=nil)
@config.libdir.each do |libdir|
ddlfile = File.join([libdir, "mcollective", ddltype.to_s, "#{ddlname}.ddl"])
if File.exist?(ddlfile)
log_code(:PLMC18, "Found %{ddlname} ddl at %{ddlfile}", :debug, :ddlname => ddlname, :ddlfile => ddlfile)
Log.debug("Found #{ddlname} ddl at #{ddlfile}")
return ddlfile
end
end
Expand All @@ -103,12 +101,12 @@ def findddlfile(ddlname=nil, ddltype=nil)
def validate_requirements
if requirement = @requirements[:mcollective]
if Util.mcollective_version == "@DEVELOPMENT_VERSION@"
log_code(:PLMC19, "DDL requirements validation being skipped in development", :warn)
Log.warn("DDL requirements validation being skipped in development")
return true
end

if Util.versioncmp(Util.mcollective_version, requirement) < 0
DDL.validation_fail!(:PLMC20, "%{type} plugin '%{name}' requires MCollective version %{requirement} or newer", :debug, :type => @plugintype.to_s.capitalize, :name => @pluginname, :requirement => requirement)
raise DDLValidationError, "%s plugin '%s' requires MCollective version %s or newer" % [@plugintype.to_s.capitalize, @pluginname, requirement]
end
end

Expand Down Expand Up @@ -144,19 +142,19 @@ def validate_input_argument(input, key, argument)

return true
rescue => e
DDL.validation_fail!(:PLMC21, "Cannot validate input '%{input}': %{error}", :debug, :input => key, :error => e.to_s)
raise DDLValidationError, "Cannot validate input %s: %s" % [key, e.to_s]
end

# Registers an input argument for a given action
#
# See the documentation for action for how to use this
def input(argument, properties)
raise_code(:PLMC22, "Cannot determine what entity input '%{entity}' belongs to", :error, :entity => @current_entity) unless @current_entity
raise "Cannot figure out what entity input #{argument} belongs to" unless @current_entity

entity = @current_entity

[:prompt, :description, :type].each do |arg|
raise_code(:PLMC23, "Input needs a :%{property} property", :debug, :property => arg) unless properties.include?(arg)
raise "Input needs a :#{arg} property" unless properties.include?(arg)
end

@entities[entity][:input][argument] = {:prompt => properties[:prompt],
Expand Down
Loading

0 comments on commit 16b027d

Please sign in to comment.