Search in sources :

Example 26 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class FoloPomDownloadListener method onFileUpload.

public void onFileUpload(@Observes final FileStorageEvent event) {
    // check for a TransferOperation of DOWNLOAD
    final TransferOperation op = event.getType();
    if (op != TransferOperation.DOWNLOAD) {
        logger.trace("Not a download transfer operation. No pom existence check performed.");
        return;
    }
    // check if it is a path that doesn't end in with ".pom"
    final Transfer transfer = event.getTransfer();
    if (transfer == null) {
        logger.trace("No transfer. No pom existence check performed.");
        return;
    }
    String txfrPath = transfer.getPath();
    if (txfrPath.endsWith(".pom")) {
        logger.trace("This is a pom download.");
        return;
    }
    // use ArtifactPathInfo to parse into a GAV, just to verify that it's looking at an artifact download
    ArtifactPathInfo artPathInfo = ArtifactPathInfo.parse(txfrPath);
    if (artPathInfo == null) {
        logger.trace("Not an artifact download ({}). No pom existence check performed.", txfrPath);
        return;
    }
    // verify that the associated .pom file exists
    String pomFilename = String.format("%s-%s.pom", artPathInfo.getArtifactId(), artPathInfo.getVersion());
    ConcreteResource pomResource = transfer.getResource().getParent().getChild(pomFilename);
    if (cacheProvider.exists(pomResource)) {
        logger.trace("Pom {} already exists.", cacheProvider.getFilePath(pomResource));
        return;
    }
    // trigger pom download by requesting it from the same repository as the original artifact
    StoreKey storeKey = StoreKey.fromString(transfer.getLocation().getName());
    ArtifactStore store;
    try {
        store = storeManager.getArtifactStore(storeKey);
    } catch (final IndyDataException ex) {
        logger.error("Error retrieving artifactStore with key " + storeKey, ex);
        return;
    }
    try {
        logger.debug("Downloading POM as automatic response to associated artifact download: {}/{}", storeKey, pomResource.getPath());
        contentManager.retrieve(store, pomResource.getPath(), event.getEventMetadata());
    } catch (final IndyWorkflowException ex) {
        logger.error("Error while retrieving pom artifact " + pomResource.getPath() + " from store " + store, ex);
        return;
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ArtifactPathInfo(org.commonjava.atlas.maven.ident.util.ArtifactPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 27 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class SettingsSubStore method getSettingsTemplate.

private synchronized SettingsTemplate getSettingsTemplate(final URIMatcher matcher) throws WebdavException {
    final StoreKey key = matcher.getStoreKey();
    ArtifactStore store;
    try {
        store = indy.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve artifact store: %s. Reason: %s", key, e.getMessage()), e);
        throw new WebdavException("Failed to retrieve length for: " + matcher.getURI());
    }
    if (store == null) {
        throw new WebdavException("Cannot retrieve ArtifactStore: " + key);
    }
    StorageAdvice advice;
    try {
        advice = advisor.getStorageAdvice(store);
    } catch (final DotMavenException e) {
        logger.error(String.format("Failed to retrieve storage advice for: %s. Reason: %s", key, e.getMessage()), e);
        throw new WebdavException("Failed to retrieve length for: " + matcher.getURI());
    }
    return new SettingsTemplate(key, advice, requestInfo, templatingEngine);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) StorageAdvice(org.commonjava.indy.dotmaven.data.StorageAdvice) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) SettingsTemplate(org.commonjava.indy.dotmaven.util.SettingsTemplate) WebdavException(net.sf.webdav.exceptions.WebdavException) StoreKey(org.commonjava.indy.model.core.StoreKey) DotMavenException(org.commonjava.indy.dotmaven.DotMavenException)

Example 28 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class StorageAdvisor method getStorageAdvice.

public StorageAdvice getStorageAdvice(final ArtifactStore store) throws DotMavenException {
    boolean deployable = false;
    boolean releases = true;
    boolean snapshots = false;
    HostedRepository hostedStore = null;
    final StoreType type = store.getKey().getType();
    all: switch(type) {
        case group:
            {
                List<ArtifactStore> constituents;
                try {
                    constituents = dataManager.query().enabledState(true).getOrderedConcreteStoresInGroup(MAVEN_PKG_KEY, store.getName());
                } catch (final IndyDataException e) {
                    throw new DotMavenException("Failed to retrieve constituent ArtifactStores for group: %s. Reason: %s", e, store.getName(), e.getMessage());
                }
                for (final ArtifactStore as : constituents) {
                    if (as.getKey().getType() == hosted) {
                        deployable = true;
                        hostedStore = (HostedRepository) as;
                        snapshots = hostedStore.isAllowSnapshots();
                        releases = hostedStore.isAllowReleases();
                        break all;
                    }
                }
                break;
            }
        case hosted:
            {
                deployable = true;
                hostedStore = (HostedRepository) store;
                snapshots = hostedStore.isAllowSnapshots();
                releases = hostedStore.isAllowReleases();
                break;
            }
        default:
    }
    return new StorageAdvice(store, hostedStore, deployable, releases, snapshots);
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) HostedRepository(org.commonjava.indy.model.core.HostedRepository) DotMavenException(org.commonjava.indy.dotmaven.DotMavenException)

Example 29 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class RepoProxyContentLimiter method clearContent.

private void clearContent(String skp) {
    String[] parts = skp.split("#");
    StoreKey storeKey = StoreKey.fromString(parts[0]);
    if (remote == storeKey.getType()) {
        ArtifactStore store;
        try {
            store = storeDataManager.getArtifactStore(storeKey);
            contentManager.delete(store, parts[1]);
        } catch (IndyDataException e) {
            logger.warn("Failed to lookup store: {} from event: {}", storeKey, skp);
        } catch (IndyWorkflowException e) {
            logger.warn("Failed to delete: {} from: {}, from event: {}", parts[1], storeKey, skp);
        }
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 30 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class ScheduleDBManager method rescheduleDisableTimeout.

public void rescheduleDisableTimeout(final StoreKey key) throws IndySchedulerException {
    if (!schedulerConfig.isEnabled()) {
        logger.debug("Scheduler disabled.");
        return;
    }
    ArtifactStore store = null;
    try {
        store = dataManager.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve store for: %s. Reason: %s", key, e.getMessage()), e);
    }
    if (store == null) {
        return;
    }
    int timeout = store.getDisableTimeout();
    if (timeout == TIMEOUT_USE_DEFAULT) {
        // case TIMEOUT_USE_DEFAULT: will use default timeout configuration
        timeout = config.getStoreDisableTimeoutSeconds();
    }
    if (timeout > TIMEOUT_USE_DEFAULT && store.isDisabled()) {
        final StoreKey sk = store.getKey();
        logger.debug("Set/Reschedule disable timeout for store:{}", sk);
        scheduleForStore(sk, DISABLE_TIMEOUT, sk.toString() + "#" + DISABLE_TIMEOUT, sk, timeout);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreKey(org.commonjava.indy.model.core.StoreKey)

Aggregations

ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)168 IndyDataException (org.commonjava.indy.data.IndyDataException)90 StoreKey (org.commonjava.indy.model.core.StoreKey)83 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)54 Logger (org.slf4j.Logger)45 ArrayList (java.util.ArrayList)43 Group (org.commonjava.indy.model.core.Group)42 StoreType (org.commonjava.indy.model.core.StoreType)38 Transfer (org.commonjava.maven.galley.model.Transfer)38 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)33 IOException (java.io.IOException)29 HashSet (java.util.HashSet)29 List (java.util.List)28 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)26 LoggerFactory (org.slf4j.LoggerFactory)25 StoreDataManager (org.commonjava.indy.data.StoreDataManager)24 Set (java.util.Set)23 Inject (javax.inject.Inject)22 HostedRepository (org.commonjava.indy.model.core.HostedRepository)21 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)17