aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-09-21 09:53:43 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-09-26 23:49:38 +0200
commit0d049321178a98f46a1739f1c2817098064f1475 (patch)
treee9a6283fd41eae24ccd65d2a660281c8c6ac4e99 /server/sonar-process
parent231d183396ca7187b2b45c50927aa8a3bc8dac56 (diff)
downloadsonarqube-0d049321178a98f46a1739f1c2817098064f1475.tar.gz
sonarqube-0d049321178a98f46a1739f1c2817098064f1475.zip
SONAR-9802 Fix quality flaws
Diffstat (limited to 'server/sonar-process')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java1
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java1
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java2
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java6
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java22
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java12
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java3
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastObjects.java3
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java3
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java4
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java8
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java12
12 files changed, 44 insertions, 33 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java
index 7d4fc4d51f3..234b930d241 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java
@@ -27,7 +27,6 @@ import java.util.Optional;
import java.util.function.Predicate;
public interface NetworkUtils {
- NetworkUtils INSTANCE = new NetworkUtilsImpl();
int getNextAvailablePort(InetAddress address);
diff --git a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java
index 9da928a7c9d..3f7d6892f35 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java
@@ -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;
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java
index 5d90670108a..012474d50d7 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java
@@ -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);
}
diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java
index f5a0bc920c8..526b17ee183 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java
@@ -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);
}
diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java
index 0a70741d020..d2e081d4443 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java
@@ -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);
diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java
index 806b0d7cf8e..55a5dd0a4ed 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java
@@ -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));
}
diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java
index 3b7abe59f89..222ea28e7f9 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java
@@ -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);
};
}
diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastObjects.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastObjects.java
index 97e5952b8d7..ddcf39bc126 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastObjects.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastObjects.java
@@ -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
*/
diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java
index 2cdf3d5dd75..5b45fc8a6a8 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java
@@ -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;
}
}
diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java
index 9316ad6d3e0..6a4973b8d13 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java
@@ -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();
diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java
index 72087914a8e..4d83a82f233 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java
@@ -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);
diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java
index 309e3463a32..ce5c36de367 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java
@@ -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