use of org.commonjava.indy.promote.model.PathsPromoteRequest in project indy by Commonjava.
the class PromoteDryRunTest method run.
@Test
public void run() throws Exception {
final PathsPromoteResult result = client.module(IndyPromoteClientModule.class).promoteByPath(new PathsPromoteRequest(source.getKey(), target.getKey()).setDryRun(true));
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());
assertThat(client.content().exists(target.getKey(), first), equalTo(false));
assertThat(client.content().exists(target.getKey(), second), equalTo(false));
}
use of org.commonjava.indy.promote.model.PathsPromoteRequest in project indy by Commonjava.
the class PromoteWithPurgeThenRollbackTest method run.
@Test
public void run() throws Exception {
PathsPromoteResult result = client.module(IndyPromoteClientModule.class).promoteByPath(new PathsPromoteRequest(source.getKey(), target.getKey()).setPurgeSource(true));
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 = client.module(IndyPromoteClientModule.class).rollbackPathPromote(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());
assertThat(client.content().exists(target.getKey().getType(), target.getName(), first), equalTo(false));
assertThat(client.content().exists(target.getKey().getType(), target.getName(), second), equalTo(false));
assertThat(client.content().exists(source.getKey().getType(), source.getName(), first), equalTo(true));
assertThat(client.content().exists(source.getKey().getType(), source.getName(), second), equalTo(true));
}
use of org.commonjava.indy.promote.model.PathsPromoteRequest in project indy by Commonjava.
the class RollbackTwoArtifactsAsyncTest method run.
@Test
public void run() throws Exception {
PathsPromoteResult result = client.module(IndyPromoteClientModule.class).promoteByPath(getAsyncRequest(new PathsPromoteRequest(source.getKey(), target.getKey())));
assertEquals(result.getResultCode(), ACCEPTED);
result = getAsyncPromoteResult(PathsPromoteResult.class);
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 = client.module(IndyPromoteClientModule.class).rollbackPathPromote(result);
assertEquals(result.getResultCode(), ACCEPTED);
result = getAsyncPromoteResult(PathsPromoteResult.class);
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());
assertThat(client.content().exists(target.getKey(), first), equalTo(false));
assertThat(client.content().exists(target.getKey(), second), equalTo(false));
}
use of org.commonjava.indy.promote.model.PathsPromoteRequest 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.PathsPromoteRequest in project indy by Commonjava.
the class PromotionManager method runPathPromotions.
private PathsPromoteResult runPathPromotions(final PathsPromoteRequest request, final Set<String> pending, final List<Transfer> contents, final ValidationResult validation) {
long begin = System.currentTimeMillis();
PromotionHelper.PromotionRepoRetrievalResult checkResult = promotionHelper.checkAndRetrieveSourceAndTargetRepos(request);
if (checkResult.hasErrors()) {
return new PathsPromoteResult(request, pending, emptySet(), emptySet(), StringUtils.join(checkResult.errors, "\n"), validation);
}
final ArtifactStore targetStore = checkResult.targetStore;
StoreKey targetKey = targetStore.getKey();
logger.info("Run promotion from: {} to: {}, paths: {}", request.getSource(), targetKey, pending);
Set<Group> affectedGroups;
try {
affectedGroups = storeManager.query().getGroupsAffectedBy(targetKey);
logger.info("Calculate affected groups, target: {}, affected-groups: {}", targetKey, affectedGroups);
} catch (IndyDataException e) {
logger.error("Get affected groups failed", e);
return new PathsPromoteResult(request, pending, emptySet(), emptySet(), "Get affected groups failed, " + e.getMessage(), validation);
}
DrainingExecutorCompletionService<Set<PathTransferResult>> svc = new DrainingExecutorCompletionService<>(transferService);
int corePoolSize = transferService.getCorePoolSize();
int size = contents.size();
int batchSize = getParalleledBatchSize(size, corePoolSize);
logger.info("Execute parallel on collection, size: {}, batch: {}", size, batchSize);
Collection<Collection<Transfer>> batches = batch(contents, batchSize);
final List<String> errors = new ArrayList<>();
try {
detectOverloadVoid(() -> batches.forEach(batch -> svc.submit(newPathPromotionsJob(batch, targetStore, request, affectedGroups))));
} catch (IndyWorkflowException e) {
// might be PoolOverloadException. Log it and continue to revert any completed paths
String msg = String.format("Failed to submit all path promotion jobs. Error: %s", e.toString());
logger.error(msg, e);
errors.add(msg);
}
final Set<PathTransferResult> results = new HashSet<>();
try {
svc.drain(results::addAll);
} catch (InterruptedException | ExecutionException e) {
String msg = String.format("Error waiting for promotion of: %s to: %s", request.getSource(), request.getTarget());
logger.error(msg, e);
errors.add(msg);
}
final Set<String> completed = new HashSet<>();
final Set<String> skipped = new HashSet<>();
results.forEach(result -> {
if (result.error != null) {
errors.add(result.error);
} else if (result.skipped) {
skipped.add(result.path);
} else {
completed.add(result.path);
}
});
PathsPromoteResult result;
if (!errors.isEmpty()) {
List<String> rollbackErrors = promotionHelper.deleteFromStore(completed, targetStore);
errors.addAll(rollbackErrors);
result = new PathsPromoteResult(request, pending, emptySet(), emptySet(), StringUtils.join(errors, "\n"), validation);
} else {
result = new PathsPromoteResult(request, emptySet(), completed, skipped, null, validation);
final String name = String.format("PromoteNFCClean-method(%s)-source(%s)-target(%s)", "runPathPromotions", request.getSource(), targetStore.getKey());
final String context = String.format("Class: %s, method: %s, source: %s, target: %s", this.getClass().getName(), "runPathPromotions", request.getSource(), targetStore.getKey());
storeManager.asyncGroupAffectedBy(new StoreDataManager.ContextualTask(name, context, () -> promotionHelper.clearStoreNFC(completed, targetStore, affectedGroups)));
if (request.isFireEvents()) {
fireEvent(promoteCompleteEvent, new PathsPromoteCompleteEvent(result));
}
}
logger.info("Promotion completed, promotionId: {}, timeInSeconds: {}", request.getPromotionId(), timeInSeconds(begin));
return result;
}
Aggregations