You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/06/05 17:40:06 UTC
[GitHub] [flink] zentol commented on a change in pull request #12484: [FLINK-18127][tests] Streamline manual execution of Java E2E tests
zentol commented on a change in pull request #12484:
URL: https://github.com/apache/flink/pull/12484#discussion_r436067636
##########
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:
We could harden this be explicitly checking for `flink-dist.jar`; this one should only be in the distribution.
----------------------------------------------------------------
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:
users@infra.apache.org