From: Sébastien Lesaint Date: Tue, 13 Aug 2019 11:54:45 +0000 (+0200) Subject: separate Action from indirect dependencies in system WS X-Git-Tag: 8.0~232 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1179e7ef7f549aecdc1f240418dba3a1caac3d51;p=sonarqube.git separate Action from indirect dependencies in system WS --- diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/AbstractSystemInfoWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/AbstractSystemInfoWriter.java new file mode 100644 index 00000000000..c6d2b88de20 --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/AbstractSystemInfoWriter.java @@ -0,0 +1,93 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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 java.util.Collection; +import org.sonar.api.utils.text.JsonWriter; +import org.sonar.process.systeminfo.SystemInfoUtils; +import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; +import org.sonar.server.health.Health; +import org.sonar.server.telemetry.TelemetryDataLoader; + +import static org.sonar.server.telemetry.TelemetryDataJsonWriter.writeTelemetryData; + +public abstract class AbstractSystemInfoWriter implements SystemInfoWriter { + private static final String[] ORDERED_SECTION_NAMES = { + // standalone + "System", "Database", "Plugins", + + // cluster + "Web JVM State", "Web Database Connection", "Web Logging", "Web JVM Properties", + "Compute Engine Tasks", "Compute Engine JVM State", "Compute Engine Database Connection", "Compute Engine Logging", "Compute Engine JVM Properties", + "Search State", "Search Indexes"}; + + private final TelemetryDataLoader telemetry; + + AbstractSystemInfoWriter(TelemetryDataLoader telemetry) { + this.telemetry = telemetry; + } + + protected void writeSections(Collection sections, JsonWriter json) { + SystemInfoUtils + .order(sections, ORDERED_SECTION_NAMES) + .forEach(section -> writeSection(section, json)); + } + + private void writeSection(ProtobufSystemInfo.Section section, JsonWriter json) { + json.name(section.getName()); + json.beginObject(); + for (ProtobufSystemInfo.Attribute attribute : section.getAttributesList()) { + writeAttribute(attribute, json); + } + json.endObject(); + } + + private void writeAttribute(ProtobufSystemInfo.Attribute attribute, JsonWriter json) { + switch (attribute.getValueCase()) { + case BOOLEAN_VALUE: + json.prop(attribute.getKey(), attribute.getBooleanValue()); + break; + case LONG_VALUE: + json.prop(attribute.getKey(), attribute.getLongValue()); + break; + case DOUBLE_VALUE: + json.prop(attribute.getKey(), attribute.getDoubleValue()); + break; + case STRING_VALUE: + json.prop(attribute.getKey(), attribute.getStringValue()); + break; + case VALUE_NOT_SET: + json.name(attribute.getKey()).beginArray().values(attribute.getStringValuesList()).endArray(); + break; + default: + throw new IllegalArgumentException("Unsupported type: " + attribute.getValueCase()); + } + } + + protected void writeHealth(Health health, JsonWriter json) { + json.prop("Health", health.getStatus().name()); + json.name("Health Causes").beginArray().values(health.getCauses()).endArray(); + } + + protected void writeTelemetry(JsonWriter json) { + json.name("Statistics"); + writeTelemetryData(json, telemetry.load()); + } +} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelActionModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelActionModule.java deleted file mode 100644 index d8ef16a9604..00000000000 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelActionModule.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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.core.platform.Module; -import org.sonar.server.platform.WebServer; - -public class ChangeLogLevelActionModule extends Module { - private final WebServer webServer; - - public ChangeLogLevelActionModule(WebServer webServer) { - this.webServer = webServer; - } - - @Override - protected void configureModule() { - add(ChangeLogLevelAction.class); - if (webServer.isStandalone()) { - add(ChangeLogLevelStandaloneService.class); - } else { - add(ChangeLogLevelClusterService.class); - } - } -} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelServiceModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelServiceModule.java new file mode 100644 index 00000000000..ad0664b6331 --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelServiceModule.java @@ -0,0 +1,40 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.core.platform.Module; +import org.sonar.server.platform.WebServer; + +public class ChangeLogLevelServiceModule extends Module { + private final WebServer webServer; + + public ChangeLogLevelServiceModule(WebServer webServer) { + this.webServer = webServer; + } + + @Override + protected void configureModule() { + if (webServer.isStandalone()) { + add(ChangeLogLevelStandaloneService.class); + } else { + add(ChangeLogLevelClusterService.class); + } + } +} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ClusterSystemInfoWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ClusterSystemInfoWriter.java index 97c92f8323f..06b3bb4972b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ClusterSystemInfoWriter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ClusterSystemInfoWriter.java @@ -29,7 +29,7 @@ import org.sonar.server.platform.monitoring.cluster.NodeInfo; import org.sonar.server.platform.monitoring.cluster.SearchNodesInfoLoader; import org.sonar.server.telemetry.TelemetryDataLoader; -public class ClusterSystemInfoWriter extends SystemInfoWriter { +public class ClusterSystemInfoWriter extends AbstractSystemInfoWriter { private final GlobalInfoLoader globalInfoLoader; private final AppNodesInfoLoader appNodesInfoLoader; private final SearchNodesInfoLoader searchNodesInfoLoader; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/HealthActionModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/HealthActionModule.java deleted file mode 100644 index 453d287fc1c..00000000000 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/HealthActionModule.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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.core.platform.Module; -import org.sonar.server.health.AppNodeClusterCheck; -import org.sonar.server.health.CeStatusNodeCheck; -import org.sonar.server.health.DbConnectionNodeCheck; -import org.sonar.server.health.EsStatusClusterCheck; -import org.sonar.server.health.EsStatusNodeCheck; -import org.sonar.server.health.HealthCheckerImpl; -import org.sonar.server.health.WebServerStatusNodeCheck; -import org.sonar.server.platform.WebServer; - -public class HealthActionModule extends Module { - private final WebServer webServer; - - public HealthActionModule(WebServer webServer) { - this.webServer = webServer; - } - - @Override - protected void configureModule() { - // NodeHealthCheck implementations - add(WebServerStatusNodeCheck.class, - DbConnectionNodeCheck.class, - CeStatusNodeCheck.class); - if (webServer.isStandalone()) { - add(EsStatusNodeCheck.class); - } else { - // ClusterHealthCheck implementations - add(EsStatusClusterCheck.class, - AppNodeClusterCheck.class); - } - - add(HealthCheckerImpl.class, - HealthActionSupport.class, - HealthAction.class); - } -} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/HealthCheckerModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/HealthCheckerModule.java new file mode 100644 index 00000000000..8707f7da7f2 --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/HealthCheckerModule.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.core.platform.Module; +import org.sonar.server.health.AppNodeClusterCheck; +import org.sonar.server.health.CeStatusNodeCheck; +import org.sonar.server.health.DbConnectionNodeCheck; +import org.sonar.server.health.EsStatusClusterCheck; +import org.sonar.server.health.EsStatusNodeCheck; +import org.sonar.server.health.HealthCheckerImpl; +import org.sonar.server.health.WebServerStatusNodeCheck; +import org.sonar.server.platform.WebServer; + +public class HealthCheckerModule extends Module { + private final WebServer webServer; + + public HealthCheckerModule(WebServer webServer) { + this.webServer = webServer; + } + + @Override + protected void configureModule() { + // NodeHealthCheck implementations + add(WebServerStatusNodeCheck.class, + DbConnectionNodeCheck.class, + CeStatusNodeCheck.class); + if (webServer.isStandalone()) { + add(EsStatusNodeCheck.class); + } else { + // ClusterHealthCheck implementations + add(EsStatusClusterCheck.class, + AppNodeClusterCheck.class); + } + + add(HealthCheckerImpl.class); + } +} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SafeModeHealthActionModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SafeModeHealthActionModule.java deleted file mode 100644 index 96f8f7bb934..00000000000 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SafeModeHealthActionModule.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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.core.platform.Module; -import org.sonar.server.health.DbConnectionNodeCheck; -import org.sonar.server.health.EsStatusNodeCheck; -import org.sonar.server.health.HealthCheckerImpl; -import org.sonar.server.health.WebServerSafemodeNodeCheck; - -public class SafeModeHealthActionModule extends Module { - @Override - protected void configureModule() { - add( - // NodeHealthCheck implementations - WebServerSafemodeNodeCheck.class, - DbConnectionNodeCheck.class, - EsStatusNodeCheck.class, - - HealthCheckerImpl.class, - HealthActionSupport.class, - SafeModeHealthAction.class); - } -} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SafeModeHealthCheckerModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SafeModeHealthCheckerModule.java new file mode 100644 index 00000000000..f1bd0698f99 --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SafeModeHealthCheckerModule.java @@ -0,0 +1,39 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.core.platform.Module; +import org.sonar.server.health.DbConnectionNodeCheck; +import org.sonar.server.health.EsStatusNodeCheck; +import org.sonar.server.health.HealthCheckerImpl; +import org.sonar.server.health.WebServerSafemodeNodeCheck; + +public class SafeModeHealthCheckerModule extends Module { + @Override + protected void configureModule() { + add( + // NodeHealthCheck implementations + WebServerSafemodeNodeCheck.class, + DbConnectionNodeCheck.class, + EsStatusNodeCheck.class, + + HealthCheckerImpl.class); + } +} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SafemodeSystemWsModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SafemodeSystemWsModule.java new file mode 100644 index 00000000000..9a3919c2bf5 --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SafemodeSystemWsModule.java @@ -0,0 +1,37 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.core.platform.Module; + +public class SafemodeSystemWsModule extends Module { + @Override + protected void configureModule() { + add( + StatusAction.class, + MigrateDbAction.class, + DbMigrationStatusAction.class, + HealthActionSupport.class, + SafeModeHealthAction.class, + SystemWs.class + + ); + } +} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/StandaloneSystemInfoWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/StandaloneSystemInfoWriter.java index 3557fa3caf4..a883a75c548 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/StandaloneSystemInfoWriter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/StandaloneSystemInfoWriter.java @@ -31,7 +31,7 @@ import org.sonar.server.telemetry.TelemetryDataLoader; import static java.util.Arrays.stream; -public class StandaloneSystemInfoWriter extends SystemInfoWriter { +public class StandaloneSystemInfoWriter extends AbstractSystemInfoWriter { private final CeHttpClient ceHttpClient; private final HealthChecker healthChecker; private final SystemInfoSection[] systemInfoSections; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SystemInfoWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SystemInfoWriter.java index 5c0b046a028..fd6726573b8 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SystemInfoWriter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SystemInfoWriter.java @@ -19,77 +19,8 @@ */ package org.sonar.server.platform.ws; -import java.util.Collection; import org.sonar.api.utils.text.JsonWriter; -import org.sonar.process.systeminfo.SystemInfoUtils; -import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; -import org.sonar.server.health.Health; -import org.sonar.server.telemetry.TelemetryDataLoader; -import static org.sonar.server.telemetry.TelemetryDataJsonWriter.writeTelemetryData; - -public abstract class SystemInfoWriter { - private static final String[] ORDERED_SECTION_NAMES = { - // standalone - "System", "Database", "Plugins", - - // cluster - "Web JVM State", "Web Database Connection", "Web Logging", "Web JVM Properties", - "Compute Engine Tasks", "Compute Engine JVM State", "Compute Engine Database Connection", "Compute Engine Logging", "Compute Engine JVM Properties", - "Search State", "Search Indexes"}; - - private final TelemetryDataLoader telemetry; - - SystemInfoWriter(TelemetryDataLoader telemetry) { - this.telemetry = telemetry; - } - - public abstract void write(JsonWriter json) throws Exception; - - protected void writeSections(Collection sections, JsonWriter json) { - SystemInfoUtils - .order(sections, ORDERED_SECTION_NAMES) - .forEach(section -> writeSection(section, json)); - } - - private void writeSection(ProtobufSystemInfo.Section section, JsonWriter json) { - json.name(section.getName()); - json.beginObject(); - for (ProtobufSystemInfo.Attribute attribute : section.getAttributesList()) { - writeAttribute(attribute, json); - } - json.endObject(); - } - - private void writeAttribute(ProtobufSystemInfo.Attribute attribute, JsonWriter json) { - switch (attribute.getValueCase()) { - case BOOLEAN_VALUE: - json.prop(attribute.getKey(), attribute.getBooleanValue()); - break; - case LONG_VALUE: - json.prop(attribute.getKey(), attribute.getLongValue()); - break; - case DOUBLE_VALUE: - json.prop(attribute.getKey(), attribute.getDoubleValue()); - break; - case STRING_VALUE: - json.prop(attribute.getKey(), attribute.getStringValue()); - break; - case VALUE_NOT_SET: - json.name(attribute.getKey()).beginArray().values(attribute.getStringValuesList()).endArray(); - break; - default: - throw new IllegalArgumentException("Unsupported type: " + attribute.getValueCase()); - } - } - - protected void writeHealth(Health health, JsonWriter json) { - json.prop("Health", health.getStatus().name()); - json.name("Health Causes").beginArray().values(health.getCauses()).endArray(); - } - - protected void writeTelemetry(JsonWriter json) { - json.name("Statistics"); - writeTelemetryData(json, telemetry.load()); - } +public interface SystemInfoWriter { + void write(JsonWriter json) throws Exception; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SystemInfoWriterModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SystemInfoWriterModule.java new file mode 100644 index 00000000000..1da4de96524 --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SystemInfoWriterModule.java @@ -0,0 +1,89 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.core.platform.Module; +import org.sonar.process.systeminfo.JvmPropertiesSection; +import org.sonar.process.systeminfo.JvmStateSection; +import org.sonar.server.platform.WebServer; +import org.sonar.server.platform.monitoring.DbConnectionSection; +import org.sonar.server.platform.monitoring.DbSection; +import org.sonar.server.platform.monitoring.EsIndexesSection; +import org.sonar.server.platform.monitoring.EsStateSection; +import org.sonar.server.platform.monitoring.LoggingSection; +import org.sonar.server.platform.monitoring.PluginsSection; +import org.sonar.server.platform.monitoring.SettingsSection; +import org.sonar.server.platform.monitoring.StandaloneSystemSection; +import org.sonar.server.platform.monitoring.cluster.AppNodesInfoLoaderImpl; +import org.sonar.server.platform.monitoring.cluster.CeQueueGlobalSection; +import org.sonar.server.platform.monitoring.cluster.EsClusterStateSection; +import org.sonar.server.platform.monitoring.cluster.GlobalInfoLoader; +import org.sonar.server.platform.monitoring.cluster.GlobalSystemSection; +import org.sonar.server.platform.monitoring.cluster.NodeSystemSection; +import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider; +import org.sonar.server.platform.monitoring.cluster.SearchNodesInfoLoaderImpl; + +public class SystemInfoWriterModule extends Module { + private final WebServer webServer; + + public SystemInfoWriterModule(WebServer webServer) { + this.webServer = webServer; + } + + @Override + protected void configureModule() { + boolean standalone = webServer.isStandalone(); + + add( + new JvmPropertiesSection("Web JVM Properties"), + new JvmStateSection("Web JVM State"), + DbSection.class, + DbConnectionSection.class, + EsIndexesSection.class, + LoggingSection.class, + PluginsSection.class, + SettingsSection.class + + ); + if (standalone) { + add( + EsStateSection.class, + StandaloneSystemSection.class, + StandaloneSystemInfoWriter.class + + ); + } else { + add( + CeQueueGlobalSection.class, + EsClusterStateSection.class, + GlobalSystemSection.class, + NodeSystemSection.class, + + ProcessInfoProvider.class, + GlobalInfoLoader.class, + AppNodesInfoLoaderImpl.class, + SearchNodesInfoLoaderImpl.class, + ClusterSystemInfoWriter.class + + ); + } + } + +} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SystemWsModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SystemWsModule.java new file mode 100644 index 00000000000..38b377b80ec --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SystemWsModule.java @@ -0,0 +1,44 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.core.platform.Module; + +public class SystemWsModule extends Module { + + @Override + protected void configureModule() { + add( + ChangeLogLevelAction.class, + DbMigrationStatusAction.class, + HealthActionSupport.class, + HealthAction.class, + InfoAction.class, + LogsAction.class, + MigrateDbAction.class, + PingAction.class, + RestartAction.class, + StatusAction.class, + UpgradesAction.class, + SystemWs.class + + ); + } +} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/WebSystemInfoModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/WebSystemInfoModule.java deleted file mode 100644 index 276b14b8ac4..00000000000 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/WebSystemInfoModule.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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.config.Configuration; -import org.sonar.core.platform.Module; -import org.sonar.process.systeminfo.JvmPropertiesSection; -import org.sonar.process.systeminfo.JvmStateSection; -import org.sonar.server.platform.WebServer; -import org.sonar.server.platform.monitoring.DbConnectionSection; -import org.sonar.server.platform.monitoring.DbSection; -import org.sonar.server.platform.monitoring.EsIndexesSection; -import org.sonar.server.platform.monitoring.EsStateSection; -import org.sonar.server.platform.monitoring.LoggingSection; -import org.sonar.server.platform.monitoring.PluginsSection; -import org.sonar.server.platform.monitoring.SettingsSection; -import org.sonar.server.platform.monitoring.StandaloneSystemSection; -import org.sonar.server.platform.monitoring.cluster.AppNodesInfoLoaderImpl; -import org.sonar.server.platform.monitoring.cluster.CeQueueGlobalSection; -import org.sonar.server.platform.monitoring.cluster.EsClusterStateSection; -import org.sonar.server.platform.monitoring.cluster.GlobalInfoLoader; -import org.sonar.server.platform.monitoring.cluster.GlobalSystemSection; -import org.sonar.server.platform.monitoring.cluster.NodeSystemSection; -import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider; -import org.sonar.server.platform.monitoring.cluster.SearchNodesInfoLoaderImpl; - -public class WebSystemInfoModule extends Module { - private final WebServer webServer; - - public WebSystemInfoModule(WebServer webServer) { - this.webServer = webServer; - } - - @Override - protected void configureModule() { - boolean standalone = webServer.isStandalone(); - - add( - new JvmPropertiesSection("Web JVM Properties"), - new JvmStateSection("Web JVM State"), - DbSection.class, - DbConnectionSection.class, - EsIndexesSection.class, - LoggingSection.class, - PluginsSection.class, - SettingsSection.class, - InfoAction.class - - ); - if (standalone) { - add( - EsStateSection.class, - StandaloneSystemSection.class, - StandaloneSystemInfoWriter.class - - ); - } else { - add( - CeQueueGlobalSection.class, - EsClusterStateSection.class, - GlobalSystemSection.class, - NodeSystemSection.class, - - ProcessInfoProvider.class, - GlobalInfoLoader.class, - AppNodesInfoLoaderImpl.class, - SearchNodesInfoLoaderImpl.class, - ClusterSystemInfoWriter.class - - ); - } - } - -} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionModuleTest.java deleted file mode 100644 index d69daf028f5..00000000000 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionModuleTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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 java.util.Collection; -import org.junit.Test; -import org.picocontainer.ComponentAdapter; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.server.platform.WebServer; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.sonar.core.platform.ComponentContainer.COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER; - -public class ChangeLogLevelActionModuleTest { - private WebServer webServer = mock(WebServer.class); - private ChangeLogLevelActionModule underTest = new ChangeLogLevelActionModule(webServer); - - @Test - public void provide_returns_ChangeLogLevelClusterService_if_cluster_not_on_SonarCloud() { - when(webServer.isStandalone()).thenReturn(false); - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - Collection> adapters = container.getPicoContainer().getComponentAdapters(); - assertThat(adapters) - .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 2) - .extracting(ComponentAdapter::getComponentKey) - .contains(ChangeLogLevelClusterService.class, ChangeLogLevelAction.class) - .doesNotContain(ChangeLogLevelStandaloneService.class); - } - - @Test - public void provide_returns_ChangeLogLevelStandaloneService_if_SQ_standalone() { - when(webServer.isStandalone()).thenReturn(true); - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - verifyInStandaloneSQ(container); - } - - private void verifyInStandaloneSQ(ComponentContainer container) { - Collection> adapters = container.getPicoContainer().getComponentAdapters(); - assertThat(adapters) - .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 2) - .extracting(ComponentAdapter::getComponentKey) - .contains(ChangeLogLevelStandaloneService.class, ChangeLogLevelAction.class) - .doesNotContain(ChangeLogLevelClusterService.class); - } - -} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelServiceModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelServiceModuleTest.java new file mode 100644 index 00000000000..9a964e5f01d --- /dev/null +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelServiceModuleTest.java @@ -0,0 +1,71 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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 java.util.Collection; +import org.junit.Test; +import org.picocontainer.ComponentAdapter; +import org.sonar.core.platform.ComponentContainer; +import org.sonar.server.platform.WebServer; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.sonar.core.platform.ComponentContainer.COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER; + +public class ChangeLogLevelServiceModuleTest { + private WebServer webServer = mock(WebServer.class); + private ChangeLogLevelServiceModule underTest = new ChangeLogLevelServiceModule(webServer); + + @Test + public void provide_returns_ChangeLogLevelClusterService_if_cluster_not_on_SonarCloud() { + when(webServer.isStandalone()).thenReturn(false); + ComponentContainer container = new ComponentContainer(); + + underTest.configure(container); + + Collection> adapters = container.getPicoContainer().getComponentAdapters(); + assertThat(adapters) + .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 1) + .extracting(ComponentAdapter::getComponentKey) + .contains(ChangeLogLevelClusterService.class) + .doesNotContain(ChangeLogLevelStandaloneService.class); + } + + @Test + public void provide_returns_ChangeLogLevelStandaloneService_if_SQ_standalone() { + when(webServer.isStandalone()).thenReturn(true); + ComponentContainer container = new ComponentContainer(); + + underTest.configure(container); + + verifyInStandaloneSQ(container); + } + + private void verifyInStandaloneSQ(ComponentContainer container) { + Collection> adapters = container.getPicoContainer().getComponentAdapters(); + assertThat(adapters) + .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 1) + .extracting(ComponentAdapter::getComponentKey) + .contains(ChangeLogLevelStandaloneService.class) + .doesNotContain(ChangeLogLevelClusterService.class); + } + +} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionModuleTest.java deleted file mode 100644 index f628ad95c10..00000000000 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionModuleTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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 java.util.Collection; -import java.util.List; -import java.util.Random; -import java.util.stream.Collectors; -import org.junit.Test; -import org.picocontainer.ComponentAdapter; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.server.health.AppNodeClusterCheck; -import org.sonar.server.health.CeStatusNodeCheck; -import org.sonar.server.health.ClusterHealthCheck; -import org.sonar.server.health.DbConnectionNodeCheck; -import org.sonar.server.health.EsStatusClusterCheck; -import org.sonar.server.health.EsStatusNodeCheck; -import org.sonar.server.health.HealthCheckerImpl; -import org.sonar.server.health.NodeHealthCheck; -import org.sonar.server.health.WebServerStatusNodeCheck; -import org.sonar.server.platform.WebServer; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class HealthActionModuleTest { - private WebServer webServer = mock(WebServer.class); - private HealthActionModule underTest = new HealthActionModule(webServer); - - @Test - public void verify_action_and_HealthChecker() { - boolean standalone = new Random().nextBoolean(); - when(webServer.isStandalone()).thenReturn(standalone); - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - assertThat(classesAddedToContainer(container)) - .describedAs("Verifying action and HealthChecker with standalone=%s", standalone) - .contains(HealthCheckerImpl.class) - .contains(HealthActionSupport.class) - .contains(HealthAction.class) - .doesNotContain(SafeModeHealthAction.class); - } - - @Test - public void verify_installed_NodeHealthChecks_implementations_when_standalone() { - when(webServer.isStandalone()).thenReturn(true); - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - List> checks = classesAddedToContainer(container).stream().filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); - assertThat(checks) - .hasSize(4) - .contains(WebServerStatusNodeCheck.class) - .contains(DbConnectionNodeCheck.class) - .contains(EsStatusNodeCheck.class) - .contains(CeStatusNodeCheck.class); - } - - @Test - public void verify_installed_NodeHealthChecks_implementations_when_clustered() { - when(webServer.isStandalone()).thenReturn(false); - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - List> checks = classesAddedToContainer(container).stream().filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); - assertThat(checks) - .hasSize(3) - .contains(WebServerStatusNodeCheck.class) - .contains(DbConnectionNodeCheck.class) - .contains(CeStatusNodeCheck.class) - .doesNotContain(EsStatusNodeCheck.class); - } - - @Test - public void verify_installed_ClusterHealthChecks_implementations_in_standalone() { - when(webServer.isStandalone()).thenReturn(true); - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - List> checks = classesAddedToContainer(container).stream().filter(ClusterHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); - assertThat(checks).isEmpty(); - } - - @Test - public void verify_installed_ClusterHealthChecks_implementations_in_clustering() { - when(webServer.isStandalone()).thenReturn(false); - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - List> checks = classesAddedToContainer(container).stream().filter(ClusterHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); - assertThat(checks) - .hasSize(2) - .contains(EsStatusClusterCheck.class) - .contains(AppNodeClusterCheck.class); - } - - private List> classesAddedToContainer(ComponentContainer container) { - Collection> componentAdapters = container.getPicoContainer().getComponentAdapters(); - return componentAdapters.stream().map(ComponentAdapter::getComponentImplementation).collect(Collectors.toList()); - } -} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthCheckerModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthCheckerModuleTest.java new file mode 100644 index 00000000000..1819b595dbd --- /dev/null +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthCheckerModuleTest.java @@ -0,0 +1,125 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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 java.util.Collection; +import java.util.List; +import java.util.Random; +import java.util.stream.Collectors; +import org.junit.Test; +import org.picocontainer.ComponentAdapter; +import org.sonar.core.platform.ComponentContainer; +import org.sonar.server.health.AppNodeClusterCheck; +import org.sonar.server.health.CeStatusNodeCheck; +import org.sonar.server.health.ClusterHealthCheck; +import org.sonar.server.health.DbConnectionNodeCheck; +import org.sonar.server.health.EsStatusClusterCheck; +import org.sonar.server.health.EsStatusNodeCheck; +import org.sonar.server.health.HealthCheckerImpl; +import org.sonar.server.health.NodeHealthCheck; +import org.sonar.server.health.WebServerStatusNodeCheck; +import org.sonar.server.platform.WebServer; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class HealthCheckerModuleTest { + private WebServer webServer = mock(WebServer.class); + private HealthCheckerModule underTest = new HealthCheckerModule(webServer); + + @Test + public void verify_HealthChecker() { + boolean standalone = new Random().nextBoolean(); + when(webServer.isStandalone()).thenReturn(standalone); + ComponentContainer container = new ComponentContainer(); + + underTest.configure(container); + + assertThat(classesAddedToContainer(container)) + .describedAs("Verifying action and HealthChecker with standalone=%s", standalone) + .contains(HealthCheckerImpl.class) + .doesNotContain(HealthActionSupport.class) + .doesNotContain(HealthAction.class) + .doesNotContain(SafeModeHealthAction.class); + } + + @Test + public void verify_installed_NodeHealthChecks_implementations_when_standalone() { + when(webServer.isStandalone()).thenReturn(true); + ComponentContainer container = new ComponentContainer(); + + underTest.configure(container); + + List> checks = classesAddedToContainer(container).stream().filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); + assertThat(checks) + .hasSize(4) + .contains(WebServerStatusNodeCheck.class) + .contains(DbConnectionNodeCheck.class) + .contains(EsStatusNodeCheck.class) + .contains(CeStatusNodeCheck.class); + } + + @Test + public void verify_installed_NodeHealthChecks_implementations_when_clustered() { + when(webServer.isStandalone()).thenReturn(false); + ComponentContainer container = new ComponentContainer(); + + underTest.configure(container); + + List> checks = classesAddedToContainer(container).stream().filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); + assertThat(checks) + .hasSize(3) + .contains(WebServerStatusNodeCheck.class) + .contains(DbConnectionNodeCheck.class) + .contains(CeStatusNodeCheck.class) + .doesNotContain(EsStatusNodeCheck.class); + } + + @Test + public void verify_installed_ClusterHealthChecks_implementations_in_standalone() { + when(webServer.isStandalone()).thenReturn(true); + ComponentContainer container = new ComponentContainer(); + + underTest.configure(container); + + List> checks = classesAddedToContainer(container).stream().filter(ClusterHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); + assertThat(checks).isEmpty(); + } + + @Test + public void verify_installed_ClusterHealthChecks_implementations_in_clustering() { + when(webServer.isStandalone()).thenReturn(false); + ComponentContainer container = new ComponentContainer(); + + underTest.configure(container); + + List> checks = classesAddedToContainer(container).stream().filter(ClusterHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); + assertThat(checks) + .hasSize(2) + .contains(EsStatusClusterCheck.class) + .contains(AppNodeClusterCheck.class); + } + + private List> classesAddedToContainer(ComponentContainer container) { + Collection> componentAdapters = container.getPicoContainer().getComponentAdapters(); + return componentAdapters.stream().map(ComponentAdapter::getComponentImplementation).collect(Collectors.toList()); + } +} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/InfoActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/InfoActionTest.java index 8d63f470c41..b4d2eac3ed2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/InfoActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/InfoActionTest.java @@ -38,7 +38,7 @@ public class InfoActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - private SystemInfoWriter jsonWriter = new SystemInfoWriter(null) { + private SystemInfoWriter jsonWriter = new AbstractSystemInfoWriter(null) { @Override public void write(JsonWriter json) { json.prop("key", "value"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionModuleTest.java deleted file mode 100644 index d328fac2e69..00000000000 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionModuleTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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 java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; -import org.junit.Test; -import org.picocontainer.ComponentAdapter; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.server.health.DbConnectionNodeCheck; -import org.sonar.server.health.EsStatusNodeCheck; -import org.sonar.server.health.HealthCheckerImpl; -import org.sonar.server.health.NodeHealthCheck; -import org.sonar.server.health.WebServerSafemodeNodeCheck; - -import static org.assertj.core.api.Assertions.assertThat; - -public class SafeModeHealthActionModuleTest { - private SafeModeHealthActionModule underTest = new SafeModeHealthActionModule(); - - @Test - public void verify_action_and_HealthChecker() { - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - assertThat(classesAddedToContainer(container)) - .contains(HealthCheckerImpl.class) - .contains(HealthActionSupport.class) - .contains(SafeModeHealthAction.class) - .doesNotContain(HealthAction.class); - } - - @Test - public void verify_installed_HealthChecks_implementations() { - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - List> checks = classesAddedToContainer(container).stream().filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); - assertThat(checks) - .hasSize(3) - .contains(WebServerSafemodeNodeCheck.class) - .contains(DbConnectionNodeCheck.class) - .contains(EsStatusNodeCheck.class); - } - - private List> classesAddedToContainer(ComponentContainer container) { - Collection> componentAdapters = container.getPicoContainer().getComponentAdapters(); - return componentAdapters.stream().map(ComponentAdapter::getComponentImplementation).collect(Collectors.toList()); - } - -} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthCheckerModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthCheckerModuleTest.java new file mode 100644 index 00000000000..4506531f52c --- /dev/null +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthCheckerModuleTest.java @@ -0,0 +1,71 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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 java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; +import org.junit.Test; +import org.picocontainer.ComponentAdapter; +import org.sonar.core.platform.ComponentContainer; +import org.sonar.server.health.DbConnectionNodeCheck; +import org.sonar.server.health.EsStatusNodeCheck; +import org.sonar.server.health.HealthCheckerImpl; +import org.sonar.server.health.NodeHealthCheck; +import org.sonar.server.health.WebServerSafemodeNodeCheck; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SafeModeHealthCheckerModuleTest { + private SafeModeHealthCheckerModule underTest = new SafeModeHealthCheckerModule(); + + @Test + public void verify_HealthChecker() { + ComponentContainer container = new ComponentContainer(); + + underTest.configure(container); + + assertThat(classesAddedToContainer(container)) + .contains(HealthCheckerImpl.class) + .doesNotContain(HealthActionSupport.class) + .doesNotContain(SafeModeHealthAction.class) + .doesNotContain(HealthAction.class); + } + + @Test + public void verify_installed_HealthChecks_implementations() { + ComponentContainer container = new ComponentContainer(); + + underTest.configure(container); + + List> checks = classesAddedToContainer(container).stream().filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); + assertThat(checks) + .hasSize(3) + .contains(WebServerSafemodeNodeCheck.class) + .contains(DbConnectionNodeCheck.class) + .contains(EsStatusNodeCheck.class); + } + + private List> classesAddedToContainer(ComponentContainer container) { + Collection> componentAdapters = container.getPicoContainer().getComponentAdapters(); + return componentAdapters.stream().map(ComponentAdapter::getComponentImplementation).collect(Collectors.toList()); + } + +} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafemodeSystemWsModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafemodeSystemWsModuleTest.java new file mode 100644 index 00000000000..066fe788321 --- /dev/null +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafemodeSystemWsModuleTest.java @@ -0,0 +1,36 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.junit.Test; +import org.sonar.core.platform.ComponentContainer; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.core.platform.ComponentContainer.COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER; + +public class SafemodeSystemWsModuleTest { + @Test + public void verify_count_of_added_components() { + ComponentContainer container = new ComponentContainer(); + new SafemodeSystemWsModule().configure(container); + assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 6); + } + +} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SystemInfoWriterModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SystemInfoWriterModuleTest.java new file mode 100644 index 00000000000..664472ef744 --- /dev/null +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SystemInfoWriterModuleTest.java @@ -0,0 +1,65 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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 java.util.Collection; +import org.junit.Test; +import org.picocontainer.ComponentAdapter; +import org.sonar.core.platform.ComponentContainer; +import org.sonar.server.platform.WebServer; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.sonar.core.platform.ComponentContainer.COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER; + +public class SystemInfoWriterModuleTest { + private WebServer webServer = mock(WebServer.class); + private SystemInfoWriterModule underTest = new SystemInfoWriterModule(webServer); + + @Test + public void verify_system_info_configuration_in_cluster_mode() { + when(webServer.isStandalone()).thenReturn(false); + ComponentContainer container = new ComponentContainer(); + + underTest.configure(container); + + Collection> adapters = container.getPicoContainer().getComponentAdapters(); + assertThat(adapters) + .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 17); + } + + @Test + public void verify_system_info_configuration_in_standalone_mode() { + when(webServer.isStandalone()).thenReturn(true); + ComponentContainer container = new ComponentContainer(); + + underTest.configure(container); + + verifyConfigurationStandaloneSQ(container); + } + + public void verifyConfigurationStandaloneSQ(ComponentContainer container) { + Collection> adapters = container.getPicoContainer().getComponentAdapters(); + assertThat(adapters) + .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 11); + } + +} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SystemWsModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SystemWsModuleTest.java new file mode 100644 index 00000000000..855c2adc823 --- /dev/null +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SystemWsModuleTest.java @@ -0,0 +1,37 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.junit.Test; +import org.sonar.core.platform.ComponentContainer; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.core.platform.ComponentContainer.COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER; + +public class SystemWsModuleTest { + @Test + public void verify_count_of_added_components() { + ComponentContainer container = new ComponentContainer(); + new SystemWsModule().configure(container); + assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 12); + } + + +} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java index 733c12cae02..de93a9d8d1e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java @@ -36,7 +36,7 @@ public class SystemWsTest { public void define() { RestartAction action1 = new RestartAction(mock(UserSession.class), mock(ProcessCommandWrapper.class), mock(RestartFlagHolder.class), mock(WebServer.class)); - InfoAction action2 = new InfoAction(new AnonymousMockUserSession(), mock(SystemInfoWriter.class)); + InfoAction action2 = new InfoAction(new AnonymousMockUserSession(), mock(AbstractSystemInfoWriter.class)); SystemWs ws = new SystemWs(action1, action2); WebService.Context context = new WebService.Context(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/WebSystemInfoModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/WebSystemInfoModuleTest.java deleted file mode 100644 index fb6485a6cf3..00000000000 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/WebSystemInfoModuleTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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 java.util.Collection; -import org.junit.Test; -import org.picocontainer.ComponentAdapter; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.server.platform.WebServer; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.sonar.core.platform.ComponentContainer.COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER; - -public class WebSystemInfoModuleTest { - private WebServer webServer = mock(WebServer.class); - private WebSystemInfoModule underTest = new WebSystemInfoModule(webServer); - - @Test - public void verify_system_info_configuration_in_cluster_mode() { - when(webServer.isStandalone()).thenReturn(false); - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - Collection> adapters = container.getPicoContainer().getComponentAdapters(); - assertThat(adapters) - .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 18); - } - - @Test - public void verify_system_info_configuration_in_standalone_mode() { - when(webServer.isStandalone()).thenReturn(true); - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - verifyConfigurationStandaloneSQ(container); - } - - public void verifyConfigurationStandaloneSQ(ComponentContainer container) { - Collection> adapters = container.getPicoContainer().getComponentAdapters(); - assertThat(adapters) - .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 12); - } - -} diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index b72635af2a9..c367e84d711 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -120,19 +120,12 @@ import org.sonar.server.platform.web.DeprecatedPropertiesWsFilter; import org.sonar.server.platform.web.WebServiceFilter; import org.sonar.server.platform.web.WebServiceReroutingFilter; import org.sonar.server.platform.web.requestid.HttpRequestIdModule; -import org.sonar.server.platform.ws.ChangeLogLevelActionModule; -import org.sonar.server.platform.ws.DbMigrationStatusAction; -import org.sonar.server.platform.ws.HealthActionModule; +import org.sonar.server.platform.ws.ChangeLogLevelServiceModule; +import org.sonar.server.platform.ws.HealthCheckerModule; import org.sonar.server.platform.ws.L10nWs; -import org.sonar.server.platform.ws.LogsAction; -import org.sonar.server.platform.ws.MigrateDbAction; -import org.sonar.server.platform.ws.PingAction; -import org.sonar.server.platform.ws.RestartAction; import org.sonar.server.platform.ws.ServerWs; -import org.sonar.server.platform.ws.StatusAction; -import org.sonar.server.platform.ws.SystemWs; -import org.sonar.server.platform.ws.UpgradesAction; -import org.sonar.server.platform.ws.WebSystemInfoModule; +import org.sonar.server.platform.ws.SystemWsModule; +import org.sonar.server.platform.ws.SystemInfoWriterModule; import org.sonar.server.plugins.PluginDownloader; import org.sonar.server.plugins.PluginUninstaller; import org.sonar.server.plugins.ServerExtensionInstaller; @@ -469,16 +462,9 @@ public class PlatformLevel4 extends PlatformLevel { // System ServerLogging.class, - RestartAction.class, - PingAction.class, - UpgradesAction.class, - StatusAction.class, - MigrateDbAction.class, - LogsAction.class, - ChangeLogLevelActionModule.class, - DbMigrationStatusAction.class, - HealthActionModule.class, - SystemWs.class, + ChangeLogLevelServiceModule.class, + HealthCheckerModule.class, + SystemWsModule.class, // Plugins WS PluginUpdateAggregator.class, @@ -537,7 +523,7 @@ public class PlatformLevel4 extends PlatformLevel { ); // system info - add(WebSystemInfoModule.class); + add(SystemInfoWriterModule.class); addAll(level4AddedComponents); } diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelSafeMode.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelSafeMode.java index 81c6adf532e..6eacf03ff4d 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelSafeMode.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelSafeMode.java @@ -27,13 +27,10 @@ import org.sonar.server.platform.db.migration.DatabaseMigrationImpl; import org.sonar.server.platform.db.migration.MigrationEngineModule; import org.sonar.server.platform.db.migration.NoopDatabaseMigrationImpl; import org.sonar.server.platform.web.WebServiceFilter; -import org.sonar.server.platform.ws.DbMigrationStatusAction; import org.sonar.server.platform.ws.IndexAction; import org.sonar.server.platform.ws.L10nWs; -import org.sonar.server.platform.ws.MigrateDbAction; -import org.sonar.server.platform.ws.SafeModeHealthActionModule; -import org.sonar.server.platform.ws.StatusAction; -import org.sonar.server.platform.ws.SystemWs; +import org.sonar.server.platform.ws.SafeModeHealthCheckerModule; +import org.sonar.server.platform.ws.SafemodeSystemWsModule; import org.sonar.server.ws.WebServiceEngine; import org.sonar.server.ws.ws.WebServicesWsModule; @@ -52,11 +49,8 @@ public class PlatformLevelSafeMode extends PlatformLevel { IndexAction.class, // Server WS - StatusAction.class, - MigrateDbAction.class, - DbMigrationStatusAction.class, - SafeModeHealthActionModule.class, - SystemWs.class, + SafeModeHealthCheckerModule.class, + SafemodeSystemWsModule.class, // Listing WS WebServicesWsModule.class,