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);
}
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);
}
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;
}
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;
}
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());
}
}
Aggregations