Wednesday, October 04, 2006

Actuate: Cluster Nodes Start via a VBS File

While my last post described how to write a small program to restart all the nodes in an Actuate cluster, I ran into a problem with the implementation. Turns out that the server does not have .Net 2.0 installed. So to avoid the annoyances of TI paperwork, I took the same concept and applied it to a small VBScript to do the same thing. This works out a little better in the sense that it is slightly more portable. I did omit the code to pull the server statuses however due to the fact that I did not have a sniffer handy to retrieve those messages, so I hardcoded a small array of strings with the server names to restart. I also do not have the post run statuses. This demonstrates some of the flexibility of one of the greatest evils Microsoft ever unleashed. It also demonstrates how to instantiate the HTTPRequest and XML DOM objects inside of a script.

The following code can be run is a scheduled task as a Visual Basic Script file (.vbs) using CScript to execute. If it were saved as serverStart.vbs, I would run “cscript serverStart.vbs”.

'----------------------------------------------------------------------------

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Function to send the startup message
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function getStartMessage(servername, authID)
    Dim s
    s = "<?xml version=""1.0"" encoding=""UTF-8""?>"
    s = s & "<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" SOAP-ENV:encodingstyle=""http://schemas.xmlsoap.org/soap/encoding"" xmlns:xsd=""http://www.w3.org/2000/10/XMLSchema"" xmlns=""http://schemas.actuate.com/actuate8"" xmlns:SOAP-ENC=""http://schemas.xmlsoap.org/soap/encoding/"">"
    s = s & "<SOAP-ENV:Header>"
    s = s & "<AuthId>" & authID & "</AuthId>"
    s = s & "<Locale>en_US</Locale>"
    s = s & "</SOAP-ENV:Header>"
    s = s & "<SOAP-ENV:Body>"
    s = s & "<SOAP-ACTU:StartServer xmlns:SOAP-ACTU=""http://schemas.actuate.com/actuate8"">"
    s = s & "<ServerName>" & servername & "</ServerName>"
    s = s & "<SystemHeartbeatInformation><UseMulticast>false</UseMulticast></SystemHeartbeatInformation>"
    s = s & "</SOAP-ACTU:StartServer>"
    s = s & "</SOAP-ENV:Body></SOAP-ENV:Envelope>"
    
    getStartMessage = s
End Function
'----------------------------------------------------------------------------

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Function to send the login message
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function getLoginMessage(passwd)
    Dim s
    s = "<?xml version='1.0' encoding='UTF-8'?>"
    s = s & "<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" "
    s = s & "SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" "
    s = s & "xmlns:xsd=""http://www.w3.org/2000/10/XMLSchema"" "
    s = s & "xmlns:SOAP-ENC=""http://schemas.xmlsoap.org/soap/encoding/"" "
    s = s & "xmlns=""http://schemas.actuate.com/actuate8"">"
    s = s & "<SOAP-ENV:Header>"
    s = s & "<Locale>en_us</Locale>"
    s = s & "</SOAP-ENV:Header>"
    s = s & "<SOAP-ENV:Body>"
    s = s & "<SystemLogin>"
    s = s & "<SystemPassword>"
    s = s & passwd
    s = s & "</SystemPassword>"
    s = s & "</SystemLogin>"
    s = s & "</SOAP-ENV:Body>"
    s = s & "</SOAP-ENV:Envelope>"
    
    getLoginMessage = s
End Function
'----------------------------------------------------------------------------
    
'Objects needed for XML and HTTP Requests
Dim xm
Set xm = CreateObject("Msxml2.DOMDocument.6.0")
Dim h
Set h = CreateObject("WinHttp.WinHttpRequest.5.1")

'Used to store the authID after login, the server list, and a generic counter
Dim authID
Dim serverList(1)
Dim x

'Add more cluster nodes to here when they are added
serverList(1) = "clusterChild1"

'Setup the request header and server information
h.Open "POST", "http://master:8000/"
h.setRequestHeader "Content-Type", "text/xml;charset=utf-8"

'Sent the login
h.send getLoginMessage("password")

'Load the login response into the XML object, then retrieve the AuthID from the
'response text
xm.loadXML h.responseText
authID = xm.Text

'Go through our server list, send the startup message for each server
For x = 1 To UBound(serverList)
    h.send getStartMessage(serverList(x), authID)
Next

No comments: