import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
+import java.util.UUID;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
private final List<String> hosts;
private final List<String> networkInterfaces;
private final NodeType nodeType;
+ private final String nodeName;
ClusterProperties(AppSettings appSettings) {
port = appSettings.getProps().valueAsInt(ProcessProperties.CLUSTER_NODE_PORT);
appSettings.getProps().value(ProcessProperties.CLUSTER_HOSTS, "")
);
nodeType = NodeType.parse(appSettings.getProps().value(ProcessProperties.CLUSTER_NODE_TYPE));
+ nodeName = appSettings.getProps().value(ProcessProperties.CLUSTER_NODE_NAME, "sonarqube-" + UUID.randomUUID().toString());
}
int getPort() {
return networkInterfaces;
}
+ public String getNodeName() {
+ return nodeName;
+ }
+
void validate() {
// Test validity of port
checkArgument(
import static org.sonar.process.cluster.ClusterObjectKeys.HOSTNAME;
import static org.sonar.process.cluster.ClusterObjectKeys.IP_ADDRESSES;
import static org.sonar.process.cluster.ClusterObjectKeys.LEADER;
+import static org.sonar.process.cluster.ClusterObjectKeys.NODE_NAME;
import static org.sonar.process.cluster.ClusterObjectKeys.NODE_TYPE;
import static org.sonar.process.cluster.ClusterObjectKeys.OPERATIONAL_PROCESSES;
import static org.sonar.process.cluster.ClusterObjectKeys.SONARQUBE_VERSION;
.setProperty("hazelcast.logging.type", "slf4j");
// Trying to resolve the hostname
+ hzConfig.getMemberAttributeConfig()
+ .setStringAttribute(NODE_NAME, clusterProperties.getNodeName());
hzConfig.getMemberAttributeConfig()
.setStringAttribute(HOSTNAME, getHostname());
hzConfig.getMemberAttributeConfig()
public ExpectedException expectedException = ExpectedException.none();
@Test
- public void test_default_settings() throws Exception {
+ public void test_default_settings_for_standalone_mode() throws Exception {
File homeDir = temp.newFolder();
Props props = new Props(new Properties());
props.set(ProcessProperties.SEARCH_PORT, "1234");
props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath());
props.set(ProcessProperties.CLUSTER_NAME, "sonarqube");
- props.set(ProcessProperties.CLUSTER_NODE_NAME, "node-1");
EsSettings esSettings = new EsSettings(props, new EsFileSystem(props));
// no cluster, but cluster and node names are set though
assertThat(generated.get("cluster.name")).isEqualTo("sonarqube");
- assertThat(generated.get("node.name")).isEqualTo("sonar-1");
+ assertThat(generated.get("node.name")).isEqualTo("sonarqube");
assertThat(generated.get("path.data")).isNotNull();
assertThat(generated.get("path.logs")).isNotNull();
assertThat(generated.get("action.auto_create_index")).isEqualTo("false");
}
+ @Test
+ public void test_default_settings_for_cluster_mode() throws Exception {
+ File homeDir = temp.newFolder();
+ Props props = new Props(new Properties());
+ props.set(ProcessProperties.SEARCH_PORT, "1234");
+ props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1");
+ props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
+ props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath());
+ props.set(ProcessProperties.CLUSTER_NAME, "sonarqube-1");
+ props.set(ProcessProperties.CLUSTER_ENABLED, "true");
+ props.set(ProcessProperties.CLUSTER_NODE_NAME, "node-1");
+
+ EsSettings esSettings = new EsSettings(props, new EsFileSystem(props));
+
+ Map<String, String> generated = esSettings.build();
+ assertThat(generated.get("cluster.name")).isEqualTo("sonarqube-1");
+ assertThat(generated.get("node.name")).isEqualTo("node-1");
+ }
+
@Test
public void test_node_name_default_for_cluster_mode() throws Exception {
File homeDir = temp.newFolder();