rservicebus 0.1.70 → 0.1.71

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,50 +3,49 @@ require 'net/sftp'
3
3
 
4
4
  module RServiceBus
5
5
 
6
- class ScpUploadHelper
7
- attr_reader :uri
6
+ class ScpUploadHelper
7
+ attr_reader :uri
8
8
 
9
- def initialize( uri )
10
- @uri = uri
11
- end
12
-
13
- def upload( source )
14
- #opportunity for smarts here. Could tar zip if it was a directory of files
9
+ def initialize( uri )
10
+ @uri = uri
11
+ end
15
12
 
16
- # Net::SCP.upload!(@uri.host, @uri.user, source, @uri.path, :recursive )
17
- RServiceBus.log "Host: #{@uri.host}, User: #{@uri.user}, Source: #{source}, Destination: #{@uri.path}", true
18
- Net::SSH.start( @uri.host, @uri.user ) do|ssh|
19
- ssh.scp.upload!( source, @uri.path, :recursive => true )
20
- end
13
+ def upload( source )
14
+ #opportunity for smarts here. Could tar zip if it was a directory of files
21
15
 
22
- end
16
+ #Net::SCP.upload!(@uri.host, @uri.user, source, @uri.path, :recursive )
17
+ RServiceBus.log "Host: #{@uri.host}, User: #{@uri.user}, Source: #{source}, Destination: #{@uri.path}", true
18
+ Net::SSH.start( @uri.host, @uri.user ) do|ssh|
19
+ ssh.scp.upload!( source, @uri.path, :recursive => true )
20
+ end
21
+ end
23
22
 
24
- def close
25
- end
23
+ def close
24
+ end
26
25
 
27
- def delete( path, filepattern )
28
- RServiceBus.log "Host: #{@uri.host}, User: #{@uri.user}, File Pattern: #{filepattern}, Destination: #{@uri.path}", true
29
- Net::SSH.start( @uri.host, @uri.user ) do |ssh|
30
- ssh.sftp.connect do |sftp|
31
- sftp.dir.glob(path, filepattern) {
32
- |file|
33
- r = sftp.remove("#{path}/#{file.name}")
34
- r.wait
35
- }
36
- end
26
+ def delete( path, filepattern )
27
+ RServiceBus.log "Host: #{@uri.host}, User: #{@uri.user}, File Pattern: #{filepattern}, Destination: #{@uri.path}", true
28
+ regexp = Regexp.new filepattern
29
+ Net::SSH.start( @uri.host, @uri.user ) do |ssh|
30
+ ssh.sftp.connect do |sftp|
31
+ sftp.dir.foreach(path) do |entry|
32
+ if entry.name =~ regexp then
33
+ r = sftp.remove("#{path}/#{entry.name}")
34
+ r.wait
37
35
  end
36
+ end
38
37
  end
39
-
38
+ end
40
39
  end
40
+ end
41
41
 
42
- class AppResource_ScpUpload<AppResource
42
+ class AppResource_ScpUpload<AppResource
43
43
 
44
- def connect(uri)
45
- return ScpUploadHelper.new( uri )
46
-
47
- return inputDir;
48
- end
44
+ def connect(uri)
45
+ return ScpUploadHelper.new( uri )
49
46
 
47
+ return inputDir;
50
48
  end
51
49
 
50
+ end
52
51
  end
@@ -1,36 +1,36 @@
1
1
  module RServiceBus
2
-
2
+
3
3
  require "zlib"
4
4
  require "yaml"
5
5
  require "uuidtools"
6
6
 
7
7
  #This is the top level message that is passed around the bus
8
8
  class Message
9
-
9
+
10
10
  attr_reader :returnAddress, :msgId, :remoteQueueName, :remoteHostName, :lastErrorSourceQueue, :lastErrorString, :correlationId, :sendAt
11
-
11
+
12
12
  # Constructor
13
13
  #
14
14
  # @param [Object] msg The msg to be sent
15
15
  # @param [Object] returnAddress A queue to which the destination message handler can send replies
16
16
  def initialize( msg, returnAddress, correlationId=nil )
17
- if ENV["RSBMSG_COMPRESS"].nil? then
17
+ if !RServiceBus.checkEnvironmentVariable('RSBMSG_COMPRESS') then
18
18
  @compressed = false
19
19
  @_msg=YAML::dump(msg)
20
20
  else
21
21
  @compressed = true
