use of org.commonjava.maven.galley.event.EventMetadata 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());
}
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class PromotionManagerTest method rollback_PurgeSource_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback_VerifyContentInSource.
@Test
public void rollback_PurgeSource_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback_VerifyContentInSource() throws Exception {
final HostedRepository source = new HostedRepository(MAVEN_PKG_KEY, "source");
storeManager.storeArtifactStore(source, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
final String first = "/first/path";
final String second = "/second/path";
contentManager.store(source, first, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
contentManager.store(source, second, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
final HostedRepository target = new HostedRepository(MAVEN_PKG_KEY, "target");
storeManager.storeArtifactStore(target, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
PathsPromoteResult result = manager.promotePaths(new PathsPromoteRequest(source.getKey(), target.getKey()).setPurgeSource(true), FAKE_BASE_URL);
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
Set<String> pending = result.getPendingPaths();
assertThat(pending == null || pending.isEmpty(), equalTo(true));
Set<String> completed = result.getCompletedPaths();
assertThat(completed, notNullValue());
assertThat(completed.size(), equalTo(2));
assertThat(result.getError(), nullValue());
result = manager.rollbackPathsPromote(result);
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
completed = result.getCompletedPaths();
assertThat(completed == null || completed.isEmpty(), equalTo(true));
pending = result.getPendingPaths();
assertThat(pending, notNullValue());
assertThat(pending.size(), equalTo(2));
assertThat(result.getError(), nullValue());
Transfer ref = downloadManager.getStorageReference(target, first);
assertThat(ref.exists(), equalTo(false));
ref = downloadManager.getStorageReference(target, second);
assertThat(ref.exists(), equalTo(false));
ref = downloadManager.getStorageReference(source, first);
assertThat(ref.exists(), equalTo(true));
ref = downloadManager.getStorageReference(source, second);
assertThat(ref.exists(), equalTo(true));
}
use of org.commonjava.maven.galley.event.EventMetadata in project galley by Commonjava.
the class Transfer method createFile.
public void createFile() throws IOException {
provider.waitForWriteUnlock(resource);
if (decorator != null) {
decorator.decorateCreateFile(this, new EventMetadata());
}
provider.createFile(resource);
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class GroupDataManagerTCK method createAndDeleteGroup.
@Test
public void createAndDeleteGroup() throws Exception {
final StoreDataManager manager = getFixtureProvider().getDataManager();
final Group grp = new Group("test");
store(grp);
manager.deleteArtifactStore(grp.getKey(), summary, new EventMetadata());
final Group result = manager.query().packageType(MAVEN_PKG_KEY).storeType(Group.class).getByName(grp.getName());
assertThat(result, nullValue());
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class RepositoryDataManagerTCK method createAndDeleteCentralRepoProxy.
@Test
public void createAndDeleteCentralRepoProxy() throws Exception {
final StoreDataManager manager = getFixtureProvider().getDataManager();
final RemoteRepository repo = new RemoteRepository("central", "http://repo1.maven.apache.org/maven2/");
storeRemoteRepository(repo, false);
manager.deleteArtifactStore(repo.getKey(), summary, new EventMetadata());
final ArtifactStore result = manager.query().packageType(MAVEN_PKG_KEY).storeType(RemoteRepository.class).getByName(repo.getName());
assertThat(result, nullValue());
}
Aggregations