Search in sources :

Example 61 with Files

use of java.nio.file.Files in project flink by apache.

the class UnalignedCheckpointStressITCase method discoverRetainedCheckpoint.

private File discoverRetainedCheckpoint() throws Exception {
    // structure: root/attempt/checkpoint/_metadata
    File rootDir = temporaryFolder.getRoot();
    Path checkpointDir = null;
    for (int i = 0; i <= 1000 && checkpointDir == null; i++) {
        Thread.sleep(5);
        try (Stream<Path> files = Files.walk(Paths.get(rootDir.getPath()))) {
            checkpointDir = files.filter(Files::isRegularFile).filter(path -> path.endsWith("_metadata")).map(path -> path.getParent()).sorted(Comparator.comparingInt(UnalignedCheckpointStressITCase::getCheckpointNumberFromPath)).reduce((first, second) -> second).orElse(null);
        }
    }
    if (checkpointDir == null) {
        List<Path> files = Files.walk(Paths.get(rootDir.getPath())).collect(Collectors.toList());
        throw new IllegalStateException("Failed to find _metadata file among " + files);
    }
    return checkpointDir.toFile();
}
Also used : Path(java.nio.file.Path) Deadline(org.apache.flink.api.common.time.Deadline) TumblingProcessingTimeWindows(org.apache.flink.streaming.api.windowing.assigners.TumblingProcessingTimeWindows) FileUtils(org.apache.flink.util.FileUtils) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) KeyedCoProcessFunction(org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CHECKPOINTS_DIRECTORY(org.apache.flink.configuration.CheckpointingOptions.CHECKPOINTS_DIRECTORY) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) MapFunction(org.apache.flink.api.common.functions.MapFunction) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) ListState(org.apache.flink.api.common.state.ListState) Matcher(java.util.regex.Matcher) TestUtils.submitJobAndWaitForResult(org.apache.flink.test.util.TestUtils.submitJobAndWaitForResult) CheckpointListener(org.apache.flink.api.common.state.CheckpointListener) After(org.junit.After) Level(org.slf4j.event.Level) Duration(java.time.Duration) StreamGraph(org.apache.flink.streaming.api.graph.StreamGraph) TestLogger(org.apache.flink.util.TestLogger) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) FsStateChangelogStorageFactory(org.apache.flink.changelog.fs.FsStateChangelogStorageFactory) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) NetworkActionsLogger(org.apache.flink.runtime.io.network.logger.NetworkActionsLogger) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) DataStreamUtils(org.apache.flink.streaming.api.datastream.DataStreamUtils) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) ParallelSourceFunction(org.apache.flink.streaming.api.functions.source.ParallelSourceFunction) Pattern(java.util.regex.Pattern) Iterables.getOnlyElement(org.apache.flink.shaded.guava30.com.google.common.collect.Iterables.getOnlyElement) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) RestartStrategies(org.apache.flink.api.common.restartstrategy.RestartStrategies) DataStreamSource(org.apache.flink.streaming.api.datastream.DataStreamSource) Collector(org.apache.flink.util.Collector) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Nullable(javax.annotation.Nullable) Before(org.junit.Before) MAX_RETAINED_CHECKPOINTS(org.apache.flink.configuration.CheckpointingOptions.MAX_RETAINED_CHECKPOINTS) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) Time(org.apache.flink.streaming.api.windowing.time.Time) LogLevelRule(org.apache.flink.util.LogLevelRule) ExternalizedCheckpointCleanup(org.apache.flink.streaming.api.environment.CheckpointConfig.ExternalizedCheckpointCleanup) Files(java.nio.file.Files) Configuration(org.apache.flink.configuration.Configuration) SingleOutputStreamOperator(org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator) Test(org.junit.Test) IOException(java.io.IOException) ProcessWindowFunction(org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction) File(java.io.File) DataStream(org.apache.flink.streaming.api.datastream.DataStream) Rule(org.junit.Rule) Paths(java.nio.file.Paths) Comparator(java.util.Comparator) SavepointRestoreSettings(org.apache.flink.runtime.jobgraph.SavepointRestoreSettings) TemporaryFolder(org.junit.rules.TemporaryFolder) Preconditions.checkState(org.apache.flink.shaded.curator5.org.apache.curator.shaded.com.google.common.base.Preconditions.checkState) AbstractRichFunction(org.apache.flink.api.common.functions.AbstractRichFunction) Files(java.nio.file.Files) File(java.io.File)

