use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class ImpliedRepoMaintainerTest method dontRemoveImpliedRepoWhenRepoRemovedFromGroup.
@Test
public void dontRemoveImpliedRepoWhenRepoRemovedFromGroup() throws Exception {
final Group g = new Group(MAVEN_PKG_KEY, "test");
storeDataManager.storeArtifactStore(g, summary, false, true, new EventMetadata());
final RemoteRepository repo1 = new RemoteRepository(MAVEN_PKG_KEY, "one", "http://www.foo.com/repo");
storeDataManager.storeArtifactStore(repo1, summary, false, true, new EventMetadata());
final RemoteRepository repo2 = new RemoteRepository(MAVEN_PKG_KEY, "one", "http://www.foo.com/repo");
storeDataManager.storeArtifactStore(repo2, summary, false, true, new EventMetadata());
metadataManager.addImpliedMetadata(repo1, Collections.singletonList(repo2));
// Simulates removal of repo1...odd, I know, but since they post-process these updates, it's what the
// event observers would see.
g.addConstituent(repo2);
final ArtifactStorePreUpdateEvent event = new ArtifactStorePreUpdateEvent(ArtifactStoreUpdateType.UPDATE, new EventMetadata(), Collections.singletonMap(g.copyOf(), g));
maintainer.updateImpliedStores(event);
assertThat(g.getConstituents().contains(repo2.getKey()), equalTo(true));
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class ImpliedRepoMaintainerTest method addImpliedRepoWhenRepoAddedToGroup.
@Test
public void addImpliedRepoWhenRepoAddedToGroup() throws Exception {
final Group g = new Group(MAVEN_PKG_KEY, "test");
storeDataManager.storeArtifactStore(g, summary, false, true, new EventMetadata());
final RemoteRepository repo1 = new RemoteRepository(MAVEN_PKG_KEY, "one", "http://www.foo.com/repo");
storeDataManager.storeArtifactStore(repo1, summary, false, true, new EventMetadata());
final RemoteRepository repo2 = new RemoteRepository(MAVEN_PKG_KEY, "one", "http://www.foo.com/repo");
storeDataManager.storeArtifactStore(repo2, summary, false, true, new EventMetadata());
metadataManager.addImpliedMetadata(repo1, Collections.singletonList(repo2));
g.addConstituent(repo1);
final ArtifactStorePreUpdateEvent event = new ArtifactStorePreUpdateEvent(ArtifactStoreUpdateType.UPDATE, new EventMetadata(), Collections.singletonMap(g.copyOf(), g));
maintainer.updateImpliedStores(event);
assertThat(g.getConstituents().contains(repo2.getKey()), equalTo(true));
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class IndexingContentManagerDecorator method store.
@Override
@Measure
public Transfer store(final ArtifactStore store, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
if (!indexCfg.isEnabled()) {
return delegate.store(store, path, stream, op, eventMetadata);
}
Logger logger = LoggerFactory.getLogger(getClass());
logger.trace("Storing: {} in: {} from indexing level", path, store.getKey());
Transfer transfer = delegate.store(store, path, stream, op, eventMetadata);
if (transfer != null) {
if (indexCfg.isEnabled()) {
logger.trace("Indexing: {} in: {}", transfer, store.getKey());
indexManager.indexTransferIn(transfer, store.getKey());
}
nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
// may change the content index sequence based on the constituents sequence in parent groups
if (store.getType() == StoreType.hosted) {
final String name = String.format("ContentIndexStoreDeIndex-store(%s)-path(%s)", store.getKey(), path);
final String context = String.format("Class: %s, method: %s, store: %s, path: %s", this.getClass().getName(), "store", store.getKey(), path);
storeDataManager.asyncGroupAffectedBy(new StoreDataManager.ContextualTask(name, context, () -> {
try {
Set<Group> groups = storeDataManager.affectedBy(Arrays.asList(store.getKey()), eventMetadata);
if (groups != null && !groups.isEmpty() && indexCfg.isEnabled()) {
groups.forEach(g -> {
indexManager.deIndexStorePath(g.getKey(), path);
nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(g), path));
});
}
} catch (IndyDataException e) {
logger.error(String.format("Failed to get groups which contains: %s for NFC handling. Reason: %s", store.getKey(), e.getMessage()), e);
}
}));
}
}
return transfer;
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class IndexingContentManagerDecorator method getTransfer.
@Override
public Transfer getTransfer(final StoreKey storeKey, final String path, final TransferOperation op) throws IndyWorkflowException {
if (!indexCfg.isEnabled()) {
return delegate.getTransfer(storeKey, path, op);
}
Transfer transfer = getIndexedTransfer(storeKey, null, path, TransferOperation.DOWNLOAD, new EventMetadata());
if (exists(transfer)) {
logger.debug("Returning indexed transfer: {}", transfer);
return transfer;
}
ArtifactStore store;
try {
store = storeDataManager.getArtifactStore(storeKey);
} catch (IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup ArtifactStore: %s for NFC handling. Reason: %s", e, storeKey, e.getMessage());
}
if (isAuthoritativelyMissing(store)) {
logger.debug("Not found indexed transfer: {} and authoritative index switched on. Return null.", transfer);
return null;
}
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
StoreType type = storeKey.getType();
if (StoreType.group == type) {
Group g = (Group) store;
if (g == null) {
throw new IndyWorkflowException("Cannot find requested group: %s", storeKey);
}
if (nfc.isMissing(resource)) {
logger.debug("NFC / MISSING: {}", resource);
return null;
}
logger.debug("No group index hits. Devolving to member store indexes.");
transfer = getTransferFromConstituents(g.getConstituents(), resource, path, g, memberKey -> getTransfer(memberKey, path, op));
nfcForGroup(store, transfer, resource);
return transfer;
}
transfer = delegate.getTransfer(storeKey, path, op);
if (exists(transfer) && indexCfg.isEnabled()) {
logger.debug("Indexing transfer: {}", transfer);
indexManager.indexTransferIn(transfer, storeKey);
}
return transfer;
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class IndexingContentManagerDecorator method getTransfer.
@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation op) throws IndyWorkflowException {
if (!indexCfg.isEnabled()) {
return delegate.getTransfer(store, path, op);
}
Transfer transfer = getIndexedTransfer(store.getKey(), null, path, TransferOperation.DOWNLOAD, new EventMetadata());
if (exists(transfer)) {
return transfer;
} else if (isAuthoritativelyMissing(store)) {
logger.info("Not found indexed transfer: {} and authoritative index switched on. Considering not found and return null.", transfer);
return null;
}
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
StoreType type = store.getKey().getType();
if (StoreType.group == type) {
if (!nfc.isMissing(resource)) {
logger.debug("No group index hits. Devolving to member store indexes.");
transfer = getTransferFromConstituents(((Group) store).getConstituents(), resource, path, store, memberKey -> {
try {
ArtifactStore member = storeDataManager.getArtifactStore(memberKey);
return getTransfer(member, path, op);
} catch (IndyDataException e) {
logger.error(String.format("Failed to lookup store: %s (in membership of: %s). Reason: %s", memberKey, store.getKey(), e.getMessage()), e);
return null;
}
});
nfcForGroup(store, transfer, resource);
return transfer;
} else {
logger.debug("NFC marks {} as missing. Returning null.", resource);
return null;
}
}
transfer = delegate.getTransfer(store, path, op);
// index the transfer only if it exists, it cannot be null at this point
if (exists(transfer) && indexCfg.isEnabled()) {
indexManager.indexTransferIn(transfer, store.getKey());
}
logger.debug("Returning transfer: {}", transfer);
return transfer;
}
Aggregations