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);
}
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));
}
}
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);
}
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;
}));
}
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);
}
}
}
Aggregations