22
22
  @_msg=Zlib::Deflate.deflate(YAML::dump(msg))
23
23
  end
24
-
24
+
25
25
  @correlationId = correlationId
26
26
  @returnAddress=returnAddress
27
-
27
+
28
28
  @createdAt = DateTime.now
29
-
29
+
30
30
  @msgId=UUIDTools::UUID.random_create
31
31
  @errorList = Array.new
32
32
  end
33
-
33
+
34
34
  # If an error occurs while processing the message, this method allows details of the error to held
35
35
  # next to the msg.
36
36
  #
@@ -42,22 +42,22 @@ module RServiceBus
42
42
  def addErrorMsg( sourceQueue, errorString )
43
43
  @lastErrorSourceQueue = sourceQueue
44
44
  @lastErrorString = errorString
45
-
45
+
46
46
  @errorList << RServiceBus::ErrorMessage.new( sourceQueue, errorString )
47
47
  end
48
-
48
+
49
49
  def setRemoteHostName( hostName )
50
50
  @remoteHostName = hostName
51
51
  end
52
-
52
+
53
53
  def setRemoteQueueName( queueName )
54
54
  @remoteQueueName = queueName
55
55
  end
56
-
56
+
57
57
  def sendAt( timestamp )
58
58
  @sendAt = timestamp
59
59
  end
60
-
60
+
61
61
  # @return [Object] The msg to be sent
62
62
  def msg
63
63
  if @compressed == true then
@@ -67,13 +67,13 @@ module RServiceBus
67
67
  end
68
68
  rescue ArgumentError => e
69
69
  raise e if e.message.index( "undefined class/module " ).nil?
70
-
70
+
71
71
  puts e.message
72
72
  msg_name = e.message.sub( "undefined class/module ", "" )
73
-
73
+
74
74
  raise ClassNotFoundForMsg.new( msg_name )
75
75
  end
76
-
76
+
77
77
  end
78
-
78
+
79
79
  end
@@ -1,18 +1,16 @@
1
1
  require 'cgi'
2
- require 'zip/zip'
3
- require 'zlib'
4
2
 
5
3
  module RServiceBus
6
-
4
+
7
5
  class Monitor_DirNotifier<Monitor
8
-
9
- @Path
10
-
6
+
7
+ attr_reader :Path, :ProcessingFolder, :Filter
8
+
11
9
  def connect(uri)
12
10
  #Pass the path through the Dir object to check syntax on startup
13
11
  begin
14
- inputDir = Dir.new( uri.path )
15
- if !File.writable?( uri.path ) then
12
+ self.open_folder uri.path
13
+ if !self.file_writable?( uri.path ) then
16
14
  puts "***** Directory is not writable, #{uri.path}."
17
15
  puts "***** Make the directory, #{uri.path}, writable and try again."
18
16
  abort()
@@ -21,27 +19,80 @@ module RServiceBus
21
19
  puts "***** Directory does not exist, #{uri.path}."
22
20
  puts "***** Create the directory, #{uri.path}, and try again."
23
21
  puts "***** eg, mkdir #{uri.path}"
24
- abort();
22
+ abort()
25
23
  rescue Errno::ENOTDIR => e
26
24
  puts "***** The specified path does not point to a directory, #{uri.path}."
27
25
  puts "***** Either repoint path to a directory, or remove, #{uri.path}, and create it as a directory."
28
26
  puts "***** eg, rm #{uri.path} && mkdir #{uri.path}"
29
- abort();
27
+ abort()
28
+ end
29
+
30
+ @Path = uri.path
31
+
32
+ if uri.query.nil?
33
+ puts "***** Processing Directory is not specified."
34
+ puts "***** Specify the Processing Directory as a query string in the Path URI"
35
+ puts "***** eg, '/#{uri.path}?processing=*ProcessingDir*"
36
+ abort()
37
+ else
38
+ parts = CGI.parse(uri.query)
39
+
40
+ if parts.has_key? "processing" then
41
+ processingUri = URI.parse parts["processing"][0]
42
+ begin
43
+ self.open_folder processingUri.path
44
+ if !self.file_writable?( processingUri.path ) then
45
+ puts "***** Processing Directory is not writable, #{processingUri.path}."
46
+ puts "***** Make the directory, #{processingUri.path}, writable and try again."
47
+ abort()
48
+ end
49
+ rescue Errno::ENOENT => e
50
+ puts "***** Processing Directory does not exist, #{processingUri.path}."
51
+ puts "***** Create the directory, #{processingUri.path}, and try again."
52
+ puts "***** eg, mkdir #{processingUri.path}"
53
+ abort()
54
+ rescue Errno::ENOTDIR => e
55
+ puts "***** Processing Directory does not point to a directory, #{processingUri.path}."
56
+ puts "***** Either repoint path to a directory, or remove, #{processingUri.path}, and create it as a directory."
57
+ puts "***** eg, rm #{processingUri.path} && mkdir #{processingUri.path}"
58
+ abort()
59
+ end
60
+
61
+ @ProcessingFolder = processingUri.path
62
+ end
63
+
64
+ @Filter = "*"
65
+ if parts.has_key? "filter" then
66
+ @Filter = parts["filter"][0]
67
+ end
30
68
  end
