I have a pattern that I'm often using when there are multiple environments, e.g. development, staging, production and fail-over, and the workspace has to connect to the corresponding resources depending on which environment it is running. The pattern works for both FME Desktop and Server.
The reason for this pattern is to avoid having to remember to manually set all the parameters correctly when publishing to each environment, eliminating human errors.
The idea is to have a centralized configuration file for each environment and having FME read parameters such as database connections, path names, etc from the configuration file rather than having them hard-coded in the workspaces. This way you can publish / use the exact same workspace on each environment without any changes.
I personally like to use ini-files as they are easy to manipulate, but you can of course use whatever suits you, even XML! Sample config.ini file:
[DBCONNECTION]dbhost=srv-db-production.mydomain.comdbinstance=gis-prd-db[DATA_INPUT]parcels=//nas/production/data/input/parcelsaddress=//nas/production/data/static/address
This configuration file can either be placed in a common folder or uploaded as a resource to FME Server.
The workspaces can then access the settings through private scripted Python parameters. This example is for a parameter that returns the directory containing the 'parcels' dataset from the config.ini example above:
from ConfigParser import SafeConfigParser # Built-in Python moduleif FME_MacroValues.has_key('FME_SHAREDRESOURCE_DATA'): # The workspace is running on FME Server # config.ini is a shared data resource ini_file = FME_MacroValues['FME_SHAREDRESOURCE_DATA'] + '/config/config.ini'else: # The workspace is running on FME Desktop # config.ini is located relative to the workspace directory ini_file = FME_MacroValues['FME_MF_DIR'] + '/config/config.ini' config = SafeConfigParser() # Initialize parserconfig.read(ini_file) # Read the ini filereturn config.get('DATA_INPUT', 'parcels') # Return value
The private parameter can then be linked wherever necessary throughout the workspace. The private parameter script will only be evaluated once when the workspace starts, even if the script is referenced multiple places.
If you use this pattern a lot you might want to create a small Python module that you can import into your workspaces. That way you can streamline it even further, e.g. by avoiding reading and parsing the config.ini for each parameter.
I've attached a small smaple workspace that shows the above in action: scriptedparameters.zip