Java Code Examples for hudson.model.Executor#isBusy()

The following examples show how to use hudson.model.Executor#isBusy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HudsonTestCase.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Waits until Jenkins finishes building everything, including those builds in the queue, or fail the test
 * if the specified timeout milliseconds is exceeded.
 */
protected void waitUntilNoActivityUpTo(int timeout) throws Exception {
    long startTime = System.currentTimeMillis();
    int streak = 0;

    while (true) {
        Thread.sleep(100);
        if (isSomethingHappening())
            streak=0;
        else
            streak++;

        if (streak>2)   // the system is quiet for a while
            return;

        if (System.currentTimeMillis()-startTime > timeout) {
            List<Executable> building = new ArrayList<Executable>();
            for (Computer c : jenkins.getComputers()) {
                for (Executor e : c.getExecutors()) {
                    if (e.isBusy())
                        building.add(e.getCurrentExecutable());
                }
            }
            throw new AssertionError(String.format("Jenkins is still doing something after %dms: queue=%s building=%s",
                    timeout, Arrays.asList(jenkins.getQueue().getItems()), building));
        }
    }
}
 
Example 2
Source File: JobRunnerForCause.java    From github-integration-plugin with MIT License 4 votes vote down vote up
public synchronized int abortRunning(int number) throws IllegalAccessException {
        int aborted = 0;

        Computer[] computers = getJenkinsInstance().getComputers();
        for (Computer computer : computers) {
            if (isNull(computer)) {
                continue;
            }

            List<Executor> executors = computer.getExecutors();
            executors.addAll(computer.getOneOffExecutors());

            for (Executor executor : executors) {
                if (isNull(executor) || !executor.isBusy() || nonNull(executor.getCauseOfDeath()) ||
                        !getInterruptCauses(executor).isEmpty() || getInterruptStatus(executor) == Result.ABORTED) {
                    continue;
                }

                Queue.Executable executable = executor.getCurrentExecutable();
                final SubTask parent = executable.getParent();

                if (!(executable instanceof Run)) {
                    continue;
                }
                final Run executableRun = (Run) executable;

                if (!(parent instanceof Job)) {
                    continue;
                }
                final Job parentJob = (Job) parent;

                if (!parentJob.getFullName().equals(job.getFullName())) {
                    // name doesn't match
                    continue;
                }

                if (executableRun.getResult() == Result.ABORTED) {
                    // was already aborted
                    continue;
                }

                if (executableRun instanceof MatrixRun) {
                    // the whole MatrixBuild will be aborted
                    continue;
                }
//                if (executable instanceof MatrixBuild) {
//                    final MatrixBuild executable1 = (MatrixBuild) executable;
//                    executable1.doStop()
//                }

                final GitHubPRCause causeAction = (GitHubPRCause) executableRun.getCause(GitHubPRCause.class);
                if (nonNull(causeAction) && causeAction.getNumber() == number) {
                    LOGGER.info("Aborting '{}', by interrupting '{}'", executableRun, executor);
                    executor.interrupt(Result.ABORTED, new NewPRInterruptCause());
                    aborted++;
                }
            }
        }

        return aborted;
    }