/** * Ignore the problem and go back to using Hudson. */ public void doIgnore(StaplerRequest req, StaplerResponse rsp) throws IOException { ignore = true; WebAppController.get().install(Hudson.getInstance()); rsp.sendRedirect2(req.getContextPath() + '/'); } private static final Logger LOGGER = Logger.getLogger(DoubleLaunchChecker.class.getName());
public synchronized void install(final Object app) { if (app == null) { throw new NullPointerException(); } if (log.isLoggable(Level.FINE)) { log.fine("Attempting to install app: " + app); } if (getInstallStrategy().isAllowed(app)) { getContext().setAttribute(APP, app); } else { log.warning("Strategy denied install"); } }
final WebAppController controller = WebAppController.get(); try { controller.setContext(servletContext); } catch (IllegalStateException e) { controller.setInstallStrategy(new DefaultInstallStrategy()); } catch (IllegalStateException e) { new URLClassLoader(new URL[0], getClass().getClassLoader()); } catch (SecurityException e) { controller.install(new InsufficientPermissionDetected(e)); return; controller.install(new NoHomeDir(home)); return; controller.install(new IncompatibleVMDetected()); return; ServletResponse.class.getMethod("setCharacterEncoding", String.class); } catch (NoSuchMethodException e) { controller.install(new IncompatibleServletVersionDetected(ServletResponse.class)); return; FileSet.class.getMethod("getDirectoryScanner"); } catch (NoSuchMethodException e) { controller.install(new IncompatibleAntVersionDetected(FileSet.class)); return;
@Inject public ReadyDetector(final EventPublisher publisher, final Hudson hudson) { this.publisher = checkNotNull(publisher); this.hudson = checkNotNull(hudson); this.controller = WebAppController.get(); setDaemon(true); }
@Override public void run() { try { // Creating of the god object performs most of the booting muck Hudson hudson = new Hudson(hudsonHomeDir, servletContext, null, restart); //Now Hudson is fully loaded, reload Hudson Security Manager HudsonSecurityEntitiesHolder.setHudsonSecurityManager(new HudsonSecurityManager(hudsonHomeDir)); // once its done, hook up to stapler and things should be ready to go controller.install(hudson); // trigger the loading of changelogs in the background, // but give the system 10 seconds so that the first page // can be served quickly // Trigger.timer.schedule(new SafeTimerTask() { // public void doRun() { // User.getUnknown().getBuilds(); // } // }, 1000 * 10); } catch (Error e) { logger.error("Failed to initialize Hudson", e); controller.install(new HudsonFailedToLoad(e)); throw e; } catch (Exception e) { logger.error("Failed to initialize Hudson", e); controller.install(new HudsonFailedToLoad(e)); } } }
public synchronized Object current() { return getContext().getAttribute(APP); }
private boolean isReady() { // Hudson does not give us a nice InitMilestone when its really ready, // but if its not yet COMPLETED, don't bother trying to figure out more if (hudson.getInitLevel() != InitMilestone.COMPLETED) { return false; } HudsonFilter filter = HudsonFilter.get(hudson.servletContext); if (filter == null) { return false; } // Need to get access to the filter's filter field to see if its actually initialized or not // it does not expose it directly, so we have to use reflection to force access Filter delegate = getDelegate(filter); if (delegate == null) { return false; } // At this point we _should_ be ready, see if the app root object is installed... fingers crossed! try { Object app = controller.current(); // FIXME: This may actually be the only check needed? return app instanceof hudson.model.Hudson; } catch (IllegalStateException e) { return false; // context not yet available } }
final WebAppController controller = WebAppController.get(); try { controller.setContext(hudson.servletContext); } catch (IllegalStateException e) { controller.setInstallStrategy(new DefaultInstallStrategy()); } catch (IllegalStateException e) { controller.install(hudson);
public void invokeHudson(boolean restart) { final WebAppController controller = WebAppController.get(); if (initialClassLoader == null) { initialClassLoader = getClass().getClassLoader(); } Class hudsonIsLoadingClass; try { outerClassLoader = new OuterClassLoader(initialClassLoader); hudsonIsLoadingClass = outerClassLoader.loadClass("hudson.util.HudsonIsLoading"); HudsonIsLoading hudsonIsLoading = (HudsonIsLoading) hudsonIsLoadingClass.newInstance(); Class runnableClass = outerClassLoader.loadClass("org.eclipse.hudson.init.InitialRunnable"); Constructor ctor = runnableClass.getDeclaredConstructors()[0]; ctor.setAccessible(true); InitialRunnable initialRunnable = (InitialRunnable) ctor.newInstance(controller, logger, hudsonHomeDir, servletContext, restart); controller.install(hudsonIsLoading); initThread = new Thread(initialRunnable, "hudson initialization thread " + (++highInitThreadNumber)); initThread.setContextClassLoader(outerClassLoader); initThread.start(); } catch (Exception ex) { logger.error("Hudson failed to load!!!", ex); } /** * Above replaces these lines controller.install(new HudsonIsLoading()); * * new Thread("hudson initialization thread") { }.start(); */ }
protected void execute() { File timestampFile = new File(home, ".owner"); long t = timestampFile.lastModified(); if (t != 0 && lastWriteTime != 0 && t != lastWriteTime && !ignore) { try { collidingId = FileUtils.readFileToString(timestampFile); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Failed to read collision file", e); } // we noticed that someone else have updated this file. // switch GUI to display this error. WebAppController.get().install(this); LOGGER.severe("Collision detected. timestamp=" + t + ", expected=" + lastWriteTime); // we need to continue updating this file, so that the other Hudson would notice the problem, too. } try { FileUtils.writeStringToFile(timestampFile, getId()); lastWriteTime = timestampFile.lastModified(); } catch (IOException e) { // if failed to write, err on the safe side and assume things are OK. lastWriteTime = 0; } schedule(); }
@Override public void run() { try { HudsonSecurityManager.grantFullControl(); // Wait 'til we have no active executors. doQuietDown(true, 0); // Make sure isQuietingDown is still true. if (isQuietingDown) { WebAppController.get().install(new HudsonIsRestarting()); // give some time for the browser to load the "reloading" page logger.info("Restart in 10 seconds"); Thread.sleep(10000); logger.error(String.format("Restarting VM as requested by %s", exitUser)); for (RestartListener listener : RestartListener.all()) { listener.onRestart(); } lifecycle.restart(); } else { logger.info("Safe-restart mode cancelled"); } } catch (InterruptedException e) { logger.warn("Failed to restart Hudson", e); } catch (IOException e) { logger.warn("Failed to restart Hudson", e); } finally { Hudson.this.safeRestarting = false; } } }.start();
/** * Performs a restart. */ public void restart() throws RestartNotSupportedException { final Lifecycle lifecycle = Lifecycle.get(); lifecycle.verifyRestartable(); // verify that Hudson is restartable WebAppController.get().install(new HudsonIsRestarting()); new Thread("restart thread") { final String exitUser = getAuthentication().getName(); @Override public void run() { try { HudsonSecurityManager.grantFullControl(); // give some time for the browser to load the "reloading" page Thread.sleep(5000); logger.error(String.format("Restarting VM as requested by %s", exitUser)); for (RestartListener listener : RestartListener.all()) { listener.onRestart(); } lifecycle.restart(); } catch (InterruptedException e) { logger.warn("Failed to restart Hudson", e); } catch (IOException e) { logger.warn("Failed to restart Hudson", e); } } }.start(); }
/** * Reloads the configuration. */ @CLIMethod(name = "reload-configuration") public synchronized HttpResponse doReload() throws IOException { checkPermission(ADMINISTER); // engage "loading ..." UI and then run the actual task in a separate thread WebAppController.get().install(new HudsonIsLoading()); new Thread("Hudson config reload thread") { @Override public void run() { try { HudsonSecurityManager.grantFullControl(); reload(); } catch (IOException e) { logger.error("Failed to reload Hudson config", e); } catch (ReactorException e) { logger.error("Failed to reload Hudson config", e); } catch (InterruptedException e) { logger.error("Failed to reload Hudson config", e); } } }.start(); return HttpResponses.redirectViaContextPath("/"); }