Search in sources :

Example 1 with Project

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

the class BuildTypeResolverTest method basicAncestorProjects.

public void basicAncestorProjects() throws Exception {
    ProjectEx p0 = myFixture.createProject("p0");
    ProjectEx p1 = myFixture.createProject("p1", p0);
    ProjectEx p2 = myFixture.createProject("p2", p1);
    ProjectEx p3 = myFixture.createProject("p3", p2);
    BuildTypeImpl realBuildType = myFixture.createBuildType(p3, "testBT", "test");
    ProjectsConnection ancestors = myResolver.ancestorProjects(new jetbrains.buildServer.server.graphql.model.buildType.BuildType(realBuildType), myDataFetchingEnvironment);
    // _Root, p0 .. p3
    assertEquals(5, ancestors.getCount());
    // Ancestors must be from closest to _Root
    assertExtensibleEdges(ancestors.getEdges().getData(), new Project(p3), new Project(p2), new Project(p1), new Project(p0), new Project(myFixture.getProjectManager().getRootProject()));
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Project(jetbrains.buildServer.server.graphql.model.Project) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) ProjectsConnection(jetbrains.buildServer.server.graphql.model.connections.ProjectsConnection)

Example 2 with Project

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

the class ProjectResolverTest method testBuildTypes.

@Test
public void testBuildTypes() throws Exception {
    BuildTypesConnection buildTypes = myResolver.buildTypes(new Project(mySubProject), null, null, myDataFetchingEnvironment);
    assertEquals(2, buildTypes.getCount());
    assertExtensibleEdges(buildTypes.getEdges().getData(), new BuildType(myBuildType1), new BuildType(myBuildType2));
}
Also used : Project(jetbrains.buildServer.server.graphql.model.Project) BuildTypesConnection(jetbrains.buildServer.server.graphql.model.connections.BuildTypesConnection) BuildType(jetbrains.buildServer.server.graphql.model.buildType.BuildType) Test(org.testng.annotations.Test)

Example 3 with Project

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

the class AgentPoolMutation method unassignProjectFromAgentPool.

