hoth 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,95 @@
1
+ # Hoth
2
+
3
+ Creating a SOA requires a centralized location to define all services within the SOA. Furthermore you want to know where those services live.
4
+
5
+ # How to use
6
+
7
+ ## Install
8
+
9
+ gem install hoth
10
+
11
+ ## Define services and modules
12
+
13
+ ### Service-Definition
14
+
15
+ This is how you define services:
16
+
17
+ Hoth::Services.define do
18
+
19
+ service :service_name do |first_param, second_param|
20
+ returns :descriptive_name
21
+ end
22
+
23
+ end
24
+
25
+ This definition describes a service with a name, some parameters and its return value. The naming of the parameters is just for your understanding and will never be used again, so be descriptive. Same goes for the return value. The only exception is, if you want to assure that a service returns nil you can write
26
+
27
+ returns :nothing
28
+
29
+ A service whith this return value will always return nil. You can also specify `:nil`, with the same result.
30
+
31
+ ### Module-Definition
32
+
33
+ After defining all you services, you need to specify in which modules they live. Each module can be seen as a set of implemented services. Each module can have one or more endpoints. Here is how you define these modules with its endpoints and services:
34
+
35
+
36
+ Hoth::Modules.define do
37
+
38
+ service_module :module_name do
39
+ env :development, :test do
40
+ endpoint :default,
41
+ :host => 'localhost',
42
+ :port => 3000,
43
+ :transport_type => :http
44
+
45
+ endpoint :bert,
46
+ :host => 'localhost',
47
+ :port => 9999,
48
+ :transport_type => :bert
49
+
50
+ end
51
+
52
+ env :production do
53
+ endpoint :default,
54
+ :host => '192.168.1.12',
55
+ :port => 3000,
56
+ :transport_type => :http
57
+
58
+ endpoint :bert,
59
+ :host => '192.168.1.15',
60
+ :port => 9999,
61
+ :transport_type => :bert
62
+
63
+ end
64
+
65
+ add_service :first_service
66
+ add_service :second_service, :via => :bert
67
+ end
68
+
69
+ end
70
+
71
+
72
+ As you can see, it is possible to define different endpoints for different environments. Each endpoint has a host, a port and a transport-type. After defining your endpoints you can add your previously defined services to the module and define which endpoint they should use. If you do not specify an endpoint the :default endpoint will be used.
73
+
74
+ ## Integrate in your project
75
+
76
+ Just execute current code (in rails you can add this line to an initializer):
77
+
78
+ Hoth.init!
79
+
80
+ By default, Hoth looks for the files service_definition and module_definition in the config-Directory (`./config`). If you need to load these files from another place, just set `Hoth.config_path` to your needs.
81
+
82
+ ## Note on Patches/Pull Requests
83
+
84
+ * Fork the project.
85
+ * Make your feature addition or bug fix.
86
+ * Add tests for it. This is important so I don't break it in a
87
+ future version unintentionally.
88
+ * Commit, do not mess with rakefile, version, or history.
89
+ (if you want to have your own version, that is fine but
90
+ bump version in a commit by itself I can ignore when I pull)
91
+ * Send me a pull request. Bonus points for topic branches.
92
+
93
+ ## Copyright
94
+
95
+ Copyright (c) 2009-2010 Dirk Breuer. See LICENSE for details.
@@ -0,0 +1,9 @@
1
+ # Hoth THANKS
2
+
3
+ A number of people have contributed to Hoth by reporting problems,
4
+ suggesting improvements or submitting changes. Some of these people are:
5
+
6
+ * Andreas Bade (<andi.bade@gmail.com>)
7
+ * Sebastian Cohnen (<sebastian.cohnen@gmail.com>)
8
+ * Björn Vollmer (<bjoern.vollmer@googlemail.com>)
9
+ * Andreas Riemer
@@ -3,15 +3,15 @@ require 'singleton'
3
3
  require 'active_support/inflector'
4
4
 
5
5
  require 'hoth/transport/hoth_transport'
