Skip to main content

Writing to Multiple File Systems from the Same Deployer

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:


    <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

Popular posts from this blog

Running sp_updatestats on AWS RDS database

Part of the maintenance tasks that I perform on a MSSQL Content Manager database is to run stored procedure sp_updatestats . exec sp_updatestats However, that is not supported on an AWS RDS instance. The error message below indicates that only the sa  account can perform this: Msg 15247 , Level 16 , State 1 , Procedure sp_updatestats, Line 15 [Batch Start Line 0 ] User does not have permission to perform this action. Instead there are several posts that suggest using UPDATE STATISTICS instead: https://dba.stackexchange.com/questions/145982/sp-updatestats-vs-update-statistics I stumbled upon the following post from 2008 (!!!), https://social.msdn.microsoft.com/Forums/sqlserver/en-US/186e3db0-fe37-4c31-b017-8e7c24d19697/spupdatestats-fails-to-run-with-permission-error-under-dbopriveleged-user , which describes a way to wrap the call to sp_updatestats and execute it under a different user: create procedure dbo.sp_updstats with execute as 'dbo' as

I Have Gone Dark

Maybe it's the Holidays, but my mood has gone pretty dark. That is, regarding the look and feel of my computer and Tridion CME, of course. What I did was to dim the lights on the operating system, so I installed Placebo themes for Windows 7 . I went for the Ashtray look -- great name :) My VM looks now like this: But, once you change the theme on Windows, you should 'match' the theme of your applications. Some skin easily, some not. The Office suite has an in-built scheme, which can be set to Black , but it doesn't actually dim the ribbon tool bars -- it looks quite weird. Yahoo Messenger is skinnable, but you can't change the big white panels where you actually 'chat'. Skype is not skinnable at all. For Chrome, there are plenty of grey themes. Now i'm using Pro Grey . But then I got into changing the theme of websites. While very few offer skinnable interfaces (as GMail does), I had to find a way to darken the websites... Enter Stylish -- a pl

REL Standard Tag Library

The RSTL is a library of REL tags providing standard functionality such as iterating collections, conditionals, imports, assignments, XML XSLT transformations, formatting dates, etc. RSTL distributable is available on my Google Code page under  REL Standard Tag Library . Always use the latest JAR . This post describes each RSTL tag in the library explaining its functionality, attributes and providing examples. For understanding the way expressions are evaluated, please read my post about the  Expression Language used by REL Standard Tag Library . <c:choose> / <c:when> / <c:otherwise> Syntax:     <c:choose>         <c:when test="expr1">             Do something         </c:when>         <c:when test="expr2">             Do something else         </c:when>         <c:otherwise>             Do something otherwise         </c:otherwise>     </c:choose> Att