xmlstarlet to remove XML stanzas

Given our environmnet has both WebSphere v7 and WebSphere v9, we must merge their respective plugins. There are similarly named clusters in both v7 and v9 (e.g. Level_1, Level_2, etc.), and for some reason the GenPluginCfg.sh will merge one (and only one) of the clusters. They’re not even the same clusters in test and prod. In addition, there are unique entries for the cluster in question.

I have noticed this before, but given everything worked as expected through our IHS (aka Apache), it did not register on our radar. However, when I updated our traffic to go through the latest IHS version, we began to see ServerIOTimeouts to the cluster that spans both WAS v7 and WAS v9. We have yet to pinpoint exactly why IHS v9 is more strict than IHS v7, but either way we had to fix this problem.

The error messages were saying it was due to the ServerIOTimeout, but the numbers were not matching with what I had explicitly set for Level_1 servers (60 seconds). This led me to the “Shared Cluster” that the plugin merge had created on its own.

ERROR: ws_common: ServerActionfromReadRC: ServerIOTimeout fired. Time out 1. retry count 0. serverIOTimeoutRetry -1, retry YES, rc 2, server Level_1_was_v9_01_1, URI /someUrl, client port 1234

The plugin-cfg.xml file with the merged and independent pieces look like this:

<ServerCluster CloneSeparatorChange="false" GetDWLMTable="false"
	IgnoreAffinityRequests="true" LoadBalance="Round Robin"
	Name="Shared_3_Cluster_0" PostBufferSize="64" PostSizeLimit="-1"
	RemoveSpecialHeaders="true" RetryInterval="60" ServerIOTimeoutRetry="-1">
	<Server CloneID="1basreo4a" ConnectTimeout="5"
		ExtendedHandshake="false" LoadBalanceWeight="77"
		MaxConnections="0"
		Name="wasv901Node_Level_1_was_v9_01_1"
		ServerIOTimeout="-1" WaitForContinue="false">
		<Transport ConnectionTTL="28" Hostname="wasv901"
			Port="9445" Protocol="https">
			<Property Name="keyring" Value="/ihs/security/plugin-key.kdb"/>
			<Property Name="stashfile" Value="/ihs/security/plugin-key.sth"/>
		</Transport>
	</Server>
	<Server CloneID="1692lco3o" ConnectTimeout="90"
		ExtendedHandshake="false" LoadBalanceWeight="77"
		MaxConnections="-1"
		Name="wasv701Node_Level_1_WAS_v7_01_0"
		ServerIOTimeout="-1" WaitForContinue="false">
		<Transport Hostname="wasv701.company.com" Port="30006" Protocol="http"/>
		<Transport Hostname="wasv701.company.com" Port="31006" Protocol="https">
			<Property Name="keyring" Value="/ihs/security/plugin-key.kdb"/>
			<Property Name="stashfile" Value="/ihs/security/plugin-key.sth"/>
		</Transport>
	</Server>
	<Server CloneID="1692lcpij" ConnectTimeout="90"
		ExtendedHandshake="false" LoadBalanceWeight="77"
		MaxConnections="-1"
		Name="wasv702Node_Level_1_WAS_v7_02_0"
		ServerIOTimeout="-1" WaitForContinue="false">
		<Transport Hostname="wasv702.company.com" Port="30006" Protocol="http"/>
		<Transport Hostname="wasv702.company.com" Port="31006" Protocol="https">
			<Property Name="keyring" Value="/ihs/security/plugin-key.kdb"/>
			<Property Name="stashfile" Value="/ihs/security/plugin-key.sth"/>
		</Transport>
	</Server>
	<Server CloneID="1bassd4fp" ConnectTimeout="5"
		ExtendedHandshake="false" LoadBalanceWeight="77"
		MaxConnections="0"
		Name="wasv902Node_Level_1_was_v9_02_1"
		ServerIOTimeout="-1" WaitForContinue="false">
		<Transport ConnectionTTL="28" Hostname="wasv902"
			Port="9445" Protocol="https">
			<Property Name="keyring" Value="/ihs/security/plugin-key.kdb"/>
			<Property Name="stashfile" Value="/ihs/security/plugin-key.sth"/>
		</Transport>
	</Server>
	<PrimaryServers>
		<Server Name="wasv901Node_Level_1_was_v9_01_1"/>
		<Server Name="wasv702Node_Level_1_WAS_v7_02_0"/>
		<Server Name="wasv902Node_Level_1_was_v9_02_1"/>
	</PrimaryServers>
	<BackupServers>
		<Server Name="wasv701Node_Level_1_WAS_v7_01_0"/>
	</BackupServers>
