[KARAF-2433] Refactoring of the Cave API to prepare the destroy command git-svn-id: https://svn.apache.org/repos/asf/karaf/cave/trunk@1514562 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/karaf-cave/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf-cave/commit/f740a191 Tree: http://git-wip-us.apache.org/repos/asf/karaf-cave/tree/f740a191 Diff: http://git-wip-us.apache.org/repos/asf/karaf-cave/diff/f740a191 Branch: refs/heads/master Commit: f740a19159ab48f69924bc6340abc6d0b52c382e Parents: ab67133 Author: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68> Authored: Fri Aug 16 02:48:53 2013 +0000 Committer: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68> Committed: Fri Aug 16 02:48:53 2013 +0000 ---------------------------------------------------------------------- .../cave/server/api/CaveRepositoryService.java | 53 +++++++----- .../server/command/RepositoryCreateCommand.java | 4 +- .../internal/CaveRepositoryMBeanImpl.java | 2 +- .../cave/server/storage/CaveRepositoryImpl.java | 28 +++---- .../storage/CaveRepositoryServiceImpl.java | 84 +++++++++++++------- 5 files changed, 106 insertions(+), 65 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf-cave/blob/f740a191/server/api/src/main/java/org/apache/karaf/cave/server/api/CaveRepositoryService.java ---------------------------------------------------------------------- diff --git a/server/api/src/main/java/org/apache/karaf/cave/server/api/CaveRepositoryService.java b/server/api/src/main/java/org/apache/karaf/cave/server/api/CaveRepositoryService.java index 945d813..733f631 100644 --- a/server/api/src/main/java/org/apache/karaf/cave/server/api/CaveRepositoryService.java +++ b/server/api/src/main/java/org/apache/karaf/cave/server/api/CaveRepositoryService.java @@ -25,45 +25,60 @@ import javax.ws.rs.*; public interface CaveRepositoryService { /** - * Create a new Karaf Cave repository. + * Create a Cave repository. * * @param name the name of the repository - * @param scan if true, the repository is scanned at creation time. - * @return the Karaf Cave repository. + * @param scan if true, the repository is scanned at creation time, and the OBR metadata are created. + * @return the Cave repository. * @throws Exception in case of creation failure. */ @POST @Consumes("application/xml") @Produces("application/xml") - CaveRepository createRepository(String name, boolean scan) throws Exception; + CaveRepository create(String name, boolean scan) throws Exception; /** - * Create a new Karaf Cave repository. + * Create a Cave repository. * * @param name the name of the repository. * @param location the storage location of the repository. - * @param scan if true, the repository is scanned at creation time. - * @return the Karaf Cave repository. + * @param scan if true, the repository is scanned at creation time, and the OBR metadata are created. + * @return the Cave repository. * @throws Exception in case of creation failure. */ @POST @Consumes("application/xml") @Produces("application/xml") - CaveRepository createRepository(String name, String location, boolean scan) throws Exception; + CaveRepository create(String name, String location, boolean scan) throws Exception; /** - * Uninstall (remove) an existing Karaf Cave repository from the OBR registry. - * NB: the Karaf Cave repository storage is not removed. + * Uninstall a Cave repository from the OBR service. * - * @param name the name of Karaf Cave repository to remove. - * @throws Exception in case of remove failure. + * @param name the name of the repository. + * @throws Exception in case of uninstall failure. */ void uninstall(String name) throws Exception; /** - * Install (register) a Karaf Cave repository into the OBR registry. + * Remove a Cave repository from the repositories registry. + * + * @param name the name of the repository. + * @throws Exception in case of remove failure. + */ + void remove(String name) throws Exception; + + /** + * Destroy a Cave repository, including the storage. + * + * @param name the name of the repository. + * @throws Exception incase of remove failure. + */ + void destroy(String name) throws Exception; + + /** + * Install a Cave repository into the OBR service. * - * @param name the name of the Karaf Cave repository. + * @param name the name of the Cave repository. * @throws Exception in case of registration failure. */ @POST @@ -71,9 +86,9 @@ public interface CaveRepositoryService { void install(String name) throws Exception; /** - * Get the list of all Karaf Cave repositories. + * Get the list of all Cave repositories. * - * @return the Karaf Cave repositories. + * @return the Cave repositories. */ @GET @Path("/repositories") @@ -81,10 +96,10 @@ public interface CaveRepositoryService { CaveRepository[] getRepositories(); /** - * Get the Karaf Cave repository identified by the given name. + * Get a Cave repository identified by the given name. * - * @param name the name of the Karaf Cave repository to look for. - * @return the Karaf Cave repository + * @param name the name of the Cave repository. + * @return the Cave repository */ @GET @Path("/repositories/{name}") http://git-wip-us.apache.org/repos/asf/karaf-cave/blob/f740a191/server/command/src/main/java/org/apache/karaf/cave/server/command/RepositoryCreateCommand.java ---------------------------------------------------------------------- diff --git a/server/command/src/main/java/org/apache/karaf/cave/server/command/RepositoryCreateCommand.java b/server/command/src/main/java/org/apache/karaf/cave/server/command/RepositoryCreateCommand.java index d159f7b..2a4ebce 100644 --- a/server/command/src/main/java/org/apache/karaf/cave/server/command/RepositoryCreateCommand.java +++ b/server/command/src/main/java/org/apache/karaf/cave/server/command/RepositoryCreateCommand.java @@ -45,9 +45,9 @@ public class RepositoryCreateCommand extends CaveRepositoryCommandSupport { return null; } if (location != null) { - getCaveRepositoryService().createRepository(name, location, false); + getCaveRepositoryService().create(name, location, false); } else { - getCaveRepositoryService().createRepository(name, false); + getCaveRepositoryService().create(name, false); } CaveRepository caveRepository = getCaveRepositoryService().getRepository(name); if (!noOBRGenerate) { http://git-wip-us.apache.org/repos/asf/karaf-cave/blob/f740a191/server/management/src/main/java/org/apache/karaf/cave/server/management/internal/CaveRepositoryMBeanImpl.java ---------------------------------------------------------------------- diff --git a/server/management/src/main/java/org/apache/karaf/cave/server/management/internal/CaveRepositoryMBeanImpl.java b/server/management/src/main/java/org/apache/karaf/cave/server/management/internal/CaveRepositoryMBeanImpl.java index f4c1d47..40979b1 100644 --- a/server/management/src/main/java/org/apache/karaf/cave/server/management/internal/CaveRepositoryMBeanImpl.java +++ b/server/management/src/main/java/org/apache/karaf/cave/server/management/internal/CaveRepositoryMBeanImpl.java @@ -65,7 +65,7 @@ public class CaveRepositoryMBeanImpl extends StandardMBean implements CaveReposi } public void createRepository(String name) throws Exception { - caveRepositoryService.createRepository(name, true); + caveRepositoryService.create(name, true); } public void removeRepository(String name) throws Exception { http://git-wip-us.apache.org/repos/asf/karaf-cave/blob/f740a191/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryImpl.java ---------------------------------------------------------------------- diff --git a/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryImpl.java b/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryImpl.java index 987ecac..468ce65 100644 --- a/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryImpl.java +++ b/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryImpl.java @@ -41,7 +41,7 @@ import java.io.OutputStreamWriter; import java.net.URL; /** - * Default implementation of a Karaf Cave repository. + * Default implementation of a Cave repository. */ public class CaveRepositoryImpl extends CaveRepository { @@ -65,11 +65,11 @@ public class CaveRepositoryImpl extends CaveRepository { * Check if the repository folder exists and create it if not. */ private void createRepositoryDirectory() throws Exception { - LOGGER.debug("Create Karaf Cave repository {} folder.", this.getName()); + LOGGER.debug("Create Cave repository {} folder.", this.getName()); File locationFile = new File(this.getLocation()); if (!locationFile.exists()) { locationFile.mkdirs(); - LOGGER.debug("Karaf Cave repository {} location has been created.", this.getName()); + LOGGER.debug("Cave repository {} location has been created.", this.getName()); LOGGER.debug(locationFile.getAbsolutePath()); } obrRepository = new RepositoryImpl(); @@ -179,7 +179,7 @@ public class CaveRepositoryImpl extends CaveRepository { } /** - * Proxy an URL (by adding repository.xml OBR information) in the Karaf Cave repository. + * Proxy an URL (by adding repository.xml OBR information) in the Cave repository. * * @param url the URL to proxyFilesystem. the URL to proxyFilesystem. * @param filter regex filter. Only artifacts URL matching the filter will be considered. @@ -199,7 +199,7 @@ public class CaveRepositoryImpl extends CaveRepository { } /** - * Proxy an URL (by adding repository.xml OBR information) in the Karaf Cave repository. + * Proxy an URL (by adding repository.xml OBR information) in the Cave repository. * * @param url the URL to proxy. * @throws Exception @@ -288,7 +288,7 @@ public class CaveRepositoryImpl extends CaveRepository { } /** - * Populate an URL into the Karaf Cave repository, and eventually update the OBR information. + * Populate an URL into the Cave repository, and eventually update the OBR information. * * @param url the URL to copy. * @param filter regex filter. Only artifacts URL matching the filter will be considered. @@ -297,12 +297,12 @@ public class CaveRepositoryImpl extends CaveRepository { */ public void populate(URL url, String filter, boolean update) throws Exception { if (url.getProtocol().equals("file")) { - // populate the Karaf Cave repository from a filesystem folder + // populate the Cave repository from a filesystem folder File populateFolder = new File(url.toURI()); this.populateFromFilesystem(populateFolder, filter, update); } if (url.getProtocol().equals("http")) { - // populate the Karaf Cave repository from a HTTP URL + // populate the Cave repository from a HTTP URL this.populateFromHttp(url.toExternalForm(), filter, update); } if (update) { @@ -311,7 +311,7 @@ public class CaveRepositoryImpl extends CaveRepository { } /** - * Populate an URL into the Karaf Cave repository, and eventually update the OBR information. + * Populate an URL into the Cave repository, and eventually update the OBR information. * * @param url the URL to copy. * @param update if true the OBR information is updated, false else. @@ -322,7 +322,7 @@ public class CaveRepositoryImpl extends CaveRepository { } /** - * Populate the Karaf Cave repository using a filesystem directory. + * Populate the Cave repository using a filesystem directory. * * @param filesystem the "source" directory. * @param filter regex filter. Only artifacts URL matching the filter will be considered. @@ -359,7 +359,7 @@ public class CaveRepositoryImpl extends CaveRepository { } /** - * Populate the Karaf Cave repository using the given URL. + * Populate the Cave repository using the given URL. * * @param url the "source" HTTP URL. * @param filter regex filter. Only artifacts URL matching the filter will be considered. @@ -382,7 +382,7 @@ public class CaveRepositoryImpl extends CaveRepository { if ((filter == null) || (url.matches(filter))) { ResourceImpl resource = (ResourceImpl) new DataModelHelperImpl().createResource(new URL(url)); if (resource != null) { - LOGGER.debug("Copy {} into the Karaf Cave repository storage", url); + LOGGER.debug("Copy {} into the Cave repository storage", url); int index = url.lastIndexOf("/"); if (index > 0) { url = url.substring(index); @@ -422,7 +422,7 @@ public class CaveRepositoryImpl extends CaveRepository { * Convert the Resource absolute URI to an URI relative to the repository one. * * @param resource the Resource to manipulate. - * @throws Exception in cave of URI convertion failure. + * @throws Exception in cave of URI conversion failure. */ private void useResourceRelativeUri(ResourceImpl resource) throws Exception { String resourceURI = resource.getURI(); @@ -452,7 +452,7 @@ public class CaveRepositoryImpl extends CaveRepository { } /** - * Return the OBR repository.xml corresponding to this Karaf Cave repository. + * Return the OBR repository.xml corresponding to this Cave repository. * * @return the URL of the OBR repository.xml. * @throws Exception in case of lookup failure. http://git-wip-us.apache.org/repos/asf/karaf-cave/blob/f740a191/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryServiceImpl.java ---------------------------------------------------------------------- diff --git a/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryServiceImpl.java b/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryServiceImpl.java index 6097f70..4d6c82e 100644 --- a/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryServiceImpl.java +++ b/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryServiceImpl.java @@ -28,7 +28,7 @@ import java.util.Map; import java.util.Properties; /** - * Default implementation of the Cave Repository Service. + * Default implementation of the CaveRepositoryService. */ public class CaveRepositoryServiceImpl implements CaveRepositoryService { @@ -58,28 +58,28 @@ public class CaveRepositoryServiceImpl implements CaveRepositoryService { } /** - * Create a new Karaf Cave repository. + * Create a Cave repository. * * @param name the name of the repository * @param scan if true, the repository is scanned at creation time. - * @return the Karaf Cave repository. + * @return the Cave repository. * @throws Exception in case of creation failure. */ - public synchronized CaveRepository createRepository(String name, boolean scan) throws Exception { + public synchronized CaveRepository create(String name, boolean scan) throws Exception { File location = new File(storageLocation, name); - return this.createRepository(name, location.getAbsolutePath(), scan); + return this.create(name, location.getAbsolutePath(), scan); } /** - * Create a new Karaf Cave repository. + * Create a Cave repository. * * @param name the name of the repository. * @param location the storage location of the repository. - * @param scan if true, the repostory is scanned at creation time. - * @return the Karaf Cave repository. + * @param scan if true, the repository is scanned at creation time. + * @return the Cave repository. * @throws Exception in case of creation failure. */ - public synchronized CaveRepository createRepository(String name, String location, boolean scan) throws Exception { + public synchronized CaveRepository create(String name, String location, boolean scan) throws Exception { if (repositories.get(name) != null) { throw new IllegalArgumentException("Cave repository " + name + " already exists"); } @@ -90,52 +90,78 @@ public class CaveRepositoryServiceImpl implements CaveRepositoryService { } /** - * Uninstall (remove) a Karaf Cave repository from the repositories registry. + * Uninstall a Cave repository from the repositories registry. * - * @param name the name of Karaf Cave repository to remove. + * @param name the name of Cave repository to remove. * @throws Exception in case of remove failure. */ public synchronized void uninstall(String name) throws Exception { CaveRepository repository = this.getRepository(name); - if (repository != null) { - repositoryAdmin.removeRepository(repository.getRepositoryXml().toString()); - repositories.remove(name); - save(); - } else { - throw new IllegalArgumentException("Cave repository " + name + " not found"); + if (repository == null) { + throw new IllegalArgumentException("Cave repository " + name + " doesn't exist"); + } + repositoryAdmin.removeRepository(repository.getRepositoryXml().toString()); + save(); + } + + /** + * Remove a Cave repository from the repositories registry. + * @param name the name of the repository. + * @throws Exception + */ + public synchronized void remove(String name) throws Exception { + CaveRepository repository = this.getRepository(name); + if (repository == null) { + throw new IllegalArgumentException("Cave repository " + name + " doesn't exist"); + } + repositories.remove(name); + } + + /** + * Destroy a Cave repository. It removes the repository from the repositories registry + * and cleanup the repository storage. + * + * @param name the name of the repository. + * @throws Exception + */ + public synchronized void destroy(String name) throws Exception { + CaveRepository repository = this.getRepository(name); + if (repository == null) { + throw new IllegalArgumentException("Cave repository " + name + " doesn't exist"); } + repositories.remove(name); + repository.cleanup(); } /** - * Install (register) a Karaf Cave repository in the OBR service. + * Install a Cave repository in the OBR service. * NB: this method allows refresh the repository in the OBR "client". * - * @param name the name of the Karaf Cave repository. + * @param name the name of the Cave repository. * @throws Exception in case of registration failure. */ public synchronized void install(String name) throws Exception { CaveRepository caveRepository = this.getRepository(name); - if (caveRepository != null) { - repositoryAdmin.addRepository(caveRepository.getRepositoryXml()); - } else { - throw new IllegalArgumentException("Cave repository " + name + " not found"); + if (caveRepository == null) { + throw new IllegalArgumentException("Cave repository " + name + " doesn't exist"); } + repositoryAdmin.addRepository(caveRepository.getRepositoryXml()); } /** - * Get the list of all Karaf Cave repositories. + * Get the list of all Cave repositories. * - * @return the list of all Karaf Cave repositories. + * @return the list of all Cave repositories. */ public synchronized CaveRepository[] getRepositories() { return repositories.values().toArray(new CaveRepository[0]); } /** - * Get the Karaf Cave repository identified by name. + * Get the Cave repository identified by name. * - * @param name the name of the Karaf Cave repository to look for. - * @return the corresponding Karaf Cave repository. + * @param name the name of the Cave repository to look for. + * @return the corresponding Cave repository. */ public synchronized CaveRepository getRepository(String name) { return repositories.get(name); @@ -152,7 +178,7 @@ public class CaveRepositoryServiceImpl implements CaveRepositoryService { storage.setProperty("item." + i + ".name", repositories[i].getName()); storage.setProperty("item." + i + ".location", repositories[i].getLocation()); } - saveStorage(storage, new File(storageLocation, STORAGE_FILE), "Karaf Cave Service storage"); + saveStorage(storage, new File(storageLocation, STORAGE_FILE), "Cave Service storage"); } /**
