Search in sources :

Example 51 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildRequest method deleteComment.

@DELETE
@Path("/{buildLocator}/comment")
@ApiOperation(value = "Remove the build comment matching the locator.", nickname = "deleteBuildComment")
public void deleteComment(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, @Context HttpServletRequest request) {
    BuildPromotion build = myBuildFinder.getBuildPromotion(null, buildLocator);
    final SUser user = SessionUser.getUser(request);
    setBuildComment(build, null, user);
}
Also used : SUser(jetbrains.buildServer.users.SUser) ApiOperation(io.swagger.annotations.ApiOperation)

Example 52 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildRequest method pinMultiple.

/**
 * Experimental.
 * Pins multiple builds
 * @return List of error messages with associated entities, if any
 */
@PUT
@Path("/multiple/{buildLocator}/pinInfo/")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Pin multiple matching builds.", nickname = "pinMultipleBuilds")
public MultipleOperationResult pinMultiple(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, PinInfo pinStatus, @QueryParam("fields") String fields, @Context HttpServletRequest request) {
    Boolean newStatus = pinStatus.getStatusFromPosted();
    if (newStatus == null)
        throw new BadRequestException("Pin status should be specified in the payload");
    String commentText = pinStatus.getCommentTextFromPosted();
    SUser user = SessionUser.getUser(request);
    return processMultiple(buildLocator, (build) -> pinBuild(build, user, commentText, newStatus), new Fields(fields));
}
Also used : SUser(jetbrains.buildServer.users.SUser) ApiOperation(io.swagger.annotations.ApiOperation)

Example 53 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildRequest method replaceComment.

@PUT
@Path("/{buildLocator}/comment")
@Consumes({ "text/plain" })
@ApiOperation(value = "Update the comment on the matching build.", nickname = "setBuildComment")
public void replaceComment(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, String text, @Context HttpServletRequest request) {
    BuildPromotion build = myBuildFinder.getBuildPromotion(null, buildLocator);
    final SUser user = SessionUser.getUser(request);
    setBuildComment(build, text, user);
}
Also used : SUser(jetbrains.buildServer.users.SUser) ApiOperation(io.swagger.annotations.ApiOperation)

Example 54 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildRequest method cancelBuild.

// todo: deprecate in favor of posting to .../canceledInfo
@POST
@Path("/{buildLocator}")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "cancelBuild")
public Build cancelBuild(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, BuildCancelRequest cancelRequest, @QueryParam("fields") String fields, @Context HttpServletRequest request) {
    final SUser currentUser = SessionUser.getUser(request);
    BuildPromotion build = myBuildFinder.getBuildPromotion(null, buildLocator);
    LinkedHashMap<Long, RuntimeException> errors = cancelBuilds(Collections.singletonList(build), cancelRequest, currentUser);
    if (!errors.isEmpty()) {
        throw errors.entrySet().iterator().next().getValue();
    }
    final SBuild associatedBuild = build.getAssociatedBuild();
    if (associatedBuild == null) {
        return null;
    }
    return new Build(associatedBuild, new Fields(fields), myBeanContext);
}
Also used : BaseBuild(jetbrains.buildServer.serverSide.impl.BaseBuild) QueuedBuild(jetbrains.buildServer.QueuedBuild) SUser(jetbrains.buildServer.users.SUser) ApiOperation(io.swagger.annotations.ApiOperation)

Example 55 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class CloudRequest method stopInstance.

@DELETE
@Path("/instances/{instanceLocator}")
@ApiOperation(value = "Stop cloud instance matching the locator.", nickname = "stopInstance")
public void stopInstance(@PathParam("instanceLocator") String instanceLocator) {
    jetbrains.buildServer.clouds.CloudInstance instance = myCloudInstanceFinder.getItem(instanceLocator).getInstance();
    final SUser user = myServiceLocator.getSingletonService(UserFinder.class).getCurrentUser();
    CloudUtil cloudUtil = myBeanContext.getSingletonService(CloudUtil.class);
    String profileId = cloudUtil.getProfileId(instance.getImage());
    if (profileId == null) {
        throw new InvalidStateException("Cannot find profile for the cloud image");
    }
    myBeanContext.getSingletonService(CloudManager.class).terminateInstance(profileId, instance.getImageId(), instance.getInstanceId(), TerminateInstanceReason.userAction(user));
}
Also used : SUser(jetbrains.buildServer.users.SUser) CloudManager(jetbrains.buildServer.clouds.server.CloudManager) InvalidStateException(jetbrains.buildServer.server.rest.errors.InvalidStateException) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

SUser (jetbrains.buildServer.users.SUser)125 Test (org.testng.annotations.Test)70 ApiOperation (io.swagger.annotations.ApiOperation)35 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)35 Build (jetbrains.buildServer.server.rest.model.build.Build)20 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)18 NotNull (org.jetbrains.annotations.NotNull)18 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)15 SecurityContextEx (jetbrains.buildServer.serverSide.SecurityContextEx)13 Fields (jetbrains.buildServer.server.rest.model.Fields)12 SUserGroup (jetbrains.buildServer.groups.SUserGroup)11 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)10 ServiceLocator (jetbrains.buildServer.ServiceLocator)9 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)9 Nullable (org.jetbrains.annotations.Nullable)9 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)8 SecurityContextImpl (jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl)8 java.util (java.util)7 Collectors (java.util.stream.Collectors)7 jetbrains.buildServer.serverSide (jetbrains.buildServer.serverSide)7