public File exec()

in src/main/java/co/elastic/support/scrub/ScrubService.java [36:98]


    public File exec(ScrubInputs inputs) throws DiagnosticException {
        ExecutorService executorService = null;
        String scrubDir = "";

        try {
            scrubDir = inputs.outputDir + SystemProperties.fileSeparator + "scrubbed-" + inputs.scrubbedFileBaseName;

            SystemUtils.refreshDir(scrubDir);

            // Redirect the log file output to the scrubbed output target location.
            createFileAppender(inputs.outputDir, "scrubber.log");
            executorService = Executors.newFixedThreadPool(inputs.workers);
            logger.info(Constants.CONSOLE, "Threadpool configured with {} workers.", inputs.workers);

            // Get a collection of entries to send parcel out to the task collection
            Vector<TaskEntry> entriesToScrub;
            String nodeString = "";
            switch (inputs.type) {
                case "zip":
                    entriesToScrub = collectZipEntries(inputs.scrub, scrubDir);
                    nodeString = getNodeInfoFromZip(inputs.scrub);
                    break;
                case "dir":
                    entriesToScrub = collectDirEntries(inputs.scrub, scrubDir);
                    nodeString = getNodeInfoFromDir(inputs.scrub);
                    break;
                default:
                    String rootDir = inputs.scrub.substring(0,
                            inputs.scrub.lastIndexOf(SystemProperties.fileSeparator));
                    entriesToScrub = collectDirEntries(inputs.scrub, rootDir);
            }

            ScrubProcessor processor;
            if (StringUtils.isNotEmpty(nodeString)) {
                processor = new ScrubProcessor(nodeString);
            } else {
                processor = new ScrubProcessor();
            }

            ArrayList<ScrubTask> tasks = new ArrayList<>();
            for (TaskEntry entry : entriesToScrub) {
                tasks.add(new ScrubTask(processor, entry, scrubDir));
            }

            List<Future<String>> futures = executorService.invokeAll(tasks);
            futures.forEach(e -> {
                try {
                    logger.debug("processed: " + e.get());
                } catch (Exception ex) {
                    logger.error(e);
                }
            });

            // Finish up by zipping it.
            return createArchive(scrubDir);
        } catch (Throwable throwable) {
            throw new DiagnosticException("Could not scrub archive", throwable);
        } finally {
            executorService.shutdown();
            closeLogs();
            SystemUtils.nukeDirectory(scrubDir);
        }
    }