@Used("graphql")
@NotNull
public DataFetcherResult<UnassignProjectFromAgentPoolPayload> unassignProjectFromAgentPool(@NotNull UnassignProjectFromAgentPoolInput input) {
    DataFetcherResult.Builder<UnassignProjectFromAgentPoolPayload> result = DataFetcherResult.newResult();
    SProject project = myProjectManager.findProjectByExternalId(input.getProjectRawId());
    if (project == null) {
        return result.error(new EntityNotFoundGraphQLError("Project with given id does not exist.")).build();
    }
    AuthorityHolder authorityHolder = mySecurityContext.getAuthorityHolder();
    boolean canRemoveThisProject = AuthUtil.hasPermissionToManageAgentPoolsWithProject(authorityHolder, project.getProjectId());
    boolean thereAreOtherAssociatedPools = false;
    if (canRemoveThisProject) {
        // let's count other pools iff we are sure that we can potentially remove given project.
        thereAreOtherAssociatedPools = myAgentPoolManager.getAgentPoolsWithProject(project.getProjectId()).stream().map(poolId -> myAgentPoolManager.findAgentPoolById(poolId)).filter(Objects::nonNull).filter(pool -> !pool.isProjectPool()).count() > 1;
    }
    if (!canRemoveThisProject || !thereAreOtherAssociatedPools) {
        if (!canRemoveThisProject) {
            return result.error(new OperationFailedGraphQLError("Can't unassign project, not enough permissions.")).build();
        }
        return result.error(new OperationFailedGraphQLError("Can't unassign project, there are no other pools associated with this project.")).build();
    }
    Set<String> projectsToDisassociate;
    if (input.isRecursive()) {
        projectsToDisassociate = new HashSet<>();
        projectsToDisassociate.add(project.getProjectId());
        project.getProjects().stream().map(p -> p.getProjectId()).forEach(projectsToDisassociate::add);
    } else {
        projectsToDisassociate = Collections.singleton(project.getProjectId());
    }
    try {
        myAgentPoolManager.dissociateProjectsFromPool(input.getAgentPoolRawId(), projectsToDisassociate);
    } catch (NoSuchAgentPoolException e) {
        return result.error(new EntityNotFoundGraphQLError("Agent pool with given id does not exist.")).build();
    }
    AgentPool agentPool = myAgentPoolManager.findAgentPoolById(input.getAgentPoolRawId());
    if (agentPool == null) {
        LOG.warn(String.format("Agent pool with id=%d is missing after associating project id=%s", input.getAgentPoolRawId(), project.getProjectId()));
        return result.error(new UnexpectedServerGraphQLError("Agent pool with given id could not be found after operation.")).build();
    }
    return result.data(new UnassignProjectFromAgentPoolPayload(new Project(project), new jetbrains.buildServer.server.graphql.model.agentPool.AgentPool(agentPool))).build();
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) CloudClientEx(jetbrains.buildServer.clouds.CloudClientEx) EntityNotFoundGraphQLError(jetbrains.buildServer.server.graphql.util.EntityNotFoundGraphQLError) UnexpectedServerGraphQLError(jetbrains.buildServer.server.graphql.util.UnexpectedServerGraphQLError) java.util(java.util) CloudProfile(jetbrains.buildServer.clouds.CloudProfile) AuthorityHolder(jetbrains.buildServer.serverSide.auth.AuthorityHolder) BooleanUtils(org.apache.commons.lang3.BooleanUtils) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) DataFetcherResult(graphql.execution.DataFetcherResult) jetbrains.buildServer.server.graphql.model.mutation.agentPool(jetbrains.buildServer.server.graphql.model.mutation.agentPool) SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) Logger(com.intellij.openapi.diagnostic.Logger) Project(jetbrains.buildServer.server.graphql.model.Project) Agent(jetbrains.buildServer.server.graphql.model.Agent) GraphQLMutationResolver(graphql.kickstart.tools.GraphQLMutationResolver) Used(jetbrains.buildServer.Used) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) jetbrains.buildServer.serverSide.agentTypes(jetbrains.buildServer.serverSide.agentTypes) Collectors(java.util.stream.Collectors) CloudManagerBase(jetbrains.buildServer.clouds.server.CloudManagerBase) jetbrains.buildServer.server.graphql.model.mutation(jetbrains.buildServer.server.graphql.model.mutation) OperationFailedGraphQLError(jetbrains.buildServer.server.graphql.util.OperationFailedGraphQLError) Component(org.springframework.stereotype.Component) Pair(com.intellij.openapi.util.Pair) AuthUtil(jetbrains.buildServer.serverSide.auth.AuthUtil) CloudImage(jetbrains.buildServer.server.graphql.model.CloudImage) NotNull(org.jetbrains.annotations.NotNull) UnexpectedServerGraphQLError(jetbrains.buildServer.server.graphql.util.UnexpectedServerGraphQLError) Project(jetbrains.buildServer.server.graphql.model.Project) DataFetcherResult(graphql.execution.DataFetcherResult) OperationFailedGraphQLError(jetbrains.buildServer.server.graphql.util.OperationFailedGraphQLError) EntityNotFoundGraphQLError(jetbrains.buildServer.server.graphql.util.EntityNotFoundGraphQLError) jetbrains.buildServer.server.graphql.model.mutation.agentPool(jetbrains.buildServer.server.graphql.model.mutation.agentPool) AuthorityHolder(jetbrains.buildServer.serverSide.auth.AuthorityHolder) Used(jetbrains.buildServer.Used) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Project

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

the class AgentPoolMutation method assignProjectWithAgentPool.

