use of jetbrains.buildServer.serverSide.agentTypes.AgentType in project teamcity-rest by JetBrains.
the class CloudImageResolver method agentPool.
@NotNull
public DataFetcherResult<AbstractAgentPool> agentPool(@NotNull CloudImage image, @NotNull DataFetchingEnvironment env) {
DataFetcherResult.Builder<AbstractAgentPool> result = new DataFetcherResult.Builder<>();
AgentType agentType = findAgentType(image);
AgentPool pool = agentType != null ? myAgentPoolManager.findAgentPoolById(agentType.getAgentPoolId()) : null;
if (agentType == null || pool == null) {
result.error(new EntityNotFoundGraphQLError(String.format("Could not find agent pool for image id=%s in profile id=%s", image.getRawId(), image.getProfileId())));
return result.build();
}
return result.data(new ProjectAgentPool(pool)).localContext(pool).build();
}
use of jetbrains.buildServer.serverSide.agentTypes.AgentType 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());
}
use of jetbrains.buildServer.serverSide.agentTypes.AgentType in project teamcity-rest by JetBrains.
the class CloudImageResolver method agentTypeRawId.
@NotNull
public DataFetcherResult<Integer> agentTypeRawId(@NotNull CloudImage image, @NotNull DataFetchingEnvironment env) {
DataFetcherResult.Builder<Integer> result = DataFetcherResult.newResult();
AgentType agentType = findAgentType(image);
if (agentType == null) {
return result.error(new EntityNotFoundGraphQLError(String.format("Agent type for image id=%s is no found.", image.getRawId()))).build();
}
return result.data(agentType.getAgentTypeId()).build();
}
Aggregations