Search in sources :

Example 1 with ContentGenerator

use of org.commonjava.indy.content.ContentGenerator in project indy by Commonjava.

the class DefaultContentManager method store.

@Override
public Transfer store(final ArtifactStore store, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
    if (group == store.getKey().getType()) {
        try {
            final List<ArtifactStore> allMembers = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
            final Transfer txfr = store(allMembers, store.getKey(), path, stream, op, eventMetadata);
            logger.info("Stored: {} for group: {} in: {}", path, store.getKey(), txfr);
            return txfr;
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
        }
    }
    logger.info("Storing: {} for: {} with event metadata: {}", path, store.getKey(), eventMetadata);
    final Transfer txfr = downloadManager.store(store, path, stream, op, eventMetadata);
    if (txfr != null) {
        final KeyedLocation kl = (KeyedLocation) txfr.getLocation();
        ArtifactStore transferStore;
        try {
            transferStore = storeManager.getArtifactStore(kl.getKey());
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to lookup store: %s. Reason: %s", e, kl.getKey(), e.getMessage());
        }
        for (final ContentGenerator generator : contentGenerators) {
            generator.handleContentStorage(transferStore, path, txfr, eventMetadata);
        }
        if (!store.equals(transferStore)) {
            for (final ContentGenerator generator : contentGenerators) {
                generator.handleContentStorage(transferStore, path, txfr, eventMetadata);
            }
        }
    }
    return txfr;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ContentGenerator(org.commonjava.indy.content.ContentGenerator) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer)

Example 2 with ContentGenerator

use of org.commonjava.indy.content.ContentGenerator in project indy by Commonjava.

the class DefaultContentManager 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 {
    logger.info("Storing: {} in: {} with event metadata: {}", path, stores, eventMetadata);
    final Transfer txfr = downloadManager.store(stores, path, stream, op, eventMetadata);
    if (txfr != null) {
        final KeyedLocation kl = (KeyedLocation) txfr.getLocation();
        ArtifactStore transferStore;
        try {
            transferStore = storeManager.getArtifactStore(kl.getKey());
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to lookup store: %s. Reason: %s", e, kl.getKey(), e.getMessage());
        }
        for (final ContentGenerator generator : contentGenerators) {
            logger.info("{} Handling content storage of: {} in: {}", generator, path, transferStore.getKey());
            generator.handleContentStorage(transferStore, path, txfr, eventMetadata);
        }
    }
    return txfr;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ContentGenerator(org.commonjava.indy.content.ContentGenerator) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer)

Example 3 with ContentGenerator

use of org.commonjava.indy.content.ContentGenerator in project indy by Commonjava.

the class DefaultContentManager method retrieve.

@Override
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    Transfer item;
    if (group == store.getKey().getType()) {
        List<ArtifactStore> members;
        try {
            members = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
        }
        if (logger.isDebugEnabled()) {
            logger.debug("{} is a group. Attempting downloads from (in order):\n  {}", store.getKey(), StringUtils.join(members, "\n  "));
        }
        item = null;
        boolean generated = false;
        for (final ContentGenerator generator : contentGenerators) {
            if (generator.canProcess(path)) {
                item = generator.generateGroupFileContent((Group) store, members, path, eventMetadata);
                logger.debug("From content {}.generateGroupFileContent: {} (exists? {})", generator.getClass().getSimpleName(), item, item != null && item.exists());
                generated = true;
                break;
            }
        }
        if (!generated) {
            for (final ArtifactStore member : members) {
                try {
                    item = doRetrieve(member, path, eventMetadata);
                } catch (IndyWorkflowException e) {
                    logger.error("Failed to retrieve artifact from for path {} from {} in group {}, error is: {}", path, member, store, e.getMessage());
                }
                if (item != null) {
                    break;
                }
            }
        }
    } else {
        item = doRetrieve(store, path, eventMetadata);
    }
    logger.info("Returning transfer: {}", item);
    return item;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ContentGenerator(org.commonjava.indy.content.ContentGenerator) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer)

Example 4 with ContentGenerator

use of org.commonjava.indy.content.ContentGenerator in project indy by Commonjava.

the class PromotionManagerTest method setup.

