Search in sources :

Example 11 with StreamTaskListener

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

the class ZFSInstaller method doStart.

/**
     * Called from the confirmation screen to actually initiate the migration.
     */
public void doStart(StaplerRequest req, StaplerResponse rsp, @QueryParameter String username, @QueryParameter String password) throws ServletException, IOException {
    requirePOST();
    Hudson hudson = Hudson.getInstance();
    hudson.checkPermission(Hudson.ADMINISTER);
    final String datasetName;
    ByteArrayOutputStream log = new ByteArrayOutputStream();
    StreamTaskListener listener = new StreamTaskListener(log);
    try {
        datasetName = createZfsFileSystem(listener, username, password);
    } catch (Exception e) {
        e.printStackTrace(listener.error(e.getMessage()));
        if (e instanceof ZFSException) {
            ZFSException ze = (ZFSException) e;
            if (ze.getCode() == ErrorCode.EZFS_PERM) {
                // permission problem. ask the user to give us the root password
                req.setAttribute("message", log.toString());
                rsp.forward(this, "askRootPassword", req);
                return;
            }
        }
        // for other kinds of problems, report and bail out
        req.setAttribute("pre", true);
        sendError(log.toString(), req, rsp);
        return;
    }
    // file system creation successful, so restart
    WebAppController.get().install(new HudsonIsRestarting());
    // redirect the user to the manage page
    rsp.sendRedirect2(req.getContextPath() + "/manage");
    // asynchronously restart, so that we can give a bit of time to the browser to load "restarting..." screen.
    new Thread("restart thread") {

        @Override
        public void run() {
            try {
                Thread.sleep(5000);
                // close all descriptors on exec except stdin,out,err
                int sz = LIBC.getdtablesize();
                for (int i = 3; i < sz; i++) {
                    int flags = LIBC.fcntl(i, F_GETFD);
                    if (flags < 0)
                        continue;
                    LIBC.fcntl(i, F_SETFD, flags | FD_CLOEXEC);
                }
                // re-exec with the system property to indicate where to migrate the data to.
                // the 2nd phase is implemented in the migrate method.
                JavaVMArguments args = JavaVMArguments.current();
                args.setSystemProperty(ZFSInstaller.class.getName() + ".migrate", datasetName);
                Daemon.selfExec(args);
            } catch (InterruptedException e) {
                LOGGER.log(Level.SEVERE, "Restart failed", e);
            } catch (IOException e) {
                LOGGER.log(Level.SEVERE, "Restart failed", e);
            }
        }
    }.start();
}
Also used : StreamTaskListener(hudson.util.StreamTaskListener) ZFSException(org.jvnet.solaris.libzfs.ZFSException) Hudson(hudson.model.Hudson) JavaVMArguments(com.sun.akuma.JavaVMArguments) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) IOException(java.io.IOException) HudsonIsRestarting(hudson.util.HudsonIsRestarting) ServletException(javax.servlet.ServletException) ZFSException(org.jvnet.solaris.libzfs.ZFSException) IOException(java.io.IOException)

Aggregations

StreamTaskListener (hudson.util.StreamTaskListener)11 IOException (java.io.IOException)8 File (java.io.File)5 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)5 ServletException (javax.servlet.ServletException)3 AbortException (hudson.AbortException)2 ZFSException (org.jvnet.solaris.libzfs.ZFSException)2 JavaVMArguments (com.sun.akuma.JavaVMArguments)1 Extension (hudson.Extension)1 FilePath (hudson.FilePath)1 Launcher (hudson.Launcher)1 LocalLauncher (hudson.Launcher.LocalLauncher)1 WindowsSlaveInstaller (hudson.lifecycle.WindowsSlaveInstaller)1 EnvironmentSpecific (hudson.model.EnvironmentSpecific)1 Executor (hudson.model.Executor)1 Hudson (hudson.model.Hudson)1 Node (hudson.model.Node)1 Run (hudson.model.Run)1 Channel (hudson.remoting.Channel)1 VirtualChannel (hudson.remoting.VirtualChannel)1