Search in sources :

Example 1 with AgentPool

use of jetbrains.buildServer.server.graphql.model.agentPool.AgentPool in project teamcity-rest by JetBrains.

the class AbstractAgentPoolResolverTest method basicProjectsConnection.

public void basicProjectsConnection() throws Throwable {
    jetbrains.buildServer.serverSide.agentPools.AgentPool realPool = myFixture.getAgentPoolManager().createNewAgentPool("testAgentPool");
    Set<String> allProjectIds = new HashSet<>();
    Set<String> visibleProjectNames = new HashSet<>();
    MockAuthorityHolder mockUser = new MockAuthorityHolder();
    Permissions viewProjectPermissions = new Permissions(Permission.VIEW_PROJECT);
    for (int i = 0; i < 5; i++) {
        ProjectEx project = createProject("visibleProject" + i);
        mockUser.projectPerms.put(project.getProjectId(), viewProjectPermissions);
        allProjectIds.add(project.getProjectId());
        visibleProjectNames.add(project.getName());
    }
    List<ProjectEx> invisibleProjects = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        ProjectEx project = createProject("invisibleProject" + i);
        allProjectIds.add(project.getProjectId());
        invisibleProjects.add(project);
    }
    myFixture.getAgentPoolManager().associateProjectsWithPool(realPool.getAgentPoolId(), allProjectIds);
    Mock fieldSelectionSetMock = mock(DataFetchingFieldSelectionSet.class);
    fieldSelectionSetMock.stubs().method("contains").with(eq("excludedCount")).will(returnValue(true));
    myDataFetchingEnvironment.setSelectionSet((DataFetchingFieldSelectionSet) fieldSelectionSetMock.proxy());
    AgentPoolProjectsConnection connection = myFixture.getSecurityContext().runAs(mockUser, () -> myResolver.projects(new AgentPool(realPool), new ProjectsFilter(), myDataFetchingEnvironment));
    connection.getEdges().getData().forEach(edge -> {
        String name = edge.getNode().getData().getName();
        assertTrue("Project '" + name + "' is visible, but shouldn't be.", visibleProjectNames.contains(name));
    });
    assertEquals(visibleProjectNames.size(), connection.getCount());
    assertEquals(new Integer(invisibleProjects.size()), connection.getExcludedCount());
}
Also used : ProjectsFilter(jetbrains.buildServer.server.graphql.model.filter.ProjectsFilter) AgentPoolProjectsConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolProjectsConnection) AgentPool(jetbrains.buildServer.server.graphql.model.agentPool.AgentPool) Mock(org.jmock.Mock) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Permissions(jetbrains.buildServer.serverSide.auth.Permissions) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) MockAuthorityHolder(jetbrains.buildServer.serverSide.impl.MockAuthorityHolder)

Example 2 with AgentPool

use of jetbrains.buildServer.server.graphql.model.agentPool.AgentPool in project teamcity-rest by JetBrains.

the class AbstractAgentPoolResolverTest method basicAgentsConnection.

public void basicAgentsConnection() throws AgentPoolCannotBeRenamedException, NoSuchAgentPoolException, AgentTypeCannotBeMovedException, PoolQuotaExceededException {
    AgentPoolManager manager = myFixture.getAgentPoolManager();
    jetbrains.buildServer.serverSide.agentPools.AgentPool evenAgents = manager.createNewAgentPool("evenAgents");
    jetbrains.buildServer.serverSide.agentPools.AgentPool oddAgents = manager.createNewAgentPool("oddAgents");
    final int num = 2;
    for (int i = 0; i < num * 2; i++) {
        MockBuildAgent agent = myFixture.createEnabledAgent("agent_" + i);
        registerAndEnableAgent(agent);
        manager.moveAgentToPool((i % 2 == 0) ? evenAgents.getAgentPoolId() : oddAgents.getAgentPoolId(), agent);
    }
    AgentPoolAgentsConnection evenConnection = myResolver.agents(new AgentPool(evenAgents), myDataFetchingEnvironment);
    assertEquals(num, evenConnection.getCount());
    for (AgentPoolAgentsConnection.AgentPoolAgentsConnectionEdge edge : evenConnection.getEdges().getData()) {
        assertEquals(evenAgents.getAgentPoolId(), edge.getNode().getData().getRealAgent().getAgentPoolId());
    }
    AgentPoolAgentsConnection oddConnection = myResolver.agents(new AgentPool(oddAgents), myDataFetchingEnvironment);
    assertEquals(num, oddConnection.getCount());
    for (AgentPoolAgentsConnection.AgentPoolAgentsConnectionEdge edge : oddConnection.getEdges().getData()) {
        assertEquals(oddAgents.getAgentPoolId(), edge.getNode().getData().getRealAgent().getAgentPoolId());
    }
}
Also used : AgentPoolAgentsConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolAgentsConnection) MockBuildAgent(jetbrains.buildServer.serverSide.impl.MockBuildAgent) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) AgentPool(jetbrains.buildServer.server.graphql.model.agentPool.AgentPool)

Example 3 with AgentPool

use of jetbrains.buildServer.server.graphql.model.agentPool.AgentPool 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

AgentPool (jetbrains.buildServer.server.graphql.model.agentPool.AgentPool)3 AgentPoolAgentsConnection (jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolAgentsConnection)2 AgentPoolProjectsConnection (jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolProjectsConnection)2 ProjectsFilter (jetbrains.buildServer.server.graphql.model.filter.ProjectsFilter)2 jetbrains.buildServer.serverSide.agentPools (jetbrains.buildServer.serverSide.agentPools)2 Pair (com.intellij.openapi.util.Pair)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 BuildProject (jetbrains.buildServer.BuildProject)1 CloudClientEx (jetbrains.buildServer.clouds.CloudClientEx)1 CloudConstants (jetbrains.buildServer.clouds.CloudConstants)1 CloudImage (jetbrains.buildServer.clouds.CloudImage)1 CloudProfile (jetbrains.buildServer.clouds.CloudProfile)1 CloudManagerBase (jetbrains.buildServer.clouds.server.CloudManagerBase)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 PaginationArguments (jetbrains.buildServer.server.graphql.model.connections.PaginationArguments)1