@@ -30,18 +30,16 @@ import org.sonar.application.es.EsConnector; | |||
import org.sonar.application.es.EsConnectorImpl; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.Props; | |||
import org.sonar.process.cluster.NodeType; | |||
import org.sonar.process.cluster.hz.HazelcastMember; | |||
import org.sonar.process.cluster.hz.HazelcastMemberBuilder; | |||
import static java.util.Arrays.asList; | |||
import static org.sonar.process.ProcessProperties.Property.CLUSTER_HOSTS; | |||
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NAME; | |||
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST; | |||
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME; | |||
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT; | |||
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS; | |||
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NAME; | |||
public class AppStateFactory { | |||
@@ -64,7 +62,6 @@ public class AppStateFactory { | |||
HazelcastMemberBuilder builder = new HazelcastMemberBuilder() | |||
.setNetworkInterface(props.nonNullValue(CLUSTER_NODE_HOST.getKey())) | |||
.setMembers(asList(props.nonNullValue(CLUSTER_HOSTS.getKey()).split(","))) | |||
.setNodeType(NodeType.parse(props.nonNullValue(CLUSTER_NODE_TYPE.getKey()))) | |||
.setNodeName(props.nonNullValue(CLUSTER_NODE_NAME.getKey())) | |||
.setPort(Integer.parseInt(props.nonNullValue(CLUSTER_NODE_PORT.getKey()))) | |||
.setProcessId(ProcessId.APP); |
@@ -48,11 +48,9 @@ import org.sonar.application.es.EsConnector; | |||
import org.sonar.process.MessageException; | |||
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.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; | |||
@@ -282,8 +280,7 @@ public class ClusterAppStateImpl implements ClusterAppState { | |||
@Override | |||
public void memberRemoved(MembershipEvent membershipEvent) { | |||
removeOperationalProcess(membershipEvent.getMember().getUuid()); | |||
if (membershipEvent.getMembers().stream() | |||
.noneMatch(this::isAppNode)) { | |||
if (membershipEvent.getMembers().isEmpty()) { | |||
purgeSharedMemoryForAppNodes(); | |||
} | |||
} | |||
@@ -293,10 +290,6 @@ public class ClusterAppStateImpl implements ClusterAppState { | |||
// Nothing to do | |||
} | |||
private boolean isAppNode(Member member) { | |||
return NodeType.APPLICATION.getValue().equals(member.getStringAttribute(NODE_TYPE.getKey())); | |||
} | |||
private void removeOperationalProcess(String uuid) { | |||
for (ClusterProcess clusterProcess : operationalProcesses.keySet()) { | |||
if (clusterProcess.getNodeUuid().equals(uuid)) { |
@@ -32,7 +32,6 @@ import org.sonar.application.es.EsConnector; | |||
import org.sonar.process.MessageException; | |||
import org.sonar.process.NetworkUtilsImpl; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.cluster.NodeType; | |||
import org.sonar.process.cluster.hz.HazelcastMember; | |||
import org.sonar.process.cluster.hz.HazelcastMemberBuilder; | |||
@@ -140,7 +139,6 @@ public class ClusterAppStateImplTest { | |||
InetAddress loopback = InetAddress.getLoopbackAddress(); | |||
return new HazelcastMemberBuilder() | |||
.setNodeType(NodeType.APPLICATION) | |||
.setProcessId(ProcessId.COMPUTE_ENGINE) | |||
.setNodeName("bar") | |||
.setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback)) |
@@ -27,7 +27,6 @@ import java.util.Map; | |||
import java.util.Set; | |||
import java.util.concurrent.locks.Lock; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.cluster.NodeType; | |||
public interface HazelcastMember extends AutoCloseable { | |||
@@ -36,11 +35,6 @@ public interface HazelcastMember extends AutoCloseable { | |||
* The key of the node name attribute of a member | |||
*/ | |||
NODE_NAME("NODE_NAME"), | |||
/** | |||
* The role of the sonar-application inside the SonarQube cluster | |||
* {@link NodeType} | |||
*/ | |||
NODE_TYPE("NODE_TYPE"), | |||
/** | |||
* Key of process as defined by {@link ProcessId#getKey()} | |||
*/ |
@@ -30,7 +30,6 @@ import java.util.List; | |||
import java.util.stream.Collectors; | |||
import javax.annotation.CheckForNull; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.cluster.NodeType; | |||
import org.sonar.process.cluster.hz.HazelcastMember.Attribute; | |||
import static java.lang.String.format; | |||
@@ -42,7 +41,6 @@ public class HazelcastMemberBuilder { | |||
private String nodeName; | |||
private int port; | |||
private NodeType nodeType; | |||
private ProcessId processId; | |||
private String networkInterface; | |||
private List<String> members = new ArrayList<>(); | |||
@@ -52,12 +50,10 @@ public class HazelcastMemberBuilder { | |||
return this; | |||
} | |||
public HazelcastMemberBuilder setNodeType(NodeType t) { | |||
this.nodeType = t; | |||
return this; | |||
} | |||
public HazelcastMemberBuilder setProcessId(ProcessId p) { | |||
if (p == ProcessId.ELASTICSEARCH) { | |||
throw new IllegalArgumentException("Hazelcast must not be enabled on Elasticsearch node"); | |||
} | |||
this.processId = p; | |||
return this; | |||
} | |||
@@ -128,7 +124,6 @@ public class HazelcastMemberBuilder { | |||
MemberAttributeConfig attributes = config.getMemberAttributeConfig(); | |||
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)); |
@@ -23,11 +23,11 @@ import java.net.InetAddress; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.DisableOnDebug; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TestRule; | |||
import org.junit.rules.Timeout; | |||
import org.sonar.process.NetworkUtilsImpl; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.cluster.NodeType; | |||
import static java.util.Arrays.asList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -35,6 +35,8 @@ import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT; | |||
public class HazelcastMemberBuilderTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60)); | |||
@@ -45,7 +47,6 @@ public class HazelcastMemberBuilderTest { | |||
@Test | |||
public void build_member() { | |||
HazelcastMember member = underTest | |||
.setNodeType(NodeType.APPLICATION) | |||
.setProcessId(ProcessId.COMPUTE_ENGINE) | |||
.setNodeName("bar") | |||
.setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback)) | |||
@@ -76,4 +77,12 @@ public class HazelcastMemberBuilderTest { | |||
"bar:9100", | |||
"1.2.3.4:" + CLUSTER_NODE_PORT.getDefaultValue()); | |||
} | |||
@Test | |||
public void fail_if_elasticsearch_process() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Hazelcast must not be enabled on Elasticsearch node"); | |||
underTest.setProcessId(ProcessId.ELASTICSEARCH); | |||
} | |||
} |
@@ -37,7 +37,6 @@ import org.junit.rules.TestRule; | |||
import org.junit.rules.Timeout; | |||
import org.sonar.process.NetworkUtilsImpl; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.cluster.NodeType; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -112,7 +111,6 @@ public class HazelcastMemberImplTest { | |||
private static HazelcastMember newHzMember(int port, int... otherPorts) { | |||
return new HazelcastMemberBuilder() | |||
.setNodeType(NodeType.APPLICATION) | |||
.setProcessId(ProcessId.COMPUTE_ENGINE) | |||
.setNodeName("name" + port) | |||
.setPort(port) |