31
-
32
- @Path = inputDir.path
33
-
34
69
  end
35
70
 
36
71
  def Look
37
-
38
- fileList = Dir.glob( "#{@Path}/*" )
72
+ fileList = self.get_files
39
73
  fileList.each do |filePath|
40
- self.send( nil, URI.parse( "file://#{filePath}" ) )
41
-
74
+ newPath = self.move_file(filePath, @ProcessingFolder)
75
+ self.send( nil, URI.parse( "file://#{newPath}" ) )
42
76
  end
43
-
44
77
  end
45
-
78
+
79
+ def file_writable? path
80
+ return File.writable? path
81
+ end
82
+
83
+ def open_folder path
84
+ Dir.new path
85
+ end
86
+
87
+ def move_file src, dest
88
+ FileUtils.mv(src, dest)
89
+ filename = Pathname.new(src).basename
90
+ return Pathname.new(dest).join(filename)
91
+ end
92
+
93
+ def get_files
94
+ return Dir.glob( Pathname.new("#{@Path}").join(@Filter) ).select { |f| File.file?(f) }
95
+ end
96
+
46
97
  end
47
98
  end
@@ -1,59 +1,59 @@
1
1
  module RServiceBus
2
-
3
-
2
+
3
+
4
4
  def RServiceBus.convertDTOToHash( obj )
5
5
  hash = {};
6
6
  obj.instance_variables.each {|var| hash[var.to_s.delete("@")] = obj.instance_variable_get(var) }
7
-
7
+
8
8
  return hash
9
9
  end
10
-
10
+
11
11
  def RServiceBus.convertDTOToJson( obj )
12
12
  hash = RServiceBus.convertDTOToHash(obj)
13
-
13
+
14
14
  return hash.to_json
15
15
  end
16
-
16
+
17
17
  def RServiceBus.log(string, ver=false)
18
- return unless ENV['TESTING'].nil?
19
-
18
+ return if RServiceBus.checkEnvironmentVariable("TESTING")
19
+
20
20
  type = ver ? "VERB" : "INFO"
21
- if !ENV["VERBOSE"].nil? || !ver then
21
+ if RServiceBus.checkEnvironmentVariable("VERBOSE") || !ver then
22
22
  timestamp = Time.new.strftime( "%Y-%m-%d %H:%M:%S" )
23
23
  puts "[#{type}] #{timestamp} :: #{string}"
24
24
  end
25
25
  end
26
-
26
+
27
27
  def RServiceBus.rlog(string)
28
- if !ENV["RSBVERBOSE"].nil? then
28
+ if RServiceBus.checkEnvironmentVariable("RSBVERBOSE") then
29
29
  timestamp = Time.new.strftime( "%Y-%m-%d %H:%M:%S" )
30
30
  puts "[RSB] #{timestamp} :: #{string}"
31
31
  end
32
32
  end
33
-
33
+
34
34
  def RServiceBus.createAnonymousClass( name_for_class )
35
35
  newAnonymousClass = Class.new(Object)
36
36
  Object.const_set( name_for_class, newAnonymousClass )
37
37
  return Object.const_get( name_for_class ).new
38
38
  end
39
-
39
+
40
40
  def RServiceBus.getValue( name, default=nil )
41
41
  value = ( ENV[name].nil? || ENV[name] == "" ) ? default : ENV[name];
42
42
  log "Env value: #{name}: #{value}"
43
43
  return value
44
44
  end
45
-
45
+
46
46
  def RServiceBus.sendMsg( msg, responseQueue="agent" )
47
47
  require "rservicebus/EndpointMapping"
