Package hudson.model

Examples of hudson.model.Executor


            private static final String COOKIE_VAR = "JENKINS_SERVER_COOKIE";

            @Override public void run() {
                try {
                    Executor exec = Executor.currentExecutor();
                    if (exec == null) {
                        throw new IllegalStateException("running task without associated executor thread");
                    }
                    Computer computer = exec.getOwner();
                    // Set up context for other steps inside this one.
                    Node node = computer.getNode();
                    if (node == null) {
                        throw new IllegalStateException("running computer lacks a node");
                    }
                    TaskListener listener = context.get(TaskListener.class);
                    Launcher launcher = node.createLauncher(listener);
                    Run<?,?> r = context.get(Run.class);
                    if (cookie == null) {
                        // First time around.
                        cookie = UUID.randomUUID().toString();
                        // Switches the label to a self-label, so if the executable is killed and restarted via ExecutorPickle, it will run on the same node:
                        label = computer.getName();
                        EnvVars env = computer.buildEnvironment(listener);
                        env.put(COOKIE_VAR, cookie);
                        synchronized (runningTasks) {
                            runningTasks.put(cookie, context);
                        }
                        // For convenience, automatically allocate a workspace, like WorkspaceStep would:
                        Job<?,?> j = r.getParent();
                        if (!(j instanceof TopLevelItem)) {
                            throw new Exception(j + " must be a top-level job");
                        }
                        FilePath p = node.getWorkspaceFor((TopLevelItem) j);
                        if (p == null) {
                            throw new IllegalStateException(node + " is offline");
                        }
                        WorkspaceList.Lease lease = computer.getWorkspaceList().allocate(p);
                        FilePath workspace = lease.path;
                        FlowNode flowNode = context.get(FlowNode.class);
                        flowNode.addAction(new WorkspaceActionImpl(workspace, flowNode));
                        listener.getLogger().println("Running on " + computer.getDisplayName() + " in " + workspace); // TODO hyperlink
                        context.invokeBodyLater(exec, computer, env, workspace).addCallback(new Callback(cookie, lease));
                        LOGGER.log(Level.FINE, "started {0}", cookie);
                    } else {
                        // just rescheduled after a restart; wait for task to complete
                        LOGGER.log(Level.FINE, "resuming {0}", cookie);
                    }
                    try {
                        // wait until the invokeBodyLater call above completes and notifies our Callback object
                        synchronized (runningTasks) {
                            while (runningTasks.containsKey(cookie)) {
                                LOGGER.log(Level.FINE, "waiting on {0}", cookie);
                                try {
                                    runningTasks.wait();
                                } catch (InterruptedException x) {
                                    // Jenkins is shutting down or this task was interrupted (Executor.doStop)
                                    // TODO if the latter, we would like an API to StepExecution.stop the tip of our body
                                    exec.recordCauseOfInterruption(r, listener);
                                }
                            }
                        }
                    } finally {
                        try {
View Full Code Here


                    try {
                        execution.interrupt(Result.ABORTED);
                    } catch (Exception x2) {
                        LOGGER.log(Level.WARNING, null, x2);
                    }
                    Executor exec = Executor.currentExecutor();
                    if (exec != null) {
                        exec.recordCauseOfInterruption(this, listener);
                    }
                }
                copyLogs();
            }
        }
View Full Code Here

    }

    /** TODO {@link AbstractBuild#doStop} could be pulled up into {@link Run} making this unnecessary. */
    @RequirePOST
    public synchronized HttpResponse doStop() {
        Executor e = getOneOffExecutor();
        if (e != null) {
            return e.doStop();
        } else {
            return HttpResponses.forwardToPreviousPage();
        }
    }
View Full Code Here

            !(def instanceof StringParameterDefinition) &&
            v.getClass().equals(StringParameterValue.class);
    }

    private static String getCurrentBuildName() {
        Executor e = Executor.currentExecutor();
        if(e == null) {
            return null;
        }
       
        Queue.Executable task = e.getCurrentExecutable();
        if(task == null || !(task instanceof AbstractBuild)) {
            return null;
        }
       
        return ((AbstractBuild<?,?>)task).getFullDisplayName();
View Full Code Here

        Run b = p.getBuildByNumber(Integer.parseInt(id.number));
        if (b==null)
            throw new AbortException("No such build: "+id.number);

        Executor exec = b.getExecutor();
        if (exec==null)
            throw new AbortException(b.getFullDisplayName()+" is not building");

        Node node = exec.getOwner().getNode();

        if (t instanceof NodeSpecific) {
            NodeSpecific n = (NodeSpecific) t;
            t = (ToolInstallation)n.forNode(node,new StreamTaskListener(stderr));
        }
View Full Code Here

                        if (q.cancel(c)) {
                            logger.println(Messages.MatrixBuild_Cancelled(c.getDisplayName()));
                        }
                        MatrixRun b = c.getBuildByNumber(n);
                        if (b != null) {
                            Executor exe = b.getExecutor();
                            if (exe != null) {
                                logger.println(Messages.MatrixBuild_Interrupting(b.getDisplayName()));
                                exe.interrupt();
                            }
                        }
                    }
                }
            }
View Full Code Here

        startLatch.abort(cause);
        endLatch.abort(cause);

        Thread c = Thread.currentThread();
        for (WorkUnit wu : workUnits) {
            Executor e = wu.getExecutor();
            if (e!=null && e!=c)
                e.interrupt();
        }
    }
View Full Code Here

        startLatch = new Latch(workUnitSize) {
            @Override
            protected void onCriteriaMet() {
                // on behalf of the member Executors,
                // the one that executes the main thing will send notifications
                Executor e = Executor.currentExecutor();
                if (e.getCurrentWorkUnit().isMainWork()) {
                    e.getOwner().taskAccepted(e,task);
                }
            }
        };

        endLatch = new Latch(workUnitSize);
View Full Code Here

     */
    public void synchronizeEnd(Queue.Executable executable, Throwable problems, long duration) throws InterruptedException {
        endLatch.synchronize();

        // the main thread will send a notification
        Executor e = Executor.currentExecutor();
        WorkUnit wu = e.getCurrentWorkUnit();
        if (wu.isMainWork()) {
            if (problems == null) {
                future.set(executable);
                e.getOwner().taskCompleted(e, task, duration);
            } else {
                future.set(problems);
                e.getOwner().taskCompletedWithProblems(e, task, duration, problems);
            }
        }
    }
View Full Code Here

TOP

Related Classes of hudson.model.Executor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.