Search in sources :

Example 1 with NullStream

use of hudson.util.NullStream in project workflow-job-plugin by jenkinsci.

the class WorkflowRun method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    if (completed != null) {
        throw new IllegalStateException("double onLoad of " + this);
    }
    FlowExecution fetchedExecution = execution;
    if (fetchedExecution != null) {
        try {
            if (getParent().isResumeBlocked() && execution instanceof BlockableResume) {
                ((BlockableResume) execution).setResumeBlocked(true);
            }
            fetchedExecution.onLoad(new Owner(this));
        } catch (Exception x) {
            LOGGER.log(Level.WARNING, null, x);
            // probably too broken to use
            execution = null;
        }
    }
    fetchedExecution = execution;
    if (fetchedExecution != null) {
        fetchedExecution.addListener(new GraphL());
        executionPromise.set(fetchedExecution);
        if (!fetchedExecution.isComplete()) {
            // we've been restarted while we were running. let's get the execution going again.
            FlowExecutionListener.fireResumed(fetchedExecution);
            try {
                OutputStream logger = new FileOutputStream(getLogFile(), true);
                listener = new StreamBuildListener(logger, Charset.defaultCharset());
                listener.getLogger().println("Resuming build at " + new Date() + " after Jenkins restart");
            } catch (IOException x) {
                LOGGER.log(Level.WARNING, null, x);
                listener = new StreamBuildListener(new NullStream());
            }
            completed = new AtomicBoolean();
            Timer.get().submit(new // JENKINS-31614
            Runnable() {

                @Override
                public void run() {
                    Queue.getInstance().schedule(new AfterRestartTask(WorkflowRun.this), 0);
                }
            });
        }
    }
    // only for diagnostics
    checkouts(null);
    synchronized (LOADING_RUNS) {
        // or could just make the value type be WeakReference<WorkflowRun>
        LOADING_RUNS.remove(key());
        LOADING_RUNS.notifyAll();
    }
}
Also used : FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) NullStream(hudson.util.NullStream) LineTransformationOutputStream(hudson.console.LineTransformationOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) StreamBuildListener(hudson.model.StreamBuildListener) AbortException(hudson.AbortException) IOException(java.io.IOException) FlowInterruptedException(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) Date(java.util.Date) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) FileOutputStream(java.io.FileOutputStream) BlockableResume(org.jenkinsci.plugins.workflow.flow.BlockableResume)

Example 2 with NullStream

use of hudson.util.NullStream in project hudson-2.x by hudson.

the class JDK method isDefaultJDKValid.

/**
 * Checks if "java" is in PATH on the given node.
 *
 * <p>
 * If it's not, then the user must specify a configured JDK,
 * so this is often useful for form field validation.
 */
public static boolean isDefaultJDKValid(Node n) {
    try {
        TaskListener listener = new StreamTaskListener(new NullStream());
        Launcher launcher = n.createLauncher(listener);
        return launcher.launch().cmds("java", "-fullversion").stdout(listener).join() == 0;
    } catch (IOException e) {
        return false;
    } catch (InterruptedException e) {
        return false;
    }
}
Also used : StreamTaskListener(hudson.util.StreamTaskListener) NullStream(hudson.util.NullStream) StreamTaskListener(hudson.util.StreamTaskListener) Launcher(hudson.Launcher) IOException(java.io.IOException)

Example 3 with NullStream

use of hudson.util.NullStream in project hudson-2.x by hudson.

the class FilePathTest method testCopyTo.

public void testCopyTo() throws Exception {
    File tmp = File.createTempFile("testCopyTo", "");
    FilePath f = new FilePath(french, tmp.getPath());
    f.copyTo(new NullStream());
    assertTrue("target does not exist", tmp.exists());
    assertTrue("could not delete target " + tmp.getPath(), tmp.delete());
}
Also used : NullStream(hudson.util.NullStream) File(java.io.File)

Example 4 with NullStream

use of hudson.util.NullStream in project workflow-job-plugin by jenkinsci.

the class WorkflowRun method sleep.

private AsynchronousExecution sleep() {
    final AsynchronousExecution asynchronousExecution = new AsynchronousExecution() {

        @Override
        public void interrupt(boolean forShutdown) {
            if (forShutdown) {
                return;
            }
            Timer.get().submit(new Runnable() {

                @Override
                public void run() {
                    if (execution == null) {
                        return;
                    }
                    Executor executor = getExecutor();
                    if (executor == null) {
                        LOGGER.log(Level.WARNING, "Lost executor for {0}", WorkflowRun.this);
                        return;
                    }
                    try {
                        Collection<CauseOfInterruption> causes = executor.getCausesOfInterruption();
                        execution.interrupt(executor.abortResult(), causes.toArray(new CauseOfInterruption[causes.size()]));
                    } catch (Exception x) {
                        LOGGER.log(Level.WARNING, null, x);
                    }
                    executor.recordCauseOfInterruption(WorkflowRun.this, listener);
                    printLater(StopState.TERM, "Click here to forcibly terminate running steps");
                }
            });
        }

        @Override
        public boolean blocksRestart() {
            return execution != null && execution.blocksRestart();
        }

        @Override
        public boolean displayCell() {
            return blocksRestart();
        }
    };
    final AtomicReference<ScheduledFuture<?>> copyLogsTask = new AtomicReference<>();
    copyLogsTask.set(copyLogsExecutorService().scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            synchronized (completed) {
                if (completed.get()) {
                    asynchronousExecution.completed(null);
                    copyLogsTask.get().cancel(false);
                    return;
                }
                Jenkins jenkins = Jenkins.getInstance();
                if (jenkins == null || jenkins.isTerminating()) {
                    LOGGER.log(Level.FINE, "shutting down, breaking waitForCompletion on {0}", this);
                    // Stop writing content, in case a new set of objects gets loaded after in-VM restart and starts writing to the same file:
                    listener.closeQuietly();
                    listener = new StreamBuildListener(new NullStream());
                    return;
                }
                try (WithThreadName naming = new WithThreadName(" (" + WorkflowRun.this + ")")) {
                    copyLogs();
                }
            }
        }
    }, 1, 1, TimeUnit.SECONDS));
    return asynchronousExecution;
}
Also used : AsynchronousExecution(jenkins.model.queue.AsynchronousExecution) NullStream(hudson.util.NullStream) WithThreadName(org.jenkinsci.plugins.workflow.support.concurrent.WithThreadName) AtomicReference(java.util.concurrent.atomic.AtomicReference) StreamBuildListener(hudson.model.StreamBuildListener) AbortException(hudson.AbortException) IOException(java.io.IOException) FlowInterruptedException(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) ScheduledFuture(java.util.concurrent.ScheduledFuture) Jenkins(jenkins.model.Jenkins) Executor(hudson.model.Executor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Collection(java.util.Collection)

Aggregations

NullStream (hudson.util.NullStream)4 IOException (java.io.IOException)3 AbortException (hudson.AbortException)2 StreamBuildListener (hudson.model.StreamBuildListener)2 FlowInterruptedException (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException)2 Launcher (hudson.Launcher)1 LineTransformationOutputStream (hudson.console.LineTransformationOutputStream)1 Executor (hudson.model.Executor)1 StreamTaskListener (hudson.util.StreamTaskListener)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Collection (java.util.Collection)1 Date (java.util.Date)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Jenkins (jenkins.model.Jenkins)1 AsynchronousExecution (jenkins.model.queue.AsynchronousExecution)1