jdc 0.2.1 → 0.2.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. data/LICENSE +1277 -24
  2. data/Rakefile +13 -0
  3. data/bin/jdc +12 -2
  4. data/lib/admin/README.md +15 -0
  5. data/lib/admin/curl.rb +60 -0
  6. data/lib/admin/guid.rb +89 -0
  7. data/lib/admin/plugin.rb +6 -0
  8. data/lib/admin/service_auth_token.rb +94 -0
  9. data/lib/admin/service_broker/add.rb +47 -0
  10. data/lib/admin/service_broker/service_brokers.rb +24 -0
  11. data/lib/admin/set_quota.rb +44 -0
  12. data/lib/console/README.md +8 -0
  13. data/lib/console/console.rb +187 -0
  14. data/lib/console/plugin.rb +33 -0
  15. data/lib/jdc.rb +15 -2
  16. data/lib/jdc/cli.rb +556 -0
  17. data/lib/jdc/cli/app/app.rb +43 -0
  18. data/lib/jdc/cli/app/apps.rb +87 -0
  19. data/lib/jdc/cli/app/base.rb +72 -0
  20. data/lib/jdc/cli/app/delete.rb +95 -0
  21. data/lib/jdc/cli/app/deprecated.rb +11 -0
  22. data/lib/jdc/cli/app/env.rb +78 -0
  23. data/lib/jdc/cli/app/events.rb +45 -0
  24. data/lib/jdc/cli/app/files.rb +137 -0
  25. data/lib/jdc/cli/app/health.rb +26 -0
  26. data/lib/jdc/cli/app/instances.rb +53 -0
  27. data/lib/jdc/cli/app/logs.rb +76 -0
  28. data/lib/jdc/cli/app/push.rb +103 -0
  29. data/lib/jdc/cli/app/push/create.rb +108 -0
  30. data/lib/jdc/cli/app/push/interactions.rb +86 -0
  31. data/lib/jdc/cli/app/push/sync.rb +57 -0
  32. data/lib/jdc/cli/app/rename.rb +35 -0
  33. data/lib/jdc/cli/app/restart.rb +31 -0
  34. data/lib/jdc/cli/app/scale.rb +63 -0
  35. data/lib/jdc/cli/app/start.rb +161 -0
  36. data/lib/jdc/cli/app/stats.rb +67 -0
  37. data/lib/jdc/cli/app/stop.rb +27 -0
  38. data/lib/jdc/cli/domain/base.rb +9 -0
  39. data/lib/jdc/cli/domain/domains.rb +40 -0
  40. data/lib/jdc/cli/domain/map.rb +55 -0
  41. data/lib/jdc/cli/domain/unmap.rb +56 -0
  42. data/lib/jdc/cli/help.rb +15 -0
  43. data/lib/jdc/cli/interactive.rb +105 -0
  44. data/lib/jdc/cli/login_requirements.rb +15 -0
  45. data/lib/jdc/cli/organization/base.rb +14 -0
  46. data/lib/jdc/cli/organization/create.rb +37 -0
  47. data/lib/jdc/cli/organization/delete.rb +63 -0
  48. data/lib/jdc/cli/organization/org.rb +45 -0
  49. data/lib/jdc/cli/organization/orgs.rb +30 -0
  50. data/lib/jdc/cli/organization/rename.rb +37 -0
  51. data/lib/jdc/cli/populators/base.rb +16 -0
  52. data/lib/jdc/cli/populators/organization.rb +32 -0
  53. data/lib/jdc/cli/populators/populator_methods.rb +64 -0
  54. data/lib/jdc/cli/populators/space.rb +33 -0
  55. data/lib/jdc/cli/populators/target.rb +13 -0
  56. data/lib/jdc/cli/route/base.rb +9 -0
  57. data/lib/jdc/cli/route/delete.rb +28 -0
  58. data/lib/jdc/cli/route/map.rb +68 -0
  59. data/lib/jdc/cli/route/routes.rb +26 -0
  60. data/lib/jdc/cli/route/unmap.rb +56 -0
  61. data/lib/jdc/cli/service/base.rb +9 -0
  62. data/lib/jdc/cli/service/bind.rb +44 -0
  63. data/lib/jdc/cli/service/create.rb +159 -0
  64. data/lib/jdc/cli/service/delete.rb +83 -0
  65. data/lib/jdc/cli/service/rename.rb +36 -0
  66. data/lib/jdc/cli/service/service.rb +42 -0
  67. data/lib/jdc/cli/service/service_instance_helper.rb +99 -0
  68. data/lib/jdc/cli/service/services.rb +111 -0
  69. data/lib/jdc/cli/service/unbind.rb +37 -0
  70. data/lib/jdc/cli/space/base.rb +29 -0
  71. data/lib/jdc/cli/space/create.rb +67 -0
  72. data/lib/jdc/cli/space/delete.rb +56 -0
  73. data/lib/jdc/cli/space/rename.rb +38 -0
  74. data/lib/jdc/cli/space/space.rb +66 -0
  75. data/lib/jdc/cli/space/spaces.rb +57 -0
  76. data/lib/jdc/cli/space/switch.rb +19 -0
  77. data/lib/jdc/cli/start/base.rb +41 -0
  78. data/lib/jdc/cli/start/colors.rb +13 -0
  79. data/lib/jdc/cli/start/target.rb +50 -0
  80. data/lib/jdc/cli/start/target_prettifier.rb +17 -0
  81. data/lib/jdc/cli/start/targets.rb +16 -0
  82. data/lib/jdc/cli/user/base.rb +30 -0
  83. data/lib/jdc/cli/user/create.rb +52 -0
  84. data/lib/jdc/cli/user/passwd.rb +37 -0
  85. data/lib/jdc/cli/user/register.rb +43 -0
  86. data/lib/jdc/cli/user/users.rb +32 -0
  87. data/lib/jdc/constants.rb +11 -0
  88. data/lib/jdc/errors.rb +19 -0
  89. data/lib/jdc/object_extensions.rb +15 -0
  90. data/lib/jdc/plugin.rb +56 -0
  91. data/lib/jdc/spacing.rb +89 -0
  92. data/lib/jdc/spec_helper.rb +1 -0
  93. data/lib/jdc/test_support.rb +6 -0
  94. data/lib/jdc/version.rb +3 -0
  95. data/lib/manifests/errors.rb +35 -0
  96. data/lib/manifests/loader.rb +31 -0
  97. data/lib/manifests/loader/builder.rb +39 -0
  98. data/lib/manifests/loader/normalizer.rb +145 -0
  99. data/lib/manifests/loader/resolver.rb +79 -0
  100. data/lib/manifests/manifests.rb +344 -0
  101. data/lib/manifests/plugin.rb +140 -0
  102. data/lib/micro/README.md +9 -0
  103. data/lib/micro/errors.rb +4 -0
  104. data/lib/{jdc → micro}/micro.rb +15 -15
  105. data/lib/micro/plugin.rb +197 -0
  106. data/lib/micro/switcher/base.rb +79 -0
  107. data/lib/{jdc/micro → micro}/switcher/darwin.rb +5 -3
  108. data/lib/{jdc/micro → micro}/switcher/dummy.rb +1 -1
  109. data/lib/micro/switcher/linux.rb +16 -0
  110. data/lib/{jdc/micro → micro}/switcher/windows.rb +5 -5
  111. data/lib/{jdc/micro → micro}/vmrun.rb +26 -19
  112. data/lib/tasks/gem_release.rake +42 -0
  113. data/lib/tunnel/README.md +29 -0
  114. data/{config → lib/tunnel/config}/clients.yml +2 -2
  115. data/lib/tunnel/helper-app/Gemfile +10 -0
  116. data/lib/tunnel/helper-app/Gemfile.lock +48 -0
  117. data/{caldecott_helper → lib/tunnel/helper-app}/server.rb +5 -5
  118. data/lib/tunnel/plugin.rb +183 -0
  119. data/lib/tunnel/tunnel.rb +295 -0
  120. metadata +371 -210
  121. data/README.md +0 -102
  122. data/config/micro/paths.yml +0 -22
  123. data/config/micro/refresh_ip.rb +0 -20
  124. data/lib/cli.rb +0 -53
  125. data/lib/cli/commands/admin.rb +0 -58
  126. data/lib/cli/commands/apps.rb +0 -1129
  127. data/lib/cli/commands/base.rb +0 -228
  128. data/lib/cli/commands/manifest.rb +0 -56
  129. data/lib/cli/commands/micro.rb +0 -115
  130. data/lib/cli/commands/misc.rb +0 -126
  131. data/lib/cli/commands/services.rb +0 -178
  132. data/lib/cli/commands/user.rb +0 -14
  133. data/lib/cli/config.rb +0 -173
  134. data/lib/cli/console_helper.rb +0 -170
  135. data/lib/cli/core_ext.rb +0 -122
  136. data/lib/cli/errors.rb +0 -19
  137. data/lib/cli/frameworks.rb +0 -265
  138. data/lib/cli/manifest_helper.rb +0 -300
  139. data/lib/cli/runner.rb +0 -505
  140. data/lib/cli/services_helper.rb +0 -84
  141. data/lib/cli/tunnel_helper.rb +0 -332
  142. data/lib/cli/usage.rb +0 -86
  143. data/lib/cli/version.rb +0 -7
  144. data/lib/cli/zip_util.rb +0 -77
  145. data/lib/jdc/client.rb +0 -457
  146. data/lib/jdc/const.rb +0 -25
  147. data/lib/jdc/micro/switcher/base.rb +0 -97
  148. data/lib/jdc/micro/switcher/linux.rb +0 -16
  149. data/lib/jdc/signature/version.rb +0 -27
  150. data/lib/jdc/signer.rb +0 -13
  151. data/lib/jdc/timer.rb +0 -12