6
- require 'hoth/transport/json_transport'
6
+ require 'hoth/transport/http_transport'
7
7
  require 'hoth/transport/bert_transport'
8
8
  require 'hoth/transport/workling_transport'
9
9
 
10
- require 'hoth/definition'
11
- require 'hoth/deployment_module'
10
+ require 'hoth/service_definition'
11
+ require 'hoth/service_module'
12
12
  require 'hoth/endpoint'
13
13
  require 'hoth/service'
14
- require 'hoth/service_deployment'
14
+ require 'hoth/modules'
15
15
  require 'hoth/service_registry'
16
16
  require 'hoth/services'
17
17
 
@@ -20,4 +20,39 @@ require 'hoth/util/logger'
20
20
  require 'hoth/extension/core/exception'
21
21
  require 'hoth/exceptions'
22
22
 
23
- Hoth::Logger.init_logging!
23
+ module Hoth
24
+
25
+ class <<self
26
+ def init!
27
+ load_service_definition
28
+ load_module_definition
29
+ Logger.init_logging!
30
+ end
31
+
32
+ def config_path
33
+ @config_path || "config/"
34
+ end
35
+
36
+ def config_path=(config_path)
37
+ @config_path = config_path
38
+ end
39
+
40
+ def load_service_definition
41
+ require File.join(config_path, "service_definition")
42
+ end
43
+
44
+ def load_module_definition
45
+ require File.join(config_path, "module_definition")
46
+ end
47
+
48
+ def env
49
+ @env || ENV["HOTH_ENV"] || (Object.const_defined?("Rails") ? Rails.env.to_sym : :development)
50
+ end
51
+
52
+ def env=(env)
53
+ @env = env.to_sym
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -17,9 +17,5 @@ module Hoth
17
17
  def to_url
18
18
  "http://#{@host}:#{@port}/execute"
19
19
  end
20
-
21
- def is_local?
22
- ENV["LOCAL"] == "true" ? true : false # make dynamic
23
- end
24
20
  end
25
21
  end
@@ -0,0 +1,27 @@
1
+ module Hoth
2
+ class Modules
3
+ include Singleton
4
+
5
+ attr_reader :service_modules
6
+
7
+ def self.define(&block)
8
+ instance.instance_eval(&block)
9
+ end
10
+
11
+ def self.module(module_name)
12
+ instance.service_modules[module_name]
13
+ end
14
+
15
+ def service_module(module_name, &block)
16
+ service_module = ServiceModule.new(:name => module_name)
17
+ service_module.instance_eval(&block)
18
+ @service_modules[module_name] = service_module
19
+ end
20
+
21
+ private
22
+
23
+ def initialize
24
+ @service_modules = {}
25
+ end
26
+ end
27
+ end
@@ -1,36 +1,55 @@
1
1
  module Hoth
2
2
  class Service
3
- attr_accessor :name, :endpoint, :params, :return_value
3
+ attr_accessor :name, :params_arity, :return_value, :module
4
4
 
5
- def initialize(name, args = {})
5
+ def initialize(name, &block)
6
6
  @name = name
7
- @endpoint = ServiceDeployment.module(args[:endpoint])[Services.env].endpoint
8
- @params = args[:params]
9
- @return_value = args[:returns]
7
+ @params_arity = block.arity
8
+ instance_eval(&block)
9
+ end
10
+
11
+ def returns(return_value)
12
+ @return_value = return_value
10
13
  end
11
14
 
12
15
  def transport
13
16
  @transport ||= "hoth/transport/#{endpoint.transport_type}_transport".camelize.constantize.new(self)
14
17
  end
15
18
 
