From b49a62254e8266d1a421ed626851c4f3bb780e0b Mon Sep 17 00:00:00 2001 From: Sébastien Lesaint Date: Tue, 5 Sep 2017 17:19:17 +0200 Subject: SONAR-9741 move NodeType to sonar-cluster --- .../java/org/sonar/cluster/ClusterObjectKeys.java | 2 +- .../src/main/java/org/sonar/cluster/NodeType.java | 49 ++++++++++++++++++++++ .../test/java/org/sonar/cluster/NodeTypeTest.java | 47 +++++++++++++++++++++ .../application/cluster/ClusterProperties.java | 2 +- .../application/cluster/HazelcastCluster.java | 2 +- .../sonar/application/config/ClusterSettings.java | 2 +- .../src/main/java/org/sonar/process/NodeType.java | 49 ---------------------- .../test/java/org/sonar/process/NodeTypeTest.java | 47 --------------------- .../java/org/sonar/server/es/EsClientProvider.java | 4 +- 9 files changed, 102 insertions(+), 102 deletions(-) create mode 100644 server/sonar-cluster/src/main/java/org/sonar/cluster/NodeType.java create mode 100644 server/sonar-cluster/src/test/java/org/sonar/cluster/NodeTypeTest.java delete mode 100644 server/sonar-process/src/main/java/org/sonar/process/NodeType.java delete mode 100644 server/sonar-process/src/test/java/org/sonar/process/NodeTypeTest.java diff --git a/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterObjectKeys.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterObjectKeys.java index ce0a4185850..16464b6c53e 100644 --- a/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterObjectKeys.java +++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterObjectKeys.java @@ -51,7 +51,7 @@ public final class ClusterObjectKeys { public static final String NODE_NAME = "NODE_NAME"; /** * The role of the sonar-application inside the SonarQube cluster - * {@link org.sonar.process.NodeType} + * {@link org.sonar.cluster.NodeType} */ public static final String NODE_TYPE = "NODE_TYPE"; /** diff --git a/server/sonar-cluster/src/main/java/org/sonar/cluster/NodeType.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/NodeType.java new file mode 100644 index 00000000000..6a2ce537c34 --- /dev/null +++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/NodeType.java @@ -0,0 +1,49 @@ +/* + * 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.cluster; + +import static java.util.Arrays.stream; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; + +public enum NodeType { + APPLICATION("application"), SEARCH("search"); + + private final String value; + + NodeType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static NodeType parse(String nodeType) { + return stream(values()) + .filter(t -> nodeType.equals(t.value)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("Invalid value for [" + CLUSTER_NODE_TYPE + "]: [" + nodeType + "]")); + } + + public static boolean isValid(String nodeType) { + return stream(values()) + .anyMatch(t -> nodeType.equals(t.value)); + } +} diff --git a/server/sonar-cluster/src/test/java/org/sonar/cluster/NodeTypeTest.java b/server/sonar-cluster/src/test/java/org/sonar/cluster/NodeTypeTest.java new file mode 100644 index 00000000000..12d9e6a5be1 --- /dev/null +++ b/server/sonar-cluster/src/test/java/org/sonar/cluster/NodeTypeTest.java @@ -0,0 +1,47 @@ +/* + * 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.cluster; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class NodeTypeTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void test_parse() { + assertThat(NodeType.parse("application")).isEqualTo(NodeType.APPLICATION); + assertThat(NodeType.parse("search")).isEqualTo(NodeType.SEARCH); + } + + @Test + public void parse_an_unknown_value_must_throw_IAE() { + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Invalid value for "); + + NodeType.parse("XYZ"); + } +} diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java index bb25b4f9a0b..4f7dc00e876 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java @@ -31,7 +31,7 @@ import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.application.config.AppSettings; -import org.sonar.process.NodeType; +import org.sonar.cluster.NodeType; import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java index 98f279e6e1e..6625cd2e926 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java @@ -53,7 +53,7 @@ import org.sonar.application.AppStateListener; import org.sonar.cluster.ClusterObjectKeys; import org.sonar.cluster.localclient.HazelcastClient; import org.sonar.process.MessageException; -import org.sonar.process.NodeType; +import org.sonar.cluster.NodeType; import org.sonar.process.ProcessId; import static java.lang.String.format; diff --git a/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java b/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java index d8ec697ddc7..3eb66a2d1b1 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java @@ -31,7 +31,7 @@ import java.util.List; import java.util.function.Consumer; import org.apache.commons.lang.StringUtils; import org.sonar.process.MessageException; -import org.sonar.process.NodeType; +import org.sonar.cluster.NodeType; import org.sonar.process.ProcessId; import org.sonar.process.Props; diff --git a/server/sonar-process/src/main/java/org/sonar/process/NodeType.java b/server/sonar-process/src/main/java/org/sonar/process/NodeType.java deleted file mode 100644 index ecd8e44bc95..00000000000 --- a/server/sonar-process/src/main/java/org/sonar/process/NodeType.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.process; - -import static java.util.Arrays.stream; -import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; - -public enum NodeType { - APPLICATION("application"), SEARCH("search"); - - private final String value; - - NodeType(String value) { - this.value = value; - } - - public String getValue() { - return value; - } - - public static NodeType parse(String nodeType) { - return stream(values()) - .filter(t -> nodeType.equals(t.value)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException("Invalid value for [" + CLUSTER_NODE_TYPE + "]: [" + nodeType + "]")); - } - - public static boolean isValid(String nodeType) { - return stream(values()) - .anyMatch(t -> nodeType.equals(t.value)); - } -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/NodeTypeTest.java b/server/sonar-process/src/test/java/org/sonar/process/NodeTypeTest.java deleted file mode 100644 index 180600a5ecb..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/NodeTypeTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.process; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.assertj.core.api.Assertions.assertThat; - -public class NodeTypeTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void test_parse() { - assertThat(NodeType.parse("application")).isEqualTo(NodeType.APPLICATION); - assertThat(NodeType.parse("search")).isEqualTo(NodeType.SEARCH); - } - - @Test - public void parse_an_unknown_value_must_throw_IAE() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Invalid value for "); - - NodeType.parse("XYZ"); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java b/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java index 138ea698fcd..110ae95f6fa 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java @@ -34,14 +34,14 @@ import org.sonar.api.config.Configuration; import org.sonar.api.server.ServerSide; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; -import org.sonar.process.NodeType; +import org.sonar.cluster.NodeType; import org.sonar.process.ProcessProperties; import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; -import static org.sonar.process.NodeType.SEARCH; +import static org.sonar.cluster.NodeType.SEARCH; @ComputeEngineSide @ServerSide -- cgit v1.2.3