There are several posts both in the BMC Communities as well as ARSList which outlines various examples of automating the flushing of the MidTier Cache using varying methods and languages.
At some point last year when the latest ARSList thread on this topic came up, I looked at all the examples and extrapolated my own version written in Java using the Apache's httpclient along with snakeyaml in order to create a useful utility that I use quite a bit to automate flushing cache in larger environments that have multiple mid-tiers (as well as my own development enviornment that has a single midtier).
I feel it is a useful enough utility to share so I've decided to post it here as a document along with full source code for anybody interested in extending / reusing.
There are a few improvements (in my eyes) that I made to the various example code I've seen on ARSList and the BMC Communities around automating cache flush (not all the examples were created equal and some where stubs of bigger programs so some may have done some of this already).
- Better error checking at the various http GET actions, simply looking for an "OK" back from the HTTP server doens't mean the action was successful. For example, when actually performing the flush cache action, when there is an error a web page is still presented back to you so http status will be "OK" but the page will tell you that it wasn't able to flush the cache. Same applies for a bad password, you still get HTTP "OK" back but the rest of the process fails as you haven't bypassed the login portion yet.
- Added a yaml configuration file where one or more mid-tiers can be defined so that once compilled you don't have to touch code anymore, just update the config file for any target mid-tier(s) you want flushed.
- Encode the password properly for the use in a URL (e.g. if special characters like "&" are part of the password, it needs to be encoded to not break URI conforming URLs)
- Distributed as an executable (packed) jar file so that you can simply double-click if you want and it will execute and provide feedback by dialog boxes as each mid-tier is actioned against. If it was successful you will get a dialog telling you that said midtier was flushed successfully, if there was an error, it will tell you the error and against which mid-tier.
- Because I'm using apache's httpclient, you get SSL support right out of the box so that you can connect to secured MidTiers, just make sure that if you are using SSL, that the certificate is trusted by the JVM you execute this utility with (e.g. normal verified certificates are fine, if you are using self-signed or non-trusted certificates, makes sure to add that cert to your keystore or it won't work and an error will be popped).
The midtiers.yaml configuration file, as the name implies, is based on yaml format which is a very easy to parse and read syntax. If you had three mid-tiers deployed and wanted to flush them all, your configuration file could look like this:
- Target: http://midtierserver1/arsys
- Target: http://midtierserver3/arsys
- Target: https://securemidtierserver1/arsys
If you have only a single midtier, then you just have one set of Target, UserName and Password elements under the MidTiers parent.
I have attached to this post a zip file that contains the compiled executable jar file as well as a sample midtiers.yaml configuration file. Extract both files somewhere (keep them together) and then you can start using it right away by tayloring the configuration file to your target mid-tiers and then double-click on the FlushCache.jar file to begin. This should work exactly the same on non-windows since it is written in Java with nothing windows specific in it.
I've also attached the java source file as well as a pom.xml file that I used for those that use maven for dependancies and packaging.
I hope this may be useful to somebody someday