@@ -0,0 +1,57 @@
1
+ module JDC::App
2
+ module Sync
3
+ def apply_changes(app)
4
+ app.memory = megabytes(input[:memory]) if input.has?(:memory)
5
+ app.total_instances = input[:instances] if input.has?(:instances)
6
+ app.command = input[:command] if input.has?(:command)
7
+ app.buildpack = input[:buildpack] if input.has?(:buildpack)
8
+ end
9
+
10
+ def display_changes(app)
11
+ return unless app.changed?
12
+
13
+ line "Changes:"
14
+
15
+ indented do
16
+ app.changes.each do |attr, (old, new)|
17
+ line "#{c(attr, :name)}: #{diff_str(attr, old)} -> #{diff_str(attr, new)}"
18
+ end
19
+ end
20
+ end
21
+
22
+ def commit_changes(app)
23
+ if app.changed?
24
+ with_progress("Updating #{c(app.name, :name)}") do
25
+ wrap_message_format_errors do
26
+ app.update!
27
+ end
28
+ end
29
+ end
30
+
31
+ if input[:restart] && app.started?
32
+ invoke :restart, :app => app
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def diff_str(attr, val)
39
+ case attr
40
+ when :memory
41
+ human_mb(val)
42
+ when :command, :buildpack
43
+ "'#{val}'"
44
+ else
45
+ val
46
+ end
47
+ end
48
+
49
+ def bool(b)
50
+ if b
51
+ c("true", :yes)
52
+ else
53
+ c("false", :no)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,35 @@
1
+ require "jdc/cli/app/base"
2
+
3
+ module JDC::App
4
+ class Rename < Base
5
+ desc "Rename an application"
6
+ group :apps, :manage
7
+ input :app, :desc => "Application to rename", :argument => :optional,
8
+ :from_given => by_name(:app)
9
+ input :name, :desc => "New application name", :argument => :optional
10
+ def rename
11
+ app = input[:app]
12
+ name = input[:name]
13
+
14
+ app.name = name
15
+
16
+ with_progress("Renaming to #{c(name, :name)}") do
17
+ app.update!
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def ask_app
24
+ apps = client.apps
25
+ fail "No applications." if apps.empty?
26
+
27
+ ask("Rename which application?", :choices => apps.sort_by(&:name),
28
+ :display => proc(&:name))
29
+ end
30
+
31
+ def ask_name
32
+ ask("New name")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ require "jdc/cli/app/base"
2
+
3
+ module JDC::App
4
+ class Restart < Base
5
+ desc "Stop and start an application"
6
+ group :apps, :manage
7
+ input :apps, :desc => "Applications to start", :argument => :splat,
8
+ :singular => :app, :from_given => by_name(:app)
9
+ input :debug_mode, :desc => "Debug mode to start in", :aliases => "-d"
10
+ input :all, :desc => "Restart all applications", :default => false
11
+
12
+ ############# Uncomment to complete 50543607
13
+ #input :command, :desc => "Command to restart application", :default => nil
14
+
15
+ def restart
16
+ invoke :stop, :all => input[:all], :apps => input[:apps]
17
+
18
+ line unless quiet?
19
+
20
+ input[:apps].each do |app|
21
+ unless input[:command].nil?
22
+ app.command = input[:command]
23
+ end
24
+ app.update!
25
+ end
26
+
27
+ invoke :start, :all => input[:all], :apps => input[:apps],
28
+ :debug_mode => input[:debug_mode]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,63 @@
1
+ require "jdc/cli/app/base"
2
+
3
+ module JDC::App
4
+ class Scale < Base
5
+ desc "Update the instances/memory limit for an application"
6
+ group :apps, :info
7
+ input :app, :desc => "Application to update", :argument => true,
8
+ :from_given => by_name(:app)
9
+ input :instances, :desc => "Number of instances to run",
10
+ :type => :numeric
11
+ input :memory, :desc => "Memory limit"
12
+ input :disk, :desc => "Disk quota"
13
+ input :restart, :desc => "Restart app after updating?", :default => true
14
+
15
+ def scale
16
+ app = input[:app]
17
+
18
+ if input.has?(:instances)
19
+ instances = input[:instances, app.total_instances]
20
+ end
21
+
22
+ if input.has?(:memory)
23
+ memory = input[:memory, app.memory]
24
+ end
25
+
26
+ if input.has?(:disk)
27
+ disk = input[:disk, human_mb(app.disk_quota)]
28
+ end
29
+
30
+ unless instances || memory || disk
31
+ instances = input[:instances, app.total_instances]
32
+ memory = input[:memory, app.memory]
33
+ end
34
+
35
+ app.total_instances = instances if input.has?(:instances)
36
+ app.memory = megabytes(memory) if input.has?(:memory)
37
+ app.disk_quota = megabytes(disk) if input.has?(:disk)
38
+
39
+ fail "No changes!" unless app.changed?
40
+
41
+ with_progress("Scaling #{c(app.name, :name)}") do
42
+ app.update!
43
+ end
44
+
45
+ needs_restart = app.changes.key?(:memory) || app.changes.key?(:disk_quota)
46
+
47
+ if needs_restart && app.started? && input[:restart]
48
+ invoke :restart, :app => app
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def ask_instances(default)
55
+ ask("Instances", :default => default)
56
+ end
57
+
58
+ def ask_memory(default)
59
+ ask("Memory Limit", :choices => memory_choices,
60
+ :default => human_mb(default), :allow_other => true)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,161 @@
1
+ require "jdc/cli/app/base"
2
+
3
+ module JDC::App
4
+ class Start < Base
5
+ APP_CHECK_LIMIT = 60
6
+
7
+ desc "Start an application"
8
+ group :apps, :manage
9
+ input :apps, :desc => "Applications to start", :argument => :splat,
10
+ :singular => :app, :from_given => by_name(:app)
11
+ input :debug_mode, :desc => "Debug mode to start in", :aliases => "-d"
12
+ input :all, :desc => "Start all applications", :default => false
13
+ def start
14
+ apps = input[:all] ? client.apps : input[:apps]
15
+ fail "No applications given." if apps.empty?
16
+
17
+ spaced(apps) do |app|
18
+ app = filter(:start_app, app)
19
+
20
+ switch_mode(app, input[:debug_mode])
21
+
22
+ if app.started?
23
+ err "Application #{b(app.name)} is already started."
24
+ next
25
+ end
26
+
27
+ log = start_app(app)
28
+ stream_start_log(log) if log
29
+ check_application(app)
30
+
31
+ if !app.debug_mode.nil? && app.debug_mode != "none" && !quiet?
32
+ line
33
+ invoke :instances, :app => app
34
+ end
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def start_app(app)
41
+ log = nil
42
+ with_progress("Preparing to start #{c(app.name, :name)}") do
43
+ app.start! do |url|
44
+ log = url
45
+ end
46
+ end
47
+ log
48
+ end
49
+
50
+ def stream_start_log(log)
51
+ offset = 0
52
+
53
+ while true
54
+ begin
55
+ client.stream_url(log + "&tail&tail_offset=#{offset}") do |out|
56
+ offset += out.size
57
+ print out
58
+ end
59
+ rescue Timeout::Error
60
+ end
61
+ end
62
+ rescue JFoundry::APIError
63
+ end
64
+
65
+ # set app debug mode, ensuring it's valid, and shutting it down
66
+ def switch_mode(app, mode)
67
+ mode = "run" if mode == "" # no value given
68
+
69
+ return false if app.debug == mode
70
+
71
+ if mode == "none"
72
+ with_progress("Removing debug mode") do
73
+ app.debug = mode
74
+ app.stop! if app.started?
75
+ end
76
+
77
+ return true
78
+ end
79
+
80
+ with_progress("Switching mode to #{c(mode, :name)}") do |s|
81
+ app.debug = mode
82
+ app.stop! if app.started?
83
+ end
84
+ end
85
+
86
+ def check_application(app)
87
+ if app.debug == "suspend"
88
+ line "Application is in suspended debugging mode."
89
+ line "It will wait for you to attach to it before starting."
90
+ return
91
+ end
92
+
93
+ print("Checking status of app '#{c(app.name, :name)}'...")
94
+
95
+ seconds = 0
96
+ @first_time_after_staging_succeeded = true
97
+
98
+ begin
99
+ instances = []
100
+ while true
101
+ if any_instance_flapping?(instances) || seconds == APP_CHECK_LIMIT
102
+ err "Push unsuccessful."
103
+ return
104
+ end
105
+
106
+ begin
107
+ return unless instances = app.instances
108
+
109
+ indented { print_instances_summary(instances) }
110
+
111
+ if all_instances_running?(instances)
112
+ line "#{c("Push successful! App '#{app.name}' available at http://#{app.host}.#{app.domain}", :good)}"
113
+ return
114
+ end
115
+ rescue JFoundry::NotStaged
116
+ print (".")
117
+ end
118
+
119
+ sleep 1
120
+ seconds += 1
121
+ end
122
+ rescue JFoundry::StagingError
123
+ err "Application failed to stage"
124
+ end
125
+ end
126
+
127
+ def all_instances_running?(instances)
128
+ instances.all? { |i| i.state == "RUNNING" }
129
+ end
130
+
131
+ def any_instance_flapping?(instances)
132
+ instances.any? { |i| i.state == "FLAPPING" }
133
+ end
134
+
135
+ def print_instances_summary(instances)
136
+
137
+ if @first_time_after_staging_succeeded
138
+ line
139
+ @first_time_after_staging_succeeded = false
140
+ end
141
+
142
+ counts = Hash.new { 0 }
143
+ instances.each do |i|
144
+ counts[i.state] += 1
145
+ end
146
+
147
+ states = []
148
+ %w{RUNNING STARTING DOWN FLAPPING}.each do |state|
149
+ if (num = counts[state]) > 0
150
+ states << "#{b(num)} #{c(state.downcase, state_color(state))}"
151
+ end
152
+ end
153
+
154
+ total = instances.count
155
+ running = counts["RUNNING"].to_s.rjust(total.to_s.size)
156
+
157
+ ratio = "#{running}#{d(" of ")}#{total} instances running"
158
+ line "#{ratio} (#{states.join(", ")})"
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,67 @@
1
+ require "jdc/cli/app/base"
2
+
3
+ module JDC::App
4
+ class Stats < Base
5
+ desc "Display application instance status"
6
+ group :apps, :info
7
+ input :app, :desc => "Application to get the stats for",
8
+ :argument => true, :from_given => by_name(:app)
9
+ def stats
10
+ app = input[:app]
11
+
12
+ stats =
13
+ with_progress("Getting stats for #{c(app.name, :name)}") do |s|
14
+ begin
15
+ app.stats
16
+ rescue JFoundry::StatsError
17
+ s.fail do
18
+ err "Application #{b(app.name)} is not running."
19
+ return
20
+ end
21
+ end
22
+ end
23
+
24
+ line unless quiet?
25
+
26
+ table(
27
+ %w{instance cpu memory disk},
28
+ stats.sort_by { |idx, _| idx.to_i }.collect { |idx, info|
29
+ idx = c("\##{idx}", :instance)
30
+
31
+ if info[:state] == "DOWN"
32
+ [idx, c("down", :bad)]
33
+ else
34
+ stats = info[:stats]
35
+ usage = stats[:usage]
36
+
37
+ if usage
38
+ [ idx,
39
+ "#{percentage(usage[:cpu])}",
40
+ "#{usage(usage[:mem], stats[:mem_quota])}",
41
+ "#{usage(usage[:disk], stats[:disk_quota])}"
42
+ ]
43
+ else
44
+ [idx, c("n/a", :neutral)]
45
+ end
46
+ end
47
+ })
48
+ end
49
+
50
+ def percentage(num, low = 50, mid = 70)
51
+ color =
52
+ if num <= low
53
+ :good
54
+ elsif num <= mid
55
+ :warning
56
+ else
57
+ :bad
58
+ end
59
+
60
+ c(format("%.1f\%", num), color)
61
+ end
62
+
63
+ def usage(used, limit)
64
+ "#{b(human_size(used))} of #{b(human_size(limit, 0))}"
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,27 @@
1
+ require "jdc/cli/app/base"
2
+
3
+ module JDC::App
4
+ class Stop < Base
5
+ desc "Stop an application"
6
+ group :apps, :manage
7
+ input :apps, :desc => "Applications to start", :argument => :splat,
8
+ :singular => :app, :from_given => by_name(:app)
9
+ input :all, :desc => "Stop all applications", :default => false
10
+ def stop
11
+ apps = input[:all] ? client.apps : input[:apps]
12
+ fail "No applications given." if apps.empty?
13
+
14
+ apps.each do |app|
15
+ with_progress("Stopping #{c(app.name, :name)}") do |s|
16
+ if app.stopped?
17
+ s.skip do
18
+ err "Application is not running."
19
+ end
20
+ end
21
+
22
+ app.stop!
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end