Customize This: Tailoring Deployment Packages to Your Target Environments
Join the DZone community and get the full member experience.Join For Free
sometime in the bright future , you will be able to deploy the same virtual appliance containing your application to all your target environments without adjustments. for the time being, however, deployments to traditional dtap 1 landscapes almost always mean "tweaking" the application and associated configuration and resources to match the target environment - think endpoints, properties files or datasource usernames and passwords, to name but a few.
in the absence of any established standards or even guidelines in this area, many different solutions to this problem of
deployment package customization
have been employed, from fairly elegant approaches such as
to crude string search-and-replace.
furthermore, different types of middleware platforms have varying degrees of support for customizations: typically, portals, esbs and process servers offer some "native" solution to the problem, whereas application servers tend to leave users to fend for themselves.
more often than not, the result is a chaotic mix of customization approaches across projects, target platforms and departments 2 . here, we'll look at some of these approaches, classify them and examine some drawbacks and benefits.
important considerations: so what are we looking for..?
when comparing different approaches to customization, there are a number of things to bear in mind:
- convenience: the customization procedure should be easy to set up and quick to carry out. this is mainly a concern for developers that might have to execute a customization whenever the application is deployed to the development environment.
- visibility: it should be easy for appropriately authorized users to view both the customization points (i.e. which parts of the application can be customized) and the values assigned to them in a given environment.
- fail-safety: if an application is deployed with missing or invalid values for customization points (think forgetting to set a timeout or using the test endpoint for the production environment) this should be detected quickly. preferably, missing or incorrect values would be detected at deployment-time, rather than becoming apparent only due to spurious runtime behaviour.
- revisioning and access control: only appropriate users should be able to view and edit the values assigned to an application's customization points. preferably, a history of changes to these values would be maintained. this aids the comparison of the values for an application across versions, as well as allowing users to compare the values for the same version of a deployed application across target environments.
wait for it... do this at runtime
as ever, a good way to approach a problem is to try to avoid it. in this case, you can side-step the need to tweak the application at deployment-time by deferring the lookup of application properties to runtime, using jmx (which, after all, was designed also for that purpose) with suitable default values. you get all the access control, history management etc. of the jmx implementation for free, and can update the environment-specific values without having to edit application files.
of course, this only works if your container provides a suitably convenient jmx implementation - if not, getting your development environment set up is unlikely to be a lot of fun. more fundamentally, this will not work for attributes that are set before the application is started (e.g. the context root) or for properties of middleware resources (such as a queue retry timeout).
- convenience: usually moderate, as the developer's environment tends not to be easy to set up, but this depends strongly on the target platform's support for jmx or whichever lookup mechanism is used. needs to be balanced against the advantage of being able to change the behaviour of the running application.
- visibility: in the case of jmx, good, since it is easy to see all the mbeans and their properties, especially if a sensible naming convention is used.
- fail-safety: jmx will usually require "safe" default values (which should not be environment-specific).
- revisioning and access control: again, depends on the target platform's implementation. but generally good, especially access control, as it is usually integrated with the management console of the middleware stack.
replace me: token-based replacement
token-based replacement basically means placeholders – the deployment package contains (in artifacts, resource definitions etc.) special symbols, and at deployment time these symbols are replaced by values supplied for them. token-based customization requires the provider, usually developers, to prepare the deployment artifacts specifically.
this means that, firstly, all the tokens that need to be replaced are
known at the time of delivery, which has the added advantage that the
application now has a well-defined set of customization points. the
special syntax of tokens also makes it relatively easy to verify that
values for all the tokens have been supplied.
even if this verification fails, the application will presumably break due to syntax errors – tokens are usually not valid values – which provides an extra "fail-safe" mechanism.
of course, from a developer's perspective this fail-safe mechanism can be a nuisance, too. since the application doesn't work until the tokens have been replaced, build processes have to be set up to carry this out, and quickly , certainly in development environments.
- convenience: moderate, since the build process has to be set up to correctly process files containing tokens. if you're working in a development environment like eclipse with wtp it can be worse, especially if it interferes with "hot-update" capabilities.
wherever there is a token there is a customization points, so they are clear and self-documenting. if you're using
arguably the "right" way of doing token-based replacement in jee, the
assigned values are usually also very easy to see in the console.
gaining insight on the can be trickier if you're working with file-based search-and-replace as is usual with properties files, as you have to not only have the final artifact to see the values but also need to look at the original to see where the placeholders were.
- fail-safety: high, which in the context of a mission-critical activity such as deployment is crucial. tokens are almost never valid values, so forgetting to assign a value will usually result in a failed deployment. of course, there is still a risk of replacing the tokens with values for the wrong environment.
- revisioning and access control: depends on how the values that are to be assigned to the customization points are provided. with jndi, good revisioning and access control normally come "for free" with the console. as for the common case of properties files, we've seen a bit of everything: from files that are not versioned and shared with everyone as part of a "template project", to ones that are maintained in a dedicated version control system.
replace that: pointer-based replacement
pointer-based replacement is essentially a fancy way of referring to "search-and-replace" and its slightly more advanced cousin, xpath -based replacement, commonly found in portal or esb environments. this is fragile because the deployment package contains valid values, so there is a strong risk of silent failure. further, the customization points of the package are essentially invisible. ironically, this can be useful in order to "patch" packages that were not written in a customizable way.
it is generally true that it is much easier to prepare a deployment package for pointer-based customization – it is simply a matter of exporting, or making a snapshot of, the settings and artifacts of the development or other "authoring" environment. of course, such an export can be "tokenized" (by replacing the values that need to be customizable with tokens), but this is error-prone and can involve prohibitive manual overhead, especially a problem during development when such exports are made frequently.
obviously, pointer-based customization is only possible if the artifacts or definitions that need to be customized are structured in some way – otherwise, it is not possible to construct a pointer to refer to the item to be modified. xml and resource definitions (i.e. properties files) fall into this category, but e.g. plain text files do not.
- convenience: high. the source application contains valid values, so can run "as is".
- visibility: customization points are not visible in the source files, although they can be deduced (with more or less ease) from the specification of the pointers that define where values need to be replaced. the values to be assigned are usually defined alongside the pointer specifications.
- fail-safety: weak, since the source application contains (syntactically) valid values, even if the replacement is not or only partially carried out. this means it can take quite a while before the problem manifests itself, often in spurious ways - a maintenance nightmare.
- revisioning and access control: depends again on how the pointers and values are specified and stored. because the pointer specifications are usually contained in the same file as the values to be assigned, it is usually not possible to separate access to customization point (i.e. pointer) definitions - usually a developer activity - from access to the assigned values, which often should only be known to operations.
if the customizations required for your application can be carried out after the application has started, it's certainly worth considering designing your application to be runtime-configurable. this makes management of the application convenient and secure, but of course adds some extra complexity at development time. and in some cases 4 , customization needs to be carried out before the application is loaded.
whilst pointer-based replacement is convenient and can be used even with applications that were not designed to be customized, token-based replacement offers significant advantages in terms of (fail-)safety and visibility. since deployments are often mission-critical, these are substantial benefits and should lead to tokens being preferred wherever possible.
unfortunately, many of the existing middleware platforms have neglected to properly address this issue, yet another reason why a deployment automation solution like deployit that is designed to support customization in a consistent and secure way can be a big benefit.
Opinions expressed by DZone contributors are their own.