| author | Polina Genova | 2012-09-13 15:38:49 (EDT) |
|---|---|---|
| committer | Borislav Kapukaranov | 2012-09-13 15:38:49 (EDT) |
| commit | 5045d35e06c9d557b8be684dbd9b83caf7037737 (patch) (side-by-side diff) | |
| tree | 13d2f081e205c5c473952de8fc49101a9001a603 | |
| parent | 90938e26d7af77faf22889d06bb0ca61c303df91 (diff) | |
| download | org.eclipse.virgo.nano-5045d35e06c9d557b8be684dbd9b83caf7037737.zip org.eclipse.virgo.nano-5045d35e06c9d557b8be684dbd9b83caf7037737.tar.gz org.eclipse.virgo.nano-5045d35e06c9d557b8be684dbd9b83caf7037737.tar.bz2 | |
Bug 389421 - [bulk] Adapt the new multifile InitialEvent in the deployer APIs and the hot-deployer
2 files changed, 76 insertions, 2 deletions
diff --git a/org.eclipse.virgo.nano.deployer.api/src/main/java/org/eclipse/virgo/nano/deployer/api/core/ApplicationDeployer.java b/org.eclipse.virgo.nano.deployer.api/src/main/java/org/eclipse/virgo/nano/deployer/api/core/ApplicationDeployer.java index a6d4371..64cedd9 100644 --- a/org.eclipse.virgo.nano.deployer.api/src/main/java/org/eclipse/virgo/nano/deployer/api/core/ApplicationDeployer.java +++ b/org.eclipse.virgo.nano.deployer.api/src/main/java/org/eclipse/virgo/nano/deployer/api/core/ApplicationDeployer.java @@ -13,6 +13,7 @@ package org.eclipse.virgo.nano.deployer.api.core; import java.net.URI; +import java.util.List; import org.osgi.framework.Version; @@ -38,7 +39,8 @@ public interface ApplicationDeployer { * @throws DeploymentException if installation fails. */ DeploymentIdentity install(URI uri, DeploymentOptions options) throws DeploymentException; - + + /** * Deploys the artifact are the supplied <code>location</code>. The supplied <code>options</code> govern how the * installed artifact is handled by the deployed, e.g. if it is recovered and re-installed upon warm restart. @@ -66,6 +68,20 @@ public interface ApplicationDeployer { DeploymentIdentity deploy(URI uri) throws DeploymentException; /** + * Deploys a bunch of deployable artifacts altogether + * so that if there are dependencies in between,they are resolved successfully. + * Note that this may not always be the case if they are deployed one by one + * through some of the other deploy methods. + * Therefore the method is convenient to solve dependency resolution issues + * that are caused due to the order in which deployable bundles are deployed. + * @param uris the location paths of the deployable artifacts + * @param options the options for this deployment + * @return an array of the successfully deployed applications's {@link DeploymentIdentity}. + * @throws DeploymentException + */ + DeploymentIdentity[] bulkDeploy (List<URI> uris, DeploymentOptions options) throws DeploymentException; + + /** * Deploy an application which may be either an OSGi application or a legacy application such as a WAR. This is used * by admin. and hot deployment. * @@ -105,6 +121,7 @@ public interface ApplicationDeployer { * @throws DeploymentException */ DeploymentIdentity deploy(String type, String name, Version version, DeploymentOptions options) throws DeploymentException; + /** * Undeploy an application with a given symbolic name and version. diff --git a/org.eclipse.virgo.nano.deployer.hot/src/main/java/org/eclipse/virgo/nano/deployer/hot/HotDeployerFileSystemListener.java b/org.eclipse.virgo.nano.deployer.hot/src/main/java/org/eclipse/virgo/nano/deployer/hot/HotDeployerFileSystemListener.java index 71d5fca..34d70a2 100644 --- a/org.eclipse.virgo.nano.deployer.hot/src/main/java/org/eclipse/virgo/nano/deployer/hot/HotDeployerFileSystemListener.java +++ b/org.eclipse.virgo.nano.deployer.hot/src/main/java/org/eclipse/virgo/nano/deployer/hot/HotDeployerFileSystemListener.java @@ -3,6 +3,8 @@ package org.eclipse.virgo.nano.deployer.hot; import java.io.File; import java.net.URI; import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,6 +22,7 @@ import org.eclipse.virgo.util.io.FileSystemEvent; import org.eclipse.virgo.util.io.FileSystemListener; import org.eclipse.virgo.util.io.PathReference; + /** * {@link FileSystemListener} that monitors a pickup directory for file system events. When a file is created it is * passed to the {@link ApplicationDeployer} for deployment. When a file is modified, it is re-deployed. When a file is @@ -80,6 +83,59 @@ final class HotDeploymentFileSystemListener implements FileSystemListener { determineFailureAndLogMessage(event, fileName, ex); } } + + + /** + * {@inheritDoc} + * + * Reacts to initial event in the pickup directory and calls the bulk deploy method in {@link ApplicationDeployer}. + */ + public void onInitialEvent(List<String> paths) { + this.eventLogger.log(HotDeployerLogEvents.HOT_DEPLOY_PROCESSING_FILE, FileSystemEvent.INITIAL, getConcatenatedPaths(paths)); + try { + bulkDeployIfNotDeployed(paths); + } catch (Exception ex) { + ex.printStackTrace(System.out); + determineFailureAndLogMessage(FileSystemEvent.INITIAL, getConcatenatedPaths(paths), ex); + } + } + + private String getConcatenatedPaths(List<String> paths){ + StringBuilder sb = new StringBuilder(""); + for (String path:paths){ + sb.append(new PathReference(path).getName()).append("; "); + } + return new String(sb); + } + + /** + * Collects only the source artifacts that are not yet deployed and transforms the given paths to URIs. + * + */ + private List<URI> getNotDeployedUris (List<String> sourceArtefacts){ + List<URI> notDeployedFileUris = new ArrayList<URI>(); + for (String sourceArtefact:sourceArtefacts){ + if (!isDeployed(sourceArtefact)) { + notDeployedFileUris.add(getDefinitiveUri(sourceArtefact)); + logger.info("ApplicationConditionallyDeploying path '{}'.", sourceArtefact); + } else { + this.eventLogger.log(HotDeployerLogEvents.HOT_DEPLOY_SKIPPED, sourceArtefact); + } + } + return notDeployedFileUris; + } + + + /** + * Triggers bulk deployment of source artifacts that are not yet deployed. + * + * @param sourceArtefact the source artifact URI string + * @throws DeploymentException + */ + private void bulkDeployIfNotDeployed(List<String> sourceArtefacts) throws DeploymentException{ + this.deployer.bulkDeploy(getNotDeployedUris(sourceArtefacts), new DeploymentOptions(true, true, false)); + } + /** * Determines the {@link LogEvent} that corresponds the {@link FileSystemEvent}. @@ -152,7 +208,7 @@ final class HotDeploymentFileSystemListener implements FileSystemListener { } return baseUri; } - + /** * Deploys the application at the supplied PathReference asynchronously. * @@ -178,6 +234,7 @@ final class HotDeploymentFileSystemListener implements FileSystemListener { } } + /** * {@inheritDoc} */ |

