Showing posts with label OLE/COM. Show all posts
Showing posts with label OLE/COM. Show all posts

Friday, January 5, 2018

Day 24 The tide is high

Day 24

The tide is high

Let us say that you do not have Sterling Control Center to run the High Water Mark report for maximum concurrent sessions.
You might want this for determining if you are making optimum use of the number of concurrent sessions that you are licensed for.
You may not have enough Connect:Direct nodes that you feel justifies the need for Sterling Control Center.

For Windows

The following script water-mark.vbs is an example of how to do this using VBScript and the Connect:Direct Windows SDK.
In fact this is a fairly simple example of how to use the Connect:Direct Windows SDK.
'
' Script to report on the high water mark for the number of concurrent Connect:Direct sessions 
'

Dim node        ' Represents the Connect Direct Node we are using. 
Dim stats       ' A collection of statistic records. 
Dim stat        ' An individual statistic record. 

' Make the OLE/COM connection to Connect:Direct 
Set node = CreateObject("CD.Node")

' Sign on using defaults from the Client Connection Utility
node.Connect "CD.NICKE","",""

' Get start and end sessions statistics records since yesterday
set stats = node.SelectStats("select statistics startt=(today) recids=(SSTR,SEND) ccode=(eq,0)")

currentNumberOfSessions = 0
highWaterMark  = 0

For Each stat in stats
       Select Case stat.RecId 
          Case "SSTR" currentNumberOfSessions=currentNumberOfSessions+1          Case "SEND" currentNumberOfSessions=currentNumberOfSessions-1       End Select
       If currentNumberOfSessions > highWaterMark Then
          highWaterMark = currentNumberOfSessions
       End If
Next

Wscript.echo "Concurrent sessions high water mark = " & highWaterMark

Set node  = nothing
Set stats = nothing
Set stat  = nothing
If you have the Connect:Direct Windows SDK installed and default sign on credentials registered with the Client Connection Utility you can run the script as follows:
C:\Users\nicke> cscript /nologo water-mark.vbs

Concurrent sessions high water mark = 5
The above script is minimal in that it is only meant to be run interactively as it does not itself check for every error.
You run the script on a Windows machine with the SDK installed, but the node in question can be a remote Windows or UNIX (I have not tested other platforms) Connect:Direct node as long as the node is registered with the Client Connection Utility.

For UNIX

If all you have are UNIX machines then you can use the following shell function for convenience:
function watermark
{
        # Usage: cd work/UNIX.NODE ; cat S201712* | watermark
        egrep "RECI=(SSTR|SEND)" | grep CCOD=0 | awk '
BEGIN{
        currentNumberOfSessions=0
        highWaterMark=0
}
/RECI=SSTR/ { currentNumberOfSessions++ }
/RECI=SEND/ { currentNumberOfSessions-- }
{
        if(currentNumberOfSessions > highWaterMark){
                highWaterMark=currentNumberOfSessions
        }
}
END{
        print "Concurrent sessions high water mark = " highWaterMark
}'
}
Put the above shell function definition either in your .profile or just paste it into a terminal session. You will need to be in the work directory for your UNIX node where the statistics files are. Then you can run it as follows by piping whatever period of statistics files you want through the watermark shell function:
[work/CD.UNIX] $ cat S201712* | watermark
Concurrent sessions high water mark = 8
Now you will know whether the number of sessions you use is appropriate for your licensing of these nodes.



Tuesday, January 22, 2013

No Chit Chat, just Smalltalk


Day 20

This is something that you do not see every day.  Below is an extract from an old Smalltalk workspace listing I found where I was experimenting with Cincom's ObjectStudio Smalltalk programming environment and the OLE/COM interface to Connect:Direct.

It was just as easy if not easier than VBScript to control Connect:Direct using Smalltalk.

D := OLEDispatcher new: 'CD.NODE'.
N :=  D call: 'Connect' params: (Array with: 'MY.NODE' with: '' with: '').


TXT := 'TEST001 PROCESS'                           + CrLf
           + '     MAXDELAY=UNLIMITED'             + CrLf
           + '     REMOTE=CD.REMOTE'               + CrLf
           + '     HOLD = NO'                      + CrLf
           + 'STEP01 COPY  FROM ('                 + CrLf
           + '     FILE=C:\TEMP\INPUT.TXT '        + CrLf
           + '     LOCAL /*$Windows NT$*/)'        + CrLf
           + '     TO ('                           + CRLF
           + '     REMOTE /*$Windows NT$*/'        + CrLf
           + '     FILE=C:\TEMP\OUTPUT.TXT'        + CrLf
           + '     DISP=(RPL))'                    + CrLf
           + 'PEND'.

P := D call: 'Submit' params: (Array with: TXT).

P at: 'ProcessNumber'


S := D call: 'SelectStats' params: (Array with: 'select statistics pnumber=62').
I := S call: 'HasMore'.
I := S call: 'GetNext'.
I at: 'MsgId'

Smalltalk is one of my favourite programming languages, due to its' simple syntax and object orientation.

It might be interesting to see how this compares to using OLE/COM from TCL.  I'll save that for another post.

Monday, May 31, 2010

OLE/COM & Connect:Direct

Day 11

