diff src/goodjava/lucene/backup/BackupIndexWriter.java @ 1512:31b543826ca9

lucene.backup login
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 23 May 2020 19:01:57 -0600
parents 0ba144491a42
children 634f6765830e
line wrap: on
line diff
--- a/src/goodjava/lucene/backup/BackupIndexWriter.java	Fri May 22 19:10:14 2020 -0600
+++ b/src/goodjava/lucene/backup/BackupIndexWriter.java	Sat May 23 19:01:57 2020 -0600
@@ -28,15 +28,17 @@
 	private static final Logger logger = LoggerFactory.getLogger(BackupIndexWriter.class);
 	public static String[] backupDomains;
 	private final String name;
+	private final String password;
 	private final File dir;
 	private boolean isSyncPending = false;
 	private final ExecutorService exec = Executors.newSingleThreadExecutor();
 
-	public BackupIndexWriter(LuceneIndexWriter indexWriter,File logDir,String name) throws IOException {
+	public BackupIndexWriter(LuceneIndexWriter indexWriter,File logDir,String name,String password) throws IOException {
 		super(indexWriter,logDir);
 		if( backupDomains == null )
 			throw new RuntimeException("must set backupDomains");
 		this.name = name;
+		this.password = password;
 		File f = new File(System.getProperty("java.io.tmpdir"));
 		dir = new File(f,"goodjava.lucene/"+name);
 		IoUtils.mkdirs(dir);
@@ -121,12 +123,15 @@
 		}
 		for( String backupDomain : backupDomains ) {
 			RpcClient rpc = BackupServer.rpcClient(backupDomain);
-			RpcCall call = new RpcCall("check",name,logInfo);
 			try {
+				RpcCall call = new RpcCall("login",name,password);
+				rpc.write(call);
+				rpc.read();
+				call = new RpcCall("check",logInfo);
 				while(true) {
 					rpc.write(call);
 					RpcResult result = rpc.read();
-					logger.info(Arrays.asList(result.returnValues).toString());
+					//logger.info(Arrays.asList(result.returnValues).toString());
 					String status = (String)result.returnValues[0];
 					if( status.equals("ok") ) {
 						break;
@@ -137,7 +142,7 @@
 						LogFile log = logMap.get(fileName);
 						long len = log.end() - 8;
 						InputStream in = log.input();
-						call = new RpcCall(in,len,"add",name,logInfo,fileName);
+						call = new RpcCall(in,len,"add",logInfo,fileName);
 					} else if( status.equals("incomplete") ) {
 						String fileName = (String)result.returnValues[1];
 						long logEnd = (Long)result.returnValues[2];
@@ -145,7 +150,7 @@
 						long len = log.end() - logEnd;
 						InputStream in = log.input();
 						in.skip(logEnd-8);
-						call = new RpcCall(in,len,"append",name,logInfo,fileName);
+						call = new RpcCall(in,len,"append",logInfo,fileName);
 					} else
 						throw new RuntimeException("status "+status);
 				}