use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class GroupPromoteAndRollbackAsyncTest method run.
@Test
public void run() throws Exception {
GroupPromoteResult result = client.module(IndyPromoteClientModule.class).promoteToGroup(getAsyncRequest(new GroupPromoteRequest(source.getKey(), target.getName())));
assertEquals(result.getResultCode(), ACCEPTED);
result = getAsyncPromoteResult(GroupPromoteResult.class);
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTarget().getName(), equalTo(target.getName()));
assertThat(result.getError(), nullValue());
assertThat(client.content().exists(target.getKey().getType(), target.getName(), first), equalTo(true));
assertThat(client.content().exists(target.getKey().getType(), target.getName(), second), equalTo(true));
Group g = client.stores().load(StoreType.group, target.getName(), Group.class);
assertThat(g.getConstituents().contains(source.getKey()), equalTo(true));
// now rollback.
result = client.module(IndyPromoteClientModule.class).rollbackGroupPromote(result);
assertThat(result.getError(), nullValue());
// wait for events to propagate and remove indexed values.
Thread.sleep(2000);
assertThat(client.content().exists(target.getKey().getType(), target.getName(), first), equalTo(false));
assertThat(client.content().exists(target.getKey().getType(), target.getName(), second), equalTo(false));
g = client.stores().load(StoreType.group, target.getName(), Group.class);
assertThat(g.getConstituents().contains(source.getKey()), equalTo(false));
}
use of org.commonjava.indy.model.core.Group 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;
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class GroupNFCEntryClearedOnByPathPromoteTest method setupRepos.
@Before
public void setupRepos() throws IndyClientException {
String message = "test setup";
a = client.stores().create(new HostedRepository(MAVEN_PKG_KEY, HOSTED_A_NAME), message, HostedRepository.class);
b = client.stores().create(new HostedRepository(MAVEN_PKG_KEY, HOSTED_B_NAME), message, HostedRepository.class);
g = client.stores().create(new Group(MAVEN_PKG_KEY, GROUP_G_NAME, a.getKey()), message, Group.class);
client.content().store(b.getKey(), PATH, new ByteArrayInputStream(POM_CONTENT.getBytes()));
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class GroupHostedMetadataRemergedOnPromoteTest method setupRepos.
@Before
public void setupRepos() throws IndyClientException {
String message = "test setup";
a = client.stores().create(new HostedRepository(HOSTED_A_NAME), message, HostedRepository.class);
b = client.stores().create(new HostedRepository(HOSTED_B_NAME), message, HostedRepository.class);
c = client.stores().create(new HostedRepository(HOSTED_C_NAME), message, HostedRepository.class);
g = client.stores().create(new Group(GROUP_G_NAME, a.getKey(), b.getKey()), message, Group.class);
client.content().store(a.getKey(), PATH, new ByteArrayInputStream(REPO_CONTENT_TEMPLATE.replaceAll("%version%", A_VERSION).getBytes()));
client.content().store(b.getKey(), PATH, new ByteArrayInputStream(REPO_CONTENT_TEMPLATE.replaceAll("%version%", B_VERSION).getBytes()));
client.content().store(c.getKey(), PATH, new ByteArrayInputStream(REPO_CONTENT_TEMPLATE.replaceAll("%version%", C_VERSION).getBytes()));
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class PromotionHelper method clearStoreNFC.
/**
* Clear NFC for the source store and affected groups.
*
* @param sourcePaths The set of paths that need to be cleared from the NFC.
* @param store The store whose affected groups should have their NFC entries cleared
*/
public void clearStoreNFC(final Set<String> sourcePaths, final ArtifactStore store, final Set<Group> affectedGroups) {
Set<String> paths = sourcePaths.stream().map(sp -> sp.startsWith("/") && sp.length() > 1 ? sp.substring(1) : sp).collect(Collectors.toSet());
paths.forEach(path -> {
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
logger.trace("Clearing NFC path: {} from: {}\n\tResource: {}", path, store.getKey(), resource);
nfc.clearMissing(resource);
});
Set<Group> groups;
if (affectedGroups != null) {
groups = affectedGroups;
} else {
try {
groups = storeManager.query().getGroupsAffectedBy(store.getKey());
} catch (IndyDataException e) {
logger.warn("Failed to clear NFC for groups affected by " + store.getKey(), e);
return;
}
}
if (groups != null) {
groups.forEach(group -> {
KeyedLocation gl = LocationUtils.toLocation(group);
paths.forEach(path -> {
ConcreteResource resource = new ConcreteResource(gl, path);
logger.trace("Clearing NFC path: {} from: {}\n\tResource: {}", path, group.getKey(), resource);
nfc.clearMissing(resource);
});
});
}
}
Aggregations