Example 62 with Files

use of java.nio.file.Files in project flink by apache.

the class JarFileChecker method findNonBinaryFilesContainingText.

private static int findNonBinaryFilesContainingText(Path jar, Path jarRoot, Collection<Pattern> forbidden) throws IOException {
    try (Stream<Path> files = Files.walk(jarRoot)) {
        return files.filter(path -> !path.equals(jarRoot)).filter(path -> !Files.isDirectory(path)).filter(JarFileChecker::isNoClassFile).filter(path -> !getFileName(path).equals("dependencies")).filter(path -> !getFileName(path).startsWith("license")).filter(path -> !getFileName(path).startsWith("notice")).filter(path -> !pathStartsWith(path, "/META-INF/versions/11/javax/xml/bind")).filter(path -> !isJavaxManifest(jar, path)).filter(path -> !pathStartsWith(path, "/org/glassfish/jersey/internal")).filter(path -> !pathStartsWith(path, "/org/apache/pulsar/shade/org/glassfish/jersey/")).map(path -> {
            try {
                final String fileContents;
                try {
                    fileContents = readFile(path).toLowerCase(Locale.ROOT);
                } catch (MalformedInputException mie) {
                    // binary file
                    return 0;
                }
                int violations = 0;
                for (Pattern text : forbidden) {
                    if (text.matcher(fileContents).find()) {
                        // do not count individual violations because it can be
                        // confusing when checking with aliases for the same
                        // license
                        violations = 1;
                        LOG.error("File '{}' in jar '{}' contains match with forbidden regex '{}'.", path, jar, text);
                    }
                }
                return violations;
            } catch (IOException e) {
                throw new RuntimeException(String.format("Could not read contents of file '%s' in jar '%s'.", path, jar), e);
            }
        }).reduce(Integer::sum).orElse(0);
    }
}
Also used : Path(java.nio.file.Path) Logger(org.slf4j.Logger) MalformedInputException(java.nio.charset.MalformedInputException) Files(java.nio.file.Files) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) FileSystem(java.nio.file.FileSystem) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) List(java.util.List) Stream(java.util.stream.Stream) Locale(java.util.Locale) URI(java.net.URI) Pattern(java.util.regex.Pattern) Path(java.nio.file.Path) Collections(java.util.Collections) FileSystems(java.nio.file.FileSystems) Pattern(java.util.regex.Pattern) MalformedInputException(java.nio.charset.MalformedInputException) IOException(java.io.IOException)

Example 63 with Files

use of java.nio.file.Files in project flink by apache.

the class TestBaseUtils method getAllInvolvedFiles.

private static File[] getAllInvolvedFiles(String resultPath, final String[] excludePrefixes) {
    final File result = asFile(resultPath);
    assertTrue("Result file was not written", result.exists());
    if (result.isDirectory()) {
        try {
            return Files.walk(result.toPath()).filter(Files::isRegularFile).filter(path -> {
                for (String prefix : excludePrefixes) {
                    if (path.getFileName().startsWith(prefix)) {
                        return false;
                    }
                }
                return true;
            }).map(Path::toFile).filter(file -> !file.isHidden()).toArray(File[]::new);
        } catch (IOException e) {
            throw new RuntimeException("Failed to retrieve result files");
        }
    } else {
        return new File[] { result };
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Arrays(java.util.Arrays) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) ArrayList(java.util.ArrayList) Matcher(java.util.regex.Matcher) Map(java.util.Map) ConfigConstants(org.apache.flink.configuration.ConfigConstants) TestLogger(org.apache.flink.util.TestLogger) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) Path(java.nio.file.Path) Tuple(org.apache.flink.api.java.tuple.Tuple) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Assert.assertTrue(org.junit.Assert.assertTrue) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) CommonTestUtils(org.apache.flink.core.testutils.CommonTestUtils) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Preconditions.checkArgument(org.apache.flink.util.Preconditions.checkArgument) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) Assert(org.junit.Assert) Comparator(java.util.Comparator) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Path(java.nio.file.Path) IOException(java.io.IOException) Files(java.nio.file.Files) File(java.io.File)

Example 64 with Files

use of java.nio.file.Files in project flink by apache.

the class SavepointITCase method testTriggerSavepointAndResumeWithNoClaim.

