use of org.commonjava.indy.promote.model.GroupPromoteRequest in project indy by Commonjava.
the class IndyPromoteClientModule method promoteToGroup.
public GroupPromoteResult promoteToGroup(final StoreType srcType, final String srcName, final String targetGroup) throws IndyClientException {
final GroupPromoteRequest req = new GroupPromoteRequest(new StoreKey(srcType, srcName), targetGroup);
final GroupPromoteResult result = http.postWithResponse(GROUP_PROMOTE_PATH, req, GroupPromoteResult.class, HttpStatus.SC_OK);
return result;
}
use of org.commonjava.indy.promote.model.GroupPromoteRequest in project indy by Commonjava.
the class PromotionManager method rollbackGroupPromote.
public GroupPromoteResult rollbackGroupPromote(GroupPromoteResult result, String user) throws PromotionException {
GroupPromoteRequest request = result.getRequest();
if (!storeManager.hasArtifactStore(request.getSource())) {
String error = String.format("No such source/member store: %s", request.getSource());
logger.warn(error);
return new GroupPromoteResult(request, error);
}
Group target;
try {
target = (Group) storeManager.getArtifactStore(request.getTargetKey());
} catch (IndyDataException e) {
throw new PromotionException("Cannot retrieve target group: %s. Reason: %s", e, request.getTargetGroup(), e.getMessage());
}
if (target == null) {
String error = String.format("No such target group: %s.", request.getTargetGroup());
logger.warn(error);
return new GroupPromoteResult(request, error);
}
if (target.getConstituents().contains(request.getSource())) {
// give the preUpdate event a different object to compare vs. the original group.
target = target.copyOf();
target.removeConstituent(request.getSource());
try {
final ChangeSummary changeSummary = new ChangeSummary(user, "Removing " + request.getSource() + " from membership of group: " + target.getKey());
storeManager.storeArtifactStore(target, changeSummary, false, true, new EventMetadata());
} catch (IndyDataException e) {
throw new PromotionException("Failed to store group: %s with additional member: %s. Reason: %s", e, target.getKey(), request.getSource(), e.getMessage());
}
} else {
return new GroupPromoteResult(request, "Group: " + target.getKey() + " does not contain member: " + request.getSource());
}
return new GroupPromoteResult(request);
}
use of org.commonjava.indy.promote.model.GroupPromoteRequest in project indy by Commonjava.
the class GroupPromoteFailsValidationTest method run.
@Test
public void run() throws Exception {
final GroupPromoteResult result = client.module(IndyPromoteClientModule.class).promoteToGroup(new GroupPromoteRequest(source.getKey(), target.getName()));
assertFalse(result.succeeded());
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTargetGroup(), equalTo(target.getName()));
assertThat(result.getError(), nullValue());
ValidationResult validations = result.getValidations();
assertThat(validations, notNullValue());
Map<String, String> errors = validations.getValidatorErrors();
assertThat(errors, notNullValue());
String error = errors.get("fail-all.groovy");
assertThat(error, notNullValue());
assertThat(client.content().exists(target.getKey().getType(), target.getName(), first), equalTo(false));
assertThat(client.content().exists(target.getKey().getType(), target.getName(), second), equalTo(false));
Group g = client.stores().load(StoreType.group, target.getName(), Group.class);
assertThat(g.getConstituents().contains(source.getKey()), equalTo(false));
}
use of org.commonjava.indy.promote.model.GroupPromoteRequest in project indy by Commonjava.
the class GroupPromoteMatchesSucceedingValidationTest method run.
@Test
public void run() throws Exception {
final GroupPromoteResult result = client.module(IndyPromoteClientModule.class).promoteToGroup(new GroupPromoteRequest(source.getKey(), target.getName()));
assertThat(result.succeeded(), equalTo(true));
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTargetGroup(), equalTo(target.getName()));
assertThat(result.getError(), nullValue());
ValidationResult validations = result.getValidations();
assertThat(validations, notNullValue());
assertThat(validations.isValid(), equalTo(true));
assertThat(client.content().exists(target.getKey().getType(), target.getName(), first), equalTo(true));
assertThat(client.content().exists(target.getKey().getType(), target.getName(), second), equalTo(true));
Group g = client.stores().load(StoreType.group, target.getName(), Group.class);
assertThat(g.getConstituents().contains(source.getKey()), equalTo(true));
}
use of org.commonjava.indy.promote.model.GroupPromoteRequest in project indy by Commonjava.
the class GroupPromoteSourceIsReadOnlyTest method run.
@Test
public void run() throws Exception {
final GroupPromoteResult result = client.module(IndyPromoteClientModule.class).promoteToGroup(new GroupPromoteRequest(source.getKey(), target.getName()));
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTargetGroup(), equalTo(target.getName()));
assertThat(result.getError(), nullValue());
assertThat(client.content().exists(target.getKey().getType(), target.getName(), first), equalTo(true));
assertThat(client.content().exists(target.getKey().getType(), target.getName(), second), equalTo(true));
Group g = client.stores().load(StoreType.group, target.getName(), Group.class);
assertThat(g.getConstituents().contains(source.getKey()), equalTo(true));
source = client.stores().load(hosted, source.getName(), HostedRepository.class);
assertThat(source.isReadonly(), equalTo(true));
}
Aggregations