|
(→AHPSCRIPTS-134)
|
(→AHPSCRIPTS-128)
|
| Line 1643: | |||
| //BMG</pre> | //BMG</pre> | ||
| + | = Change Environments of an Agent = | ||
| + | ==== AHPSCRIPTS-126 ==== | ||
| + | ''Script to change environments on '''ONE AGENT''''': | ||
| + | <pre>/********************************************************************************************/ | ||
| + | /* */ | ||
| + | /* CHANGEAGENTENVIRONMENTS.BSH */ | ||
| + | /* */ | ||
| + | /* Anthill Remoting API Script to add all agents in anthillpro to the specified environment */ | ||
| + | /* */ | ||
| + | /* Author: Brad M. Galla */ | ||
| + | /* Date: 02/11/2011 @ 12:18 */ | ||
| + | /* */ | ||
| + | /********************************************************************************************/ | ||
| + | /*===============================*/ | ||
| + | /* */ | ||
| + | /* IMPORTS */ | ||
| + | /* */ | ||
| + | /*===============================*/ | ||
| + | import com.urbancode.anthill3.main.client.AnthillClient; | ||
| + | import com.urbancode.anthill3.persistence.UnitOfWork; | ||
| + | import com.urbancode.anthill3.domain.servergroup.*; | ||
| + | import com.urbancode.anthill3.domain.agent.*; | ||
| + | /*===============================*/ | ||
| + | /* */ | ||
| + | /* CLIENT PARAMETERS */ | ||
| + | /* */ | ||
| + | /*===============================*/ | ||
| + | String serverHost = "localhost"; | ||
| + | int serverPort = 4567; | ||
| + | String userName = "admin"; | ||
| + | String password = "admin"; | ||
| + | /*===============================*/ | ||
| + | /* */ | ||
| + | /* CLIENT CONNECTION */ | ||
| + | /* */ | ||
| + | /*===============================*/ | ||
| + | AnthillClient anthill = AnthillClient.connect(serverHost, serverPort,userName, password); | ||
| + | UnitOfWork uow = anthill.createUnitOfWork(); | ||
| + | print("\n"); | ||
| + | print("==========================="); | ||
| + | print(" AGENT CONFIG DEBUG SCREEN"); | ||
| + | print("==========================="); | ||
| + | /*===============================*/ | ||
| + | /* */ | ||
| + | /* SCRIPT */ | ||
| + | /* */ | ||
| + | /*===============================*/ | ||
| + | ServerGroupFactory servergroupfactory = ServerGroupFactory.getInstance(); | ||
| + | ServerGroup environment = servergroupfactory.restoreForName("Build-Farm"); //Replace with Environment Name | ||
| + | AgentFactory agentfactory = AgentFactory.getInstance(); | ||
| + | Agent[] agentArray = agentfactory.restoreAllNotIgnored(); | ||
| + | String agentName; | ||
| + | int subtotal=0; | ||
| + | int total=0; | ||
| + | int warnings=0; | ||
| + | for (Agent index : agentArray){ | ||
| + | agentName = index.getName(); | ||
| + | total++; | ||
| + | print("[INFO] Attempting to configure " + agentName + " in " + environment.getName()); | ||
| + | |||
| + | if (environment.containsServer(index)){ | ||
| + | print("[WARN] Agent " + agentName + " already in environment " + environment.getName() + "!!! Skipping. . ."); | ||
| + | warnings++; | ||
| + | } | ||
| + | |||
| + | else{ | ||
| + | environment.addServer(index); | ||
| + | index.setConfigured(true); | ||
| + | agentName = index.getName(); | ||
| + | print("[SUCC] Agent " + agentName + " configured successfully."); | ||
| + | subtotal++; | ||
| + | } | ||
| + | } | ||
| + | //Count successes, warnings, and total agents returned | ||
| + | print(""); | ||
| + | print("++++++++++++++++|"); | ||
| + | print(" TOTAL SUCCESS: | " + subtotal); | ||
| + | print(" TOTAL WARNING: | " + warnings); | ||
| + | print(" TOTAL AGENTS: | " + total); | ||
| + | print("++++++++++++++++|"); | ||
| + | uow.commitAndClose(); | ||
| + | //BMG | ||
| + | </pre> | ||
| + | ''Change environments on '''ALL AGENTS''''': | ||
| + | <pre>/********************************************************************************************/ | ||
| + | /* */ | ||
| + | /* CHANGEAGENTALLENVIRONMENTS.BSH */ | ||
| + | /* */ | ||
| + | /* Anthill Remoting API Script to add all agents in anthillpro to all environments */ | ||
| + | /* */ | ||
| + | /* Author: Brad M. Galla */ | ||
| + | /* Date: 02/17/2011 @ 15:06 */ | ||
| + | /* */ | ||
| + | /********************************************************************************************/ | ||
| + | /*===============================*/ | ||
| + | /* */ | ||
| + | /* IMPORTS */ | ||
| + | /* */ | ||
| + | /*===============================*/ | ||
| + | import com.urbancode.anthill3.main.client.AnthillClient; | ||
| + | import com.urbancode.anthill3.persistence.UnitOfWork; | ||
| + | import com.urbancode.anthill3.domain.servergroup.*; | ||
| + | import com.urbancode.anthill3.domain.agent.*; | ||
| + | /*===============================*/ | ||
| + | /* */ | ||
| + | /* CLIENT PARAMETERS */ | ||
| + | /* */ | ||
| + | /*===============================*/ | ||
| + | String serverHost = "localhost"; | ||
| + | int serverPort = 4567; | ||
| + | String userName = "admin"; | ||
| + | String password = "admin"; | ||
| + | /*===============================*/ | ||
| + | /* */ | ||
| + | /* CLIENT CONNECTION */ | ||
| + | /* */ | ||
| + | /*===============================*/ | ||
| + | AnthillClient anthill = AnthillClient.connect(serverHost, serverPort,userName, password); | ||
| + | UnitOfWork uow = anthill.createUnitOfWork(); | ||
| + | print("\n"); | ||
| + | print("==========================="); | ||
| + | print(" AGENT CONFIG DEBUG SCREEN"); | ||
| + | print("==========================="); | ||
| + | /*===============================*/ | ||
| + | /* */ | ||
| + | /* SCRIPT */ | ||
| + | /* */ | ||
| + | /*===============================*/ | ||
| + | ServerGroupFactory servergroupfactory = ServerGroupFactory.getInstance(); | ||
| + | ServerGroup[] environments = servergroupfactory.restoreAll(); | ||
| + | AgentFactory agentfactory = AgentFactory.getInstance(); | ||
| + | Agent[] agentArray = agentfactory.restoreAllNotIgnored(); | ||
| + | String agentName; | ||
| + | int subtotal=0; | ||
| + | int total=0; | ||
| + | int warnings=0; | ||
| + | int environmentcount=0; | ||
| + | for(ServerGroup environmentindex : environments) | ||
| + | { | ||
| + | print(""); | ||
| + | print("********************************************************"); | ||
| + | print(" CONFIGURING: " + environmentindex.getName()); | ||
| + | print("********************************************************"); | ||
| + | for (Agent index : agentArray) | ||
| + | { | ||
| + | agentName = index.getName(); | ||
| + | total++; | ||
| + | print("[INFO] Configuring " + agentName); | ||
| + | |||
| + | if (environmentindex.containsServer(index)) | ||
| + | { | ||
| + | print("[WARN] Configuring " + agentName + " failed...already exists!"); | ||
| + | warnings++; | ||
| + | } | ||
| + | |||
| + | else | ||
| + | { | ||
| + | environmentindex.addServer(index); | ||
| + | index.setConfigured(true); | ||
| + | agentName = index.getName(); | ||
| + | print("[SUCC] Configuring " + agentName + " was successful."); | ||
| + | subtotal++; | ||
| + | } | ||
| + | } | ||
| + | environmentcount++; | ||
| + | } | ||
| + | //Count successes, warnings, and total agents returned | ||
| + | print(""); | ||
| + | print("+++++++++++++++++++++| "); | ||
| + | print(" TOTAL SUCCESSES: | " + subtotal); | ||
| + | print(" TOTAL WARNINGS: | " + warnings); | ||
| + | print(" TOTAL AGENTS: | " + total/environmentcount); | ||
| + | print(" TOTAL ENVIRONMENTS: | " + environmentcount); | ||
| + | print("+++++++++++++++++++++| "); | ||
| + | uow.commitAndClose(); | ||
| + | //BMG | ||
| + | </pre> | ||