16
- def service_impl_class
17
- @service_impl_class_name ||= "#{self.name.to_s.camelize}Impl"
18
- # in Rails development environment we cannot cache the class constant, because it gets unloaded, so you get
19
- # an "A copy of xxxImpl has been removed from the module tree but is still active!" error from ActiveSupport dependency mechanism
20
- # TODO: Try to solve this problem
21
- # TODO: get rid of these Rails dependencies
22
- @service_impl_class_name.constantize
19
+ def impl_class
20
+ @impl_class_name ||= "#{self.name.to_s.camelize}Impl"
21
+ begin
22
+ @impl_class_name.constantize
23
+ rescue NameError => e
24
+ # no local implementation
25
+ false
26
+ end
27
+ end
28
+
29
+ def is_local?
30
+ !!impl_class
23
31
  end
24
32
 
25
33
  def execute(*args)
26
- if self.endpoint.is_local?
34
+ if self.is_local?
27
35
  decoded_params = transport.decode_params(*args)
28
- Hoth::Logger.debug "decoded_params: #{decoded_params.inspect}"
29
- result = service_impl_class.send(:execute, *decoded_params)
30
- return return_value ? result : nil
36
+ result = impl_class.send(:execute, *decoded_params)
37
+ return return_nothing? ? nil : result
31
38
  else
32
39
  transport.call_remote_with(*args)
33
40
  end
34
41
  end
42
+
43
+ def return_nothing?
44
+ return_value == :nothing || return_value == :nil || return_value == nil
45
+ end
46
+
47
+ def via_endpoint(via = nil)
48
+ @via_endpoint = via || :default
49
+ end
50
+
51
+ def endpoint
52
+ @endpoint ||= self.module[Hoth.env][@via_endpoint]
53
+ end
35
54
  end
36
55
  end
@@ -0,0 +1,7 @@
1
+ module Hoth
2
+ class ServiceDefinition
3
+ def service(service_name, &block)
4
+ ServiceRegistry.add_service(Service.new(service_name, &block))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,55 @@
1
+ module Hoth
2
+ class ServiceModule
3
+ attr_accessor :name, :environments
4
+
5
+ class Environment
6
+ attr_accessor :endpoints
7
+
8
+ def initialize(&block)
9
+ @endpoints = {}
10
+ instance_eval(&block)
11
+ end
12
+
13
+ def endpoint(endpoint_name, options)
14
+ @endpoints[endpoint_name.to_sym] = Endpoint.new(options)
15
+ end
16
+
17
+ def [](endpoint_name)
18
+ @endpoints[endpoint_name.to_sym]
19
+ end
20
+ end
21
+
22
+ def initialize(attributes = {})
23
+ @environments = {}
24
+ @name = attributes[:name]
25
+ end
26
+
27
+ def env(*env_names, &block)
28
+ env_names.each do |env_name|
29
+ @environments[env_name.to_sym] = Environment.new(&block)
30
+ end
31
+ end
32
+
33
+ def add_service(service_name, options = {})
34
+ unless self.environments[Hoth.env]
35
+ puts("no endpoint-definition for environment '#{Hoth.env}' and service '#{service_name}'")
36
+ exit
37
+ end
38
+
39
+ service = ServiceRegistry.locate_service(service_name.to_sym)
40
+
41
+ unless service
42
+ puts("tried to add service '#{service_name}' but was not defined by service-definition")
43
+ exit
44
+ end
45
+
46
+ service.module = self
47
+ service.via_endpoint(options[:via])
48
+ end
49
+
50
+ def [](env_name)
51
+ @environments[env_name.to_sym]
52
+ end
53
+
54
+ end
55
+ end
@@ -11,11 +11,11 @@ module Hoth
11
11
  end
12
12
 
13
13
  def add_service(service)
14
- @registry[service.name] = service
14
+ @registry[service.name.to_sym] = service
15
15
  end
16
16
 
17
17
  def locate_service(service_name)
18
- @registry[service_name]
18
+ @registry[service_name.to_sym]
19
19
  end
20
20
 
21
21
  private
@@ -1,7 +1,7 @@
1
1
  module Hoth
2
2
  class Services
3
3
  def self.define(&block)
4
- (@definition || Definition.new).instance_eval(&block)
4
+ ServiceDefinition.new.instance_eval(&block)
5
5
  end
6
6
 
7
7
  class <<self
