-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol-impl
More file actions
executable file
·118 lines (97 loc) · 2.59 KB
/
control-impl
File metadata and controls
executable file
·118 lines (97 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env oo-ruby
# -*- ruby -*-
require 'rubygems'
require 'openshift-origin-node'
require 'digest/md5'
require 'etc'
require_relative 'queue'
@@impl = OpenShift::Runtime::ApplicationContainer
@namespace = "test"
@cart_name = "php-5.3"
VALID_FUNCTIONS = %w(start stop restart create)
DELETE_FUNCTIONS = %w(destroy delete)
NUM_APPS = 100
@num_apps = nil
@command = nil
# Process args
ARGV.each do |arg|
case (val = arg.strip)
when /^\d+/
@num_apps = Integer(val)
when "all"
@num_apps = :all
when *VALID_FUNCTIONS
@command = val.to_sym
when *DELETE_FUNCTIONS
@command = :destroy
@num_apps ||= :all
else
abort "Invalid option"
end
end
def get_apps
# Get all of the apps to operate on
apps = @@impl.all.to_a
# Make sure the app is in the correct state for the operation
wanted_state = case @command
when *[:start, :destroy]
"stopped"
when *[:stop, :restart]
"started"
else
nil
end
if wanted_state
apps = apps.select{|x| x.state.value == wanted_state }
end
if @num_apps == :all
@num_apps = apps.length
else
# Make sure to grab the middle apps
sp = [0, (apps.length-@num_apps)/2].max
apps = apps.slice(sp,@num_apps)
end
# Make sure we have enough apps
apps
end
def create_app(idx)
app_name = "test#{idx}"
app_uuid = Digest::MD5.hexdigest("#{app_name}-#{@namespace}")
container = @@impl.new(app_uuid, app_uuid, nil, app_name, app_name, @namespace, nil, nil, nil)
container.create
container.configure(@cart_name)
container.post_configure(@cart_name)
container.stop(@cart_name)
end
@num_apps ||= NUM_APPS
apps = if @command == :create
abort "Cannot use all with create" if @num_apps == :all
uids = []
Etc.passwd { |u| uids << u.uid }
max_uid = uids.max
(max_uid+1 .. max_uid+@num_apps).to_a
else
get_apps
end
# Select the appropriate number of applications
abort "No apps to operate on" if apps.empty?
if apps.length < @num_apps
puts "Not enough apps in the desired state, running with what we've got"
end
Queue.run(5, max: apps.length) do |q|
apps.each do |container|
q.enqueue do
# TODO: Should restart be called by itself or as stop/start
case @command
when :create
# With create, this is actually the next available uid
create_app(container)
when :destroy
container.send(@command)
else
container.send(@command, @cart_name)
end
end
end
end
# vim: filetype=ruby