Search in sources :

Example 31 with IndyDataException

use of org.commonjava.indy.data.IndyDataException 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 32 with IndyDataException

use of org.commonjava.indy.data.IndyDataException 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().packageType(MAVEN_PKG_KEY).enabledState(true).getOrderedConcreteStoresInGroup(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 33 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class AutoProxDataManagerDecorator method getRemoteRepository.

private RemoteRepository getRemoteRepository(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
    logger.debug("DECORATED (getRemoteRepository: {})", key);
    RemoteRepository repo = (RemoteRepository) dataManager.getArtifactStore(key);
    if (!catalog.isEnabled()) {
        logger.debug("AutoProx decorator disabled; returning: {}", repo);
        return repo;
    }
    logger.debug("AutoProx decorator active");
    if (repo == null) {
        logger.info("AutoProx: creating repository for: {}", key);
        try {
            repo = catalog.createRemoteRepository(key);
            if (repo != null) {
                if (!checkValidity(key)) {
                    return null;
                }
                final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? repo.getKey() : impliedBy);
                dataManager.storeArtifactStore(repo, new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating remote repository for: '" + key + "'"), false, true, eventMetadata);
            }
        } catch (final AutoProxRuleException e) {
            throw new IndyDataException("[AUTOPROX] Failed to create new remote repository from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
        }
    }
    return repo;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 34 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class AutoProxDataManagerDecorator method getGroup.

private Group getGroup(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
    logger.debug("DECORATED (getGroup: {})", key);
    Group g = (Group) dataManager.getArtifactStore(key);
    if (!catalog.isEnabled()) {
        logger.debug("AutoProx decorator disabled; returning: {}", g);
        return g;
    }
    logger.debug("AutoProx decorator active");
    if (g == null) {
        logger.debug("AutoProx: creating repository for: {}", key);
        if (!checkValidity(key)) {
            return null;
        }
        try {
            g = catalog.createGroup(key);
        } catch (final AutoProxRuleException e) {
            throw new IndyDataException("[AUTOPROX] Failed to create new group from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
        }
        if (g != null) {
            logger.info("Validating group: {}", g);
            for (final StoreKey memberKey : new ArrayList<>(g.getConstituents())) {
                final ArtifactStore store = getArtifactStore(memberKey, impliedBy == null ? g.getKey() : impliedBy);
                if (store == null) {
                    g.removeConstituent(memberKey);
                }
            }
            if (g.getConstituents().isEmpty()) {
                return null;
            }
            final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? g.getKey() : impliedBy);
            dataManager.storeArtifactStore(g, new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating group for: '" + key + "'"), false, true, eventMetadata);
        }
    }
    return g;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 35 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class PromotionValidator method validate.

public void validate(PromoteRequest request, ValidationResult result, String baseUrl) throws PromotionValidationException {
    ValidationRuleSet set = validationsManager.getRuleSetMatching(request.getTargetKey());
    Logger logger = LoggerFactory.getLogger(getClass());
    if (set != null) {
        logger.debug("Running validation rule-set for promotion: {}", set.getName());
        result.setRuleSet(set.getName());
        List<String> ruleNames = set.getRuleNames();
        if (ruleNames != null && !ruleNames.isEmpty()) {
            final ArtifactStore store = getRequestStore(request, baseUrl);
            try {
                final ValidationRequest req = new ValidationRequest(request, set, validationTools, store);
                for (String ruleRef : ruleNames) {
                    String ruleName = // flatten in case some path fragment leaks in...
                    new File(ruleRef).getName();
                    ValidationRuleMapping rule = validationsManager.getRuleMappingNamed(ruleName);
                    if (rule != null) {
                        try {
                            logger.debug("Running promotion validation rule: {}", rule.getName());
                            String error = rule.getRule().validate(req);
                            if (StringUtils.isNotEmpty(error)) {
                                logger.debug("{} failed", rule.getName());
                                result.addValidatorError(rule.getName(), error);
                            } else {
                                logger.debug("{} succeeded", rule.getName());
                            }
                        } catch (Exception e) {
                            if (e instanceof PromotionValidationException) {
                                throw (PromotionValidationException) e;
                            }
                            throw new PromotionValidationException("Failed to run validation rule: {} for request: {}. Reason: {}", e, rule.getName(), request, e);
                        }
                    }
                }
            } finally {
                if (needTempRepo(request)) {
                    try {
                        final String changeSum = String.format("Removes the temp remote repo [%s] after promote operation.", store);
                        storeDataMgr.deleteArtifactStore(store.getKey(), new ChangeSummary(ChangeSummary.SYSTEM_USER, changeSum), new EventMetadata().set(ContentManager.SUPPRESS_EVENTS, true));
                        logger.info("Promotion temporary repo {} has been deleted for {}", store.getKey(), request.getSource());
                    } catch (IndyDataException e) {
                        logger.warn("StoreDataManager can not remove artifact stores correctly.", e);
                    }
                }
            }
        }
    } else {
        logger.info("No validation rule-sets are defined for: {}", request.getTargetKey());
    }
}
Also used : ValidationRequest(org.commonjava.indy.promote.validate.model.ValidationRequest) Logger(org.slf4j.Logger) IndyDataException(org.commonjava.indy.data.IndyDataException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ValidationRuleMapping(org.commonjava.indy.promote.validate.model.ValidationRuleMapping) ValidationRuleSet(org.commonjava.indy.promote.model.ValidationRuleSet) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) File(java.io.File)

Aggregations

IndyDataException (org.commonjava.indy.data.IndyDataException)75 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)50 StoreKey (org.commonjava.indy.model.core.StoreKey)30 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)26 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)24 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)24 Transfer (org.commonjava.maven.galley.model.Transfer)19 ArrayList (java.util.ArrayList)17 Group (org.commonjava.indy.model.core.Group)17 IOException (java.io.IOException)16 Logger (org.slf4j.Logger)16 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)14 HashSet (java.util.HashSet)10 List (java.util.List)7 StoreType (org.commonjava.indy.model.core.StoreType)7 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)7 HostedRepository (org.commonjava.indy.model.core.HostedRepository)6 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)6 ContentGenerator (org.commonjava.indy.content.ContentGenerator)5 InputStream (java.io.InputStream)4