return false; } else if (!contentSource.equals(other.contentSource)) { return false;
+ contentSource.getContentSourceType() + "]"); adapter.initialize(contentSource.getConfiguration()); } catch (Exception e) { log.warn("Failed to initialize adapter for content source [" + contentSource.getName() + "]");
ContentSource loaded = entityManager.find(ContentSource.class, contentSource.getId()); if (contentSource.getConfiguration() == null) { if (loaded.getConfiguration() != null) { entityManager.remove(loaded.getConfiguration()); if (!loaded.getName().equals(contentSource.getName())) { log.info("Content source [" + loaded.getName() + "] is being renamed to [" + contentSource.getName() + "]. Will now unschedule the old sync job"); try {
/** * Creates the name for the scheduled content source's sync job. Calling this * method multiple times with the same content source always produces the same name. * * @param cs the content source whose scheduled job name is to be returned * * @return the scheduled job name for the given content source */ public static String createJobName(ContentSource cs) { // the quartz table has a limited column width of 80 - but we need to use the names to make jobs unique // so encode the names' hashcodes to ensure we fix into the quartz job name column. String nameEncoded = Integer.toHexString(cs.getName().hashCode()); String typeNameEncoded = Integer.toHexString(cs.getContentSourceType().getName().hashCode()); String jobName = nameEncoded + SEPARATOR + typeNameEncoded; if (jobName.length() > 80) { throw new IllegalArgumentException("Job names max size is 80 chars due to DB column size restrictions: " + jobName); } return jobName; }
public void synchronizeCandidateRepos(StringBuilder progress) throws Exception { if (!(provider instanceof RepoSource)) { // Nothing to do. return; } progress.append(new Date()).append(": "); progress.append("Asking content source for new repositories to import...\n"); RepoSource repoSource = (RepoSource) provider; long start = System.currentTimeMillis(); // Call to the plugin RepoImportReport report = repoSource.importRepos(); Subject overlord = subjectManager.getOverlord(); repoManager.processRepoImportReport(overlord, report, source.getId(), progress); log.info("importRepos: [" + source.getName() + "]: report has been merged (" + (System.currentTimeMillis() - start) + ")ms"); } }
private void obfuscatePasswords(ContentSource contentSource) { ConfigurationDefinition configurationDefinition = contentSource.getContentSourceType().getContentSourceConfigurationDefinition(); if (configurationDefinition == null) { ContentSourceType attachedContentSourceType = getContentSourceType(contentSource.getContentSourceType().getName()); configurationDefinition = attachedContentSourceType.getContentSourceConfigurationDefinition(); } PasswordObfuscationUtility.obfuscatePasswords(configurationDefinition, contentSource.getConfiguration()); } }
if (source.getDownloadMode() == DownloadMode.NEVER) { String msg = "Download mode of NEVER for source [" + source.getName() + "], skipping " + "package bits sync for repo [" + repo.getName() + "]"; log.info(msg); if (source.isLazyLoad()) { String msg = "Lazy load enabled for source [" + source.getName() + "], skipping " + "package bits sync for repo [" + repo.getName() + "]"; log.info(msg); .getUnloadedPackageVersionsFromContentSourceInRepo(overlord, source.getId(), repo.getId(), pc); String msg = "Synchronize Package Bits: [" + source.getName() + "], repo [" + repo.getName() + "]: loaded package list for sync (" + (System.currentTimeMillis() - start) + ")ms"; log.info(msg); log.info("All package bits for content source [" + source.getName() + "] have been downloaded." + "The downloads started at [" + new Date(start) + "] and ended at [" + new Date() + "]");
/** * Given a ID to a content source, this returns the adapter that is * responsible for communicating with that content source where that adapter * object will ensure invocations on it are isolated to its plugin * classloader. * * @param contentProviderId * an ID to a {@link ContentSource} * @return the adapter that is communicating with the content source, * isolated to its classloader * @throws RuntimeException * if there is no content source with the given ID */ public ContentProvider getIsolatedContentProvider(int contentProviderId) throws RuntimeException { synchronized (this.adapters) { for (ContentSource contentSource : this.adapters.keySet()) { if (contentSource.getId() == contentProviderId) { return getIsolatedContentSourceAdapter(contentSource); } } } throw new RuntimeException("Content source ID [" + contentProviderId + "] doesn't exist; can't get adapter"); }
private PackageBits preparePackageBits(Subject subject, InputStream bitsStream, PackageVersionContentSource pvcs) { PackageVersionContentSourcePK pk = pvcs.getPackageVersionContentSourcePK(); int contentSourceId = pk.getContentSource().getId(); int packageVersionId = pk.getPackageVersion().getId(); String packageVersionLocation = pvcs.getLocation(); PreparedStatement ps2 = null; try { packageBits = createPackageBits(pk.getContentSource().getDownloadMode() == DownloadMode.DATABASE); if (pk.getContentSource().getDownloadMode() == DownloadMode.DATABASE) { packageBits = entityManager.find(PackageBits.class, packageBits.getId());
/** * This will schedule the sync job for the given content source. Once the scheduling is complete, the content * source's adapter will be asked to synchronize with the remote content source according to the time(s) specified * in the {@link ContentSource#getSyncSchedule() schedule}. * * <p>If the content source's sync schedule is empty, this method assumes it should not be automatically sync'ed, so * no schedule will be created, and this method simply returns.</p> * * @param contentSource provider to sync * * @throws SchedulerException if failed to schedule the job */ public void scheduleProviderSyncJob(ContentSource contentSource) throws SchedulerException { String syncSchedule = contentSource.getSyncSchedule(); if ((syncSchedule == null) || (syncSchedule.trim().length() == 0)) { getLog().debug(contentSource.toString() + " does not define a sync schedule - not scheduling."); return; } SchedulerLocal scheduler = LookupUtil.getSchedulerBean(); scheduler.scheduleCronJob(ContentProviderSyncJob.createJobName(contentSource), CONTENT_SRC_SYNC_JOB_GROUP_NAME, ContentProviderSyncJob.createJobDataMap(contentSource, null), ContentProviderSyncJob.class, true, false, syncSchedule); }
if (cs.getConfiguration() != null) { entityManager.remove(cs.getConfiguration()); List<ContentSourceSyncResults> results = cs.getSyncResults(); if (results != null) { int[] ids = new int[results.size()];
@Override public int hashCode() { int result = 1; result = (31 * result) + ((repo == null) ? 0 : repo.hashCode()); result = (31 * result) + ((contentSource == null) ? 0 : contentSource.hashCode()); return result; }
log.error("Synchronize Advisory: [" + source.getName() + "]: syncing repo [" + repo.getName() + "]"); ThreadUtil.checkInterrupted(); log.error("Synchronize Advisory: [" + source.getName() + "]: loaded existing list of size=[" + advs.size() + "] (" + (System.currentTimeMillis() - start) + ")ms"); ThreadUtil.checkInterrupted(); log.error("Synchronize Advisory: [" + source.getName() + "]: got sync report from adapter=[" + advReport + "] (" + (System.currentTimeMillis() - start) + ")ms"); ThreadUtil.checkInterrupted(); log.error("Synchronize Advisory: [" + source.getName() + "]: finished mergeAdvisorySyncReport (" + (System.currentTimeMillis() - start) + ")ms");
ServerPluginEnvironment env = this.pluginManager.getPluginEnvironment(contentSource.getContentSourceType()); if (env == null) { throw new RuntimeException("There is no plugin env. for content source [" + contentSource + "]");
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void _mergePackageSyncReportUpdateRepo(int contentSourceId) { // this method should be called only after a merge of a content source // added/updated/removed one or more packages. When this happens, we need to change // the last modified time for all repos that get content from the changed content source long now = System.currentTimeMillis(); ContentSource contentSource = entityManager.find(ContentSource.class, contentSourceId); Set<RepoContentSource> ccss = contentSource.getRepoContentSources(); for (RepoContentSource ccs : ccss) { ccs.getRepoContentSourcePK().getRepo().setLastModifiedDate(now); } return; }
if (contentSource.getDownloadMode().equals(DownloadMode.FILESYSTEM)) { List<PackageVersionContentSource> allPackageVersions = contentSourceManager .getPackageVersionsFromContentSource(subject, contentSourceId, pc);
/** * Creates a unique name for a new content source sync job. Calling this * method multiple times with the same content source always produces a different name * which is useful if you want to schedule an new job that is separate and distinct * from any other job in the system. * * @param cs the content source * * @return a unique job name that can be used for a new job to sync a given content source */ public static String createUniqueJobName(ContentSource cs) { // the quartz table has a limited column width of 80 - but we need to use the names to make jobs unique // so encode the names' hashcodes to ensure we fix into the quartz job name column. // appendStr is used to make the job unique among others for the same content source. String nameEncoded = Integer.toHexString(cs.getName().hashCode()); String typeNameEncoded = Integer.toHexString(cs.getContentSourceType().getName().hashCode()); String appendStr = Long.toHexString(System.currentTimeMillis()); String jobName = nameEncoded + SEPARATOR + typeNameEncoded + SEPARATOR + appendStr; if (jobName.length() > 80) { throw new IllegalArgumentException("Job names max size is 80 chars due to DB column size restrictions: " + jobName); } return jobName; } }
public ContentSourceSyncResults persistContentSourceSyncResults(ContentSourceSyncResults results) { ContentManagerHelper helper = new ContentManagerHelper(entityManager); Query q = entityManager.createNamedQuery(ContentSourceSyncResults.QUERY_GET_INPROGRESS_BY_CONTENT_SOURCE_ID); q.setParameter("contentSourceId", results.getContentSource().getId()); return (ContentSourceSyncResults) helper.persistSyncResults(q, results); }
existingPVCS = contentSourceManager.getPackageVersionsFromContentSourceForRepo(overlord, source.getId(), repo .getId()); log.info("Synchronize Packages: [" + source.getName() + "]: loaded existing list of size=[" + existingCount + "] (" + (System.currentTimeMillis() - start) + ")ms"); tracker.setPackageSyncCount(report.getNewPackages().size() + report.getUpdatedPackages().size()); log.info("Synchronize Packages: [" + source.getName() + "]: got sync report from adapter=[" + report + "] (" + (System.currentTimeMillis() - start) + ")ms. Have: " + tracker.getPackageSyncCount() + " packages to sync"); tracker.getRepoSyncResults()); tracker.setRepoSyncResults(syncResults); log.info("Synchronize Packages: [" + source.getName() + "]: merged sync report=(" + (System.currentTimeMillis() - start) + ")ms"); return tracker;
private InputStream preloadPackageBits(PackageVersionContentSource pvcs) throws Exception { PackageVersionContentSourcePK pk = pvcs.getPackageVersionContentSourcePK(); int contentSourceId = pk.getContentSource().getId(); int packageVersionId = pk.getPackageVersion().getId(); String packageVersionLocation = pvcs.getLocation(); switch (pk.getContentSource().getDownloadMode()) { case NEVER: { return null; // no-op, our content source was told to never download package bits