48
48
  endpointMapping = EndpointMapping.new
49
49
  endpointMapping.Configure
50
50
  queueName = endpointMapping.get( msg.class.name )
51
-
51
+
52
52
  ENV["RSBMQ"] = "beanstalk://localhost" if ENV["RSBMQ"].nil?
53
53
  agent = RServiceBus::Agent.new
54
54
  Audit.new( agent ).audit( msg )
55
55
  agent.sendMsg(msg, queueName, responseQueue)
56
-
56
+
57
57
  rescue QueueNotFoundForMsg=>e
58
58
  msg = "\n"
59
59
  msg = "#{msg}*** Queue not found for, #{e.message}\n"
@@ -61,18 +61,18 @@ module RServiceBus
61
61
  msg = "#{msg}*** MESSAGE_ENDPOINT_MAPPINGS=#{e.message}:<QueueName>\n"
62
62
  raise StandardError.new( msg )
63
63
  end
64
-
64
+
65
65
  def RServiceBus.sendMsg( msg, responseQueue="agent" )
66
66
  require "rservicebus/EndpointMapping"
67
67
  endpointMapping = EndpointMapping.new
68
68
  endpointMapping.Configure
69
69
  queueName = endpointMapping.get( msg.class.name )
70
-
70
+
71
71
  ENV["RSBMQ"] = "beanstalk://localhost" if ENV["RSBMQ"].nil?
72
72
  agent = RServiceBus::Agent.new
73
73
  Audit.new( agent ).auditOutgoing( msg )
74
74
  agent.sendMsg(msg, queueName, responseQueue)
75
-
75
+
76
76
  rescue QueueNotFoundForMsg=>e
77
77
  msg = "\n"
78
78
  msg = "#{msg}*** Queue not found for, #{e.message}\n"
@@ -80,19 +80,24 @@ module RServiceBus
80
80
  msg = "#{msg}*** MESSAGE_ENDPOINT_MAPPINGS=#{e.message}:<QueueName>\n"
81
81
  raise StandardError.new( msg )
82
82
  end
83
-
83
+
84
84
  def RServiceBus.checkForReply( queueName )
85
85
  ENV["RSBMQ"] = "beanstalk://localhost" if ENV["RSBMQ"].nil?
86
86
  agent = RServiceBus::Agent.new
87
87
  msg = agent.checkForReply( queueName )
88
88
  Audit.new( agent ).auditIncoming( msg )
89
-
89
+
90
90
  return msg
91
91
  end
92
-
92
+
93
93
  def RServiceBus.tick( string )
94
94
  puts "[TICK] #{Time.new.strftime( '%Y-%m-%d %H:%M:%S.%6N' )} :: #{caller[0]}. #{string}"
95
95
  end
96
-
97
-
96
+
97
+ def RServiceBus.checkEnvironmentVariable( string )
98
+ return false if ENV[string].nil?
99
+ return true if ENV[string] == true || ENV[string] =~ (/(true|t|yes|y|1)$/i)
100
+ return false if ENV[string] == false || ENV[string].blank? || ENV[string] =~ (/(false|f|no|n|0)$/i)
101
+ raise ArgumentError.new("invalid value for Environment Variable: \"#{string}\"")
102
+ end
98
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rservicebus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.70
4
+ version: 0.1.71
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-10 00:00:00.000000000 Z
12
+ date: 2014-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: uuidtools
16
- requirement: &70345483351560 !ruby/object:Gem::Requirement
16
+ requirement: &70094435904140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70345483351560
24
+ version_requirements: *70094435904140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70345483350000 !ruby/object:Gem::Requirement
27
+ requirement: &70094435903680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70345483350000
35
+ version_requirements: *70094435903680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: beanstalk-client
38
- requirement: &70345483348360 !ruby/object:Gem::Requirement
38
+ requirement: &70094435903220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70345483348360
46
+ version_requirements: *70094435903220
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: fluiddb
49
- requirement: &70345483363680 !ruby/object:Gem::Requirement
49
+ requirement: &70094435902780 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70345483363680
57
+ version_requirements: *70094435902780
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: parse-cron
60
- requirement: &70345483362840 !ruby/object:Gem::Requirement
60
+ requirement: &70094435902320 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70345483362840
68
+ version_requirements: *70094435902320
69
69
  description: A Ruby interpretation of NServiceBus
70
70
  email: guy@guyirvine.com
71
71
  executables: