]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9802 Fix quality flaws
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Thu, 21 Sep 2017 07:53:43 +0000 (09:53 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 26 Sep 2017 21:49:38 +0000 (23:49 +0200)
33 files changed:
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
server/sonar-main/src/main/java/org/sonar/application/AppStateImpl.java
server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java
server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java
server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java
server/sonar-main/src/test/java/org/sonar/application/TestAppState.java
server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java
server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java
server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java
server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java
server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java
server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java
server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java
server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java
server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java
server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java
server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastObjects.java
server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java
server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java
server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java
server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java
server/sonar-server/src/main/java/org/sonar/server/platform/ServerLogging.java
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/OfficialDistribution.java
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/ProcessInfoProvider.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java
server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java
server/sonar-server/src/test/java/org/sonar/server/cluster/StartableHazelcastMemberTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/OfficialDistributionTest.java
tests/src/test/java/org/sonarqube/tests/Byteman.java
tests/src/test/java/org/sonarqube/tests/settings/ElasticsearchSettingsTest.java

index b62dca5b43002d443cab8bb7892c25d3e01ffc09..c5e45edfa256d53088c6a00361d378d247927fc3 100644 (file)
@@ -73,7 +73,7 @@ import org.sonar.db.DatabaseChecker;
 import org.sonar.db.DbClient;
 import org.sonar.db.DefaultDatabase;
 import org.sonar.db.purge.PurgeProfiler;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 import org.sonar.process.logging.LogbackHelper;
@@ -127,8 +127,8 @@ import org.sonar.server.platform.WebServerImpl;
 import org.sonar.server.platform.db.migration.MigrationConfigurationModule;
 import org.sonar.server.platform.db.migration.version.DatabaseVersion;
 import org.sonar.server.platform.monitoring.DatabaseSection;
-import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider;
 import org.sonar.server.platform.monitoring.cluster.LoggingSection;
+import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider;
 import org.sonar.server.plugins.InstalledPluginReferentialFactory;
 import org.sonar.server.plugins.ServerExtensionInstaller;
 import org.sonar.server.plugins.privileged.PrivilegedPluginsBootstraper;
@@ -238,7 +238,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
       SonarRuntimeImpl.forSonarQube(ApiVersion.load(System2.INSTANCE), SonarQubeSide.COMPUTE_ENGINE),
       CeProcessLogging.class,
       UuidFactoryImpl.INSTANCE,
-      NetworkUtils.INSTANCE,
+      NetworkUtilsImpl.INSTANCE,
       WebServerImpl.class,
       LogbackHelper.class,
       DefaultDatabase.class,
index 4cf1cac4434993295b9652abb4df6a7fd3d31243..c10b6f94c6d633b7a4861018de2b41c88852651f 100644 (file)
@@ -42,7 +42,7 @@ import org.sonar.ce.CeDistributedInformationImpl;
 import org.sonar.ce.StandaloneCeDistributedInformation;
 import org.sonar.db.DbTester;
 import org.sonar.db.property.PropertyDto;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.ProcessId;
 import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
@@ -87,7 +87,7 @@ public class ComputeEngineContainerImplTest {
 
   @Test
   public void real_start_with_cluster() throws IOException {
-    Optional<InetAddress> localhost = NetworkUtils.INSTANCE.getLocalNonLoopbackIpv4Address();
+    Optional<InetAddress> localhost = NetworkUtilsImpl.INSTANCE.getLocalNonLoopbackIpv4Address();
     // test is ignored if offline
     assumeThat(localhost.isPresent(), CoreMatchers.is(true));
 
@@ -96,7 +96,7 @@ public class ComputeEngineContainerImplTest {
     properties.setProperty(CLUSTER_ENABLED, "true");
     properties.setProperty(CLUSTER_NODE_TYPE, "application");
     properties.setProperty(CLUSTER_NODE_HOST, localhost.get().getHostAddress());
-    properties.setProperty(CLUSTER_NODE_PORT, "" + NetworkUtils.INSTANCE.getNextAvailablePort(localhost.get()));
+    properties.setProperty(CLUSTER_NODE_PORT, "" + NetworkUtilsImpl.INSTANCE.getNextAvailablePort(localhost.get()));
 
     // required persisted properties
     insertProperty(CoreProperties.SERVER_ID, "a_startup_id");
index 942abe0bc8a30d43c55903771797bbed61e33dd4..d1f3936a6da1e4e6184fb0a720634486e15aa8ce 100644 (file)
@@ -26,7 +26,7 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.atomic.AtomicBoolean;
 import javax.annotation.Nonnull;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.ProcessId;
 
 public class AppStateImpl implements AppState {
@@ -74,7 +74,7 @@ public class AppStateImpl implements AppState {
 
   @Override
   public Optional<String> getLeaderHostName() {
-    return Optional.of(NetworkUtils.INSTANCE.getHostname());
+    return Optional.of(NetworkUtilsImpl.INSTANCE.getHostname());
   }
 
   @Override
index 3c23a5501eb99c17968c6c71991010658b5eb7e8..2876b2eccbcf357b9d20ee283da157c8b741adf6 100644 (file)
@@ -45,12 +45,15 @@ import org.sonar.application.cluster.health.SearchNodeHealthProvider;
 import org.sonar.application.config.AppSettings;
 import org.sonar.application.config.ClusterSettings;
 import org.sonar.process.MessageException;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.ProcessId;
 import org.sonar.process.cluster.NodeType;
 import org.sonar.process.cluster.hz.HazelcastMember;
 
 import static java.lang.String.format;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.HOSTNAME;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.IP_ADDRESSES;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_TYPE;
 import static org.sonar.process.cluster.hz.HazelcastObjects.CLUSTER_NAME;
 import static org.sonar.process.cluster.hz.HazelcastObjects.LEADER;
 import static org.sonar.process.cluster.hz.HazelcastObjects.OPERATIONAL_PROCESSES;
@@ -77,7 +80,7 @@ public class ClusterAppStateImpl implements ClusterAppState {
     nodeDisconnectedListenerUUID = hzMember.getCluster().addMembershipListener(new NodeDisconnectedListener());
 
     if (ClusterSettings.isLocalElasticsearchEnabled(settings)) {
-      this.healthStateSharing = new HealthStateSharingImpl(hzMember, new SearchNodeHealthProvider(settings.getProps(), this, NetworkUtils.INSTANCE));
+      this.healthStateSharing = new HealthStateSharingImpl(hzMember, new SearchNodeHealthProvider(settings.getProps(), this, NetworkUtilsImpl.INSTANCE));
       this.healthStateSharing.start();
     }
   }
@@ -187,7 +190,7 @@ public class ClusterAppStateImpl implements ClusterAppState {
       Optional<Member> leader = hzMember.getCluster().getMembers().stream().filter(m -> m.getUuid().equals(leaderId)).findFirst();
       if (leader.isPresent()) {
         return Optional.of(
-          format("%s (%s)", leader.get().getStringAttribute(HazelcastMember.Attribute.HOSTNAME), leader.get().getStringAttribute(HazelcastMember.Attribute.IP_ADDRESSES)));
+          format("%s (%s)", leader.get().getStringAttribute(HOSTNAME.getKey()), leader.get().getStringAttribute(IP_ADDRESSES.getKey())));
       }
     }
     return Optional.empty();
@@ -278,7 +281,7 @@ public class ClusterAppStateImpl implements ClusterAppState {
     }
 
     private boolean isAppNode(Member member) {
-      return NodeType.APPLICATION.getValue().equals(member.getStringAttribute(HazelcastMember.Attribute.NODE_TYPE));
+      return NodeType.APPLICATION.getValue().equals(member.getStringAttribute(NODE_TYPE.getKey()));
     }
 
     private void removeOperationalProcess(String uuid) {
index 801e61410ace9d0b256997d9933f66a4fa50598a..006c512b7bca5e9251d8bfca466e34d6b58c2fe2 100644 (file)
@@ -30,7 +30,7 @@ import java.util.Properties;
 import java.util.function.Consumer;
 import org.slf4j.LoggerFactory;
 import org.sonar.process.ConfigurationUtils;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
@@ -44,7 +44,7 @@ public class AppSettingsLoaderImpl implements AppSettingsLoader {
 
   public AppSettingsLoaderImpl(String[] cliArguments) {
     this(cliArguments, detectHomeDir(),
-      new FileSystemSettings(), new JdbcSettings(), new ClusterSettings(NetworkUtils.INSTANCE));
+      new FileSystemSettings(), new JdbcSettings(), new ClusterSettings(NetworkUtilsImpl.INSTANCE));
   }
 
   AppSettingsLoaderImpl(String[] cliArguments, File homeDir, Consumer<Props>... consumers) {
index 8919ed84c75dce6d112244329db1d8329af55991..86080ff87da4441f132b7d46f3b1cea8075c7991 100644 (file)
@@ -25,7 +25,7 @@ import org.hamcrest.CoreMatchers;
 import org.junit.Test;
 import org.sonar.application.cluster.ClusterAppStateImpl;
 import org.sonar.application.config.TestAppSettings;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assume.assumeThat;
@@ -42,7 +42,7 @@ public class AppStateFactoryTest {
 
   @Test
   public void create_cluster_implementation_if_cluster_is_enabled() {
-    Optional<InetAddress> ip = NetworkUtils.INSTANCE.getLocalNonLoopbackIpv4Address();
+    Optional<InetAddress> ip = NetworkUtilsImpl.INSTANCE.getLocalNonLoopbackIpv4Address();
     assumeThat(ip.isPresent(), CoreMatchers.is(true));
 
     settings.set(CLUSTER_ENABLED, "true");
index ee6e3e9cfa1400e130ab4008ed7c9eff2f6956e6..b0b9464261962f88d4fba96ecc995e67fcd21fec 100644 (file)
@@ -26,7 +26,7 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.atomic.AtomicBoolean;
 import javax.annotation.Nonnull;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.ProcessId;
 
 public class TestAppState implements AppState {
@@ -84,7 +84,7 @@ public class TestAppState implements AppState {
 
   @Override
   public Optional<String> getLeaderHostName() {
-    return Optional.of(NetworkUtils.INSTANCE.getHostname());
+    return Optional.of(NetworkUtilsImpl.INSTANCE.getHostname());
   }
 
   @Override
index bf93a7b88c5b2619df334b3d12cd2b68f3a61913..ba85353df39d4877d50d05bf6aa1f62cadb5837a 100644 (file)
@@ -29,7 +29,7 @@ import org.junit.rules.Timeout;
 import org.sonar.application.AppStateListener;
 import org.sonar.application.config.TestAppSettings;
 import org.sonar.process.MessageException;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.ProcessId;
 import org.sonar.process.cluster.NodeType;
 import org.sonar.process.cluster.hz.HazelcastMember;
@@ -143,7 +143,7 @@ public class ClusterAppStateImplTest {
       .setProcessId(ProcessId.COMPUTE_ENGINE)
       .setClusterName("foo")
       .setNodeName("bar")
-      .setPort(NetworkUtils.INSTANCE.getNextAvailablePort(loopback))
+      .setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback))
       .setNetworkInterface(loopback.getHostAddress())
       .build();
   }
index 245b935d5a83b7f12739d3a286d2c4635640183d..4895083944cd7b23fb4ce953ba48dcc2f1b491ac 100644 (file)
@@ -30,6 +30,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.process.MessageException;
 import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.ProcessProperties;
 
 import static org.junit.Assume.assumeThat;
@@ -49,7 +50,7 @@ public class ClusterSettingsLoopbackTest {
 
   private InetAddress loopback = InetAddress.getLoopbackAddress();
   private InetAddress nonLoopbackLocal;
-  private NetworkUtils network = spy(NetworkUtils.INSTANCE);
+  private NetworkUtils network = spy(NetworkUtilsImpl.INSTANCE);
 
   @Before
   public void setUp() throws Exception {
index f3f528da701b68978758b2eebcd153bdf0ed5c33..c7088c507ec578ab45332e9aaaec709c96089dbd 100644 (file)
@@ -27,6 +27,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.process.MessageException;
 import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 
 import static java.lang.String.format;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -49,7 +50,7 @@ public class ClusterSettingsTest {
   public ExpectedException expectedException = ExpectedException.none();
 
   private InetAddress nonLoopbackLocal = InetAddress.getLoopbackAddress();
-  private NetworkUtils network = spy(NetworkUtils.INSTANCE);
+  private NetworkUtils network = spy(NetworkUtilsImpl.INSTANCE);
 
   @Before
   public void setUp() throws Exception {
index 7d4fc4d51f33e40599bba8606da5f67d5835a5ee..234b930d2419a11e69c85f80aa98aa7332f69bea 100644 (file)
@@ -27,7 +27,6 @@ import java.util.Optional;
 import java.util.function.Predicate;
 
 public interface NetworkUtils {
-  NetworkUtils INSTANCE = new NetworkUtilsImpl();
 
   int getNextAvailablePort(InetAddress address);
 
index 9da928a7c9dc2ddae0d8fd53a72ed205ea7ac565..3f7d6892f35cf66d06bd50b186ec26323fbb810c 100644 (file)
@@ -40,6 +40,7 @@ import static org.apache.commons.lang.StringUtils.isBlank;
 
 public class NetworkUtilsImpl implements NetworkUtils {
 
+  public static final NetworkUtils INSTANCE = new NetworkUtilsImpl();
   private static final Set<Integer> PORTS_ALREADY_ALLOCATED = new HashSet<>();
   private static final int PORT_MAX_TRIES = 50;
 
index 5d90670108ab86ad03fd0263ceac25bc1933c3ed..012474d50d72db14cfade333380ea4dcd4b4ca89 100644 (file)
@@ -135,7 +135,7 @@ public class ProcessProperties {
     if ("0".equals(port)) {
       String address = props.nonNullValue(addressPropertyKey);
       try {
-        props.set(portPropertyKey, String.valueOf(NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getByName(address))));
+        props.set(portPropertyKey, String.valueOf(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getByName(address))));
       } catch (UnknownHostException e) {
         throw new IllegalStateException("Cannot resolve address [" + address + "] set by property [" + addressPropertyKey + "]", e);
       }
index f5a0bc920c87319977871d754867618ee6a5c37a..526b17ee183d59deacaac0297a2af494e2b911da 100644 (file)
@@ -30,6 +30,8 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
 
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_NAME;
+
 /**
  * Answer of {@link DistributedCall}, aggregating the answers from
  * all the target members.
@@ -75,7 +77,7 @@ public class DistributedAnswer<T> {
   public void propagateExceptions() {
     if (!failedMembers.isEmpty()) {
       String failedMemberNames = failedMembers.keySet().stream()
-        .map(m -> m.getStringAttribute(HazelcastMember.Attribute.NODE_NAME))
+        .map(m -> m.getStringAttribute(NODE_NAME.getKey()))
         .collect(Collectors.joining(", "));
       throw new IllegalStateException("Distributed cluster action in cluster nodes " + failedMemberNames + " (other nodes may have timed out)",
         failedMembers.values().iterator().next());
@@ -83,7 +85,7 @@ public class DistributedAnswer<T> {
 
     if (!timedOutMembers.isEmpty()) {
       String timedOutMemberNames = timedOutMembers.stream()
-        .map(m -> m.getStringAttribute(HazelcastMember.Attribute.NODE_NAME))
+        .map(m -> m.getStringAttribute(NODE_NAME.getKey()))
         .collect(Collectors.joining(", "));
       throw new IllegalStateException("Distributed cluster action timed out in cluster nodes " + timedOutMemberNames);
     }
index 0a70741d02067bcb5a2cde7fe21d68e8aa490102..d2e081d4443e02ac566910659b1f4219d246a369 100644 (file)
@@ -31,28 +31,38 @@ import org.sonar.process.cluster.NodeType;
 
 public interface HazelcastMember extends AutoCloseable {
 
-  interface Attribute {
+  enum Attribute {
     /**
      * The key of the hostname attribute of a member
      */
-    String HOSTNAME = "HOSTNAME";
+    HOSTNAME("HOSTNAME"),
     /**
      * The key of the ips list attribute of a member
      */
-    String IP_ADDRESSES = "IP_ADDRESSES";
+    IP_ADDRESSES("IP_ADDRESSES"),
     /**
      * The key of the node name attribute of a member
      */
-    String NODE_NAME = "NODE_NAME";
+    NODE_NAME("NODE_NAME"),
     /**
      * The role of the sonar-application inside the SonarQube cluster
      * {@link NodeType}
      */
-    String NODE_TYPE = "NODE_TYPE";
+    NODE_TYPE("NODE_TYPE"),
     /**
      * Key of process as defined by {@link ProcessId#getKey()}
      */
-    String PROCESS_KEY = "PROCESS_KEY";
+    PROCESS_KEY("PROCESS_KEY");
+
+    private final String key;
+
+    Attribute(String key) {
+      this.key = key;
+    }
+
+    public String getKey() {
+      return key;
+    }
   }
 
   <E> IAtomicReference<E> getAtomicReference(String name);
index 806b0d7cf8e41f9ce72921cbddf691b77529c6f6..55a5dd0a4edf0db7e77bed0ddecf30854a10dbce 100644 (file)
@@ -29,7 +29,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.stream.Collectors;
 import javax.annotation.CheckForNull;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.ProcessId;
 import org.sonar.process.ProcessProperties;
 import org.sonar.process.cluster.NodeType;
@@ -130,11 +130,11 @@ public class HazelcastMemberBuilder {
       .setProperty("hazelcast.logging.type", "slf4j");
 
     MemberAttributeConfig attributes = config.getMemberAttributeConfig();
-    attributes.setStringAttribute(Attribute.HOSTNAME, NetworkUtils.INSTANCE.getHostname());
-    attributes.setStringAttribute(Attribute.IP_ADDRESSES, NetworkUtils.INSTANCE.getIPAddresses());
-    attributes.setStringAttribute(Attribute.NODE_NAME, requireNonNull(nodeName, "Node name is missing"));
-    attributes.setStringAttribute(Attribute.NODE_TYPE, requireNonNull(nodeType, "Node type is missing").getValue());
-    attributes.setStringAttribute(Attribute.PROCESS_KEY, requireNonNull(processId, "Process key is missing").getKey());
+    attributes.setStringAttribute(Attribute.HOSTNAME.getKey(), NetworkUtilsImpl.INSTANCE.getHostname());
+    attributes.setStringAttribute(Attribute.IP_ADDRESSES.getKey(), NetworkUtilsImpl.INSTANCE.getIPAddresses());
+    attributes.setStringAttribute(Attribute.NODE_NAME.getKey(), requireNonNull(nodeName, "Node name is missing"));
+    attributes.setStringAttribute(Attribute.NODE_TYPE.getKey(), requireNonNull(nodeType, "Node type is missing").getValue());
+    attributes.setStringAttribute(Attribute.PROCESS_KEY.getKey(), requireNonNull(processId, "Process key is missing").getKey());
 
     return new HazelcastMemberImpl(Hazelcast.newHazelcastInstance(config));
   }
index 3b7abe59f892830a03b914e273af8bc70a0fb7e7..222ea28e7f9a828fd8bc3d3999efee421c3dbcaa 100644 (file)
@@ -25,6 +25,7 @@ import org.sonar.process.ProcessId;
 
 import static java.util.Arrays.asList;
 import static org.sonar.process.ProcessId.fromKey;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.PROCESS_KEY;
 
 public class HazelcastMemberSelectors {
 
@@ -34,7 +35,7 @@ public class HazelcastMemberSelectors {
   public static MemberSelector selectorForProcessIds(ProcessId... processIds) {
     List<ProcessId> processIdList = asList(processIds);
     return member -> {
-      ProcessId memberProcessId = fromKey(member.getStringAttribute(HazelcastMember.Attribute.PROCESS_KEY));
+      ProcessId memberProcessId = fromKey(member.getStringAttribute(PROCESS_KEY.getKey()));
       return processIdList.contains(memberProcessId);
     };
   }
index 97e5952b8d781ceb45d3e35c95d79dcc74140aa7..ddcf39bc12617e8239ed834f834142ee81ec8a79 100644 (file)
@@ -20,9 +20,6 @@
 
 package org.sonar.process.cluster.hz;
 
-import org.sonar.process.ProcessId;
-import org.sonar.process.cluster.NodeType;
-
 /**
  * This class holds all object keys accessible via Hazelcast
  */
index 2cdf3d5dd752d4eb4ec298e4a2f522fba99b16f6..5b45fc8a6a81b1ed06c4d205d079f9feee016c5a 100644 (file)
@@ -28,6 +28,7 @@ import org.junit.rules.ExpectedException;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_NAME;
 
 
 public class DistributedAnswerTest {
@@ -133,7 +134,7 @@ public class DistributedAnswerTest {
   private static Member newMember(String uuid) {
     Member member = mock(Member.class);
     when(member.getUuid()).thenReturn(uuid);
-    when(member.getStringAttribute(HazelcastMember.Attribute.NODE_NAME)).thenReturn(uuid);
+    when(member.getStringAttribute(NODE_NAME.getKey())).thenReturn(uuid);
     return member;
   }
 }
index 9316ad6d3e07364a1ab89dd6c915773b27dcb9cc..6a4973b8d13926eeeec9b09e9e79a202b87c0d89 100644 (file)
@@ -25,7 +25,7 @@ import org.junit.Test;
 import org.junit.rules.DisableOnDebug;
 import org.junit.rules.TestRule;
 import org.junit.rules.Timeout;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.ProcessId;
 import org.sonar.process.ProcessProperties;
 import org.sonar.process.cluster.NodeType;
@@ -49,7 +49,7 @@ public class HazelcastMemberBuilderTest {
       .setProcessId(ProcessId.COMPUTE_ENGINE)
       .setClusterName("foo")
       .setNodeName("bar")
-      .setPort(NetworkUtils.INSTANCE.getNextAvailablePort(loopback))
+      .setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback))
       .setNetworkInterface(loopback.getHostAddress())
       .build();
 
index 72087914a8ec2a5c8706aa58577b86fd6cf8dfbf..4d83a82f2333078ca8ed7cd771bd1d042da458cd 100644 (file)
@@ -35,7 +35,7 @@ import org.junit.rules.DisableOnDebug;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TestRule;
 import org.junit.rules.Timeout;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.ProcessId;
 import org.sonar.process.cluster.NodeType;
 
@@ -56,9 +56,9 @@ public class HazelcastMemberImplTest {
 
   @BeforeClass
   public static void setUp() throws Exception {
-    int port1 = NetworkUtils.INSTANCE.getNextAvailablePort(loopback);
-    int port2 = NetworkUtils.INSTANCE.getNextAvailablePort(loopback);
-    int port3 = NetworkUtils.INSTANCE.getNextAvailablePort(loopback);
+    int port1 = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback);
+    int port2 = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback);
+    int port3 = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback);
     member1 = newHzMember(port1, port2, port3);
     member2 = newHzMember(port2, port1, port3);
     member3 = newHzMember(port3, port1, port2);
index 309e3463a3251d0de22ccda4ced82b45ec7199dc..ce5c36de367fc3a7087482b8ad4357d174197546 100644 (file)
@@ -38,13 +38,13 @@ public class HazelcastMemberSelectorsTest {
     Member member = mock(Member.class);
     MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(COMPUTE_ENGINE);
 
-    when(member.getStringAttribute(PROCESS_KEY)).thenReturn(COMPUTE_ENGINE.getKey());
+    when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey());
     assertThat(underTest.select(member)).isTrue();
 
-    when(member.getStringAttribute(PROCESS_KEY)).thenReturn(WEB_SERVER.getKey());
+    when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey());
     assertThat(underTest.select(member)).isFalse();
 
-    when(member.getStringAttribute(PROCESS_KEY)).thenReturn(APP.getKey());
+    when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey());
     assertThat(underTest.select(member)).isFalse();
   }
 
@@ -53,13 +53,13 @@ public class HazelcastMemberSelectorsTest {
     Member member = mock(Member.class);
     MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(WEB_SERVER, APP);
 
-    when(member.getStringAttribute(PROCESS_KEY)).thenReturn(COMPUTE_ENGINE.getKey());
+    when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey());
     assertThat(underTest.select(member)).isFalse();
 
-    when(member.getStringAttribute(PROCESS_KEY)).thenReturn(WEB_SERVER.getKey());
+    when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey());
     assertThat(underTest.select(member)).isTrue();
 
-    when(member.getStringAttribute(PROCESS_KEY)).thenReturn(APP.getKey());
+    when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey());
     assertThat(underTest.select(member)).isTrue();
   }
 }
\ No newline at end of file
index c7da8f500859493f7bf154b884261de2cfde3c7c..5075fff884ce74fa691f0fab94b512d98405d9c2 100644 (file)
@@ -42,7 +42,7 @@ import static org.sonar.api.utils.log.LoggerLevel.TRACE;
 public class ServerLogging implements Startable {
 
   /** Used for Hazelcast's distributed queries in cluster mode */
-  private static ServerLogging INSTANCE;
+  private static ServerLogging instance;
   private final LogbackHelper helper;
   private final Configuration config;
   private final ServerProcessLogging serverProcessLogging;
@@ -62,16 +62,16 @@ public class ServerLogging implements Startable {
 
   @Override
   public void start() {
-    INSTANCE = this;
+    instance = this;
   }
 
   @Override
   public void stop() {
-    INSTANCE = null;
+    instance = null;
   }
 
   public static void changeLevelFromHazelcastDistributedQuery(LoggerLevel level) {
-    INSTANCE.changeLevel(level);
+    instance.changeLevel(level);
   }
 
   public void changeLevel(LoggerLevel level) {
index 4120fcda0f42fd08ff338d261f6980c1c819cc8c..5d90aadf749ad23ab108b3364429877f9958cfa9 100644 (file)
 package org.sonar.server.platform.monitoring;
 
 import java.io.File;
-import org.sonar.api.platform.Server;
 import org.sonar.api.server.ServerSide;
+import org.sonar.server.platform.ServerFileSystem;
 
 @ServerSide
 public class OfficialDistribution {
   static final String BRANDING_FILE_PATH = "web/WEB-INF/classes/com/sonarsource/branding";
 
-  private final Server server;
+  private final ServerFileSystem serverFileSystem;
 
-  public OfficialDistribution(Server server) {
-    this.server = server;
+  public OfficialDistribution(ServerFileSystem serverFileSystem) {
+    this.serverFileSystem = serverFileSystem;
   }
 
   public boolean check() {
     // the dependency com.sonarsource:sonarsource-branding is shaded to webapp
     // during release (see sonar-web pom)
-    File brandingFile = new File(server.getRootDir(), BRANDING_FILE_PATH);
+    File brandingFile = new File(serverFileSystem.getHomeDir(), BRANDING_FILE_PATH);
     // no need to check that the file exists. java.io.File#length() returns zero in this case.
     return brandingFile.length() > 0L;
   }
index 67c943028f01b1eb960b6ca687f68ed4f3a3d843..bb545a764eb7eeacb1de98bf6f6049e636144b78 100644 (file)
@@ -31,6 +31,9 @@ import org.sonar.process.cluster.hz.DistributedAnswer;
 import org.sonar.process.cluster.hz.HazelcastMember;
 import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
 
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_NAME;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.PROCESS_KEY;
+
 @ServerSide
 public class AppNodesInfoLoaderImpl implements AppNodesInfoLoader {
 
@@ -45,7 +48,7 @@ public class AppNodesInfoLoaderImpl implements AppNodesInfoLoader {
       Map<String, NodeInfo> nodesByName = new HashMap<>();
       DistributedAnswer<ProtobufSystemInfo.SystemInfo> distributedAnswer = hzMember.call(ProcessInfoProvider::provide, new CeWebMemberSelector(), 15_000L);
       for (Member member : distributedAnswer.getMembers()) {
-        String nodeName = member.getStringAttribute(HazelcastMember.Attribute.NODE_NAME);
+        String nodeName = member.getStringAttribute(NODE_NAME.getKey());
         NodeInfo nodeInfo = nodesByName.get(nodeName);
         if (nodeInfo == null) {
           nodeInfo = new NodeInfo(nodeName);
@@ -76,7 +79,7 @@ public class AppNodesInfoLoaderImpl implements AppNodesInfoLoader {
   private static class CeWebMemberSelector implements MemberSelector {
     @Override
     public boolean select(Member member) {
-      String processKey = member.getStringAttribute(HazelcastMember.Attribute.PROCESS_KEY);
+      String processKey = member.getStringAttribute(PROCESS_KEY.getKey());
       return processKey.equals(ProcessId.WEB_SERVER.getKey()) || processKey.equals(ProcessId.COMPUTE_ENGINE.getKey());
     }
   }
index 3f4350c66191f17ec385b873daff8f438f0069bc..a2f106b5a4f7c7abd94a3b4f8914b96694f9cc06 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
 public class ProcessInfoProvider implements Startable {
 
   /** Used for Hazelcast's distributed queries in cluster mode */
-  private static ProcessInfoProvider INSTANCE;
+  private static ProcessInfoProvider instance;
   private final List<SystemInfoSection> sections;
 
   public ProcessInfoProvider(SystemInfoSection[] sections) {
@@ -45,17 +45,17 @@ public class ProcessInfoProvider implements Startable {
 
   @Override
   public void start() {
-    INSTANCE = this;
+    instance = this;
   }
 
   @Override
   public void stop() {
-    INSTANCE = null;
+    instance = null;
   }
 
   public static ProtobufSystemInfo.SystemInfo provide() {
     ProtobufSystemInfo.SystemInfo.Builder protobuf = ProtobufSystemInfo.SystemInfo.newBuilder();
-    INSTANCE.sections.forEach(section -> protobuf.addSections(section.toProtobuf()));
+    instance.sections.forEach(section -> protobuf.addSections(section.toProtobuf()));
     return protobuf.build();
   }
 }
index 56e312902294859d5b52a915745565c454fb728e..87bfb90d1e7303f97601a962f5668a4b643697ef 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.platform.platformlevel;
 import java.time.Clock;
 import java.util.Properties;
 import javax.annotation.Nullable;
-import org.sonar.process.NetworkUtils;
 import org.sonar.api.SonarQubeSide;
 import org.sonar.api.SonarQubeVersion;
 import org.sonar.api.internal.ApiVersion;
@@ -40,6 +39,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DefaultDatabase;
 import org.sonar.db.purge.PurgeProfiler;
 import org.sonar.db.semaphore.SemaphoresImpl;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.logging.LogbackHelper;
 import org.sonar.server.app.ProcessCommandWrapperImpl;
 import org.sonar.server.app.RestartFlagHolderImpl;
@@ -86,7 +86,7 @@ public class PlatformLevel1 extends PlatformLevel {
       ProcessCommandWrapperImpl.class,
       RestartFlagHolderImpl.class,
       UuidFactoryImpl.INSTANCE,
-      NetworkUtils.INSTANCE,
+      NetworkUtilsImpl.INSTANCE,
       UrlSettings.class,
       EmbeddedDatabaseFactory.class,
       LogbackHelper.class,
index 2840cba3b4593eece993f5110611ac8cd5bd4d47..5162e13d24036bcfbea82278036f0d63672ef7a2 100644 (file)
@@ -28,7 +28,7 @@ import org.apache.commons.io.FileUtils;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.Props;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -55,7 +55,7 @@ public class EmbeddedTomcatTest {
 
     // start server on a random port
     InetAddress address = InetAddress.getLoopbackAddress();
-    int httpPort = NetworkUtils.INSTANCE.getNextAvailablePort(address);
+    int httpPort = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(address);
     props.set("sonar.web.host", address.getHostAddress());
     props.set("sonar.web.port", String.valueOf(httpPort));
     EmbeddedTomcat tomcat = new EmbeddedTomcat(props);
index 475079444eca14a41ca7b97c42887f69a2c8cb6a..84e82d23386a62ee0745d0eb7e7d5440abe2bf54 100644 (file)
@@ -27,6 +27,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
@@ -45,7 +46,7 @@ public class StartableHazelcastMemberTest {
   @Test
   public void start_initializes_hazelcast() {
     completeValidSettings();
-    StartableHazelcastMember underTest = new StartableHazelcastMember(settings.asConfig(), NetworkUtils.INSTANCE);
+    StartableHazelcastMember underTest = new StartableHazelcastMember(settings.asConfig(), NetworkUtilsImpl.INSTANCE);
     verifyStopped(underTest);
 
     underTest.start();
index 416524560f15248a9388623439dc0d2ca5f95a0e..5306c9d40516c4f86efc863232e3f4910482791a 100644 (file)
@@ -34,7 +34,7 @@ import org.junit.rules.Timeout;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.LogTester;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 
 import static junit.framework.Assert.fail;
 import static org.mockito.Mockito.mock;
@@ -113,7 +113,7 @@ public class EmbeddedDatabaseTest {
 
   @Test
   public void start_ignores_URL_to_create_database_and_uses_default_username_and_password_when_then_are_not_set() throws IOException {
-    int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
+    int port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
     settings
       .setProperty(PATH_DATA, temporaryFolder.newFolder().getAbsolutePath())
       .setProperty(PROP_URL, "jdbc url")
@@ -126,7 +126,7 @@ public class EmbeddedDatabaseTest {
 
   @Test
   public void start_creates_db_and_adds_tcp_listener() throws IOException {
-    int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
+    int port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
     settings
       .setProperty(PATH_DATA, temporaryFolder.newFolder().getAbsolutePath())
       .setProperty(PROP_URL, "jdbc url")
@@ -144,7 +144,7 @@ public class EmbeddedDatabaseTest {
 
   @Test
   public void start_supports_in_memory_H2_JDBC_URL() throws IOException {
-    int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
+    int port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
     settings
       .setProperty(PATH_DATA, temporaryFolder.newFolder().getAbsolutePath())
       .setProperty(PROP_URL, "jdbc:h2:mem:sonar")
index 3f6a1cdb80a3de45dad8bedfe17688717fa2aa98..dc68af71716048ccf27979809e323def2f367cd5 100644 (file)
@@ -24,7 +24,7 @@ import org.apache.commons.io.FileUtils;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.platform.Server;
+import org.sonar.server.platform.ServerFileSystem;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -36,14 +36,14 @@ public class OfficialDistributionTest {
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  private Server server = mock(Server.class);
-  private OfficialDistribution underTest = new OfficialDistribution(server);
+  private ServerFileSystem serverFileSystem = mock(ServerFileSystem.class);
+  private OfficialDistribution underTest = new OfficialDistribution(serverFileSystem);
 
   @Test
   public void official_distribution() throws Exception {
     File rootDir = temp.newFolder();
     FileUtils.write(new File(rootDir, OfficialDistribution.BRANDING_FILE_PATH), "1.2");
-    when(server.getRootDir()).thenReturn(rootDir);
+    when(serverFileSystem.getHomeDir()).thenReturn(rootDir);
 
     assertThat(underTest.check()).isTrue();
   }
@@ -52,7 +52,7 @@ public class OfficialDistributionTest {
   public void not_an_official_distribution() throws Exception {
     File rootDir = temp.newFolder();
     // branding file is missing
-    when(server.getRootDir()).thenReturn(rootDir);
+    when(serverFileSystem.getHomeDir()).thenReturn(rootDir);
 
     assertThat(underTest.check()).isFalse();
   }
index 23a0b0161c8ba758613182c657f65f048b3b9646..2e84c5aa1a993430cfa3deadebefdef60ce5e594 100644 (file)
@@ -24,7 +24,7 @@ import java.io.File;
 import java.net.InetAddress;
 import java.util.Collections;
 import org.jboss.byteman.agent.submit.Submit;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 
 import static java.lang.String.format;
 
@@ -50,7 +50,7 @@ public class Byteman {
   public Byteman(OrchestratorBuilder builder, Process process) {
     this.builder = builder;
     String jar = findBytemanJar();
-    port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
+    port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
     String bytemanArg = format("-javaagent:%s=boot:%s,port:%d", jar, jar, port);
     builder.setServerProperty(process.argument, bytemanArg);
   }
index 0c046076021b70f4cba1066ca605da31a45fb4f2..7a2bb9eec1680889afaf18761dfa6bc1a0422e5a 100644 (file)
@@ -25,7 +25,7 @@ import com.sonar.orchestrator.http.HttpResponse;
 import java.net.InetAddress;
 import okhttp3.HttpUrl;
 import org.junit.Test;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -33,7 +33,7 @@ public class ElasticsearchSettingsTest {
 
   @Test
   public void set_http_port_through_sonar_properties() throws Exception {
-    int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
+    int port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
     Orchestrator orchestrator = Orchestrator
       .builderEnv()
       .setServerProperty("sonar.search.httpPort", "" + port)