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;
}
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;
}
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;
}
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();
}
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;
}
Aggregations