Search in sources :

Example 1 with ValidationResult

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);
    }
}
Also used : PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) Transfer(org.commonjava.maven.galley.model.Transfer) ValidationResult(org.commonjava.indy.promote.model.ValidationResult) StoreKey(org.commonjava.indy.model.core.StoreKey) HashSet(java.util.HashSet)

Example 2 with ValidationResult

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);
}
Also used : PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) ValidationResult(org.commonjava.indy.promote.model.ValidationResult) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 3 with ValidationResult

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));
}
Also used : GroupPromoteRequest(org.commonjava.indy.promote.model.GroupPromoteRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GroupPromoteResult(org.commonjava.indy.promote.model.GroupPromoteResult) ValidationResult(org.commonjava.indy.promote.model.ValidationResult) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 4 with ValidationResult

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>"));
}
Also used : InputStream(java.io.InputStream) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ValidationResult(org.commonjava.indy.promote.model.ValidationResult) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 5 with ValidationResult

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 ) );
}
Also used : GroupPromoteRequest(org.commonjava.indy.promote.model.GroupPromoteRequest) InputStream(java.io.InputStream) GroupPromoteResult(org.commonjava.indy.promote.model.GroupPromoteResult) ValidationResult(org.commonjava.indy.promote.model.ValidationResult) IOException(java.io.IOException) IndyClientException(org.commonjava.indy.client.core.IndyClientException) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

ValidationResult (org.commonjava.indy.promote.model.ValidationResult)20 Test (org.junit.Test)17 GroupPromoteResult (org.commonjava.indy.promote.model.GroupPromoteResult)16 GroupPromoteRequest (org.commonjava.indy.promote.model.GroupPromoteRequest)15 Category (org.junit.experimental.categories.Category)14 InputStream (java.io.InputStream)7 PathsPromoteResult (org.commonjava.indy.promote.model.PathsPromoteResult)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Group (org.commonjava.indy.model.core.Group)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 IndyDataException (org.commonjava.indy.data.IndyDataException)2 StoreKey (org.commonjava.indy.model.core.StoreKey)2 IndyPromoteClientModule (org.commonjava.indy.promote.client.IndyPromoteClientModule)2 PathsPromoteRequest (org.commonjava.indy.promote.model.PathsPromoteRequest)2 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)2 Transfer (org.commonjava.maven.galley.model.Transfer)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)1 IndyClientException (org.commonjava.indy.client.core.IndyClientException)1