use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class PropEntitiesStep method setToBuildType.
public boolean setToBuildType(@NotNull final BuildTypeSettingsEx buildTypeSettings, @NotNull final ServiceLocator serviceLocator) {
Storage original = new Storage(buildTypeSettings);
try {
removeAllSteps(buildTypeSettings);
if (propEntities != null) {
String[] runnersOrder = new String[propEntities.size()];
boolean needToChangeOrder = false;
int i = 0;
for (PropEntityStep entity : propEntities) {
SBuildRunnerDescriptor result = entity.addToInternal(buildTypeSettings, serviceLocator);
runnersOrder[i] = result.getId();
List<SBuildRunnerDescriptor> currentRunners = buildTypeSettings.getBuildRunners();
if (!needToChangeOrder && (currentRunners.size() < i + 1 || !currentRunners.get(i).getId().equals(result.getId())))
needToChangeOrder = true;
i++;
}
if (needToChangeOrder)
buildTypeSettings.applyRunnersOrder(runnersOrder);
}
return true;
} catch (Exception e) {
// restore original settings
original.apply(buildTypeSettings);
throw new BadRequestException("Error replacing items", e);
}
}
use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class VcsRootEntry method addToInternal.
@NotNull
public SVcsRoot addToInternal(@NotNull final BuildTypeSettings buildType, @NotNull final VcsRootFinder vcsRootFinder) {
if (vcsRoot == null) {
throw new BadRequestException("Element vcs-root should be specified.");
}
final SVcsRoot result = vcsRoot.getVcsRoot(vcsRootFinder);
try {
buildType.addVcsRoot(result);
} catch (InvalidVcsRootScopeException e) {
throw new BadRequestException("Could not attach VCS root with id '" + result.getExternalId() + "' because of scope issues. Error: " + e.getMessage());
}
buildType.setCheckoutRules(result, new CheckoutRules(checkoutRules != null ? checkoutRules : ""));
return result;
}
use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class PropEntityAgentRequirement method replaceIn.
@NotNull
@Override
public Requirement replaceIn(@NotNull final BuildTypeSettingsEx buildType, @NotNull final Requirement entityToReplace, @NotNull final ServiceLocator serviceLocator) {
PropEntitiesAgentRequirement.Storage original = new PropEntitiesAgentRequirement.Storage(buildType);
buildType.removeRequirement(entityToReplace);
try {
return addTo(buildType, serviceLocator);
} catch (Exception e) {
// restore
original.apply(buildType);
throw new BadRequestException("Error setting new agent requirement", e);
}
}
use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class CloudInstance method startInstance.
@Nullable
public jetbrains.buildServer.clouds.CloudInstance startInstance(@NotNull final SUser user, @NotNull final ServiceLocator serviceLocator) {
if (submittedImage == null) {
throw new BadRequestException("Cloud Instance should contain image");
}
CloudUtil util = serviceLocator.getSingletonService(CloudUtil.class);
jetbrains.buildServer.clouds.CloudImage image = submittedImage.getFromPosted(serviceLocator);
String profileId = util.getProfileId(image);
if (profileId == null) {
throw new InvalidStateException("Cannot find profile for the cloud image");
}
CloudManager cloudManager = serviceLocator.getSingletonService(CloudManager.class);
cloudManager.startInstance(profileId, image.getId(), StartInstanceReason.userAction(user));
return null;
}
use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class Build method getSubmittedBuildType.
private SBuildType getSubmittedBuildType(@NotNull ServiceLocator serviceLocator, @Nullable final SVcsModification personalChange, @Nullable final SUser currentUser) {
if (submittedBuildType == null) {
if (submittedBuildTypeId == null) {
throw new BadRequestException("No 'buildType' element in the posted entry.");
}
SBuildType buildType = serviceLocator.getSingletonService(ProjectManager.class).findBuildTypeByExternalId(submittedBuildTypeId);
if (buildType == null) {
throw new NotFoundException("No build type found by submitted id '" + submittedBuildTypeId + "'");
}
return buildType;
}
final BuildTypeOrTemplate buildTypeFromPosted = submittedBuildType.getBuildTypeFromPosted(serviceLocator.findSingletonService(BuildTypeFinder.class));
final SBuildType regularBuildType = buildTypeFromPosted.getBuildType();
if (regularBuildType == null) {
throw new BadRequestException("Found template instead on build type. Only build types can run builds.");
}
if (personalChange == null) {
return regularBuildType;
}
if (currentUser == null) {
throw new BadRequestException("Cannot trigger a personal build while no current user is present. Please specify credentials of a valid and non-special user.");
}
return ((BuildTypeEx) regularBuildType).createPersonalBuildType(currentUser, personalChange.getId());
}
Aggregations