コード例 #1
0
@Configuration
public class LakeviewModule {

  private static final RepetitionRule LAKEVIEW_UPLOAD =
      RepetitionRules.every(Duration.standardHours(12)).withOffset(Duration.standardHours(4));
  private static final String SERVICE_NAME = "lakeview";
  private static final String REMOTE_ID = "azure";

  @Autowired ContentLister contentLister;
  @Autowired ContentResolver contentResolver;
  @Autowired AdapterLog log;
  @Autowired SimpleScheduler scheduler;
  @Autowired DatabasedMongo mongo;
  @Autowired ChannelResolver channelResolver;

  private @Value("${lakeview.upload.enabled}") String enabled;
  private @Value("${lakeview.upload.container}") String container;
  private @Value("${lakeview.upload.account}") String account;
  private @Value("${lakeview.upload.key}") String key;

  private @Value("${lakeview.feature.genericTitlesEnabled}") boolean genericTitlesEnabled;

  private @Value("${lakeview.feature.addXBoxOneAvailability}") boolean addXboxOneAvailability;

  private static final String SCHEMA_VERSION = "0_6";
  private static final String FILENAME_PROVIDER_ID = "CA1.Xbox4oD";

  public @Bean LakeviewController lakeviewController() {
    return new LakeviewController(
        lakeviewContentFetcher(), lakeviewFeedCompiler(), lakeviewFeedOutputter());
  }

  public @Bean LakeviewContentFetcher lakeviewContentFetcher() {
    return new LakeviewContentFetcher(contentLister, contentResolver);
  }

  public @Bean LakeviewFeedCompiler lakeviewFeedCompiler() {
    return new LakeviewFeedCompiler(channelResolver, genericTitlesEnabled, addXboxOneAvailability);
  }

  public @Bean XmlFeedOutputter lakeviewFeedOutputter() {
    return /* new ValidatingXmlFeedOutputter(lakeViewValidator(), */ new SerializingFeedOutputter() /* ) */;
  }

  public @Bean XMLValidator lakeViewValidator() {
    try {
      return XMLValidator.forSchemas(
          ImmutableSet.of(
              Resources.getResource("xml.xsd").openStream(),
              Resources.getResource("Lakeview_Content_Catalog_Feed.xsd").openStream()));
    } catch (Exception e) {
      log.record(
          new AdapterLogEntry(Severity.WARN)
              .withDescription("Couldn't load schemas for Lakeview XML validation")
              .withCause(e));
      return null;
    }
  }

  public @Bean HealthProbe lakeviewHealthProbe() {
    return new LakeviewServerHealthProbe(
        new SystemClock(), lakeviewFileValidator(), lakeviewResultStore(), REMOTE_ID);
  }

  public @Bean FileUploader lakeviewAzureUploader() {
    return ResultStoringFileUploader.resultStoringFileUploader(
        lakeviewResultStore(),
        SERVICE_NAME,
        REMOTE_ID,
        new AzureFileUploader(account, key, container));
  }

  public @Bean AzureLatestFileDownloader azureLatestFileDownloader() {
    return new AzureLatestFileDownloader(account, key, container);
  }

  public @Bean LakeviewFileValidator lakeviewFileValidator() {
    Clock clock = new SystemClock();
    Builder<LakeviewFeedValidationRule> validationRules = ImmutableList.builder();
    validationRules.add(new CompletenessValidationRule(contentLister, 200));
    validationRules.add(new HeirarchyValidationRule());
    validationRules.add(new UpToDateValidationRule(1, clock));
    // We need to find better candidates for this, as we don't see updates to these brands
    // validationRules.add(new
    // RecentUpdateToBrandValidationRule("http://channel4.com/en-GB/TVSeries/deal-or-no-deal", 5,
    // clock));
    // validationRules.add(new
    // RecentUpdateToBrandValidationRule("http://channel4.com/en-GB/TVSeries/countdown", 5, clock));
    return new LakeviewFileValidator(
        lakeviewContentFetcher(),
        lakeviewFeedCompiler(),
        lakeviewFeedOutputter(),
        validationRules.build(),
        log);
  }

