hudson.model.Executor Java Examples

The following examples show how to use hudson.model.Executor. 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: DockerOnceRetentionStrategy.java    From yet-another-docker-plugin with MIT License 6 votes vote down vote up
protected void done(Executor executor) {
    final AbstractCloudComputer<?> c = (AbstractCloudComputer) executor.getOwner();
    Queue.Executable exec = executor.getCurrentExecutable();
    if (executor instanceof OneOffExecutor) {
        LOG.debug("Not terminating {} because {} was a flyweight task", c.getName(), exec);
        return;
    }

    if (exec instanceof ContinuableExecutable && ((ContinuableExecutable) exec).willContinue()) {
        LOG.debug("not terminating {} because {} says it will be continued", c.getName(), exec);
        return;
    }

    LOG.debug("terminating {} since {} seems to be finished", c.getName(), exec);
    done(c);
}
 
Example #2
Source File: SubBuildScheduler.java    From DotCi with MIT License 6 votes vote down vote up
public void cancelSubBuilds(final PrintStream logger) {
    final Queue q = getJenkins().getQueue();
    synchronized (q) {
        final int n = this.dynamicBuild.getNumber();
        for (final Item i : q.getItems()) {
            final ParentBuildAction parentBuildAction = i.getAction(ParentBuildAction.class);
            if (parentBuildAction != null && this.dynamicBuild.equals(parentBuildAction.getParent())) {
                q.cancel(i);
            }
        }
        for (final DynamicSubProject c : this.dynamicBuild.getAllSubProjects()) {
            final DynamicSubBuild b = c.getBuildByNumber(n);
            if (b != null && b.isBuilding()) {
                final Executor exe = b.getExecutor();
                if (exe != null) {
                    logger.println(Messages.MatrixBuild_Interrupting(ModelHyperlinkNote.encodeTo(b)));
                    exe.interrupt();
                }
            }
        }
    }
}
 
Example #3
Source File: ContainerRecordUtils.java    From yet-another-docker-plugin with MIT License 6 votes vote down vote up
public static void attachFacet(Run<?, ?> run, TaskListener listener) {
    final Executor executor = run.getExecutor();
    if (executor == null) {
        return;
    }

    final Computer owner = executor.getOwner();
    DockerComputer dockerComputer;
    if (owner instanceof DockerComputer) {
        dockerComputer = (DockerComputer) owner;
        try {
            DockerFingerprints.addRunFacet(
                    createRecordFor(dockerComputer),
                    run
            );
        } catch (IOException | ParseException e) {
            listener.error("Can't add Docker fingerprint to run.");
            LOG.error("Can't add fingerprint to run {}", run, e);
        }
    }


}
 
Example #4
Source File: KubernetesSlave.java    From kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public Launcher createLauncher(TaskListener listener) {
    Launcher launcher = super.createLauncher(listener);
    if (template != null) {
        Executor executor = Executor.currentExecutor();
        if (executor != null) {
            Queue.Executable currentExecutable = executor.getCurrentExecutable();
            if (currentExecutable != null && executables.add(currentExecutable)) {
                listener.getLogger().println(Messages.KubernetesSlave_AgentIsProvisionedFromTemplate(
                        ModelHyperlinkNote.encodeTo("/computer/" + getNodeName(), getNodeName()),
                        getTemplate().getName())
                );
                printAgentDescription(listener);
                checkHomeAndWarnIfNeeded(listener);
            }
        }
    }
    return launcher;
}
 
Example #5
Source File: DbBackedBuild.java    From DotCi with MIT License 6 votes vote down vote up
@Override
@Exported
public Executor getExecutor() {
    final Jenkins jenkins = Jenkins.getInstance();
    if (jenkins == null) {
        return null;
    }
    for (final Computer computer : jenkins.getComputers()) {
        for (final Executor executor : computer.getExecutors()) {
            if (isCurrent(executor)) {
                return executor;
            }
        }
    }
    return null;
}
 
Example #6
Source File: Computers.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Exported(inline=true)
public Container<ExecutorInfo> getExecutors() {
    final List<ExecutorInfo> out = new ArrayList<>();
    if (computer != null) {
        for (Executor e : computer.getExecutors()) {
            out.add(new ExecutorInfo(this, e));
        }
    }
    return new Container() {
        @Override
        public Object get(String string) {
            throw new UnsupportedOperationException("Not supported.");
        }

        @Override
        public Iterator iterator() {
            return out.iterator();
        }

        @Override
        public Link getLink() {
            return parent.rel("executors");
        }
    };
}
 
