tillrohrmann commented on a change in pull request #12484:
URL: https://github.com/apache/flink/pull/12484#discussion_r436017785
##########
File path:
flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/flink/LocalStandaloneFlinkResourceFactory.java
##########
@@ -33,19 +37,83 @@
public final class LocalStandaloneFlinkResourceFactory implements
FlinkResourceFactory {
private static final Logger LOG =
LoggerFactory.getLogger(LocalStandaloneFlinkResourceFactory.class);
+ private static final ParameterProperty<Path> PROJECT_ROOT_DIRECTORY =
new ParameterProperty<>("rootDir", Paths::get);
private static final ParameterProperty<Path> DISTRIBUTION_DIRECTORY =
new ParameterProperty<>("distDir", Paths::get);
private static final ParameterProperty<Path>
DISTRIBUTION_LOG_BACKUP_DIRECTORY = new ParameterProperty<>("logBackupDir",
Paths::get);
@Override
public FlinkResource create(FlinkResourceSetup setup) {
Optional<Path> distributionDirectory =
DISTRIBUTION_DIRECTORY.get();
if (!distributionDirectory.isPresent()) {
- throw new IllegalArgumentException("The distDir
property was not set. You can set it when running maven via -DdistDir=<path>
.");
+ // distDir was not explicitly set, let's search for it
+
+ Path projectRootPath;
+ Optional<Path> projectRoot =
PROJECT_ROOT_DIRECTORY.get();
+ if (projectRoot.isPresent()) {
+ // running with maven
+ projectRootPath = projectRoot.get();
+ } else {
+ // running in the IDE; working directory is
test module
+ Optional<Path> projectRootDirectory =
findProjectRootDirectory(Paths.get("").toAbsolutePath());
+ // this distinction is required in case this
class is used outside of Flink
+ if (projectRootDirectory.isPresent()) {
+ projectRootPath =
projectRootDirectory.get();
+ } else {
+ throw new IllegalArgumentException(
+ "The 'distDir' property was not
set and the flink-dist module could not be found automatically." +
+ " Please point the
'distDir' property to the directory containing distribution; you can set it
when running maven via -DdistDir=<path> .");
+ }
+ }
+ Optional<Path> distribution =
findDistribution(projectRootPath);
+ if (!distribution.isPresent()) {
+ throw new IllegalArgumentException(
+ "The 'distDir' property was not set and
a distribution could not be found automatically." +
+ " Please point the 'distDir'
property to the directory containing distribution; you can set it when running
maven via -DdistDir=<path> .");
+ } else {
+ distributionDirectory = distribution;
+ }
}
Optional<Path> logBackupDirectory =
DISTRIBUTION_LOG_BACKUP_DIRECTORY.get();
if (!logBackupDirectory.isPresent()) {
LOG.warn("Property {} not set, logs will not be backed
up in case of test failures.",
DISTRIBUTION_LOG_BACKUP_DIRECTORY.getPropertyName());
}
return new
LocalStandaloneFlinkResource(distributionDirectory.get(),
logBackupDirectory.orElse(null), setup);
}
+
+ public static void main(String[] args) {
+
System.out.println(findProjectRootDirectory(Paths.get("").toAbsolutePath()));
+ }
+
+ private static Optional<Path> findProjectRootDirectory(Path
currentDirectory) {
+ // move up the module structure until we find flink-dist;
relies on all modules being prefixed with 'flink'
+ do {
+ if
(Files.exists(currentDirectory.resolve("flink-dist"))) {
+ return Optional.of(currentDirectory);
+ }
+ currentDirectory = currentDirectory.getParent();
+ } while
(currentDirectory.getFileName().toString().startsWith("flink"));
+ return Optional.empty();
+ }
+
+ private static Optional<Path> findDistribution(Path
projectRootDirectory) {
+ final Path distTargetDirectory =
projectRootDirectory.resolve("flink-dist").resolve("target");
+ try {
+ Collection<Path> paths =
FileUtils.listFilesInDirectory(distTargetDirectory, p ->
p.getFileName().toString().contains("flink-dist"));
+ if (paths.size() == 0) {
+ // likely due to flink-dist not having been
built
+ return Optional.empty();
+ }
+ if (paths.size() > 1) {
Review comment:
I guess this works because we first descend recursively in a dfs manner
so that we find the
`flink/flink-dist/target/flink-1.12-SNAPSHOT-bin/flink-1.12-SNAPSHOT/lib/flink-dist_2.11-1.12-SNAPSHOT.jar`
##########
File path:
flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/flink/LocalStandaloneFlinkResourceFactory.java
##########
@@ -33,19 +37,83 @@
public final class LocalStandaloneFlinkResourceFactory implements
FlinkResourceFactory {
private static final Logger LOG =
LoggerFactory.getLogger(LocalStandaloneFlinkResourceFactory.class);
+ private static final ParameterProperty<Path> PROJECT_ROOT_DIRECTORY =
new ParameterProperty<>("rootDir", Paths::get);
private static final ParameterProperty<Path> DISTRIBUTION_DIRECTORY =
new ParameterProperty<>("distDir", Paths::get);
private static final ParameterProperty<Path>
DISTRIBUTION_LOG_BACKUP_DIRECTORY = new ParameterProperty<>("logBackupDir",
Paths::get);
@Override
public FlinkResource create(FlinkResourceSetup setup) {
Optional<Path> distributionDirectory =
DISTRIBUTION_DIRECTORY.get();
if (!distributionDirectory.isPresent()) {
- throw new IllegalArgumentException("The distDir
property was not set. You can set it when running maven via -DdistDir=<path>
.");
+ // distDir was not explicitly set, let's search for it
+
+ Path projectRootPath;
+ Optional<Path> projectRoot =
PROJECT_ROOT_DIRECTORY.get();
+ if (projectRoot.isPresent()) {
+ // running with maven
+ projectRootPath = projectRoot.get();
+ } else {
+ // running in the IDE; working directory is
test module
+ Optional<Path> projectRootDirectory =
findProjectRootDirectory(Paths.get("").toAbsolutePath());
+ // this distinction is required in case this
class is used outside of Flink
+ if (projectRootDirectory.isPresent()) {
+ projectRootPath =
projectRootDirectory.get();
+ } else {
+ throw new IllegalArgumentException(
+ "The 'distDir' property was not
set and the flink-dist module could not be found automatically." +
+ " Please point the
'distDir' property to the directory containing distribution; you can set it
when running maven via -DdistDir=<path> .");
+ }
+ }
+ Optional<Path> distribution =
findDistribution(projectRootPath);
+ if (!distribution.isPresent()) {
+ throw new IllegalArgumentException(
+ "The 'distDir' property was not set and
a distribution could not be found automatically." +
+ " Please point the 'distDir'
property to the directory containing distribution; you can set it when running
maven via -DdistDir=<path> .");
+ } else {
+ distributionDirectory = distribution;
+ }
}
Optional<Path> logBackupDirectory =
DISTRIBUTION_LOG_BACKUP_DIRECTORY.get();
if (!logBackupDirectory.isPresent()) {
LOG.warn("Property {} not set, logs will not be backed
up in case of test failures.",
DISTRIBUTION_LOG_BACKUP_DIRECTORY.getPropertyName());
}
return new
LocalStandaloneFlinkResource(distributionDirectory.get(),
logBackupDirectory.orElse(null), setup);
}
+
+ public static void main(String[] args) {
+
System.out.println(findProjectRootDirectory(Paths.get("").toAbsolutePath()));
+ }
+
+ private static Optional<Path> findProjectRootDirectory(Path
currentDirectory) {
+ // move up the module structure until we find flink-dist;
relies on all modules being prefixed with 'flink'
+ do {
+ if
(Files.exists(currentDirectory.resolve("flink-dist"))) {
+ return Optional.of(currentDirectory);
+ }
+ currentDirectory = currentDirectory.getParent();
+ } while
(currentDirectory.getFileName().toString().startsWith("flink"));
+ return Optional.empty();
+ }
+
+ private static Optional<Path> findDistribution(Path
projectRootDirectory) {
+ final Path distTargetDirectory =
projectRootDirectory.resolve("flink-dist").resolve("target");
+ try {
+ Collection<Path> paths =
FileUtils.listFilesInDirectory(distTargetDirectory, p ->
p.getFileName().toString().contains("flink-dist"));
+ if (paths.size() == 0) {
+ // likely due to flink-dist not having been
built
+ return Optional.empty();
+ }
+ if (paths.size() > 1) {
Review comment:
Won't `flink-dist/target` also contain
`flink-dist_2.11-1.12-SNAPSHOT.jar`? At least this is the case for me. Can this
be a problem?
##########
File path:
flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/flink/LocalStandaloneFlinkResourceFactory.java
##########
@@ -33,19 +37,83 @@
public final class LocalStandaloneFlinkResourceFactory implements
FlinkResourceFactory {
private static final Logger LOG =
LoggerFactory.getLogger(LocalStandaloneFlinkResourceFactory.class);
+ private static final ParameterProperty<Path> PROJECT_ROOT_DIRECTORY =
new ParameterProperty<>("rootDir", Paths::get);
private static final ParameterProperty<Path> DISTRIBUTION_DIRECTORY =
new ParameterProperty<>("distDir", Paths::get);
private static final ParameterProperty<Path>
DISTRIBUTION_LOG_BACKUP_DIRECTORY = new ParameterProperty<>("logBackupDir",
Paths::get);
@Override
public FlinkResource create(FlinkResourceSetup setup) {
Optional<Path> distributionDirectory =
DISTRIBUTION_DIRECTORY.get();
if (!distributionDirectory.isPresent()) {
- throw new IllegalArgumentException("The distDir
property was not set. You can set it when running maven via -DdistDir=<path>
.");
+ // distDir was not explicitly set, let's search for it
+
+ Path projectRootPath;
+ Optional<Path> projectRoot =
PROJECT_ROOT_DIRECTORY.get();
+ if (projectRoot.isPresent()) {
+ // running with maven
+ projectRootPath = projectRoot.get();
+ } else {
+ // running in the IDE; working directory is
test module
+ Optional<Path> projectRootDirectory =
findProjectRootDirectory(Paths.get("").toAbsolutePath());
+ // this distinction is required in case this
class is used outside of Flink
+ if (projectRootDirectory.isPresent()) {
+ projectRootPath =
projectRootDirectory.get();
+ } else {
+ throw new IllegalArgumentException(
+ "The 'distDir' property was not
set and the flink-dist module could not be found automatically." +
+ " Please point the
'distDir' property to the directory containing distribution; you can set it
when running maven via -DdistDir=<path> .");
+ }
+ }
+ Optional<Path> distribution =
findDistribution(projectRootPath);
+ if (!distribution.isPresent()) {
+ throw new IllegalArgumentException(
+ "The 'distDir' property was not set and
a distribution could not be found automatically." +
+ " Please point the 'distDir'
property to the directory containing distribution; you can set it when running
maven via -DdistDir=<path> .");
+ } else {
+ distributionDirectory = distribution;
+ }
}
Optional<Path> logBackupDirectory =
DISTRIBUTION_LOG_BACKUP_DIRECTORY.get();
if (!logBackupDirectory.isPresent()) {
LOG.warn("Property {} not set, logs will not be backed
up in case of test failures.",
DISTRIBUTION_LOG_BACKUP_DIRECTORY.getPropertyName());
}
return new
LocalStandaloneFlinkResource(distributionDirectory.get(),
logBackupDirectory.orElse(null), setup);
}
+
+ public static void main(String[] args) {
+
System.out.println(findProjectRootDirectory(Paths.get("").toAbsolutePath()));
+ }
Review comment:
I guess this can be removed.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]