Search in sources :

Example 31 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class ContentIndexManager method clearIndexedPathFrom.

/**
     * <b>NOT Recursive</b>. This assumes you've recursed the group membership structure beforehand, using
     * {@link StoreDataManager#getGroupsAffectedBy(Collection)} to find the set of {@link Group} instances for which
     * the path should be cleared.
     */
public void clearIndexedPathFrom(String path, Set<Group> groups, Consumer<IndexedStorePath> pathConsumer) {
    if (groups == null || groups.isEmpty()) {
        return;
    }
    Logger logger = LoggerFactory.getLogger(getClass());
    //        logger.debug( "Clearing path: '{}' from content index and storage of: {}", path, groups );
    groups.forEach((group) -> {
        logger.debug("Clearing path: '{}' from content index and storage of: {}", path, group.getName());
        // if we remove an indexed path, it SHOULD mean there was content. If not, we should delete the NFC entry.
        if (!removeIndexedStorePath(path, group.getKey(), pathConsumer)) {
            ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(group), path);
            nfc.clearMissing(resource);
        }
    });
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger)

Example 32 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class IndexingContentManagerDecorator method store.

//    @Override
//    public Transfer store( final List<? extends ArtifactStore> stores, final String path, final InputStream stream, final TransferOperation op )
//            throws IndyWorkflowException
//    {
//        return store( stores, path, stream, op, new EventMetadata() );
//    }
@Override
public Transfer store(final List<? extends ArtifactStore> stores, final StoreKey topKey, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
    Transfer transfer = delegate.store(stores, topKey, path, stream, op, eventMetadata);
    if (transfer != null) {
        indexManager.indexTransferIn(transfer, topKey);
        try {
            ArtifactStore topStore = storeDataManager.getArtifactStore(topKey);
            nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(topStore), path));
        } catch (IndyDataException e) {
            Logger logger = LoggerFactory.getLogger(getClass());
            logger.error(String.format("Failed to retrieve top store: %s for NFC management. Reason: %s", topKey, e.getMessage()), e);
        }
    }
    return transfer;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger)

Example 33 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class IndexingContentManagerDecorator method retrieve.

@Override
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.trace("Looking for indexed path: {} in: {}", path, store.getKey());
    Transfer transfer = getIndexedTransfer(store.getKey(), null, path, TransferOperation.DOWNLOAD);
    if (transfer != null) {
        logger.debug("Found indexed transfer: {}. Returning.", transfer);
        return transfer;
    }
    StoreType type = store.getKey().getType();
    if (StoreType.group == type) {
        ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
        if (nfc.isMissing(resource)) {
            logger.debug("{} is marked as missing. Returning null.", resource);
            return null;
        }
        logger.debug("No group index hits. Devolving to member store indexes.");
        KeyedLocation location = LocationUtils.toLocation(store);
        SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(location, path, store.getPackageType());
        if (specialPathInfo == null || !specialPathInfo.isMergable()) {
            transfer = getIndexedMemberTransfer((Group) store, path, TransferOperation.DOWNLOAD, (member) -> {
                try {
                    return delegate.retrieve(member, path);
                } catch (IndyWorkflowException e) {
                    logger.error(String.format("Failed to retrieve() for member path: %s:%s. Reason: %s", member.getKey(), path, e.getMessage()), e);
                }
                return null;
            });
            if (transfer != null) {
                nfc.clearMissing(resource);
                return transfer;
            }
            logger.debug("No index hits. Delegating to main content manager for: {} in: {}", path, store);
        } else {
            logger.debug("Merged content. Delegating to main content manager for: {} in: {}", path, store);
            transfer = delegate.retrieve(store, path, eventMetadata);
            if (transfer == null) {
                nfc.addMissing(resource);
            }
            return transfer;
        }
    }
    transfer = delegate.retrieve(store, path, eventMetadata);
    if (transfer != null) {
        logger.debug("Got transfer from delegate: {} (will index)", transfer);
        indexManager.indexTransferIn(transfer, store.getKey());
    }
    logger.debug("Returning transfer: {}", transfer);
    return transfer;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Delegate(javax.decorator.Delegate) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LoggerFactory(org.slf4j.LoggerFactory) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) Any(javax.enterprise.inject.Any) Decorator(javax.decorator.Decorator) StoreKey(org.commonjava.indy.model.core.StoreKey) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) ContentManager(org.commonjava.indy.content.ContentManager) Objects(java.util.Objects) List(java.util.List) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) InputStream(java.io.InputStream) Group(org.commonjava.indy.model.core.Group) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger)

