dendrite 0.5.16 → 0.5.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49062c845259f7937adde0c0117c2e959230c1a8
4
- data.tar.gz: ff0d54398dc923cc2b216c6c733b32fa81401169
3
+ metadata.gz: 7bf4b1fdc08a024b3a13ce91325cf5cf2dc8ee7a
4
+ data.tar.gz: 41723c08f763f7aa8e4be85e780cb21375ca8ba7
5
5
  SHA512:
6
- metadata.gz: 805535d01e524c4ba6c1c43bbf035f147da826061a1dae416fb71d326b859cd17cc330333c0fbf577c7f68e0c9f3c337eb5a4173f3c904f58288d95280b0ff49
7
- data.tar.gz: 64611c7155aae5776642a218c8c5d51f467b1fd609bab47666720544293e54c8489c6d7d3b5d3d7adaea0b4df94918bc521fbdba539f41dad58f4d0707785673
6
+ metadata.gz: 2632a11b89af6cb462cb1ea725f46895d19141993cceb35e1896d488c7f75077a7d680cdadad53d450c1c02c9534cf31960eca1952583c2c2ea4e5acc799c8c2
7
+ data.tar.gz: 2de9a065d1e4e1a3f5bd2a0a8d2f646e6d03c26fe709f060c37f54885fb19f3610912ce9bffab6a40201522885ec9fea878fa6daca24c4beb45e5a8ba63abe4a
data/bin/register CHANGED
@@ -28,7 +28,7 @@ rescue
28
28
  []
29
29
  end.collect(&:to_s)
30
30
  services += options[:service_name].split(',')
31
- services.uniq!
31
+ services = services.collect{|s| s.gsub("_readonly", "")}.uniq
32
32
 
33
33
  raise Dendrite::InvalidData unless graph.valid?
34
34
  raise Dendrite::UnknownService unless services.collect {|service_name| graph[service_name]}.all?
@@ -40,6 +40,7 @@ subcomponents:
40
40
  subcomponent: cat
41
41
  latency: foo
42
42
  identifier: barbaz
43
+ read_only: true
43
44
  - component: cams
44
45
  subcomponent: foobar
45
46
  latency: foo
@@ -55,13 +56,19 @@ subcomponents:
55
56
  scale:
56
57
  min_instance_count: 1
57
58
  max_instance_count: 5
59
+ default_servers:
60
+ - host: 0.0.0.0
61
+ port: 8080
62
+ environment: prd
58
63
  ports:
59
64
  loadbalancer_port: 8081
60
65
  service_port: 8080
61
66
  dependencies:
62
67
  - component: cams
63
- subcomponent: foobar
64
- latency: foo
68
+ subcomponent: cat
69
+ latency: 10
70
+ metadata:
71
+ read_only: true
65
72
  - name: baz
66
73
  type: tomcat
67
74
  deploy:
@@ -11,7 +11,19 @@ module Dendrite
11
11
 
12
12
  def to_h
13
13
  service_list = services.inject({}) do |hash, service|
14
- hash[service.name] = service.to_h
14
+ if service.read_write
15
+ hash[service.name] = service.to_h
16
+ hash["#{service.name}_readonly"] = service.to_h.merge({
17
+ zk_path: "/smartstack/services/#{service.organization}/#{service.component}/#{service.service.real_name}_readonly/instances"
18
+ })
19
+ elsif service.read_only
20
+ hash["#{service.name}_readonly"] = service.to_h.merge({
21
+ zk_path: "/smartstack/services/#{service.organization}/#{service.component}/#{service.service.real_name}_readonly/instances"
22
+ })
23
+ else
24
+ hash[service.name] = service.to_h
25
+ end
26
+
15
27
  hash
16
28
  end
17
29
 
@@ -26,6 +38,14 @@ module Dendrite
26
38
  def_delegator :service, :component, :component
27
39
  def_delegator :service, :organization, :organization
28
40
 
41
+ def read_only
42
+ service.metadata && service.metadata.read_only
43
+ end
44
+
45
+ def read_write
46
+ read_only && service.metadata.write_only
47
+ end
48
+
29
49
  def to_h
