Search in sources :

Example 1 with SAgentType

use of jetbrains.buildServer.serverSide.agentTypes.SAgentType 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 2 with SAgentType

use of jetbrains.buildServer.serverSide.agentTypes.SAgentType 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;
    });
}
Also used : Agent(jetbrains.buildServer.server.rest.model.agent.Agent) BuildAgent(jetbrains.buildServer.BuildAgent) SAgentType(jetbrains.buildServer.serverSide.agentTypes.SAgentType) AgentTypeFinder(jetbrains.buildServer.serverSide.agentTypes.AgentTypeFinder) AgentRestrictor(jetbrains.buildServer.AgentRestrictor) AgentPool(jetbrains.buildServer.serverSide.agentPools.AgentPool) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 3 with SAgentType

use of jetbrains.buildServer.serverSide.agentTypes.SAgentType in project teamcity-rest by JetBrains.

the class AgentFinder method getAgentType.

public static SAgentType getAgentType(@NotNull final String agentTypeLocator, @NotNull final AgentTypeFinder agentTypeFinder) {
    // support only int single value for now
    Integer agentTypeId = null;
    try {
        agentTypeId = Integer.valueOf(agentTypeLocator);
    } catch (NumberFormatException e) {
        throw new BadRequestException("Bad agent type id '" + agentTypeLocator + "': should be a number");
    }
    // make AgentFinder finding agent types in the future
    SAgentType agentType = agentTypeFinder.findAgentType(agentTypeId);
    if (agentType == null) {
        throw new NotFoundException("No agent type is found by id '" + agentTypeId + "'");
    }
    return agentType;
}
Also used : SAgentType(jetbrains.buildServer.serverSide.agentTypes.SAgentType) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException)

Aggregations

SAgentType (jetbrains.buildServer.serverSide.agentTypes.SAgentType)3 Pair (com.intellij.openapi.util.Pair)1 ArrayList (java.util.ArrayList)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 AgentRestrictor (jetbrains.buildServer.AgentRestrictor)1 BuildAgent (jetbrains.buildServer.BuildAgent)1 CloudClientEx (jetbrains.buildServer.clouds.CloudClientEx)1 CloudImage (jetbrains.buildServer.clouds.CloudImage)1 CloudProfile (jetbrains.buildServer.clouds.CloudProfile)1 AgentPoolCloudImagesConnection (jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolCloudImagesConnection)1 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 Agent (jetbrains.buildServer.server.rest.model.agent.Agent)1 AgentPool (jetbrains.buildServer.serverSide.agentPools.AgentPool)1 AgentTypeFinder (jetbrains.buildServer.serverSide.agentTypes.AgentTypeFinder)1 AgentTypeKey (jetbrains.buildServer.serverSide.agentTypes.AgentTypeKey)1 NotNull (org.jetbrains.annotations.NotNull)1