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());
}
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);
}
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);
}
Aggregations