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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
#
# SonarQube, open source software quality management tool.
# Copyright (C) 2008-2013 SonarSource
# mailto:contact AT sonarsource DOT com
#
# SonarQube is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# SonarQube is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
class Api::ServerController < Api::ApiController
skip_before_filter :check_authentication, :except => 'system'
# prevent HTTP proxies from caching server status
before_filter :set_cache_buster, :only => 'index'
# execute database setup
skip_before_filter :check_database_version, :setup
def key
render :text => Java::OrgSonarServerPlatform::Platform.getServer().getId()
end
def version
render :text => Java::OrgSonarServerPlatform::Platform.getServer().getVersion()
end
def index
hash={:id => Java::OrgSonarServerPlatform::Platform.getServer().getId(), :version => Java::OrgSonarServerPlatform::Platform.getServer().getVersion()}
complete_with_status(hash)
respond_to do |format|
format.json{ render :json => jsonp(hash) }
format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'server') }
format.text { render :text => text_not_supported}
end
end
def system
access_denied unless has_role?(:admin)
@server=Server.new
json=[
{:system_info => server_properties_to_json(@server.system_info)},
{:system_statistics => server_properties_to_json(@server.system_statistics)},
{:sonar_info => server_properties_to_json(@server.sonar_info)},
{:sonar_plugins => server_properties_to_json(@server.sonar_plugins)},
{:system_properties => server_properties_to_json(@server.system_properties)},
]
respond_to do |format|
format.json{ render :json => jsonp(json) }
format.xml { render :xml => xml_not_supported }
format.text { render :text => text_not_supported}
end
end
def setup
verify_post_request
manager=DatabaseMigrationManager.instance
begin
# Ask the DB migration manager to start the migration
# => No need to check for authorizations (actually everybody can run the upgrade)
# nor concurrent calls (this is handled directly by DatabaseMigrationManager)
manager.start_migration
operational=manager.is_sonar_access_allowed?
current_status = operational ? "ok" : "ko"
hash={
# deprecated fields
:status => current_status,
:migration_status => manager.status,
# correct fields
:operational => operational,
:state => manager.status
}
hash[:message]=manager.message if manager.message
hash[:startedAt]=manager.migration_start_time if manager.migration_start_time
respond_to do |format|
format.json{ render :json => jsonp(hash) }
format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'setup') }
format.text { render :text => hash[:status] }
end
rescue => e
hash={
# deprecated fields
:status => 'ko',
:msg => e.message,
# correct fields
:message => e.message,
:state => manager.status
}
respond_to do |format|
format.json{ render :json => jsonp(hash) }
format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'setup') }
format.text { render :text => hash[:status] }
end
end
end
def index_projects
verify_post_request
access_denied unless has_role?(:admin)
logger.info 'Indexing projects'
Java::OrgSonarServerUi::JRubyFacade.getInstance().indexProjects()
render_success('Projects indexed')
end
private
def server_properties_to_json(properties)
hash={}
properties.each do |prop|
hash[prop[0].to_s]=prop[1].to_s
end
hash
end
def complete_with_status(hash)
if DatabaseMigrationManager.instance.is_sonar_access_allowed?
hash[:status]='UP'
elsif DatabaseMigrationManager.instance.migration_running?
hash[:status]='MIGRATION_RUNNING'
elsif DatabaseMigrationManager.instance.requires_migration?
hash[:status]='SETUP'
else
# migration failed or not connected to the database
hash[:status]='DOWN'
hash[:status_msg]=DatabaseMigrationManager.instance.message
end
end
def set_cache_buster
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
end
|