Hello Magnolians!
I'm opening this 3d since I'm trying to create a code snippet that will permit
me to re-install automatically certain modules in my repository.
I'd like to achieve this because we have to deploy on our Test Server on a
daily basis and I don't want to be forced to change the version number because
within our Development cycle we have to maintain the same version
number(x.y.z-SNAPSHOT).
Basically the process is based on a file that I add in the tomcat/webapps
folder. This file will act as a "flag" and in case it's not present some
modules will be re-installed.
I added into a getExtraInstallTask(), defined in my Handler class, a call to
the getStartupTasks() (that has been overridden). Inside the overridden
getStartupTasks() this is what I do:
Preliminary controls:
1. Check if the webapp directory in the tomcat's installation exists or not
2. Check if the file already exists or not
The file exists:
3. I leave to Magnolia the further steps since I assume that if the file
exists, I don't want to reload any module. So the process will continue by
himself and at the end I'll login into the Magnolia UI without any issue.
The file doesn't exists:
3. I create the file and put it in the tomcat/webapps directory
4. I get all the installed modules by doing:
[code]
// I get all the installed modules
Map<String,
ModuleDefinition> map = new HashMap<String, ModuleDefinition>();
try {
map = new BetwixtModuleDefinitionReader().readAll();
} catch
(ModuleManagementException e) {
e.printStackTrace();
}
[/code]
5. Now that I have all the modules in a map I want to get only the modules that
are part of my client business. At this point I added a filter based on the
CanonicalName() and ClassName() of my modules.
6. I split the two modules types:
6.1 Some from Magnolia that I don't want to touch
6.2 Some made by me that have for example a
canonicalName().contains("com.acme")
7. I create a RemoveNodeTask since the modules(6.2) are the ones that have to
be deleted and installed
[code]
// here is where the deletion tasks are created
for(Entry<String, String> entry : vitecModulesMap.entrySet()) {
Task removeNodeTask = new RemoveNodeTask("Delete Acme Module: " +
entry.getKey(), "Delete Acme Modules to optimize
installation",RepositoryConstants.CONFIG, "/modules/" + entry.getKey());
taskForModulesToRemove.add(new NodeExistsDelegateTask("Deletion of Acme's
modules", "This task will delete the old Acme modules from the application",
RepositoryConstants.CONFIG, "/modules/" + entry.getKey(), removeNodeTask));
}
[/code]
8. The tasks that I create are attached to the getExtraInstallTask() return
list and finally executed. Everything goes fine until this stage [b]UNLESS[/b]
the fact that I don't know how to reinstall the modules that have been just
deleted.
What I tried so far:
- Override the following methods from [b]AbstractModuleVersionHandler[/b] class
[code]
getBasicInstallTasks(InstallContext installContext); // to fix
ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING
getInstall(InstallContext installContext); // to fix few null pointer
exceptions that I was having during the development
getStartupTask(InstallContext installContext); //to add the logic described in
the steps 1..8
[/code]
- Change a bit the methods from [b]ModuleManagerImpl[/b] class according to my
needs. All the changes are pure overloading of the existing methods. The
overloading is used to pass the various variables to avoid
nullPointerExceptions and further errors. Methods updated are:
[code]
checkForInstallOrUpdates(InstallContextImpl installContextImpl,
[b]List<ModuleDefinition> acmeModulesDefinitions[/b])
performInstallOrUpdate(final ModuleManagementState state,
[b]List<ModuleDefinition> modulesDefinitionsList[/b])
loadModulesRepositories([b]List<ModuleDefinition> modulesDefinitions[/b])
[/code]
The addings that I made are in [b]bold[/b]. As you can see the overloading
involves just the ModuleDefinition list. This is because the ModuleManagerImpl
class has got a list:
[code]
/**
* List<ModuleDefinition> of modules found to be deployed.
*/
private List<ModuleDefinition> orderedModuleDescriptors;
[/code]
That is private and for this reason can't be used from other classes.
This is what I made since today.
After all these writing I'm wondering if I've been able to explain properly
what I'm trying to achieve but anyway, if anybody have an answer to the
question: [b]What to do to trigger a modules re-installation after the step
8?[/b]
Or need further information please comment.
PS.
I tried by overriding framework classes(as described above) but if anybody has
got any suggestion (maybe easier than my approach), please let me know!
Thanks for your time and for your further help.
Regards,
--
Context is everything:
http://forum.magnolia-cms.com/forum/thread.html?threadId=6a1862fe-6da8-4277-a57d-f4a648f53345
----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------