Search in sources :

Example 6 with SBuildAgent

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

the class AgentRequest method setAllowedRunConfigurations.

/**
 * Experimental use only
 */
@PUT
@Path("/{agentLocator}/compatibilityPolicy")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update build configuration run policy of agent matching locator.", nickname = "setBuildConfigurationRunPolicy")
public CompatibilityPolicy setAllowedRunConfigurations(@ApiParam(format = LocatorName.AGENT) @PathParam("agentLocator") String agentLocator, CompatibilityPolicy payload, @QueryParam("fields") String fields) {
    final SBuildAgent agent = myAgentFinder.getItem(agentLocator);
    payload.applyTo(agent, myServiceLocator);
    return CompatibilityPolicy.getCompatibilityPolicy(agent, new Fields(fields), myBeanContext);
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with SBuildAgent

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

the class AgentRequest method setEnabledInfo.

@PUT
@Path("/{agentLocator}/enabledInfo")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update the enablement status of the matching agent.", nickname = "setEnabledInfo")
public AgentEnabledInfo setEnabledInfo(@ApiParam(format = LocatorName.AGENT) @PathParam("agentLocator") String agentLocator, AgentEnabledInfo enabledInfo, @QueryParam("fields") String fields) {
    final SBuildAgent agent = myAgentFinder.getItem(agentLocator);
    if (enabledInfo == null)
        throw new BadRequestException("No data is sent as payload.");
    String commentText = enabledInfo.getCommentTextFromPosted();
    Boolean value = enabledInfo.getStatusFromPosted();
    if (value == null && commentText == null)
        throw new BadRequestException("Neither value nor comment are provided, nothing to change");
    Date switchTime = enabledInfo.getStatusSwitchTimeFromPosted(myServiceLocator);
    SUser currentUser = myServiceLocator.getSingletonService(UserFinder.class).getCurrentUser();
    if (switchTime == null) {
        agent.setEnabled(value != null ? value : agent.isEnabled(), currentUser, Agent.getActualActionComment(commentText));
    } else {
        agent.setEnabled(value != null ? value : agent.isEnabled(), currentUser, Agent.getActualActionComment(commentText), switchTime.getTime());
    }
    return new AgentEnabledInfo(agent, new Fields(fields), myBeanContext);
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) SUser(jetbrains.buildServer.users.SUser) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) Date(java.util.Date) ApiOperation(io.swagger.annotations.ApiOperation)

Example 8 with SBuildAgent

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

the class AgentRequest method getAgentPool.

@GET
@Path("/{agentLocator}/pool")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get the agent pool of the matching agent.", nickname = "getAgentPool")
public AgentPool getAgentPool(@ApiParam(format = LocatorName.AGENT) @PathParam("agentLocator") String agentLocator, @QueryParam("fields") String fields) {
    final SBuildAgent agent = myAgentFinder.getItem(agentLocator);
    final jetbrains.buildServer.serverSide.agentPools.AgentPool agentPool = myAgentPoolFinder.getAgentPool(agent);
    return agentPool == null ? null : new AgentPool(agentPool, new Fields(fields), myBeanContext);
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) ApiOperation(io.swagger.annotations.ApiOperation)

Example 9 with SBuildAgent

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

the class AgentRequest method deleteAgent.

@DELETE
@Path("/{agentLocator}")
@ApiOperation(value = "Delete an inactive agent.", nickname = "deleteAgent")
public void deleteAgent(@ApiParam(format = LocatorName.AGENT) @PathParam("agentLocator") String agentLocator) {
    final SBuildAgent agent = myAgentFinder.getItem(agentLocator);
    myServiceLocator.getSingletonService(BuildAgentManager.class).removeAgent(agent, myServiceLocator.getSingletonService(UserFinder.class).getCurrentUser());
}
Also used : BuildAgentManager(jetbrains.buildServer.serverSide.BuildAgentManager) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) ApiOperation(io.swagger.annotations.ApiOperation)

Example 10 with SBuildAgent

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

the class Agents method init.

private void init(@Nullable final Collection<SBuildAgent> agentObjects, @Nullable final PagerData pagerData, @NotNull final Fields fields, @NotNull final BeanContext beanContext) {
    if (agentObjects != null) {
        agents = ValueWithDefault.decideDefault(fields.isIncluded(AGENT, false, true), new ValueWithDefault.Value<List<Agent>>() {

            @Nullable
            public List<Agent> get() {
                final ArrayList<Agent> items = new ArrayList<Agent>(agentObjects.size());
                Fields agentFields = fields.getNestedField(AGENT);
                for (SBuildAgent item : agentObjects) {
                    items.add(new Agent(item, agentFields, beanContext));
                }
                return items;
            }
        });
        count = ValueWithDefault.decideIncludeByDefault(fields.isIncluded(COUNT), agentObjects.size());
    }
    if (pagerData != null) {
        href = ValueWithDefault.decideDefault(fields.isIncluded("href", true), beanContext.getApiUrlBuilder().transformRelativePath(pagerData.getHref()));
        nextHref = ValueWithDefault.decideDefault(fields.isIncluded("nextHref"), pagerData.getNextHref() != null ? beanContext.getApiUrlBuilder().transformRelativePath(pagerData.getNextHref()) : null);
        prevHref = ValueWithDefault.decideDefault(fields.isIncluded("prevHref"), pagerData.getPrevHref() != null ? beanContext.getApiUrlBuilder().transformRelativePath(pagerData.getPrevHref()) : null);
    }
}
Also used : SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) Fields(jetbrains.buildServer.server.rest.model.Fields) ArrayList(java.util.ArrayList) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent)

Aggregations

SBuildAgent (jetbrains.buildServer.serverSide.SBuildAgent)12 ApiOperation (io.swagger.annotations.ApiOperation)10 Fields (jetbrains.buildServer.server.rest.model.Fields)9 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)3 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)2 SecurityContext (jetbrains.buildServer.serverSide.auth.SecurityContext)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 CloudImage (jetbrains.buildServer.clouds.CloudImage)1 CloudManager (jetbrains.buildServer.clouds.server.CloudManager)1 PagerData (jetbrains.buildServer.server.rest.model.PagerData)1 BuildAgentManager (jetbrains.buildServer.serverSide.BuildAgentManager)1 SUser (jetbrains.buildServer.users.SUser)1 Nullable (org.jetbrains.annotations.Nullable)1