Search in sources :

Example 16 with PathsPromoteRequest

use of org.commonjava.indy.promote.model.PathsPromoteRequest in project indy by Commonjava.

the class ValidationRequest method getSourcePaths.

private Set<String> getSourcePaths(boolean includeMetadata, boolean includeChecksums, Predicate<String> filter) throws PromotionValidationException {
    if (requestPaths == null) {
        Set<String> paths = null;
        if (promoteRequest instanceof PathsPromoteRequest) {
            paths = ((PathsPromoteRequest) promoteRequest).getPaths();
        }
        if (paths == null || paths.isEmpty()) {
            if (sourceRepository != null) {
                try {
                    paths = new HashSet<>();
                    // This is used to let galley ignore the NPMPathStorageCalculator handling,
                    // which will append package.json to a directory transfer and make listing not applicable.
                    ThreadContext context = ThreadContext.getContext(true);
                    context.put(RequestContextHelper.IS_RAW_VIEW, Boolean.TRUE);
                    listRecursively(sourceRepository, "/", paths);
                    context.put(RequestContextHelper.IS_RAW_VIEW, Boolean.FALSE);
                } catch (IndyWorkflowException e) {
                    throw new PromotionValidationException("Failed to list paths in source: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
                }
            }
        }
        requestPaths = paths;
    }
    if (!includeMetadata || !includeChecksums) {
        return requestPaths.stream().filter(filter).collect(Collectors.toSet());
    }
    return requestPaths;
}
Also used : IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ThreadContext(org.commonjava.cdi.util.weft.ThreadContext) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) PromotionValidationException(org.commonjava.indy.promote.validate.PromotionValidationException)

Example 17 with PathsPromoteRequest

use of org.commonjava.indy.promote.model.PathsPromoteRequest 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 18 with PathsPromoteRequest

use of org.commonjava.indy.promote.model.PathsPromoteRequest in project indy by Commonjava.

the class GroupNFCEntryClearedOnByPathPromoteTest method run.

@Test
@Category(EventDependent.class)
public void run() throws Exception {
    try (InputStream stream = client.content().get(new StoreKey(MAVEN_PKG_KEY, group, GROUP_G_NAME), PATH)) {
        assertThat("Path should not yet be available from group!", stream, nullValue());
    }
    // NOTE: This really shouldn't be needed, but I was having trouble getting the NFC entry registered without it.
    try (InputStream stream = client.content().get(new StoreKey(MAVEN_PKG_KEY, group, GROUP_G_NAME), PATH)) {
        assertThat("NFC: Path should be marked as missing!", stream, nullValue());
    }
    PathsPromoteRequest request = new PathsPromoteRequest(b.getKey(), a.getKey(), PATH);
    PathsPromoteResult response = promote.promoteByPath(request);
    assertThat(response.getError(), nullValue());
    waitForEventPropagation();
    // If you want to see that clearing the NFC works, uncomment this:
    // try (InputStream stream = client.content().get( new StoreKey( MAVEN_PKG_KEY, group, GROUP_G_NAME ), PATH ))
    // {
    // assertThat( "NFC: Path should be marked as missing!", stream,
    // nullValue() );
    // }
    // 
    // 
    // client.module( IndyNfcClientModule.class ).clearAll();
    assertContent(g, PATH, POM_CONTENT);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) StoreKey(org.commonjava.indy.model.core.StoreKey) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 19 with PathsPromoteRequest

use of org.commonjava.indy.promote.model.PathsPromoteRequest in project indy by Commonjava.

the class PromotionManagerTest method rollback_PushTwoArtifactsToHostedRepo_PromoteFailedAndAutoRollback.

/**
 * To make the promotion fail, we just add a same path to target and set the request failWhenExists.
 */
@Test
public void rollback_PushTwoArtifactsToHostedRepo_PromoteFailedAndAutoRollback() throws Exception {
    prepareHostedReposAndTwoPaths();
    contentManager.store(target, second, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
    PathsPromoteRequest request = new PathsPromoteRequest(source.getKey(), target.getKey());
    request.setFailWhenExists(true);
    PathsPromoteResult result = manager.promotePaths(request, FAKE_BASE_URL);
    Set<String> pending = result.getPendingPaths();
    assertThat(pending, notNullValue());
    assertThat(pending.size(), equalTo(2));
    Set<String> completed = result.getCompletedPaths();
    assertThat(completed.size(), equalTo(0));
    assertThat(result.getError(), notNullValue());
    System.out.println(">>> " + result.getError());
    verifyExistence(false, true, true, true);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 20 with PathsPromoteRequest

use of org.commonjava.indy.promote.model.PathsPromoteRequest in project indy by Commonjava.

the class PromotionManagerTest method rollback_PurgeSource_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback_VerifyContentInSource.

@Test
public void rollback_PurgeSource_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback_VerifyContentInSource() throws Exception {
    prepareHostedReposAndTwoPaths();
    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());
    verifyExistence(false, false, true, true);
}
Also used : PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) Test(org.junit.Test)

Aggregations

PathsPromoteRequest (org.commonjava.indy.promote.model.PathsPromoteRequest)47 PathsPromoteResult (org.commonjava.indy.promote.model.PathsPromoteResult)40 Test (org.junit.Test)34 IndyPromoteClientModule (org.commonjava.indy.promote.client.IndyPromoteClientModule)15 Category (org.junit.experimental.categories.Category)10 InputStream (java.io.InputStream)8 StoreKey (org.commonjava.indy.model.core.StoreKey)8 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 HashSet (java.util.HashSet)6 IndyDataException (org.commonjava.indy.data.IndyDataException)6 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)6 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)6 IOException (java.io.IOException)5 HostedRepository (org.commonjava.indy.model.core.HostedRepository)5 PromotionValidationException (org.commonjava.indy.promote.validate.PromotionValidationException)5 Transfer (org.commonjava.maven.galley.model.Transfer)5 ExecutionException (java.util.concurrent.ExecutionException)4 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)4 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)4