Search in sources :

Example 31 with PathsPromoteRequest

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

the class PromotionManagerTest method rollback_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback.

@Test
public void rollback_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback() throws Exception {
    prepareHostedReposAndTwoPaths();
    PathsPromoteResult result = manager.promotePaths(new PathsPromoteRequest(source.getKey(), target.getKey()), FAKE_BASE_URL);
    assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
    assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
    Set<String> pending = result.getPendingPaths();
    assertThat("should be null or empty: " + pending, 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)

Example 32 with PathsPromoteRequest

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

the class PromotionManagerTest method promoteAllByPath_CollidingPaths_VerifySecondSkipped.

/**
 * On collision, the promotion manager should skip the second file to be promoted (instead of overwriting the
 * existing one). This assumes no overwrite attribute is available for setting in the promotion request (or that
 * it is available but isn't set...and defaults to false).
 * @throws Exception
 */
@Test
public void promoteAllByPath_CollidingPaths_VerifySecondSkipped() throws Exception {
    final HostedRepository source1 = new HostedRepository(MAVEN_PKG_KEY, "source1");
    final HostedRepository source2 = new HostedRepository(MAVEN_PKG_KEY, "source2");
    storeManager.storeArtifactStore(source1, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
    storeManager.storeArtifactStore(source2, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
    String originalString = "This is a test";
    final String path = "/path/path";
    contentManager.store(source1, path, new ByteArrayInputStream(originalString.getBytes()), TransferOperation.UPLOAD, new EventMetadata());
    contentManager.store(source2, path, new ByteArrayInputStream("This is another 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(source1.getKey(), target.getKey(), path), FAKE_BASE_URL);
    assertThat(result.getRequest().getSource(), equalTo(source1.getKey()));
    assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
    Set<String> pending = result.getPendingPaths();
    assertThat(pending == null || pending.isEmpty(), equalTo(true));
    Set<String> skipped = result.getSkippedPaths();
    assertThat(skipped == null || skipped.isEmpty(), equalTo(true));
    Set<String> completed = result.getCompletedPaths();
    assertThat(completed, notNullValue());
    assertThat(completed.size(), equalTo(1));
    assertThat(result.getError(), nullValue());
    Transfer ref = downloadManager.getStorageReference(target, path);
    assertThat(ref.exists(), equalTo(true));
    try (InputStream in = ref.openInputStream()) {
        String value = IOUtils.toString(in);
        assertThat(value, equalTo(originalString));
    }
    result = manager.promotePaths(new PathsPromoteRequest(source1.getKey(), target.getKey(), path), FAKE_BASE_URL);
    assertThat(result.getRequest().getSource(), equalTo(source1.getKey()));
    assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
    pending = result.getPendingPaths();
    assertThat(pending == null || pending.isEmpty(), equalTo(true));
    skipped = result.getSkippedPaths();
    assertThat(skipped, notNullValue());
    assertThat(skipped.size(), equalTo(1));
    completed = result.getCompletedPaths();
    assertThat(completed == null || completed.isEmpty(), equalTo(true));
    assertThat(result.getError(), nullValue());
    ref = downloadManager.getStorageReference(target, path);
    assertThat(ref.exists(), equalTo(true));
    try (InputStream in = ref.openInputStream()) {
        String value = IOUtils.toString(in);
        assertThat(value, equalTo(originalString));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Transfer(org.commonjava.maven.galley.model.Transfer) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) HostedRepository(org.commonjava.indy.model.core.HostedRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 33 with PathsPromoteRequest

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

the class PromotionManagerTest method promoteAllByPath_PushTwoArtifactsToHostedRepo_DryRun_VerifyPendingPathsPopulated.

@Test
public void promoteAllByPath_PushTwoArtifactsToHostedRepo_DryRun_VerifyPendingPathsPopulated() throws Exception {
    prepareHostedReposAndTwoPaths();
    final PathsPromoteResult result = manager.promotePaths(new PathsPromoteRequest(source.getKey(), target.getKey()).setDryRun(true), FAKE_BASE_URL);
    assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
    assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
    final Set<String> completed = result.getCompletedPaths();
    assertThat(completed == null || completed.isEmpty(), equalTo(true));
    final Set<String> 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)

Example 34 with PathsPromoteRequest

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

the class PromotionManager method submitRollbackPathsPromote.

private Future<PathsPromoteResult> submitRollbackPathsPromote(PathsPromoteResult result) throws IndyWorkflowException {
    return detectOverload(() -> asyncPromotionService.submit(() -> {
        if (result.getCompletedPaths().isEmpty()) {
            // clear errors so client don't misunderstand rollback result
            logger.info("Nothing to rollback (completed empty), promotionId: {}", result.getRequest().getPromotionId());
            result.setError(null);
            result.setValidations(null);
            return result;
        }
        /*
             * Rollback is the opposite of promotion. We just revert the src and target, set the paths
             * to the completed, and call the doPathsPromotion.
             */
        PathsPromoteRequest request = result.getRequest();
        PathsPromoteRequest newRequest = new PathsPromoteRequest(request.getTarget(), request.getSource(), result.getCompletedPaths());
        newRequest.setPurgeSource(true);
        PathsPromoteResult ret;
        try {
            ret = doPathsPromotion(newRequest, true, null);
        } catch (Exception ex) {
            String msg = "Rollback path promotion failed. Target: " + request.getTarget() + ", Source: " + request.getSource() + ", Reason: " + getStackTrace(ex);
            logger.warn(msg);
            ret = new PathsPromoteResult(request, msg);
        }
        if (ret.succeeded()) {
            result.setPendingPaths(result.getCompletedPaths());
            result.setCompletedPaths(null);
        } else {
            result.setError(ret.getError());
        }
        if (result.getRequest().getCallback() != null) {
            return callbackHelper.callback(result.getRequest().getCallback(), result);
        }
        return result;
    }));
}
Also used : PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) PromotionHelper.throwProperException(org.commonjava.indy.promote.data.PromotionHelper.throwProperException) IndyDataException(org.commonjava.indy.data.IndyDataException) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) PromotionValidationException(org.commonjava.indy.promote.validate.PromotionValidationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 35 with PathsPromoteRequest

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

the class PromotionManager method rollbackPathsPromote.

/**
 * Attempt to rollback a previous {@link PathsPromoteResult}.
 *
 * All paths in the completed paths set are deleted from the target. The output {@link PathsPromoteResult} contains
 * the previous content, with removed target paths moved from the completed list to the pending list.
 *
 * @param result The result to rollback
 * @return The same result, with successful deletions moved from the completed to pending paths list,
 * and the error cleared (or set to a new error)
 */
public PathsPromoteResult rollbackPathsPromote(final PathsPromoteResult result) throws PromotionException, IndyWorkflowException {
    final PathsPromoteRequest request = result.getRequest();
    Future<PathsPromoteResult> future = submitRollbackPathsPromote(result);
    if (request.isAsync()) {
        return new PathsPromoteResult(request).accepted();
    } else {
        try {
            return future.get();
        } catch (InterruptedException | ExecutionException e) {
            logger.error("Path promotion rollback failed. From (target): " + request.getTarget() + ", to (source): " + request.getSource(), e);
            throw new PromotionException("Path promotion rollback failed.", e);
        }
    }
}
Also used : PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) ExecutionException(java.util.concurrent.ExecutionException)

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