private String getLocationForBundlesInfo(String extractionFolderName) { final File warDir = new File(this.webAppsDir, extractionFolderName); if (!warDir.exists()) { logger.warn( "Directory with name [" + extractionFolderName + "] cannot be found in web applications directory." + " See logs for previous failures during install."); return null; } return BundleLocationUtil.getRelativisedURI(kernelHomeFile, warDir).toString(); }
private Bundle getInstalledBundle(String extractionFolderName) { final File warDir = new File(this.webAppsDir, extractionFolderName); if (!warDir.exists()) { logger.warn( "Directory with name [" + extractionFolderName + "] cannot be found in web applications directory." + " See logs for previous failures during install."); return null; } return this.bundleContext.getBundle( BundleLocationUtil.createInstallLocation(this.kernelHomeFile, warDir)); }
@Override public boolean isDeployed(URI path) { final String warName = extractDecodedWarNameFromString(path.toString()); final File warDir = new File(this.webAppsDir, WebBundleUtils.calculateCorrectSymbolicName(warName)); if (!warDir.exists()) { return false; } if (this.bundleContext.getBundle( BundleLocationUtil.createInstallLocation(this.kernelHomeFile, warDir)) == null) { return false; } return true; }
@Override public DeploymentIdentity getDeploymentIdentity(URI path) { final String warName = extractDecodedWarNameFromString(path.toString()); final File warDir = new File(this.webAppsDir, WebBundleUtils.calculateCorrectSymbolicName(warName)); if (!warDir.exists()) { return null; } Bundle bundle = this.bundleContext.getBundle( BundleLocationUtil.createInstallLocation(this.kernelHomeFile, warDir)); if (bundle == null) { return null; } return new StandardDeploymentIdentity( WAR, bundle.getSymbolicName(), bundle.getVersion().toString()); }
@Override public boolean install(URI uri) { this.eventLogger.log(WARDeployerLogEvents.NANO_INSTALLING, new File(uri).toString()); final String warName = extractDecodedWarNameFromString(uri.toString()); final File deployedFile = new File(uri); String extractionFolderName = WebBundleUtils.calculateCorrectSymbolicName(warName); final File warDir = new File(this.webAppsDir, extractionFolderName); StatusFileModificator.deleteStatusFile(warName, this.pickupDir); final long lastModified = deployedFile.lastModified(); if (!canWrite(uri)) { this.logger.error( "Cannot open the file " + uri + " for writing. The configured timeout is " + this.largeFileCopyTimeout + "."); StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_DEPLOY, STATUS_ERROR, -1L, lastModified); this.eventLogger.log(WARDeployerLogEvents.NANO_INSTALLING_ERROR, uri); return false; } final Bundle installed; try { // Extract the war file to the webapps directory. Use always JarUtils.unpackToDestructive. try { JarUtils.unpackToDestructive(new PathReference(deployedFile), new PathReference(warDir)); } catch (FatalIOException e) { if (UNPACK_TO_DESTRUCTIVE) { throw e; } else { this.logger.warn("Cannot delete directory '" + warDir + "'.", e); org.eclipse.virgo.web.war.deployer.IOUtils.extractJar(deployedFile, warDir); } } // make the manifest transformation in the unpacked location transformUnpackedManifest(warDir, warName); // install the bundle installed = this.bundleContext.installBundle( BundleLocationUtil.createInstallLocation(this.kernelHomeFile, warDir)); this.eventLogger.log( WARDeployerLogEvents.NANO_INSTALLED, installed.getSymbolicName(), installed.getVersion()); } catch (Exception e) { this.eventLogger.log(WARDeployerLogEvents.NANO_INSTALLING_ERROR, e, uri); StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_DEPLOY, STATUS_ERROR, -1L, lastModified); return false; } return true; }
@Override public final boolean update(URI path) { final String warName = extractDecodedWarNameFromString(path.toString()); String extractionFolderName = WebBundleUtils.calculateCorrectSymbolicName(warName); final File updatedFile = new File(path); final File warDir = new File(this.webAppsDir, extractionFolderName); if (!warDir.exists()) { this.logger.info("Can't update artifact for path '" + path + "'. It is not deployed."); } final boolean isOfflineUpdated = isOfflineUpdated(path); StatusFileModificator.deleteStatusFile(warName, this.pickupDir); final long bundleId = -1L; final long lastModified = updatedFile.lastModified(); if (!canWrite(path)) { this.logger.error( "Cannot open the file [" + path + "] for writing. Timeout is [" + this.largeFileCopyTimeout + "]."); StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_DEPLOY, STATUS_ERROR, bundleId, lastModified); this.eventLogger.log(WARDeployerLogEvents.NANO_UPDATING_ERROR, path); return STATUS_ERROR; } final Bundle bundle = this.bundleContext.getBundle( BundleLocationUtil.createInstallLocation(this.kernelHomeFile, warDir)); if (bundle != null) { try { boolean isLegalState = checkWabState(bundle, isOfflineUpdated); if (isLegalState == false) { this.eventLogger.log( WARDeployerLogEvents.NANO_UPDATE_STATE_ERROR, bundle.getSymbolicName(), bundle.getVersion()); StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_DEPLOY, STATUS_ERROR, bundleId, lastModified); return STATUS_ERROR; } wabStates.put(bundle.getSymbolicName(), ""); bundle.stop(); if (bundle instanceof BundleHost) { BundleClassLoader loader = (BundleClassLoader) ((BundleHost) bundle).getClassLoader(); loader.close(); } // Extract the war file to the webapps directory. Use always JarUtils.unpackToDestructive. try { JarUtils.unpackToDestructive(new PathReference(updatedFile), new PathReference(warDir)); } catch (FatalIOException e) { if (UNPACK_TO_DESTRUCTIVE) { throw e; } else { this.logger.warn("Cannot delete directory '" + warDir + "'.", e); org.eclipse.virgo.web.war.deployer.IOUtils.extractJar(updatedFile, warDir); } } // make the manifest transformation in the unpacked location transformUnpackedManifest(warDir, warName); this.eventLogger.log( WARDeployerLogEvents.NANO_UPDATING, bundle.getSymbolicName(), bundle.getVersion()); bundle.update(); if (this.packageAdmin != null) { ((PackageAdminImpl) this.packageAdmin).refreshPackages(new Bundle[] {bundle}, true, null); this.logger.info("Update of file with path [" + path + "] is successful."); } bundle.start(); this.eventLogger.log( WARDeployerLogEvents.NANO_UPDATED, bundle.getSymbolicName(), bundle.getVersion()); } catch (Exception e) { this.eventLogger.log( WARDeployerLogEvents.NANO_UPDATE_ERROR, e, bundle.getSymbolicName(), bundle.getVersion()); StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_DEPLOY, STATUS_ERROR, bundleId, lastModified); return STATUS_ERROR; } StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_DEPLOY, STATUS_OK, bundleId, lastModified); } else { deploy(path); } return STATUS_OK; }
@Override public final boolean undeploy(Bundle bundle) { String bundleLocation = removeTrailingFileSeparator(bundle.getLocation()); String warPath = extractWarPath(bundleLocation); String extractedWarNameFromBundleLocation = extractWarNameFromBundleLocation(warPath); final File warDir = new File(warPath); String warName = StatusFileModificator.deleteStatusFileByNamePattern( extractedWarNameFromBundleLocation.replaceAll("[.]", "[^a-zA-Z0-9_-]"), this.pickupDir); if (("").equals(warName)) { warName = extractedWarNameFromBundleLocation; } try { if (this.logger.isInfoEnabled()) { this.logger.info( "Removing bundle '" + bundle.getSymbolicName() + "' version '" + bundle.getVersion() + "' from bundles.info."); } if (this.bundleInfosUpdaterUtil != null && this.bundleInfosUpdaterUtil.isAvailable()) { String locationForBundlesInfo = BundleLocationUtil.getRelativisedURI(kernelHomeFile, warDir).toString(); BundleInfosUpdater.unregisterToBundlesInfo(bundle, locationForBundlesInfo, NOT_A_FRAGMENT); this.logger.info( "Successfully removed bundle '" + bundle.getSymbolicName() + "' version '" + bundle.getVersion() + "' from bundles.info."); } else { this.logger.error( "BundleInfosUpdater not available. Failed to remove bundle '" + bundle.getSymbolicName() + "' version '" + bundle.getVersion() + "' from bundles.info."); } this.eventLogger.log( WARDeployerLogEvents.NANO_STOPPING, bundle.getSymbolicName(), bundle.getVersion()); bundle.stop(); this.eventLogger.log( WARDeployerLogEvents.NANO_STOPPED, bundle.getSymbolicName(), bundle.getVersion()); this.eventLogger.log( WARDeployerLogEvents.NANO_UNINSTALLING, bundle.getSymbolicName(), bundle.getVersion()); bundle.uninstall(); // we need to decode the path before delete or a /webapps entry might leak FileSystemUtils.deleteRecursively(new File(warDir.getAbsolutePath())); this.eventLogger.log( WARDeployerLogEvents.NANO_UNINSTALLED, bundle.getSymbolicName(), bundle.getVersion()); wabStates.remove((String) bundle.getSymbolicName()); } catch (BundleException e) { this.eventLogger.log( WARDeployerLogEvents.NANO_UNDEPLOY_ERROR, e, bundle.getSymbolicName(), bundle.getVersion()); StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_UNDEPLOY, STATUS_ERROR, -1, -1); return STATUS_ERROR; } catch (IOException e) { this.eventLogger.log( WARDeployerLogEvents.NANO_PERSIST_ERROR, e, bundle.getSymbolicName(), bundle.getVersion()); } catch (URISyntaxException e) { this.eventLogger.log( WARDeployerLogEvents.NANO_PERSIST_ERROR, e, bundle.getSymbolicName(), bundle.getVersion()); } StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_UNDEPLOY, STATUS_OK, -1, -1); return STATUS_OK; }
@Override public final boolean deploy(URI path) { this.eventLogger.log(WARDeployerLogEvents.NANO_INSTALLING, new File(path).toString()); final String warName = extractDecodedWarNameFromString(path.toString()); final File deployedFile = new File(path); String extractionFolderName = WebBundleUtils.calculateCorrectSymbolicName(warName); final File warDir = new File(this.webAppsDir, extractionFolderName); StatusFileModificator.deleteStatusFile(warName, this.pickupDir); long bundleId = -1L; final long lastModified = deployedFile.lastModified(); if (!canWrite(path)) { this.logger.error( "Cannot open the file " + path + " for writing. The configured timeout is " + this.largeFileCopyTimeout + "."); StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_DEPLOY, STATUS_ERROR, bundleId, lastModified); this.eventLogger.log(WARDeployerLogEvents.NANO_INSTALLING_ERROR, path); return STATUS_ERROR; } final Bundle installed; try { // Extract the war file to the webapps directory. Use always JarUtils.unpackToDestructive. try { JarUtils.unpackToDestructive(new PathReference(deployedFile), new PathReference(warDir)); } catch (FatalIOException e) { if (UNPACK_TO_DESTRUCTIVE) { throw e; } else { this.logger.warn("Cannot delete directory '" + warDir + "'.", e); org.eclipse.virgo.web.war.deployer.IOUtils.extractJar(deployedFile, warDir); } } // make the manifest transformation in the unpacked location transformUnpackedManifest(warDir, warName); // install the bundle installed = this.bundleContext.installBundle( BundleLocationUtil.createInstallLocation(this.kernelHomeFile, warDir)); } catch (Exception e) { this.eventLogger.log(WARDeployerLogEvents.NANO_INSTALLING_ERROR, e, path); StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_DEPLOY, STATUS_ERROR, bundleId, lastModified); return STATUS_ERROR; } this.eventLogger.log( WARDeployerLogEvents.NANO_INSTALLED, installed.getSymbolicName(), installed.getVersion()); this.eventLogger.log( WARDeployerLogEvents.NANO_WEB_STARTING, installed.getSymbolicName(), installed.getVersion()); try { installed.start(); } catch (Exception e) { this.eventLogger.log( WARDeployerLogEvents.NANO_STARTING_ERROR, e, installed.getSymbolicName(), installed.getVersion()); StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_DEPLOY, STATUS_ERROR, bundleId, lastModified); return STATUS_ERROR; } this.eventLogger.log( WARDeployerLogEvents.NANO_WEB_STARTED, installed.getSymbolicName(), installed.getVersion()); bundleId = installed.getBundleId(); // now update bundle's info if (this.logger.isInfoEnabled()) { this.logger.info("Bundles info will be updated for war with path '" + path + "'."); } try { if (this.bundleInfosUpdaterUtil != null && this.bundleInfosUpdaterUtil.isAvailable()) { BundleInfosUpdater.registerToBundlesInfo( installed, getLocationForBundlesInfo(extractionFolderName), NOT_A_FRAGMENT); } } catch (Exception e) { this.eventLogger.log( WARDeployerLogEvents.NANO_PERSIST_ERROR, e, installed.getSymbolicName(), installed.getVersion()); StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_DEPLOY, STATUS_ERROR, bundleId, lastModified); return STATUS_ERROR; } StatusFileModificator.createStatusFile( warName, this.pickupDir, StatusFileModificator.OP_DEPLOY, STATUS_OK, bundleId, lastModified); return STATUS_OK; }