Search in sources :

Example 1 with Agent

use of jetbrains.buildServer.server.rest.model.agent.Agent in project teamcity-rest by JetBrains.

the class BuildTest method testBuildOnAgentTriggering.

@Test
public void testBuildOnAgentTriggering() {
    myFixture.addService(new AgentRestrictorFactoryImpl());
    final MockBuildAgent agent2 = myFixture.createEnabledAgent("agent2", "Ant");
    final Build build = new Build();
    final BuildType buildType = new BuildType();
    buildType.setId(myBuildType.getExternalId());
    build.setBuildType(buildType);
    final Agent submittedAgent = new Agent();
    submittedAgent.id = agent2.getId();
    build.setAgent(submittedAgent);
    final SUser triggeringUser = getOrCreateUser("user");
    final SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
    assertEquals(Integer.valueOf(agent2.getId()), queuedBuild.getBuildAgentId());
}
Also used : Agent(jetbrains.buildServer.server.rest.model.agent.Agent) Build(jetbrains.buildServer.server.rest.model.build.Build) SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 2 with Agent

use of jetbrains.buildServer.server.rest.model.agent.Agent in project teamcity-rest by JetBrains.

the class BuildTest method testBuildOnCloudAgentTriggering.

@Test
public void testBuildOnCloudAgentTriggering() throws NoSuchAgentPoolException, AgentPoolCannotBeRenamedException, PoolQuotaExceededException {
    int cloudAgentTypeId = myFixture.getAgentTypeManager().getOrCreateAgentTypeId(new AgentTypeKey("Cloud", "Profile", "Image"));
    final SUser triggeringUser = getOrCreateUser("user");
    {
        final Build build = new Build();
        final BuildType buildType = new BuildType();
        buildType.setId(myBuildType.getExternalId());
        build.setBuildType(buildType);
        Agent submittedAgent = new Agent();
        submittedAgent.typeId = cloudAgentTypeId;
        build.setAgent(submittedAgent);
        SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
        assertNotNull(queuedBuild.getAgentRestrictor());
        assertEquals(AgentRestrictorType.CLOUD_IMAGE, queuedBuild.getAgentRestrictor().getType());
        assertEquals(cloudAgentTypeId, queuedBuild.getAgentRestrictor().getId());
    }
    {
        final Build build = new Build();
        final BuildType buildType = new BuildType();
        buildType.setId(myBuildType.getExternalId());
        build.setBuildType(buildType);
        final MockBuildAgent agent2 = myFixture.createEnabledAgent("agent2", "Ant");
        Agent submittedAgent = new Agent();
        submittedAgent.locator = "id:" + agent2.getId();
        submittedAgent.typeId = cloudAgentTypeId;
        build.setAgent(submittedAgent);
        SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
        assertNotNull(queuedBuild.getAgentRestrictor());
        assertEquals(AgentRestrictorType.SINGLE_AGENT, queuedBuild.getAgentRestrictor().getType());
        assertEquals(agent2.getId(), queuedBuild.getAgentRestrictor().getId());
    }
    {
        final Build build = new Build();
        final BuildType buildType = new BuildType();
        buildType.setId(myBuildType.getExternalId());
        build.setBuildType(buildType);
        Agent submittedAgent = new Agent();
        submittedAgent.typeId = cloudAgentTypeId + 10;
        build.setAgent(submittedAgent);
        checkException(NotFoundException.class, () -> build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>()), "triggering build on not existent agent type");
    }
}
Also used : Agent(jetbrains.buildServer.server.rest.model.agent.Agent) Build(jetbrains.buildServer.server.rest.model.build.Build) AgentTypeKey(jetbrains.buildServer.serverSide.agentTypes.AgentTypeKey) SUser(jetbrains.buildServer.users.SUser) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 3 with Agent

use of jetbrains.buildServer.server.rest.model.agent.Agent 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)

Example 4 with Agent

use of jetbrains.buildServer.server.rest.model.agent.Agent in project teamcity-rest by JetBrains.

the class Build method getPlannedAgent.

