-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#368 tryout remote reading minute diffs
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
server/src/main/scala/kpn/core/tools/next/support/TryoutReadReplicateTool.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package kpn.core.tools.next.support | ||
|
||
import com.jcraft.jsch.ChannelSftp | ||
import com.jcraft.jsch.JSch | ||
import com.jcraft.jsch.Session | ||
import org.apache.commons.io.IOUtils | ||
|
||
import java.nio.charset.StandardCharsets | ||
import java.util.zip.GZIPInputStream | ||
|
||
object MonitorReadReplicateTool { | ||
def main(args: Array[String]): Unit = { | ||
new MonitorReadReplicateTool().tryout() | ||
} | ||
} | ||
|
||
class MonitorReadReplicateTool { | ||
def tryout(): Unit = { | ||
val session = openSession() | ||
try { | ||
val channel = openChannel(session) | ||
try { | ||
readStatusFile(channel) | ||
readStateFile(channel) | ||
readMinuteDiffFile(channel) | ||
} | ||
finally { | ||
channel.exit() | ||
} | ||
} | ||
finally { | ||
session.disconnect() | ||
} | ||
} | ||
|
||
private def openSession(): Session = { | ||
val jsch = new JSch() | ||
jsch.addIdentity("/home/XXX/.ssh/id_rsa") | ||
jsch.setKnownHosts("/home/XXX/.ssh/known_hosts") | ||
val session = jsch.getSession("XXX", "kpn-analysis") | ||
session.connect() | ||
session | ||
} | ||
|
||
private def openChannel(session: Session): ChannelSftp = { | ||
val channel = session.openChannel("sftp").asInstanceOf[ChannelSftp] | ||
channel.connect() | ||
channel | ||
} | ||
|
||
private def readStatusFile(channel: ChannelSftp): Unit = { | ||
val inputStream = channel.get("/kpn/status/analysis2") | ||
val string = IOUtils.toString(inputStream, StandardCharsets.UTF_8) | ||
println(string) | ||
} | ||
|
||
private def readStateFile(channel: ChannelSftp): Unit = { | ||
val inputStream = channel.get("/kpn/replicate/005/981/121.state.txt") | ||
val string = IOUtils.toString(inputStream, StandardCharsets.UTF_8) | ||
println("---") | ||
println(string) | ||
println("---") | ||
} | ||
|
||
private def readMinuteDiffFile(channel: ChannelSftp): Unit = { | ||
val gzippedInputStream = channel.get("/kpn/replicate/005/981/121.osc.gz") | ||
val inputStream = new GZIPInputStream(gzippedInputStream) | ||
val string = IOUtils.toString(inputStream, StandardCharsets.UTF_8) | ||
println(string) | ||
} | ||
} |