2014-01-15 3 views
1

LDIF 파일에서 LDAP 서버로 대량 가져 오기를 수행 할 수 있기를 원합니다. 언 바운드 ID LDAP SDK를 사용하는 작업 구현 (아래)이 있습니다. 이 문제는 LDIF의 각 항목을 반복하며 큰 파일 (수백만 개의 항목)에 대해 매우 느릴 수 있습니다. 고속 가져 오기에 사용할 수있는 도구/SDK가 있습니까? 이 프로그래밍 방식으로 달성 할 수 있어야합니다 (선호 자바). 감사!프로그래밍 방식으로 LDIF 대량 가져 오기

public static void importLdif(){ 
try{ 
    LDAPConnection connection = new LDAPConnection("ldapserver.com", 389, 
      "uid=admin,ou=system", "secret"); 
    LDIFReader ldifReader = new LDIFReader("C:/Users/ejamcud/Desktop/LDAP/ldifs/Sailors.ldif"); 

    int entriesRead = 0; 
    int entriesAdded = 0; 
    int errorsEncountered = 0; 
    Entry entry; 
    LDAPResult addResult; 
    while (true) 
    { 
     try 
     { 
      entry = ldifReader.readEntry(); 
      if (entry == null) 
      { 
       System.out.println("All entries have been read."); 
       break; 
      } 

      entriesRead++; 
     } 
     catch (LDIFException le) 
     { 
      errorsEncountered++; 
      if (le.mayContinueReading()) 
      { 
       // A recoverable error occurred while attempting to read a change 
       // record, at or near line number le.getLineNumber() 
       // The entry will be skipped, but we'll try to keep reading from the 
       // LDIF file. 
       continue; 
      } 
      else 
      { 
       // An unrecoverable error occurred while attempting to read an entry 
       // at or near line number le.getLineNumber() 
       // No further LDIF processing will be performed. 
       break; 
      } 
     } 
     catch (IOException ioe) 
     { 
      // An I/O error occurred while attempting to read from the LDIF file. 
      // No further LDIF processing will be performed. 
      errorsEncountered++; 
      break; 
     } 

     try 
     { 
      addResult = connection.add(entry); 
      // If we got here, then the change should have been processed 
      // successfully. 
      System.out.println(entry.toLDIFString()); 

      entriesAdded++; 
     } 
     catch (LDAPException le) 
     { 
      // If we got here, then the change attempt failed. 
      le.printStackTrace(); 
      addResult = le.toLDAPResult(); 
      errorsEncountered++; 
     } 
    } 

}catch(IOException ioe){ 
    ioe.printStackTrace(); 
} 
catch(LDAPException lde){ 
    lde.printStackTrace(); 
}finally{ 
    //ldifReader.close(); 
} 
} 
+0

준수하는 LDAP 서버와 함께 OpenLDAP 클라이언트 도구를 사용할 수 있습니다. – EJP

답변

2

정말 사용중인 디렉토리 서버에 따라 다릅니다. 일부 서버는 특정 조건에서 대량 추가를 지원하므로 사용중인 서버의 경우인지 여부를 조사해야 할 수 있습니다. 그러나 표준 LDAP 일 것을 원한다면 다중 스레드를 사용하여 서버에 항목을 추가하는 프로세스를 병렬 처리하는 것이 가장 좋습니다.

추가하는 항목에 대한 모든 상위 항목이 이미 존재하는 경우 (즉, 계층 구조는 추가하지 않고 리프 항목 만 추가하는 경우), UnboundID LDAP SDK를 사용하여 프로세스를 병렬 처리하는 것은 매우 간단합니다 여러 스레드에 걸쳐 LDIF 판독기는 이미 여러 스레드를 사용하여 LDIF 레코드 읽기 및 디코딩 프로세스를 병렬 처리하고 (구문 분석 스레드 수를 지정할 수있는 LDIFReader 생성자 사용), LDAP 추가를 수행하는 LDIFReaderEntryTranslator와 함께 사용할 수 있습니다 읽힌 항목의

계층 구조가있는 데이터를 추가해야하는 경우 상위가 추가 될 때까지 하위를 추가 할 수 없기 때문에 프로세스를 병렬화하는 것이 더 복잡합니다. 그러나 현재 추가중인 항목을 추적하고 일종의 잠금 메커니즘을 사용하여 상위 항목을 추가 할 때까지 하위 항목을 추가 할 수 없으므로 상당히 우수한 병렬 처리를 구현할 수 있습니다. 이것은 아마도 잠금을 필요로하지 않는 것처럼 빠르지 않을지라도, 다른 하위 트리에서 추가를 병렬화 할 수 있습니다.

+0

현재 Apacheds를 사용하고 있지만 향후 여러 가지 유형의 서버를 사용할 수 있습니다. – Sionnach733

관련 문제