Example 34 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class MavenMetadataGeneratorTest method generateFileContent_VersionsMetadataWith2Versions.

@Test
public void generateFileContent_VersionsMetadataWith2Versions() throws Exception {
    final StoreResource resource = setupVersionsStructureWith2Versions();
    final ConcreteResource metadataFile = resource.getChild("maven-metadata.xml");
    final Transfer transfer = generator.generateFileContent(stores.getArtifactStore(resource.getStoreKey()), metadataFile.getPath(), new EventMetadata());
    assertThat(transfer, notNullValue());
    final MavenMetadataView metadata = metadataReader.readMetadata(new SimpleProjectVersionRef("org.group", "artifact", "1.0-SNAPSHOT"), Collections.singletonList(transfer), new EventMetadata());
    assertThat(metadata, notNullValue());
    final VersioningView versioning = metadata.getVersioning();
    final List<SingleVersion> versions = versioning.getVersions();
    assertThat(versions, notNullValue());
    assertThat(versions.get(0).renderStandard(), equalTo("1.0"));
    assertThat(versions.get(1).renderStandard(), equalTo("1.1"));
    assertThat(versioning.getReleaseVersion().renderStandard(), equalTo("1.1"));
    assertThat(versioning.getLatestVersion().renderStandard(), equalTo("1.1"));
}
Also used : MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) VersioningView(org.commonjava.maven.galley.maven.model.view.meta.VersioningView) StoreResource(org.commonjava.indy.content.StoreResource) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 35 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class MavenMetadataGeneratorTest method setupVersionsStructureWith2Versions.

private StoreResource setupVersionsStructureWith2Versions() throws Exception {
    final RemoteRepository store = new RemoteRepository(MAVEN_PKG_KEY, "testrepo", "http://foo.bar");
    stores.storeArtifactStore(store, summary, false, true, new EventMetadata());
    final String path = "org/group/artifact";
    final KeyedLocation location = LocationUtils.toLocation(store);
    final StoreResource resource = new StoreResource(location, path);
    fixture.getTransport().registerListing(resource, new TestListing(new ListingResult(resource, new String[] { "1.0/", "1.1/" })));
    ConcreteResource versionDir = (resource.getChild("1.0/"));
    fixture.getTransport().registerListing(versionDir, new TestListing(new ListingResult(versionDir, new String[] { "artifact-1.0.jar", "artifact-1.0.pom" })));
    versionDir = (resource.getChild("1.1/"));
    fixture.getTransport().registerListing(versionDir, new TestListing(new ListingResult(versionDir, new String[] { "artifact-1.1.jar", "artifact-1.1.pom" })));
    return resource;
}
Also used : StoreResource(org.commonjava.indy.content.StoreResource) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) TestListing(org.commonjava.maven.galley.testing.core.transport.job.TestListing) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ListingResult(org.commonjava.maven.galley.model.ListingResult) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Aggregations

ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)122 Test (org.junit.Test)85 Transfer (org.commonjava.maven.galley.model.Transfer)63 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)35 Location (org.commonjava.maven.galley.model.Location)28 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)21 Group (org.commonjava.indy.model.core.Group)20 HashSet (java.util.HashSet)15 HostedRepository (org.commonjava.indy.model.core.HostedRepository)15 TransferException (org.commonjava.maven.galley.TransferException)15 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)15 BMScript (org.jboss.byteman.contrib.bmunit.BMScript)15 ByteArrayInputStream (java.io.ByteArrayInputStream)14 InputStream (java.io.InputStream)13 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)13 OutputStream (java.io.OutputStream)12 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)12 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)12 Logger (org.slf4j.Logger)12 ListingResult (org.commonjava.maven.galley.model.ListingResult)11