Search in sources :

Example 11 with Group

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

the class MavenMetadataMergerTest method mergeOneTransferWithProviderError.

@Test
public void mergeOneTransferWithProviderError() throws Exception {
    String path = "org/foo/bar/maven-metadata.xml";
    HostedRepository h1 = new HostedRepository("test-hosted-1");
    Transfer t1 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h1), path));
    initTestData(t1, VERSION_META + "simple-1.xml");
    Group g = new Group("test-group", h1.getKey());
    List<Transfer> sources = Arrays.asList(t1);
    TestMavenMetadataProvider testProvider = new TestMavenMetadataProvider(new IndyWorkflowException("Failed to get provider content"));
    byte[] output = new MavenMetadataMerger(Collections.singletonList(testProvider)).merge(sources, g, path);
    Metadata merged = new MetadataXpp3Reader().read(new ByteArrayInputStream(output));
    assertThat(merged.getGroupId(), equalTo("org.foo"));
    assertThat(merged.getArtifactId(), equalTo("bar"));
    Versioning versioning = merged.getVersioning();
    assertThat(versioning, notNullValue());
    List<String> versions = versioning.getVersions();
    assertThat(versions, notNullValue());
    assertThat(versions.size(), equalTo(1));
    assertThat(versioning.getRelease(), equalTo("1.0"));
    assertThat(versioning.getLatest(), equalTo("1.0"));
    int idx = 0;
    assertThat(versions.get(idx), equalTo("1.0"));
}
Also used : Group(org.commonjava.indy.model.core.Group) MetadataXpp3Reader(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) ByteArrayInputStream(java.io.ByteArrayInputStream) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 12 with Group

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

the class AutoProxDataManagerDecorator method getGroup.

private Group getGroup(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
    logger.debug("DECORATED (getGroup: {})", key);
    Group g = (Group) dataManager.getArtifactStore(key);
    if (!catalog.isEnabled()) {
        logger.debug("AutoProx decorator disabled; returning: {}", g);
        return g;
    }
    logger.debug("AutoProx decorator active");
    if (g == null) {
        logger.debug("AutoProx: creating repository for: {}", key);
        if (!checkValidity(key)) {
            return null;
        }
        try {
            g = catalog.createGroup(key);
        } catch (final AutoProxRuleException e) {
            throw new IndyDataException("[AUTOPROX] Failed to create new group from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
        }
        if (g != null) {
            logger.info("Validating group: {}", g);
            for (final StoreKey memberKey : new ArrayList<>(g.getConstituents())) {
                final ArtifactStore store = getArtifactStore(memberKey, impliedBy == null ? g.getKey() : impliedBy);
                if (store == null) {
                    g.removeConstituent(memberKey);
                }
            }
            if (g.getConstituents().isEmpty()) {
                return null;
            }
            final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? g.getKey() : impliedBy);
            dataManager.storeArtifactStore(g, new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating group for: '" + key + "'"), false, true, eventMetadata);
        }
    }
    return g;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 13 with Group

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

the class TestAutoProxFactory method createGroup.

@Override
public Group createGroup(final StoreKey key) {
    final List<StoreKey> constituents = new ArrayList<StoreKey>();
    constituents.add(new StoreKey(key.getPackageType(), StoreType.hosted, key.getName()));
    constituents.add(new StoreKey(key.getPackageType(), StoreType.remote, key.getName()));
    constituents.add(new StoreKey(key.getPackageType(), StoreType.remote, "first"));
    constituents.add(new StoreKey(key.getPackageType(), StoreType.remote, "second"));
    return new Group(key.getPackageType(), key.getName(), constituents);
}
Also used : Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 14 with Group

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

the class AutoProxCatalogManager method createGroup.

public Group createGroup(final StoreKey key) throws AutoProxRuleException {
    if (!checkEnabled()) {
        throw new AutoProxRuleException("AutoProx is disabled");
    }
    final AutoProxRule rule = getRuleMatching(key);
    try {
        if (rule != null) {
            Group group = rule.createGroup(key);
            group.setMetadata(ArtifactStore.METADATA_ORIGIN, AUTOPROX_ORIGIN);
            return group;
        }
        return null;
    } catch (final Exception e) {
        throw new AutoProxRuleException("Failed to create remote repository for: %s. Reason: %s", e, key, e.getMessage());
    }
}
Also used : Group(org.commonjava.indy.model.core.Group) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 15 with Group

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

the class AutoProxDataManagerDecoratorTest method groupNotAutoCreatedWhenTargetIsInvalid.

@Test
public void groupNotAutoCreatedWhenTargetIsInvalid() throws Exception {
    simpleCatalog();
    final String testUrl = http.formatUrl("target", "test");
    http.expect(testUrl, 404, "");
    catalog.setEnabled(false);
    assertThat(storeQuery.getGroup("test"), nullValue());
    catalog.setEnabled(true);
    final Group group = storeQuery.getGroup("test");
    assertThat(group, nullValue());
}
Also used : Group(org.commonjava.indy.model.core.Group) Test(org.junit.Test)

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