Search in sources :

Example 1 with AgentRestrictor

use of jetbrains.buildServer.AgentRestrictor in project teamcity-rest by JetBrains.

the class Build method getAgent.

@XmlElement(name = "agent")
public Agent getAgent() {
    return ValueWithDefault.decideDefault(myFields.isIncluded("agent", false), () -> {
        if (myBuild != null) {
            if (myBuild.isAgentLessBuild())
                return null;
            SBuildAgent agent = myBuild.getAgent();
            return new Agent(agent, myFields.getNestedField("agent"), myBeanContext);
        }
        if (myQueuedBuild != null) {
            final AgentRestrictor agentRestrictor = myQueuedBuild.getAgentRestrictor();
            if (agentRestrictor != null) {
                if (agentRestrictor.getType() == AgentRestrictorType.SINGLE_AGENT) {
                    SBuildAgent agent = myQueuedBuild.getBuildAgent();
                    if (agent != null) {
                        return new Agent(agent, myFields.getNestedField("agent"), myBeanContext);
                    }
                }
                if (agentRestrictor.getType() == AgentRestrictorType.AGENT_POOL) {
                    final int agentPoolId = agentRestrictor.getId();
                    final AgentPool agentPool = myBeanContext.getSingletonService(AgentPoolFinder.class).getAgentPoolById(agentPoolId);
                    return new Agent(agentPool, myFields.getNestedField("agent"), myBeanContext);
                }
                if (agentRestrictor.getType() == AgentRestrictorType.CLOUD_IMAGE) {
                    final int agentTypeId = agentRestrictor.getId();
                    final SAgentType agentType = AgentFinder.getAgentType(String.valueOf(agentTypeId), myBeanContext.getSingletonService(AgentTypeFinder.class));
                    return new Agent(agentType, myFields.getNestedField("agent"), myBeanContext);
                }
            }
        }
        return null;
    });
}
Also used : Agent(jetbrains.buildServer.server.rest.model.agent.Agent) BuildAgent(jetbrains.buildServer.BuildAgent) SAgentType(jetbrains.buildServer.serverSide.agentTypes.SAgentType) AgentTypeFinder(jetbrains.buildServer.serverSide.agentTypes.AgentTypeFinder) AgentRestrictor(jetbrains.buildServer.AgentRestrictor) AgentPool(jetbrains.buildServer.serverSide.agentPools.AgentPool) XmlElement(javax.xml.bind.annotation.XmlElement)

Aggregations

XmlElement (javax.xml.bind.annotation.XmlElement)1 AgentRestrictor (jetbrains.buildServer.AgentRestrictor)1 BuildAgent (jetbrains.buildServer.BuildAgent)1 Agent (jetbrains.buildServer.server.rest.model.agent.Agent)1 AgentPool (jetbrains.buildServer.serverSide.agentPools.AgentPool)1 AgentTypeFinder (jetbrains.buildServer.serverSide.agentTypes.AgentTypeFinder)1 SAgentType (jetbrains.buildServer.serverSide.agentTypes.SAgentType)1