(→Create a Folder and Append Name if One Already Exists)
|
(→Find All Agents Online And Offline)
|
Line 2314: | |||
BuildRequest br = new BuildRequest(bl, wflow, sg, usr, rse, req); | BuildRequest br = new BuildRequest(bl, wflow, sg, usr, rse, req); | ||
BuildService.getInstance().runWorkflow(br);</pre> | BuildService.getInstance().runWorkflow(br);</pre> | ||
- | = Find All Agents Online And Offline = | ||
- | * This can be heavily modified for practical uses in other applications (such as finding agents online in each environment versus offline, return just a list of online agents, return just a list of offline agents, etc.). The following script will return the status of all agents that the server is aware of: | ||
- | ==== AHPSCRIPTS-128 ==== | ||
- | <pre>/***********************************************************************/ | ||
- | /* */ | ||
- | /* This script will retrieve all online agents across all environments */ | ||
- | /* and print this information out */ | ||
- | /* */ | ||
- | /* @author BMG */ | ||
- | /* @date 02/22/2011 */ | ||
- | /* */ | ||
- | /***********************************************************************/ | ||
- | import com.urbancode.anthill3.main.client.AnthillClient; | ||
- | import com.urbancode.anthill3.persistence.UnitOfWork; | ||
- | import com.urbancode.anthill3.domain.agent.*; | ||
- | import com.urbancode.anthill3.services.agent.AgentManager; | ||
- | //The following settings are for establishing a connection to the | ||
- | //anthill server | ||
- | String username = "admin"; | ||
- | String password = "admin"; | ||
- | String host = "localhost"; | ||
- | int remotingPort = 4567; | ||
- | //obtain connection to the Anthill server | ||
- | AnthillClient anthill = AnthillClient.connect(host, remotingPort, username, password); | ||
- | //create a Unit of Work | ||
- | UnitOfWork uow = anthill.createUnitOfWork(); | ||
- | //Make room for debug info | ||
- | print("\n\n"); | ||
- | //quick description | ||
- | Thread.sleep(333); | ||
- | print("Now attempting to query all agents, and return status of each. PLEASE WAIT. . ."); | ||
- | Thread.sleep(500); | ||
- | //main script | ||
- | String agentName; | ||
- | String environmentName; | ||
- | int online = 0; | ||
- | int offline = 0; | ||
- | int total = 0; | ||
- | int none = 0; | ||
- | boolean others = false; | ||
- | AgentFactory agentFactory = AgentFactory.getInstance(); | ||
- | Agent[] agentArray = agentFactory.restoreAll(); | ||
- | print(""); | ||
- | for (index : agentArray){ | ||
- | status = AgentManager.getInstance().getAgentStatus(index); | ||
- | if (status != null && status.isOnline()){ | ||
- | agentName = index.getName(); | ||
- | print("[ ] - Agent '" + agentName + "' is returning ONLINE."); | ||
- | online++; | ||
- | } | ||
- | else if (status != null && !status.isOnline()){ | ||
- | agentName = index.getName(); | ||
- | print("[ERROR] - Agent '" + agentName + "' is returning OFFLINE."); | ||
- | offline++; | ||
- | } | ||
- | else{ | ||
- | print(status); | ||
- | others = true; | ||
- | } | ||
- | total++; | ||
- | } | ||
- | Thread.sleep(1000); | ||
- | print(""); | ||
- | print(""); | ||
- | print("+------------------------+ "); | ||
- | print("+ TOTAL ONLINE AGENTS : " + online); | ||
- | print("+ TOTAL OFFLINE AGENTS : " + offline); | ||
- | if (others==true){ | ||
- | print("+ TOTAL UNKNOWN AGENTS : " + none); | ||
- | } | ||
- | print("+ TOTAL AGENTS : " + total); | ||
- | print("+------------------------+ "); | ||
- | uow.commitAndClose(); | ||
- | print("\n\n"); | ||
- | //BMG</pre> |