@@ -5,7 +5,7 @@ module Hoth
5
5
  class HothTransport
6
6
  extend Forwardable
7
7
 
8
- def_delegators :@service_delegate, :name, :endpoint, :params, :return_value
8
+ def_delegators :@service_delegate, :name, :module, :endpoint, :params, :return_value
9
9
 
10
10
  def initialize(service_delegate)
11
11
  @service_delegate = service_delegate
@@ -1,9 +1,10 @@
1
1
  require 'json'
2
2
  require 'net/http'
3
3
 
4
+
4
5
  module Hoth
5
6
  module Transport
6
- class JsonTransport < HothTransport
7
+ class HttpTransport < HothTransport
7
8
  def call_remote_with(*args)
8
9
  response = Net::HTTP.post_form(
9
10
  URI.parse(self.endpoint.to_url),
@@ -4,13 +4,17 @@ rescue LoadError
4
4
  STDERR.puts "You need the simple_publisher gem if you want to use Workling/Starling transport."
5
5
  end
6
6
 
7
+
8
+
9
+
10
+
7
11
  module Hoth
8
12
  module Transport
9
13
 
10
14
  class WorklingTransport < HothTransport
11
15
 
12
16
  def call_remote_with(*args)
13
- topic = SimplePublisher::Topic.new(:name => "#{endpoint.module_name.to_s.underscore}_subscribers__#{name.to_s.underscore}")
17
+ topic = SimplePublisher::Topic.new(:name => "#{self.module.name.to_s.underscore}_subscribers__#{name.to_s.underscore}")
14
18
  connection = SimplePublisher::StarlingConnection.new(:host => endpoint.host, :port => endpoint.port)
15
19
 
16
20
  publisher = SimplePublisher::Publisher.new(:topic => topic, :connection => connection)
@@ -6,7 +6,7 @@ require 'hoth'
6
6
  require 'spec'
7
7
  require 'spec/autorun'
8
8
 
9
- Hoth::Services.env = "test"
9
+ Hoth.env = "test"
10
10
 
11
11
  Spec::Matchers.define :string_matching do |regex|
12
12
  match do |string|
@@ -39,11 +39,6 @@ describe Hoth::Endpoint do
39
39
  json_endpoint.should_not equal(bert_endpoint)
40
40
  end
41
41
 
42
- it "should know if it is local or not" do
43
- endpoint = Hoth::Endpoint.new({})
44
- endpoint.is_local?.should_not be(nil)
45
- end
46
-
47
42
  it "should should know the deployment module this endpoint is associated to" do
48
43
  endpoint = Hoth::Endpoint.new(:module_name => "TestModule")
49
44
  endpoint.module_name.should == "TestModule"
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hoth do
4
+
5
+ before(:each) do
6
+ @old_hoth_env = Hoth.env
7
+ Hoth.instance_variable_set "@env", nil
8
+ end
9
+
10
+ after(:each) do
11
+ Hoth.env = @old_hoth_env
12
+ end
13
+
14
+ it "should set the environment explicitly" do
15
+ Hoth.env = :test
16
+ Hoth.env.should == :test
17
+ end
18
+
19
+ it "should default to :development if no environment is set" do
20
+ Hoth.env.should equal(:development)
21
+ end
22
+
23
+ it "should return the Rails env if Rails is available" do
24
+ module Rails; end
25
+ Rails.should_receive(:env).and_return(:production)
26
+ Hoth.env.should equal(:production)
27
+ Object.send :remove_const, :Rails
28
+ end
29
+
30
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ module Hoth
4
+ describe ServiceDefinition do
5
+
6
+ it "should create a Service and add it to the registry instance" do
7
+ service_name = :my_service
8
+
9
+ definition = ServiceDefinition.new
10
+ definition.service service_name do |some_params|
11
+ returns :nothing
12
+ end
13
+
14
+ service = ServiceRegistry.locate_service(service_name)
15
+ service.should_not be(nil)
16
+ service.params_arity.should be(1)
17
+ service.return_value.should be(:nothing)
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ module Hoth
4
+
5
+ describe ServiceModule do
6
+
7
+ it "should have a name" do
8
+ service_module = ServiceModule.new :name => :my_service_module
9
+ service_module.name.should equal(:my_service_module)
10
+ end
11
+
12
+ it "should have an environment" do
13
+ service_module = ServiceModule.new(:name => "service_module_name")
14
+ block = Proc.new {}
15
+ service_module.env :test, &block
16
+ service_module[:test].should be_a(ServiceModule::Environment)
17
+ end
18
+
19
+ it "should have multiple environments" do
20
+ service_module = ServiceModule.new(:name => "service_module_name")
21
+ block = Proc.new {}
22
+ service_module.env :test, :development, &block
23
+ service_module[:test].should be_a(ServiceModule::Environment)
24
+ service_module[:development].should be_a(ServiceModule::Environment)
25
+ end
26
+
27
+ it "should be able to add services" do
28
+ service_module = ServiceModule.new(:name => "service_module_name")
29
+ block = Proc.new {}
30
+
31
+ service_module.env :test, &block
32
+
33
+ ServiceRegistry.should_receive(:locate_service).with(:service_name).and_return(service = mock("ServiceMock"))
34
+ service.should_receive(:module=).with(service_module)
35
+ service.should_receive(:via_endpoint).with(:special_endpoint)
36
+
37
+ service_module.add_service("service_name", :via => :special_endpoint)
38
+ end
39
+
40
+ describe ServiceModule::Environment do
41
+
42
+ it "should have an endpoint" do
43
+ endpoint_mock = mock("Endpoint", :null_object => true)
44
+
45
+ endpoint_block = Proc.new { endpoint :development, {} }
46
+ env = ServiceModule::Environment.new(&endpoint_block)
47
+ env[:development].should_not be(nil)
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -6,60 +6,56 @@ class TestServiceImpl
6
6
  end
7
7
  end
8
8
 
9
- describe Hoth::Service do
9
+ module Hoth
10
10
 
11
- before(:each) do
12
- Hoth::ServiceDeployment.should_receive(:module).
13
- and_return({:test => stub(:endpoint => stub("Endpoint"))})
11
+ describe Service do
14
12
 
15
- @service = Hoth::Service.new("TestService",
16
- :endpoint => "test_module",
17
- :params => ["parameter", "another_parameter"],
18
- :returns => [:some_data]
19
- )
20
- end
21
-
22
- it "should have a name and an endpoint based ob the deployment definition" do
23
- Hoth::ServiceDeployment.should_receive(:module).
24
- with("test_module").
25
- and_return({:test => mock("DeploymentModule", :endpoint => stub("Endpoint"))})
26
-
27
- service = Hoth::Service.new("TestService", :endpoint => "test_module")
28
- service.name.should == "TestService"
29
- end
30
-
31
- it "should define parameters and return values" do
32
- Hoth::ServiceDeployment.should_receive(:module).
33
- and_return({:test => stub(:endpoint => stub("Endpoint"))})
34
-
35
- service = Hoth::Service.new("TestService",
36
- :endpoint => "test_module",
37
- :params => ["parameter", "another_parameter"],
38
- :returns => [:some_data]
39
- )
40
-
41
- service.params.should == ["parameter", "another_parameter"]
42
- service.return_value.should == [:some_data]
43
- end
13
+ it "should define parameters and return values" do
14
+ service_block = Proc.new { |param_1, param_2, param_3| returns :some_data }
15
+
16
+ service = Service.new("TestService", &service_block)
17
+
18
+ service.params_arity.should be(3)
19
+ service.return_value.should be(:some_data)
20
+ end
21
+
22
+ it "should know its service-impl class" do
23
+ service = Service.new("TestService") {}
24
+ service.impl_class
25
+ end
26
+
27
+ it "should know that its service-impl class is not available" do
28
+ service = Service.new("TestServiceWithoutImplClass") {}
29
+ service.impl_class
30
+ end
31
+
32
+ it "should execute the service stub locally if its impl-class was found" do
33
+ service = Service.new("test_service") { |p1, p2| returns :nothing }
34
+
35
+ service.should_receive(:transport).and_return(transport = mock("TransportMock"))
36
+ transport.should_receive(:decode_params).with(:arg1, :arg2).and_return(decoded_params = mock("DecodedParamsMock"))
37
+ service.impl_class.should_receive(:execute).with(decoded_params)
38
+
39
+ service.execute(:arg1, :arg2)
40
+ end
44
41
 
45
- it "should execute the service stub locally based on the endpoint" do
46
- @service.should_receive(:endpoint).and_return(mock("Endpoint", :is_local? => true))
47
- transport_mock = mock("HothTranport")
48
- transport_mock.should_receive(:decode_params).
49
- with(:arg1, :arg2).
50
- and_return([:decoded_arg1, :decoded_arg2])
51
-
52
- @service.should_receive(:transport).and_return(transport_mock)
53
-
54
- @service.execute(:arg1, :arg2)
55
- end
42
+ it "should call the remote service if impl-class does not exist" do
43
+ service = Service.new("test_service_without_impl") { |p1, p2| returns :nothing }
44
+
45
+ service.should_receive(:transport).and_return(transport = mock("TransportMock"))
46
+ transport.should_receive(:call_remote_with).with(:arg1, :arg2)
47
+
48
+ service.execute(:arg1, :arg2)
49
+ end
56
50
 
57
- it "should execute the service stub via transport based on the endpoint" do
58
-
59
- end
51
+ it "should create transport instance based on endpoint" do
52
+ service = Service.new("test_service") { |p1, p2| returns :nothing }
53
+ service.should_receive(:endpoint).and_return(endpoint = mock("EndpointMock"))
54
+ endpoint.should_receive(:transport_type).and_return(:http)
55
+ Hoth::Transport::HttpTransport.should_receive(:new).with(service)
56
+ service.transport
57
+ end
60
58
 
61
- it "should create transport instance based on endpoint" do
62
-
63
59
  end
64
60
 
65
- end
61
+ end
@@ -7,13 +7,16 @@ module Hoth
7
7
 
8
8
  it "should send publish a message via SimplePublisher" do
9
9
  endpoint = mock("EndpointMock")
10
- endpoint.should_receive(:module_name).and_return("TestServiceModule")
11
10
  endpoint.should_receive(:host).and_return("localhost")
12
11
  endpoint.should_receive(:port).and_return("22122")
13
12
 
13
+ service_module = mock("ServiceModule")
14
+ service_module.should_receive(:name).and_return("TestServiceModule")
15
+
14
16
  service = mock("ServiceMock")
15
17
  service.should_receive(:name).and_return("TestService")
16
18
  service.should_receive(:endpoint).any_number_of_times.and_return(endpoint)
19
+ service.should_receive(:module).any_number_of_times.and_return(service_module)
17
20
 
18
21
  SimplePublisher::Topic.should_receive(:new).with(:name => "test_service_module_subscribers__test_service").and_return(topic = mock("Topic"))
19
22
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
7
  - 2
9
- version: 0.1.2
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dirk Breuer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-26 00:00:00 +01:00
17
+ date: 2010-03-29 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -88,34 +88,35 @@ extensions: []
88
88
 
89
89
  extra_rdoc_files:
90
90
  - LICENSE
91
- - README.rdoc
91
+ - README.md
92
92
  files:
93
- - README.rdoc
93
+ - README.md
94
+ - THANKS.md
94
95
  - lib/hoth.rb
95
- - lib/hoth/definition.rb
96
- - lib/hoth/deployment_module.rb
97
96
  - lib/hoth/endpoint.rb
98
97
  - lib/hoth/exceptions.rb
99
98
  - lib/hoth/extension/core/exception.rb
99
+ - lib/hoth/modules.rb
100
100
  - lib/hoth/providers/bertrpc_provider.rb
101
101
  - lib/hoth/providers/rack_provider.rb
102
102
  - lib/hoth/service.rb
103
- - lib/hoth/service_deployment.rb
103
+ - lib/hoth/service_definition.rb
104
+ - lib/hoth/service_module.rb
104
105
  - lib/hoth/service_registry.rb
105
106
  - lib/hoth/services.rb
106
107
  - lib/hoth/transport/amqp_transport.rb
107
108
  - lib/hoth/transport/bert_transport.rb
108
109
  - lib/hoth/transport/hoth_transport.rb
109
- - lib/hoth/transport/json_transport.rb
110
+ - lib/hoth/transport/http_transport.rb
110
111
  - lib/hoth/transport/workling_transport.rb
111
112
  - lib/hoth/util/logger.rb
112
- - spec/hoth_spec.rb
113
113
  - spec/spec_helper.rb
114
- - spec/unit/definition_spec.rb
115
- - spec/unit/deployment_module_spec.rb
116
114
  - spec/unit/endpoint_spec.rb
117
115
  - spec/unit/extension/core/exception_spec.rb
116
+ - spec/unit/hoth_spec.rb
118
117
  - spec/unit/providers/rack_provider_spec.rb
118
+ - spec/unit/service_definition_spec.rb
119
+ - spec/unit/service_module_spec.rb
119
120
  - spec/unit/service_spec.rb
120
121
  - spec/unit/transport/workling_transport_spec.rb
121
122
  - LICENSE
@@ -150,12 +151,12 @@ signing_key:
150
151
  specification_version: 3
151
152
  summary: Registry and deployment description abstraction for SOA-Services
152
153
  test_files:
153
- - spec/hoth_spec.rb
154
154
  - spec/spec_helper.rb
155
- - spec/unit/definition_spec.rb
156
- - spec/unit/deployment_module_spec.rb
157
155
  - spec/unit/endpoint_spec.rb
158
156
  - spec/unit/extension/core/exception_spec.rb
157
+ - spec/unit/hoth_spec.rb
159
158
  - spec/unit/providers/rack_provider_spec.rb
159
+ - spec/unit/service_definition_spec.rb
160
+ - spec/unit/service_module_spec.rb
160
161
  - spec/unit/service_spec.rb
161
162
  - spec/unit/transport/workling_transport_spec.rb
@@ -1,18 +0,0 @@
1
- = hoth
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but
13
- bump version in a commit by itself I can ignore when I pull)
14
- * Send me a pull request. Bonus points for topic branches.
15
-
16
- == Copyright
17
-
18
- Copyright (c) 2009 Dirk Breuer. See LICENSE for details.
@@ -1,7 +0,0 @@
1
- module Hoth
2
- class Definition
3
- def service(service_name, options = {})
4
- service = ServiceRegistry.add_service(Service.new(service_name, options))
5
- end
6
- end
7
- end
@@ -1,41 +0,0 @@
1
- module Hoth
2
- class DeploymentModule
3
- attr_accessor :name, :environments
4
-
5
- class Environment
6
- attr_accessor :endpoint, :deployment_options
7
-
8
- def initialize(attributes = {})
9
- @endpoint = attributes[:endpoint]
10
- @deployment_options = attributes[:deployment_options]
11
- end
12
-
13
- def propagate_module_name_to_endpoint(module_name)
14
- @endpoint.module_name = module_name
15
- end
16
- end
17
-
18
- def initialize(attributes = {})
19
- @environments = {}
20
- @name = attributes[:name]
21
- end
22
-
23
- def env(*options)
24
- attributes = Hash === options.last ? options.pop : {}
25
- options.each do |env_name|
26
- @environments[env_name.to_sym] = Environment.new(attributes)
27
- @environments[env_name.to_sym].propagate_module_name_to_endpoint(@name)
28
- end
29
- self
30
- end
31
-
32
- def [](env_name)
33
- @environments[env_name.to_sym]
34
- end
35
-
36
- def path(path = nil)
37
- path.nil? ? @path : @path = path
38
- end
39
-
40
- end
41
- end
@@ -1,27 +0,0 @@
1
- module Hoth
2
- class ServiceDeployment
3
- include Singleton
4
-
5
- attr_reader :deployment_modules
6
-
7
- def self.define(&block)
8
- instance.instance_eval(&block)
9
- end
10
-
11
- def self.module(module_name)
12
- instance.deployment_modules[module_name]
13
- end
14
-
15
- def service_module(module_name, &block)
16
- deployment_module = DeploymentModule.new(:name => module_name)
17
- deployment_module.instance_eval(&block)
18
- @deployment_modules[module_name] = deployment_module
19
- end
20
-
21
- private
22
-
23
- def initialize
24
- @deployment_modules = {}
25
- end
26
- end
27
- end
@@ -1 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
@@ -1,21 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
-
3
- describe Hoth::Definition do
4
-
5
- it "should create a Service and add it to the registry instance" do
6
- service_name = :my_service
7
- service_options = {
8
- :params => [:some_params],
9
- :returns => nil,
10
- :endpoint => :my_service_module
11
- }
12
-
13
- service = mock("ServiceMock")
14
- Hoth::Service.should_receive(:new).with(service_name, service_options).and_return(service)
15
- Hoth::ServiceRegistry.should_receive(:add_service).with(service)
16
-
17
- definition = Hoth::Definition.new
18
- definition.service service_name, service_options
19
- end
20
-
21
- end
@@ -1,58 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
-
3
- describe Hoth::DeploymentModule do
4
-
5
- it "should have a name" do
6
- deployment_module = Hoth::DeploymentModule.new :name => :my_service_module
7
- deployment_module.name.should equal(:my_service_module)
8
- end
9
-
10
- it "should have an environment" do
11
- deployment_module = Hoth::DeploymentModule.new(:name => "deployment_module_name")
12
-
13
- env_specific_options = {:endpoint => endpoint = mock("EndpointMock"), :deployment_options => "deployment_options"}
14
- endpoint.should_receive(:module_name=).with("deployment_module_name").exactly(3).times
15
- deployment_module.env :test, env_specific_options
16
- deployment_module[:test].should be_a(Hoth::DeploymentModule::Environment)
17
-
18
- deployment_module.env :staging, :production, env_specific_options
19
- deployment_module[:staging].should be_a(Hoth::DeploymentModule::Environment)
20
- deployment_module[:production].should be_a(Hoth::DeploymentModule::Environment)
21
-
22
- [:test, :staging, :production].each do |environment|
23
- deployment_module[environment].endpoint.should == endpoint
24
- deployment_module[environment].deployment_options.should == "deployment_options"
25
- end
26
- end
27
-
28
- it "should have a path pointing to the service root" do
29
- deployment_module = Hoth::DeploymentModule.new
30
- deployment_module.path "services_dir/my_service"
31
- deployment_module.path.should == "services_dir/my_service"
32
- end
33
-
34
- describe Hoth::DeploymentModule::Environment do
35
- it "should have an endpoint" do
36
- endpoint_mock = mock("Hoth::Endpoint", :null_object => true)
37
-
38
- env = Hoth::DeploymentModule::Environment.new(:endpoint => endpoint_mock)
39
- env.endpoint.should equal(endpoint_mock)
40
- end
41
-
42
- it "should have deployment options" do
43
- some_options = {:server_instances => 5}
44
-
45
- env = Hoth::DeploymentModule::Environment.new(:deployment_options => some_options)
46
- env.deployment_options.should equal(some_options)
47
- end
48
-
49
- it "should set propagate the module_name of the enclosing DeploymentModule to its endpoint" do
50
- endpoint = mock("Hoth::Endpoint", :null_object => true)
51
- endpoint.should_receive(:module_name=).with("deployment_module_name")
52
-
53
- env = Hoth::DeploymentModule::Environment.new(:endpoint => endpoint)
54
- env.propagate_module_name_to_endpoint("deployment_module_name")
55
- end
56
- end
57
-
58
- end