Example #7
Source File: ShellScriptRunner.java    From DotCi with MIT License 6 votes vote down vote up
public Result runScript(final ShellCommands commands) throws IOException, InterruptedException {
    Result r = Result.FAILURE;
    //Todo: use VitualChannel to figure out OS
    final String shellInterpreter = Functions.isWindows() ? "sh" : "/bin/bash";
    final Run run = this.buildExecutionContext.getRun();
    addExecutionInfoAction(run, commands);
    try {
        final Shell execution = new Shell("#!" + shellInterpreter + " -le \n" + commands.toShellScript());
        if (this.buildExecutionContext.performStep(execution, this.listener)) {
            r = Result.SUCCESS;
        }
    } catch (final InterruptedException e) {
        r = Executor.currentExecutor().abortResult();
        throw e;
    } finally {
        this.buildExecutionContext.setResult(r);
    }
    return r;
}
 
Example #8
Source File: LockStepHardKillTest.java    From lockable-resources-plugin with MIT License 5 votes vote down vote up
private void interruptTermKill(WorkflowRun b) throws Exception {
  if (b != null) {
    Executor ex = b.getExecutor();
    assertNotNull(ex);
    ex.interrupt();
    j.waitForCompletion(b);
    j.assertBuildStatus(Result.ABORTED, b);
  }
}
 
Example #9
Source File: ECSComputer.java    From amazon-ecs-plugin with MIT License 5 votes vote down vote up
@Override
public void taskAccepted(Executor executor, Queue.Task task) {
    super.taskAccepted(executor, task);
    LOGGER.log(Level.INFO, "[{0}]: JobName: {1}", new Object[] {this.getName(), task.getDisplayName()});
    LOGGER.log(Level.INFO, "[{0}]: JobUrl: {1}", new Object[] {this.getName(), task.getUrl()});
    LOGGER.log(Level.FINE, "[{0}]: taskAccepted", this);
}
 
Example #10
Source File: DockerComputer.java    From yet-another-docker-plugin with MIT License 5 votes vote down vote up
@Override
public void taskCompleted(Executor executor, Queue.Task task, long durationMS) {
    LOG.debug("Computer {} taskCompleted", this);

    // May take the slave offline and remove it, in which case getNode()
    // above would return null and we'd not find our DockerSlave anymore.
    super.taskCompleted(executor, task, durationMS);
}
 
Example #11
Source File: KubernetesComputer.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void taskCompleted(Executor executor, Queue.Task task, long durationMS) {
    Queue.Executable exec = executor.getCurrentExecutable();
    LOGGER.log(Level.FINE, " Computer {0} completed task {1}", new Object[] {this, exec});

    // May take the agent offline and remove it, in which case getNode()
    // above would return null and we'd not find our DockerSlave anymore.
    super.taskCompleted(executor, task, durationMS);
}
 
Example #12
Source File: PhabricatorBuildWrapper.java    From phabricator-jenkins-plugin with MIT License 5 votes vote down vote up
/**
 * Abort running builds when new build referencing same revision is scheduled to run
 */