Sometimes we want to be able to automate tasks with regard to Connect:Direct.  On Windows we could do this using batch files (.bat or .cmd), or with an application using the Connect:Direct Windows SDK.  My preferred way is to use some form of VBScript and the OLE/COM interface that the Connect:Direct Windows SDK provides.

That sounds more complicated that it really is.  I'll show an example Windows Script Host (WSH) script that uses the OLE/COM interface to connect to the local node and send/receive files  with a remote node.

Start by looking at the example below from the comment "Processing starts here" where you will see the creation of an object of type "CD.Node".  If my memory serves me well this is not well documented in the Connect:Direct Windows SDK manual.

Once we have an object that represents our local node in my case called "NICKE" we can make a connection with our credentials.  In this example the user name and password are empty strings and it makes the connection based on how the "CD Client Connection Utility" is setup.  This utility allows you to define several user credentials and which one is to be used as the default when none are given as in my example below.

The rest of the script then goes on to perform a transfer using the "CDSend" function to a remote node called "CD.OTHER", check for an error and then perform a receive of a file and then another check for an error.  Both "CDSend" & "CDRecv" make use of a generic function "CDTransfer" to perform a file transfer with the direction of the transfer passed as a parameter which is then used to generate a dynamic Connect:Direct process which is the submitted using the "Node.Submit" function and then the statistics for the process just submitted and executed are analysed and the highest condition code returned to the caller of the "CDTransfer" function.

At the end of the script the connection with the local node is disconnected and the "Node" object de-allocated.

The script below can either be run by double-clicking directly on the ".vbs" script in the file explorer or by giving the name of the script as a parameter to the "CSCRIPT.EXE" program as follows:

C:\> cscript cdvbsdk.vbs

In the next post I will an alternative method of driving Connect:Direct from VBScript.


' Windows Script Host Sample Connect:Direct Script. 
' 
' Includes ability to push and pull files to/from the other Node. 
 
Dim Node        ' Represents the Connect Direct Node we are using. 
Dim procs       ' A collection of process records. 
Dim proc        ' An individual process record. 
Dim stats       ' A collection of statistic records. 
Dim stat        ' An individual statistic record. 
 
' Connect:Direct condition codes values 
 
warningConditionCode = 4 
errorConditionCode   = 8 
 
 
 
 
Function CDTransfer (fromFile, toFile, otherNode, direc) 
 
        If direct = "PUSH" then 
                localOrRemote = "LOCAL" 
                remoteOrLocal = "REMOTE" 
        else 
                localOrRemote = "REMOTE" 
                remoteOrLocal = "LOCAL" 
        End If 
 
        ' The process text to be submitted. 
 
        txtProcess = "TRANSFER PROCESS"                 + vbCrLf _ 
                + "     MAXDELAY=UNLIMITED"             + vbCrLf _ 
                + "     REMOTE=" & otherNode            + vbCrLf _ 
                + "     HOLD = NO"                      + vbCrLf _ 
                + "STEP01 COPY  FROM ("                 + vbCrLf _ 
                + "     FILE=" & fromFile               + vbCrLf _ 
                + "     " & localOrRemote               + vbCrLf _ 
                + "     TO ("                           + vbCrLf _ 
                + "     " & remoteOrLocal               + vbCrLf _ 
                + "     FILE=" & toFile                 + vbCrLf _ 
                + "     DISP=(RPL))"                    + vbCrLf _ 
                + "PEND"                                + vbCrLf
 
 
        set proc = Node.Submit(txtProcess)             ' Submit the process 
 
        ' Get the statistics regarding the process that has now finished. 
 
        set stats = Node.SelectStats("SELECT STATISTICS PNUMBER=" & proc.ProcessNumber) 
 
        ' If any step in the process has a condition code greater than "warning" we have a problem. 
 
        highestConditionCode =0 
 
        For Each stat in stats
 
                if stat.ConditionCode > highestConditionCode then 
                        highestConditionCode = stat.ConditionCode
                End If 
 
        Next 
 
        If highestConditionCode > warningConditionCode then 
 
                CDTRansfer = highestConditionCode
 
        End If 
 
End Function 
 
 
 
 
Function CDSend ( fromfile, toFile, otherNode ) 
        CDSend = CDTransfer ( fromfile, toFile, otherNode, "PUSH" ) 
End Function 
 
Function CDRecv ( fromfile, toFile, otherNode ) 
        CDRecv = CDTransfer ( fromfile, toFile, otherNode, "PULL" ) 
End Function 
 
 
' ------------------------------------------------------------------------------------------ 
' 
' Processing starts here 
' 
Set Node = CreateObject("CD.Node")              ' Make the OLE/COM connection to Connect:Direct 
 
Node.Connect "NICKE","",""      ' Sign on 
 
exitcode = 0 
 
rtc = CDSend ( "c:\temp\input.txt", "c:\temp\output.txt", "CD.OTHER") 
 
if rtc > warningConditionCode then 
        wscript.echo "Send Failed" 
        exitcode = exitcode + rtc
End If 
 
rtc = CDRecv ( "c:\temp\input.txt", "c:\temp\recv.txt", "CD.OTHER") 
 
if rtc > warningConditionCode then 
        wscript.echo "Recv Failed" 
        exitcode = exitcode + rtc
End If 
 
' You need to disconnect from the Node or you will leave cscript or wscript processes hanging around 
Node.Disconnect 
Set Node=Nothing 
Wscript.Quit(exitcode)