public void execute()

in priam/src/main/java/com/netflix/priam/restore/PostRestoreHook.java [76:151]


    public void execute() throws Exception {
        if (config.isPostRestoreHookEnabled()) {
            logger.debug("Started PostRestoreHook execution");

            // create a temp file to be used to indicate state of the current process, to the
            // sub-process
            File tempLockFile =
                    File.createTempFile(
                            PriamPostRestoreHookFilePrefix, PriamPostRestoreHookFileSuffix);
            RandomAccessFile raf = new RandomAccessFile(tempLockFile.getPath(), "rw");
            FileChannel fileChannel = raf.getChannel();
            FileLock lock = fileChannel.lock();

            try {
                if (lock.isValid()) {
                    logger.info("Lock on RestoreHookFile acquired");
                    int countOfProcessStarts = 0;
                    while (true) {
                        if (doneFileExists()) {
                            logger.info(
                                    "Not starting PostRestoreHook since DONE file already exists.");
                            break;
                        }

                        String postRestoreHook = config.getPostRestoreHook();
                        // add temp file path as parameter to the jar file
                        postRestoreHook =
                                postRestoreHook
                                        + PostRestoreHookCommandDelimiter
                                        + PriamPostRestoreHookFileOptionName
                                        + tempLockFile.getAbsolutePath();
                        String[] processCommandArguments =
                                postRestoreHook.split(PostRestoreHookCommandDelimiter);
                        ProcessBuilder processBuilder = new ProcessBuilder(processCommandArguments);

                        // start sub-process
                        Process process = processBuilder.inheritIO().start();
                        logger.info(
                                "Started PostRestoreHook: {} - Attempt#{}",
                                postRestoreHook,
                                ++countOfProcessStarts);

                        // monitor progress of sub-process
                        monitorPostRestoreHookHeartBeat(process);

                        // block until sub-process completes or until the timeout
                        if (!process.waitFor(
                                config.getPostRestoreHookTimeOutInDays(), TimeUnit.DAYS)) {
                            logger.info(
                                    "PostRestoreHook process did not complete within {} days. Forcefully terminating the process.",
                                    config.getPostRestoreHookTimeOutInDays());
                            process.destroyForcibly();
                        }

                        if (process.exitValue() == 0) {
                            logger.info("PostRestoreHook process completed successfully");
                            break;
                        }
                        logger.warn("PostRestoreHook process exited unsuccessfully");
                    }
                    logger.debug("Completed PostRestoreHook execution");
                } else {
                    throw new PostRestoreHookException(
                            String.format(
                                    "Could not acquire lock on a temp file necessary for PostRestoreHook to execute. Path to temp file: %s",
                                    tempLockFile.getAbsolutePath()));
                }
            } finally {
                // close and delete temp file
                lock.release();
                fileChannel.close();
                raf.close();
                tempLockFile.delete();
            }
        }
    }