Skip to content

Commit c6894b3

Browse files
lukasz-jarocki-sonarsourcesonartech
authored andcommitted
SONAR-24276 Bump elasticsearch. Now SonarQube requires JDK to run!
1 parent 3f184e2 commit c6894b3

7 files changed

Lines changed: 50 additions & 33 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ projectTitle=SonarQube
1313
org.gradle.jvmargs=-Xmx2048m
1414
org.gradle.caching=true
1515
org.gradle.vfs.watch=true
16-
elasticSearchServerVersion=8.16.6
16+
elasticSearchServerVersion=8.19.8
1717
projectType=application
1818
artifactoryUrl=https://repox.jfrog.io/repox
1919
jre_release_name=jdk-21.0.9+10

server/sonar-main/src/main/java/org/sonar/application/ProcessLauncherImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ private void writeConfFiles(EsInstallation esInstallation) {
151151

152152
private static void pruneElasticsearchConfDirectory(File confDir) {
153153
try {
154-
Files.deleteIfExists(confDir.toPath());
154+
if (confDir.exists()) {
155+
FileUtils2.deleteDirectory(confDir);
156+
}
155157
} catch (IOException e) {
156158
throw new IllegalStateException("Could not delete Elasticsearch temporary conf directory", e);
157159
}

server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import static org.sonar.process.ProcessProperties.Property.PATH_DATA;
4444
import static org.sonar.process.ProcessProperties.Property.PATH_HOME;
4545
import static org.sonar.process.ProcessProperties.Property.PATH_LOGS;
46-
import static org.sonar.process.ProcessProperties.Property.PATH_TEMP;
4746

4847
/**
4948
* Holds {@link File} to the various directories of ElasticSearch distribution embedded in SonarQube and provides
@@ -120,8 +119,11 @@ private static File buildLogPath(Props props) {
120119
}
121120

122121
private static File buildConfDir(Props props) {
123-
File tempPath = props.nonNullValueAsFile(PATH_TEMP.getKey());
124-
return new File(new File(tempPath, "conf"), "es");
122+
// Elasticsearch 8.19+ forbids modules from having READ_WRITE access to paths under es.path.conf
123+
// The keystore file needs write access, so we must place config in the data directory instead
124+
// See: https://github.com/elastic/elasticsearch/pull/126852
125+
String dataPath = props.nonNullValue(PATH_DATA.getKey());
126+
return new File(new File(dataPath, "es8"), "config");
125127
}
126128

127129
public File getHomeDirectory() {

server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ private void configureCluster(Map<String, String> builder) {
241241

242242
private void configureOthers(Map<String, String> builder) {
243243
builder.put("action.auto_create_index", String.valueOf(false));
244+
244245
if (props.value(JAVA_ADDITIONAL_OPS_PROPERTY, "").contains("-D" + SECCOMP_PROPERTY + "=" + Boolean.FALSE)) {
245246
builder.put(SECCOMP_PROPERTY, Boolean.FALSE.toString());
246247
}

server/sonar-main/src/test/java/org/sonar/application/ProcessLauncherImplTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,31 @@ public void throw_ISE_if_command_fails() throws IOException {
312312
.hasMessage("Fail to launch process [%s]", ProcessId.ELASTICSEARCH.getHumanReadableName());
313313
}
314314

315+
@Test
316+
public void should_delete_elasticsearch_conf_directory_if_exists() throws Exception {
317+
File tempDir = temp.newFolder();
318+
File homeDir = temp.newFolder();
319+
File dataDir = temp.newFolder();
320+
File logDir = temp.newFolder();
321+
ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, TestProcessBuilder::new);
322+
JavaCommand command = createEsCommand(tempDir, homeDir, dataDir, logDir);
323+
324+
// Create the ES conf directory that should be deleted
325+
File esConfDir = command.getEsInstallation().getConfDirectory();
326+
assertThat(esConfDir.mkdirs()).isTrue();
327+
// Add some files to the directory to test recursive deletion
328+
File fileInConfDir = new File(esConfDir, "test-file.txt");
329+
assertThat(fileInConfDir.createNewFile()).isTrue();
330+
assertThat(esConfDir).exists();
331+
assertThat(fileInConfDir).exists();
332+
333+
underTest.launch(command);
334+
335+
// The old conf directory should be deleted and recreated
336+
assertThat(esConfDir).exists();
337+
assertThat(fileInConfDir).doesNotExist();
338+
}
339+
315340
private JavaCommand<?> createEsCommand(File tempDir, File homeDir, File dataDir, File logDir) throws IOException {
316341
JavaCommand command = new JavaCommand(ProcessId.ELASTICSEARCH, temp.newFolder());
317342
Props props = new Props(new Properties());

server/sonar-main/src/test/java/org/sonar/application/es/EsInstallationTest.java

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import static org.sonar.process.ProcessProperties.Property.PATH_DATA;
3636
import static org.sonar.process.ProcessProperties.Property.PATH_HOME;
3737
import static org.sonar.process.ProcessProperties.Property.PATH_LOGS;
38-
import static org.sonar.process.ProcessProperties.Property.PATH_TEMP;
3938

4039
public class EsInstallationTest {
4140

@@ -52,14 +51,14 @@ public void constructor_fails_with_IAE_if_sq_home_property_is_not_defined() {
5251
}
5352

5453
@Test
55-
public void constructor_fails_with_IAE_if_temp_dir_property_is_not_defined() throws IOException {
54+
public void constructor_fails_with_IAE_if_logs_dir_property_is_not_defined() throws IOException {
5655
Props props = new Props(new Properties());
5756
props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath());
5857
props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath());
5958

6059
assertThatThrownBy(() -> new EsInstallation(props))
6160
.isInstanceOf(IllegalArgumentException.class)
62-
.hasMessage("Property sonar.path.temp is not set");
61+
.hasMessage("Property sonar.path.logs is not set");
6362
}
6463

6564
@Test
@@ -78,7 +77,6 @@ public void getHomeDirectory_is_elasticsearch_subdirectory_of_sq_home_directory(
7877
Props props = new Props(new Properties());
7978
props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath());
8079
props.set(PATH_HOME.getKey(), sqHomeDir.getAbsolutePath());
81-
props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath());
8280
props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath());
8381

8482
EsInstallation underTest = new EsInstallation(props);
@@ -89,11 +87,9 @@ public void getHomeDirectory_is_elasticsearch_subdirectory_of_sq_home_directory(
8987
@Test
9088
public void override_data_dir() throws Exception {
9189
File sqHomeDir = temp.newFolder();
92-
File tempDir = temp.newFolder();
9390
File dataDir = temp.newFolder();
9491
Props props = new Props(new Properties());
9592
props.set(PATH_HOME.getKey(), sqHomeDir.getAbsolutePath());
96-
props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath());
9793
props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath());
9894

9995
props.set(PATH_DATA.getKey(), dataDir.getAbsolutePath());
@@ -110,7 +106,6 @@ public void getLogDirectory_is_configured_with_non_nullable_PATH_LOG_variable()
110106
Props props = new Props(new Properties());
111107
props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath());
112108
props.set(PATH_HOME.getKey(), sqHomeDir.getAbsolutePath());
113-
props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath());
114109
props.set(PATH_LOGS.getKey(), logDir.getAbsolutePath());
115110

116111
EsInstallation underTest = new EsInstallation(props);
@@ -125,7 +120,6 @@ public void getOutdatedSearchDirectories_returns_all_previously_used_es_data_dir
125120
Props props = new Props(new Properties());
126121
props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath());
127122
props.set(PATH_HOME.getKey(), sqHomeDir.getAbsolutePath());
128-
props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath());
129123
props.set(PATH_LOGS.getKey(), logDir.getAbsolutePath());
130124

131125
EsInstallation underTest = new EsInstallation(props);
@@ -136,17 +130,16 @@ public void getOutdatedSearchDirectories_returns_all_previously_used_es_data_dir
136130
}
137131

138132
@Test
139-
public void conf_directory_is_conf_es_subdirectory_of_sq_temp_directory() throws IOException {
140-
File tempDir = temp.newFolder();
133+
public void conf_directory_is_config_subdirectory_of_es8_data_directory() throws IOException {
134+
File dataDir = temp.newFolder();
141135
Props props = new Props(new Properties());
142-
props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath());
136+
props.set(PATH_DATA.getKey(), dataDir.getAbsolutePath());
143137
props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath());
144-
props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath());
145138
props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath());
146139

147140
EsInstallation underTest = new EsInstallation(props);
148141

149-
assertThat(underTest.getConfDirectory()).isEqualTo(new File(tempDir, "conf/es"));
142+
assertThat(underTest.getConfDirectory()).isEqualTo(new File(new File(dataDir, "es8"), "config"));
150143
}
151144

152145
@Test
@@ -155,7 +148,6 @@ public void getExecutable_resolve_executable_for_platform() throws IOException {
155148
Props props = new Props(new Properties());
156149
props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath());
157150
props.set(PATH_HOME.getKey(), sqHomeDir.getAbsolutePath());
158-
props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath());
159151
props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath());
160152

161153
EsInstallation underTest = new EsInstallation(props);
@@ -165,44 +157,41 @@ public void getExecutable_resolve_executable_for_platform() throws IOException {
165157

166158
@Test
167159
public void getLog4j2Properties_is_in_es_conf_directory() throws IOException {
168-
File tempDir = temp.newFolder();
160+
File dataDir = temp.newFolder();
169161
Props props = new Props(new Properties());
170-
props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath());
162+
props.set(PATH_DATA.getKey(), dataDir.getAbsolutePath());
171163
props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath());
172-
props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath());
173164
props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath());
174165

175166
EsInstallation underTest = new EsInstallation(props);
176167

177-
assertThat(underTest.getLog4j2PropertiesLocation()).isEqualTo(new File(tempDir, "conf/es/log4j2.properties"));
168+
assertThat(underTest.getLog4j2PropertiesLocation()).isEqualTo(new File(new File(dataDir, "es8"), "config/log4j2.properties"));
178169
}
179170

180171
@Test
181172
public void getElasticsearchYml_is_in_es_conf_directory() throws IOException {
182-
File tempDir = temp.newFolder();
173+
File dataDir = temp.newFolder();
183174
Props props = new Props(new Properties());
184-
props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath());
175+
props.set(PATH_DATA.getKey(), dataDir.getAbsolutePath());
185176
props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath());
186-
props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath());
187177
props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath());
188178

189179
EsInstallation underTest = new EsInstallation(props);
190180

191-
assertThat(underTest.getElasticsearchYml()).isEqualTo(new File(tempDir, "conf/es/elasticsearch.yml"));
181+
assertThat(underTest.getElasticsearchYml()).isEqualTo(new File(new File(dataDir, "es8"), "config/elasticsearch.yml"));
192182
}
193183

194184
@Test
195185
public void getJvmOptions_is_in_es_conf_directory() throws IOException {
196-
File tempDir = temp.newFolder();
186+
File dataDir = temp.newFolder();
197187
Props props = new Props(new Properties());
198-
props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath());
188+
props.set(PATH_DATA.getKey(), dataDir.getAbsolutePath());
199189
props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath());
200-
props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath());
201190
props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath());
202191

203192
EsInstallation underTest = new EsInstallation(props);
204193

205-
assertThat(underTest.getJvmOptions()).isEqualTo(new File(tempDir, "conf/es/jvm.options"));
194+
assertThat(underTest.getJvmOptions()).isEqualTo(new File(new File(dataDir, "es8"), "config/jvm.options"));
206195
}
207196

208197
@Test
@@ -211,7 +200,6 @@ public void isHttpEncryptionEnabled_shouldReturnCorrectValue() throws IOExceptio
211200
Props props = new Props(new Properties());
212201
props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath());
213202
props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath());
214-
props.set(PATH_TEMP.getKey(), sqHomeDir.getAbsolutePath());
215203
props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath());
216204
props.set(CLUSTER_ENABLED.getKey(), "true");
217205
props.set(CLUSTER_SEARCH_PASSWORD.getKey(), "password");

sonar-application/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ task zip(type: Zip, dependsOn: [configurations.compileClasspath]) {
202202
exclude '**/modules/frozen-indices/**'
203203
exclude '**/modules/inference/**'
204204
exclude '**/modules/ingest-attachment/**'
205-
exclude '**/modules/ingest-common/**'
206205
exclude '**/modules/ingest-geoip/**'
207206
exclude '**/modules/ingest-user-agent/**'
208207
exclude '**/modules/kibana/**'

0 commit comments

Comments
 (0)