Search in sources :

Example 11 with GroupPromoteRequest

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;
}
Also used : GroupPromoteRequest(org.commonjava.indy.promote.model.GroupPromoteRequest) GroupPromoteResult(org.commonjava.indy.promote.model.GroupPromoteResult) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 12 with GroupPromoteRequest

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);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) GroupPromoteRequest(org.commonjava.indy.promote.model.GroupPromoteRequest) Group(org.commonjava.indy.model.core.Group) GroupPromoteResult(org.commonjava.indy.promote.model.GroupPromoteResult) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 13 with GroupPromoteRequest

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));
}
Also used : GroupPromoteRequest(org.commonjava.indy.promote.model.GroupPromoteRequest) Group(org.commonjava.indy.model.core.Group) GroupPromoteResult(org.commonjava.indy.promote.model.GroupPromoteResult) ValidationResult(org.commonjava.indy.promote.model.ValidationResult) IndyPromoteClientModule(org.commonjava.indy.promote.client.IndyPromoteClientModule) Test(org.junit.Test)

Example 14 with GroupPromoteRequest

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));
}
Also used : GroupPromoteRequest(org.commonjava.indy.promote.model.GroupPromoteRequest) Group(org.commonjava.indy.model.core.Group) GroupPromoteResult(org.commonjava.indy.promote.model.GroupPromoteResult) ValidationResult(org.commonjava.indy.promote.model.ValidationResult) IndyPromoteClientModule(org.commonjava.indy.promote.client.IndyPromoteClientModule) Test(org.junit.Test)

Example 15 with GroupPromoteRequest

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));
}
Also used : GroupPromoteRequest(org.commonjava.indy.promote.model.GroupPromoteRequest) Group(org.commonjava.indy.model.core.Group) GroupPromoteResult(org.commonjava.indy.promote.model.GroupPromoteResult) IndyPromoteClientModule(org.commonjava.indy.promote.client.IndyPromoteClientModule) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Aggregations

GroupPromoteRequest (org.commonjava.indy.promote.model.GroupPromoteRequest)22 GroupPromoteResult (org.commonjava.indy.promote.model.GroupPromoteResult)22 Test (org.junit.Test)20 ValidationResult (org.commonjava.indy.promote.model.ValidationResult)15 Category (org.junit.experimental.categories.Category)15 Group (org.commonjava.indy.model.core.Group)6 InputStream (java.io.InputStream)5 IndyPromoteClientModule (org.commonjava.indy.promote.client.IndyPromoteClientModule)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)2 IOException (java.io.IOException)1 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)1 IndyClientException (org.commonjava.indy.client.core.IndyClientException)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 HostedRepository (org.commonjava.indy.model.core.HostedRepository)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)1