@Before
public void setup() throws Exception {
    contentMetadata.clear();
    galleyParts = new GalleyMavenFixture(true, temp);
    galleyParts.initMissingComponents();
    storeManager = new MemoryStoreDataManager(true);
    downloadManager = new DefaultDownloadManager(storeManager, galleyParts.getTransferManager(), new IndyLocationExpander(storeManager), new MockInstance<>(new MockContentAdvisor()));
    DirectContentAccess dca = new DefaultDirectContentAccess(downloadManager, Executors.newSingleThreadExecutor());
    ContentDigester contentDigester = new DefaultContentDigester(dca, new CacheHandle<String, TransferMetadata>("content-metadata", contentMetadata));
    contentManager = new DefaultContentManager(storeManager, downloadManager, new IndyObjectMapper(true), new SpecialPathManagerImpl(), new MemoryNotFoundCache(), contentDigester, Collections.<ContentGenerator>emptySet());
    dataManager = new DataFileManager(temp.newFolder("data"), new DataFileEventManager());
    validationsManager = new PromoteValidationsManager(dataManager, new PromoteConfig(), new ValidationRuleParser(new ScriptEngine(dataManager), new IndyObjectMapper(true)));
    MavenModelProcessor modelProcessor = new MavenModelProcessor();
    validator = new PromotionValidator(validationsManager, new PromotionValidationTools(contentManager, storeManager, galleyParts.getPomReader(), galleyParts.getMavenMetadataReader(), modelProcessor, galleyParts.getTypeMapper(), galleyParts.getTransferManager(), contentDigester), storeManager);
    PromoteConfig config = new PromoteConfig();
    manager = new PromotionManager(validator, contentManager, downloadManager, storeManager, config);
    executor = Executors.newCachedThreadPool();
}
Also used : ValidationRuleParser(org.commonjava.indy.promote.validate.ValidationRuleParser) GalleyMavenFixture(org.commonjava.maven.galley.testing.maven.GalleyMavenFixture) DefaultContentManager(org.commonjava.indy.core.content.DefaultContentManager) MavenModelProcessor(org.commonjava.maven.galley.maven.rel.MavenModelProcessor) SpecialPathManagerImpl(org.commonjava.maven.galley.io.SpecialPathManagerImpl) ContentGenerator(org.commonjava.indy.content.ContentGenerator) DirectContentAccess(org.commonjava.indy.content.DirectContentAccess) DefaultDirectContentAccess(org.commonjava.indy.core.content.DefaultDirectContentAccess) MockInstance(org.commonjava.indy.test.fixture.core.MockInstance) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) MemoryStoreDataManager(org.commonjava.indy.mem.data.MemoryStoreDataManager) IndyLocationExpander(org.commonjava.indy.content.IndyLocationExpander) DefaultDownloadManager(org.commonjava.indy.core.content.DefaultDownloadManager) PromotionValidator(org.commonjava.indy.promote.validate.PromotionValidator) ContentDigester(org.commonjava.indy.content.ContentDigester) DefaultContentDigester(org.commonjava.indy.core.content.DefaultContentDigester) PromotionValidationTools(org.commonjava.indy.promote.validate.PromotionValidationTools) DefaultContentDigester(org.commonjava.indy.core.content.DefaultContentDigester) DataFileEventManager(org.commonjava.indy.subsys.datafile.change.DataFileEventManager) PromoteConfig(org.commonjava.indy.promote.conf.PromoteConfig) MemoryNotFoundCache(org.commonjava.maven.galley.nfc.MemoryNotFoundCache) ScriptEngine(org.commonjava.indy.subsys.template.ScriptEngine) PromoteValidationsManager(org.commonjava.indy.promote.validate.PromoteValidationsManager) DataFileManager(org.commonjava.indy.subsys.datafile.DataFileManager) MockContentAdvisor(org.commonjava.indy.test.fixture.core.MockContentAdvisor) DefaultDirectContentAccess(org.commonjava.indy.core.content.DefaultDirectContentAccess) Before(org.junit.Before)

Example 5 with ContentGenerator

use of org.commonjava.indy.content.ContentGenerator in project indy by Commonjava.

the class DefaultContentManager method retrieveAll.

@Override
public List<Transfer> retrieveAll(final List<? extends ArtifactStore> stores, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    final List<Transfer> txfrs = new ArrayList<>();
    for (final ArtifactStore store : stores) {
        if (group == store.getKey().getType()) {
            List<ArtifactStore> members;
            try {
                members = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
            } catch (final IndyDataException e) {
                throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
            }
            final List<Transfer> storeTransfers = new ArrayList<>();
            for (final ContentGenerator generator : contentGenerators) {
                final Transfer txfr = generator.generateGroupFileContent((Group) store, members, path, eventMetadata);
                if (txfr != null) {
                    storeTransfers.add(txfr);
                }
            }
            // ...if it's generated, it's merged in this case.
            if (storeTransfers.isEmpty()) {
                for (final ArtifactStore member : members) {
                    // NOTE: This is only safe to call because we're concrete ordered stores, so anything passing through here is concrete.
                    final Transfer txfr = doRetrieve(member, path, eventMetadata);
                    if (txfr != null) {
                        storeTransfers.add(txfr);
                    }
                }
            }
            txfrs.addAll(storeTransfers);
        } else {
            // NOTE: This is only safe to call because we're doing the group check up front, so anything passing through here is concrete.
            final Transfer txfr = doRetrieve(store, path, eventMetadata);
            if (txfr != null) {
                txfrs.add(txfr);
            }
        }
    }
    return txfrs;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ContentGenerator(org.commonjava.indy.content.ContentGenerator) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList) Transfer(org.commonjava.maven.galley.model.Transfer)

Aggregations

ContentGenerator (org.commonjava.indy.content.ContentGenerator)7 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)6 IndyDataException (org.commonjava.indy.data.IndyDataException)5 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)5 Transfer (org.commonjava.maven.galley.model.Transfer)5 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)2 ArrayList (java.util.ArrayList)1 ContentDigester (org.commonjava.indy.content.ContentDigester)1 DirectContentAccess (org.commonjava.indy.content.DirectContentAccess)1 IndyLocationExpander (org.commonjava.indy.content.IndyLocationExpander)1 StoreResource (org.commonjava.indy.content.StoreResource)1 DefaultContentDigester (org.commonjava.indy.core.content.DefaultContentDigester)1 DefaultContentManager (org.commonjava.indy.core.content.DefaultContentManager)1 DefaultDirectContentAccess (org.commonjava.indy.core.content.DefaultDirectContentAccess)1 DefaultDownloadManager (org.commonjava.indy.core.content.DefaultDownloadManager)1 MemoryStoreDataManager (org.commonjava.indy.mem.data.MemoryStoreDataManager)1 Group (org.commonjava.indy.model.core.Group)1 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)1 PromoteConfig (org.commonjava.indy.promote.conf.PromoteConfig)1 PromoteValidationsManager (org.commonjava.indy.promote.validate.PromoteValidationsManager)1