Search in sources :

Example 71 with BadRequestException

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);
    }
}
Also used : SBuildRunnerDescriptor(jetbrains.buildServer.serverSide.SBuildRunnerDescriptor) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException)

Example 72 with BadRequestException

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;
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) InvalidVcsRootScopeException(jetbrains.buildServer.serverSide.InvalidVcsRootScopeException) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotNull(org.jetbrains.annotations.NotNull)

Example 73 with BadRequestException

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);
    }
}
Also used : BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) NotNull(org.jetbrains.annotations.NotNull)

Example 74 with BadRequestException

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;
}
Also used : CloudManager(jetbrains.buildServer.clouds.server.CloudManager) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) CloudUtil(jetbrains.buildServer.server.rest.data.CloudUtil) InvalidStateException(jetbrains.buildServer.server.rest.errors.InvalidStateException) Nullable(org.jetbrains.annotations.Nullable)

Example 75 with BadRequestException

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());
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) RevisionsNotFoundException(jetbrains.buildServer.vcs.impl.RevisionsNotFoundException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException)

Aggregations

BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)128 NotNull (org.jetbrains.annotations.NotNull)52 ApiOperation (io.swagger.annotations.ApiOperation)39 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)35 ServiceLocator (jetbrains.buildServer.ServiceLocator)28 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)22 Nullable (org.jetbrains.annotations.Nullable)22 SUser (jetbrains.buildServer.users.SUser)19 Fields (jetbrains.buildServer.server.rest.model.Fields)17 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)16 Collectors (java.util.stream.Collectors)10 SProject (jetbrains.buildServer.serverSide.SProject)9 StringUtil (jetbrains.buildServer.util.StringUtil)9 Date (java.util.Date)8 jetbrains.buildServer.serverSide (jetbrains.buildServer.serverSide)8 java.util (java.util)7 Locator (jetbrains.buildServer.server.rest.data.Locator)7 OperationException (jetbrains.buildServer.server.rest.errors.OperationException)7 PagerData (jetbrains.buildServer.server.rest.model.PagerData)7 Permission (jetbrains.buildServer.serverSide.auth.Permission)7