LogStorageInfos { public static S3LogLocation buildLogLocation(Task task, S3LogLocation defaultLogLocation) { S3Bucket customS3Bucket = findCustomS3Bucket(task).orElse(null); String customPathPrefix = findCustomPathPrefix(task).orElse(null); if (customS3Bucket == null && customPathPrefix == null) { return defaultLogLocation; } String fullPrefix = customPathPrefix == null ? defaultLogLocation.getKey() : buildPathPrefix(customPathPrefix, defaultLogLocation.getKey()); if (customS3Bucket == null) { return new S3LogLocation( defaultLogLocation.getAccountName(), defaultLogLocation.getAccountId(), defaultLogLocation.getRegion(), defaultLogLocation.getBucket(), fullPrefix ); } return customS3Bucket.getS3Account() .map(account -> new S3LogLocation( account.getAccountId(), account.getAccountId(), account.getRegion(), customS3Bucket.getBucketName(), fullPrefix )) .orElseGet(() -> new S3LogLocation( defaultLogLocation.getAccountName(), defaultLogLocation.getAccountId(), defaultLogLocation.getRegion(), customS3Bucket.getBucketName(), fullPrefix )); }  static Map<String, String> toS3LogLocationTaskContext(Job<E> job); static S3LogLocation buildLogLocation(Task task, S3LogLocation defaultLogLocation); static Optional<S3Bucket> findCustomS3Bucket(Job<?> job); static Optional<S3Bucket> findCustomS3Bucket(JobDescriptor<?> jobDescriptor); static Optional<S3Bucket> findCustomS3Bucket(Task task); static Optional<String> findCustomPathPrefix(JobDescriptor<?> jobDescriptor); static Optional<String> findCustomPathPrefix(Task task); static String buildPathPrefix(String first, String second);  }
@Test public void testBuildLogLocation() { assertThat(LogStorageInfos.buildLogLocation(JobGenerator.oneBatchTask(), DEFAULT_LOG_LOCATION)).isEqualTo(DEFAULT_LOG_LOCATION); assertThat(LogStorageInfos.buildLogLocation(newTask("bucketA", "pathB"), DEFAULT_LOG_LOCATION)).isEqualTo( new S3LogLocation( DEFAULT_LOG_LOCATION.getAccountName(), DEFAULT_LOG_LOCATION.getAccountId(), DEFAULT_LOG_LOCATION.getRegion(), "bucketA", "pathB/defaultKey" ) ); assertThat(LogStorageInfos.buildLogLocation( newTask("arn:aws:s3:us-west-2:123456789012:accesspoint/test", "pathB"), DEFAULT_LOG_LOCATION) ).isEqualTo( new S3LogLocation( "123456789012", "123456789012", "us-west-2", "arn:aws:s3:us-west-2:123456789012:accesspoint/test", "pathB/defaultKey" ) ); }