@Override
public void preCheckout(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException,
        InterruptedException {
    String abortOnRevisionId = getAbortOnRevisionId(build);
    // If ABORT_ON_REVISION_ID is available
    if (!CommonUtils.isBlank(abortOnRevisionId)) {
        // Create a cause of interruption
        PhabricatorCauseOfInterruption causeOfInterruption =
                new PhabricatorCauseOfInterruption(build.getUrl());
        Run upstreamRun = getUpstreamRun(build);

        // Get the running builds that were scheduled before the current one
        RunList<AbstractBuild> runningBuilds = (RunList<AbstractBuild>) build.getProject().getBuilds();
        for (AbstractBuild runningBuild : runningBuilds) {
            Executor executor = runningBuild.getExecutor();
            Run runningBuildUpstreamRun = getUpstreamRun(runningBuild);

            // Ignore builds that were triggered by the same upstream build
            // Find builds triggered with the same ABORT_ON_REVISION_ID_FIELD
            if (runningBuild.isBuilding()
                    && runningBuild.number < build.number
                    && abortOnRevisionId.equals(getAbortOnRevisionId(runningBuild))
                    && (upstreamRun == null
                    || runningBuildUpstreamRun == null
                    || !upstreamRun.equals(runningBuildUpstreamRun))
                    && executor != null) {
                // Abort the builds
                executor.interrupt(Result.ABORTED, causeOfInterruption);
            }
        }
    }
}
 
Example #13
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 #14
Source File: DockerOnceRetentionStrategy.java    From docker-plugin with MIT License 5 votes vote down vote up
private void done(Executor executor) {
    final DockerComputer c = (DockerComputer) executor.getOwner();
    Queue.Executable exec = executor.getCurrentExecutable();
    if (exec instanceof ContinuableExecutable && ((ContinuableExecutable) exec).willContinue()) {
        LOGGER.log(Level.FINE, "not terminating {0} because {1} says it will be continued", new Object[]{c.getName(), exec});
        return;
    }
    LOGGER.log(Level.FINE, "terminating {0} since {1} seems to be finished", new Object[]{c.getName(), exec});
    done(c);
}
 
Example #15
Source File: DockerSwarmComputer.java    From docker-swarm-plugin with MIT License 5 votes vote down vote up
public Queue.Executable getCurrentBuild() {
    if (!Iterables.isEmpty(getExecutors())) {
        final Executor exec = getExecutors().get(0);
        return exec.getCurrentExecutable() == null ? null : exec.getCurrentExecutable();
    }
    return null;
}
 
Example #16
Source File: DockerSwarmAgentRetentionStrategy.java    From docker-swarm-plugin with MIT License 5 votes vote down vote up
private void done(Executor executor) {
    final DockerSwarmComputer c = (DockerSwarmComputer) executor.getOwner();
    Queue.Executable exec = executor.getCurrentExecutable();
    if (exec instanceof ContinuableExecutable && ((ContinuableExecutable) exec).willContinue()) {
        LOGGER.log(Level.FINE, "not terminating {0} because {1} says it will be continued",
                new Object[] { c.getName(), exec });
        return;
    }
    LOGGER.log(Level.FINE, "terminating {0} since {1} seems to be finished", new Object[] { c.getName(), exec });
    done(c);
}
 
Example #17
Source File: DbBackedBuild.java    From DotCi with MIT License 5 votes vote down vote up
@Override
public Executor getOneOffExecutor() {
    for (final Computer c : Jenkins.getInstance().getComputers()) {
        for (final Executor e : c.getOneOffExecutors()) {
            if (isCurrent(e))
                return e;
        }
    }
    return null;
}
 
Example #18
Source File: DockerOnceRetentionStrategy.java    From docker-plugin with MIT License 4 votes vote down vote up
@Override
public void taskCompletedWithProblems(Executor executor, Queue.Task task, long durationMS, Throwable problems) {
    done(executor);
}
 
Example #19
Source File: DynamicBuild.java    From DotCi with MIT License 4 votes vote down vote up
@Override
@Exported
public Executor getExecutor() {
    final Executor executor = super.getExecutor();
    return executor == null ? getOneOffExecutor() : executor;
}
 
Example #20
Source File: DockerOnceRetentionStrategy.java    From docker-plugin with MIT License 4 votes vote down vote up
@Override
public void taskCompleted(Executor executor, Queue.Task task, long durationMS) {
    done(executor);
}
 
Example #21
Source File: DbBackedBuild.java    From DotCi with MIT License 4 votes vote down vote up
private boolean isCurrent(final Executor executor) {
    final Executable currentExecutable = executor.getCurrentExecutable();
    return currentExecutable != null && currentExecutable instanceof DbBackedBuild && this.equals(currentExecutable);
}
 
Example #22
Source File: DockerOnceRetentionStrategy.java    From docker-plugin with MIT License 4 votes vote down vote up
@Override
public void taskAccepted(Executor executor, Queue.Task task) {
}
 
Example #23
Source File: ECSComputer.java    From amazon-ecs-plugin with MIT License 4 votes vote down vote up
@Override
public void taskCompletedWithProblems(Executor executor, Queue.Task task, long durationMS, Throwable problems) {
    super.taskCompletedWithProblems(executor, task, durationMS, problems);
    LOGGER.log(Level.FINE, "[{0}]: taskCompletedWithProblems", this);
}
 
Example #24
Source File: ECSComputer.java    From amazon-ecs-plugin with MIT License 4 votes vote down vote up
@Override
public void taskCompleted(Executor executor, Queue.Task task, long durationMS) {
    super.taskCompleted(executor, task, durationMS);
    LOGGER.log(Level.FINE, "[{0}]: taskCompleted", this);
}
 
Example #25
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;
    }
 
Example #26
Source File: DockerOnceRetentionStrategy.java    From yet-another-docker-plugin with MIT License 4 votes vote down vote up
@Override
public void taskAccepted(Executor executor, Queue.Task task) {
}
 
Example #27
Source File: JobHelper.java    From github-integration-plugin with MIT License 4 votes vote down vote up
public static List<CauseOfInterruption> getInterruptCauses(Executor executor) throws IllegalAccessException {
    return (List<CauseOfInterruption>) FieldUtils.readField(executor, "causes", true);
}
 
Example #28
Source File: KubernetesComputer.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void taskAccepted(Executor executor, Queue.Task task) {
    super.taskAccepted(executor, task);
    Queue.Executable exec = executor.getCurrentExecutable();
    LOGGER.log(Level.FINE, " Computer {0} accepted task {1}", new Object[] {this, exec});
}
 
Example #29
Source File: DockerSwarmAgentRetentionStrategy.java    From docker-swarm-plugin with MIT License 4 votes vote down vote up
@Override
public void taskCompleted(Executor executor, Queue.Task task, long durationMS) {
    this.isTaskCompleted = true;
    getLogger(executor).println("Task completed: " + task.getFullDisplayName());
    done(executor);
}
 
Example #30
Source File: DockerSwarmAgentRetentionStrategy.java    From docker-swarm-plugin with MIT License 4 votes vote down vote up
private PrintStream getLogger(Executor executor) {
    final DockerSwarmComputer c = (DockerSwarmComputer) executor.getOwner();
    return c.getListener().getLogger();
}