Search in sources :

Example 1 with CloudImage

use of jetbrains.buildServer.clouds.CloudImage in project teamcity-rest by JetBrains.

the class CloudInstanceData method getAgent.

@Nullable
public SBuildAgent getAgent() {
    CloudImage image = myInstance.getImage();
    String profileId = myServiceLocator.getSingletonService(CloudInstanceFinder.class).myCloudUtil.getProfileId(image);
    if (profileId == null)
        return null;
    Collection<SBuildAgent> agents = myServiceLocator.getSingletonService(CloudManager.class).findAgentByInstance(profileId, myInstance.getInstanceId());
    return agents.size() > 0 ? agents.iterator().next() : null;
}
Also used : CloudManager(jetbrains.buildServer.clouds.server.CloudManager) CloudImage(jetbrains.buildServer.clouds.CloudImage) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with CloudImage

use of jetbrains.buildServer.clouds.CloudImage 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());
}
Also used : CloudProfile(jetbrains.buildServer.clouds.CloudProfile) SAgentType(jetbrains.buildServer.serverSide.agentTypes.SAgentType) CloudClientEx(jetbrains.buildServer.clouds.CloudClientEx) AgentPoolCloudImagesConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolCloudImagesConnection) AgentTypeKey(jetbrains.buildServer.serverSide.agentTypes.AgentTypeKey) ArrayList(java.util.ArrayList) CloudImage(jetbrains.buildServer.clouds.CloudImage) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CloudImage

use of jetbrains.buildServer.clouds.CloudImage 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());
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) CloudClientEx(jetbrains.buildServer.clouds.CloudClientEx) AgentTypeManager(jetbrains.buildServer.serverSide.agentTypes.AgentTypeManager) CloudProfile(jetbrains.buildServer.clouds.CloudProfile) AgentPool(jetbrains.buildServer.server.graphql.model.agentPool.AgentPool) AuthorityHolder(jetbrains.buildServer.serverSide.auth.AuthorityHolder) AgentPoolProjectsConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolProjectsConnection) PaginationArguments(jetbrains.buildServer.server.graphql.model.connections.PaginationArguments) ArrayList(java.util.ArrayList) AgentType(jetbrains.buildServer.serverSide.agentTypes.AgentType) CloudImage(jetbrains.buildServer.clouds.CloudImage) AgentTypeKey(jetbrains.buildServer.serverSide.agentTypes.AgentTypeKey) SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) AgentPoolAgentsConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolAgentsConnection) ProjectsConnection(jetbrains.buildServer.server.graphql.model.connections.ProjectsConnection) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) Set(java.util.Set) AgentPoolPermissions(jetbrains.buildServer.server.graphql.model.agentPool.AgentPoolPermissions) ModelResolver(jetbrains.buildServer.server.graphql.util.ModelResolver) Collectors(java.util.stream.Collectors) CloudManagerBase(jetbrains.buildServer.clouds.server.CloudManagerBase) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Component(org.springframework.stereotype.Component) ProjectsFilter(jetbrains.buildServer.server.graphql.model.filter.ProjectsFilter) Permission(jetbrains.buildServer.serverSide.auth.Permission) jetbrains.buildServer.server.graphql.model.agentPool.actions(jetbrains.buildServer.server.graphql.model.agentPool.actions) AgentPoolCloudImagesConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolCloudImagesConnection) Pair(com.intellij.openapi.util.Pair) AuthUtil(jetbrains.buildServer.serverSide.auth.AuthUtil) CloudConstants(jetbrains.buildServer.clouds.CloudConstants) AgentPoolManager(jetbrains.buildServer.serverSide.agentPools.AgentPoolManager) NotNull(org.jetbrains.annotations.NotNull) BuildProject(jetbrains.buildServer.BuildProject) CloudProfile(jetbrains.buildServer.clouds.CloudProfile) CloudClientEx(jetbrains.buildServer.clouds.CloudClientEx) AgentTypeKey(jetbrains.buildServer.serverSide.agentTypes.AgentTypeKey) ArrayList(java.util.ArrayList) AgentType(jetbrains.buildServer.serverSide.agentTypes.AgentType) AgentPoolCloudImagesConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolCloudImagesConnection) AuthorityHolder(jetbrains.buildServer.serverSide.auth.AuthorityHolder) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CloudImage (jetbrains.buildServer.clouds.CloudImage)3 Pair (com.intellij.openapi.util.Pair)2 ArrayList (java.util.ArrayList)2 CloudClientEx (jetbrains.buildServer.clouds.CloudClientEx)2 CloudProfile (jetbrains.buildServer.clouds.CloudProfile)2 AgentPoolCloudImagesConnection (jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolCloudImagesConnection)2 AgentTypeKey (jetbrains.buildServer.serverSide.agentTypes.AgentTypeKey)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 BuildProject (jetbrains.buildServer.BuildProject)1 CloudConstants (jetbrains.buildServer.clouds.CloudConstants)1 CloudManager (jetbrains.buildServer.clouds.server.CloudManager)1 CloudManagerBase (jetbrains.buildServer.clouds.server.CloudManagerBase)1 AgentPool (jetbrains.buildServer.server.graphql.model.agentPool.AgentPool)1 AgentPoolPermissions (jetbrains.buildServer.server.graphql.model.agentPool.AgentPoolPermissions)1 jetbrains.buildServer.server.graphql.model.agentPool.actions (jetbrains.buildServer.server.graphql.model.agentPool.actions)1