Search in sources :

Example 1 with BuildTypes

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

the class ChangeRequest method getDeploymentConfigurations.

/**
 * Experimental support only!
 */
@GET
@Path("/{changeLocator}/deploymentConfigurations")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get build configurations where this change could potentially be deployed.", nickname = "getDeploymentConfigurations", hidden = true)
public BuildTypes getDeploymentConfigurations(@ApiParam(format = LocatorName.CHANGE) @PathParam("changeLocator") String changeLocator, @QueryParam("fields") String fields) {
    final SVcsModification change = myChangeFinder.getItem(changeLocator).getSVcsModification();
    ChangeStatusProvider myStatusProvider = myServiceLocator.getSingletonService(ChangeStatusProvider.class);
    ChangeStatus changeStatus = myStatusProvider.getMergedChangeStatus(change);
    return new BuildTypes(BuildTypes.fromBuildTypes(changeStatus.getDeploymentStatus().keySet()), null, new Fields(fields), myBeanContext);
}
Also used : SVcsModification(jetbrains.buildServer.vcs.SVcsModification) ChangeStatus(jetbrains.buildServer.vcs.ChangeStatus) Fields(jetbrains.buildServer.server.rest.model.Fields) BuildTypes(jetbrains.buildServer.server.rest.model.buildType.BuildTypes) ChangeStatusProvider(jetbrains.buildServer.vcs.ChangeStatusProvider) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with BuildTypes

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

the class ChangeRequest method getRelatedBuildTypes.

/**
 * Experimental support only!
 */
@GET
@Path("/{changeLocator}/buildTypes")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get build configurations related to the matching change.", nickname = "getRelatedBuildTypes", hidden = true)
public BuildTypes getRelatedBuildTypes(@ApiParam(format = LocatorName.CHANGE) @PathParam("changeLocator") String changeLocator, @QueryParam("fields") String fields) {
    final SVcsModification change = myChangeFinder.getItem(changeLocator).getSVcsModification();
    ChangeStatusProvider myStatusProvider = myServiceLocator.getSingletonService(ChangeStatusProvider.class);
    ChangeStatus changeStatus = myStatusProvider.getMergedChangeStatus(change);
    return new BuildTypes(BuildTypes.fromBuildTypes(changeStatus.getRelatedConfigurations()), null, new Fields(fields), myBeanContext);
}
Also used : SVcsModification(jetbrains.buildServer.vcs.SVcsModification) ChangeStatus(jetbrains.buildServer.vcs.ChangeStatus) Fields(jetbrains.buildServer.server.rest.model.Fields) BuildTypes(jetbrains.buildServer.server.rest.model.buildType.BuildTypes) ChangeStatusProvider(jetbrains.buildServer.vcs.ChangeStatusProvider) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with BuildTypes

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

the class CompatibilityPolicy method applyTo.