@Used("graphql")
@NotNull
public DataFetcherResult<AssignProjectWithAgentPoolPayload> assignProjectWithAgentPool(@NotNull AssignProjectWithAgentPoolInput input) {
    DataFetcherResult.Builder<AssignProjectWithAgentPoolPayload> result = DataFetcherResult.newResult();
    if (!myAgentPoolActionsAccessChecker.canManageProjectsInPool(input.getAgentPoolRawId())) {
        return result.error(new OperationFailedGraphQLError("Can't assign project.")).build();
    }
    SProject project = myProjectManager.findProjectByExternalId(input.getProjectRawId());
    if (project == null) {
        return result.error(new EntityNotFoundGraphQLError("Project with given id does not exist.")).build();
    }
    try {
        myAgentPoolManager.associateProjectsWithPool(input.getAgentPoolRawId(), Collections.singleton(project.getProjectId()));
    } catch (NoSuchAgentPoolException e) {
        return result.error(new EntityNotFoundGraphQLError("Agent pool with given id does not exist.")).build();
    }
    if (BooleanUtils.isTrue(input.getExclusively())) {
        myAgentPoolManager.dissociateProjectsFromOtherPools(input.getAgentPoolRawId(), Collections.singleton(project.getProjectId()));
    }
    AgentPool agentPool = myAgentPoolManager.findAgentPoolById(input.getAgentPoolRawId());
    if (agentPool == null) {
        LOG.warn(String.format("Agent pool with id=%d is missing after associating project id=%s", input.getAgentPoolRawId(), project.getProjectId()));
        return result.error(new UnexpectedServerGraphQLError("Agent pool with given id could not be found after operation.")).build();
    }
    return result.data(new AssignProjectWithAgentPoolPayload(new Project(project), new jetbrains.buildServer.server.graphql.model.agentPool.AgentPool(agentPool))).build();
}
Also used : UnexpectedServerGraphQLError(jetbrains.buildServer.server.graphql.util.UnexpectedServerGraphQLError) Project(jetbrains.buildServer.server.graphql.model.Project) DataFetcherResult(graphql.execution.DataFetcherResult) OperationFailedGraphQLError(jetbrains.buildServer.server.graphql.util.OperationFailedGraphQLError) EntityNotFoundGraphQLError(jetbrains.buildServer.server.graphql.util.EntityNotFoundGraphQLError) jetbrains.buildServer.server.graphql.model.mutation.agentPool(jetbrains.buildServer.server.graphql.model.mutation.agentPool) Used(jetbrains.buildServer.Used) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Project

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

the class ProjectAgentPoolResolver method project.

@NotNull
public Project project(@NotNull ProjectAgentPool pool, @NotNull DataFetchingEnvironment env) {
    AgentPool realPool = pool.getRealPool();
    if (!realPool.isProjectPool()) {
        throw new RuntimeException(String.format("Pool id=%d is not a project pool.", realPool.getAgentPoolId()));
    }
    String projectId = ((ProjectAgentPoolImpl) realPool).getProjectId();
    SProject project = myProjectManager.findProjectById(projectId);
    if (project == null) {
        throw new RuntimeException(String.format("ProjectAgentPool id=%d does not have a project.", realPool.getAgentPoolId()));
    }
    return new Project(project);
}
Also used : ProjectAgentPoolImpl(jetbrains.buildServer.serverSide.agentPools.ProjectAgentPoolImpl) SProject(jetbrains.buildServer.serverSide.SProject) Project(jetbrains.buildServer.server.graphql.model.Project) SProject(jetbrains.buildServer.serverSide.SProject) AgentPool(jetbrains.buildServer.serverSide.agentPools.AgentPool) ProjectAgentPool(jetbrains.buildServer.server.graphql.model.agentPool.ProjectAgentPool) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Project (jetbrains.buildServer.server.graphql.model.Project)6 NotNull (org.jetbrains.annotations.NotNull)3 DataFetcherResult (graphql.execution.DataFetcherResult)2 Used (jetbrains.buildServer.Used)2 ProjectsConnection (jetbrains.buildServer.server.graphql.model.connections.ProjectsConnection)2 jetbrains.buildServer.server.graphql.model.mutation.agentPool (jetbrains.buildServer.server.graphql.model.mutation.agentPool)2 EntityNotFoundGraphQLError (jetbrains.buildServer.server.graphql.util.EntityNotFoundGraphQLError)2 OperationFailedGraphQLError (jetbrains.buildServer.server.graphql.util.OperationFailedGraphQLError)2 UnexpectedServerGraphQLError (jetbrains.buildServer.server.graphql.util.UnexpectedServerGraphQLError)2 Test (org.testng.annotations.Test)2 Logger (com.intellij.openapi.diagnostic.Logger)1 Pair (com.intellij.openapi.util.Pair)1 GraphQLMutationResolver (graphql.kickstart.tools.GraphQLMutationResolver)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 CloudClientEx (jetbrains.buildServer.clouds.CloudClientEx)1 CloudProfile (jetbrains.buildServer.clouds.CloudProfile)1 CloudManagerBase (jetbrains.buildServer.clouds.server.CloudManagerBase)1 Agent (jetbrains.buildServer.server.graphql.model.Agent)1