use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class AgentPoolRequest method deleteProjects.
/**
* Removed all the projects from the pool
*/
@DELETE
@Path("/{agentPoolLocator}/projects")
@ApiOperation(value = "Unassign all projects from the matching agent pool.", nickname = "deleteAllProjectsFromAgentPool")
public void deleteProjects(@ApiParam(format = LocatorName.AGENT_POOL) @PathParam("agentPoolLocator") String agentPoolLocator) {
final jetbrains.buildServer.serverSide.agentPools.AgentPool agentPool = myAgentPoolFinder.getItem(agentPoolLocator);
final AgentPoolManager agentPoolManager = myServiceLocator.getSingletonService(AgentPoolManager.class);
final int agentPoolId = agentPool.getAgentPoolId();
try {
agentPoolManager.dissociateProjectsFromPool(agentPoolId, agentPoolManager.getPoolProjects(agentPoolId));
} catch (NoSuchAgentPoolException e) {
throw new BadRequestException("Agent pool with id \'" + agentPoolId + "' is not found.");
}
}
use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class AgentPoolRequest method deletePoolProject.
@DELETE
@Path("/{agentPoolLocator}/projects/{projectLocator}")
@ApiOperation(value = "Unassign the project from the matching agent pool.", nickname = "deleteProjectFromAgentPool")
public void deletePoolProject(@ApiParam(format = LocatorName.AGENT_POOL) @PathParam("agentPoolLocator") String agentPoolLocator, @ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator) {
final jetbrains.buildServer.serverSide.agentPools.AgentPool agentPool = myAgentPoolFinder.getItem(agentPoolLocator);
final SProject project = myProjectFinder.getItem(projectLocator);
final AgentPoolManager agentPoolManager = myServiceLocator.getSingletonService(AgentPoolManager.class);
final int agentPoolId = agentPool.getAgentPoolId();
try {
agentPoolManager.dissociateProjectsFromPool(agentPoolId, Collections.singleton(project.getProjectId()));
} catch (NoSuchAgentPoolException e) {
throw new BadRequestException("Agent pool with id \'" + agentPoolId + "' is not found.");
}
}
use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class BuildTypeRequest method addFeatureParameter.
@PUT
@Path("/{btLocator}/features/{featureId}/parameters/{parameterName}")
@Produces({ "text/plain" })
@Consumes({ "text/plain" })
@ApiOperation(value = "Update build feature parameter for the matching build configuration.", nickname = "addParameterToBuildFeature")
public String addFeatureParameter(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @PathParam("featureId") String featureId, @PathParam("parameterName") String parameterName, String newValue) {
final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
SBuildFeatureDescriptor feature = BuildTypeUtil.getBuildTypeFeature(buildType.get(), featureId);
Map<String, String> parameters = new HashMap<String, String>();
parameters.putAll(feature.getParameters());
if (StringUtil.isEmpty(parameterName)) {
throw new BadRequestException("Parameter name cannot be empty.");
}
parameters.put(parameterName, newValue);
buildType.get().updateBuildFeature(feature.getId(), feature.getType(), parameters);
buildType.persist("Build feature parameter added");
return BuildTypeUtil.getParameter(parameterName, BuildTypeUtil.getBuildTypeFeature(buildType.get(), featureId).getParameters(), false, false, myServiceLocator);
}
use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class ProjectRequest method deleteProjectAgentPools.
@DELETE
@Path("/{projectLocator}/agentPools/{agentPoolLocator}")
@ApiOperation(value = "Unassign a project from the matching agent pool.", nickname = "removeProjectFromAgentPool")
public void deleteProjectAgentPools(@ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, @PathParam("agentPoolLocator") String agentPoolLocator) {
SProject project = myProjectFinder.getItem(projectLocator);
final jetbrains.buildServer.serverSide.agentPools.AgentPool agentPool = myAgentPoolFinder.getItem(agentPoolLocator);
final AgentPoolManager agentPoolManager = myServiceLocator.getSingletonService(AgentPoolManager.class);
final int agentPoolId = agentPool.getAgentPoolId();
try {
agentPoolManager.dissociateProjectsFromPool(agentPoolId, singleton(project.getProjectId()));
} catch (NoSuchAgentPoolException e) {
throw new BadRequestException("Agent pool with id \'" + agentPoolId + "' is not found.");
}
}
use of jetbrains.buildServer.server.rest.errors.BadRequestException 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