* invalid
*/
public boolean synchronizeRepo(int repoId) {
log.debug("synchronizeRepo() :: start");
RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
Subject overlord = subjectManager.getOverlord();
// Load the repo to sync
Repo repo = repoManager.getRepo(overlord, repoId);
if (repo == null) {
throw new IllegalArgumentException("Invalid repository with id [" + repoId + "] specified for sync.");
}
// results =
// contentSourceManager.persistContentSourceSyncResults(results);
StringBuilder progress = new StringBuilder();
progress.append(new Date()).append(": ");
progress.append("Start synchronization of Repository [").append(repo.getName()).append("]\n");
progress.append(new Date()).append(": ");
progress.append("Getting currently known list of content source packages...\n");
SyncTracker tracker = new SyncTracker(new RepoSyncResults(repo), new ProgressWatcher());
tracker.setResults(progress.toString());
tracker.setRepoSyncResults(repoManager.persistRepoSyncResults(tracker.getRepoSyncResults()));
log.debug("synchronizeRepo :: inProgress");
tracker = updatePercentComplete(tracker, repoManager);
if (tracker.getRepoSyncResults() == null) {
log.info("Repository [" + repo.getName()
+ "] is already currently being synchronized - this sync request will be ignored.");
return false;
}
boolean syncCancelled = false;
try {
ThreadUtil.checkInterrupted();
// Sync each of the content sources associated with the repo.
for (ContentSource source : repo.getContentSources()) {
try {
ContentProvider provider = getIsolatedContentProvider(source.getId());
SyncProgressWeight sw = provider.getSyncProgressWeight();
PackageSourceSynchronizer packageSourceSynchronizer = new PackageSourceSynchronizer(repo, source,
provider);
log.debug("synchronizeRepo :: synchronizePackageMetadata");
tracker = updateSyncStatus(tracker, ContentSyncStatus.PACKAGEMETADATA);
tracker = packageSourceSynchronizer.synchronizePackageMetadata(tracker);
} catch (Exception e) {
processSyncException(e, tracker, repo, source, repoManager);
}
}
ThreadUtil.checkInterrupted();
// Setup ProgressWatcher
for (ContentSource source : repo.getContentSources()) {
ContentProvider provider = getIsolatedContentProvider(source.getId());
SyncProgressWeight sw = provider.getSyncProgressWeight();
tracker.getProgressWatcher().addWork(sw.getPackageMetadataWeight());
tracker.addAdvisoryMetadataWork(provider);
tracker.getProgressWatcher().addWork(sw.getDistribtutionBitsWeight());
tracker.getProgressWatcher().addWork(sw.getDistribtutionMetadataWeight());
tracker.addPackageBitsWork(provider);
tracker.getProgressWatcher().finishWork(sw.getPackageMetadataWeight());
}
tracker = updatePercentComplete(tracker, repoManager);
// Sync package bits.
for (ContentSource source : repo.getContentSources()) {
// Don't let the entire sync fail if a single content source
// fails
try {
ContentProvider provider = getIsolatedContentProvider(source.getId());
if (provider instanceof PackageSource) {
PackageSourceSynchronizer packageSourceSyncer = new PackageSourceSynchronizer(repo, source,
provider);
log.debug("synchronizeRepo :: synchronizePackageBits");
tracker = updateSyncStatus(tracker, ContentSyncStatus.PACKAGEBITS);
tracker = packageSourceSyncer.synchronizePackageBits(tracker, provider);
tracker = updatePercentComplete(tracker, repoManager);
}
} catch (Exception e) {
processSyncException(e, tracker, repo, source, repoManager);
}
// Check for cancellation after each content source.
ThreadUtil.checkInterrupted();
}
// Sync distro metadata.
log.debug("synchronizeRepo :: synchronizeDistributionMetadata");
for (ContentSource source : repo.getContentSources()) {
try {
ContentProvider provider = getIsolatedContentProvider(source.getId());
if (provider instanceof DistributionSource) {
DistributionSourceSynchronizer distroSourceSyncer = new DistributionSourceSynchronizer(
repo, source, provider);
tracker = updateSyncStatus(tracker, ContentSyncStatus.DISTROMETADATA);
tracker = distroSourceSyncer.synchronizeDistributionMetadata(tracker);
tracker = updatePercentComplete(tracker, repoManager);
}
} catch (Exception e) {
processSyncException(e, tracker, repo, source, repoManager);
}
// Check for cancellation after each content source.
ThreadUtil.checkInterrupted();
}
// Sync distro bits.
log.debug("synchronizeRepo :: synchronizeDistributionBits");
for (ContentSource source : repo.getContentSources()) {
try {
ContentProvider provider = getIsolatedContentProvider(source.getId());
if (provider instanceof DistributionSource) {
DistributionSourceSynchronizer distroSourceSyncer = new DistributionSourceSynchronizer(
repo, source, provider);
tracker = updateSyncStatus(tracker, ContentSyncStatus.DISTROBITS);
tracker = distroSourceSyncer.synchronizeDistributionBits(tracker);
tracker = updatePercentComplete(tracker, repoManager);
}
ThreadUtil.checkInterrupted();
} catch (Exception e) {
processSyncException(e, tracker, repo, source, repoManager);
}
// Check for cancellation after each content source.
ThreadUtil.checkInterrupted();
}
// Sync advisory metadata.
log.debug("synchronizeRepo :: synchronizeAdvisoryMetadata");
for (ContentSource source : repo.getContentSources()) {
try {
ContentProvider provider = getIsolatedContentProvider(source.getId());
if (provider instanceof AdvisorySource) {
tracker = updateSyncStatus(tracker, ContentSyncStatus.ADVISORYMETADATA);
AdvisorySourceSynchronizer advisorySourceSyncer = new AdvisorySourceSynchronizer(repo, source,
provider);
tracker = advisorySourceSyncer.synchronizeAdvisoryMetadata(tracker);
tracker = updatePercentComplete(tracker, repoManager);
}
} catch (Exception e) {
processSyncException(e, tracker, repo, source, repoManager);
}
// Check for cancellation after each content source.
ThreadUtil.checkInterrupted();
}
// Update status to finished.
if (tracker.getRepoSyncResults().getStatus() != ContentSyncStatus.FAILURE) {
tracker.getRepoSyncResults().setStatus(ContentSyncStatus.SUCCESS);
}
tracker = updateSyncStatus(tracker, tracker.getRepoSyncResults().getStatus());
progress = new StringBuilder();
progress.append("\n");
progress.append(tracker.getRepoSyncResults().getResults());
progress.append("\n");
progress.append(new Date()).append(": ");
progress.append("Repository [").append(repo.getName()).append("] ");
progress.append("completed syncing with ");
progress.append((tracker.getRepoSyncResults().getStatus() == ContentSyncStatus.FAILURE) ? "one or more" : "no");
progress.append(" errors.\n");
tracker.setResults(progress.toString());
log.debug("synchronizeRepo :: " + tracker.getRepoSyncResults().getStatus());
} catch (InterruptedException e) {
RepoSyncResults recentResults = repoManager.getMostRecentSyncResults(overlord, repo.getId());
log.debug("Caught InterruptedException during sync of repo with id [" + repoId + "].");
progress.append("\n ** Cancelled syncing **");
tracker.setResults(progress.toString());
tracker.getProgressWatcher().resetToZero();
tracker = updatePercentComplete(tracker, repoManager);
try {
tracker = updateSyncStatus(tracker, ContentSyncStatus.CANCELLED);
} catch (InterruptedException e1) {
throw new RuntimeException("Unexpected InterruptedException", e1);
}
syncCancelled = true;
}
if (tracker.getRepoSyncResults() != null) {
// pw.stop();
tracker.getRepoSyncResults().setEndTime(System.currentTimeMillis());
// results.setPercentComplete(new
// Long(pw.getPercentComplete()));
repoManager.mergeRepoSyncResults(tracker.getRepoSyncResults());
log.debug("synchronizeRepo :: merging results.");
}
return !syncCancelled;
}