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);
}
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);
}
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 + "'");
}
}
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);
}
Aggregations