30
50
  {
31
51
  host: Dendrite::Config.public_ip,
@@ -1,17 +1,26 @@
1
1
  module Dendrite
2
2
  module Generators
3
3
  class Synapse < Base
4
- def initialize(graph:, service_names:, proxy: false, environment: :dev)
4
+ attr_reader :read_only
5
+ def initialize(graph:, service_names:, environment: :dev)
5
6
  super(graph: graph, service_names: service_names)
6
- unless proxy
7
- dep = []
8
- @services.each do |service|
9
- service.dependencies.each do |_, dependency|
10
- dep << dependency.service
7
+ dep = []
8
+ read_only = {}
9
+ @services.each do |service|
10
+ service.dependencies.each do |_, dependency|
11
+ dep << dependency.service
12
+ if read_only.keys.include?(dependency.service.name)
13
+ if read_only[dependency.service.name] != dependency.read_only
14
+ raise "Trying to add r/o and r/w for same service"
15
+ end
16
+ else
17
+ read_only[dependency.service.name] = dependency.read_only
11
18
  end
12
19
  end
13
- @services = dep.uniq
14
20
  end
21
+
22
+ @read_only = read_only
23
+ @services = dep.uniq
15
24
  @services.group_by { |service| service.loadbalancer_port }.each do |port, services|
16
25
  if services.length > 1
17
26
  raise PortCollision, "Port collission between #{services.collect(&:name).join(',')}"
@@ -22,7 +31,17 @@ module Dendrite
22
31
 
23
32
  def to_h
24
33
  service_list = services.inject({}) do |hash, service|
25
- hash[service.name] = service.to_h
34
+
35
+ if read_only[service.name]
36
+ data = service.to_h
37
+ discovery_data = data[:discovery].merge({
38
+ path: "/smartstack/services/#{service.organization}/#{service.component}/#{service.service.real_name}_readonly/instances"
39
+ })
40
+ data[:discovery] = discovery_data
41
+ hash[service.name] = data
42
+ else
43
+ hash[service.name] = service.to_h
44
+ end
26
45
  hash
27
46
  end
28
47
 
data/lib/dendrite/io.rb CHANGED
@@ -16,7 +16,7 @@ module Dendrite
16
16
  if service[:dependencies]
17
17
  service[:dependencies].each do |deps|
18
18
  dependency_name = "#{service[:organization]}_#{deps[:component]}_#{deps[:subcomponent]}"
19
- graph[node.name].add_dependency(service: graph[dependency_name], latency: deps[:latency], identifier: deps[:identifier])
19
+ graph[node.name].add_dependency(service: graph[dependency_name], latency: deps[:latency], identifier: deps[:identifier], read_only: deps.fetch(:read_only, false))
20
20
  end
21
21
  end
22
22
  end
@@ -95,7 +95,7 @@ module Dendrite
95
95
  validates_inclusion_of :port, :in => 1..65535
96
96
  end
97
97
 
98
- Dependency = Struct.new(:service, :latency, :identifier) do
98
+ Dependency = Struct.new(:service, :latency, :identifier, :read_only) do
99
99
  include ActiveModel::Validations
100
100
  validates_presence_of :service
101
101
  validates_presence_of :latency
@@ -196,8 +196,8 @@ module Dendrite
196
196
  ports[:loadbalancer_port].port if ports[:loadbalancer_port]
197
197
  end
198
198
 
199
- def add_dependency(service:, latency:, identifier:)
200
- @dependencies[service.name] = Dependency.new(service, latency, identifier)
199
+ def add_dependency(service:, latency:, identifier:, read_only: false)
200
+ @dependencies[service.name] = Dependency.new(service, latency, identifier, read_only == true)
201
201
  end
202
202
 
203
203
  def to_h
@@ -1,3 +1,3 @@
1
1
  module Dendrite
2
- VERSION = "0.5.16"
2
+ VERSION = "0.5.20"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dendrite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.16
4
+ version: 0.5.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yagnik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-06 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,7 +84,6 @@ description: Build config files for synapse and nerve of smartstack
84
84
  email:
85
85
  - yagnikkhanna@gmail.com
86
86
  executables:
87
- - add_proxy
88
87
  - metadata
89
88
  - register
90
89
  extensions: []
@@ -96,7 +95,6 @@ files:
96
95
  - LICENSE.txt
97
96
  - README.md
98
97
  - Rakefile
99
- - bin/add_proxy
100
98
  - bin/metadata
101
99
  - bin/register
102
100
  - conf/config.yml
data/bin/add_proxy DELETED
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'dendrite'
3
- require 'optparse'
4
-
5
- options = {}
6
- OptionParser.new do |opts|
7
- opts.banner = "Usage: proxy [options]"
8
- opts.on("-s", "--services SERVICE_NAME:PORT,..", "service name and port") do |v|
9
- options[:services] = v
10
- end
11
-
12
- opts.on("-c", "--config CONFIG_FILE", "config file") do |v|
13
- options[:config] = v
14
- end
15
- end.parse!
16
-
17
- services = options[:services].split(',').inject({}) do |hsh, name_port|
18
- name, port = name_port.split(':')
19
- name = name.strip
20
- port = port.to_i
21
- hsh[name] = port
22
- hsh
23
- end
24
-
25
- puts "Loading config"
26
- Dendrite::Config.load(source: options[:config])
27
- puts "Loading graph"
28
- graph = Dendrite::IO.load(source: Dendrite::Config.services_source)
29
- raise Dendrite::InvalidData unless graph.valid?
30
- raise Dendrite::UnknownService unless services.keys.collect {|service_name| graph[service_name]}.all?
31
-
32
- services.each do |name, port|
33
- puts "adding proxy for #{name}"
34
- Dendrite::Config.custom_frontend!(name: "custom_#{name}", port: port, backend_name: name)
35
- end
36
- synapse = Dendrite::Generators::Synapse.new(graph: graph, service_names: services, proxy: true)
37
- Dendrite::IO.write(data: synapse.to_yaml, destination: Dendrite::Config.synapse_config_path)
38
-