aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-09-11 18:39:27 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-09-11 18:39:27 +0200
commit0d57ce7853c35d7b6c502bd4b1c3284dafc41371 (patch)
tree049eba39c22f35a6deb5e9eca06dacc980ae3ca2 /sonar-server/src/main
parent77b9a13434344be895a495fcf0eabe77edf10baf (diff)
downloadsonarqube-0d57ce7853c35d7b6c502bd4b1c3284dafc41371.tar.gz
sonarqube-0d57ce7853c35d7b6c502bd4b1c3284dafc41371.zip
SONAR-2603 provide a dedicated page to generate server id
Diffstat (limited to 'sonar-server/src/main')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java2
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ServerIdGenerator.java (renamed from sonar-server/src/main/java/org/sonar/server/platform/ServerKeyGenerator.java)26
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java6
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java11
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/server_id_configuration_controller.rb (renamed from sonar-server/src/main/webapp/WEB-INF/app/controllers/server_key_configuration_controller.rb)37
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/server_id_configuration/index.html.erb60
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/server_key_configuration/index.html.erb58
8 files changed, 104 insertions, 98 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index 7eb85ce851a..c733a991588 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -144,7 +144,7 @@ public final class Platform {
coreContainer.as(Characteristics.CACHE).addComponent(UpdateCenterClient.class);
coreContainer.as(Characteristics.CACHE).addComponent(UpdateCenterMatrixFactory.class);
coreContainer.as(Characteristics.CACHE).addComponent(PluginDownloader.class);
- coreContainer.as(Characteristics.CACHE).addComponent(ServerKeyGenerator.class);
+ coreContainer.as(Characteristics.CACHE).addComponent(ServerIdGenerator.class);
coreContainer.as(Characteristics.CACHE).addComponent(ServerImpl.class);
coreContainer.as(Characteristics.NO_CACHE).addComponent(FilterExecutor.class);
coreContainer.as(Characteristics.NO_CACHE).addAdapter(new DatabaseSessionProvider());
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerKeyGenerator.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerIdGenerator.java
index 0a29e0eb876..3577effe7e6 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/ServerKeyGenerator.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerIdGenerator.java
@@ -35,7 +35,7 @@ import java.util.List;
/**
* @since 2.11
*/
-public class ServerKeyGenerator {
+public class ServerIdGenerator {
/**
* Increment this version each time the algorithm is changed. Do not exceed 9.
@@ -46,23 +46,23 @@ public class ServerKeyGenerator {
private final boolean acceptPrivateAddress;
- public ServerKeyGenerator() {
+ public ServerIdGenerator() {
this(false);
}
- ServerKeyGenerator(boolean acceptPrivateAddress) {
+ ServerIdGenerator(boolean acceptPrivateAddress) {
this.acceptPrivateAddress = acceptPrivateAddress;
}
- public String generate(String organization, String ipAddress) {
- String key = null;
- if (StringUtils.isNotBlank(organization) && StringUtils.isNotBlank(ipAddress)) {
+ public String generate(String organisation, String ipAddress) {
+ String id = null;
+ if (StringUtils.isNotBlank(organisation) && StringUtils.isNotBlank(ipAddress)) {
InetAddress inetAddress = toValidAddress(ipAddress);
if (inetAddress != null) {
- key = toKey(organization, inetAddress);
+ id = toId(organisation, inetAddress);
}
}
- return key;
+ return id;
}
boolean isFixed(InetAddress address) {
@@ -72,13 +72,13 @@ public class ServerKeyGenerator {
return acceptPrivateAddress || (!address.isLoopbackAddress() && !address.isLinkLocalAddress());
}
- String toKey(String organization, InetAddress address) {
- String key = new StringBuilder().append(organization).append("-").append(address.getHostAddress()).toString();
+ String toId(String organisation, InetAddress address) {
+ String id = new StringBuilder().append(organisation).append("-").append(address.getHostAddress()).toString();
try {
- return VERSION + DigestUtils.shaHex(key.getBytes("UTF-8")).substring(0, CHECKSUM_SIZE);
+ return VERSION + DigestUtils.shaHex(id.getBytes("UTF-8")).substring(0, CHECKSUM_SIZE);
} catch (UnsupportedEncodingException e) {
- throw new IllegalArgumentException("Organization is not UTF-8 encoded: " + organization, e);
+ throw new IllegalArgumentException("Organisation is not UTF-8 encoded: " + organisation, e);
}
}
@@ -112,7 +112,7 @@ public class ServerKeyGenerator {
}
}
} catch (SocketException e) {
- LoggerFactory.getLogger(ServerKeyGenerator.class).error("Fail to browse network interfaces", e);
+ LoggerFactory.getLogger(ServerIdGenerator.class).error("Fail to browse network interfaces", e);
}
return result;
}
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java
index f030202c85d..abd659627fc 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java
@@ -66,10 +66,10 @@ public final class ServerImpl extends Server {
}
}
- public String getKey() {
+ public String getPermanentServerId() {
DatabaseSession session = dbSessionFactory.getSession();
- Property serverKey = session.getSingleResult(Property.class, "key", CoreProperties.SERVER_KEY);
- return (serverKey!= null ? serverKey.getValue() : null);
+ Property serverId = session.getSingleResult(Property.class, "key", CoreProperties.PERMANENT_SERVER_ID);
+ return (serverId!= null ? serverId.getValue() : null);
}
public String getId() {
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
index 297f1b23413..bb8d0d3b99b 100644
--- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
+++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
@@ -44,7 +44,7 @@ import org.sonar.server.filters.FilterExecutor;
import org.sonar.server.filters.FilterResult;
import org.sonar.server.notifications.reviews.ReviewsNotificationManager;
import org.sonar.server.platform.Platform;
-import org.sonar.server.platform.ServerKeyGenerator;
+import org.sonar.server.platform.ServerIdGenerator;
import org.sonar.server.plugins.*;
import org.sonar.server.rules.ProfilesConsole;
import org.sonar.server.rules.RulesConsole;
@@ -52,7 +52,6 @@ import org.sonar.updatecenter.common.Version;
import java.net.InetAddress;
import java.sql.Connection;
-import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -276,12 +275,12 @@ public final class JRubyFacade {
return getContainer().getComponent(Configuration.class).getString(key, null);
}
- public List<InetAddress> getValidInetAddressesForServerKey() {
- return getContainer().getComponent(ServerKeyGenerator.class).getAvailableAddresses();
+ public List<InetAddress> getValidInetAddressesForServerId() {
+ return getContainer().getComponent(ServerIdGenerator.class).getAvailableAddresses();
}
- public String generateServerKey(String organization, String ipAddress) {
- return getContainer().getComponent(ServerKeyGenerator.class).generate(organization, ipAddress);
+ public String generateServerId(String organisation, String ipAddress) {
+ return getContainer().getComponent(ServerIdGenerator.class).generate(organisation, ipAddress);
}
public Connection getConnection() {
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/server_key_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/server_id_configuration_controller.rb
index 8e2e59fd3e1..9f77056ad06 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/server_key_configuration_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/server_id_configuration_controller.rb
@@ -17,37 +17,42 @@
# License along with Sonar; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
#
-class ServerKeyConfigurationController < ApplicationController
+class ServerIdConfigurationController < ApplicationController
SECTION=Navigation::SECTION_CONFIGURATION
- PROPERTY_SERVER_KEY = 'sonar.server_key'
- PROPERTY_IP_ADDRESS = 'sonar.server_key.ip_address'
- PROPERTY_ORGANIZATION = 'sonar.organization'
+ PROPERTY_SERVER_ID = 'sonar.server_id'
+ PROPERTY_IP_ADDRESS = 'sonar.server_id.ip_address'
+ PROPERTY_ORGANISATION = 'sonar.organisation'
before_filter :admin_required
- verify :method => :post, :only => [:save], :redirect_to => {:action => :index}
+ verify :method => :post, :only => [:generate], :redirect_to => {:action => :index}
def index
- @server_key = Property.value(PROPERTY_SERVER_KEY)
- @organization = Property.value(PROPERTY_ORGANIZATION)
+ @server_id = Property.value(PROPERTY_SERVER_ID)
+ @organisation = Property.value(PROPERTY_ORGANISATION)
@address = Property.value(PROPERTY_IP_ADDRESS)
- @valid_addresses = java_facade.getValidInetAddressesForServerKey()
+ @valid_addresses = java_facade.getValidInetAddressesForServerId()
+ @bad_id = false
+ if @server_id.present?
+ id = java_facade.generateServerId(@organisation, @address)
+ @bad_id = (@server_id != id)
+ end
params[:layout]='false'
end
- def save
- organization = params[:organization]
- Property.set(PROPERTY_ORGANIZATION, organization)
+ def generate
+ organisation = params[:organisation]
+ Property.set(PROPERTY_ORGANISATION, organisation)
ip_address=params[:address]
Property.set(PROPERTY_IP_ADDRESS, ip_address)
- key = java_facade.generate_server_key(organization, ip_address)
- if key
- Property.set(PROPERTY_SERVER_KEY, key)
+ id = java_facade.generateServerId(organisation, ip_address)
+ if id
+ Property.set(PROPERTY_SERVER_ID, id)
else
- Property.clear(PROPERTY_SERVER_KEY)
- flash[:error] = 'Please set valid organization and IP address'
+ Property.clear(PROPERTY_SERVER_ID)
+ flash[:error] = Api::Utils.message('server_id_configuration.generation_error')
end
redirect_to :action => 'index'
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb
index 8a052d24953..d3d27285c9e 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb
@@ -21,7 +21,7 @@ class SettingsController < ApplicationController
SECTION=Navigation::SECTION_CONFIGURATION
- SPECIAL_CATEGORIES=['email', 'server_key']
+ SPECIAL_CATEGORIES=['email', 'server_id']
verify :method => :post, :only => ['update'], :redirect_to => {:action => :index}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/server_id_configuration/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/server_id_configuration/index.html.erb
new file mode 100644
index 00000000000..b5c39c8ac28
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/server_id_configuration/index.html.erb
@@ -0,0 +1,60 @@
+<h3 class="marginbottom10"><%= message('server_id_configuration.page') -%></h3>
+
+<% if @server_id %>
+ <p>
+ <big><b><span class="<%= @bad_id ? 'error' : 'notice' -%>"><%= @server_id -%></span></b></big>
+ <% if @bad_id %>
+ <span class="error"><%= message('server_id_configuration.bad_id') -%></span>
+ <% end %>
+ </p>
+ <br/>
+<% end %>
+
+<p>
+ <%= message('server_id_configuration.information') -%>
+</p>
+
+<% form_tag :action => 'generate' do %>
+ <table class="data marginbottom10">
+ <thead>
+ <tr>
+ <th></th>
+ </tr>
+ </thead>
+ <tfoot>
+ <tr>
+ <td colspan="3">
+ <%= submit_tag message('server_id_configuration.generate_button'), :disable_with => message('server_id_configuration.generating_button') %>
+ </td>
+ </tr>
+ </tfoot>
+ <tbody>
+ <tr class="even">
+ <td style="padding: 10px">
+ <h3><%= message('server_id_configuration.organisation.title') -%></h3>
+
+ <p class="marginbottom10"><%= message('server_id_configuration.organisation.desc') -%></p>
+
+ <p>
+ <input type="text" name="organisation" value="<%= @organisation -%>"/>
+ </p>
+ </td>
+ </tr>
+ <tr class="odd">
+ <td style="padding: 10px">
+ <h3><%= message('server_id_configuration.ip.title') -%></h3>
+
+ <p class="marginbottom10"><%= message('server_id_configuration.ip.desc') -%></p>
+ <ul class="marginbottom10 bullet">
+ <% @valid_addresses.each_with_index do |ip_address, index| %>
+ <li><span class="address_<%= index -%>"><%= ip_address.getHostAddress() -%></span></li>
+ <% end %>
+ </ul>
+ <p>
+ <input type="text" name="address" value="<%= @address -%>"/>
+ </p>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+<% end %> \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/server_key_configuration/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/server_key_configuration/index.html.erb
deleted file mode 100644
index cf7db6f87c5..00000000000
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/server_key_configuration/index.html.erb
+++ /dev/null
@@ -1,58 +0,0 @@
-<h3 class="marginbottom10"><%= message('server_key_configuration.page') -%></h3>
-
-<% if @server_key %>
- <p>Server Key: <span class="notice"><b><%= @server_key -%></b></span></p>
-<% else %>
-<% end %>
-<p>
- Speech sur l'utilité de la clé....
-</p>
-
-<% form_tag :action => :save do %>
- <table class="data marginbottom10">
- <thead>
- <tr>
- <th></th>
- </tr>
- </thead>
- <tfoot>
- <% if @server_key %>
- <tr>
- <td colspan="3">
- <span class="warning">Changing configuration can disable your SonarSource commercial licenses. You'll have to renew them.</span>
- </td>
- </tr>
- <% end %>
- <tr>
- <td colspan="3">
- <%= submit_tag message('server_key_configuration.generate_button'), :disable_with => message('server_key_configuration.generating_button') %>
- </td>
- </tr>
- </tfoot>
- <tbody>
- <tr class="even">
- <td style="padding: 10px">
- <h3>Organization</h3>
- <p class="marginbottom10">The organization is ....</p>
- <p>
- <input type="text" name="organization" value="<%= @organization -%>"/>
- </p>
- </td>
- </tr>
- <tr class="odd">
- <td style="padding: 10px">
- <h3>Fixed IP Address</h3>
- <p class="marginbottom10">The IP address is .... Choose one of the following:</p>
- <ul class="marginbottom10 bullet">
- <% @valid_addresses.each_with_index do |ip_address, index| %>
- <li><span class="address_<%= index -%>"><%= ip_address.getHostAddress() -%></span></li>
- <% end %>
- </ul>
- <p>
- <input type="text" name="address" value="<%= @address -%>"/>
- </p>
- </td>
- </tr>
- </tbody>
- </table>
-<% end %> \ No newline at end of file