@Test
@Ignore("Disabling this test because it regularly fails on AZP. See FLINK-25427.")
public void testTriggerSavepointAndResumeWithNoClaim() throws Exception {
    final int numTaskManagers = 2;
    final int numSlotsPerTaskManager = 2;
    final int parallelism = numTaskManagers * numSlotsPerTaskManager;
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setStateBackend(new EmbeddedRocksDBStateBackend(true));
    env.getCheckpointConfig().enableExternalizedCheckpoints(CheckpointConfig.ExternalizedCheckpointCleanup.RETAIN_ON_CANCELLATION);
    env.getCheckpointConfig().setCheckpointStorage(folder.newFolder().toURI());
    env.setParallelism(parallelism);
    final SharedReference<CountDownLatch> counter = sharedObjects.add(new CountDownLatch(10_000));
    env.fromSequence(1, Long.MAX_VALUE).keyBy(i -> i % parallelism).process(new KeyedProcessFunction<Long, Long, Long>() {

        private ListState<Long> last;

        @Override
        public void open(Configuration parameters) {
            // we use list state here to create sst files of a significant size
            // if sst files do not reach certain thresholds they are not stored
            // in files, but as a byte stream in checkpoints metadata
            last = getRuntimeContext().getListState(new ListStateDescriptor<>("last", BasicTypeInfo.LONG_TYPE_INFO));
        }

        @Override
        public void processElement(Long value, KeyedProcessFunction<Long, Long, Long>.Context ctx, Collector<Long> out) throws Exception {
            last.add(value);
            out.collect(value);
        }
    }).addSink(new SinkFunction<Long>() {

        @Override
        public void invoke(Long value) {
            counter.consumeSync(CountDownLatch::countDown);
        }
    }).setParallelism(1);
    final JobGraph jobGraph = env.getStreamGraph().getJobGraph();
    MiniClusterWithClientResource cluster = new MiniClusterWithClientResource(new MiniClusterResourceConfiguration.Builder().setNumberTaskManagers(numTaskManagers).setNumberSlotsPerTaskManager(numSlotsPerTaskManager).build());
    cluster.before();
    try {
        final JobID jobID1 = new JobID();
        jobGraph.setJobID(jobID1);
        cluster.getClusterClient().submitJob(jobGraph).get();
        CommonTestUtils.waitForAllTaskRunning(cluster.getMiniCluster(), jobID1, false);
        // wait for some records to be processed before taking the checkpoint
        counter.get().await();
        final String firstCheckpoint = cluster.getMiniCluster().triggerCheckpoint(jobID1).get();
        cluster.getClusterClient().cancel(jobID1).get();
        jobGraph.setSavepointRestoreSettings(SavepointRestoreSettings.forPath(firstCheckpoint, false, RestoreMode.NO_CLAIM));
        final JobID jobID2 = new JobID();
        jobGraph.setJobID(jobID2);
        cluster.getClusterClient().submitJob(jobGraph).get();
        CommonTestUtils.waitForAllTaskRunning(cluster.getMiniCluster(), jobID2, false);
        String secondCheckpoint = cluster.getMiniCluster().triggerCheckpoint(jobID2).get();
        cluster.getClusterClient().cancel(jobID2).get();
        // delete the checkpoint we restored from
        FileUtils.deleteDirectory(Paths.get(new URI(firstCheckpoint)).getParent().toFile());
        // we should be able to restore from the second checkpoint even though it has been built
        // on top of the first checkpoint
        jobGraph.setSavepointRestoreSettings(SavepointRestoreSettings.forPath(secondCheckpoint, false, RestoreMode.NO_CLAIM));
        final JobID jobID3 = new JobID();
        jobGraph.setJobID(jobID3);
        cluster.getClusterClient().submitJob(jobGraph).get();
        CommonTestUtils.waitForAllTaskRunning(cluster.getMiniCluster(), jobID3, false);
    } finally {
        cluster.after();
    }
}
Also used : Arrays(java.util.Arrays) SharedObjects(org.apache.flink.testutils.junit.SharedObjects) MemorySize(org.apache.flink.configuration.MemorySize) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) ExceptionUtils.findThrowable(org.apache.flink.util.ExceptionUtils.findThrowable) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) TestUtils.submitJobAndWaitForResult(org.apache.flink.test.util.TestUtils.submitJobAndWaitForResult) FSDataOutputStream(org.apache.flink.core.fs.FSDataOutputStream) CheckpointListener(org.apache.flink.api.common.state.CheckpointListener) Duration(java.time.Duration) Map(java.util.Map) StreamGraph(org.apache.flink.streaming.api.graph.StreamGraph) ExceptionUtils.assertThrowable(org.apache.flink.util.ExceptionUtils.assertThrowable) RichSourceFunction(org.apache.flink.streaming.api.functions.source.RichSourceFunction) Path(java.nio.file.Path) StateSnapshotContext(org.apache.flink.runtime.state.StateSnapshotContext) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) BoundedOneInput(org.apache.flink.streaming.api.operators.BoundedOneInput) FileSystemFactory(org.apache.flink.core.fs.FileSystemFactory) CountDownLatch(java.util.concurrent.CountDownLatch) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) Stream(java.util.stream.Stream) ValueState(org.apache.flink.api.common.state.ValueState) ClusterClient(org.apache.flink.client.program.ClusterClient) Assert.assertFalse(org.junit.Assert.assertFalse) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) Time(org.apache.flink.api.common.time.Time) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) FlinkException(org.apache.flink.util.FlinkException) LocalFileSystem(org.apache.flink.core.fs.local.LocalFileSystem) JobStatus(org.apache.flink.api.common.JobStatus) KeyedProcessFunction(org.apache.flink.streaming.api.functions.KeyedProcessFunction) TypeSafeDiagnosingMatcher(org.hamcrest.TypeSafeDiagnosingMatcher) TaskManagerOptions(org.apache.flink.configuration.TaskManagerOptions) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) RichMapFunction(org.apache.flink.api.common.functions.RichMapFunction) Collector(org.apache.flink.util.Collector) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) Before(org.junit.Before) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) Files(java.nio.file.Files) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) File(java.io.File) AbstractStreamOperator(org.apache.flink.streaming.api.operators.AbstractStreamOperator) ExecutionException(java.util.concurrent.ExecutionException) JobID(org.apache.flink.api.common.JobID) Paths(java.nio.file.Paths) Matcher(org.hamcrest.Matcher) Assert(org.junit.Assert) SavepointRestoreSettings(org.apache.flink.runtime.jobgraph.SavepointRestoreSettings) Assert.assertEquals(org.junit.Assert.assertEquals) StateBackendOptions(org.apache.flink.configuration.StateBackendOptions) EntropyInjectingTestFileSystem(org.apache.flink.testutils.EntropyInjectingTestFileSystem) Deadline(org.apache.flink.api.common.time.Deadline) ExceptionUtils.findThrowableWithMessage(org.apache.flink.util.ExceptionUtils.findThrowableWithMessage) ClusterOptions(org.apache.flink.configuration.ClusterOptions) FileUtils(org.apache.flink.util.FileUtils) URISyntaxException(java.net.URISyntaxException) BiFunction(java.util.function.BiFunction) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) LoggerFactory(org.slf4j.LoggerFactory) BlockingNoOpInvokable(org.apache.flink.runtime.testtasks.BlockingNoOpInvokable) Random(java.util.Random) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) EmbeddedRocksDBStateBackend(org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend) MapFunction(org.apache.flink.api.common.functions.MapFunction) BasicTypeInfo(org.apache.flink.api.common.typeinfo.BasicTypeInfo) Assert.assertThat(org.junit.Assert.assertThat) ListState(org.apache.flink.api.common.state.ListState) CommonTestUtils.waitForAllTaskRunning(org.apache.flink.runtime.testutils.CommonTestUtils.waitForAllTaskRunning) ChainingStrategy(org.apache.flink.streaming.api.operators.ChainingStrategy) TestLogger(org.apache.flink.util.TestLogger) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) KeySelector(org.apache.flink.api.java.functions.KeySelector) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) CheckpointingOptions(org.apache.flink.configuration.CheckpointingOptions) Objects(java.util.Objects) TestingUtils(org.apache.flink.testutils.TestingUtils) List(java.util.List) FileSystem(org.apache.flink.core.fs.FileSystem) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Optional(java.util.Optional) CheckpointConfig(org.apache.flink.streaming.api.environment.CheckpointConfig) ParallelSourceFunction(org.apache.flink.streaming.api.functions.source.ParallelSourceFunction) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) RichFlatMapFunction(org.apache.flink.api.common.functions.RichFlatMapFunction) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) IterativeStream(org.apache.flink.streaming.api.datastream.IterativeStream) CompletableFuture(java.util.concurrent.CompletableFuture) RestartStrategies(org.apache.flink.api.common.restartstrategy.RestartStrategies) RestClusterClient(org.apache.flink.client.program.rest.RestClusterClient) RestoreMode(org.apache.flink.runtime.jobgraph.RestoreMode) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) CompletableFuture.allOf(java.util.concurrent.CompletableFuture.allOf) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) JobDetailsHeaders(org.apache.flink.runtime.rest.messages.job.JobDetailsHeaders) SharedReference(org.apache.flink.testutils.junit.SharedReference) Description(org.hamcrest.Description) Logger(org.slf4j.Logger) LocalRecoverableWriter(org.apache.flink.core.fs.local.LocalRecoverableWriter) DiscardingSink(org.apache.flink.streaming.api.functions.sink.DiscardingSink) Assert.assertNotNull(org.junit.Assert.assertNotNull) Configuration(org.apache.flink.configuration.Configuration) ExceptionUtils.assertThrowableWithMessage(org.apache.flink.util.ExceptionUtils.assertThrowableWithMessage) DataStream(org.apache.flink.streaming.api.datastream.DataStream) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) Ignore(org.junit.Ignore) ListCheckpointed(org.apache.flink.streaming.api.checkpoint.ListCheckpointed) FileVisitOption(java.nio.file.FileVisitOption) CommonTestUtils(org.apache.flink.runtime.testutils.CommonTestUtils) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) KeyedProcessFunction(org.apache.flink.streaming.api.functions.KeyedProcessFunction) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) FlinkException(org.apache.flink.util.FlinkException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) EmbeddedRocksDBStateBackend(org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) JobID(org.apache.flink.api.common.JobID) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 65 with Files

