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