Search in sources :

Example 56 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class GroupPromoteAndRollbackTest method run.

@Test
public void run() throws Exception {
    GroupPromoteResult result = client.module(IndyPromoteClientModule.class).promoteToGroup(new GroupPromoteRequest(source.getKey(), target.getName()));
    assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
    assertThat(result.getRequest().getTarget().getName(), 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));
    // now rollback.
    result = client.module(IndyPromoteClientModule.class).rollbackGroupPromote(result);
    assertThat(result.getError(), nullValue());
    // wait for events to propagate and remove indexed values.
    Thread.sleep(2000);
    assertThat(client.content().exists(target.getKey().getType(), target.getName(), first), equalTo(false));
    assertThat(client.content().exists(target.getKey().getType(), target.getName(), second), equalTo(false));
    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) IndyPromoteClientModule(org.commonjava.indy.promote.client.IndyPromoteClientModule) Test(org.junit.Test)

Example 57 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class GroupPromoteMatchesSucceedingValidationAsyncTest method run.

@Test
public void run() throws Exception {
    GroupPromoteResult result = client.module(IndyPromoteClientModule.class).promoteToGroup(getAsyncRequest(new GroupPromoteRequest(source.getKey(), target.getName())));
    assertEquals(result.getResultCode(), ACCEPTED);
    result = getAsyncPromoteResult(GroupPromoteResult.class);
    assertThat(result.succeeded(), equalTo(true));
    assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
    assertThat(result.getRequest().getTarget().getName(), 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 58 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class GroupTest method copyFidelity.

@Test
public void copyFidelity() {
    Group src = new Group(GENERIC_PKG_KEY, "test");
    src.setMetadata("key", "value");
    src.setDescription("some description");
    src.setDisableTimeout(500);
    src.setDisabled(true);
    src.setTransientMetadata("transient", "someval");
    src.setPathStyle(PathStyle.hashed);
    src.addConstituent(new StoreKey(GENERIC_PKG_KEY, remote, "foo"));
    Group target = src.copyOf();
    Stream.of(Group.class.getMethods()).filter(m -> m.getName().startsWith("get") && m.isAccessible() && m.getParameterCount() == 0).forEach(m -> {
        try {
            assertThat(m.getName() + " didn't get copied correctly!", m.invoke(target), equalTo(m.invoke(src)));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            fail("Failed to invoke: " + m.getName());
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    });
}
Also used : CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) StoreType(org.commonjava.indy.model.core.StoreType) Test(org.junit.Test) Group(org.commonjava.indy.model.core.Group) InvocationTargetException(java.lang.reflect.InvocationTargetException) Assert.assertThat(org.junit.Assert.assertThat) Stream(java.util.stream.Stream) StoreType.remote(org.commonjava.indy.model.core.StoreType.remote) StoreType.hosted(org.commonjava.indy.model.core.StoreType.hosted) Assert.fail(org.junit.Assert.fail) PathStyle(org.commonjava.indy.model.core.PathStyle) GENERIC_PKG_KEY(org.commonjava.indy.model.core.GenericPackageTypeDescriptor.GENERIC_PKG_KEY) StoreKey(org.commonjava.indy.model.core.StoreKey) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) Group(org.commonjava.indy.model.core.Group) StoreKey(org.commonjava.indy.model.core.StoreKey) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 59 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class AbstractCoreUrlsTest method before.

@Before
public void before() throws Exception {
    if (!createStandardTestStructures()) {
        return;
    }
    final String changelog = "Create test structures";
    final HostedRepository hosted = this.client.stores().create(new HostedRepository(STORE), changelog, HostedRepository.class);
    Group g;
    if (client.stores().exists(group, PUBLIC)) {
        System.out.println("Loading pre-existing public group.");
        g = client.stores().load(group, PUBLIC, Group.class);
    } else {
        System.out.println("Creating new group 'public'");
        g = client.stores().create(new Group(PUBLIC), changelog, Group.class);
    }
    g.setConstituents(Collections.singletonList(hosted.getKey()));
    client.stores().update(g, changelog);
}
Also used : Group(org.commonjava.indy.model.core.Group) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Before(org.junit.Before)

Example 60 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class MaintenanceController method getTombstoneStores.

public Set<StoreKey> getTombstoneStores(String packageType) throws IndyDataException {
    List<HostedRepository> stores = storeDataManager.query().getAllHostedRepositories(packageType);
    Set<StoreKey> tombstoneStores = new HashSet<>();
    for (HostedRepository hosted : stores) {
        StoreKey key = hosted.getKey();
        ConcreteResource root = new ConcreteResource(LocationUtils.toLocation(hosted), PathUtils.ROOT);
        String[] files = cacheProvider.list(root);
        if (files == null || files.length == 0) {
            logger.debug("Empty store: {}", key);
            Set<Group> affected = storeDataManager.affectedBy(Arrays.asList(key));
            if (affected == null || affected.isEmpty()) {
                logger.info("Find tombstone store (no content and not in any group): {}", key);
                tombstoneStores.add(key);
            }
        }
    }
    return tombstoneStores;
}
Also used : Group(org.commonjava.indy.model.core.Group) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) StoreKey(org.commonjava.indy.model.core.StoreKey) HostedRepository(org.commonjava.indy.model.core.HostedRepository) HashSet(java.util.HashSet)

Aggregations

Group (org.commonjava.indy.model.core.Group)211 Test (org.junit.Test)111 HostedRepository (org.commonjava.indy.model.core.HostedRepository)89 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)82 StoreKey (org.commonjava.indy.model.core.StoreKey)76 ByteArrayInputStream (java.io.ByteArrayInputStream)67 InputStream (java.io.InputStream)62 IndyDataException (org.commonjava.indy.data.IndyDataException)44 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)42 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)42 Transfer (org.commonjava.maven.galley.model.Transfer)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)30 Logger (org.slf4j.Logger)30 Before (org.junit.Before)29 StoreDataManager (org.commonjava.indy.data.StoreDataManager)27 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)27 HashSet (java.util.HashSet)26 ArrayList (java.util.ArrayList)25 List (java.util.List)22 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)22