mirror of https://github.com/apache/nifi.git
NIFI-3364 Sorted Bootstrap java.arg properties in ascending alphabetical order (#9490)
Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
11cb2c56e2
commit
6095d950cf
|
@ -16,6 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.nifi.bootstrap.configuration;
|
package org.apache.nifi.bootstrap.configuration;
|
||||||
|
|
||||||
|
import static java.util.function.Predicate.not;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UncheckedIOException;
|
import java.io.UncheckedIOException;
|
||||||
|
@ -24,7 +26,6 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -64,23 +65,18 @@ public class StandardConfigurationProvider implements ConfigurationProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get additional arguments for application command from Bootstrap Properties starting with java.arg
|
* Get additional arguments for application command from Bootstrap Properties starting with java.arg
|
||||||
|
* Return the list sorted by java.arg names in ascending alphabetical order
|
||||||
*
|
*
|
||||||
* @return Additional arguments
|
* @return Additional arguments
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAdditionalArguments() {
|
public List<String> getAdditionalArguments() {
|
||||||
final List<String> additionalArguments = new ArrayList<>();
|
return bootstrapProperties.stringPropertyNames().stream()
|
||||||
|
.filter(name -> name.startsWith(BootstrapProperty.JAVA_ARGUMENT.getProperty()))
|
||||||
for (final String propertyName : bootstrapProperties.stringPropertyNames()) {
|
.sorted()
|
||||||
if (propertyName.startsWith(BootstrapProperty.JAVA_ARGUMENT.getProperty())) {
|
.map(bootstrapProperties::getProperty)
|
||||||
final String additionalArgument = bootstrapProperties.getProperty(propertyName);
|
.filter(not(String::isBlank))
|
||||||
if (!additionalArgument.isBlank()) {
|
.toList();
|
||||||
additionalArguments.add(additionalArgument);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return additionalArguments;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -117,6 +118,34 @@ class StandardConfigurationProviderTest {
|
||||||
assertEquals(MANAGEMENT_SERVER_ADDRESS, address.toString());
|
assertEquals(MANAGEMENT_SERVER_ADDRESS, address.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetAdditionalArguments(@TempDir final Path applicationHomeDirectory) throws IOException {
|
||||||
|
final Path bootstrapConfiguration = setRequiredConfiguration(applicationHomeDirectory);
|
||||||
|
// Properties in random order and containing some java.arg and some non-java.arg names.
|
||||||
|
List<String> propertyNames = List.of("java.arg9", "java.arg2", "java.arg.my2", "non.java.arg.2",
|
||||||
|
"java.arg1", "java.arg.memory", "java.arg", "java.arg.my1", "non.java.arg.3", "random.nothing");
|
||||||
|
// The expected returned list of java.arg properties sorted in ascending alphabetical order.
|
||||||
|
List<String> expectedArguments = List.of("java.arg", "java.arg.memory", "java.arg.my1", "java.arg.my2",
|
||||||
|
"java.arg1", "java.arg2", "java.arg9");
|
||||||
|
|
||||||
|
final Properties bootstrapProperties = new Properties();
|
||||||
|
for (String propertyName : propertyNames) {
|
||||||
|
bootstrapProperties.put(propertyName, propertyName);
|
||||||
|
}
|
||||||
|
try (OutputStream outputStream = Files.newOutputStream(bootstrapConfiguration)) {
|
||||||
|
bootstrapProperties.store(outputStream, Properties.class.getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
|
final StandardConfigurationProvider provider = new StandardConfigurationProvider(environmentVariables, systemProperties);
|
||||||
|
|
||||||
|
final List<String> actualAdditionalArguments = provider.getAdditionalArguments();
|
||||||
|
|
||||||
|
assertEquals(expectedArguments.size(), actualAdditionalArguments.size());
|
||||||
|
for (int i = 0; i < expectedArguments.size(); i++) {
|
||||||
|
assertEquals(expectedArguments.get(i), actualAdditionalArguments.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Path setRequiredConfiguration(final Path applicationHomeDirectory) throws IOException {
|
private Path setRequiredConfiguration(final Path applicationHomeDirectory) throws IOException {
|
||||||
environmentVariables.put(EnvironmentVariable.NIFI_HOME.name(), applicationHomeDirectory.toString());
|
environmentVariables.put(EnvironmentVariable.NIFI_HOME.name(), applicationHomeDirectory.toString());
|
||||||
final Path configurationDirectory = createConfigurationDirectory(applicationHomeDirectory);
|
final Path configurationDirectory = createConfigurationDirectory(applicationHomeDirectory);
|
||||||
|
|
Loading…
Reference in New Issue