Search in sources :

Example 1 with AgentPool

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

Example 2 with AgentPool

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

the class AgentPoolRequest method createPool.

@POST
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Create a new agent pool.", nickname = "createAgentPool")
public AgentPool createPool(AgentPool agentPool) {
    if (agentPool.agents != null) {
        throw new BadRequestException("Creating an agent pool with agents is not supported. Please add agents after the pool creation");
    }
    final jetbrains.buildServer.serverSide.agentPools.AgentPool newAgentPool;
    try {
        AgentPoolLimits agentDetails = AgentPoolLimits.DEFAULT;
        if (agentPool.maxAgents != null) {
            agentDetails = new AgentPoolLimitsImpl(AgentPoolLimits.DEFAULT.getMinAgents(), agentPool.maxAgents != null ? Integer.valueOf(agentPool.maxAgents) : AgentPoolLimits.DEFAULT.getMaxAgents());
        }
        newAgentPool = myServiceLocator.getSingletonService(AgentPoolManager.class).createNewAgentPool(agentPool.name, agentDetails);
    } catch (AgentPoolCannotBeRenamedException e) {
        throw new BadRequestException("Agent pool with name \'" + agentPool.name + "' already exists.");
    }
    if (agentPool.projects != null) {
        replaceProjects("id:" + newAgentPool, agentPool.projects);
    }
    return new AgentPool(newAgentPool, Fields.LONG, myBeanContext);
}
Also used : BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) AgentPool(jetbrains.buildServer.server.rest.model.agent.AgentPool) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with AgentPool

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

the class ProjectRequest method setProjectAgentPools.

@POST
@Path("/{projectLocator}/agentPools")
@Produces({ "application/xml", "application/json" })
@Consumes({ "application/xml", "application/json" })
@ApiOperation(value = "Assign the matching project to the agent pool.", nickname = "addAgentPoolsProject")
public AgentPool setProjectAgentPools(@ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, AgentPool pool) {
    SProject project = myProjectFinder.getItem(projectLocator);
    final AgentPoolManager agentPoolManager = myServiceLocator.getSingletonService(AgentPoolManager.class);
    final jetbrains.buildServer.serverSide.agentPools.AgentPool agentPoolFromPosted = pool.getAgentPoolFromPosted(myAgentPoolFinder);
    final int agentPoolId = agentPoolFromPosted.getAgentPoolId();
    try {
        agentPoolManager.associateProjectsWithPool(agentPoolId, singleton(project.getProjectId()));
    } catch (NoSuchAgentPoolException e) {
        throw new BadRequestException("Agent pool with id \'" + agentPoolId + "' is not found.");
    }
    return new AgentPool(agentPoolFromPosted, Fields.LONG, myBeanContext);
}
Also used : NoSuchAgentPoolException(jetbrains.buildServer.serverSide.agentPools.NoSuchAgentPoolException) AgentPoolManager(jetbrains.buildServer.serverSide.agentPools.AgentPoolManager) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) AgentPool(jetbrains.buildServer.server.rest.model.agent.AgentPool) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

AgentPool (jetbrains.buildServer.server.rest.model.agent.AgentPool)3 ApiOperation (io.swagger.annotations.ApiOperation)2 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)2 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)1 Agent (jetbrains.buildServer.server.rest.model.agent.Agent)1 Build (jetbrains.buildServer.server.rest.model.build.Build)1 jetbrains.buildServer.serverSide.agentPools (jetbrains.buildServer.serverSide.agentPools)1 AgentPoolManager (jetbrains.buildServer.serverSide.agentPools.AgentPoolManager)1 NoSuchAgentPoolException (jetbrains.buildServer.serverSide.agentPools.NoSuchAgentPoolException)1 SUser (jetbrains.buildServer.users.SUser)1 Test (org.testng.annotations.Test)1