use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class TimeoutEventListener method onFileAccessEvent.
public void onFileAccessEvent(@Observes final FileAccessEvent event) {
// TODO: handle this stuff in Weft somehow...
Map original = MDC.getCopyOfContextMap();
try {
MDC.setContextMap(event.getMDCMap());
final StoreKey key = getKey(event);
if (key != null) {
final Transfer transfer = event.getTransfer();
final StoreType type = key.getType();
if (type == StoreType.hosted) {
try {
scheduleManager.setSnapshotTimeouts(key, transfer.getPath());
} catch (final IndySchedulerException e) {
logger.error("Failed to set snapshot timeouts related to: " + transfer, e);
}
} else if (type == StoreType.remote) {
SpecialPathInfo info = specialPathManager.getSpecialPathInfo(transfer);
if (info == null || !info.isMetadata()) {
logger.debug("Accessed resource {} timeout will be reset.", transfer);
try {
scheduleManager.setProxyTimeouts(key, transfer.getPath());
} catch (final IndySchedulerException e) {
logger.error("Failed to set proxy-cache timeouts related to: " + transfer, e);
}
} else {
logger.debug("Accessed resource {} is metadata. NOT rescheduling timeout!", transfer);
}
}
}
} finally {
if (original != null && !original.isEmpty()) {
MDC.setContextMap(original);
} else {
MDC.setContextMap(Collections.emptyMap());
}
}
}
use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class SuccessiveRetrievalWithRemoteRepoDeletionBetweenTest method run.
@Test
public void run() throws Exception {
final String testRepo = "test";
final PomRef pom = loadPom("simple.pom", Collections.<String, String>emptyMap());
final String url = server.formatUrl(testRepo, pom.path);
server.expect(url, 200, pom.pom);
Stream.of(1, 2).forEach((currentTry) -> {
CloseableHttpResponse response = null;
InputStream stream = null;
final HttpGet get = new HttpGet(url);
CloseableHttpClient httpClient = null;
try {
httpClient = proxiedHttp();
response = httpClient.execute(get);
stream = response.getEntity().getContent();
final String resultingPom = IOUtils.toString(stream);
assertThat(currentTry + ": retrieved POM was null!", resultingPom, notNullValue());
assertThat(currentTry + ": retrieved POM contains wrong content!", resultingPom, equalTo(pom.pom));
} catch (Exception e) {
e.printStackTrace();
fail(currentTry + ": Failed to retrieve file: " + url);
} finally {
IOUtils.closeQuietly(stream);
HttpResources.cleanupResources(get, response, httpClient);
}
try {
client.stores().delete(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, REMOTE_NAME), "Deleting for pass: " + currentTry);
} catch (IndyClientException e) {
fail("Failed to delete remote repo: " + REMOTE_NAME);
}
});
final RemoteRepository remoteRepo = this.client.stores().load(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, REMOTE_NAME), RemoteRepository.class);
assertThat(remoteRepo, nullValue());
}
use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class ImpliedRepoClientModule method setStoresImpliedBy.
public void setStoresImpliedBy(final ArtifactStore store, final List<StoreKey> implied, final String changelog) throws IndyClientException {
final List<ArtifactStore> stores = new ArrayList<>();
for (final StoreKey storeKey : implied) {
final ArtifactStore is = getClient().stores().load(storeKey.getType(), storeKey.getName(), storeKey.getType().getStoreClass());
if (is == null) {
throw new IndyClientException("No such store: %s. Cannot add to the implied-store list for: %s", storeKey, store.getKey());
}
stores.add(is);
}
try {
metadataManager.addImpliedMetadata(store, stores);
} catch (final ImpliedReposException e) {
throw new IndyClientException("Failed to set implied-store metadata: %s", e, e.getMessage());
}
stores.add(store);
for (final ArtifactStore toSave : stores) {
logger.info("Updating implied-store metadata in: {} triggered by adding implications to: {}", toSave.getKey(), store.getKey());
getClient().stores().update(toSave, changelog);
}
}
use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class ImpliedRepoMaintainer method updateImpliedStores.
// FIXME: How to tell whether a repo that is implied by other repos was added manually???
// That, vs. just left there after the repo that implied it was removed???
// We cannot currently remove formerly implied repos because we can't distinguish between the above states.
public void updateImpliedStores(@Observes final ArtifactStorePreUpdateEvent event) {
if (!storeManager.isStarted()) {
return;
}
if (!config.isEnabled()) {
logger.debug("Implied-repository processing is not enabled.");
return;
}
try {
// TODO: Update for changes map.
final Map<StoreKey, ArtifactStore> currentStores = mapStores(event);
for (final ArtifactStore store : event) {
logger.debug("Processing store: {} for implied repo metadata", store);
processStore(store, currentStores);
}
} catch (Throwable error) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.error(String.format("Implied-repository maintenance failed: %s", error.getMessage()), error);
}
}
use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class ImpliedRepositoryDetector method updateExistingGroups.
private boolean updateExistingGroups(final ImplicationsJob job) {
final StoreKey key = job.store.getKey();
boolean anyChanged = false;
try {
final Set<Group> groups = storeManager.query().packageType(MAVEN_PKG_KEY).getGroupsContaining(key);
if (groups != null) {
logger.debug("{} groups contain: {}\n {}", groups.size(), key, new JoinString("\n ", groups));
final String message = String.format("Adding repositories implied by: %s\n\n %s", key, StringUtils.join(job.implied, "\n "));
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, message);
for (final Group g : groups) {
Group group = g.copyOf();
boolean changed = false;
for (final ArtifactStore implied : job.implied) {
boolean groupChanged = group.addConstituent(implied);
changed = groupChanged || changed;
logger.debug("After attempting to add: {} to group: {}, changed status is: {}", implied, group, changed);
}
if (changed) {
storeManager.storeArtifactStore(group, summary, false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, IMPLIED_REPOS_DETECTION).set(IMPLIED_REPOS, job.implied));
}
anyChanged = changed || anyChanged;
}
}
} catch (final IndyDataException e) {
logger.error("Failed to lookup groups containing: " + key, e);
}
return anyChanged;
}
Aggregations