use of jetbrains.buildServer.serverSide.agentTypes.AgentTypeKey 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.serverSide.agentTypes.AgentTypeKey in project teamcity-rest by JetBrains.
the class AbstractAgentPoolResolver method cloudImages.
@NotNull
public AgentPoolCloudImagesConnection cloudImages(@NotNull AbstractAgentPool pool, @NotNull DataFetchingEnvironment env) {
List<Pair<CloudProfile, CloudImage>> images = new ArrayList<>();
for (SAgentType agentType : myAgentTypeFinder.getAgentTypesByPool(pool.getRealPool().getAgentPoolId())) {
if (!agentType.isCloud())
continue;
AgentTypeKey targetAgentTypeKey = agentType.getAgentTypeKey();
CloudProfile profile = myCloudManager.findProfileGloballyById(targetAgentTypeKey.getProfileId());
if (profile == null)
continue;
CloudClientEx client = myCloudManager.getClient(profile.getProjectId(), profile.getProfileId());
for (CloudImage image : client.getImages()) {
SAgentType type = myCloudManager.getDescriptionFor(profile, image.getId());
if (type == null)
continue;
if (targetAgentTypeKey.equals(type.getAgentTypeKey())) {
images.add(new Pair<>(profile, image));
break;
}
}
}
return new AgentPoolCloudImagesConnection(images, PaginationArguments.everything());
}
use of jetbrains.buildServer.serverSide.agentTypes.AgentTypeKey in project teamcity-rest by JetBrains.
the class AgentPoolResolver method assignableCloudImages.
@NotNull
public AgentPoolCloudImagesConnection assignableCloudImages(@NotNull AgentPool pool, @NotNull DataFetchingEnvironment env) {
AuthorityHolder authHolder = mySecurityContext.getAuthorityHolder();
jetbrains.buildServer.serverSide.agentPools.AgentPool defaultPool = myPoolManager.findAgentPoolById(jetbrains.buildServer.serverSide.agentPools.AgentPool.DEFAULT_POOL_ID);
if (!AuthUtil.hasGlobalOrPoolProjectsPermission(authHolder, defaultPool, Permission.MANAGE_AGENT_POOLS, Permission.MANAGE_AGENT_POOLS_FOR_PROJECT)) {
return AgentPoolCloudImagesConnection.empty();
}
if (!myPoolActionsAccessChecker.canManageAgentsInPool(pool.getRealPool())) {
return AgentPoolCloudImagesConnection.empty();
}
final Set<String> profileIdsInRootProject = myProjectManager.getRootProject().getOwnFeaturesOfType(CloudConstants.CLOUD_PROFILE_FEATURE_TYPE).stream().map(SProjectFeatureDescriptor::getId).collect(Collectors.toSet());
List<Pair<CloudProfile, CloudImage>> images = new ArrayList<>();
profileIdsInRootProject.forEach(profileId -> {
CloudClientEx client = myCloudManager.getClientIfExists(BuildProject.ROOT_PROJECT_ID, profileId);
CloudProfile profile = myCloudManager.findProfileById(BuildProject.ROOT_PROJECT_ID, profileId);
if (client == null || profile == null)
return;
client.getImages().stream().filter(image -> {
AgentTypeKey key = new AgentTypeKey(profile.getCloudCode(), profileId, image.getId());
AgentType type = myAgentTypeManager.findAgentTypeByKey(key);
return type != null && pool.getRealPool().getAgentPoolId() != type.getAgentPoolId();
}).forEach(image -> {
images.add(new Pair<>(profile, image));
});
});
return new AgentPoolCloudImagesConnection(images, PaginationArguments.everything());
}
Aggregations