use of com.fo0.robot.model.KeyValue in project Robot by fo0.
the class TypeZipChainTest method unzip.
@Test
public void unzip() {
ActionItem item = ActionItem.builder().type(EActionType.Unzip).value("$SRC(/home/max/Schreibtisch/Robot/test/agent.zip) $DST(/home/max/Schreibtisch/Robot/test/x)").description("description example").build();
List<KeyValue> list = item.parsedValue();
KeyValue zipFile = list.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.SOURCE)).findFirst().orElse(null);
Assert.assertEquals(CONSTANTS_PATTERN.SOURCE, zipFile.getKey());
Assert.assertEquals("/home/max/Schreibtisch/Robot/test/agent.zip", zipFile.getValue());
KeyValue zipDstFolder = list.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.DESTINATION)).findFirst().orElse(null);
Assert.assertEquals(CONSTANTS_PATTERN.DESTINATION, zipDstFolder.getKey());
Assert.assertEquals("/home/max/Schreibtisch/Robot/test/x", zipDstFolder.getValue());
}
use of com.fo0.robot.model.KeyValue in project Robot by fo0.
the class ChainActionItem method untargz.
public EChainResponse untargz(List<KeyValue> list) throws Exception {
List<KeyValue> unzipList = list;
KeyValue unzipSrc = unzipList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.SOURCE)).findFirst().orElse(null);
KeyValue unzipDst = unzipList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.DESTINATION)).findFirst().orElse(KeyValue.builder().build());
ctx.addToLog(type, "SRC: " + unzipSrc.getValue());
ctx.addToLog(type, "DST: " + unzipDst.getValue());
Archiver unzipArchive = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP);
unzipArchive.extract(new File(unzipSrc.getValue()), new File(unzipDst.getValue()));
return EChainResponse.Continue;
}
use of com.fo0.robot.model.KeyValue in project Robot by fo0.
the class ChainActionItem method sleep.
private EChainResponse sleep(List<KeyValue> list) {
List<KeyValue> zipList = list;
KeyValue item = zipList.stream().findFirst().orElse(null);
ctx.addToLog(type, "Sleep (ms): " + item.getValue());
ctx.addToLog(type, "start sleep (ms): " + item.getValue());
Utils.sleep(Long.valueOf(item.getValue()));
ctx.addToLog(type, "stopped sleep (ms): " + item.getValue());
return EChainResponse.Continue;
}
use of com.fo0.robot.model.KeyValue in project Robot by fo0.
the class ChainActionItem method ssh.
public EChainResponse ssh(List<KeyValue> list) throws Exception {
List<KeyValue> sshList = list;
KeyValue sshHost = sshList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.HOST)).findFirst().orElse(null);
KeyValue sshPort = sshList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.PORT)).findFirst().orElse(KeyValue.builder().key("$PORT").value("22").build());
KeyValue sshUser = sshList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.USER)).findFirst().orElse(null);
KeyValue sshPassword = sshList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.PASSWORD)).findFirst().orElse(KeyValue.builder().key(CONSTANTS_PATTERN.PASSWORD).value("").build());
KeyValue sshCmd = sshList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.CMD)).findFirst().orElse(null);
ctx.addToLog(type, "HOST: " + sshHost.getValue());
ctx.addToLog(type, "PORT: " + sshPort.getValue());
ctx.addToLog(type, "User: " + sshUser.getValue());
ctx.addToLog(type, "Password: " + StringUtils.join(IntStream.range(0, sshPassword.getValue().length()).mapToObj(e -> "*").toArray(String[]::new)));
ctx.addToLog(type, "CMD: " + sshCmd.getValue());
SimpleSSHClient sshClient = new SimpleSSHClient(Host.builder().address(sshHost.getValue()).port(Integer.parseInt(sshPort.getValue())).username(sshUser.getValue()).password(sshPassword.getValue()).build());
try {
sshClient.connect();
} catch (Exception e2) {
ctx.addToLog(type, "failed to connect to Host " + e2);
return EChainResponse.Failed;
}
sshClient.command(sshCmd.getValue(), out -> {
ctx.addToLogPlain(type, out);
}, error -> {
ctx.addToLogPlain(type, error);
});
return EChainResponse.Continue;
}
use of com.fo0.robot.model.KeyValue in project Robot by fo0.
the class ChainActionItem method unSevenZip.
public EChainResponse unSevenZip(List<KeyValue> list) throws Exception {
List<KeyValue> unzipList = list;
KeyValue unzipSrc = unzipList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.SOURCE)).findFirst().orElse(null);
KeyValue unzipDst = unzipList.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.DESTINATION)).findFirst().orElse(KeyValue.builder().build());
ctx.addToLog(type, "SRC: " + unzipSrc.getValue());
ctx.addToLog(type, "DST: " + unzipDst.getValue());
Archiver unzipArchive = ArchiverFactory.createArchiver(ArchiveFormat.SEVEN_Z);
unzipArchive.extract(new File(unzipSrc.getValue()), new File(unzipDst.getValue()));
return EChainResponse.Continue;
}
Aggregations