]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9802 create mocks WS for api/system/info
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 13 Sep 2017 08:20:19 +0000 (10:20 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 26 Sep 2017 21:49:37 +0000 (23:49 +0200)
server/sonar-server/src/main/java/org/sonar/server/platform/ws/ClusterInfoAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoActionModule.java
server/sonar-server/src/main/java/org/sonar/server/platform/ws/StandaloneInfoAction.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/platform/ws/InfoActionModuleTest.java

diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/ClusterInfoAction.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/ClusterInfoAction.java
new file mode 100644 (file)
index 0000000..6f9125f
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+package org.sonar.server.platform.ws;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.server.user.UserSession;
+
+public class ClusterInfoAction implements SystemWsAction {
+
+  private final UserSession userSession;
+
+  public ClusterInfoAction(UserSession userSession) {
+    this.userSession = userSession;
+  }
+
+  @Override
+  public void define(WebService.NewController controller) {
+    controller.createAction("cluster_info")
+      .setDescription("WIP")
+      .setSince("6.6")
+      .setInternal(true)
+      .setResponseExample(getClass().getResource("/org/sonar/server/platform/ws/info-example.json"))
+      .setHandler(this);
+  }
+
+  @Override
+  public void handle(Request request, Response response) {
+    userSession.checkIsSystemAdministrator();
+
+    try (JsonWriter json = response.newJsonWriter()) {
+      json.beginObject();
+
+      // global section
+      json.prop("Cluster", true);
+      json.prop("Cluster Name", "foo");
+      json.prop("Server Id", "ABC123");
+      json.prop("Health", "RED");
+      json
+        .name("Health Causes")
+        .beginArray().beginObject().prop("message", "Requires at least two search nodes").endObject().endArray();
+
+      json.name("Settings");
+      json.beginObject();
+      json.prop("sonar.forceAuthentication", true);
+      json.prop("sonar.externalIdentityProviders", "GitHub, BitBucket");
+      json.endObject();
+
+
+
+      json.name("Database");
+      json
+        .beginObject()
+        .prop("Name", "PostgreSQL")
+        .prop("Version", "9.6.3")
+        .endObject();
+
+      json.name("Compute Engine");
+      json
+        .beginObject()
+        .prop("Pending", 5)
+        .prop("In Progress", 4)
+        .prop("workers", 8)
+        .prop("workersPerNode", 4)
+        .endObject();
+
+      json.name("Elasticsearch");
+      json
+        .beginObject()
+        .prop("Health", "GREEN")
+        .prop("Number of Nodes", 4)
+        .prop("Index Components - Docs", 152_515_155)
+        .prop("Index Components - Shards", 20)
+        .prop("Index Components - Size", "25GB")
+        .prop("Index Issues - Docs", 5)
+        .prop("Index Issues - Shards", 5)
+        .prop("Index Issues - Size", "52MB")
+        .prop("Index Tests - Docs", 56605)
+        .prop("Index Tests - Shards", 2)
+        .prop("Index Tests - Size", "520MB")
+        .endObject();
+
+      json.name("Application Nodes");
+      json
+        .beginArray()
+        .beginObject()
+        .prop("Name", "Mont Blanc")
+        .prop("Host", "10.158.92.16")
+        .prop("Health", "YELLOW")
+        .name("healthCauses").beginArray().beginObject().prop("message", "Db connectivity error").endObject().endArray()
+        .prop("Start Time", "2017-05-30T10:23:45")
+        .prop("Official Distribution", true)
+        .prop("Processors", 4);
+      json
+        .name("Web JVM").beginObject()
+        .prop("JVM Name", "Java HotSpot(TM) 64-Bit Server VM")
+        .prop("JVM Vendor", "Oracle Corporation")
+        .prop("Max Memory", "948MB")
+        .prop("Free Memory", "38MB")
+        .endObject()
+
+        .name("Web JVM Properties").beginObject()
+        .prop("catalina.home", "/sonarsource/var/tmp/sonarsource/sssonarqube/tc")
+        .prop("glowroot.tmp.dir", "/var/tmp/sonarsource/ssglowroot-agent")
+        .prop("glowroot.adad.dir", "/var/tmp/sonarsource/ssglowroot-agent")
+        .prop("java.specification.version", "1.8")
+        .endObject()
+
+        .name("Web Database Connectivity").beginObject()
+        .prop("Driver", "PostgreSQL JDBC Driver")
+        .prop("Driver Version", "PostgreSQL JDBC Driver")
+        .prop("Pool Idle Connections", 2)
+        .prop("Pool Max Connections", 50)
+        .prop("URL", "jdbc:postgresql://next-rds.cn6pfc2xc6oq.us-east-1.rds.amazonaws.com/dory")
+        .endObject();
+
+      json
+        .name("Compute Engine JVM").beginObject()
+        .prop("JVM Name", "Java HotSpot(TM) 64-Bit Server VM")
+        .prop("JVM Vendor", "Oracle Corporation")
+        .prop("Max Memory", "25MB")
+        .prop("Free Memory", "8MB")
+        .endObject();
+
+      json
+        .name("Compute Engine JVM Properties").beginObject()
+        .prop("java.ext.dirs", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.io.tmpdir", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.library.path", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.net.preferIPv4Stack", true)
+        .prop("java.rmi.server.randomIDs", true)
+        .prop("java.specification.version", "1.8")
+        .endObject();
+
+      json.endObject().endArray();
+
+      json.name("Search Nodes");
+      json
+        .beginArray()
+        .beginObject()
+        .prop("Name", "Parmelan")
+        .prop("Host", "10.158.92.19")
+        .prop("Health", "GREEN")
+        .name("Health Causes").beginArray().endArray()
+        .prop("Start Time", "2017-05-30T10:23:45")
+        .prop("Processors", 2)
+        .prop("Disk Available", "25GB")
+        .prop("JVM Threads", 52)
+
+        .name("JVM Properties").beginObject()
+        .prop("java.ext.dirs", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.io.tmpdir", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.library.path", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.net.preferIPv4Stack", true)
+        .prop("java.rmi.server.randomIDs", true)
+        .endObject()
+
+        .name("JVM").beginObject()
+        .prop("java.ext.dirs", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.io.tmpdir", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.library.path", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.net.preferIPv4Stack", true)
+        .prop("java.rmi.server.randomIDs", true)
+        .endObject()
+
+        .endObject()
+        .endArray();
+
+      json.endObject();
+    }
+  }
+}
index 78bff02585c19717266acb0ef4cc7f2cf3762da5..fb3f3859a2dea82387a11a49ae43881a4c98d91d 100644 (file)
@@ -26,6 +26,8 @@ public class InfoActionModule extends Module {
   @Override
   protected void configureModule() {
     add(TelemetryDataLoader.class,
-      InfoAction.class);
+      InfoAction.class,
+      ClusterInfoAction.class,
+      StandaloneInfoAction.class);
   }
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/StandaloneInfoAction.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/StandaloneInfoAction.java
new file mode 100644 (file)
index 0000000..adb9277
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+package org.sonar.server.platform.ws;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.server.user.UserSession;
+
+public class StandaloneInfoAction implements SystemWsAction {
+
+  private final UserSession userSession;
+
+  public StandaloneInfoAction(UserSession userSession) {
+    this.userSession = userSession;
+  }
+
+  @Override
+  public void define(WebService.NewController controller) {
+    controller.createAction("standalone_info")
+      .setDescription("WIP")
+      .setSince("6.6")
+      .setInternal(true)
+      .setResponseExample(getClass().getResource("/org/sonar/server/platform/ws/info-example.json"))
+      .setHandler(this);
+  }
+
+  @Override
+  public void handle(Request request, Response response) {
+    userSession.checkIsSystemAdministrator();
+
+    try (JsonWriter json = response.newJsonWriter()) {
+      json.beginObject();
+
+      // global section
+      json
+        .prop("Server Id", "ABC123")
+        .prop("Health", "RED")
+        .prop("Host", "10.158.92.16")
+        .prop("Start Time", "2017-05-30T10:23:45")
+        .prop("Official Distribution", true)
+        .prop("Processors", 4)
+        .prop("Disk Available", "25GB")
+        .prop("JVM Threads", 52);
+      json
+        .name("Health Causes")
+        .beginArray().beginObject().prop("message", "Db connectivity error").endObject().endArray();
+
+      json.name("Settings");
+      json.beginObject();
+      json.prop("sonar.forceAuthentication", true);
+      json.prop("sonar.externalIdentityProviders", "GitHub, BitBucket");
+      json.endObject();
+
+
+
+      json.name("Database");
+      json
+        .beginObject()
+        .prop("Name", "PostgreSQL")
+        .prop("Version", "9.6.3")
+        .endObject();
+
+      json.name("Compute Engine");
+      json
+        .beginObject()
+        .prop("Pending", 5)
+        .prop("In Progress", 4)
+        .prop("workers", 8)
+        .prop("workersPerNode", 4)
+        .endObject();
+
+      json.name("Elasticsearch");
+      json
+        .beginObject()
+        .prop("Health", "GREEN")
+        .prop("Number of Nodes", 4)
+        .prop("Index Components - Docs", 152_515_155)
+        .prop("Index Components - Shards", 20)
+        .prop("Index Components - Size", "25GB")
+        .prop("Index Issues - Docs", 5)
+        .prop("Index Issues - Shards", 5)
+        .prop("Index Issues - Size", "52MB")
+        .prop("Index Tests - Docs", 56605)
+        .prop("Index Tests - Shards", 2)
+        .prop("Index Tests - Size", "520MB")
+        .endObject();
+
+      json
+        .name("Web JVM").beginObject()
+        .prop("JVM Name", "Java HotSpot(TM) 64-Bit Server VM")
+        .prop("JVM Vendor", "Oracle Corporation")
+        .prop("Max Memory", "948MB")
+        .prop("Free Memory", "38MB")
+        .endObject()
+
+        .name("Web JVM Properties").beginObject()
+        .prop("catalina.home", "/sonarsource/var/tmp/sonarsource/sssonarqube/tc")
+        .prop("glowroot.tmp.dir", "/var/tmp/sonarsource/ssglowroot-agent")
+        .prop("glowroot.adad.dir", "/var/tmp/sonarsource/ssglowroot-agent")
+        .prop("java.specification.version", "1.8")
+        .endObject()
+
+        .name("Web Database Connectivity").beginObject()
+        .prop("Driver", "PostgreSQL JDBC Driver")
+        .prop("Driver Version", "PostgreSQL JDBC Driver")
+        .prop("Pool Idle Connections", 2)
+        .prop("Pool Max Connections", 50)
+        .prop("URL", "jdbc:postgresql://next-rds.cn6pfc2xc6oq.us-east-1.rds.amazonaws.com/dory")
+        .endObject();
+
+      json
+        .name("Compute Engine JVM").beginObject()
+        .prop("JVM Name", "Java HotSpot(TM) 64-Bit Server VM")
+        .prop("JVM Vendor", "Oracle Corporation")
+        .prop("Max Memory", "25MB")
+        .prop("Free Memory", "8MB")
+        .endObject();
+
+      json
+        .name("Compute Engine JVM Properties").beginObject()
+        .prop("java.ext.dirs", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.io.tmpdir", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.library.path", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.net.preferIPv4Stack", true)
+        .prop("java.rmi.server.randomIDs", true)
+        .prop("java.specification.version", "1.8")
+        .endObject();
+
+      json
+        .name("Search JVM Properties").beginObject()
+        .prop("java.ext.dirs", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.io.tmpdir", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.library.path", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.net.preferIPv4Stack", true)
+        .prop("java.rmi.server.randomIDs", true)
+        .endObject();
+
+      json.name("Search JVM").beginObject()
+        .prop("java.ext.dirs", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.io.tmpdir", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.library.path", "/opt/sonarsource/jvm/java-1.8.0-sun-x64/jre/lib/ext:/usr/java/packages/lib/ext")
+        .prop("java.net.preferIPv4Stack", true)
+        .prop("java.rmi.server.randomIDs", true)
+        .endObject();
+
+      json.endObject();
+    }
+  }
+}
index 674b61c572dbc9df6ef47660c99d9e20ed33601a..d06d5dbdf208b37d120a410327ad3c7511404fb5 100644 (file)
@@ -32,7 +32,7 @@ public class InfoActionModuleTest {
 
     new InfoActionModule().configure(container);
 
-    assertThat(container.size()).isEqualTo(2 + COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER);
+    assertThat(container.size()).isEqualTo(4 + COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER);
   }
 
 }