/** * Doing the start, stop, reload and lazy unload of webapps inside all hosts respectively when * getting request. * * @param nameOfOperation the operation to be performed in oder to hot update the host * @throws CarbonException if errors occurs when hot update the host */ private void handleHotUpdateToHost(String nameOfOperation) throws CarbonException { if (DataHolder.getHotUpdateService() != null) { List<String> mappings = URLMappingHolder.getInstance().getUrlMappingsPerApplication(this.context.getName()); Engine engine = DataHolder.getCarbonTomcatService().getTomcat().getEngine(); Context hostContext; Host host; for (String hostName : mappings) { host = (Host) engine.findChild(hostName); if (host != null) { hostContext = (Context) host.findChild("/"); if (hostContext != null) { if (nameOfOperation.equalsIgnoreCase("start")) { start(hostContext); } else if (nameOfOperation.equalsIgnoreCase("stop")) { stop(hostContext); } else if (nameOfOperation.equalsIgnoreCase("reload")) { reload(hostContext); } else if (nameOfOperation.equalsIgnoreCase("lazyunload")) { lazyUnload(hostContext); DataHolder.getHotUpdateService().removeHost(hostName); } else if (nameOfOperation.equalsIgnoreCase("delete")) { DataHolder.getHotUpdateService().deleteHost(hostName); } } } } } }
/** * Return a File object representing the "application root" directory for our associated Host. * * @return The AppBase //TODO - when webapp exploding is supported for stratos, this should return * the tenant's webapp dir */ protected File getAppBase() { File appBase = null; File file = new File(DataHolder.getCarbonTomcatService().getTomcat().getHost().getAppBase()); /*if (!file.isAbsolute()) { file = new File(System.getProperty("catalina.base"), host.getAppBase()); }*/ try { appBase = file.getCanonicalFile(); } catch (IOException e) { appBase = file; } return appBase; }
private void lazyUnload(Context context) throws CarbonException { Host host = DataHolder.getCarbonTomcatService().getTomcat().getHost(); try { if (context.getAvailable()) { // If the following is not done, the Realm will throw a LifecycleException, because // Realm.stop is called for each context. context.setRealm(null); context.stop(); context.destroy(); host.removeChild(context); log.info("Unloaded webapp: " + context); } // if the webapp is stopped above context.getAvailable() becomes false. // So to unload stopped webapps this is done. else if (LifecycleState.STOPPED.equals(context.getState())) { context.setRealm(null); context.destroy(); host.removeChild(context); log.info("Unloaded webapp: " + context); } } catch (Exception e) { throw new CarbonException("Cannot lazy unload webapp " + this.context, e); } }