static TaskPair configureNode()

in buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/fixture/hadoop/HadoopClusterFormationTasks.groovy [214:305]


    static TaskPair configureNode(Project project, String prefix, Object dependsOn, InstanceInfo node,
                                  Configuration distributionConfiguration) {
        Task setup = project.tasks.create(name: taskName(prefix, node, 'clean'), type: Delete, dependsOn: dependsOn) {
            delete node.homeDir
            delete node.cwd
            group = 'hadoopFixture'
        }

        // Only create CWD and check previous if the role is an executable process
        if (node.getConfig().getRoleDescriptor().isExecutableProcess()) {
            setup = project.tasks.create(name: taskName(prefix, node, 'createCwd'), type: DefaultTask, dependsOn: setup) {
                doLast {
                    node.cwd.mkdirs()
                }
                outputs.dir node.cwd
                group = 'hadoopFixture'
            }
            setup = configureCheckPreviousTask(taskName(prefix, node, 'checkPrevious'), project, setup, node)
            setup = configureStopTask(taskName(prefix, node, 'stopPrevious'), project, setup, node)
        }

        // Always extract the package contents, and configure the files
        setup = configureExtractTask(taskName(prefix, node, 'extract'), project, setup, node, distributionConfiguration)
        setup = configureWriteConfigTask(taskName(prefix, node, 'configure'), project, setup, node)
        setup = configureExtraConfigFilesTask(taskName(prefix, node, 'extraConfig'), project, setup, node)

        // Give the service descriptor a chance to provide service-specific setup tasks
        SetupTaskFactory setupTaskFactory = new SetupTaskFactory(project, { String name -> taskName(prefix, node, name) }, setup)
        node.config.getServiceDescriptor().configureSetupTasks(node.config, setupTaskFactory)
        setup = setupTaskFactory.getLastSetupTask()

        // If the role for this instance is not a process, we skip creating start and stop tasks for it.
        if (!node.getConfig().getRoleDescriptor().isExecutableProcess()) {
            // Go through the given dependencies for the instance and if any of them are Fixtures, pick the stop tasks off
            // and set the instance tasks as finalized by them.
            for (Object dependency : node.config.getDependencies()) {
                if (dependency instanceof Fixture) {
                    def depStop = ((Fixture)dependency).stopTask
                    setup.finalizedBy(depStop)
                }
            }
            return new TaskPair(startTask: setup)
        }

        Map<String, Object[]> setupCommands = new LinkedHashMap<>()
        setupCommands.putAll(node.config.getServiceDescriptor().defaultSetupCommands(node.config))
        setupCommands.putAll(node.config.getSetupCommands())
        for (Map.Entry<String, Object[]> command : setupCommands) {
            // the first argument is the actual script name, relative to home
            Object[] args = command.getValue().clone()
            if (args == null || args.length == 0) {
                throw new GradleException("Empty command line for setup command [$command.key]")
            }
            final Object commandPath
            if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                /*
                 * We have to delay building the string as the path will not exist during configuration which will fail on
                 * Windows due to getting the short name requiring the path to already exist. Note that we have to capture the
                 * value of arg[0] now otherwise we would stack overflow later since arg[0] is replaced below.
                 */
                String argsZero = args[0]
                commandPath = "${-> Paths.get(InstanceInfo.getShortPathName(node.homeDir.toString())).resolve(argsZero.toString()).toString()}"
            } else {
                commandPath = node.homeDir.toPath().resolve(args[0].toString()).toString()
            }
            args[0] = commandPath
            setup = configureExecTask(taskName(prefix, node, command.getKey()), project, setup, node, args)
        }

        // Configure daemon start task
        Task start = configureStartTask(taskName(prefix, node, 'start'), project, setup, node)

        // Configure wait task
        Task wait = configureWaitTask(taskName(prefix, node, 'wait'), project, node, start, 30)

        // Configure daemon stop task
        Task stop = configureStopTask(taskName(prefix, node, 'stop'), project, [], node)

        // We're running in the background, so make sure that the stop command is called after all cluster tasks finish
        wait.finalizedBy(stop)

        // Go through the given dependencies for the instance and if any of them are Fixtures, pick the stop tasks off
        // and set the instance tasks as finalized by them.
        for (Object dependency : node.config.getDependencies()) {
            if (dependency instanceof Fixture) {
                def depStop = ((Fixture)dependency).stopTask
                wait.finalizedBy(depStop)
                stop.finalizedBy(depStop)
            }
        }
        return new TaskPair(startTask: wait, stopTask: stop)
    }