@XmlElement(name = "plannedAgent")
public Agent getPlannedAgent() {
    return ValueWithDefault.decideDefault(myFields.isIncluded("plannedAgent", false, false), () -> {
        if (myQueuedBuild == null || myQueuedBuild.getBuildPromotion().isCompositeBuild()) {
            return null;
        }
        BuildEstimates estimates = myQueuedBuild.getBuildEstimates();
        if (estimates == null) {
            return null;
        }
        BuildAgent agent = estimates.getAgent();
        if (agent == null || !(agent instanceof SBuildAgent)) {
            return null;
        }
        return new Agent((SBuildAgent) agent, myFields.getNestedField("plannedAgent"), myBeanContext);
    });
}
Also used : Agent(jetbrains.buildServer.server.rest.model.agent.Agent) BuildAgent(jetbrains.buildServer.BuildAgent) BuildAgent(jetbrains.buildServer.BuildAgent) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 5 with Agent

use of jetbrains.buildServer.server.rest.model.agent.Agent in project teamcity-rest by JetBrains.

the class BuildTest method testBuildOnAgentPoolTriggering.

@Test
public void testBuildOnAgentPoolTriggering() throws Exception {
    final MockBuildAgent agent2 = myFixture.createEnabledAgent("agent2", "Ant");
    final int poolId1 = myFixture.getAgentPoolManager().createNewAgentPool("pool1").getAgentPoolId();
    myFixture.getAgentPoolManager().moveAgentTypesToPool(poolId1, createSet(agent2.getId()));
    final Build build = new Build();
    final BuildType buildType = new BuildType();
    buildType.setId(myBuildType.getExternalId());
    build.setBuildType(buildType);
    final SUser triggeringUser = getOrCreateUser("user");
    Agent submittedAgent = new Agent();
    submittedAgent.locator = "pool:(id:" + poolId1 + ")";
    build.setAgent(submittedAgent);
    SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
    assertNotNull(queuedBuild.getAgentRestrictor());
    assertEquals(AgentRestrictorType.SINGLE_AGENT, queuedBuild.getAgentRestrictor().getType());
    assertEquals(agent2.getId(), queuedBuild.getAgentRestrictor().getId());
    submittedAgent = new Agent();
    submittedAgent.pool = new AgentPool();
    submittedAgent.pool.id = poolId1;
    build.setAgent(submittedAgent);
    queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
    assertNotNull(queuedBuild.getAgentRestrictor());
    assertEquals(AgentRestrictorType.AGENT_POOL, queuedBuild.getAgentRestrictor().getType());
    assertEquals(poolId1, queuedBuild.getAgentRestrictor().getId());
    submittedAgent = new Agent();
    submittedAgent.pool = new AgentPool();
    submittedAgent.pool.locator = "id:" + poolId1;
    build.setAgent(submittedAgent);
    queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
    assertNotNull(queuedBuild.getAgentRestrictor());
    assertEquals(AgentRestrictorType.AGENT_POOL, queuedBuild.getAgentRestrictor().getType());
    assertEquals(poolId1, queuedBuild.getAgentRestrictor().getId());
}
Also used : Agent(jetbrains.buildServer.server.rest.model.agent.Agent) Build(jetbrains.buildServer.server.rest.model.build.Build) SUser(jetbrains.buildServer.users.SUser) AgentPool(jetbrains.buildServer.server.rest.model.agent.AgentPool) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Aggregations

Agent (jetbrains.buildServer.server.rest.model.agent.Agent)9 Build (jetbrains.buildServer.server.rest.model.build.Build)5 SUser (jetbrains.buildServer.users.SUser)5 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)3 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)3 Logger (com.intellij.openapi.diagnostic.Logger)2 java.util (java.util)2 Pattern (java.util.regex.Pattern)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 XmlElement (javax.xml.bind.annotation.XmlElement)2 BuildAgent (jetbrains.buildServer.BuildAgent)2 ServiceLocator (jetbrains.buildServer.ServiceLocator)2 ErrorData (jetbrains.buildServer.messages.ErrorData)2 ParametersProvider (jetbrains.buildServer.parameters.ParametersProvider)2 AbstractMapParametersProvider (jetbrains.buildServer.parameters.impl.AbstractMapParametersProvider)2 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)2 TagFinder (jetbrains.buildServer.server.rest.data.build.TagFinder)2 TestFinder (jetbrains.buildServer.server.rest.data.problem.TestFinder)2