use of org.commonjava.indy.promote.change.event.PathsPromoteCompleteEvent in project indy by Commonjava.
the class EventAuditListener method onPromoteComplete.
public void onPromoteComplete(@Observes final PromoteCompleteEvent event) {
if (!eventAuditConfig.isEnabled()) {
return;
}
if (event instanceof PathsPromoteCompleteEvent) {
FileGroupingEvent fileGroupingEvent = new FileGroupingEvent(FileGroupingEventType.BY_PATH_PROMOTION);
transformFileGroupingEvent(event, fileGroupingEvent);
eventPublisher.publishFileGroupingEvent(fileGroupingEvent);
} else {
logger.trace("Unsupported grouping event: {}", event.getClass());
return;
}
}
use of org.commonjava.indy.promote.change.event.PathsPromoteCompleteEvent 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.promote.change.event.PathsPromoteCompleteEvent in project indy by Commonjava.
the class EventAuditListener method transformFileGroupingEvent.
private void transformFileGroupingEvent(PromoteCompleteEvent event, FileGroupingEvent fileGroupingEvent) {
PathsPromoteCompleteEvent pathsPromoteCompleteEvent = (PathsPromoteCompleteEvent) event;
PathsPromoteResult promoteResult = pathsPromoteCompleteEvent.getPromoteResult();
String error = promoteResult.getError();
if (error != null) {
logger.trace("Error in promoteResult, skip audit.");
return;
}
Set<String> paths = promoteResult.getCompletedPaths();
if (paths.isEmpty()) {
logger.trace("No completedPaths, skip audit.");
return;
}
PathsPromoteRequest req = promoteResult.getRequest();
StoreKey source = req.getSource();
StoreKey target = req.getTarget();
// TODO How about generating the key if it does not exist.
TrackingKey trackingKey = getTrackingKey(source);
if (trackingKey == null) {
logger.trace("No tracking key found to: {}", source);
return;
}
Map<String, String> extra = new HashMap<>();
extra.put(EventConstants.SOURCE, source.toString());
extra.put(EventConstants.TARGET, target.toString());
fileGroupingEvent.setExtra(extra);
fileGroupingEvent.setTimestamp(new Date());
fileGroupingEvent.setSessionId(trackingKey.getId());
}
Aggregations