use of org.commonjava.indy.promote.model.ValidationResult in project indy by Commonjava.
the class PromotionManager method promotePaths.
/**
* Promote artifacts from the source to the target given in the {@link PathsPromoteRequest}. If a set of paths are given, only try to promotePaths those.
* Otherwise, build a recursive list of available artifacts in the source store, and try to promotePaths them all.
*
* @param request The request containing source and target store keys, and an optional list of paths to promotePaths
*
* @return The result, including the source and target store keys used, the paths completed (promoted successfully), the pending paths (those that
* weren't processed due to some error...or null), and a nullable error explaining what (if anything) went wrong with the promotion.
*
* @throws PromotionException
* @throws IndyWorkflowException
*/
public PathsPromoteResult promotePaths(final PathsPromoteRequest request, final String baseUrl) throws PromotionException, IndyWorkflowException {
final Set<String> paths = request.getPaths();
final StoreKey source = request.getSource();
List<Transfer> contents;
if (paths == null || paths.isEmpty()) {
contents = downloadManager.listRecursively(source, DownloadManager.ROOT_PATH);
} else {
contents = getTransfersForPaths(source, paths);
}
final Set<String> pending = new HashSet<>();
for (final Transfer transfer : contents) {
pending.add(transfer.getPath());
}
ValidationResult validation = new ValidationResult();
validator.validate(request, validation, baseUrl);
if (request.isDryRun()) {
return new PathsPromoteResult(request, pending, Collections.emptySet(), Collections.emptySet(), validation);
} else if (validation.isValid()) {
return runPathPromotions(request, pending, Collections.emptySet(), Collections.emptySet(), contents, validation);
} else {
return new PathsPromoteResult(request, pending, Collections.emptySet(), Collections.emptySet(), validation);
}
}
use of org.commonjava.indy.promote.model.ValidationResult in project indy by Commonjava.
the class CacheCheckingforPromoteWithRemoteTest method run.
@Test
public // @Category( EventDependent.class )
void run() throws Exception {
/* @formatter:off */
final String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<project>\n" + " <modelVersion>4.0.0</modelVersion>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <version>1</version>\n" + "</project>\n";
/* @formatter:on */
final String pomUrl = server.formatUrl(rId, pomPath);
server.expect(pomUrl, 200, content);
assertContent(getContent(g), content);
assertTrue(StringUtils.isBlank(getContent(h)));
PathsPromoteRequest request = new PathsPromoteRequest(r.getKey(), h.getKey(), pomPath);
PathsPromoteResult result = module.promoteByPath(request);
assertThat(result, notNullValue());
ValidationResult validations = result.getValidations();
assertThat(validations, notNullValue());
Map<String, String> validatorErrors = validations.getValidatorErrors();
assertThat(validatorErrors, notNullValue());
System.out.println(String.format("[errors] validation errors: %s", validatorErrors));
//FIXME: some way to check cache directly but not through client
assertContent(getContent(h), content);
}
use of org.commonjava.indy.promote.model.ValidationResult in project indy by Commonjava.
the class ArtifactRefs_DependencyInAnotherRepoInGroup_RuleTest method run.
@Test
@Category(EventDependent.class)
public void run() throws Exception {
String invalid = "org/foo/invalid/1/invalid-1.pom";
String valid = "org/foo/valid/1.1/valid-1.1.pom";
String validDepPom = "org/bar/dep/1.0/dep-1.0.pom";
String validDepJar = "org/bar/dep/1.0/dep-1.0.jar";
String content = "this is some content";
client.content().store(otherSource.getKey(), validDepPom, new ByteArrayInputStream(content.getBytes()));
client.content().store(otherSource.getKey(), validDepJar, new ByteArrayInputStream(content.getBytes()));
InputStream stream = client.content().get(other.getKey(), validDepPom);
String retrieved = IOUtils.toString(stream);
stream.close();
assertThat(validDepPom + " invalid from: " + other.getKey(), retrieved, equalTo(content));
stream = client.content().get(other.getKey(), validDepJar);
retrieved = IOUtils.toString(stream);
stream.close();
assertThat(validDepJar + " invalid from: " + other.getKey(), retrieved, equalTo(content));
deployResource(invalid, PREFIX + "invalid-external-dep.pom.xml");
deployResource(valid, PREFIX + "valid-single-external-dep.pom.xml");
waitForEventPropagation();
GroupPromoteRequest request = new GroupPromoteRequest(source.getKey(), target.getName());
GroupPromoteResult result = module.promoteToGroup(request);
assertThat(result, notNullValue());
ValidationResult validations = result.getValidations();
assertThat(validations, notNullValue());
Map<String, String> validatorErrors = validations.getValidatorErrors();
assertThat(validatorErrors, notNullValue());
System.out.println(validatorErrors);
String errors = validatorErrors.get(RULE);
assertThat(errors, notNullValue());
System.out.println(validatorErrors);
assertThat(errors.contains(valid), equalTo(false));
assertThat(errors.contains(invalid), equalTo(true));
}
use of org.commonjava.indy.promote.model.ValidationResult in project indy by Commonjava.
the class ArtifactRefs_PromoteWithParent_RuleTest method run.
@Test
@Category(EventDependent.class)
public void run() throws Exception {
String child = "org/foo/child/1/child-1.pom";
String parent = "org/foo/parent/1/parent-1.pom";
deployResource(child, PREFIX + "child.pom.xml");
deployResource(parent, PREFIX + "parent.pom.xml");
waitForEventPropagation();
InputStream stream = client.content().get(source.getKey(), child);
String childRerived = IOUtils.toString(stream);
stream.close();
logger.debug("promote with parent in source: child content: {}", childRerived);
assertThat(childRerived, containsString("<artifactId>child</artifactId>"));
stream = client.content().get(source.getKey(), parent);
String parentRetrived = IOUtils.toString(stream);
stream.close();
logger.debug("promote with parent in source: parent content: {}", parentRetrived);
assertThat(parentRetrived, containsString("<artifactId>parent</artifactId>"));
PathsPromoteRequest request = new PathsPromoteRequest(source.getKey(), target.getKey(), child, parent);
PathsPromoteResult result = module.promoteByPath(request);
assertThat(result, notNullValue());
ValidationResult validations = result.getValidations();
System.out.println(validations);
assertThat(validations, notNullValue());
assertThat(validations.isValid(), equalTo(true));
stream = client.content().get(target.getKey(), child);
childRerived = IOUtils.toString(stream);
stream.close();
logger.debug("promote with parent in target: child content: {}", childRerived);
assertThat(childRerived, containsString("<artifactId>child</artifactId>"));
stream = client.content().get(target.getKey(), parent);
parentRetrived = IOUtils.toString(stream);
stream.close();
logger.debug("promote with parent in target: parent content: {}", parentRetrived);
assertThat(parentRetrived, containsString("<artifactId>parent</artifactId>"));
}
use of org.commonjava.indy.promote.model.ValidationResult in project indy by Commonjava.
the class FullRuleStack_GroupWithOneOfTwoHosts_RuleTest method run.
@Test
@Category(EventDependent.class)
public void run() throws Exception {
List<String> deploy = Arrays.asList("org/foo/valid/1.1.0-redhat-1/valid-1.1.0-redhat-1.pom", "org/foo/valid/1.1.0-redhat-1/valid-1.1.0-redhat-1.jar", "org/foo/valid/1.1.0-redhat-1/valid-1.1.0-redhat-1-sources.jar", "org/foo/valid/1.1.0-redhat-1/valid-1.1.0-redhat-1-javadoc.jar");
Stream.of(hostTarget1, hostTarget2).forEach((repo) -> {
deploy.forEach((path) -> {
try {
deployResource(repo.getKey(), path, PREFIX + "valid.pom.xml");
try (InputStream stream = client.content().get(repo.getKey(), path)) {
String retrieved = IOUtils.toString(stream);
assertThat(path + " invalid from: " + repo.getKey(), retrieved, equalTo(resourceToString(PREFIX + "valid.pom.xml")));
}
} catch (Exception e) {
fail("Failed to deploy: " + path + " to: " + repo);
}
});
});
// GroupPromoteRequest request = new GroupPromoteRequest( hostTarget1.getKey(), target.getName() );
// GroupPromoteResult result = module.promoteToGroup( request );
//
// assertThat( result, notNullValue() );
// assertThat( result.getValidations(), notNullValue() );
// assertThat( result.getValidations().isValid(), equalTo( true ) );
target.addConstituent(hostTarget1);
client.stores().update(target, "update target");
deploy.forEach((path) -> {
try {
try (InputStream stream = client.content().get(target.getKey(), path)) {
String retrieved = IOUtils.toString(stream);
assertThat(path + " invalid from: " + target.getKey(), retrieved, equalTo(resourceToString(PREFIX + "valid.pom.xml")));
}
} catch (Exception e) {
fail("Failed to verify: " + path + " in: " + target.getKey());
}
});
waitForEventPropagation();
GroupPromoteRequest request = new GroupPromoteRequest(hostTarget2.getKey(), target.getName());
GroupPromoteResult result = module.promoteToGroup(request);
assertThat(result, notNullValue());
ValidationResult validations = result.getValidations();
assertThat(validations, notNullValue());
Map<String, String> validatorErrors = validations.getValidatorErrors();
assertThat(validatorErrors, notNullValue());
System.out.println(validatorErrors);
String errors = validatorErrors.get(RULE);
assertThat(errors, notNullValue());
System.out.println(validatorErrors);
// assertThat( errors.contains( deploy ), equalTo( true ) );
}
Aggregations