  public @Bean FileUploadResultStore lakeviewResultStore() {
    return new MongoFileUploadResultStore(mongo);
  }

  @PostConstruct
  public void scheduleTasks() {
    if (Boolean.parseBoolean(enabled)) {
      LakeviewFileUpdater updater =
          new LakeviewFileUpdater(
              lakeviewContentFetcher(),
              lakeviewFeedCompiler(),
              lakeviewFeedOutputter(),
              FILENAME_PROVIDER_ID,
              SCHEMA_VERSION,
              lakeviewAzureUploader(),
              new SystemClock(),
              log);
      scheduler.schedule(updater.withName("Lakeview Azure updater"), LAKEVIEW_UPLOAD);
    }
  }
}
コード例 #2
0
  @Override
  public void configure() {
    MongoChannelGroupStore channelGroupStore = new MongoChannelGroupStore(mongo());
    MongoLookupEntryStore lookupEntryStore = contentLookupEntryStore();
    MongoContentResolver contentResolver = contentResolver();
    BroadcastBooster booster =
        new ChannelGroupBroadcastChannelBooster(
            mongoChannelGroupStore(), channelResolver(), priorityChannelGroup);
    CachingChannelStore channelStore =
        new CachingChannelStore(
            new MongoChannelStore(mongo(), channelGroupStore, channelGroupStore));
    SimpleScheduler simplescheduler = new SimpleScheduler();

    channelStore.start();
    LuceneContentIndex index =
        new LuceneContentIndex(
            new File(luceneDir), contentResolver, booster, channelStore, backupDirectory);

    IndexBackupScheduledTask indexBackupTask = new IndexBackupScheduledTask(index);
    simplescheduler.schedule(indexBackupTask, RepetitionRules.every(Duration.standardHours(24)));

    Builder<HealthProbe> probes = ImmutableList.builder();

    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(3);
    ReloadingContentBootstrapper mongoBootstrapper =
        new ReloadingContentBootstrapper(
            index,
            mongoBootstrapper(),
            scheduler,
            Boolean.valueOf(luceneIndexAtStartup),
            180,
            TimeUnit.MINUTES);
    probes.add(new LuceneSearcherProbe("mongo-lucene", mongoBootstrapper));

    ReloadingContentBootstrapper cassandraBootstrapper = null;
    if (Boolean.valueOf(enableCassandra)) {
      cassandraBootstrapper =
          new ReloadingContentBootstrapper(
              index,
              cassandraBootstrapper(),
              scheduler,
              Boolean.valueOf(luceneIndexAtStartup),
              7,
              TimeUnit.DAYS);
      probes.add(new LuceneSearcherProbe("cassandra-lucene", cassandraBootstrapper));
    }

    ReloadingContentBootstrapper musicBootStrapper = null;
    if (Boolean.valueOf(enableMusic)) {
      musicBootStrapper =
          new ReloadingContentBootstrapper(
              index, musicBootstrapper(), scheduler, true, 120, TimeUnit.MINUTES);
      probes.add(new LuceneSearcherProbe("mongo-music", musicBootStrapper));
    }

    bind("/system/health", new HealthController(probes.build()));
    bind("/titles", new SearchServlet(new JsonSearchResultsView(), index));
    bind("/debug/document", new DocumentController(index));
    bind(
        "/index",
        new ContentIndexController(
            new LookupResolvingContentResolver(contentResolver, lookupEntryStore), index));
    bind("/system/backup", new BackupController(index));

    mongoBootstrapper.startAsync();

    if (cassandraBootstrapper != null) {
      cassandraBootstrapper.startAsync();
    }

    if (musicBootStrapper != null) {
      musicBootStrapper.startAsync();
    }
  }