コード例 #1
0
ファイル: Bootstrap.java プロジェクト: pes2009k/whois
 private String loadTextDump(String[] dumpfile, final Loader loader) {
   try {
     sourceContext.setCurrentSourceToWhoisMaster();
     return loader.loadSplitFiles(dumpfile);
   } finally {
     sourceContext.removeCurrentSource();
   }
 }
コード例 #2
0
ファイル: JdbcRpslObjectDao.java プロジェクト: RIPE-NCC/whois
  @Override
  public void load(final List<Identifiable> proxy, final List<RpslObject> result) {
    final Map<Integer, RpslObject> loadedObjects = Maps.newHashMapWithExpectedSize(proxy.size());

    Set<Integer> differences = loadObjects(proxy, loadedObjects);
    if (!differences.isEmpty()) {
      final Source originalSource = sourceContext.getCurrentSource();
      LOGGER.info("Objects in source {} not found for ids: {}", originalSource, differences);

      if (originalSource.getType().equals(Source.Type.SLAVE)) {
        final Source masterSource = Source.master(originalSource.getName());
        try {
          sourceContext.setCurrent(masterSource);
          differences = loadObjects(proxy, loadedObjects);
          if (!differences.isEmpty()) {
            LOGGER.info("Objects in source {} not found for ids: {}", masterSource, differences);
          }
        } catch (IllegalSourceException e) {
          LOGGER.debug("Source not configured: {}", masterSource, e);
        } finally {
          sourceContext.setCurrent(originalSource);
        }
      }
    }

    final List<RpslObject> rpslObjects = Lists.newArrayList(loadedObjects.values());
    Collections.sort(
        rpslObjects,
        new Comparator<RpslObject>() {
          final List<Integer> requestedIds =
              Lists.newArrayList(
                  Iterables.transform(
                      proxy,
                      new Function<Identifiable, Integer>() {
                        @Override
                        public Integer apply(final Identifiable input) {
                          return input.getObjectId();
                        }
                      }));

          @Override
          public int compare(final RpslObject o1, final RpslObject o2) {
            return requestedIds.indexOf(o1.getObjectId()) - requestedIds.indexOf(o2.getObjectId());
          }
        });

    // TODO [AK] Return result rather than adding all to the collection
    result.addAll(rpslObjects);
  }
コード例 #3
0
 @Before
 public void setUp() throws Exception {
   when(request.getRemoteAddr()).thenReturn("127.0.0.1");
   when(messageHandler.handle(any(UpdateRequest.class), any(UpdateContext.class)))
       .thenReturn(new UpdateResponse(UpdateStatus.SUCCESS, "OK"));
   when(sourceContext.getCurrentSource()).thenReturn(Source.master("TEST"));
 }
コード例 #4
0
ファイル: GrsSourceImporter.java プロジェクト: pes2009k/whois
  void grsImport(final GrsSource grsSource, final boolean rebuild) {
    final AuthoritativeResource authoritativeResource = grsSource.getAuthoritativeResource();

    if (sourceContext.isVirtual(grsSource.getName())) {
      grsSource.getLogger().info("Not updating GRS data");
    } else {
      acquireAndUpdateGrsData(grsSource, rebuild, authoritativeResource);
    }

    resourceTagger.tagObjects(grsSource);
  }
コード例 #5
0
ファイル: Bootstrap.java プロジェクト: pes2009k/whois
  public String bootstrap() {
    if (dumpFileLocation == null
        || dumpFileLocation.length == 0
        || dumpFileLocation[0] == null
        || dumpFileLocation[0].length() == 0) {
      return "Bootstrap is not enabled (dump file undefined)";
    }
    try {
      sourceContext.setCurrentSourceToWhoisMaster();
      loaderRisky.resetDatabase();

      // wait until trees pick up empty DB to avoid case where few updates done and new objects
      // added to text dump result in
      // treeupdaters not recognising rebuild is needed
      Uninterruptibles.sleepUninterruptibly(IpTreeUpdater.TREE_UPDATE_IN_SECONDS, TimeUnit.SECONDS);

      return loaderRisky.loadSplitFiles(dumpFileLocation);
    } finally {
      sourceContext.removeCurrentSource();
    }
  }
コード例 #6
0
 private boolean sourceMatchesContext(final String source) {
   return (source != null)
       && sourceContext.getCurrentSource().getName().equals(CIString.ciString(source));
 }