use of com.google.gerrit.server.project.CreateProjectArgs in project gerrit by GerritCodeReview.
the class ProjectOperationsImpl method createNewProject.
private Project.NameKey createNewProject(TestProjectCreation projectCreation) throws Exception {
String name = projectCreation.name().orElse(RandomStringUtils.randomAlphabetic(8));
CreateProjectArgs args = new CreateProjectArgs();
args.setProjectName(name);
args.permissionsOnly = projectCreation.permissionOnly().orElse(false);
args.branch = projectCreation.branches().stream().map(RefNames::fullName).collect(toImmutableList());
args.createEmptyCommit = projectCreation.createEmptyCommit().orElse(true);
projectCreation.parent().ifPresent(p -> args.newParent = p);
// ProjectCreator wants non-null owner IDs.
args.ownerIds = new ArrayList<>(projectCreation.owners());
projectCreation.submitType().ifPresent(st -> args.submitType = st);
projectCreator.createProject(args);
return Project.nameKey(name);
}
use of com.google.gerrit.server.project.CreateProjectArgs in project gerrit by GerritCodeReview.
the class CreateProject method apply.
@Override
public Response<ProjectInfo> apply(TopLevelResource resource, IdString id, ProjectInput input) throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException {
String name = id.get();
if (input == null) {
input = new ProjectInput();
}
if (input.name != null && !name.equals(input.name)) {
throw new BadRequestException("name must match URL");
}
CreateProjectArgs args = new CreateProjectArgs();
args.setProjectName(ProjectUtil.sanitizeProjectName(name));
String parentName = MoreObjects.firstNonNull(Strings.emptyToNull(input.parent), allProjects.get());
args.newParent = projectsCollection.get().parse(parentName, false).getNameKey();
if (args.newParent.equals(allUsers)) {
throw new ResourceConflictException(String.format("Cannot inherit from '%s' project", allUsers.get()));
}
args.createEmptyCommit = input.createEmptyCommit;
args.permissionsOnly = input.permissionsOnly;
args.projectDescription = Strings.emptyToNull(input.description);
args.submitType = input.submitType;
args.branch = normalizeBranchNames(input.branches);
if (input.owners == null || input.owners.isEmpty()) {
args.ownerIds = new ArrayList<>(projectOwnerGroups.create(args.getProject()).get());
} else {
args.ownerIds = Lists.newArrayListWithCapacity(input.owners.size());
for (String owner : input.owners) {
args.ownerIds.add(groupResolver.get().parse(owner).getGroupUUID());
}
}
args.contributorAgreements = MoreObjects.firstNonNull(input.useContributorAgreements, InheritableBoolean.INHERIT);
args.signedOffBy = MoreObjects.firstNonNull(input.useSignedOffBy, InheritableBoolean.INHERIT);
args.contentMerge = input.submitType == SubmitType.FAST_FORWARD_ONLY ? InheritableBoolean.FALSE : MoreObjects.firstNonNull(input.useContentMerge, InheritableBoolean.INHERIT);
args.newChangeForAllNotInTarget = MoreObjects.firstNonNull(input.createNewChangeForAllNotInTarget, InheritableBoolean.INHERIT);
args.changeIdRequired = MoreObjects.firstNonNull(input.requireChangeId, InheritableBoolean.INHERIT);
args.rejectEmptyCommit = MoreObjects.firstNonNull(input.rejectEmptyCommit, InheritableBoolean.INHERIT);
args.enableSignedPush = MoreObjects.firstNonNull(input.enableSignedPush, InheritableBoolean.INHERIT);
args.requireSignedPush = MoreObjects.firstNonNull(input.requireSignedPush, InheritableBoolean.INHERIT);
try {
args.maxObjectSizeLimit = ProjectConfig.validMaxObjectSizeLimit(input.maxObjectSizeLimit);
} catch (ConfigInvalidException e) {
throw new BadRequestException(e.getMessage());
}
Lock nameLock = lockManager.call(lockManager -> lockManager.getLock(args.getProject()));
nameLock.lock();
try {
try {
projectCreationValidationListeners.runEach(l -> l.validateNewProject(args), ValidationException.class);
} catch (ValidationException e) {
throw new ResourceConflictException(e.getMessage(), e);
}
ProjectState projectState = projectCreator.createProject(args);
requireNonNull(projectState, () -> String.format("failed to create project %s", args.getProject().get()));
if (input.pluginConfigValues != null) {
ConfigInput in = new ConfigInput();
in.pluginConfigValues = input.pluginConfigValues;
in.description = args.projectDescription;
putConfig.get().apply(projectState, in);
}
return Response.created(json.format(projectState));
} finally {
nameLock.unlock();
}
}
use of com.google.gerrit.server.project.CreateProjectArgs in project gerrit by GerritCodeReview.
the class CancellationIT method handleServerDeadlineExceeded.
@Test
public void handleServerDeadlineExceeded() throws Exception {
ProjectCreationValidationListener projectCreationListener = new ProjectCreationValidationListener() {
@Override
public void validateNewProject(CreateProjectArgs args) throws ValidationException {
// Simulate an exceeded deadline by throwing RequestCancelledException.
throw new RequestCancelledException(RequestStateProvider.Reason.SERVER_DEADLINE_EXCEEDED, /* cancellationMessage= */
null);
}
};
try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/" + name("new"));
assertThat(response.getStatusCode()).isEqualTo(SC_REQUEST_TIMEOUT);
assertThat(response.getEntityContent()).isEqualTo("Server Deadline Exceeded");
}
}
use of com.google.gerrit.server.project.CreateProjectArgs in project gerrit by GerritCodeReview.
the class CancellationIT method exceededDeadlineForOneRequestDoesntAbortFollowUpRequest.
@Test
@GerritConfig(name = "deadline.default.timeout", value = "500ms")
public void exceededDeadlineForOneRequestDoesntAbortFollowUpRequest() throws Exception {
ProjectCreationValidationListener projectCreationValidationListener = new ProjectCreationValidationListener() {
@Override
public void validateNewProject(CreateProjectArgs args) throws ValidationException {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException("interrupted during sleep", e);
}
}
};
try (Registration registration = extensionRegistry.newRegistration().add(projectCreationValidationListener)) {
RestResponse response = adminRestSession.putWithHeaders("/projects/" + name("new"));
assertThat(response.getStatusCode()).isEqualTo(SC_REQUEST_TIMEOUT);
assertThat(response.getEntityContent()).isEqualTo("Server Deadline Exceeded\n\ndefault.timeout=500ms");
}
// verify that the exceeded deadline for the previous request, isn't applied to a new request
RestResponse response = adminRestSession.putWithHeaders("/projects/" + name("new2"));
response.assertCreated();
}
use of com.google.gerrit.server.project.CreateProjectArgs in project gerrit by GerritCodeReview.
the class SshCancellationIT method handleWrappedRequestCancelledException.
@Test
public void handleWrappedRequestCancelledException() throws Exception {
ProjectCreationValidationListener projectCreationListener = new ProjectCreationValidationListener() {
@Override
public void validateNewProject(CreateProjectArgs args) throws ValidationException {
throw new RuntimeException(new RequestCancelledException(RequestStateProvider.Reason.SERVER_DEADLINE_EXCEEDED, "deadline = 10m"));
}
};
try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
adminSshSession.exec("gerrit create-project " + name("new"));
adminSshSession.assertFailure("Server Deadline Exceeded (deadline = 10m)");
}
}
Aggregations