azagrebin commented on a change in pull request #6957: [FLINK-10627][E2E tests] Test s3 output for streaming file sink URL: https://github.com/apache/flink/pull/6957#discussion_r230069649
########## File path: flink-end-to-end-tests/flink-e2e-test-utils/src/main/java/org/apache/flink/streaming/tests/util/s3/S3UtilProgram.java ########## @@ -0,0 +1,221 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.streaming.tests.util.s3; + +import org.apache.flink.api.java.utils.ParameterTool; + +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import com.amazonaws.services.s3.model.DeleteObjectsRequest; +import com.amazonaws.services.s3.model.S3ObjectSummary; +import com.amazonaws.services.s3.transfer.KeyFilter; +import com.amazonaws.services.s3.transfer.TransferManager; +import com.amazonaws.services.s3.transfer.TransferManagerBuilder; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.function.Consumer; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +/** + * S3 utilities. + * + * <p>Usage: java -jar S3UtilProgram.jar args. + * + * <p>Note: {@code S3UtilProgram.Action.lineNumber*} actions are applicable only + * to valid non-compressed CSV comma separated files. + * + * <p>Program parameters: + * <ul> + * <li>action (string, required): Action to perform, see {@link S3UtilProgram.Action}.</li> + * <li>bucket (string, required): Bucket where s3 objects reside.</li> + * <li>s3file (string, required for single object actions): s3 object key.</li> + * <li>s3prefix (string, required for actions over objects grouped by key prefix): s3 key prefix.</li> + * <li>s3filePrefix (string, optional for downloadByPrefix or numberOfLinesByPrefix): s3 file name prefix w/o directory to filter files by name.</li> + * <li>localFile (string, required for single file actions): local file path.</li> + * <li>localFolder (string, required for actions over folders): local folder path.</li> + * <li>parallelism (int, default 10): parallelism for parallelizable actions (e.g. {@code numberOfLinesByPrefix}).</li> + * </ul> + */ +class S3UtilProgram { + enum Action { + listByPrefix, + downloadFile, + downloadByPrefix, + deleteFile, + deleteByPrefix, + numberOfLinesInFile, + numberOfLinesByPrefix + } + + private static final Map<Action, Consumer<ParameterTool>> handlers; + static { + Map<Action, Consumer<ParameterTool>> handlersMutable = new HashMap<>(); + handlersMutable.put(Action.listByPrefix, S3UtilProgram::listByPrefix); + handlersMutable.put(Action.downloadFile, S3UtilProgram::downloadFile); + handlersMutable.put(Action.downloadByPrefix, S3UtilProgram::downloadByPrefix); + handlersMutable.put(Action.deleteFile, S3UtilProgram::deleteFile); + handlersMutable.put(Action.deleteByPrefix, S3UtilProgram::deleteByPrefix); + handlersMutable.put(Action.numberOfLinesInFile, S3UtilProgram::numberOfLinesInFile); + handlersMutable.put(Action.numberOfLinesByPrefix, S3UtilProgram::numberOfLinesByPrefix); + handlers = Collections.unmodifiableMap(handlersMutable); + } + + private static final String countQuery = "select count(*) from s3object"; + + public static void main(String[] args) { + final ParameterTool params = ParameterTool.fromArgs(args); + final Action action = Action.valueOf(params.getRequired("action")); + handlers.get(action).accept(params); + } + + private static void listByPrefix(ParameterTool params) { Review comment: this lists by full s3 object key prefix, could be then: listByFullPrefix ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
