This topic is not new. It comes back regularly, pretty much with every single enterprise client I have implemented. "Why do we need different Deployers for different file systems?". "Why can't just Tridion publish to different file systems?". And so on...
Recently, it came up again, so I setup a small PoC to see how feasible it is to write a Storage Extension (in SDL Tridion 2011SP1) that would perform the typical CRUD operations a Deployer would perform, only on multiple file systems.
The idea behind the storage extension is to have several file systems defined in the cd_storage_conf.xml that would be grouped under one logical name. Then have an item type mapping (e.g. Page) that would point to the group of file system. The goal is to have that item type created, updated, removed, etc on each of the file systems defined in the group.
The cd_storage_conf.xml Storages node would look something like this:
Item mapping for the Page type would point to the MultiFS id:
In order to make the setup-above work, I had to create my own DAO (Data Access Object) storage extension. There is a reference to the DAO bundle definition in the cd_storage_conf.xml:
The file multifs_dao_bundle.xml contains the definition of my custom DAO:
The whole logic lies in the class MultiFSDAO, which acts like a wrapper around an array of com.tridion.storage.filesystem.FSPageDAO objects. A helper configuration class reads the StorageGroup node from cd_storage_conf.xml and then reads the Root/@path (i.e. storage location) value for each referenced Storage node.
Once we have the array of FSPageDAO objects, it's a simple matter of just implementing the CRUD operations on the collection of FSPageDAOs.
The big disclaimer: the code-above is by no means production ready -- I just used it for a small PoC. I have not tested it thoroughly either. It does deploy pages to multiple file systems, but I did not try any corner cases. I don't even think it works in all scenarios: think about here at transactionality, or what happens (or should happen) if a destination failed. The deploy will not be rolled back. What happens upon unpublish of a previously failed published? And the questions could go on... Use at your own discretion!
Recently, it came up again, so I setup a small PoC to see how feasible it is to write a Storage Extension (in SDL Tridion 2011SP1) that would perform the typical CRUD operations a Deployer would perform, only on multiple file systems.
The idea behind the storage extension is to have several file systems defined in the cd_storage_conf.xml that would be grouped under one logical name. Then have an item type mapping (e.g. Page) that would point to the group of file system. The goal is to have that item type created, updated, removed, etc on each of the file systems defined in the group.
The cd_storage_conf.xml Storages node would look something like this:
<Storage Type="filesystem"
Class="com.tridion.storage.filesystem.FSDAOFactory"
Id="MultiFS" defaultFilesystem="false">
<Root Path="not-used"
/>
</Storage>
<Storage Type="filesystem"
Class="com.tridion.storage.filesystem.FSDAOFactory"
Id="FileRoot1" defaultFilesystem="false">
<Root Path="C:\Temp\Root1"
/>
</Storage>
<Storage Type="filesystem"
Class="com.tridion.storage.filesystem.FSDAOFactory"
Id="FileRoot2" defaultFilesystem="false">
<Root Path="D:\Temp\Root2"
/>
</Storage>
<StorageGroup Id="MultiFS">
<Storage Id="FileRoot1"/>
<Storage Id="FileRoot2"/>
</StorageGroup>
Item mapping for the Page type would point to the MultiFS id:
<ItemTypes defaultStorageId="brokerdb"
cached="true">
<Item typeMapping="Page"
cached="false" storageId="MultiFS"
/>
</ItemTypes>
In order to make the setup-above work, I had to create my own DAO (Data Access Object) storage extension. There is a reference to the DAO bundle definition in the cd_storage_conf.xml:
<StorageBindings>
<Bundle src="multifs_dao_bundle.xml"
/>
</StorageBindings>
The file multifs_dao_bundle.xml contains the definition of my custom DAO:
<StorageDAOBundles>
<StorageDAOBundle type="filesystem">
<StorageDAO typeMapping="Page"
class="com.tridion.extension.multifs.MultiFSDAO"
/>
</StorageDAOBundle>
</StorageDAOBundles>
The whole logic lies in the class MultiFSDAO, which acts like a wrapper around an array of com.tridion.storage.filesystem.FSPageDAO objects. A helper configuration class reads the StorageGroup node from cd_storage_conf.xml and then reads the Root/@path (i.e. storage location) value for each referenced Storage node.
public class MultiFSDAO extends FSBaseDAO implements PageDAO {
private FSPageDAO[] pageDAOs;
public
MultiFSDAO(String storageId, String storageName, File storageLocation) {
super(storageId,
storageName, storageLocation);
createDAOs(storageId, storageName, null);
}
public
MultiFSDAO(String storageId, String storageName, File storageLocation,
FSEntityManager entityManager) {
super(storageId,
storageName, storageLocation, entityManager);
createDAOs(storageId, storageName,
entityManager);
}
private void
createDAOs(String storageId, String storageName, FSEntityManager entityManager)
{
MultiFSConfiguration configuration =
MultiFSConfiguration.getInstance();
Map<String, String> storageGroups
= configuration.getStorageGroups();
String groups =
storageGroups.get(storageId);
if (groups == null) {
groups = storageId;
}
String storageIds[] = groups.split(",");
pageDAOs = new
FSPageDAO[storageIds.length];
Map<String,
String> storageLocations = configuration.getStorageLocations();
for (int i = 0; i <
storageIds.length; i++) {
String id = storageIds[i];
String location =
storageLocations.get(id);
if (entityManager == null) {
pageDAOs[i] = new FSPageDAO(id,
storageName, new File(location));
} else {
pageDAOs[i] = new FSPageDAO(id,
storageName, new File(location), entityManager);
}
}
}
Once we have the array of FSPageDAO objects, it's a simple matter of just implementing the CRUD operations on the collection of FSPageDAOs.
public void
create(CharacterData page, String relativePath) throws
StorageException {
for (PageDAO pageDAO : pageDAOs) {
pageDAO.create(page, relativePath);
}
}
public
Collection<CharacterData> findAll(int publicationId) throws
StorageException {
Collection<CharacterData> result = null;
for (PageDAO pageDAO : pageDAOs) {
result =
pageDAO.findAll(publicationId);
}
return result;
}
public CharacterData
findByPrimaryKey(int publicationId, int pageId) throws
StorageException {
CharacterData result = null;
for (PageDAO pageDAO : pageDAOs) {
result =
pageDAO.findByPrimaryKey(publicationId, pageId);
}
return result;
}
public void remove(int publicationId, int pageId, String
relativePath) throws StorageException {
for (PageDAO pageDAO : pageDAOs) {
pageDAO.remove(publicationId, pageId,
relativePath);
}
}
public void
update(CharacterData page, String originalRelativePath, String newRelativePath)
throws
StorageException {
for (PageDAO pageDAO : pageDAOs) {
pageDAO.update(page,
originalRelativePath, newRelativePath);
}
}
The big disclaimer: the code-above is by no means production ready -- I just used it for a small PoC. I have not tested it thoroughly either. It does deploy pages to multiple file systems, but I did not try any corner cases. I don't even think it works in all scenarios: think about here at transactionality, or what happens (or should happen) if a destination failed. The deploy will not be rolled back. What happens upon unpublish of a previously failed published? And the questions could go on... Use at your own discretion!
Comments