openshift-origin-controller 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of openshift-origin-controller might be problematic. Click here for more details.
- 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,48 @@
|
|
1
|
+
class CartridgesController < BaseController
|
2
|
+
respond_to :xml, :json
|
3
|
+
before_filter :check_version
|
4
|
+
include LegacyBrokerHelper
|
5
|
+
|
6
|
+
def show
|
7
|
+
index
|
8
|
+
end
|
9
|
+
|
10
|
+
# GET /cartridges
|
11
|
+
def index
|
12
|
+
type = params[:id]
|
13
|
+
|
14
|
+
cartridges = Array.new
|
15
|
+
if type.nil? or type == "standalone"
|
16
|
+
cart_type = "standalone"
|
17
|
+
cache_key = "cart_list_#{cart_type}"
|
18
|
+
carts = get_cached(cache_key, :expires_in => 21600.seconds) do
|
19
|
+
Application.get_available_cartridges(cart_type)
|
20
|
+
end
|
21
|
+
carts.each do |cart|
|
22
|
+
if $requested_api_version >= 1.1
|
23
|
+
cartridge = RestCartridge11.new(cart_type, cart, nil, get_url, nil, nolinks)
|
24
|
+
else
|
25
|
+
cartridge = RestCartridge10.new(cart_type, cart, nil, get_url, nil, nolinks)
|
26
|
+
end
|
27
|
+
cartridges.push(cartridge)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if type.nil? or type == "embedded"
|
32
|
+
cart_type = "embedded"
|
33
|
+
cache_key = "cart_list_#{cart_type}"
|
34
|
+
carts = get_cached(cache_key, :expires_in => 21600.seconds) do
|
35
|
+
Application.get_available_cartridges(cart_type)
|
36
|
+
end
|
37
|
+
carts.each do |cart|
|
38
|
+
if $requested_api_version >= 1.1
|
39
|
+
cartridge = RestCartridge11.new(cart_type, cart, nil, get_url, nil, nolinks)
|
40
|
+
else
|
41
|
+
cartridge = RestCartridge10.new(cart_type, cart, nil, get_url, nil, nolinks)
|
42
|
+
end
|
43
|
+
cartridges.push(cartridge)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
render_success(:ok, "cartridges", cartridges, "LIST_CARTRIDGES", "List #{type.nil? ? 'all' : type} cartridges")
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class DescriptorsController < BaseController
|
2
|
+
respond_to :xml, :json
|
3
|
+
before_filter :authenticate, :check_version
|
4
|
+
|
5
|
+
def show
|
6
|
+
domain_id = params[:domain_id]
|
7
|
+
application_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
|
+
"SHOW_DESCRIPTOR") if !domain || !domain.hasAccess?(@cloud_user)
|
12
|
+
|
13
|
+
@domain_name = domain.namespace
|
14
|
+
application = Application.find(@cloud_user,application_id)
|
15
|
+
return render_error(:not_found, "Application '#{application_id}' not found for domain '#{domain_id}'",
|
16
|
+
101, "SHOW_DESCRIPTOR") unless application
|
17
|
+
|
18
|
+
@application_name = application.name
|
19
|
+
@application_uuid = application.uuid
|
20
|
+
render_success(:ok, "descriptor", application.to_descriptor.to_yaml, "SHOW_DESCRIPTOR",
|
21
|
+
"Show descriptor for application '#{application_id}' for domain '#{domain_id}'")
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'dnsruby'
|
3
|
+
|
4
|
+
class DnsResolvableController < BaseController
|
5
|
+
respond_to :xml, :json
|
6
|
+
before_filter :authenticate, :check_version
|
7
|
+
|
8
|
+
# GET /domains/[domain_id]/applications/<id>/dns_resolvable
|
9
|
+
def show
|
10
|
+
domain_id = params[:domain_id]
|
11
|
+
id = params[:application_id]
|
12
|
+
|
13
|
+
domain = Domain.get(@cloud_user, domain_id)
|
14
|
+
return render_error(:not_found, "Domain #{domain_id} not found", 127,
|
15
|
+
"DNS_RESOLVABLE") if !domain || !domain.hasAccess?(@cloud_user)
|
16
|
+
|
17
|
+
@domain_name = domain.namespace
|
18
|
+
application = Application.find(@cloud_user,id)
|
19
|
+
return render_error(:not_found, "Application '#{id}' not found", 101,
|
20
|
+
"DNS_RESOLVABLE") unless application
|
21
|
+
|
22
|
+
@application_name = application.name
|
23
|
+
@application_uuid = application.uuid
|
24
|
+
name = "#{application.name}-#{application.domain.namespace}.#{Rails.configuration.openshift[:domain_suffix]}"
|
25
|
+
nameservers = NameServerCache.get_name_servers
|
26
|
+
|
27
|
+
dns = Dnsruby::Resolver.new(:nameserver => nameservers[rand(nameservers.length)])
|
28
|
+
begin
|
29
|
+
dns.query(name, Dnsruby::Types.A)
|
30
|
+
render_success(:ok, "boolean", true, "DNS_RESOLVABLE", "Resolved DNS #{name}")
|
31
|
+
rescue
|
32
|
+
render_error(:not_found, "Could not resolve DNS #{name}", 170, "DNS_RESOLVABLE")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
class DomainsController < BaseController
|
2
|
+
respond_to :xml, :json
|
3
|
+
before_filter :authenticate, :check_version
|
4
|
+
|
5
|
+
# GET /domains
|
6
|
+
def index
|
7
|
+
domains = Array.new
|
8
|
+
Rails.logger.debug "Getting domains for user #{@cloud_user.login}"
|
9
|
+
Rails.logger.debug @cloud_user.domains
|
10
|
+
@cloud_user.domains.each do |domain|
|
11
|
+
if $requested_api_version >= 1.3
|
12
|
+
domains.push(RestDomain.new(domain, get_url, nolinks))
|
13
|
+
else
|
14
|
+
domains.push(RestDomain10.new(domain, get_url, nolinks))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
render_success(:ok, "domains", domains, "LIST_DOMAINS")
|
18
|
+
end
|
19
|
+
|
20
|
+
# GET /domains/<id>
|
21
|
+
def show
|
22
|
+
id = params[:id]
|
23
|
+
Rails.logger.debug "Getting domain #{id}"
|
24
|
+
|
25
|
+
domain = Domain.get(@cloud_user, id)
|
26
|
+
if domain and domain.hasAccess?(@cloud_user)
|
27
|
+
@domain_name = domain.namespace
|
28
|
+
if $requested_api_version >= 1.3
|
29
|
+
domain = RestDomain.new(domain, get_url, nolinks)
|
30
|
+
else
|
31
|
+
domain = RestDomain10.new(domain, get_url, nolinks)
|
32
|
+
end
|
33
|
+
return render_success(:ok, "domain", domain, "SHOW_DOMAIN", "Found domain #{id}")
|
34
|
+
end
|
35
|
+
render_error(:not_found, "Domain #{id} not found.", 127, "SHOW_DOMAIN")
|
36
|
+
end
|
37
|
+
|
38
|
+
# POST /domains
|
39
|
+
def create
|
40
|
+
namespace = params[:id]
|
41
|
+
Rails.logger.debug "Creating domain with namespace #{namespace}"
|
42
|
+
|
43
|
+
domain = Domain.new(namespace, @cloud_user)
|
44
|
+
if not domain.valid?
|
45
|
+
Rails.logger.error "Domain is not valid"
|
46
|
+
messages = get_error_messages(domain, "namespace", "id")
|
47
|
+
return render_error(:unprocessable_entity, nil, nil, "ADD_DOMAIN", nil, nil, messages)
|
48
|
+
end
|
49
|
+
|
50
|
+
begin
|
51
|
+
dom_available = Domain.namespace_available?(namespace)
|
52
|
+
rescue Exception => e
|
53
|
+
return render_exception(e, "ADD_DOMAIN")
|
54
|
+
end
|
55
|
+
|
56
|
+
return render_error(:unprocessable_entity, "Namespace '#{namespace}' is already in use. Please choose another.", 103, "ADD_DOMAIN", "id") if !dom_available
|
57
|
+
|
58
|
+
return render_error(:conflict, "Domain already exists for user. Update the domain to modify.", 158, "ADD_DOMAIN") if !@cloud_user.domains.empty?
|
59
|
+
|
60
|
+
@domain_name = namespace
|
61
|
+
begin
|
62
|
+
domain.save
|
63
|
+
rescue Exception => e
|
64
|
+
return render_exception(e, "ADD_DOMAIN")
|
65
|
+
end
|
66
|
+
|
67
|
+
if $requested_api_version >= 1.3
|
68
|
+
domain = RestDomain.new(domain, get_url, nolinks)
|
69
|
+
else
|
70
|
+
domain = RestDomain10.new(domain, get_url, nolinks)
|
71
|
+
end
|
72
|
+
render_success(:created, "domain", domain, "ADD_DOMAIN", "Created domain with namespace #{namespace}", true)
|
73
|
+
end
|
74
|
+
|
75
|
+
# PUT /domains/<existing_id>
|
76
|
+
def update
|
77
|
+
id = params[:existing_id]
|
78
|
+
new_namespace = params[:id]
|
79
|
+
domain = Domain.get(@cloud_user, id)
|
80
|
+
|
81
|
+
new_domain = Domain.new(new_namespace, @cloud_user)
|
82
|
+
if not new_domain.valid?
|
83
|
+
messages = get_error_messages(new_domain, "namespace", "id")
|
84
|
+
return render_format_error(:unprocessable_entity, nil, nil, "UPDATE_DOMAIN", nil, nil, messages)
|
85
|
+
end
|
86
|
+
return render_format_error(:not_found, "Domain '#{id}' not found", 127,
|
87
|
+
"UPDATE_DOMAIN") if !domain || !domain.hasAccess?(@cloud_user)
|
88
|
+
|
89
|
+
return render_format_error(:forbidden, "User does not have permission to modify domain '#{id}'",
|
90
|
+
132, "UPDATE_DOMAIN") if domain && !domain.hasFullAccess?(@cloud_user)
|
91
|
+
|
92
|
+
Rails.logger.debug "Updating domain #{domain.namespace} to #{new_namespace}"
|
93
|
+
begin
|
94
|
+
dom_available = Domain.namespace_available?(new_namespace)
|
95
|
+
rescue Exception => e
|
96
|
+
return render_format_exception(e, "UPDATE_DOMAIN")
|
97
|
+
end
|
98
|
+
|
99
|
+
return render_format_error(:unprocessable_entity, "Namespace '#{new_namespace}' already in use. Please choose another.",
|
100
|
+
103, "UPDATE_DOMAIN", "id") if !dom_available
|
101
|
+
|
102
|
+
domain.namespace = new_namespace
|
103
|
+
if domain.invalid?
|
104
|
+
messages = get_error_messages(domain, "namespace", "id")
|
105
|
+
return render_format_error(:unprocessable_entity, nil, nil, "UPDATE_DOMAIN", nil, nil, messages)
|
106
|
+
end
|
107
|
+
|
108
|
+
@domain_name = id
|
109
|
+
begin
|
110
|
+
domain.save
|
111
|
+
rescue Exception => e
|
112
|
+
return render_format_exception(e, "UPDATE_DOMAIN")
|
113
|
+
end
|
114
|
+
|
115
|
+
@cloud_user = CloudUser.find(@login)
|
116
|
+
if $requested_api_version >= 1.3
|
117
|
+
domain = RestDomain.new(domain, get_url, nolinks)
|
118
|
+
else
|
119
|
+
domain = RestDomain10.new(domain, get_url, nolinks)
|
120
|
+
end
|
121
|
+
render_format_success(:ok, "domain", domain, "UPDATE_DOMAIN", "Updated domain #{id} to #{new_namespace}")
|
122
|
+
end
|
123
|
+
|
124
|
+
# DELETE /domains/<id>
|
125
|
+
def destroy
|
126
|
+
id = params[:id]
|
127
|
+
force = get_bool(params[:force])
|
128
|
+
|
129
|
+
domain = Domain.get(@cloud_user, id)
|
130
|
+
return render_format_error(:not_found, "Domain #{id} not found", 127,
|
131
|
+
"DELETE_DOMAIN") if !domain || !domain.hasAccess?(@cloud_user)
|
132
|
+
|
133
|
+
return render_format_error(:forbidden, "User does not have permission to delete domain '#{id}'",
|
134
|
+
132, "DELETE_DOMAIN") if domain && !domain.hasFullAccess?(@cloud_user)
|
135
|
+
|
136
|
+
if force
|
137
|
+
Rails.logger.debug "Force deleting domain #{id}"
|
138
|
+
@cloud_user.applications.each do |app|
|
139
|
+
app.cleanup_and_delete if app.domain.uuid == domain.uuid
|
140
|
+
end if @cloud_user.applications
|
141
|
+
else
|
142
|
+
@cloud_user.applications.each do |app|
|
143
|
+
return render_format_error(:bad_request, "Domain contains applications. Delete applications first or set force to true.",
|
144
|
+
128, "DELETE_DOMAIN") if app.domain.uuid == domain.uuid
|
145
|
+
end if @cloud_user.applications
|
146
|
+
end
|
147
|
+
|
148
|
+
@domain_name = id
|
149
|
+
begin
|
150
|
+
domain.delete
|
151
|
+
render_format_success(:no_content, nil, nil, "DELETE_DOMAIN", "Domain #{id} deleted.", true)
|
152
|
+
rescue Exception => e
|
153
|
+
return render_format_exception(e, "DELETE_DOMAIN")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,276 @@
|
|
1
|
+
class EmbCartController < BaseController
|
2
|
+
respond_to :xml, :json
|
3
|
+
before_filter :authenticate, :check_version
|
4
|
+
include LegacyBrokerHelper
|
5
|
+
include CartridgeHelper
|
6
|
+
|
7
|
+
# GET /domains/[domain_id]/applications/[application_id]/cartridges
|
8
|
+
def index
|
9
|
+
domain_id = params[:domain_id]
|
10
|
+
id = params[:application_id]
|
11
|
+
|
12
|
+
domain = Domain.get(@cloud_user, domain_id)
|
13
|
+
return render_error(:not_found, "Domain #{domain_id} not found", 127,
|
14
|
+
"LIST_APP_CARTRIDGES") if !domain || !domain.hasAccess?(@cloud_user)
|
15
|
+
|
16
|
+
@domain_name = domain.namespace
|
17
|
+
|
18
|
+
Rails.logger.debug "Getting cartridges for application #{id} under domain #{domain_id}"
|
19
|
+
application = get_application(id)
|
20
|
+
return render_error(:not_found, "Application '#{id}' not found for domain '#{domain_id}'",
|
21
|
+
101, "LIST_APP_CARTRIDGES") unless application
|
22
|
+
#used for user action log
|
23
|
+
@application_name = application.name
|
24
|
+
@application_uuid = application.uuid
|
25
|
+
|
26
|
+
cartridges = get_cartridges(application)
|
27
|
+
|
28
|
+
render_success(:ok, "cartridges", cartridges, "LIST_APP_CARTRIDGES",
|
29
|
+
"Listing cartridges for application #{id} under domain #{domain_id}")
|
30
|
+
end
|
31
|
+
|
32
|
+
# GET /domains/[domain_id]/applications/[application_id]/cartridges/[id]
|
33
|
+
def show
|
34
|
+
domain_id = params[:domain_id]
|
35
|
+
application_id = params[:application_id]
|
36
|
+
id = params[:id]
|
37
|
+
#include=status_messages
|
38
|
+
status_messages = (params[:include] == "status_messages")
|
39
|
+
|
40
|
+
domain = Domain.get(@cloud_user, domain_id)
|
41
|
+
return render_error(:not_found, "Domain #{domain_id} not found", 127,
|
42
|
+
"SHOW_APP_CARTRIDGE") if !domain || !domain.hasAccess?(@cloud_user)
|
43
|
+
#used for user action log
|
44
|
+
@domain_name = domain.namespace
|
45
|
+
Rails.logger.debug "Getting cartridge #{id} for application #{application_id} under domain #{domain_id}"
|
46
|
+
application = get_application(application_id)
|
47
|
+
return render_error(:not_found, "Application '#{application_id}' not found for domain '#{domain_id}'",
|
48
|
+
101, "SHOW_APP_CARTRIDGE") if !application
|
49
|
+
|
50
|
+
@application_name = application.name
|
51
|
+
@application_uuid = application.uuid
|
52
|
+
cartridge = nil
|
53
|
+
application.embedded.each do |key, value|
|
54
|
+
if key == id
|
55
|
+
app_status = application.status(key, false) if status_messages
|
56
|
+
if $requested_api_version == 1.0
|
57
|
+
cartridge = RestCartridge10.new("embedded", key, application, get_url, app_status, nolinks)
|
58
|
+
else
|
59
|
+
cartridge = RestCartridge11.new("embedded", key, application, get_url, app_status, nolinks)
|
60
|
+
end
|
61
|
+
break
|
62
|
+
end
|
63
|
+
end if application.embedded
|
64
|
+
|
65
|
+
if !cartridge and id == application.framework and $requested_api_version != 1.0
|
66
|
+
app_status = application.status(application.framework, false) if status_messages
|
67
|
+
app_status.each do |gear_status|
|
68
|
+
#FIXME: work around until cartridge status hook provides better interface
|
69
|
+
message = "#{application.framework} is started."
|
70
|
+
message = "#{application.framework} is stopped or inaccessible." if gear_status['message'].match(/(stopped)|(inaccessible)/)
|
71
|
+
gear_status['message'] = message
|
72
|
+
end if app_status
|
73
|
+
cartridge = RestCartridge11.new("standalone", application.framework, application, get_url, app_status, nolinks)
|
74
|
+
end
|
75
|
+
return render_success(:ok, "cartridge", cartridge, "SHOW_APP_CARTRIDGE",
|
76
|
+
"Showing cartridge #{id} for application #{application_id} under domain #{domain_id}") if cartridge
|
77
|
+
|
78
|
+
render_error(:not_found, "Cartridge #{id} not found for application #{application_id}",
|
79
|
+
129, "SHOW_APP_CARTRIDGE")
|
80
|
+
end
|
81
|
+
|
82
|
+
# POST /domains/[domain_id]/applications/[application_id]/cartridges
|
83
|
+
def create
|
84
|
+
domain_id = params[:domain_id]
|
85
|
+
id = params[:application_id]
|
86
|
+
|
87
|
+
name = params[:name]
|
88
|
+
# :cartridge param is deprecated because it isn't consistent with
|
89
|
+
# the rest of the apis which take :name. Leave it here because
|
90
|
+
# some tools may still use it
|
91
|
+
name = params[:cartridge] unless name
|
92
|
+
colocate_with = params[:colocate_with]
|
93
|
+
|
94
|
+
domain = Domain.get(@cloud_user, domain_id)
|
95
|
+
return render_error(:not_found, "Domain #{domain_id} not found", 127,
|
96
|
+
"EMBED_CARTRIDGE") if !domain || !domain.hasAccess?(@cloud_user)
|
97
|
+
|
98
|
+
@domain_name = domain.namespace
|
99
|
+
application = get_application(id)
|
100
|
+
return render_error(:not_found, "Application '#{id}' not found for domain '#{domain_id}'",
|
101
|
+
101, "EMBED_CARTRIDGE") unless application
|
102
|
+
|
103
|
+
@application_name = application.name
|
104
|
+
@application_uuid = application.uuid
|
105
|
+
begin
|
106
|
+
#container = OpenShift::ApplicationContainerProxy.find_available(application.server_identity)
|
107
|
+
container = OpenShift::ApplicationContainerProxy.find_available(nil)
|
108
|
+
if not check_cartridge_type(name, container, "embedded")
|
109
|
+
carts = get_cached("cart_list_embedded", :expires_in => 21600.seconds) {
|
110
|
+
Application.get_available_cartridges("embedded")}
|
111
|
+
return render_error(:bad_request, "Invalid cartridge. Valid values are (#{carts.join(', ')})",
|
112
|
+
109, "EMBED_CARTRIDGE", "cartridge")
|
113
|
+
end
|
114
|
+
rescue Exception => e
|
115
|
+
return render_exception(e, "EMBED_CARTRIDGE")
|
116
|
+
end
|
117
|
+
|
118
|
+
#TODO: Need a proper method to let us know if cart will get its own gear
|
119
|
+
if application.scalable && colocate_with.nil? && (@cloud_user.consumed_gears >= @cloud_user.max_gears) && name != 'jenkins-client-1.4'
|
120
|
+
return render_error(:unprocessable_entity, "#{@cloud_user.login} has already reached the gear limit of #{@cloud_user.max_gears}",
|
121
|
+
104, "EMBED_CARTRIDGE")
|
122
|
+
end
|
123
|
+
|
124
|
+
cart_create_reply = ""
|
125
|
+
begin
|
126
|
+
application.add_group_override(name, colocate_with) if colocate_with
|
127
|
+
cart_create_reply = application.add_dependency(name)
|
128
|
+
rescue Exception => e
|
129
|
+
return render_exception(e, "EMBED_CARTRIDGE")
|
130
|
+
end
|
131
|
+
|
132
|
+
application = get_application(id)
|
133
|
+
|
134
|
+
application.embedded.each do |key, value|
|
135
|
+
if key == name
|
136
|
+
if $requested_api_version == 1.0
|
137
|
+
cartridge = RestCartridge10.new("embedded", key, application, get_url, nil, nolinks)
|
138
|
+
else
|
139
|
+
cartridge = RestCartridge11.new("embedded", key, application, get_url, nil, nolinks)
|
140
|
+
end
|
141
|
+
messages = []
|
142
|
+
log_msg = "Added #{name} to application #{id}"
|
143
|
+
messages.push(Message.new(:info, log_msg))
|
144
|
+
messages.push(Message.new(:info, cart_create_reply.resultIO.string, 0, :result))
|
145
|
+
messages.push(Message.new(:info, cart_create_reply.appInfoIO.string, 0, :appinfo))
|
146
|
+
return render_success(:created, "cartridge", cartridge, "EMBED_CARTRIDGE", log_msg, nil, nil, messages)
|
147
|
+
|
148
|
+
end
|
149
|
+
end if application.embedded
|
150
|
+
render_error(:internal_server_error, "Cartridge #{name} not embedded within application #{id}", nil, "EMBED_CARTRIDGE")
|
151
|
+
end
|
152
|
+
|
153
|
+
# DELETE /domains/[domain_id]/applications/[application_id]/cartridges/[id]
|
154
|
+
def destroy
|
155
|
+
domain_id = params[:domain_id]
|
156
|
+
id = params[:application_id]
|
157
|
+
cartridge = params[:id]
|
158
|
+
|
159
|
+
domain = Domain.get(@cloud_user, domain_id)
|
160
|
+
return render_format_error(:not_found, "Domain #{domain_id} not found", 127,
|
161
|
+
"REMOVE_CARTRIDGE") if !domain || !domain.hasAccess?(@cloud_user)
|
162
|
+
|
163
|
+
@domain_name = domain.namespace
|
164
|
+
application = get_application(id)
|
165
|
+
return render_format_error(:not_found, "Application '#{id}' not found for domain '#{domain_id}'",
|
166
|
+
101, "REMOVE_CARTRIDGE") unless application
|
167
|
+
|
168
|
+
@application_name = application.name
|
169
|
+
@application_uuid = application.uuid
|
170
|
+
return render_format_error(:bad_request, "Cartridge #{cartridge} not embedded within application #{id}",
|
171
|
+
129, "REMOVE_CARTRIDGE") if !application.embedded or !application.embedded.has_key?(cartridge)
|
172
|
+
|
173
|
+
begin
|
174
|
+
Rails.logger.debug "Removing #{cartridge} from application #{id}"
|
175
|
+
application.remove_dependency(cartridge)
|
176
|
+
rescue Exception => e
|
177
|
+
return render_format_exception(e, "REMOVE_CARTRIDGE")
|
178
|
+
end
|
179
|
+
|
180
|
+
application = get_application(id)
|
181
|
+
if $requested_api_version == 1.0
|
182
|
+
app = RestApplication10.new(application, get_url, nolinks)
|
183
|
+
else
|
184
|
+
app = RestApplication12.new(application, get_url, nolinks)
|
185
|
+
end
|
186
|
+
render_format_success(:ok, "application", app, "REMOVE_CARTRIDGE", "Removed #{cartridge} from application #{id}", true)
|
187
|
+
end
|
188
|
+
|
189
|
+
# UPDATE /domains/[domain_id]/applications/[application_id]/cartridges/[id]
|
190
|
+
def update
|
191
|
+
domain_id = params[:domain_id]
|
192
|
+
app_id = params[:application_id]
|
193
|
+
cartridge_name = params[:id]
|
194
|
+
additional_storage = params[:additional_gear_storage]
|
195
|
+
scales_from = params[:scales_from]
|
196
|
+
scales_to = params[:scales_to]
|
197
|
+
|
198
|
+
domain = Domain.get(@cloud_user, domain_id)
|
199
|
+
return render_format_error(:not_found, "Domain #{domain_id} not found", 127,
|
200
|
+
"UPDATE_CARTRIDGE") if !domain || !domain.hasAccess?(@cloud_user)
|
201
|
+
|
202
|
+
@domain_name = domain.namespace
|
203
|
+
application = get_application(app_id)
|
204
|
+
return render_format_error(:not_found, "Application '#{app_id}' not found for domain '#{domain_id}'",
|
205
|
+
101, "UPDATE_CARTRIDGE") unless application
|
206
|
+
#used for user action log
|
207
|
+
@application_name = application.name
|
208
|
+
@application_uuid = application.uuid
|
209
|
+
return render_format_error(:bad_request, "Cartridge #{cartridge_name} for application #{app_id} not found",
|
210
|
+
129, "UPDATE_CARTRIDGE") if ((!application.embedded or !application.embedded.has_key?(cartridge_name)) and application.framework!=cartridge_name)
|
211
|
+
|
212
|
+
storage_map = {}
|
213
|
+
application.comp_instance_map.values.each do |cinst|
|
214
|
+
if cinst.parent_cart_name==cartridge_name
|
215
|
+
group_name = cinst.group_instance_name
|
216
|
+
storage_map[group_name] = [] unless storage_map.has_key?(group_name)
|
217
|
+
storage_map[group_name] << cinst
|
218
|
+
end
|
219
|
+
end
|
220
|
+
return render_format_error(:not_found, "Cartridge '#{cartridge_name}' for application '#{app_id}' not found",
|
221
|
+
129, "UPDATE_CARTRIDGE") unless storage_map.keys.length>0
|
222
|
+
|
223
|
+
#only update attributes that are specified
|
224
|
+
if additional_storage and additional_storage!=0
|
225
|
+
max_storage = @cloud_user.capabilities['max_storage_per_gear']
|
226
|
+
return render_format_error(:forbidden, "User is not allowed to change storage quota", 164,
|
227
|
+
"UPDATE_CARTRIDGE") unless max_storage
|
228
|
+
num_storage = nil
|
229
|
+
begin
|
230
|
+
num_storage = Integer(additional_storage)
|
231
|
+
rescue => e
|
232
|
+
return render_format_error(:unprocessable_entity, "Invalid storage value provided.", 165, "UPDATE_CARTRIDGE", "additional_gear_storage")
|
233
|
+
end
|
234
|
+
begin
|
235
|
+
# first check against max_storage limit
|
236
|
+
storage_map.each do |group_name, component_instance_list|
|
237
|
+
ginst = application.group_instance_map[group_name]
|
238
|
+
current_sum = 0
|
239
|
+
component_instance_list.each { |cinst| current_sum += cinst.addtl_fs_gb }
|
240
|
+
current_sum = ginst.addtl_fs_gb-current_sum
|
241
|
+
current_sum += ginst.get_cached_min_storage_in_gb
|
242
|
+
current_sum += num_storage
|
243
|
+
return render_format_error(:forbidden, "Total additional storage for all cartridges on gear should be less than max_storage_per_gear (new_storage: #{current_sum}, max: #{max_storage}).", 166, "UPDATE_CARTRIDGE", "additional_gear_storage") if current_sum>max_storage
|
244
|
+
end
|
245
|
+
# now actually change the quota
|
246
|
+
storage_map.each do |group_name, component_instance_list|
|
247
|
+
each_component_share = (Float(num_storage))/component_instance_list.length
|
248
|
+
ginst = application.group_instance_map[group_name]
|
249
|
+
component_instance_list.each { |cinst| cinst.set_additional_quota(application, each_component_share) }
|
250
|
+
end
|
251
|
+
application.save
|
252
|
+
rescue Exception => e
|
253
|
+
return render_format_exception(e, "UPDATE_CARTRIDGE")
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
if scales_from or scales_to
|
258
|
+
begin
|
259
|
+
application.set_user_min_max(storage_map, scales_from, scales_to)
|
260
|
+
rescue OpenShift::UserException=>e
|
261
|
+
return render_format_error(:unprocessable_entity, e.message, 168,
|
262
|
+
"UPDATE_CARTRIDGE")
|
263
|
+
rescue Exception=>e
|
264
|
+
return render_format_error(:forbidden, e.message, 164,
|
265
|
+
"UPDATE_CARTRIDGE")
|
266
|
+
end
|
267
|
+
end
|
268
|
+
cart_type = cartridge_name==application.framework ? "standalone" : "embedded"
|
269
|
+
if $requested_api_version == 1.0
|
270
|
+
cartridge = RestCartridge10.new(cart_type, cartridge_name, application, get_url, nil, nolinks)
|
271
|
+
else
|
272
|
+
cartridge = RestCartridge11.new(cart_type, cartridge_name, application, get_url, nil, nolinks)
|
273
|
+
end
|
274
|
+
render_format_success(:ok, "cartridge", cartridge, "UPDATE_CARTRIDGE", "Updated #{cartridge_name} from application #{app_id}", true)
|
275
|
+
end
|
276
|
+
end
|