Skip to content
Permalink
Browse files
Added Windows agents filter for builds triggering on TeamCity. Fixes #…
…184

Signed-off-by: Slava Koptilin <slava.koptilin@gmail.com>
  • Loading branch information
sergeyuttsel authored and sk0x50 committed Jul 1, 2021
1 parent 2759b12 commit 85a50062ad11bfdd9dea4b444c8b27c0ba6d0629
Showing 1 changed file with 37 additions and 1 deletion.
@@ -47,6 +47,7 @@
import org.apache.ignite.tcbot.persistence.IStringCompactor;
import org.apache.ignite.tcignited.ITeamcityIgnited;
import org.apache.ignite.tcignited.ITeamcityIgnitedProvider;
import org.apache.ignite.tcservice.model.Property;
import org.apache.ignite.tcservice.model.agent.Agent;
import org.apache.ignite.tcservice.model.result.Build;
import org.apache.ignite.tcservice.model.result.Triggered;
@@ -70,6 +71,10 @@ public class CheckQueueJob implements Runnable {
private static final int CHECK_QUEUE_MIN_FREE_AGENTS_PERCENT =
Integer.getInteger("CHECK_QUEUE_MIN_FREE_AGENTS_PERCENT", 15);

/** Percentage of free windows agents required to trigger build. */
private static final int CHECK_QUEUE_MIN_FREE_WINDOWS_AGENTS_PERCENT =
Integer.getInteger("CHECK_QUEUE_MIN_FREE_WINDOWS_AGENTS_PERCENT", 1);

/** */
private ITcBotUserCreds creds;

@@ -192,16 +197,35 @@ protected String checkQueue(String srvCode, List<ITrackedChain> chains) {
List<Agent> agents = tcIgn.agents(true, true);

int total = agents.size();
int winAgents = 0;
int running = 0;
int winRunning = 0;

for (Agent agent : agents) {
//filter for windows agents
if (agent.getPool().getName().contains("Default") &&
agent.isEnabled() &&
agent.getProperties().getProperty().stream()
.filter(prop -> prop.getName().equals("teamcity.agent.jvm.os.name")).findAny().orElseGet(() -> {
Property emptyProp = new Property();

emptyProp.setValue("");

return emptyProp;
}).getValue().contains("Windows")) {
winAgents++;

if (agent.getBuild() != null)
winRunning++;
}

if (agent.getBuild() != null) // || !STATE_RUNNING.equals(agent.getFatBuild().status)
++running;
}

int free = total == 0 ? -1 : (total - running) * 100 / total;

final String agentStatus = MessageFormat.format("{0}% of agents are free ({1} total, {2} running builds).", free, total, running);
String agentStatus = MessageFormat.format("{0}% of agents are free ({1} total, {2} running builds).", free, total, running);

logger.info(agentStatus);

@@ -211,6 +235,18 @@ protected String checkQueue(String srvCode, List<ITrackedChain> chains) {
logger.info("There are more than {}% free agents (total={}, free={}).", CHECK_QUEUE_MIN_FREE_AGENTS_PERCENT,
total, total - running);

int winFree = winAgents == 0 ? -1 : (winAgents - winRunning) * 100 / winAgents;

agentStatus = MessageFormat.format("{0}% of Windows agents are free ({1} total, {2} running builds).", winFree, winAgents, winRunning);

logger.info(agentStatus);

if (winAgents > 0 && winFree < CHECK_QUEUE_MIN_FREE_WINDOWS_AGENTS_PERCENT)
return "Min agent percent of free Windows agents not met:" + agentStatus;

logger.info("There are more than {}% free Windows agents (total={}, free={}).", CHECK_QUEUE_MIN_FREE_WINDOWS_AGENTS_PERCENT,
winAgents, winAgents - winRunning);

String selfLogin = creds.getUser(srvCode);

tcIgn.actualizeRecentBuildRefs();

0 comments on commit 85a5006

Please sign in to comment.