Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Michael Ritter
chronopolis-core
Commits
534ffa53
Commit
534ffa53
authored
Oct 30, 2014
by
Michael Ritter
Browse files
log any errors from rsync
parent
f8919c92
Changes
1
Hide whitespace changes
Inline
Side-by-side
common/src/main/java/org/chronopolis/common/transfer/RSyncTransfer.java
View file @
534ffa53
package
org.chronopolis.common.transfer
;
import
org.chronopolis.common.exception.FileTransferException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.nio.file.Path
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.FutureTask
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
org.chronopolis.common.exception.FileTransferException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* TODO: If the rsync cannot connect it will simply hang.
*
We need some sort of prevention against that.
*
Note: Can make a ScheduledFuture w/ a timeout
* We need some sort of prevention against that.
* Note: Can make a ScheduledFuture w/ a timeout
*
* @author shake
*/
...
...
@@ -53,18 +53,18 @@ public class RSyncTransfer implements FileTransfer {
try
{
log
.
info
(
"Executing {} {} {} {} {}"
,
cmd
);
p
=
pb
.
start
();
p
.
waitFor
();
int
exit
=
p
.
waitFor
();
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
p
.
getInputStream
()));
StringBuilder
out
=
new
StringBuilder
();
String
line
=
null
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
out
.
append
(
line
).
append
(
"\n"
);
}
stats
=
out
.
toString
();
stats
=
stringFromStream
(
p
.
getInputStream
());
log
.
info
(
"rsync exit stats:\n {}"
,
stats
);
}
catch
(
IOException
e
)
{
if
(
exit
!=
0
)
{
log
.
error
(
"rsync did not complete successfully (exit code {}) \n {}"
,
exit
,
stringFromStream
(
p
.
getErrorStream
()));
}
}
catch
(
IOException
e
)
{
log
.
error
(
"IO Exception in rsync "
,
e
);
throw
new
FileTransferException
(
"IOException in rsync"
,
e
);
}
catch
(
InterruptedException
e
)
{
...
...
@@ -92,6 +92,16 @@ public class RSyncTransfer implements FileTransfer {
}
}
private
String
stringFromStream
(
InputStream
is
)
throws
IOException
{
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
is
));
StringBuilder
out
=
new
StringBuilder
();
String
line
=
null
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
out
.
append
(
line
).
append
(
"\n"
);
}
return
out
.
toString
();
}
@Override
public
void
put
(
final
Path
localFile
,
final
String
uri
)
throws
FileTransferException
{
Callable
<
Boolean
>
upload
=
new
Callable
()
{
...
...
@@ -125,8 +135,8 @@ public class RSyncTransfer implements FileTransfer {
threadPool
.
execute
(
timedTask
);
try
{
timedTask
.
get
(
1
,
TimeUnit
.
DAYS
);
}
catch
(
InterruptedException
|
ExecutionException
|
TimeoutException
e
)
{
timedTask
.
get
(
1
,
TimeUnit
.
DAYS
);
}
catch
(
InterruptedException
|
ExecutionException
|
TimeoutException
e
)
{
log
.
error
(
"rsync had a critical error"
,
e
);
throw
new
FileTransferException
(
"rsync had a critical error"
,
e
);
}
finally
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment