use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class DefaultArtifactStoreQuery method getRemoteRepositoryByUrl.
@Override
@Measure
public List<RemoteRepository> getRemoteRepositoryByUrl(String packageType, String url, Boolean enabled) throws IndyDataException {
/*
This filter does these things:
* First compare ip, if ip same, and the path(without last slash) same too, the repo is found
* If ip not same, then compare the url without scheme and last slash (if has) to find the repo
*/
List<RemoteRepository> result = emptyList();
UrlInfo temp;
try {
temp = new UrlInfo(url);
} catch (Exception error) {
logger.error("Failed to find repository, url: '{}'. Reason: {}", url, error.getMessage());
return result;
}
final UrlInfo urlInfo = temp;
// first try to find the remote repo by urlWithNoSchemeAndLastSlash
final List<RemoteRepository> remoteRepos = getAllRemoteRepositories(packageType, enabled);
result = remoteRepos.stream().filter(store -> {
final String targetUrl = store.getUrl();
UrlInfo targetUrlInfo;
try {
targetUrlInfo = new UrlInfo(targetUrl);
} catch (Exception error) {
logger.warn("Invalid repository, store: {}, url: '{}'. Reason: {}", store.getKey(), targetUrl, error.getMessage());
return false;
}
if (targetUrlInfo != null) {
if (urlInfo.getUrlWithNoSchemeAndLastSlash().equals(targetUrlInfo.getUrlWithNoSchemeAndLastSlash()) && urlInfo.getProtocol().equals(targetUrlInfo.getProtocol())) {
logger.debug("Repository found because of same host, url is {}, store key is {}", url, store.getKey());
return true;
}
}
return false;
}).collect(Collectors.toList());
if (result.isEmpty()) {
// ...if not found by hostname try to search by IP
/* @formatter:off */
result = remoteRepos.stream().filter(store -> {
final String targetUrl = store.getUrl();
UrlInfo targetUrlInfo;
try {
targetUrlInfo = new UrlInfo(targetUrl);
} catch (Exception error) {
logger.warn("Invalid repository, store: {}, url: '{}'. Reason: {}", store.getKey(), targetUrl, error.getMessage());
return false;
}
if (targetUrlInfo != null) {
String ipForUrl = null;
String ipForTargetUrl = null;
try {
ipForUrl = urlInfo.getIpForUrl();
ipForTargetUrl = targetUrlInfo.getIpForUrl();
if (ipForUrl != null && ipForUrl.equals(ipForTargetUrl) && urlInfo.getPort() == targetUrlInfo.getPort() && urlInfo.getFileWithNoLastSlash().equals(targetUrlInfo.getFileWithNoLastSlash())) {
logger.debug("Repository found because of same ip, url is {}, store key is {}", url, store.getKey());
return true;
}
} catch (UnknownHostException ue) {
logger.warn("Failed to filter remote: ip fetch error.", ue);
}
logger.debug("ip not same: ip for url:{}-{}; ip for searching repo: {}-{}", url, ipForUrl, store.getKey(), ipForTargetUrl);
}
return false;
}).collect(Collectors.toList());
/* @formatter:on */
}
return result;
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class AbstractStoreDataManager method deleteArtifactStore.
@Override
@Measure
public void deleteArtifactStore(final StoreKey key, final ChangeSummary summary, final EventMetadata eventMetadata) throws IndyDataException {
AtomicReference<IndyDataException> error = new AtomicReference<>();
opLocks.lockAnd(key, LOCK_TIMEOUT_SECONDS, k -> {
try {
final ArtifactStore store = getArtifactStoreInternal(k);
if (store == null) {
logger.warn("No store found for: {}", k);
return null;
}
if (isReadonly(store)) {
throw new IndyDataException(ApplicationStatus.METHOD_NOT_ALLOWED.code(), "The store {} is readonly. If you want to delete this store, please modify it to non-readonly", store.getKey());
}
preDelete(store, summary, true, eventMetadata);
ArtifactStore removed = removeArtifactStoreInternal(k);
logger.info("REMOVED store: {}", removed);
postDelete(store, summary, true, eventMetadata);
} catch (IndyDataException e) {
error.set(e);
}
return null;
}, (k, lock) -> {
error.set(new IndyDataException("Failed to lock: %s for DELETE after %d seconds.", k, LOCK_TIMEOUT_SECONDS));
return false;
});
IndyDataException ex = error.get();
if (ex != null) {
throw ex;
}
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class ContentIndexActions method clearMergedPath.
@Measure
public void clearMergedPath(ArtifactStore originatingStore, Set<Group> groups, String path) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Clearing merged path: {} from indexes of: {} (triggered by: {})", path, groups, originatingStore);
StoreKey key = originatingStore.getKey();
ThreadContext context = ThreadContext.getContext(true);
context.put(ORIGIN_KEY, key);
try {
// the only time a group will have local storage of the path is when it has been merged
// ...in which case we should try to delete it.
indexManager.clearIndexedPathFrom(path, groups, null);
} finally {
context.remove(ORIGIN_KEY);
}
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class DefaultContentIndexManager method clearAllIndexedPathInStore.
@Override
@Measure
public void clearAllIndexedPathInStore(ArtifactStore store) {
if (!config.isEnabled()) {
logger.debug("Content indexing is disabled.");
return;
}
StoreKey sk = store.getKey();
long total = iterateRemove(() -> queryFactory.from(IndexedStorePath.class).maxResults(ITERATE_RESULT_SIZE).having("packageType").eq(sk.getPackageType()).and().having("storeType").eq(sk.getType().name()).and().having("storeName").eq(sk.getName()).toBuilder().build());
logger.debug("Cleared all indices with group: {}, size: {}", sk, total);
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class DefaultContentIndexManager method clearAllIndexedPathWithOriginalStore.
@Override
@Measure
public void clearAllIndexedPathWithOriginalStore(ArtifactStore originalStore) {
if (!config.isEnabled()) {
logger.debug("Content indexing is disabled.");
return;
}
StoreKey osk = originalStore.getKey();
long total = iterateRemove(() -> queryFactory.from(IndexedStorePath.class).maxResults(ITERATE_RESULT_SIZE).having("packageType").eq(osk.getPackageType()).and().having("originStoreType").eq(osk.getType().name()).and().having("originStoreName").eq(osk.getName()).toBuilder().build());
logger.debug("Cleared all indices with origin: {}, size: {}", osk, total);
}
Aggregations