openshift-origin-controller 1.3.2
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.
- data/COPYRIGHT +1 -0
- data/Gemfile +4 -0
- data/LICENSE +12 -0
- data/README.md +3 -0
- data/Rakefile +9 -0
- data/app/controllers/app_events_controller.rb +115 -0
- data/app/controllers/application_templates_controller.rb +19 -0
- data/app/controllers/applications_controller.rb +214 -0
- data/app/controllers/base_controller.rb +367 -0
- data/app/controllers/cartridges_controller.rb +48 -0
- data/app/controllers/descriptors_controller.rb +23 -0
- data/app/controllers/dns_resolvable_controller.rb +35 -0
- data/app/controllers/domains_controller.rb +156 -0
- data/app/controllers/emb_cart_controller.rb +276 -0
- data/app/controllers/emb_cart_events_controller.rb +52 -0
- data/app/controllers/environment_controller.rb +11 -0
- data/app/controllers/estimates_controller.rb +71 -0
- data/app/controllers/gear_groups_controller.rb +53 -0
- data/app/controllers/gears_controller.rb +70 -0
- data/app/controllers/keys_controller.rb +96 -0
- data/app/controllers/legacy_broker_controller.rb +510 -0
- data/app/controllers/quickstarts_controller.rb +29 -0
- data/app/controllers/user_controller.rb +38 -0
- data/app/helpers/cartridge_helper.rb +25 -0
- data/app/helpers/legacy_broker_helper.rb +21 -0
- data/app/helpers/user_action_logger.rb +38 -0
- data/app/models/application.rb +1718 -0
- data/app/models/application_template.rb +27 -0
- data/app/models/cartridge_cache.rb +51 -0
- data/app/models/cloud_user.rb +334 -0
- data/app/models/component_instance.rb +228 -0
- data/app/models/connection_endpoint.rb +10 -0
- data/app/models/district.rb +210 -0
- data/app/models/domain.rb +234 -0
- data/app/models/gear.rb +376 -0
- data/app/models/group_instance.rb +306 -0
- data/app/models/key.rb +20 -0
- data/app/models/legacy_reply.rb +15 -0
- data/app/models/legacy_request.rb +126 -0
- data/app/models/link.rb +11 -0
- data/app/models/message.rb +10 -0
- data/app/models/name_server_cache.rb +46 -0
- data/app/models/optional_param.rb +12 -0
- data/app/models/param.rb +13 -0
- data/app/models/remote_job.rb +57 -0
- data/app/models/rest_application.rb +126 -0
- data/app/models/rest_application10.rb +106 -0
- data/app/models/rest_application12.rb +124 -0
- data/app/models/rest_application_estimate.rb +12 -0
- data/app/models/rest_application_template.rb +20 -0
- data/app/models/rest_cartridge10.rb +41 -0
- data/app/models/rest_cartridge11.rb +151 -0
- data/app/models/rest_domain.rb +43 -0
- data/app/models/rest_domain10.rb +42 -0
- data/app/models/rest_estimates.rb +16 -0
- data/app/models/rest_gear.rb +14 -0
- data/app/models/rest_gear_group.rb +26 -0
- data/app/models/rest_key.rb +24 -0
- data/app/models/rest_reply.rb +31 -0
- data/app/models/rest_user.rb +43 -0
- data/app/models/result_io.rb +67 -0
- data/app/models/usage_record.rb +37 -0
- data/app/models/validators/app_validator.rb +30 -0
- data/app/models/validators/key_validator.rb +30 -0
- data/app/models/validators/namespace_validator.rb +18 -0
- data/config/routes.rb +36 -0
- data/lib/controller_engine.rb +7 -0
- data/lib/openshift-origin-controller.rb +14 -0
- data/lib/openshift/application_container_proxy.rb +241 -0
- data/lib/openshift/auth_service.rb +101 -0
- data/lib/openshift/data_store.rb +33 -0
- data/lib/openshift/dns_service.rb +41 -0
- data/lib/openshift/mongo_data_store.rb +671 -0
- data/openshift-origin-controller.gemspec +42 -0
- data/rubygem-openshift-origin-controller.spec +274 -0
- data/test/cucumber/application-estimate.feature +25 -0
- data/test/cucumber/cartridge-10gen-mms-agent.feature +28 -0
- data/test/cucumber/cartridge-cron.feature +32 -0
- data/test/cucumber/cartridge-haproxy.feature +31 -0
- data/test/cucumber/cartridge-jenkins-build.feature +12 -0
- data/test/cucumber/cartridge-jenkins-client.feature +10 -0
- data/test/cucumber/cartridge-lifecycle-diy.feature +21 -0
- data/test/cucumber/cartridge-lifecycle-jbossas.feature +61 -0
- data/test/cucumber/cartridge-lifecycle-jbosseap.feature +61 -0
- data/test/cucumber/cartridge-lifecycle-jbossews10.feature +61 -0
- data/test/cucumber/cartridge-lifecycle-jenkins.feature +41 -0
- data/test/cucumber/cartridge-lifecycle-nodejs.feature +59 -0
- data/test/cucumber/cartridge-lifecycle-perl.feature +40 -0
- data/test/cucumber/cartridge-lifecycle-php.feature +106 -0
- data/test/cucumber/cartridge-lifecycle-python.feature +40 -0
- data/test/cucumber/cartridge-lifecycle-ruby18.feature +49 -0
- data/test/cucumber/cartridge-lifecycle-ruby19.feature +41 -0
- data/test/cucumber/cartridge-mongodb.feature +31 -0
- data/test/cucumber/cartridge-mysql.feature +30 -0
- data/test/cucumber/cartridge-php.feature +14 -0
- data/test/cucumber/cartridge-phpmyadmin.feature +32 -0
- data/test/cucumber/cartridge-postgresql.feature +32 -0
- data/test/cucumber/cartridge-runtime-extended-db.feature +64 -0
- data/test/cucumber/cartridge-runtime-extended-jboss.feature +24 -0
- data/test/cucumber/cartridge-runtime-extended-nodejs.feature +21 -0
- data/test/cucumber/cartridge-runtime-extended-perl.feature +18 -0
- data/test/cucumber/cartridge-runtime-extended-php.feature +19 -0
- data/test/cucumber/cartridge-runtime-extended-python.feature +18 -0
- data/test/cucumber/cartridge-runtime-extended-ruby.feature +22 -0
- data/test/cucumber/cartridge-runtime-standard-diy.feature +6 -0
- data/test/cucumber/cartridge-runtime-standard-jbossas.feature +7 -0
- data/test/cucumber/cartridge-runtime-standard-jbosseap.feature +7 -0
- data/test/cucumber/cartridge-runtime-standard-jbossews10.feature +7 -0
- data/test/cucumber/cartridge-runtime-standard-jenkins.feature +8 -0
- data/test/cucumber/cartridge-runtime-standard-nodejs.feature +7 -0
- data/test/cucumber/cartridge-runtime-standard-perl.feature +6 -0
- data/test/cucumber/cartridge-runtime-standard-php.feature +6 -0
- data/test/cucumber/cartridge-runtime-standard-python.feature +6 -0
- data/test/cucumber/cartridge-runtime-standard-ruby.feature +19 -0
- data/test/cucumber/cartridge-switchyard.feature +36 -0
- data/test/cucumber/descriptor.feature +40 -0
- data/test/cucumber/embedded.feature +44 -0
- data/test/cucumber/idler.feature +75 -0
- data/test/cucumber/misc/descriptor/manifest.yml +22 -0
- data/test/cucumber/misc/php/db_test.php +21 -0
- data/test/cucumber/openshift-node.feature +21 -0
- data/test/cucumber/rest-application-templates.feature +31 -0
- data/test/cucumber/rest-applications.feature +431 -0
- data/test/cucumber/rest-cartridge-types.feature +16 -0
- data/test/cucumber/rest-domains.feature +276 -0
- data/test/cucumber/rest-gears.feature +38 -0
- data/test/cucumber/rest-keys.feature +247 -0
- data/test/cucumber/rest-quickstarts.feature +27 -0
- data/test/cucumber/rest-workflow.feature +64 -0
- data/test/cucumber/step_definitions/api_steps.rb +369 -0
- data/test/cucumber/step_definitions/application-estimate-steps.rb +51 -0
- data/test/cucumber/step_definitions/application_steps.rb +215 -0
- data/test/cucumber/step_definitions/cartridge-10gen-mms-agent_steps.rb +11 -0
- data/test/cucumber/step_definitions/cartridge-cron_steps.rb +51 -0
- data/test/cucumber/step_definitions/cartridge-haproxy_steps.rb +30 -0
- data/test/cucumber/step_definitions/cartridge-jenkins_steps.rb +93 -0
- data/test/cucumber/step_definitions/cartridge-lifecycle-nodejs_steps.rb +30 -0
- data/test/cucumber/step_definitions/cartridge-mongodb_steps.rb +60 -0
- data/test/cucumber/step_definitions/cartridge-mysql_steps.rb +56 -0
- data/test/cucumber/step_definitions/cartridge-php_steps.rb +72 -0
- data/test/cucumber/step_definitions/cartridge-postgresql_steps.rb +59 -0
- data/test/cucumber/step_definitions/cartridge-switchyard_steps.rb +29 -0
- data/test/cucumber/step_definitions/client_steps.rb +12 -0
- data/test/cucumber/step_definitions/descriptor_step.rb +32 -0
- data/test/cucumber/step_definitions/idler_steps.rb +37 -0
- data/test/cucumber/step_definitions/node_steps.rb +203 -0
- data/test/cucumber/step_definitions/runtime_steps.rb +547 -0
- data/test/cucumber/step_definitions/runtime_url_steps.rb +46 -0
- data/test/cucumber/step_definitions/trap-user-extended_steps.rb +14 -0
- data/test/cucumber/step_definitions/trap-user_steps.rb +58 -0
- data/test/cucumber/support/00_setup_helper.rb +106 -0
- data/test/cucumber/support/app_helper.rb +243 -0
- data/test/cucumber/support/assertions.rb +52 -0
- data/test/cucumber/support/command_helper.rb +453 -0
- data/test/cucumber/support/dns_helper.rb +54 -0
- data/test/cucumber/support/env.rb +5 -0
- data/test/cucumber/support/process_helper.rb +44 -0
- data/test/cucumber/support/runtime_support.rb +440 -0
- data/test/cucumber/support/unused.rb +27 -0
- data/test/cucumber/support/user_helper.rb +37 -0
- data/test/cucumber/trap-user-extended.feature +53 -0
- data/test/cucumber/trap-user.feature +34 -0
- data/test/ddns/1.168.192-rev.db.init +13 -0
- data/test/ddns/HOWTO.txt +207 -0
- data/test/ddns/Kexample.com.+157+06142.key +1 -0
- data/test/ddns/Kexample.com.+157+06142.private +7 -0
- data/test/ddns/authconfig.rb +14 -0
- data/test/ddns/example.com.db.init +23 -0
- data/test/ddns/example.com.key +4 -0
- data/test/ddns/named.ca +52 -0
- data/test/ddns/named.conf +48 -0
- data/test/ddns/named.empty +10 -0
- data/test/ddns/named.localhost +10 -0
- data/test/ddns/named.loopback +11 -0
- data/test/ddns/named.rfc1912.zones +42 -0
- data/test/ddns/named.root.key +5 -0
- data/test/ddns/named_service.rb +127 -0
- data/test/unit/bind_dns_service_test.rb +167 -0
- data/test/unit/broker_auth_test.rb +28 -0
- metadata +545 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
class EmbCartEventsController < BaseController
|
|
2
|
+
respond_to :xml, :json
|
|
3
|
+
before_filter :authenticate, :check_version
|
|
4
|
+
|
|
5
|
+
# POST /domain/[domain_id]/applications/[application_id]/cartridges/[cartridge_id]/events
|
|
6
|
+
def create
|
|
7
|
+
domain_id = params[:domain_id]
|
|
8
|
+
id = params[:application_id]
|
|
9
|
+
cartridge = params[:cartridge_id]
|
|
10
|
+
event = params[:event]
|
|
11
|
+
|
|
12
|
+
domain = Domain.get(@cloud_user, domain_id)
|
|
13
|
+
return render_error(:not_found, "Domain #{domain_id} not found", 127,
|
|
14
|
+
"CARTRIDGE_EVENT") if !domain || !domain.hasAccess?(@cloud_user)
|
|
15
|
+
|
|
16
|
+
@domain_name = domain.namespace
|
|
17
|
+
application = get_application(id)
|
|
18
|
+
return render_error(:not_found, "Application '#{id}' not found for domain '#{domain_id}'",
|
|
19
|
+
101, "CARTRIDGE_EVENT") unless application
|
|
20
|
+
|
|
21
|
+
@application_name = application.name
|
|
22
|
+
@application_uuid = application.uuid
|
|
23
|
+
return render_error(:bad_request, "Cartridge #{cartridge} not embedded within application #{id}",
|
|
24
|
+
129, "CARTRIDGE_EVENT") if !application.embedded or !application.embedded.has_key?(cartridge)
|
|
25
|
+
|
|
26
|
+
begin
|
|
27
|
+
case event
|
|
28
|
+
when 'start'
|
|
29
|
+
application.start(cartridge)
|
|
30
|
+
when 'stop'
|
|
31
|
+
application.stop(cartridge)
|
|
32
|
+
when 'restart'
|
|
33
|
+
application.restart(cartridge)
|
|
34
|
+
when 'reload'
|
|
35
|
+
application.reload(cartridge)
|
|
36
|
+
else
|
|
37
|
+
return render_error(:bad_request, "Invalid event '#{event}' for embedded cartridge #{cartridge} within application '#{id}'",
|
|
38
|
+
126, "CARTRIDGE_EVENT")
|
|
39
|
+
end
|
|
40
|
+
rescue Exception => e
|
|
41
|
+
return render_exception(e, "CARTRIDGE_EVENT")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
application = get_application(id)
|
|
45
|
+
if $requested_api_version >= 1.2
|
|
46
|
+
app = RestApplication12.new(application, get_url, nolinks)
|
|
47
|
+
else
|
|
48
|
+
app = RestApplication10.new(application, get_url, nolinks)
|
|
49
|
+
end
|
|
50
|
+
render_success(:ok, "application", app, "CARTRIDGE_EVENT", "Added #{event} on #{cartridge} for application #{id}", true)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class EnvironmentController < BaseController
|
|
2
|
+
respond_to :xml, :json
|
|
3
|
+
before_filter :check_version
|
|
4
|
+
|
|
5
|
+
# GET /environment
|
|
6
|
+
def show
|
|
7
|
+
environment = {}
|
|
8
|
+
environment['domain_suffix'] = Rails.application.config.openshift[:domain_suffix]
|
|
9
|
+
render_success(:ok, "environment", environment, "GET_ENVIRONMENT", "Showing broker environment")
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
class EstimatesController < BaseController
|
|
2
|
+
respond_to :xml, :json
|
|
3
|
+
before_filter :authenticate, :check_version
|
|
4
|
+
|
|
5
|
+
# GET /estimates
|
|
6
|
+
def index
|
|
7
|
+
render_success(:ok, "estimates", RestEstimates.new(get_url, nolinks), "LIST_ESTIMATES")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# GET /estimates/<id>
|
|
11
|
+
def show
|
|
12
|
+
obj = params[:id]
|
|
13
|
+
descriptor = params[:descriptor]
|
|
14
|
+
|
|
15
|
+
begin
|
|
16
|
+
raise OpenShift::EstimatesException.new("Invalid estimate object. Estimates only valid for objects: 'application'") if obj != "application"
|
|
17
|
+
raise OpenShift::EstimatesException.new("Application 'descriptor' NOT specified") if !descriptor
|
|
18
|
+
# Get available framework cartridges
|
|
19
|
+
standalone_carts = Application.get_available_cartridges("standalone")
|
|
20
|
+
|
|
21
|
+
# Parse given application descriptor
|
|
22
|
+
descriptor.gsub!('\n', "\n")
|
|
23
|
+
descriptor_hash = YAML.load(descriptor)
|
|
24
|
+
#log_action(@request_id, @cloud_user.uuid, @cloud_user.login, "SHOW_ESTIMATE", false, "Invalid application descriptor") unless descriptor_hash
|
|
25
|
+
raise OpenShift::EstimatesException.new("Invalid application descriptor.") unless descriptor_hash
|
|
26
|
+
|
|
27
|
+
# Find app framework
|
|
28
|
+
framework = nil
|
|
29
|
+
descriptor_hash['Requires'].each do |cart|
|
|
30
|
+
if standalone_carts.include?(cart)
|
|
31
|
+
framework = cart
|
|
32
|
+
break
|
|
33
|
+
end
|
|
34
|
+
end if descriptor_hash.has_key?('Requires')
|
|
35
|
+
app_name = descriptor_hash['Name'] || nil
|
|
36
|
+
|
|
37
|
+
#log_action(@request_id, @cloud_user.uuid, @cloud_user.login, "SHOW_ESTIMATE", false, "Application name or framework not found in the descriptor") if !framework or !app_name
|
|
38
|
+
raise OpenShift::EstimatesException.new("Application name or framework not found in the descriptor.") if !framework or !app_name
|
|
39
|
+
|
|
40
|
+
# Elaborate app descriptor
|
|
41
|
+
template = ApplicationTemplate.new
|
|
42
|
+
template.descriptor_yaml = descriptor
|
|
43
|
+
app = Application.new(nil, app_name, nil, nil, framework, template)
|
|
44
|
+
app.elaborate_descriptor
|
|
45
|
+
|
|
46
|
+
# Generate output
|
|
47
|
+
groups = []
|
|
48
|
+
app.group_instance_map.values.uniq.each do |ginst|
|
|
49
|
+
components = []
|
|
50
|
+
ginst.component_instances.each do |cname|
|
|
51
|
+
cinst = app.comp_instance_map[cname]
|
|
52
|
+
next if cinst.parent_cart_name == app.name
|
|
53
|
+
comp = {}
|
|
54
|
+
comp['Name'] = cinst.parent_cart_name
|
|
55
|
+
components.push comp
|
|
56
|
+
end if ginst
|
|
57
|
+
|
|
58
|
+
if !components.empty?
|
|
59
|
+
app_gear = RestApplicationEstimate.new(components)
|
|
60
|
+
groups.push(app_gear)
|
|
61
|
+
end
|
|
62
|
+
end if app.group_instance_map
|
|
63
|
+
|
|
64
|
+
render_success(:ok, "application_estimates", groups, "SHOW_ESTIMATE")
|
|
65
|
+
rescue OpenShift::EstimatesException => e
|
|
66
|
+
return render_error(:unprocessable_entity, e.message, 130, "SHOW_ESTIMATE")
|
|
67
|
+
rescue Exception => e
|
|
68
|
+
return render_exception(e, "SHOW_ESTIMATE")
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
class GearGroupsController < BaseController
|
|
2
|
+
respond_to :xml, :json
|
|
3
|
+
before_filter :authenticate, :check_version
|
|
4
|
+
|
|
5
|
+
# GET /domains/[domain_id]/applications/[application_id]/gear_groups
|
|
6
|
+
def index
|
|
7
|
+
domain_id = params[:domain_id]
|
|
8
|
+
app_id = params[:application_id]
|
|
9
|
+
|
|
10
|
+
domain = Domain.get(@cloud_user, domain_id)
|
|
11
|
+
return render_error(:not_found, "Domain #{domain_id} not found", 127,
|
|
12
|
+
"LIST_GEAR_GROUPS") if !domain || !domain.hasAccess?(@cloud_user)
|
|
13
|
+
|
|
14
|
+
@domain_name = domain.namespace
|
|
15
|
+
app = Application.find(@cloud_user,app_id)
|
|
16
|
+
return render_error(:not_found, "Application '#{app_id}' not found for domain '#{domain_id}'",
|
|
17
|
+
101, "LIST_GEAR_GROUPS") unless app
|
|
18
|
+
|
|
19
|
+
@application_name = app.name
|
|
20
|
+
@application_uuid = app.uuid
|
|
21
|
+
gear_states = app.show_state()
|
|
22
|
+
group_instances = app.group_instances.map{ |group_inst| RestGearGroup.new(group_inst, gear_states, get_url, nolinks)}
|
|
23
|
+
render_success(:ok, "gear_groups", group_instances, "LIST_GEAR_GROUPS",
|
|
24
|
+
"Showing gear groups for application '#{app_id}' with domain '#{domain_id}'")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# GET /domains/[domain_id]/applications/[application_id]/gear_groups/[id]
|
|
28
|
+
def show
|
|
29
|
+
domain_id = params[:domain_id]
|
|
30
|
+
app_id = params[:application_id]
|
|
31
|
+
gear_group_id = params[:id]
|
|
32
|
+
|
|
33
|
+
domain = Domain.get(@cloud_user, domain_id)
|
|
34
|
+
return render_error(:not_found, "Domain #{domain_id} not found", 127,
|
|
35
|
+
"GET_GEAR_GROUP") if !domain || !domain.hasAccess?(@cloud_user)
|
|
36
|
+
|
|
37
|
+
@domain_name = domain.namespace
|
|
38
|
+
app = Application.find(@cloud_user,app_id)
|
|
39
|
+
return render_error(:not_found, "Application '#{app_id}' not found for domain '#{domain_id}'",
|
|
40
|
+
101, "GET_GEAR_GROUP") unless app
|
|
41
|
+
|
|
42
|
+
@application_name = app.name
|
|
43
|
+
@application_uuid = app.uuid
|
|
44
|
+
selected_gear_group = GroupInstance.get(app, gear_group_id)
|
|
45
|
+
return render_error(:not_found, "Gear group '#{gear_group_id}' for application '#{app_id}' not found",
|
|
46
|
+
163, "GET_GEAR_GROUP") unless selected_gear_group
|
|
47
|
+
|
|
48
|
+
gear_states = app.show_state()
|
|
49
|
+
group = RestGearGroup.new(selected_gear_group, gear_states, get_url, nolinks)
|
|
50
|
+
render_success(:ok, "gear_group", group, "GET_GEAR_GROUP",
|
|
51
|
+
"Showing gear group '#{app_id}' for application '#{app_id}' with domain '#{domain_id}'")
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
class GearsController < BaseController
|
|
2
|
+
respond_to :xml, :json
|
|
3
|
+
before_filter :authenticate, :check_version
|
|
4
|
+
|
|
5
|
+
def show
|
|
6
|
+
domain_id = params[:domain_id]
|
|
7
|
+
app_id = params[:application_id]
|
|
8
|
+
|
|
9
|
+
domain = Domain.get(@cloud_user, domain_id)
|
|
10
|
+
return render_error(:not_found, "Domain #{domain_id} not found", 127,
|
|
11
|
+
"LIST_GEARS") if !domain || !domain.hasAccess?(@cloud_user)
|
|
12
|
+
|
|
13
|
+
@domain_name = domain.namespace
|
|
14
|
+
app = get_application(app_id)
|
|
15
|
+
return render_error(:not_found, "Application '#{app_id}' not found for domain '#{domain_id}'",
|
|
16
|
+
101, "LIST_GEARS") unless app
|
|
17
|
+
|
|
18
|
+
@application_name = app.name
|
|
19
|
+
@application_uuid = app.uuid
|
|
20
|
+
begin
|
|
21
|
+
app_gears_info = []
|
|
22
|
+
gears = app.group_instances.uniq.map{ |ginst| ginst.gears }.flatten
|
|
23
|
+
|
|
24
|
+
has_proxy_cart = false
|
|
25
|
+
rx1 = Regexp.new(/^PROXY_HOST=(.*)/)
|
|
26
|
+
rx2 = Regexp.new(/^PROXY_PORT=(.*)/)
|
|
27
|
+
rx3 = Regexp.new(/^PORT=(.*)/)
|
|
28
|
+
|
|
29
|
+
gears.each do |gear|
|
|
30
|
+
comp_list = []
|
|
31
|
+
gear.configured_components.each do |cname|
|
|
32
|
+
comp_inst = app.comp_instance_map[cname]
|
|
33
|
+
has_proxy_cart = true if app.proxy_cartridge and cname.include? app.proxy_cartridge
|
|
34
|
+
next if comp_inst.parent_cart_name == app.name
|
|
35
|
+
|
|
36
|
+
begin
|
|
37
|
+
res = gear.show_port(comp_inst).data
|
|
38
|
+
|
|
39
|
+
m = rx1.match(res)
|
|
40
|
+
proxy_host = m[1] if m
|
|
41
|
+
m = rx2.match(res)
|
|
42
|
+
proxy_port = m[1].to_i if m
|
|
43
|
+
m = rx3.match(res)
|
|
44
|
+
internal_port = m[1].to_i if m
|
|
45
|
+
rescue
|
|
46
|
+
#ignore
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
comp_info = {
|
|
50
|
+
'name' => comp_inst.parent_cart_name,
|
|
51
|
+
'proxy_host' => proxy_host,
|
|
52
|
+
'proxy_port' => proxy_port,
|
|
53
|
+
'internal_port' => internal_port
|
|
54
|
+
}
|
|
55
|
+
if comp_inst.cart_properties and comp_inst.cart_properties.length > 0
|
|
56
|
+
comp_info = comp_inst.cart_properties.merge comp_info
|
|
57
|
+
end
|
|
58
|
+
comp_list.push comp_info
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
gear_info = RestGear.new(gear.uuid, comp_list)
|
|
62
|
+
app_gears_info.push gear_info
|
|
63
|
+
end
|
|
64
|
+
render_success(:ok, "gears", app_gears_info, "LIST_GEARS",
|
|
65
|
+
"Showing gears for application '#{app_id}' for domain '#{domain_id}'")
|
|
66
|
+
rescue Exception => e
|
|
67
|
+
return render_exception(e, "LIST_GEARS")
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
class KeysController < BaseController
|
|
2
|
+
respond_to :xml, :json
|
|
3
|
+
before_filter :authenticate, :check_version
|
|
4
|
+
|
|
5
|
+
#GET /user/keys
|
|
6
|
+
def index
|
|
7
|
+
ssh_keys = Array.new
|
|
8
|
+
@cloud_user.ssh_keys.each do |name, key|
|
|
9
|
+
ssh_key = RestKey.new(name, key["key"], key["type"], get_url, nolinks)
|
|
10
|
+
ssh_keys.push(ssh_key)
|
|
11
|
+
end if @cloud_user.ssh_keys
|
|
12
|
+
render_success(:ok, "keys", ssh_keys, "LIST_KEYS", "Found #{ssh_keys.length} ssh keys")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
#GET /user/keys/<id>
|
|
16
|
+
def show
|
|
17
|
+
id = params[:id]
|
|
18
|
+
@cloud_user.ssh_keys.each do |key_name, key|
|
|
19
|
+
return render_success(:ok, "key", RestKey.new(key_name, key["key"], key["type"], get_url, nolinks),
|
|
20
|
+
"SHOW_KEY", "Found SSH key '#{id}'") if key_name == id
|
|
21
|
+
end if @cloud_user.ssh_keys
|
|
22
|
+
render_error(:not_found, "SSH key '#{id}' not found", 118, "SHOW_KEY")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#POST /user/keys
|
|
26
|
+
def create
|
|
27
|
+
content = params[:content]
|
|
28
|
+
name = params[:name]
|
|
29
|
+
type = params[:type]
|
|
30
|
+
|
|
31
|
+
Rails.logger.debug "Creating key name:#{name} type:#{type} for user #{@login}"
|
|
32
|
+
|
|
33
|
+
key = Key.new(name, type, content)
|
|
34
|
+
if key.invalid?
|
|
35
|
+
messages = get_error_messages(key)
|
|
36
|
+
return render_error(:unprocessable_entity, nil, nil, "ADD_KEY", nil, nil, messages)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
@cloud_user.ssh_keys.each do |key_name, key|
|
|
40
|
+
return render_error(:conflict, "SSH key with name #{name} already exists. Use a different name or delete conflicting key and retry.",
|
|
41
|
+
120, "ADD_KEY", "name") if key_name == name
|
|
42
|
+
return render_error(:conflict, "Given public key is already in use. Use different key or delete conflicting key and retry.",
|
|
43
|
+
121, "ADD_KEY", "content") if key["key"] == content
|
|
44
|
+
end if @cloud_user.ssh_keys
|
|
45
|
+
|
|
46
|
+
begin
|
|
47
|
+
@cloud_user.add_ssh_key(name, content, type)
|
|
48
|
+
@cloud_user.save
|
|
49
|
+
ssh_key = RestKey.new(name, @cloud_user.ssh_keys[name]["key"], @cloud_user.ssh_keys[name]["type"], get_url, nolinks)
|
|
50
|
+
render_success(:created, "key", ssh_key, "ADD_KEY", "Created SSH key #{name}", true)
|
|
51
|
+
rescue Exception => e
|
|
52
|
+
return render_exception(e, "ADD_KEY")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#PUT /user/keys/<id>
|
|
57
|
+
def update
|
|
58
|
+
id = params[:id]
|
|
59
|
+
content = params[:content]
|
|
60
|
+
type = params[:type]
|
|
61
|
+
|
|
62
|
+
Rails.logger.debug "Updating key name:#{id} type:#{type} for user #{@login}"
|
|
63
|
+
key = Key.new(id, type, content)
|
|
64
|
+
if key.invalid?
|
|
65
|
+
messages = get_error_messages(key)
|
|
66
|
+
return render_format_error(:unprocessable_entity, nil, nil, "UPDATE_KEY", nil, nil, messages)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
return render_format_error(:not_found, "SSH key '#{id}' not found", 118,
|
|
70
|
+
"UPDATE_KEY") if !@cloud_user.ssh_keys or !@cloud_user.ssh_keys.has_key?(id)
|
|
71
|
+
|
|
72
|
+
begin
|
|
73
|
+
@cloud_user.update_ssh_key(content, type, id)
|
|
74
|
+
@cloud_user.save
|
|
75
|
+
ssh_key = RestKey.new(id, @cloud_user.ssh_keys[id]["key"], @cloud_user.ssh_keys[id]["type"], get_url, nolinks)
|
|
76
|
+
render_format_success(:ok, "key", ssh_key, "UPDATE_KEY", "Updated SSH key #{id}", true)
|
|
77
|
+
rescue Exception => e
|
|
78
|
+
return render_format_exception(e, "UPDATE_KEY")
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#DELETE /user/keys/<id>
|
|
83
|
+
def destroy
|
|
84
|
+
id = params[:id]
|
|
85
|
+
return render_format_error(:not_found, "SSH key '#{id}' not found", 118,
|
|
86
|
+
"DELETE_KEY") if !@cloud_user.ssh_keys or !@cloud_user.ssh_keys.has_key?(id)
|
|
87
|
+
|
|
88
|
+
begin
|
|
89
|
+
@cloud_user.remove_ssh_key(id)
|
|
90
|
+
@cloud_user.save
|
|
91
|
+
render_format_success(:no_content, nil, nil, "DELETE_KEY", "Deleted SSH key #{id}", true)
|
|
92
|
+
rescue Exception => e
|
|
93
|
+
return render_format_exception(e, "DELETE_KEY")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
class LegacyBrokerController < ApplicationController
|
|
2
|
+
layout nil
|
|
3
|
+
before_filter :validate_request, :process_notification
|
|
4
|
+
before_filter :authenticate, :except => :cart_list_post
|
|
5
|
+
rescue_from Exception, :with => :exception_handler
|
|
6
|
+
include LegacyBrokerHelper
|
|
7
|
+
include UserActionLogger
|
|
8
|
+
include CartridgeHelper
|
|
9
|
+
|
|
10
|
+
# Initialize domain/app variables to be used for logging in user_action.log
|
|
11
|
+
# The values will be set in the controllers handling the requests
|
|
12
|
+
@domain_name = nil
|
|
13
|
+
@application_name = nil
|
|
14
|
+
@application_uuid = nil
|
|
15
|
+
|
|
16
|
+
def user_info_post
|
|
17
|
+
if @cloud_user
|
|
18
|
+
user_info = @cloud_user.as_json
|
|
19
|
+
#FIXME: This is redundant, for now keeping it for backward compatibility
|
|
20
|
+
key_info = @cloud_user.get_ssh_key
|
|
21
|
+
if key_info
|
|
22
|
+
user_info["ssh_key"] = key_info['key']
|
|
23
|
+
user_info["ssh_type"] = key_info['type']
|
|
24
|
+
else
|
|
25
|
+
user_info["ssh_key"] = ""
|
|
26
|
+
user_info["ssh_type"] = ""
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
user_info["rhlogin"] = user_info["login"]
|
|
30
|
+
user_info.delete("login")
|
|
31
|
+
# this is to support old version of client tools
|
|
32
|
+
if @cloud_user.domains and @cloud_user.domains.length > 0
|
|
33
|
+
user_info["namespace"] = @cloud_user.domains.first.namespace
|
|
34
|
+
end
|
|
35
|
+
user_info[:rhc_domain] = Rails.configuration.openshift[:domain_suffix]
|
|
36
|
+
app_info = {}
|
|
37
|
+
unless @cloud_user.applications.nil?
|
|
38
|
+
@cloud_user.applications.each do |app|
|
|
39
|
+
app_info[app.name] = {
|
|
40
|
+
"framework" => app.framework,
|
|
41
|
+
"creation_time" => app.creation_time,
|
|
42
|
+
"uuid" => app.uuid,
|
|
43
|
+
"aliases" => app.aliases,
|
|
44
|
+
"embedded" => app.embedded
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_USER_INFO", true, "", get_extra_log_args)
|
|
50
|
+
@reply.data = {:user_info => user_info, :app_info => app_info}.to_json
|
|
51
|
+
render :json => @reply
|
|
52
|
+
else
|
|
53
|
+
log_action(@request_id, "nil", @login, "LEGACY_USER_INFO", true, "User not found", get_extra_log_args)
|
|
54
|
+
# Return a 404 to denote the user doesn't exist
|
|
55
|
+
@reply.resultIO << "User does not exist"
|
|
56
|
+
@reply.exitcode = 99
|
|
57
|
+
|
|
58
|
+
render :json => @reply, :status => :not_found
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def ssh_keys_post
|
|
63
|
+
if @cloud_user
|
|
64
|
+
case @req.action
|
|
65
|
+
when "add-key"
|
|
66
|
+
raise OpenShift::UserKeyException.new("Missing SSH key or key name", 119) if @req.ssh.nil? or @req.key_name.nil?
|
|
67
|
+
if @cloud_user.ssh_keys
|
|
68
|
+
raise OpenShift::UserKeyException.new("Key with name #{@req.key_name} already exists. Please choose a different name", 120) if @cloud_user.ssh_keys.has_key?(@req.key_name)
|
|
69
|
+
end
|
|
70
|
+
@cloud_user.add_ssh_key(@req.key_name, @req.ssh, @req.key_type)
|
|
71
|
+
@cloud_user.save
|
|
72
|
+
when "remove-key"
|
|
73
|
+
raise OpenShift::UserKeyException.new("Missing key name", 119) if @req.key_name.nil?
|
|
74
|
+
@cloud_user.remove_ssh_key(@req.key_name)
|
|
75
|
+
@cloud_user.save
|
|
76
|
+
when "update-key"
|
|
77
|
+
raise OpenShift::UserKeyException.new("Missing SSH key or key name", 119) if @req.ssh.nil? or @req.key_name.nil?
|
|
78
|
+
@cloud_user.update_ssh_key(@req.ssh, @req.key_type, @req.key_name)
|
|
79
|
+
@cloud_user.save
|
|
80
|
+
when "list-keys"
|
|
81
|
+
#FIXME: when client tools are updated
|
|
82
|
+
if @cloud_user.ssh_keys.nil? || @cloud_user.ssh_keys.empty?
|
|
83
|
+
@reply.data = {:keys => {}, :ssh_key => "", :ssh_type => ""}.to_json
|
|
84
|
+
else
|
|
85
|
+
other_keys = @cloud_user.ssh_keys.reject {|k, v| k == Key::DEFAULT_SSH_KEY_NAME }
|
|
86
|
+
if @cloud_user.ssh_keys.has_key?(Key::DEFAULT_SSH_KEY_NAME)
|
|
87
|
+
default_key = @cloud_user.ssh_keys[Key::DEFAULT_SSH_KEY_NAME]['key']
|
|
88
|
+
default_key_type = @cloud_user.ssh_keys[Key::DEFAULT_SSH_KEY_NAME]['type']
|
|
89
|
+
else
|
|
90
|
+
default_key = default_key_type = ""
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
@reply.data = { :keys => other_keys,
|
|
94
|
+
:ssh_key => default_key,
|
|
95
|
+
:ssh_type => default_key_type,
|
|
96
|
+
}.to_json
|
|
97
|
+
end
|
|
98
|
+
else
|
|
99
|
+
raise OpenShift::UserKeyException.new("Invalid action #{@req.action}", 111)
|
|
100
|
+
end
|
|
101
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_SSH_KEY", true, "Successfully completed action: #{@req.action}", get_extra_log_args)
|
|
102
|
+
render :json => @reply
|
|
103
|
+
else
|
|
104
|
+
raise OpenShift::UserException.new("Invalid user", 99)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def domain_post
|
|
109
|
+
domain = get_domain(@cloud_user, @req.namespace)
|
|
110
|
+
domain = @cloud_user.domains.first if !domain && @req.alter
|
|
111
|
+
|
|
112
|
+
if (!domain or not domain.hasFullAccess?(@cloud_user)) && (@req.alter || @req.delete)
|
|
113
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_ALTER_DOMAIN", true, "Cannot alter or remove namespace #{@req.namespace}. Namespace does not exist.", get_extra_log_args)
|
|
114
|
+
@reply.resultIO << "Cannot alter or remove namespace #{@req.namespace}. Namespace does not exist.\n"
|
|
115
|
+
@reply.exitcode = 106
|
|
116
|
+
render :json => @reply, :status => :bad_request
|
|
117
|
+
return
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
if @req.alter
|
|
121
|
+
|
|
122
|
+
Rails.logger.debug "Updating namespace for domain #{domain.uuid} from #{domain.namespace} to #{@req.namespace}"
|
|
123
|
+
|
|
124
|
+
raise OpenShift::UserException.new("The supplied namespace '#{@req.namespace}' is not allowed", 106) if OpenShift::ApplicationContainerProxy.blacklisted? @req.namespace
|
|
125
|
+
begin
|
|
126
|
+
if domain.namespace != @req.namespace
|
|
127
|
+
domain.namespace = @req.namespace
|
|
128
|
+
@reply.append domain.save
|
|
129
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_ALTER_DOMAIN", true, "Updated namespace for domain #{domain.uuid} to #{@req.namespace}", get_extra_log_args)
|
|
130
|
+
end
|
|
131
|
+
rescue Exception => e
|
|
132
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_ALTER_DOMAIN", false, "Failed to updated namespace for domain #{domain.uuid} to #{@req.namespace}", get_extra_log_args)
|
|
133
|
+
Rails.logger.error "Failed to update domain #{domain.uuid} from #{domain.namespace} to #{@req.namespace} #{e.message}"
|
|
134
|
+
Rails.logger.error e.backtrace
|
|
135
|
+
raise
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
if @req.ssh
|
|
139
|
+
@cloud_user.update_ssh_key(@req.ssh, @req.key_type, @req.key_name)
|
|
140
|
+
@cloud_user.save
|
|
141
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_ALTER_DOMAIN", true, "Updated SSH key '#{@req.key_name}' for domain #{domain.namespace}", get_extra_log_args)
|
|
142
|
+
end
|
|
143
|
+
elsif @req.delete
|
|
144
|
+
if not domain.hasFullAccess?(@cloud_user)
|
|
145
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_DELETE_DOMAIN", true, "Domain #{domain.namespace} is not associated with user", get_extra_log_args)
|
|
146
|
+
@reply.resultIO << "Cannot remove namespace #{@req.namespace}. This namespace is not associated with login: #{@cloud_user.login}\n"
|
|
147
|
+
@reply.exitcode = 106
|
|
148
|
+
render :json => @reply, :status => :bad_request
|
|
149
|
+
return
|
|
150
|
+
end
|
|
151
|
+
if not @cloud_user.applications.empty?
|
|
152
|
+
@cloud_user.applications.each do |app|
|
|
153
|
+
if app.domain.uuid == domain.uuid
|
|
154
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_DELETE_DOMAIN", true, "Domain #{domain.namespace} contains applications", get_extra_log_args)
|
|
155
|
+
@reply.resultIO << "Cannot remove namespace #{@req.namespace}. Remove existing app(s) first: "
|
|
156
|
+
@reply.resultIO << @cloud_user.applications.map{|a| a.name}.join("\n")
|
|
157
|
+
@reply.exitcode = 106
|
|
158
|
+
render :json => @reply, :status => :bad_request
|
|
159
|
+
return
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
@reply.append domain.delete
|
|
164
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_DELETE_DOMAIN", true, "Deleted domain #{@req.namespace}", get_extra_log_args)
|
|
165
|
+
render :json => @reply
|
|
166
|
+
return
|
|
167
|
+
else
|
|
168
|
+
raise OpenShift::UserException.new("The supplied namespace '#{@req.namespace}' is not allowed", 106) if OpenShift::ApplicationContainerProxy.blacklisted? @req.namespace
|
|
169
|
+
raise OpenShift::UserException.new("Domain already exists for user. Update the domain to modify.", 158) if !@cloud_user.domains.empty?
|
|
170
|
+
|
|
171
|
+
key = Key.new(Key::DEFAULT_SSH_KEY_NAME, @req.key_type, @req.ssh)
|
|
172
|
+
if key.invalid?
|
|
173
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_CREATE_DOMAIN", true, "Failed to create domain #{@req.namespace}: #{key.errors.first[1][:message]}", get_extra_log_args)
|
|
174
|
+
@reply.resultIO << key.errors.first[1][:message]
|
|
175
|
+
@reply.exitcode = key.errors.first[1][:exit_code]
|
|
176
|
+
render :json => @reply, :status => :bad_request
|
|
177
|
+
return
|
|
178
|
+
end
|
|
179
|
+
@cloud_user.add_ssh_key(Key::DEFAULT_SSH_KEY_NAME, @req.ssh, @req.key_type)
|
|
180
|
+
domain = Domain.new(@req.namespace, @cloud_user)
|
|
181
|
+
@reply.append domain.save
|
|
182
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_CREATE_DOMAIN", true, "Created domain #{@req.namespace}", get_extra_log_args)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
@reply.append @cloud_user.save
|
|
186
|
+
@reply.data = {
|
|
187
|
+
:rhlogin => @cloud_user.login,
|
|
188
|
+
:uuid => @cloud_user.uuid,
|
|
189
|
+
:rhc_domain => Rails.configuration.openshift[:domain_suffix]
|
|
190
|
+
}.to_json
|
|
191
|
+
|
|
192
|
+
render :json => @reply
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def cart_list_post
|
|
196
|
+
cart_type = @req.cart_type
|
|
197
|
+
unless cart_type
|
|
198
|
+
log_action('nil', 'nil', 'nil', "LEGACY_CART_LIST", true, "Cartridge type not specified", get_extra_log_args)
|
|
199
|
+
@reply.resultIO << "Invalid cartridge types: #{cart_type} specified"
|
|
200
|
+
@reply.exitcode = 109
|
|
201
|
+
render :json => @reply, :status => :bad_request
|
|
202
|
+
return
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
cache_key = "cart_list_#{cart_type}"
|
|
206
|
+
carts = get_cached(cache_key, :expires_in => 21600.seconds) {
|
|
207
|
+
Application.get_available_cartridges(cart_type)
|
|
208
|
+
}
|
|
209
|
+
log_action('nil', 'nil', 'nil', "LEGACY_CART_LIST")
|
|
210
|
+
@reply.data = { :carts => carts }.to_json
|
|
211
|
+
render :json => @reply
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def cartridge_post
|
|
215
|
+
raise OpenShift::UserException.new("Invalid user", 99) if @cloud_user.nil?
|
|
216
|
+
|
|
217
|
+
case @req.action
|
|
218
|
+
when 'configure' #create app and configure framework
|
|
219
|
+
apps = @cloud_user.applications
|
|
220
|
+
domain = @cloud_user.domains.first
|
|
221
|
+
app = Application.new(@cloud_user, @req.app_name, nil, @req.node_profile, @req.cartridge, nil, false, domain)
|
|
222
|
+
check_cartridge_type(@req.cartridge, "standalone")
|
|
223
|
+
if (@cloud_user.consumed_gears >= @cloud_user.max_gears)
|
|
224
|
+
raise OpenShift::UserException.new("#{@login} has already reached the gear limit of #{@cloud_user.max_gears}", 104)
|
|
225
|
+
end
|
|
226
|
+
raise OpenShift::UserException.new("The supplied application name '#{app.name}' is not allowed", 105) if OpenShift::ApplicationContainerProxy.blacklisted? app.name
|
|
227
|
+
if app.valid?
|
|
228
|
+
@domain_name = domain.namespace
|
|
229
|
+
@application_name = app.name
|
|
230
|
+
@application_uuid = app.uuid
|
|
231
|
+
begin
|
|
232
|
+
app.user_agent = request.headers["User-Agent"]
|
|
233
|
+
Rails.logger.debug "Creating application #{app.name}"
|
|
234
|
+
@reply.append app.create
|
|
235
|
+
Rails.logger.debug "Configuring dependencies #{app.name}"
|
|
236
|
+
@reply.append app.configure_dependencies
|
|
237
|
+
|
|
238
|
+
app.execute_connections
|
|
239
|
+
begin
|
|
240
|
+
@reply.append app.create_dns
|
|
241
|
+
|
|
242
|
+
case app.framework_cartridge
|
|
243
|
+
when 'php'
|
|
244
|
+
page = 'health_check.php'
|
|
245
|
+
when 'perl'
|
|
246
|
+
page = 'health_check.pl'
|
|
247
|
+
else
|
|
248
|
+
page = 'health'
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
@reply.data = {:health_check_path => page, :uuid => app.uuid}.to_json
|
|
252
|
+
rescue Exception => e
|
|
253
|
+
@reply.append app.destroy_dns
|
|
254
|
+
raise
|
|
255
|
+
end
|
|
256
|
+
rescue Exception => e
|
|
257
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_CREATE_APP", false, "Failed to create application #{app.name}: #{e.message}", get_extra_log_args)
|
|
258
|
+
@reply.append app.destroy(true)
|
|
259
|
+
if app.persisted?
|
|
260
|
+
app.delete
|
|
261
|
+
end
|
|
262
|
+
@reply.resultIO = StringIO.new(e.message)
|
|
263
|
+
raise
|
|
264
|
+
end
|
|
265
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_CREATE_APP", true, "Created application #{app.name}", get_extra_log_args)
|
|
266
|
+
@reply.resultIO << "Successfully created application: #{app.name}" if @reply.resultIO.length == 0
|
|
267
|
+
else
|
|
268
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_CREATE_APP", true, "Invalid application: #{app.errors.first[1][:message]}", get_extra_log_args)
|
|
269
|
+
@reply.resultIO << app.errors.first[1][:message]
|
|
270
|
+
@reply.exitcode = app.errors.first[1][:exit_code]
|
|
271
|
+
render :json => @reply, :status => :bad_request
|
|
272
|
+
return
|
|
273
|
+
end
|
|
274
|
+
when 'deconfigure'
|
|
275
|
+
app = get_app_from_request(@cloud_user)
|
|
276
|
+
@reply.append app.cleanup_and_delete
|
|
277
|
+
@reply.resultIO << "Successfully destroyed application: #{app.name}"
|
|
278
|
+
when 'start'
|
|
279
|
+
app = get_app_from_request(@cloud_user)
|
|
280
|
+
@reply.append app.start(app.framework)
|
|
281
|
+
when 'stop'
|
|
282
|
+
app = get_app_from_request(@cloud_user)
|
|
283
|
+
@reply.append app.stop(app.framework)
|
|
284
|
+
when 'restart'
|
|
285
|
+
app = get_app_from_request(@cloud_user)
|
|
286
|
+
@reply.append app.restart(app.framework)
|
|
287
|
+
when 'force-stop'
|
|
288
|
+
app = get_app_from_request(@cloud_user)
|
|
289
|
+
@reply.append app.force_stop(app.framework)
|
|
290
|
+
when 'reload'
|
|
291
|
+
app = get_app_from_request(@cloud_user)
|
|
292
|
+
@reply.append app.reload(app.framework)
|
|
293
|
+
when 'status'
|
|
294
|
+
app = get_app_from_request(@cloud_user)
|
|
295
|
+
@reply.append app.status(app.framework)
|
|
296
|
+
when 'tidy'
|
|
297
|
+
app = get_app_from_request(@cloud_user)
|
|
298
|
+
@reply.append app.tidy(app.framework)
|
|
299
|
+
when 'add-alias'
|
|
300
|
+
app = get_app_from_request(@cloud_user)
|
|
301
|
+
@reply.append app.add_alias @req.server_alias
|
|
302
|
+
when 'remove-alias'
|
|
303
|
+
app = get_app_from_request(@cloud_user)
|
|
304
|
+
@reply.append app.remove_alias @req.server_alias
|
|
305
|
+
when 'threaddump'
|
|
306
|
+
app = get_app_from_request(@cloud_user)
|
|
307
|
+
@reply.append app.threaddump(app.framework)
|
|
308
|
+
when 'expose-port'
|
|
309
|
+
app = get_app_from_request(@cloud_user)
|
|
310
|
+
@reply.append app.expose_port(app.framework)
|
|
311
|
+
when 'conceal-port'
|
|
312
|
+
app = get_app_from_request(@cloud_user)
|
|
313
|
+
@reply.append app.conceal_port(app.framework)
|
|
314
|
+
when 'show-port'
|
|
315
|
+
app = get_app_from_request(@cloud_user)
|
|
316
|
+
@reply.append app.show_port(app.framework)
|
|
317
|
+
when 'system-messages'
|
|
318
|
+
app = get_app_from_request(@cloud_user)
|
|
319
|
+
@reply.append app.system_messages
|
|
320
|
+
else
|
|
321
|
+
raise OpenShift::UserException.new("Invalid action #{@req.action}", 111)
|
|
322
|
+
end
|
|
323
|
+
@reply.resultIO << 'Success' if @reply.resultIO.length == 0
|
|
324
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_CARTRIDGE_POST", true, "Processed event #{@req.action} for application #{app.name}", get_extra_log_args)
|
|
325
|
+
|
|
326
|
+
render :json => @reply
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def embed_cartridge_post
|
|
330
|
+
raise OpenShift::UserException.new("Invalid user", 99) if @cloud_user.nil?
|
|
331
|
+
|
|
332
|
+
app = get_app_from_request(@cloud_user)
|
|
333
|
+
check_cartridge_type(@req.cartridge, "embedded")
|
|
334
|
+
|
|
335
|
+
# making this check here for the specific actions, so that the error codes for other conditions are not affected
|
|
336
|
+
if ['deconfigure', 'start', 'stop', 'restart', 'status', 'reload'].include?(@req.action) and ( app.embedded.nil? or not app.embedded.has_key?(@req.cartridge) )
|
|
337
|
+
raise OpenShift::UserException.new("The application #{app.name} is not configured with the embedded cartridge #{@req.cartridge}.", 129)
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
Rails.logger.debug "DEBUG: Performing action '#{@req.action}'"
|
|
341
|
+
case @req.action
|
|
342
|
+
when 'configure'
|
|
343
|
+
if app.scalable && (@cloud_user.consumed_gears >= @cloud_user.max_gears) && @req.cartridge != 'jenkins-client-1.4' #TODO Need a proper method to let us know if cart will get its own gear
|
|
344
|
+
raise OpenShift::UserException.new("#{@login} has already reached the gear limit of #{@cloud_user.max_gears}", 104)
|
|
345
|
+
end
|
|
346
|
+
@reply.append app.add_dependency(@req.cartridge)
|
|
347
|
+
when 'deconfigure'
|
|
348
|
+
@reply.append app.remove_dependency(@req.cartridge)
|
|
349
|
+
when 'start'
|
|
350
|
+
@reply.append app.start(@req.cartridge)
|
|
351
|
+
when 'stop'
|
|
352
|
+
@reply.append app.stop(@req.cartridge)
|
|
353
|
+
when 'restart'
|
|
354
|
+
@reply.append app.restart(@req.cartridge)
|
|
355
|
+
when 'status'
|
|
356
|
+
@reply.append app.status(@req.cartridge)
|
|
357
|
+
when 'reload'
|
|
358
|
+
@reply.append app.reload(@req.cartridge)
|
|
359
|
+
else
|
|
360
|
+
raise OpenShift::UserException.new("Invalid action #{@req.action}", 111)
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
log_action(@request_id, @cloud_user.uuid, @login, "LEGACY_EMBED_CARTRIDGE_POST", true, "Processed event #{@req.action} for cartridge #{@req.cartridge} of application #{app.name}", get_extra_log_args)
|
|
364
|
+
@reply.resultIO << 'Success' if @reply.resultIO.length == 0
|
|
365
|
+
render :json => @reply
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
protected
|
|
369
|
+
|
|
370
|
+
def process_notification
|
|
371
|
+
message = self.notifications if self.respond_to? "notifications"
|
|
372
|
+
@reply.messageIO << message unless message.nil?
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
# Raise an exception if cartridge type isn't supported
|
|
376
|
+
def check_cartridge_type(framework, cart_type)
|
|
377
|
+
carts = Application.get_available_cartridges(cart_type)
|
|
378
|
+
unless carts.include? framework
|
|
379
|
+
if cart_type == 'standalone'
|
|
380
|
+
raise OpenShift::UserException.new(110), "Invalid application type (-t|--type) specified: '#{framework}'. Valid application types are (#{carts.join(', ')})."
|
|
381
|
+
else
|
|
382
|
+
raise OpenShift::UserException.new(110), "Invalid type (-c|--cartridge) specified: '#{framework}'. Valid cartridge types are (#{carts.join(', ')})."
|
|
383
|
+
end
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
def get_app_from_request(user)
|
|
388
|
+
app = Application.find(user, @req.app_name)
|
|
389
|
+
raise OpenShift::UserException.new("An application named '#{@req.app_name}' does not exist", 101) if app.nil?
|
|
390
|
+
app.user_agent = request.headers["User-Agent"]
|
|
391
|
+
|
|
392
|
+
@application_name = app.name
|
|
393
|
+
@application_uuid = app.uuid
|
|
394
|
+
@domain_name = app.domain.namespace unless app.domain.nil?
|
|
395
|
+
|
|
396
|
+
return app
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
def validate_request
|
|
400
|
+
@reply = ResultIO.new
|
|
401
|
+
begin
|
|
402
|
+
@req = LegacyRequest.new.from_json(params['json_data'])
|
|
403
|
+
if @req.invalid?
|
|
404
|
+
log_action('nil','nil', 'nil', "LEGACY_BROKER", true, "Validation error: #{@req.errors.first[1][:message]}", get_extra_log_args)
|
|
405
|
+
@reply.resultIO << @req.errors.first[1][:message]
|
|
406
|
+
@reply.exitcode = @req.errors.first[1][:exit_code]
|
|
407
|
+
render :json => @reply, :status => :bad_request
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
def authenticate
|
|
413
|
+
@request_id = gen_req_uuid
|
|
414
|
+
begin
|
|
415
|
+
auth = OpenShift::AuthService.instance.login(request, params, cookies)
|
|
416
|
+
|
|
417
|
+
if auth
|
|
418
|
+
@login = auth[:username]
|
|
419
|
+
@auth_method = auth[:auth_method]
|
|
420
|
+
|
|
421
|
+
@cloud_user = CloudUser.find @login
|
|
422
|
+
if @cloud_user.nil?
|
|
423
|
+
Rails.logger.debug "Adding user #{@login}...inside legacy_controller"
|
|
424
|
+
@cloud_user = CloudUser.new(@login)
|
|
425
|
+
begin
|
|
426
|
+
@cloud_user.save
|
|
427
|
+
rescue Exception => e
|
|
428
|
+
cu = CloudUser.find @login
|
|
429
|
+
raise unless cu && (@cloud_user.parent_user_login == cu.parent_user_login)
|
|
430
|
+
@cloud_user = cu
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
@cloud_user.auth_method = @auth_method unless @cloud_user.nil?
|
|
434
|
+
end
|
|
435
|
+
unless @login
|
|
436
|
+
log_action('nil','nil', 'nil', "LEGACY_BROKER", true, "Authentication failed: Invalid user credentials", get_extra_log_args)
|
|
437
|
+
@reply.resultIO << "Invalid user credentials"
|
|
438
|
+
@reply.exitcode = 97
|
|
439
|
+
render :json => @reply, :status => :unauthorized
|
|
440
|
+
end
|
|
441
|
+
rescue OpenShift::AccessDeniedException
|
|
442
|
+
log_action('nil','nil', 'nil', "LEGACY_BROKER", true, "Authentication failed: Invalid user credentials", get_extra_log_args)
|
|
443
|
+
@reply.resultIO << "Invalid user credentials"
|
|
444
|
+
@reply.exitcode = 97
|
|
445
|
+
render :json => @reply, :status => :unauthorized
|
|
446
|
+
end
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
def exception_handler(e)
|
|
450
|
+
status = :internal_server_error
|
|
451
|
+
|
|
452
|
+
case e
|
|
453
|
+
when OpenShift::AuthServiceException
|
|
454
|
+
log_action(@request_id, 'nil', 'nil', "LEGACY_BROKER", false, "#{e.class.name} for #{request.path}: #{e.message}", get_extra_log_args)
|
|
455
|
+
Rails.logger.error e.backtrace[0..5].join("\n")
|
|
456
|
+
@reply.append e.resultIO if e.resultIO
|
|
457
|
+
@reply.resultIO << "An error occurred while contacting the authentication service. If the problem persists please contact Red Hat support." if @reply.resultIO.length == 0
|
|
458
|
+
when OpenShift::UserException
|
|
459
|
+
log_action(@request_id.nil? ? 'nil' : @request_id, @cloud_user.nil? ? 'nil' : @cloud_user.uuid, @login.nil? ? 'nil' : @login, "LEGACY_BROKER", true, "#{e.class.name} for #{request.path}: #{e.message}", get_extra_log_args)
|
|
460
|
+
@reply.resultIO << e.message
|
|
461
|
+
status = :bad_request
|
|
462
|
+
when OpenShift::DNSException
|
|
463
|
+
log_action(@request_id.nil? ? 'nil' : @request_id, @cloud_user.nil? ? 'nil' : @cloud_user.uuid, @login.nil? ? 'nil' : @login, "LEGACY_BROKER", false, "#{e.class.name} for #{request.path}: #{e.message}", get_extra_log_args)
|
|
464
|
+
@reply.resultIO << e.message
|
|
465
|
+
status = :service_unavailable
|
|
466
|
+
when OpenShift::OOException
|
|
467
|
+
log_action(@request_id.nil? ? 'nil' : @request_id, @cloud_user.nil? ? 'nil' : @cloud_user.uuid, @login.nil? ? 'nil' : @login, "LEGACY_BROKER", false, "#{e.class.name} for #{request.path}: #{e.message}", get_extra_log_args)
|
|
468
|
+
Rails.logger.error e.backtrace[0..5].join("\n")
|
|
469
|
+
Rails.logger.error e.resultIO
|
|
470
|
+
@reply.resultIO << e.message if @reply.resultIO.length == 0
|
|
471
|
+
@reply.append e.resultIO if e.resultIO
|
|
472
|
+
else
|
|
473
|
+
log_action(@request_id.nil? ? 'nil' : @request_id, @cloud_user.nil? ? 'nil' : @cloud_user.uuid, @login.nil? ? 'nil' : @login, "LEGACY_BROKER", false, "#{e.class.name} for #{request.path}: #{e.message}", get_extra_log_args)
|
|
474
|
+
Rails.logger.error e.backtrace
|
|
475
|
+
@reply.debugIO << e.message
|
|
476
|
+
@reply.debugIO << e.backtrace[0..5].join("\n")
|
|
477
|
+
@reply.resultIO << e.message if @reply.resultIO.length == 0
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
@reply.exitcode = e.respond_to?('code') ? e.code : 1
|
|
481
|
+
render :json => @reply, :status => status
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
def get_domain(cloud_user, id)
|
|
485
|
+
cloud_user.domains.each do |domain|
|
|
486
|
+
if domain.namespace == id
|
|
487
|
+
@domain_name = domain.namespace
|
|
488
|
+
return domain
|
|
489
|
+
end
|
|
490
|
+
end
|
|
491
|
+
return nil
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
def gen_req_uuid
|
|
495
|
+
# The request id can be generated differently to make it a bit more meaningful
|
|
496
|
+
File.open("/proc/sys/kernel/random/uuid", "r") do |file|
|
|
497
|
+
file.gets.strip.gsub("-","")
|
|
498
|
+
end
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
def get_extra_log_args
|
|
502
|
+
args = {}
|
|
503
|
+
args["APP"] = @application_name if @application_name
|
|
504
|
+
args["DOMAIN"] = @domain_name if @domain_name
|
|
505
|
+
args["APP_UUID"] = @application_uuid if @application_uuid
|
|
506
|
+
|
|
507
|
+
return args
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
end
|