Author: nzamosenchuk
Date: 2012-01-17 07:46:53 -0500 (Tue, 17 Jan 2012)
New Revision: 5467
Modified:
jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/RsyncIndexInfos.java
Log:
EXOJCR-1709 : Added Authentication options, added Std and Err stream support.
Modified:
jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
===================================================================
---
jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2012-01-17
12:12:18 UTC (rev 5466)
+++
jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2012-01-17
12:46:53 UTC (rev 5467)
@@ -219,13 +219,15 @@
// read RSYNC configuration
String rsyncEntryName = config.getParameterValue(PARAM_RSYNC_ENTRY_NAME, null);
String rsyncEntryPath = config.getParameterValue(PARAM_RSYNC_ENTRY_PATH, null);
+ String rsyncUserName = config.getParameterValue(PARAM_RSYNC_USER, null);
+ String rsyncPassword = config.getParameterValue(PARAM_RSYNC_PASSWORD, null);
int rsyncPort = config.getParameterInteger(PARAM_RSYNC_PORT,
PARAM_RSYNC_PORT_DEFAULT);
// rsync configured
if (rsyncEntryName != null)
{
return new RsyncIndexInfos(rootFqn, cache, system, modeHandler,
((SearchIndex)handler).getContext()
- .getIndexDirectory(), rsyncPort, rsyncEntryName, rsyncEntryPath);
+ .getIndexDirectory(), rsyncPort, rsyncEntryName, rsyncEntryPath,
rsyncUserName, rsyncPassword);
}
else
{
Modified:
jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/RsyncIndexInfos.java
===================================================================
---
jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/RsyncIndexInfos.java 2012-01-17
12:12:18 UTC (rev 5466)
+++
jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/RsyncIndexInfos.java 2012-01-17
12:46:53 UTC (rev 5467)
@@ -27,8 +27,11 @@
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jgroups.stack.IpAddress;
+import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.Serializable;
import java.util.Set;
@@ -48,11 +51,17 @@
private final String urlFormatString;
+ private final String rsyncUserName;
+
+ private final String rsyncPassword;
+
public RsyncIndexInfos(Fqn<String> rootFqn, Cache<Serializable, Object>
cache, boolean system,
- IndexerIoModeHandler modeHandler, String indexPath, int rsyncPort, String
rsyncEntryName, String rsyncEntryPath)
- throws RepositoryConfigurationException
+ IndexerIoModeHandler modeHandler, String indexPath, int rsyncPort, String
rsyncEntryName, String rsyncEntryPath,
+ String rsyncUserName, String rsyncPassword) throws
RepositoryConfigurationException
{
super(rootFqn, cache, system, modeHandler);
+ this.rsyncUserName = rsyncUserName;
+ this.rsyncPassword = rsyncPassword;
String absoluteRsyncEntryPath;
try
@@ -128,7 +137,8 @@
String address =
((IpAddress)((CacheSPI<Serializable,
Object>)cache).getRPCManager().getCoordinator()).getIpAddress()
.getHostAddress();
- RSyncJob rSyncJob = new RSyncJob(String.format(urlFormatString, address),
indexPath);
+ RSyncJob rSyncJob =
+ new RSyncJob(String.format(urlFormatString, address), indexPath,
rsyncUserName, rsyncPassword);
try
{
synchronized (this)
@@ -146,16 +156,26 @@
private class RSyncJob
{
+ private final static String RSYNC_USER_SYSTEM_PROPERTY = "USER";
+
+ private final static String RSYNC_PASSWORD_SYSTEM_PROPERTY =
"RSYNC_PASSWORD";
+
private Process process;
- private String src;
+ private final String src;
- private String dst;
+ private final String dst;
- public RSyncJob(String src, String dst)
+ private String userName;
+
+ private String password;
+
+ public RSyncJob(String src, String dst, String userName, String password)
{
this.src = src.endsWith(File.separator) ? src : src + File.separator;
this.dst = dst;
+ this.userName = userName;
+ this.password = password;
}
// TODO : Use JNI and librsync library? or handle err stream
@@ -166,8 +186,42 @@
{
String command = "rsync -rv --delete " + src + " " +
dst;
log.info("Rsync job started: " + command);
- process = run.exec(command);
+ if (userName != null && password != null)
+ {
+ String[] envProperties =
+ new String[]{RSYNC_USER_SYSTEM_PROPERTY + "=" + userName,
+ RSYNC_PASSWORD_SYSTEM_PROPERTY + "=" + password};
+ process = run.exec(command, envProperties);
+ }
+ else
+ {
+ process = run.exec(command);
+ }
+ // Handle process Standard and Error output
+ InputStream stderr = process.getErrorStream();
+ InputStreamReader isrErr = new InputStreamReader(stderr);
+ BufferedReader brErr = new BufferedReader(isrErr);
+
+ InputStream stdout = process.getInputStream();
+ InputStreamReader isrStd = new InputStreamReader(stdout);
+ BufferedReader brStd = new BufferedReader(isrStd);
+
+ String val = null;
+ StringBuilder stringBuilderErr = new StringBuilder();
+ StringBuilder stringBuilderStd = new StringBuilder();
+ while ((val = brStd.readLine()) != null)
+ {
+ stringBuilderStd.append(val);
+ stringBuilderStd.append('\n');
+ }
+
+ while ((val = brErr.readLine()) != null)
+ {
+ stringBuilderErr.append(val);
+ stringBuilderErr.append('\n');
+ }
+
Integer returnCode = null;
// wait for thread
while (returnCode == null)
@@ -181,10 +235,12 @@
// oops, this can happen sometimes
}
}
- log.info("Rsync job finished: " + returnCode);
+ log.info("Rsync job finished: " + returnCode + ". Error stream
output \n" + stringBuilderErr.toString()
+ + " Standard stream output \n" + stringBuilderStd.toString());
if (returnCode != 0)
{
- throw new IOException("RSync job finished with exit code is " +
returnCode);
+ throw new IOException("RSync job finished with exit code is " +
returnCode + ". Error stream output: \n"
+ + stringBuilderErr.toString());
}
}
finally