|
| 1 | +/************************************************************************** |
| 2 | +Copyright (c) 2023-2024 by Progress Software Corporation. All rights reserved. |
| 3 | +**************************************************************************/ |
| 4 | +/** |
| 5 | + * Author(s): Dustin Grau ([email protected]) |
| 6 | + * |
| 7 | + * Gets MSAgent requests for an ABLApp. |
| 8 | + * Usage: getRequests.p <params> |
| 9 | + * Parameter Default/Allowed |
| 10 | + * Scheme [http|https] |
| 11 | + * Hostname [localhost] |
| 12 | + * PAS Port [8810] |
| 13 | + * UserId [tomcat] |
| 14 | + * Password [tomcat] |
| 15 | + * ABL App [oepas1] |
| 16 | + * AgentID [#] |
| 17 | + */ |
| 18 | + |
| 19 | +using OpenEdge.ApplicationServer.Util.OEManagerConnection. |
| 20 | +using OpenEdge.ApplicationServer.Util.OEManagerEndpoint. |
| 21 | +using OpenEdge.Core.Json.JsonPropertyHelper. |
| 22 | +using OpenEdge.Core.JsonDataTypeEnum. |
| 23 | +using Progress.Json.ObjectModel.JsonObject. |
| 24 | +using Progress.Json.ObjectModel.JsonArray. |
| 25 | +using Progress.Json.ObjectModel.JsonDataType. |
| 26 | + |
| 27 | +define variable cOutFile as character no-undo. |
| 28 | +define variable oAgents as JsonArray no-undo. |
| 29 | +define variable oAgent as JsonObject no-undo. |
| 30 | +define variable oRequests as JsonArray no-undo. |
| 31 | +define variable iLoop as integer no-undo. |
| 32 | +define variable iPID as integer no-undo. |
| 33 | +define variable cPID as character no-undo. |
| 34 | + |
| 35 | +/* Manage the server connection to the OEManager webapp */ |
| 36 | +define variable oMgrConn as OEManagerConnection no-undo. |
| 37 | +define variable cScheme as character no-undo initial "http". |
| 38 | +define variable cHost as character no-undo initial "localhost". |
| 39 | +define variable cPort as character no-undo. |
| 40 | +define variable cUserId as character no-undo. |
| 41 | +define variable cPassword as character no-undo. |
| 42 | +define variable cAblApp as character no-undo. |
| 43 | + |
| 44 | +/* Check for passed-in arguments/parameters. */ |
| 45 | +if num-entries(session:parameter) ge 6 then |
| 46 | + assign |
| 47 | + cScheme = entry(1, session:parameter) |
| 48 | + cHost = entry(2, session:parameter) |
| 49 | + cPort = entry(3, session:parameter) |
| 50 | + cUserId = entry(4, session:parameter) |
| 51 | + cPassword = entry(5, session:parameter) |
| 52 | + cAblApp = entry(6, session:parameter) |
| 53 | + cPID = entry(7, session:parameter) |
| 54 | + . |
| 55 | +else |
| 56 | + assign |
| 57 | + cScheme = dynamic-function("getParameter" in source-procedure, "Scheme") when (dynamic-function("getParameter" in source-procedure, "Scheme") gt "") eq true |
| 58 | + cHost = dynamic-function("getParameter" in source-procedure, "Host") when (dynamic-function("getParameter" in source-procedure, "Host") gt "") eq true |
| 59 | + cPort = dynamic-function("getParameter" in source-procedure, "Port") when (dynamic-function("getParameter" in source-procedure, "Port") gt "") eq true |
| 60 | + cUserId = dynamic-function("getParameter" in source-procedure, "UserID") when (dynamic-function("getParameter" in source-procedure, "UserID") gt "") eq true |
| 61 | + cPassword = dynamic-function("getParameter" in source-procedure, "PassWD") when (dynamic-function("getParameter" in source-procedure, "PassWD") gt "") eq true |
| 62 | + cAblApp = dynamic-function("getParameter" in source-procedure, "ABLApp") when (dynamic-function("getParameter" in source-procedure, "ABLApp") gt "") eq true |
| 63 | + cPID = dynamic-function("getParameter" in source-procedure, "ProcID") when (dynamic-function("getParameter" in source-procedure, "ProcID") gt "") eq true |
| 64 | + . |
| 65 | + |
| 66 | +/* Create and OEManager connection for API calls. */ |
| 67 | +assign oMgrConn = OEManagerConnection:Build(cScheme, cHost, integer(cPort), cUserId, cPassword). |
| 68 | + |
| 69 | +if (cPID gt "") eq true then do: |
| 70 | + assign oRequests = oMgrConn:GetAgentRequests(cAblApp, integer(cPID)). |
| 71 | + if oRequests:Length gt 0 then do: |
| 72 | + /* Write requests information from the specified MSAgent. */ |
| 73 | + message substitute("Saving requests information for MSAgent PID &1...", cPID). |
| 74 | + assign cOutFile = substitute("agentRequests_&1_&2.json", cPID, replace(iso-date(now), ":", "_")). |
| 75 | + oRequests:WriteFile(session:temp-directory + cOutFile, true). /* Write entire response to disk. */ |
| 76 | + message substitute("~tRequests data written to &1", cOutFile). |
| 77 | + end. |
| 78 | + else |
| 79 | + message substitute("No requests data for MSAgent PID &1", cPID). |
| 80 | +end. // cPID Present |
| 81 | +else do: |
| 82 | + /* Otherwise output requests for all agents of an ABL Application. */ |
| 83 | + |
| 84 | + /* Initial URL to obtain a list of all MSAgents for an ABL Application. */ |
| 85 | + message substitute("Looking for MSAgents of &1...", cAblApp). |
| 86 | + assign oAgents = oMgrConn:GetAgents(cAblApp). |
| 87 | + if oAgents:Length eq 0 then |
| 88 | + message "No MSAgents running". |
| 89 | + else |
| 90 | + AGENTBLK: |
| 91 | + do iLoop = 1 to oAgents:Length |
| 92 | + on error undo, next AGENTBLK |
| 93 | + on stop undo, next AGENTBLK: |
| 94 | + oAgent = oAgents:GetJsonObject(iLoop). |
| 95 | + |
| 96 | + /* We need the agent PID for user-friendly displays since that's how we identify the process. */ |
| 97 | + if JsonPropertyHelper:HasTypedProperty(oAgent, "pid", JsonDataType:string) then |
| 98 | + assign iPID = integer(oAgent:GetCharacter("pid")). |
| 99 | + |
| 100 | + /* Write requests information from any available MSAgents. */ |
| 101 | + if iPID gt 0 and oAgent:GetCharacter("state") eq "available" then do: |
| 102 | + assign oRequests = oMgrConn:GetAgentRequests(cAblApp, iPID). |
| 103 | + if oRequests:Length gt 0 then do: |
| 104 | + message substitute("Saving requests information for MSAgent PID &1...", iPID). |
| 105 | + assign cOutFile = substitute("agentRequests_&1_&2.json", iPID, replace(iso-date(now), ":", "_")). |
| 106 | + oRequests:WriteFile(session:temp-directory + cOutFile, true). /* Write entire response to disk. */ |
| 107 | + message substitute("~tRequests data written to &1", cOutFile). |
| 108 | + end. |
| 109 | + else |
| 110 | + message substitute("No requests data for MSAgent PID &1", iPID). |
| 111 | + end. /* agent state = available */ |
| 112 | + else |
| 113 | + message substitute("Agent PID &1 not AVAILABLE, skipping requests.", iPID). |
| 114 | + end. /* iLoop - agent */ |
| 115 | +end. // All Agents |
| 116 | + |
| 117 | +catch err as Progress.Lang.Error: |
| 118 | + put unformatted substitute("~nError while communicating with PASOE instance: &1", err:GetMessage(1)) skip. |
| 119 | +end catch. |
| 120 | +finally: |
| 121 | + /* Return value expected by PCT Ant task. */ |
| 122 | + {&_proparse_ prolint-nowarn(returnfinally)} |
| 123 | + return string(0). |
| 124 | +end finally. |
0 commit comments