</ServerCluster>

	
<!-- WAS v7 -->
<ServerCluster CloneSeparatorChange="false" GetDWLMTable="false"
	IgnoreAffinityRequests="true" LoadBalance="Round Robin"
	Name="Level_1_0" PostBufferSize="64" PostSizeLimit="-1"
	RemoveSpecialHeaders="true" RetryInterval="60" ServerIOTimeoutRetry="-1">
	<Server CloneID="1692lco3o" ConnectTimeout="90"
		ExtendedHandshake="false" LoadBalanceWeight="77"
		MaxConnections="-1" Name="wasv701Node_Level_1_WAS_v7_01"
		ServerIOTimeout="60" WaitForContinue="false">
		<Transport Hostname="wasv701.company.com" Port="30006" Protocol="http"/>
		<Transport Hostname="wasv701.company.com" Port="31006" Protocol="https">
			<Property Name="keyring" Value="/ihs/security/plugin-key.kdb"/>
			<Property Name="stashfile" Value="/ihs/security/plugin-key.sth"/>
		</Transport>
	</Server>
	<Server CloneID="1692lcpij" ConnectTimeout="90"
		ExtendedHandshake="false" LoadBalanceWeight="77"
		MaxConnections="-1" Name="wasv702Node_Level_1_WAS_v7_02"
		ServerIOTimeout="60" WaitForContinue="false">
		<Transport Hostname="wasv702.company.com" Port="30006" Protocol="http"/>
		<Transport Hostname="wasv702.company.com" Port="31006" Protocol="https">
			<Property Name="keyring" Value="/ihs/security/plugin-key.kdb"/>
			<Property Name="stashfile" Value="/ihs/security/plugin-key.sth"/>
		</Transport>
	</Server>
	<PrimaryServers>
		<Server Name="wasv702Node_Level_1_WAS_v7_02"/>
	</PrimaryServers>
	<BackupServers>
		<Server Name="wasv701Node_Level_1_WAS_v7_01"/>
	</BackupServers>
</ServerCluster>


<!-- WAS v9 -->
<ServerCluster CloneSeparatorChange="false" GetDWLMTable="true"
	IgnoreAffinityRequests="false" LoadBalance="Round Robin"
	Name="Level_1_1" PostBufferSize="0" PostSizeLimit="-1"
	RemoveSpecialHeaders="true" RetryInterval="60" ServerIOTimeoutRetry="-1">
	<Server CloneID="1basreo4a" ConnectTimeout="5"
		ExtendedHandshake="false" LoadBalanceWeight="77"
		MaxConnections="0"
		Name="wasv901Node_Level_1_was_v9_01"
		ServerIOTimeout="60" WaitForContinue="false">
		<Transport ConnectionTTL="28" Hostname="wasv901"
			Port="9445" Protocol="https">
			<Property Name="keyring" Value="/ihs/security/plugin-key.kdb"/>
			<Property Name="stashfile" Value="/ihs/security/plugin-key.sth"/>
		</Transport>
	</Server>
	<Server CloneID="1bassd4fp" ConnectTimeout="5"
		ExtendedHandshake="false" LoadBalanceWeight="77"
		MaxConnections="0"
		Name="wasv902Node_Level_1_was_v9_02"
		ServerIOTimeout="60" WaitForContinue="false">
		<Transport ConnectionTTL="28" Hostname="wasv902"
			Port="9445" Protocol="https">
			<Property Name="keyring" Value="/ihs/security/plugin-key.kdb"/>
			<Property Name="stashfile" Value="/ihs/security/plugin-key.sth"/>
		</Transport>
	</Server>
	<PrimaryServers>
		<Server Name="wasv901Node_Level_1_was_v9_01"/>
		<Server Name="wasv902Node_Level_1_was_v9_02"/>
	</PrimaryServers>
</ServerCluster>

My first thought was to see if I could prevent the GenPluginCfg.sh script from merging these clusters together, but that proved to be a waste of time. I then thought to just delete this part from Test’s plugin-cfg.xml file to see if it worked, and to my delight it worked fine without issue.

Sometimes there are unintended consequences, so I put all this info into an IBM Support ticket, and had their brain power evaluate the problem at large. They said this is a poor implementation choice on their side (to merge the clusters), but they’ve seen it before and there was no time table to fix it.

I told them about my idea to just simply remove the “shared” related parts of the plugin-cfg.xml and they said that would be a perfectly fine way to fix this problem.

I first started trying to use some form of awk/sed/gawk to solve this, but those were proving to be close, but no cigar. This then led me to xmlstarlet to parse XML, which I put in another Unix script to manipulate the plugin-cfg.xml after the merge had occurred, but before it was sent out to my IHS servers:

xpathShared=`xml el -v ${PLUGIN_TEMP} | grep UriGroup | grep Shared_`
xmlstarlet ed -d "$xpathShared" plugin-cfg.xml > xml1

xpathShared=`xml el -v xml1 | grep ServerCluster | grep Shared_`
xmlstarlet ed -d "$xpathShared" xml1 > xml2

xpathShared=`xml el -v xml2 | grep Route | grep sharedCell_`
xmlstarlet ed -d "$xpathShared" xml2 > xml3

xpathShared=`xml el -v xml3 | grep UriGroup | grep sharedCell_`
xmlstarlet ed -d "$xpathShared" xml3 > xml4

xpathShared=`xml el -v xml4 | grep VirtualHost | grep sharedCell_`
xmlstarlet ed -d "$xpathShared" xml4 > plugin-cfg.xml

This script greatly simplified the removal of the unnecessary merged stanzas, and is much more maintainable then even if I had gotten the awk/sed commands to work.