Search in sources :

Example 1 with SBuildAgent

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

the class CloudInstanceData method getAgent.

@Nullable
public SBuildAgent getAgent() {
    CloudImage image = myInstance.getImage();
    String profileId = myServiceLocator.getSingletonService(CloudInstanceFinder.class).myCloudUtil.getProfileId(image);
    if (profileId == null)
        return null;
    Collection<SBuildAgent> agents = myServiceLocator.getSingletonService(CloudManager.class).findAgentByInstance(profileId, myInstance.getInstanceId());
    return agents.size() > 0 ? agents.iterator().next() : null;
}
Also used : CloudManager(jetbrains.buildServer.clouds.server.CloudManager) CloudImage(jetbrains.buildServer.clouds.CloudImage) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with SBuildAgent

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

the class AgentRequest method getCompatibleBuildTypes.

/**
 * Experimental support to get currently compatible build types
 */
@GET
@Path("/{agentLocator}/compatibleBuildTypes")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get build types compatible with the matching agent.", nickname = "getCompatibleBuildTypes")
public BuildTypes getCompatibleBuildTypes(@ApiParam(format = LocatorName.AGENT) @PathParam("agentLocator") String agentLocator, @QueryParam("fields") String fields) {
    final SBuildAgent agent = myAgentFinder.getItem(agentLocator);
    if (!AuthUtil.canViewAgentDetails(myBeanContext.getServiceLocator().getSingletonService(SecurityContext.class).getAuthorityHolder(), agent)) {
        throw new AuthorizationFailedException("No permission to view agent details");
    }
    Fields fieldsDefinition = new Fields(Agent.COMPATIBLE_BUILD_TYPES + "(" + (StringUtil.isEmpty(fields) ? "$long" : fields) + ")");
    return new Agent(agent, fieldsDefinition, myBeanContext).compatibleBuildTypes;
}
Also used : SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) Fields(jetbrains.buildServer.server.rest.model.Fields) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with SBuildAgent

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

the class AgentRequest method serveAgents.

/**
 * Returns list of agents
 *
 * @param includeDisconnected Deprecated, use "locator" parameter instead
 * @param includeUnauthorized Deprecated, use "locator" parameter instead
 * @param locator
 * @return
 */
@GET
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get all known agents.", nickname = "getAllAgents")
public Agents serveAgents(@ApiParam(hidden = true) @QueryParam("includeDisconnected") Boolean includeDisconnected, @ApiParam(hidden = true) @QueryParam("includeUnauthorized") Boolean includeUnauthorized, @ApiParam(format = LocatorName.AGENT) @QueryParam("locator") String locator, @QueryParam("fields") String fields, @Context UriInfo uriInfo, @Context HttpServletRequest request) {
    if (locator != null && includeDisconnected != null) {
        throw new BadRequestException("Both 'includeDisconnected' URL parameter and '" + AgentFinder.CONNECTED + "' locator dimension are specified. Please use locator only.");
    }
    if (locator != null && includeUnauthorized != null) {
        throw new BadRequestException("Both 'includeUnauthorized' URL parameter and '" + AgentFinder.AUTHORIZED + "' locator dimension are specified. Please use locator only.");
    }
    String locatorToUse = locator;
    if (includeDisconnected != null) {
        // pre-8.1 compatibility:
        locatorToUse = Locator.createEmptyLocator().setDimensionIfNotPresent(AgentFinder.CONNECTED, String.valueOf(!includeDisconnected)).getStringRepresentation();
    }
    final Locator parsedLocator = StringUtil.isEmpty(locatorToUse) ? Locator.createEmptyLocator() : new Locator(locatorToUse);
    if (includeUnauthorized != null) {
        // pre-8.1 compatibility:
        locatorToUse = parsedLocator.setDimensionIfNotPresent(AgentFinder.AUTHORIZED, String.valueOf(!includeUnauthorized)).getStringRepresentation();
    }
    final PagedSearchResult<SBuildAgent> result = myAgentFinder.getItems(locatorToUse);
    final PagerData pager = new PagerData(uriInfo.getRequestUriBuilder(), request.getContextPath(), result, locatorToUse, "locator");
    return new Agents(result.myEntries, pager, new Fields(fields), myBeanContext);
}
Also used : ServiceLocator(jetbrains.buildServer.ServiceLocator) Fields(jetbrains.buildServer.server.rest.model.Fields) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) PagerData(jetbrains.buildServer.server.rest.model.PagerData) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with SBuildAgent

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

the class AgentRequest method setAgentPool.

@PUT
@Path("/{agentLocator}/pool")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Assign the matching agent to the specified agent pool.", nickname = "setAgentPool")
public AgentPool setAgentPool(@ApiParam(format = LocatorName.AGENT) @PathParam("agentLocator") String agentLocator, AgentPool agentPool, @QueryParam("fields") String fields) {
    final SBuildAgent agent = myAgentFinder.getItem(agentLocator);
    myDataProvider.addAgentToPool(agentPool.getAgentPoolFromPosted(myAgentPoolFinder), agent.getAgentTypeId());
    final jetbrains.buildServer.serverSide.agentPools.AgentPool foundPool = myAgentPoolFinder.getAgentPool(agent);
    return new AgentPool(foundPool, new Fields(fields), myBeanContext);
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with SBuildAgent

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

the class AgentRequest method geIncompatibleBuildTypes.

/**
 * Experimental support to get currently incompatible build types with incompatibility reason
 */
@GET
@Path("/{agentLocator}/incompatibleBuildTypes")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get build types incompatible with the matching agent.", nickname = "getIncompatibleBuildTypes")
public Compatibilities geIncompatibleBuildTypes(@ApiParam(format = LocatorName.AGENT) @PathParam("agentLocator") String agentLocator, @QueryParam("fields") String fields) {
    final SBuildAgent agent = myAgentFinder.getItem(agentLocator);
    if (!AuthUtil.canViewAgentDetails(myBeanContext.getServiceLocator().getSingletonService(SecurityContext.class).getAuthorityHolder(), agent)) {
        throw new AuthorizationFailedException("No permission to view agent details");
    }
    Fields fieldsDefinition = new Fields(Agent.INCOMPATIBLE_BUILD_TYPES + "(" + (StringUtil.isEmpty(fields) ? "$long" : fields) + ")");
    return new Agent(agent, fieldsDefinition, myBeanContext).incompatibleBuildTypes;
}
Also used : SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) Fields(jetbrains.buildServer.server.rest.model.Fields) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) ApiOperation(io.swagger.annotations.ApiOperation)

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