public void applyTo(@NotNull final SBuildAgent agent, @NotNull final ServiceLocator serviceLocator) {
    if (!AuthUtil.canViewAgentDetails(serviceLocator.getSingletonService(SecurityContext.class).getAuthorityHolder(), agent)) {
        // can get pool name i from the error message if we do not check this
        throw new AuthorizationFailedException("No permission to view agent details");
    }
    final AgentTypeManager agentTypeManager = serviceLocator.getSingletonService(AgentTypeManager.class);
    final int agentTypeId = agent.getAgentTypeId();
    final String valueUp = policy.trim().toLowerCase();
    if (POLICY_ANY.equals(valueUp)) {
        agentTypeManager.setRunConfigurationPolicy(agentTypeId, BuildAgentManager.RunConfigurationPolicy.ALL_COMPATIBLE_CONFIGURATIONS);
    } else if (POLICY_SELECTED.equals(valueUp)) {
        if (buildTypes == null) {
            buildTypes = new BuildTypes();
        }
        List<jetbrains.buildServer.BuildType> buildTypesFromPosted = buildTypes.getBuildTypesFromPosted(serviceLocator);
        BuildAgentManager.RunConfigurationPolicy previousPolicy = agentTypeManager.getRunConfigurationPolicy(agentTypeId);
        Set<String> previous_canRunConfigurations = agentTypeManager.getCanRunConfigurations(agentTypeId);
        try {
            agentTypeManager.setRunConfigurationPolicy(agentTypeId, BuildAgentManager.RunConfigurationPolicy.SELECTED_COMPATIBLE_CONFIGURATIONS);
            agentTypeManager.excludeRunConfigurationsFromAllowed(agentTypeId, previous_canRunConfigurations.toArray(new String[0]));
            agentTypeManager.includeRunConfigurationsToAllowed(agentTypeId, buildTypesFromPosted.stream().map(jetbrains.buildServer.BuildType::getBuildTypeId).toArray(String[]::new));
        } catch (Exception e) {
            agentTypeManager.setRunConfigurationPolicy(agentTypeId, previousPolicy);
            agentTypeManager.excludeRunConfigurationsFromAllowed(agentTypeId, agentTypeManager.getCanRunConfigurations(agentTypeId).toArray(new String[0]));
            agentTypeManager.includeRunConfigurationsToAllowed(agentTypeId, previous_canRunConfigurations.toArray(new String[0]));
            throw e;
        }
    } else {
        throw new BadRequestException("Unexpected policy '" + policy + "', expected '" + POLICY_ANY + "' or '" + POLICY_SELECTED + "'");
    }
}
Also used : Set(java.util.Set) BuildTypes(jetbrains.buildServer.server.rest.model.buildType.BuildTypes) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) AgentTypeManager(jetbrains.buildServer.serverSide.agentTypes.AgentTypeManager) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) List(java.util.List) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException)

Example 4 with BuildTypes

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

the class ProjectRequest method setBuildTypesOrder.

/**
 * Put empty collection to remove custom ordering
 */
@PUT
@Path("/{projectLocator}/order/buildTypes")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update custom ordering of build configurations of the matching project.", nickname = "setBuildTypesOrder")
public BuildTypes setBuildTypesOrder(@ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, BuildTypes buildTypes, @QueryParam("field") String fields) {
    SProject project = myProjectFinder.getItem(projectLocator);
    LinkedHashSet<String> ids = new LinkedHashSet<>();
    if (buildTypes.buildTypes != null) {
        for (BuildType buildType : buildTypes.buildTypes) {
            String locatorFromPosted = buildType.getLocatorFromPosted();
            List<SBuildType> items = myBuildTypeFinder.getBuildTypes(project, locatorFromPosted);
            if (items.isEmpty()) {
                throw new BadRequestException("No build types in project found by locator '" + locatorFromPosted + "'");
            }
            for (SBuildType item : items) {
                ids.add(item.getInternalId());
            }
        }
    }
    ((ProjectEx) project).setOwnBuildTypesOrder(new ArrayList<>(ids));
    // see serveBuildTypesInProject()
    return new BuildTypes(BuildTypes.fromBuildTypes(((ProjectEx) project).getOwnBuildTypesOrder()), null, new Fields(fields), myBeanContext);
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Fields(jetbrains.buildServer.server.rest.model.Fields) BuildTypes(jetbrains.buildServer.server.rest.model.buildType.BuildTypes) BuildType(jetbrains.buildServer.server.rest.model.buildType.BuildType) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

BuildTypes (jetbrains.buildServer.server.rest.model.buildType.BuildTypes)4 ApiOperation (io.swagger.annotations.ApiOperation)3 Fields (jetbrains.buildServer.server.rest.model.Fields)3 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)2 ChangeStatus (jetbrains.buildServer.vcs.ChangeStatus)2 ChangeStatusProvider (jetbrains.buildServer.vcs.ChangeStatusProvider)2 SVcsModification (jetbrains.buildServer.vcs.SVcsModification)2 List (java.util.List)1 Set (java.util.Set)1 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)1 BuildType (jetbrains.buildServer.server.rest.model.buildType.BuildType)1 AgentTypeManager (jetbrains.buildServer.serverSide.agentTypes.AgentTypeManager)1 SecurityContext (jetbrains.buildServer.serverSide.auth.SecurityContext)1 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)1