r842 - in trunk/wikitty-publication/src: main/java/org/nuiton/wikitty/publication/synchro site/rst
Author: mfortun Date: 2011-04-27 17:51:40 +0200 (Wed, 27 Apr 2011) New Revision: 842 Url: http://nuiton.org/repositories/revision/wikitty/842 Log: * add the rst that containt spec about wikitty publication sync * make change in wikitty publication file system to supprot commit/update function * basically implements commit as an operation for wikitty publication Added: trunk/wikitty-publication/src/site/rst/sync.rst Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-27 07:59:44 UTC (rev 841) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-27 15:51:40 UTC (rev 842) @@ -24,6 +24,7 @@ */ package org.nuiton.wikitty.publication.synchro; +import java.io.File; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -35,6 +36,7 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ArgumentsParserException; +import org.nuiton.util.FileUtil; import org.nuiton.wikitty.WikittyProxy; import org.nuiton.wikitty.WikittyServiceFactory; import org.nuiton.wikitty.WikittyUtil; @@ -68,6 +70,12 @@ */ static public String WIKITTY_OPTION_COMPONENT = "wikitty.WikittyService.components"; + /** + * Key for the other uri, usefull in the case of commit/update with a file + * system wikitty service. + */ + static public String WIKITTY_SERVICE_INTERLOCUTEUR = "wikitty.service.interlocuteur"; + static protected ApplicationConfig applicationConfig; /** @@ -83,6 +91,9 @@ */ static public String IS_EXISTING_OPTION = "existing"; + /** + * Use to save the label by the wikitty publication file system + */ static public String LABEL_KEY = "working.label"; /** @@ -115,10 +126,21 @@ // allias for all the action applicationConfig.addAlias("wp sync", "--option", "sync"); + applicationConfig.addAlias("wp commit", "--option", "commit"); + + applicationConfig.addAlias("wp update", "--option", "update"); + applicationConfig .addActionAlias("sync", "org.nuiton.wikitty.publication.synchro.WikittyPublication#synchronisation"); + applicationConfig + .addActionAlias("commit", + "org.nuiton.wikitty.publication.synchro.WikittyPublication#commit"); + + applicationConfig + .addActionAlias("update", + "org.nuiton.wikitty.publication.synchro.WikittyPublication#update"); // parsing applicationConfig.parse(args); @@ -127,12 +149,11 @@ } - static public void synchronisation(String origin, String target) throws URISyntaxException - { + static public void synchronisation(String origin, String target) + throws URISyntaxException { boolean isRecur = applicationConfig .getOptionAsBoolean(IS_RECURSION_OPTION); - URI uriOrigin = new URI(origin); URI uriTarget = new URI(target); @@ -145,15 +166,22 @@ boolean isUpdate = !isDelete && !isExisting; /* - * necessary to have property correctly initialize in order to obtaint + * necessary to have property correctly initialize in order to obtain * the correct implementation of the wikitty service */ + // once on the service origin + applicationConfig.setOption(WIKITTY_SERVICE_INTERLOCUTEUR, target); + ApplicationConfig temp1 = setUpApplicationConfigServerConnector(uriOrigin); WikittyProxy proxyOrigin = new WikittyProxy( WikittyServiceFactory.buildWikittyService(temp1)); + // store the other uri in the application, if the service is a + // wikittypublication file system + // it can need it to store wikittyservice property + applicationConfig.setOption(WIKITTY_SERVICE_INTERLOCUTEUR, origin); // once on the service target ApplicationConfig temp2 = setUpApplicationConfigServerConnector(uriTarget); @@ -187,6 +215,11 @@ existOnlyOnTarget.removeAll(listOrigin); /* + * FIXME mfortun-2011-04-27 remove all that stuff for the safety of the + * version when a solution rise for the wikitty version + */ + + /* * if option is update send wikitty that are not in the target. */ if (isUpdate) { @@ -398,6 +431,98 @@ } + static public void update(String... uriFileSystem) throws Exception { + + /* + * Alors c'est facile si on a un élément dans le param c'est que on + * spécifie l'endroit du FS à updater/commit, ce qui veut dire que on + * doit aller chercher ensuite dans le dossier donné l'adresse du + * wikitty service. Notons que si il y a un élément ça doit forcément + * être une uri avec le protocole file. après on appelle simplement la + * méthode synchro avec l'ordre correct entre uritarget et uri origin. + * + * dans le cas ou ya pas d'argument ça veut dire que on doit + * commit/update le dossier courant donc aller chercher dans + * l'arborescence l'adresse du wikitty service. + * + * et pareil on va construire les adresses pour faire une synchro + */ + + } + + static public void commit(String... uriFileSystem) throws Exception { + + String target = ""; + String origin = ""; + + File currentDir = new File(FileUtil.getCurrentDirectory() + .getAbsolutePath()); + + PropertiesExtended homePorperty = null; + switch (uriFileSystem.length) { + case 0: + + homePorperty = WikittyPublicationFileSystem + .searchWikittyPublicationHomePropertie(currentDir); + + target = (String) homePorperty.get(WIKITTY_SERVICE_INTERLOCUTEUR); + + // construct the current uri for origin + // search the current label + PropertiesExtended metaPropertiesExtended = WikittyPublicationFileSystem + .getWikittyPublicationProperties( + currentDir, + WikittyPublicationFileSystem.WIKITTY_FILE_META_PROPERTIES_FILE); + String labelCurrent = metaPropertiesExtended + .getProperty(WikittyPublicationFileSystem.META_CURRENT_LABEL); + + origin = "file:///" + currentDir.getAbsolutePath() + "#" + + labelCurrent; + + synchronisation(origin, target); + break; + + case 1: + + origin = uriFileSystem[0]; + URI originUri = new URI(origin); + if (!originUri.getScheme().equals("file")) { + // Exception + } + File workingDir = new File(originUri.getPath()); + homePorperty = WikittyPublicationFileSystem + .searchWikittyPublicationHomePropertie(workingDir); + + target = (String) homePorperty.get(WIKITTY_SERVICE_INTERLOCUTEUR); + + // TODO mfortun 2011-04-27 do something on labels ? + + synchronisation(origin, target); + break; + + default: + + // exception + break; + } + + /* + * Alors c'est facile si on a un élément dans le param c'est que on + * spécifie l'endroit du FS à updater/commit, ce qui veut dire que on + * doit aller chercher ensuite dans le dossier donné l'adresse du + * wikitty service. Notons que si il y a un élément ça doit forcément + * être une uri avec le protocole file. après on appelle simplement la + * méthode synchro avec l'ordre correct entre uritarget et uri origin. + * + * dans le cas ou ya pas d'argument ça veut dire que on doit + * commit/update le dossier courant donc aller chercher dans + * l'arborescence l'adresse du wikitty service. + * + * et pareil on va construire les adresses pour faire une synchro + */ + + } + /* * TODO mfortun-2011-04-18 plus tard il faudra rajouter un fonctionnement * commit update à la commande sync, en se servant de l'adresse du wikitty Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-27 07:59:44 UTC (rev 841) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-27 15:51:40 UTC (rev 842) @@ -187,9 +187,12 @@ * recursion, @see WikittyPublication for constant * @throws URISyntaxException * if serveur url is not in the proper format (URI format) + * @throws IOException + * if error while creating/reading the wikitty service + * properties */ public WikittyPublicationFileSystem(ApplicationConfig app) - throws URISyntaxException { + throws URISyntaxException, IOException { this.mimeHelper = new MimeTypePubHelper(); @@ -209,6 +212,28 @@ label = homeFile.getName(); } + File homeProperty = new File(homeFile.getAbsolutePath() + + File.separator + PROPERTY_DIRECTORY); + + if (!homeProperty.exists()) { + homeProperty.createNewFile(); + } + + // write/update the "home property file" + PropertiesExtended propertyWikittyService = getWikittyPublicationProperties( + homeFile, WIKITTY_FILE_SERVICE); + + // the original label use to create + propertyWikittyService.setProperty(WikittyPublication.LABEL_KEY, + this.label); + // the service use to update or commit + propertyWikittyService + .setProperty( + WikittyPublication.WIKITTY_SERVICE_INTERLOCUTEUR, + app.getOption(WikittyPublication.WIKITTY_SERVICE_INTERLOCUTEUR)); + + propertyWikittyService.store(); + this.recursion = app .getOptionAsBoolean(WikittyPublication.IS_RECURSION_OPTION); @@ -1427,7 +1452,8 @@ * since the last check. If so, it increment the minor version of the * wikitty and store the new checksum and version * - * @param child the file need to check if modified + * @param child + * the file need to check if modified * @throws IOException */ protected void checkModifications(File child) throws IOException { @@ -1566,4 +1592,45 @@ return result; } + /** + * Use to search and return the home property that containt informations + * about wikitty service use to synchronise a wikitty publication file + * system + * + * @param start + * the directory where starts the search + * @return PropertiesExtended the home property + * @throws IOException + * if error while reading property file + */ + static public PropertiesExtended searchWikittyPublicationHomePropertie( + File start) throws IOException { + + if (start != null && start.exists() && start.isDirectory()) { + + // recursion, we search in the parents for the home property file + // those which containt the wikitty service property withe the + // adress of the interlocuteur + + File propertyDirectory = new File(start.getCanonicalPath() + + File.separator + PROPERTY_DIRECTORY); + + if (propertyDirectory.exists()) { + File propertie = new File(propertyDirectory.getCanonicalPath() + + File.separator + WIKITTY_FILE_SERVICE); + if (propertie.exists()) { + return new PropertiesExtended(propertie); + } + } + + return searchWikittyPublicationHomePropertie(start.getParentFile()); + } else { + // Exception + /* + * TODO mfortun-2011-04-27 write/set the appropriate exception here + */ + return null; + } + } + } Added: trunk/wikitty-publication/src/site/rst/sync.rst =================================================================== --- trunk/wikitty-publication/src/site/rst/sync.rst (rev 0) +++ trunk/wikitty-publication/src/site/rst/sync.rst 2011-04-27 15:51:40 UTC (rev 842) @@ -0,0 +1,220 @@ + + + +Spécification Wikitty publication module de synchronisation +=========================================================== +:Authors: Manoël Fortun + + +Nouvelle approche sur le modèle Rsync +------------------------------------- + +Cette nouvelle approche du module wikitty publication, basé sur Rsync, et plus +un "simple" système de commit/update/import/delete/relocate comme svn, est motivé +par l'aspect plus généraliste que celà apporte. + +Cette approche permet de syncrhoniser le contenu de n'importe quel wikitty service +avec un autre, et donc de redéployer simplement tout les wikittys que l'on souhaite +d'un wikitty service à un autre. + +La nature du wikitty service cible importe pas, on peut synchroniser un wikitty service +sur un file system avec un wikitty service sur un serveur cajo, ou deux wikitty service +sur des serveurs cajo, cette approche se veut plus universelle. Et pourra être testé justement +entre deux wikitty service sur serveur. + + +Définitions +----------- + +Fichier -> Objets wikitty ++++++++++++++++++++++++++ + +Un fichier est défini par un nom, une extention, un contenu et un chemin. +dans wikitty publication les fichiers sont convertis en fonction de leurs type +en objet wikitty. les fichiers sources sont convertit en WikittyPubText et les +fichiers binaires(eg image, etc) en WikittyPubData. + +Les deux types d'objet ont les mêmes attribut: + + - Name: correspondant au nom du fichier + - MimeType: crrespondant au type, qui donnera l'extension + - Content: le contenu binaire pour pour les PubData et textuel pour les PubText + + + +Le mimetype donne l'extention par exemple pour un PubData si on a en mimetype "image/png" + alors l'extension du fichier associé sera ".png". Dans le cas d'un PubText +le mimetype donnera l'extension et le langage de la source par exemple si on a +en mimetype "application/javascript" le langage est javascript et l'extension +sera donc ".js". + +A ces objets wikitty on associe un wikittyLabel, c'est un objet qui peut +contenir un ensemble de label différent, un label par exemple +"src.org.chorem.entities" sert ici pour contenir le chemin menant au fichier +sur le file system. Un wikitty peut avoir un certain nombre de label, pour les +wikittyPub celà indiquera qu'ils appartiennent à plusieurs arborescences. + + +Objets wikitty -> Fichier ++++++++++++++++++++++++++ + +Lorsque l'on va enregistrer des wikitties en fichier en utilisant un +wikitty service file system, on devra restaurer les fichiers en se servant +des labels pour localiser sa place dans l'arborescence, du mimetype pour +les extensions, etc. + +Dans ce cas le repo local des wikitty devra contenir toutes les informations +du wikitty si l'on veux le renvoyer vers un autre wikitty service en se servant +de l'application wikitty publication sync. + +Propriétés pour l'inversabilité fichier/wikitty ++++++++++++++++++++++++++++++++++++++++++++++++ + +Tout objet wikitty dispose d'une version qui est modifiée par le wikitty service +à chaque modification de l'objet wikitty, les wikittypub donc aussi. Cette +information de la version sera stockée dans un fichier de propriété dans un +dossier caché ".wp/" afin que l'on garde trâce des versions des objets que +l'on aura transformé en fichier, celà pour une synchronisation ultérieure avec un +autre wikitty service. + +On conservera trace ausi dans ce même fichier de propriété du label courant, permettant +de ne pas faire d'opération "complexes" et pénible sur les noms de fichier afin de retrouver +le label de travail. Conserver trace du label actuel à l'avantage de n'avoir pas +besoin de rechercher dans l'arborescence la première occurence du fichier de propriété +pour pouvoir reconstituer le label complet. + +On distinguera deux fichiers de propriétés pour les informations un qui conservera +les id des wikitty lié à leur nom de fichier. Et un autre fichiers de propriété +qui conservera un checksum, la version et les id aussi. + +On conserve les id dans un premier fichier puisque celà permet simplement de récupérer +l'ensemble des id et leurs noms de fichier lié sans avoir besoin de faire le tri +parmis toutes les propriétés enregistrées. On converse l'id aussi dans un autre fichier de +propriété, à défaut d'avoir un system de type bidimap pour les proriétés, celà permet +de récupérer l'id d'un wikitty à partir de son nom de fichier, et inversement du nom de fichier +à l'id. + +La propriété checksum sera utilisée pour enregistrer la somme de controle de +l'objet lors de son enregistrement, pour plus tard, savoir si celui ci à été +modifié depuis lors. + +Exemple pour un contenu de file system: + + +racine + |script.js + |scripttut.js + |image.png + |+.wp + ||id.properties + ||meta.properties + |+directory2 + ||script3.js + ||+.wp + |||meta.properties + |||id.properties + ||+directory3 + |||truc.js + |||+.wp + ||||meta.properties + ||||id.properties + |+directory22 + ||machin.png + ||+.wp + |||versions.properties + |||id.properties + +Exemples de fichiers de propriétés: + +meta.properties: + +script.js.version=numéroVersion7 +scripttut.js.version=numéroVersion +image.png.version=numéroVersion +current.label=racine +script.js.checksum= checksum +scripttut.js.checksum= checksum +image.png.checksum= checksum +id.image.png=uubdazudba +id.scripttut.js=11daz5facz +id.script.js=jbdub1dza8 + +id.properties: + +uubdazudba=image.png +11daz5facz=scripttut.js +jbdub1dza8=script.js + +Fonctionnalités +--------------- + +Sync +++++ + +Définitions +*********** +La fonctionnalité CP permet de transférer l'ensemble des wikittys ciblés par l'uri, +d'un service wikitty à un autre. Son fonctionnement doit être similaire à la commande +linux "rsync". + +On reprendra donc quelques options comme: + + - Recursion pour savoir si l'on s'occupe des sous labels du label ciblé. + - Update, qui permettra de mettre à jour ce qui est présent et antérieur + sur la cible et d'y envoyer les nouveaux wikitty. Par défaut cette option + sera active, et sera desactivée lorsque les autres option (delete ou existing) + seront choisis. + - Existing qui est un update mais sans l'envois des nouveaux fichiers, on + envois juste ce qui à été mis à jour et qui existe sur le wikitty service cible. + - Delete pour supprimer dans le wikitty cible, ce qui n'existe plus dans le + wikitty origine. + +La suppression n'est pas une vraie suppression elle se contente de supprimer le label +ciblé du wikitty. + +En fonction des uris des wikitty services ciblé par la fonction, une implémentation +différente de service wikitty sera instancié, en fonction des protocoles (file, hessian +ou cajo). + + +Prototype commande +****************** + + +''wp sync [--norecursion] [--delete|--existing] [URI orgirine] [URI cible]'' + +Avec URI sous forme: + - file:///truc/machin/#label + - hessian://www.adresse.com:8827/etc/etc#label + - cajo://www.adresse.com:8827/etc/etc#label + +Evidement le path pour le protocole File indiquant le répertoire où aller +chercher/mettre les wikitties. + +Les labels de l'uri cible et local peuvent être différent, et pendant ils seront +conservé, c'est à dire que des wikitties de la cible si ils ont besoin de se +mettre à jour, leurs labels seront conservés. +Dans le cas de wikitty qui n'existe pas dans la cible, on remplacera le label +origine qui à permis de trouver ces wikitties et le remplacer par le label cible, +les autres labels du wikitty seront transmit. + + +Wikitty Service File System +--------------------------- + +Un tel service devra fournir les méthodes suivantes les méthodes de sauvegarde +des wikitty, de restauration, ainsi qu'un certain nombre de fonctionnalités concernant +les recherches de wikitty. + +Le wikitty service sur file system prendra en charge les recherches sur critéria +de façon compléte. A chaque recherche sur le wikitty service file system, il faudra +indexer les nouveaux wikitty, enlever les property des fichiers/wikitty supprimé, +incrémenter la version mineur si il y a eut des modifications depuis la dernière +indexation. + + + +Commit/update +------------- + + +
participants (1)
-
mfortun@users.nuiton.org