Search in sources :

Example 61 with StoreKey

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

the class FoloRecordCacheTest method clearRecordDeletesRecord.

@Test
public void clearRecordDeletesRecord() throws Exception {
    final TrackingKey key = newKey();
    assertThat(cache.hasRecord(key), equalTo(false));
    cache.recordArtifact(new TrackedContentEntry(key, new StoreKey(StoreType.remote, "foo"), AccessChannel.MAVEN_REPO, "", "/path", StoreEffect.DOWNLOAD, 127L, "", "", ""));
    TrackedContent record = cache.seal(key);
    assertThat(record, notNullValue());
    assertThat(cache.hasRecord(key), equalTo(true));
    cache.delete(key);
    assertThat(cache.hasRecord(key), equalTo(false));
    assertThat(cache.get(key), nullValue());
}
Also used : TrackedContent(org.commonjava.indy.folo.model.TrackedContent) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) Test(org.junit.Test)

Example 62 with StoreKey

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

the class GroupDataManagerTCK method createTwoGroupsAndAffectedByForOneLevel.

@Test
public void createTwoGroupsAndAffectedByForOneLevel() throws Exception {
    final StoreDataManager manager = getFixtureProvider().getDataManager();
    final StoreKey central = new StoreKey(StoreType.remote, "central");
    final StoreKey repo2 = new StoreKey(StoreType.remote, "repo2");
    Group g1 = new Group("g1", central);
    Group g2 = new Group("g2", repo2);
    store(g1, g2);
    List<StoreKey> keys = Arrays.asList(central, repo2);
    Set<StoreKey> gKeys = manager.query().getGroupsAffectedBy(keys).stream().map(Group::getKey).collect(Collectors.toSet());
    assertThat(gKeys.contains(g1.getKey()), equalTo(Boolean.TRUE));
    assertThat(gKeys.contains(g2.getKey()), equalTo(Boolean.TRUE));
}
Also used : Group(org.commonjava.indy.model.core.Group) StoreDataManager(org.commonjava.indy.data.StoreDataManager) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 63 with StoreKey

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

the class PackageMetadataMerger method merge.

public byte[] merge(final Collection<Transfer> sources, final Group group, final String path) {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Generating merged metadata in: {}:{}", group.getKey(), path);
    InputStream stream = null;
    boolean merged = false;
    final PackageMetadata packageMetadata = new PackageMetadata();
    final IndyObjectMapper mapper = new IndyObjectMapper(true);
    for (final Transfer src : sources) {
        if (!src.exists()) {
            continue;
        }
        try {
            stream = src.openInputStream();
            String content = IOUtils.toString(stream);
            logger.debug("Adding in metadata content from: {}\n\n{}\n\n", src, content);
            PackageMetadata md = mapper.readValue(content, PackageMetadata.class);
            merged = packageMetadata.merge(md) || merged;
        } catch (final IOException e) {
            final StoreKey key = getKey(src);
            logger.error(String.format("Cannot read metadata: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
        } finally {
            closeQuietly(stream);
        }
    }
    if (metadataProviders != null) {
        for (PackageMetadataProvider provider : metadataProviders) {
            try {
                PackageMetadata toMerge = provider.getMetadata(group.getKey(), path);
                if (toMerge != null) {
                    merged = packageMetadata.merge(toMerge) || merged;
                }
            } catch (IndyWorkflowException e) {
                logger.error(String.format("Cannot read metadata: %s from metadata provider: %s. Reason: %s", path, provider.getClass().getSimpleName(), e.getMessage()), e);
            }
        }
    }
    if (merged) {
        String output = null;
        try {
            output = mapper.writeValueAsString(packageMetadata);
        } catch (JsonProcessingException e) {
            logger.error(String.format("Cannot convert from metadata: %s to String. Reason: %s", packageMetadata, e.getMessage()), e);
        }
        return output.getBytes();
    }
    return null;
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) InputStream(java.io.InputStream) PackageMetadata(org.commonjava.indy.pkg.npm.model.PackageMetadata) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 64 with StoreKey

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

the class KojiMavenMetadataProviderTest method excludeBinaryImportsFromVersionMetadata.

@Test
public void excludeBinaryImportsFromVersionMetadata() throws Exception {
    initKojiClient("metadata-with-import-generate", false);
    Metadata metadata = provider.getMetadata(new StoreKey(MAVEN_PKG_KEY, group, "public"), "commons-io/commons-io/maven-metadata.xml");
    assertThat(metadata, notNullValue());
    StringWriter sw = new StringWriter();
    new MetadataXpp3Writer().write(sw, metadata);
    System.out.println(sw.toString());
    Versioning versioning = metadata.getVersioning();
    assertThat(versioning, notNullValue());
    assertThat(versioning.getLatest(), equalTo("2.4.0.redhat-1"));
    assertThat(versioning.getRelease(), equalTo("2.4.0.redhat-1"));
    List<String> versions = versioning.getVersions();
    assertThat(versions, notNullValue());
    assertThat(versions.size(), equalTo(1));
    int idx = 0;
    assertThat(versions.get(idx), equalTo("2.4.0.redhat-1"));
}
Also used : Versioning(org.apache.maven.artifact.repository.metadata.Versioning) MetadataXpp3Writer(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer) StringWriter(java.io.StringWriter) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 65 with StoreKey

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

the class KojiMavenMetadataProviderTest method metadataNullWhenNoVersionsFound.

@Test
public void metadataNullWhenNoVersionsFound() throws Exception {
    initKojiClient("no-metadata-generate", false);
    Metadata metadata = provider.getMetadata(new StoreKey(MAVEN_PKG_KEY, group, "public"), "commons-io/commons-io/maven-metadata.xml");
    assertThat(metadata, nullValue());
}
Also used : EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Aggregations

StoreKey (org.commonjava.indy.model.core.StoreKey)186 Test (org.junit.Test)92 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)40 StoreType (org.commonjava.indy.model.core.StoreType)39 InputStream (java.io.InputStream)33 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)32 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)31 IndyDataException (org.commonjava.indy.data.IndyDataException)30 Group (org.commonjava.indy.model.core.Group)29 Transfer (org.commonjava.maven.galley.model.Transfer)27 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)24 Response (javax.ws.rs.core.Response)23 IOException (java.io.IOException)22 Logger (org.slf4j.Logger)21 ApiOperation (io.swagger.annotations.ApiOperation)20 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)20 ArrayList (java.util.ArrayList)19 Path (javax.ws.rs.Path)19 ApiResponse (io.swagger.annotations.ApiResponse)18 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)18