Search in sources :

Example 16 with SProject

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

the class AgentPoolRequest method addProject.

/**
 * Adds the posted project to the pool associated projects
 * @param agentPoolLocator
 * @param projects
 * @return
 */
@POST
@Path("/{agentPoolLocator}/projects")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Assign the project to the matching agent pool.", nickname = "addProjectToAgentPool")
public Project addProject(@ApiParam(format = LocatorName.AGENT_POOL) @PathParam("agentPoolLocator") String agentPoolLocator, Project project) {
    final jetbrains.buildServer.serverSide.agentPools.AgentPool agentPool = myAgentPoolFinder.getItem(agentPoolLocator);
    final AgentPoolManager agentPoolManager = myServiceLocator.getSingletonService(AgentPoolManager.class);
    final int agentPoolId = agentPool.getAgentPoolId();
    final SProject postedProject = project.getProjectFromPosted(myProjectFinder);
    try {
        agentPoolManager.associateProjectsWithPool(agentPoolId, Collections.singleton(postedProject.getProjectId()));
    } catch (NoSuchAgentPoolException e) {
        throw new BadRequestException("Agent pool with id \'" + agentPoolId + "' is not found.");
    }
    return new Project(postedProject, Fields.LONG, myBeanContext);
}
Also used : Project(jetbrains.buildServer.server.rest.model.project.Project) SProject(jetbrains.buildServer.serverSide.SProject) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) SProject(jetbrains.buildServer.serverSide.SProject) ApiOperation(io.swagger.annotations.ApiOperation)

Example 17 with SProject

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

the class AgentPoolRequest method getPoolProject.

@GET
@Path("/{agentPoolLocator}/projects/{projectLocator}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "getPoolProject", hidden = true)
public Project getPoolProject(@ApiParam(format = LocatorName.AGENT_POOL) @PathParam("agentPoolLocator") String agentPoolLocator, @ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, @QueryParam("fields") String fields) {
    final jetbrains.buildServer.serverSide.agentPools.AgentPool agentPool = myAgentPoolFinder.getItem(agentPoolLocator);
    final SProject project = myProjectFinder.getItem(projectLocator);
    return new Project(project, new Fields(fields), myBeanContext);
}
Also used : Project(jetbrains.buildServer.server.rest.model.project.Project) SProject(jetbrains.buildServer.serverSide.SProject) Fields(jetbrains.buildServer.server.rest.model.Fields) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) SProject(jetbrains.buildServer.serverSide.SProject) ApiOperation(io.swagger.annotations.ApiOperation)

Example 18 with SProject

use of jetbrains.buildServer.serverSide.SProject 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)

Example 19 with SProject

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

the class CloudImageResolver method project.

@NotNull
public DataFetcherResult<Project> project(@NotNull CloudImage image, @NotNull DataFetchingEnvironment env) {
    String projectId = image.getRealProfile().getProjectId();
    SProject project;
    if (SProject.ROOT_PROJECT_ID.equals(projectId)) {
        project = myProjectManager.getRootProject();
    } else {
        project = myProjectManager.findProjectById(projectId);
    }
    DataFetcherResult.Builder<Project> result = new DataFetcherResult.Builder<>();
    if (project == null) {
        result.error(new EntityNotFoundGraphQLError(String.format("Could not find project for instance id=%s", image.getRawId())));
    } else {
        result.data(new Project(project)).localContext(project);
    }
    return result.build();
}
Also used : SProject(jetbrains.buildServer.serverSide.SProject) DataFetcherResult(graphql.execution.DataFetcherResult) EntityNotFoundGraphQLError(jetbrains.buildServer.server.graphql.util.EntityNotFoundGraphQLError) SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with SProject

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

the class ProjectResolver method projectAgentPool.

@Nullable
public ProjectAgentPool projectAgentPool(@NotNull Project source, @NotNull DataFetchingEnvironment env) {
    SProject self = source.getRealProject();
    AgentPool pool = myAgentPoolManager.findProjectPoolByProjectId(self.getProjectId());
    if (pool == null)
        return null;
    return new ProjectAgentPool(pool);
}
Also used : ProjectAgentPool(jetbrains.buildServer.server.graphql.model.agentPool.ProjectAgentPool) SProject(jetbrains.buildServer.serverSide.SProject) AgentPool(jetbrains.buildServer.serverSide.agentPools.AgentPool) ProjectAgentPool(jetbrains.buildServer.server.graphql.model.agentPool.ProjectAgentPool) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

SProject (jetbrains.buildServer.serverSide.SProject)42 NotNull (org.jetbrains.annotations.NotNull)22 Test (org.testng.annotations.Test)11 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)10 ProjectManager (jetbrains.buildServer.serverSide.ProjectManager)8 Nullable (org.jetbrains.annotations.Nullable)8 SBuildType (jetbrains.buildServer.serverSide.SBuildType)7 ApiOperation (io.swagger.annotations.ApiOperation)6 Logger (com.intellij.openapi.diagnostic.Logger)5 Collectors (java.util.stream.Collectors)5 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)5 Fields (jetbrains.buildServer.server.rest.model.Fields)5 Permission (jetbrains.buildServer.serverSide.auth.Permission)5 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)5 java.util (java.util)4 List (java.util.List)4 ServiceLocator (jetbrains.buildServer.ServiceLocator)4 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)4 jetbrains.buildServer.serverSide.agentPools (jetbrains.buildServer.serverSide.agentPools)4 Predicate (java.util.function.Predicate)3