Search in sources :

Example 1 with Projects

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

the class ProjectRequestTest method memoryTest.

// @Test
public void memoryTest() throws InterruptedException {
    final ProjectRequest request = new ProjectRequest();
    request.setInTests(myProjectFinder, myBranchFinder, myBeanContext);
    final String locator = "archived:false,affectedProject:_Root";
    final String fields = "count,project(id,internalId,name,parentProjectId,archived,readOnlyUI,buildTypes(buildType(id,paused,internalId,projectId,name,type,description)),description)";
    Queue<Pair<Integer, ProjectEx>> q = new ArrayDeque<>();
    q.add(new Pair<>(0, myProject));
    final int max = 2;
    final int children = 4;
    int counter = 0;
    while (!q.isEmpty()) {
        Pair<Integer, ProjectEx> p = q.poll();
        String prefix = "Bt" + StringUtils.repeat('a', 10 * p.getFirst());
        for (int i = 0; i < children; i++) {
            ProjectEx c = myFixture.createProject("z-" + p.first + "-" + counter++, p.second);
            if (p.first < max) {
                q.add(new Pair<>(p.first + 1, c));
            }
            for (int j = 0; j < children * 4; j++) c.createBuildType(prefix + j);
        }
    }
    System.out.println(counter + " projects created.");
    Thread[] ts = new Thread[100];
    for (int i = 0; i < ts.length; i++) {
        final int threadIdx = i;
        ts[i] = new Thread(() -> {
            new RestContext(z -> null).run(() -> {
                for (int j = 0; j < 100; j++) {
                    final PagedSearchResult<SProject> result = myProjectFinder.getItems(locator);
                    Projects projects = new Projects(result.myEntries, null, new Fields(fields), myBeanContext);
                    projects.projects.stream().flatMap(p -> p.buildTypes.buildTypes.stream()).forEach(bt -> {
                        bt.getId();
                        bt.isPaused();
                        bt.getInternalId();
                        bt.getProjectId();
                        bt.getName();
                        bt.getType();
                        bt.getDescription();
                    });
                    System.out.println(String.format("Finished %d requests in thread %d", j, threadIdx));
                }
                return null;
            });
        });
        ts[i].start();
    }
    for (Thread t : ts) t.join();
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) java.util(java.util) Test(org.testng.annotations.Test) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) SProjectFeatureDescriptor(jetbrains.buildServer.serverSide.SProjectFeatureDescriptor) StringUtils(org.apache.commons.lang3.StringUtils) Branch(jetbrains.buildServer.server.rest.model.build.Branch) Projects(jetbrains.buildServer.server.rest.model.project.Projects) Option(jetbrains.buildServer.util.Option) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) RestContext(jetbrains.buildServer.server.rest.data.RestContext) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) ProjectFeatureDescriptorFactory(jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory) MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) OperationRequestor(jetbrains.buildServer.vcs.OperationRequestor) BuildFinderTestBase(jetbrains.buildServer.server.rest.data.BuildFinderTestBase) Branches(jetbrains.buildServer.server.rest.model.build.Branches) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) BeforeMethod(org.testng.annotations.BeforeMethod) RepositoryStateData.createVersionState(jetbrains.buildServer.vcs.RepositoryStateData.createVersionState) Util.map(jetbrains.buildServer.util.Util.map) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTypeEx(jetbrains.buildServer.serverSide.BuildTypeEx) Pair(com.intellij.openapi.util.Pair) SProject(jetbrains.buildServer.serverSide.SProject) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) Projects(jetbrains.buildServer.server.rest.model.project.Projects) RestContext(jetbrains.buildServer.server.rest.data.RestContext) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Fields(jetbrains.buildServer.server.rest.model.Fields) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) Pair(com.intellij.openapi.util.Pair)

Example 2 with Projects

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

the class AgentPoolRequest method replaceProjects.

/**
 * Associates the posted set of projects with the pool which replaces earlier associations on this pool
 * @param agentPoolLocator
 * @param projects
 * @return
 */
@PUT
@Path("/{agentPoolLocator}/projects")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update projects of the matching agent pool.", nickname = "setAgentPoolProjects")
public Projects replaceProjects(@ApiParam(format = LocatorName.AGENT_POOL) @PathParam("agentPoolLocator") String agentPoolLocator, Projects projects) {
    final jetbrains.buildServer.serverSide.agentPools.AgentPool agentPool = myAgentPoolFinder.getItem(agentPoolLocator);
    final AgentPoolManager agentPoolManager = myServiceLocator.getSingletonService(AgentPoolManager.class);
    final int agentPoolId = agentPool.getAgentPoolId();
    final List<SProject> projectsList = projects.getProjectsFromPosted(myProjectFinder);
    final Set<String> projectIds = new HashSet<String>(projectsList.size());
    for (SProject project : projectsList) {
        projectIds.add(project.getProjectId());
    }
    try {
        agentPoolManager.dissociateProjectsFromPool(agentPoolId, agentPoolManager.getPoolProjects(agentPoolId));
        agentPoolManager.associateProjectsWithPool(agentPoolId, projectIds);
    } catch (NoSuchAgentPoolException e) {
        throw new BadRequestException("Agent pool with id \'" + agentPoolId + "' is not found.");
    }
    return new Projects(myAgentPoolFinder.getPoolProjects(agentPool), null, Fields.LONG, myBeanContext);
}
Also used : Projects(jetbrains.buildServer.server.rest.model.project.Projects) SProject(jetbrains.buildServer.serverSide.SProject) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) HashSet(java.util.HashSet) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Projects (jetbrains.buildServer.server.rest.model.project.Projects)2 SProject (jetbrains.buildServer.serverSide.SProject)2 Pair (com.intellij.openapi.util.Pair)1 ApiOperation (io.swagger.annotations.ApiOperation)1 java.util (java.util)1 HashSet (java.util.HashSet)1 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)1 BuildFinderTestBase (jetbrains.buildServer.server.rest.data.BuildFinderTestBase)1 PagedSearchResult (jetbrains.buildServer.server.rest.data.PagedSearchResult)1 RestContext (jetbrains.buildServer.server.rest.data.RestContext)1 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 Fields (jetbrains.buildServer.server.rest.model.Fields)1 Branch (jetbrains.buildServer.server.rest.model.build.Branch)1 Branches (jetbrains.buildServer.server.rest.model.build.Branches)1 BeanContext (jetbrains.buildServer.server.rest.util.BeanContext)1 BuildTypeEx (jetbrains.buildServer.serverSide.BuildTypeEx)1 SProjectFeatureDescriptor (jetbrains.buildServer.serverSide.SProjectFeatureDescriptor)1 jetbrains.buildServer.serverSide.agentPools (jetbrains.buildServer.serverSide.agentPools)1 MockVcsSupport (jetbrains.buildServer.serverSide.impl.MockVcsSupport)1 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)1