aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-11-02 18:15:15 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-11-02 18:15:15 +0000
commit2aa3df37b9c857da35590e048c49ab5c6050b00d (patch)
treea30dd743d0846b73b82a7755c2589d0c07d86f4c
parentd97d0f40e1b7e4390dc6c637e1ae63f3ce533369 (diff)
downloadsonarqube-2aa3df37b9c857da35590e048c49ab5c6050b00d.tar.gz
sonarqube-2aa3df37b9c857da35590e048c49ab5c6050b00d.zip
SONAR-1911 New web service to get server status
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ServerUnmarshaller.java8
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb12
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java30
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java10
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java15
5 files changed, 68 insertions, 7 deletions
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ServerUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ServerUnmarshaller.java
index 87646fb0305..ad87a8133e6 100644
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ServerUnmarshaller.java
+++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ServerUnmarshaller.java
@@ -31,9 +31,15 @@ public class ServerUnmarshaller implements Unmarshaller<Server> {
public Server toModel(JavaScriptObject json) {
JSONObject map = new JSONObject(json);
- return new Server()
+ Server server = new Server()
.setId(JsonUtils.getString(map, "id"))
.setVersion(JsonUtils.getString(map, "version"));
+ server.setStatusMessage(JsonUtils.getString(map, "status_msg"));
+ String status = JsonUtils.getString(map, "status");
+ if (status != null) {
+ server.setStatus(Server.Status.valueOf(status));
+ }
+ return server;
}
public List<Server> toModels(JavaScriptObject json) {
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb
index 65a4dbe41fb..f50ec79f4fa 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb
@@ -32,6 +32,7 @@ class Api::ServerController < Api::ApiController
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') }
@@ -67,4 +68,15 @@ class Api::ServerController < Api::ApiController
end
hash
end
+
+ def complete_with_status(hash)
+ if DatabaseVersion.uptodate?
+ hash[:status]='UP'
+ elsif ActiveRecord::Base.connected?
+ hash[:status]='SETUP'
+ else
+ hash[:status]='DOWN'
+ hash[:status_msg]='Not connected to database'
+ end
+ end
end
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java
index 4919fbb123d..7967a348ce5 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java
@@ -23,8 +23,15 @@ package org.sonar.wsclient.services;
* @author Evgeny Mandrikov
*/
public class Server extends Model {
+
+ public static enum Status {
+ SETUP, UP, DOWN;
+ }
+
private String id;
private String version;
+ private Status status;
+ private String statusMessage;
public String getVersion() {
return version;
@@ -34,8 +41,8 @@ public class Server extends Model {
return id;
}
- public Server setVersion(String version) {
- this.version = version;
+ public Server setVersion(String s) {
+ this.version = s;
return this;
}
@@ -43,4 +50,23 @@ public class Server extends Model {
this.id = id;
return this;
}
+
+ public Status getStatus() {
+ return status;
+ }
+
+ public String getStatusMessage() {
+ return statusMessage;
+ }
+
+ public Server setStatus(Status status) {
+ this.status = status;
+ return this;
+ }
+
+ public Server setStatusMessage(String statusMessage) {
+ this.statusMessage = statusMessage;
+ return this;
+ }
+
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java
index d980876e3f8..a17a36189d4 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java
@@ -31,9 +31,15 @@ import java.util.List;
public class ServerUnmarshaller implements Unmarshaller<Server> {
public Server toModel(String json) {
JSONObject map = (JSONObject) JSONValue.parse(json);
- return new Server()
+ Server server = new Server()
.setId(JsonUtils.getString(map, "id"))
- .setVersion(JsonUtils.getString(map, "version"));
+ .setVersion(JsonUtils.getString(map, "version"))
+ .setStatusMessage(JsonUtils.getString(map, "status_msg"));
+ String status = JsonUtils.getString(map, "status");
+ if (status != null) {
+ server.setStatus(Server.Status.valueOf(status));
+ }
+ return server;
}
public List<Server> toModels(String json) {
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java
index 4db8b113aa9..830996828f4 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java
@@ -24,16 +24,27 @@ import org.sonar.wsclient.services.Server;
import java.io.IOException;
+import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public class ServerUnmarshallerTest {
@Test
- public void toModel() throws IOException {
- Server server = new ServerUnmarshaller().toModel("{\"id\":\"123456789\", \"version\":\"2.0-SNAPSHOT\"}");
+ public void testToModel() throws IOException {
+ Server server = new ServerUnmarshaller().toModel("{\"id\":\"123456789\", \"version\":\"2.0-SNAPSHOT\", \"status\":\"UP\", \"status_msg\":\"everything is under control\"}");
assertThat(server.getId(), is("123456789"));
assertThat(server.getVersion(), is("2.0-SNAPSHOT"));
+ assertThat(server.getStatus(), is(Server.Status.UP));
+ assertThat(server.getStatusMessage(), is("everything is under control"));
}
+ @Test
+ public void shouldNotFailIfStatusIsMissing() throws IOException {
+ Server server = new ServerUnmarshaller().toModel("{\"id\":\"123456789\", \"version\":\"2.0-SNAPSHOT\"}");
+ assertThat(server.getId(), is("123456789"));
+ assertThat(server.getVersion(), is("2.0-SNAPSHOT"));
+ assertThat(server.getStatus(), nullValue());
+ assertThat(server.getStatusMessage(), nullValue());
+ }
}