use of java.nio.file.Files in project kafka by apache.

the class TestPlugins method writeJar.

private static void writeJar(JarOutputStream jar, Path inputDir) throws IOException {
    List<Path> paths = Files.walk(inputDir).filter(Files::isRegularFile).filter(path -> !path.toFile().getName().endsWith(".java")).collect(Collectors.toList());
    for (Path path : paths) {
        try (InputStream in = new BufferedInputStream(new FileInputStream(path.toFile()))) {
            jar.putNextEntry(new JarEntry(inputDir.relativize(path).toFile().getPath().replace(File.separator, "/")));
            byte[] buffer = new byte[1024];
            for (int count; (count = in.read(buffer)) != -1; ) {
                jar.write(buffer, 0, count);
            }
            jar.closeEntry();
        }
    }
}
Also used : Path(java.nio.file.Path) Manifest(java.util.jar.Manifest) Arrays(java.util.Arrays) BufferedInputStream(java.io.BufferedInputStream) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JarEntry(java.util.jar.JarEntry) Map(java.util.Map) Path(java.nio.file.Path) JarOutputStream(java.util.jar.JarOutputStream) Logger(org.slf4j.Logger) Files(java.nio.file.Files) JavaCompiler(javax.tools.JavaCompiler) StringWriter(java.io.StringWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Attributes(java.util.jar.Attributes) Collectors(java.util.stream.Collectors) File(java.io.File) StandardJavaFileManager(javax.tools.StandardJavaFileManager) List(java.util.List) Comparator(java.util.Comparator) Collections(java.util.Collections) ToolProvider(javax.tools.ToolProvider) InputStream(java.io.InputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Files(java.nio.file.Files) JarEntry(java.util.jar.JarEntry) FileInputStream(java.io.FileInputStream)

Aggregations

Files (java.nio.file.Files)243 IOException (java.io.IOException)210 Path (java.nio.file.Path)196 List (java.util.List)176 Collectors (java.util.stream.Collectors)154 Paths (java.nio.file.Paths)133 File (java.io.File)127 ArrayList (java.util.ArrayList)117 Map (java.util.Map)109 Set (java.util.Set)96 Collections (java.util.Collections)89 Arrays (java.util.Arrays)81 Stream (java.util.stream.Stream)77 HashMap (java.util.HashMap)74 HashSet (java.util.HashSet)58 InputStream (java.io.InputStream)55 Collection (java.util.Collection)55 Logger (org.slf4j.Logger)54 Pattern (java.util.regex.Pattern)53 Optional (java.util.Optional)51