Skip to content

Commit 22e8b2c

Browse files
committed
fix: support set but empty OHSOME_PLANTE_METRICS_PORT enviroment
1 parent cb8e631 commit 22e8b2c

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

ohsome-planet-cli/src/main/java/org/heigit/ohsome/planet/cmd/Contributions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.concurrent.Callable;
1919

2020
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
21+
import static java.util.function.Predicate.not;
2122

2223
@CommandLine.Command(name = "contributions",
2324
mixinStandardHelpOptions = true,
@@ -123,6 +124,7 @@ public Integer call() throws Exception {
123124
}
124125

125126
var httpServer = Optional.ofNullable(System.getProperty(OHSOME_PLANET_METRICS_PORT, System.getenv(OHSOME_PLANET_METRICS_PORT)))
127+
.filter(not(String::isBlank))
126128
.map(Integer::parseInt)
127129
.map(port -> HTTPServer.builder().port(port));
128130
try (var ignored = (httpServer.isPresent()) ? httpServer.get().buildAndStart() : null;

ohsome-planet-cli/src/main/java/org/heigit/ohsome/planet/cmd/Replications.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111

1212
import java.nio.file.Path;
1313
import java.security.InvalidParameterException;
14+
import java.util.Optional;
1415
import java.util.concurrent.Callable;
1516

17+
import static java.util.function.Predicate.not;
18+
1619
@Command(name = "replications",
1720
versionProvider = ManifestVersionProvider.class,
1821
mixinStandardHelpOptions = true,
@@ -141,9 +144,11 @@ public Integer call() throws Exception {
141144
throw new InvalidParameterException("Either just-contributions or just-changesets can be specified");
142145
}
143146

144-
var metricsPort = System.getProperty(OHSOME_PLANET_METRICS_PORT, System.getenv(OHSOME_PLANET_METRICS_PORT));
145-
try (var ignored = (metricsPort != null ) ?
146-
HTTPServer.builder().port(Integer.parseInt(metricsPort)).buildAndStart() : null ) {
147+
var httpServer = Optional.ofNullable(System.getProperty(OHSOME_PLANET_METRICS_PORT, System.getenv(OHSOME_PLANET_METRICS_PORT)))
148+
.filter(not(String::isBlank))
149+
.map(Integer::parseInt)
150+
.map(port -> HTTPServer.builder().port(port));
151+
try (var ignored = (httpServer.isPresent()) ? httpServer.get().buildAndStart() : null) {
147152

148153
JvmMetrics.builder().register();
149154

0 commit comments

Comments
 (0)