Search in sources :

Example 1 with Measure

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;
}
Also used : UrlInfo(org.commonjava.indy.util.UrlInfo) UnknownHostException(java.net.UnknownHostException) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) UnknownHostException(java.net.UnknownHostException) IndyDataException(org.commonjava.indy.data.IndyDataException) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 2 with Measure

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;
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) AtomicReference(java.util.concurrent.atomic.AtomicReference) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 3 with Measure

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);
    }
}
Also used : ThreadContext(org.commonjava.cdi.util.weft.ThreadContext) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 4 with Measure

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);
}
Also used : StoreKey(org.commonjava.indy.model.core.StoreKey) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 5 with Measure

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);
}
Also used : StoreKey(org.commonjava.indy.model.core.StoreKey) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Aggregations

Measure (org.commonjava.o11yphant.metrics.annotation.Measure)65 StoreKey (org.commonjava.indy.model.core.StoreKey)23 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)19 Transfer (org.commonjava.maven.galley.model.Transfer)19 Logger (org.slf4j.Logger)19 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)16 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)14 IndyDataException (org.commonjava.indy.data.IndyDataException)13 ArrayList (java.util.ArrayList)12 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)11 HashSet (java.util.HashSet)9 Group (org.commonjava.indy.model.core.Group)8 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)8 BoundStatement (com.datastax.driver.core.BoundStatement)6 StoreDataManager (org.commonjava.indy.data.StoreDataManager)6 StoreKey.fromString (org.commonjava.indy.model.core.StoreKey.fromString)6 Query (org.infinispan.query.dsl.Query)6 IOException (java.io.IOException)5 Set (java.util.Set)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5