use of com.axway.ats.common.filesystem.FileSystemOperationException in project ats-framework by Axway.
the class PropertiesFileSnapshot method loadPropertiesFile.
private Properties loadPropertiesFile(String agent, String filePath) {
// load the file as a String
String fileContent = loadFileContent(agent, filePath);
Properties properties = new Properties();
StringReader reader = new StringReader(fileContent);
try {
properties.load(new StringReader(fileContent));
} catch (IOException ex) {
// the other option is to add a difference to the FileTrace object, instead of throwing an exception here
throw new FileSystemOperationException("Error loading '" + filePath + "' properties file.");
} finally {
IoUtils.closeStream(reader, "Could not close a stream while reading from '" + filePath + "'");
}
return properties;
}
use of com.axway.ats.common.filesystem.FileSystemOperationException in project ats-framework by Axway.
the class Test_LocalFileSystemOperationsRealFiles method executeExternalProcess.
private String[] executeExternalProcess(String[] command) {
String stdOut = "";
String stdErr = "";
String exitCode = "";
try {
// start the external process
Process process = Runtime.getRuntime().exec(command);
// read the external process output streams
// reading both streams helps releasing OS resources
stdOut = IoUtils.streamToString(process.getInputStream()).trim();
stdErr = IoUtils.streamToString(process.getErrorStream()).trim();
// process.getOutputStream().close();
exitCode = String.valueOf(process.waitFor());
} catch (Exception e) {
StringBuilder err = new StringBuilder();
err.append("Error executing command '");
err.append(Arrays.toString(command));
err.append("'");
if (!StringUtils.isNullOrEmpty(stdOut)) {
err.append("\nSTD OUT: ");
err.append(stdOut);
}
if (!StringUtils.isNullOrEmpty(stdErr)) {
err.append("\nSTD ERR: ");
err.append(stdErr);
}
if (!StringUtils.isNullOrEmpty(exitCode)) {
err.append("\nexit code: ");
err.append(exitCode);
}
throw new FileSystemOperationException(err.toString(), e);
}
return new String[] { stdOut, stdErr, exitCode };
}
use of com.axway.ats.common.filesystem.FileSystemOperationException in project ats-framework by Axway.
the class RemoteFileSystemOperations method copyFileTo.
public void copyFileTo(String fromFile, String toMachine, String toFile, boolean failOnError) {
try {
Integer copyFileStartPort = getCopyFilePortProperty(ActionLibraryConfigurator.getInstance().getCopyFileStartPort());
Integer copyFileEndPort = getCopyFilePortProperty(ActionLibraryConfigurator.getInstance().getCopyFileEndPort());
InternalFileSystemOperations toRemoteFSOperations = new InternalFileSystemOperations(toMachine);
if (copyFileStartPort != null && copyFileStartPort > 0 && copyFileEndPort != null && copyFileEndPort > 0) {
toRemoteFSOperations.setCopyFilePortRange(copyFileStartPort, copyFileEndPort);
}
int port = toRemoteFSOperations.openFileTransferSocket();
this.remoteFileSystemOperations.sendFileTo(fromFile, toFile, HostUtils.splitAddressHostAndPort(HostUtils.getAtsAgentIpAndPort(toMachine))[0], port, failOnError);
toRemoteFSOperations.waitForFileTransferCompletion(port);
} catch (Exception e) {
String message = new StringBuilder().append("Unable to copy file ").append(fromFile).append(" from ").append(this.atsAgent).append(" to file ").append(toFile).append(" on ").append(toMachine).toString();
throw new FileSystemOperationException(message, e);
}
}
use of com.axway.ats.common.filesystem.FileSystemOperationException in project ats-framework by Axway.
the class RemoteFileSystemOperations method getCopyFilePortProperty.
private Integer getCopyFilePortProperty(String property) {
Integer port = null;
String errorMsg = "Port for file copy operation \"" + port + "\"is illegal !";
if (StringUtils.isNullOrEmpty(property)) {
return null;
}
try {
port = Integer.parseInt(property);
} catch (NumberFormatException nfe) {
throw new FileSystemOperationException(errorMsg + " It must be a valid positive number from 1 to 65535");
}
if (port > 65535 || port < 1) {
throw new FileSystemOperationException(errorMsg + " It must be in range from 1 to 65535.");
}
return port;
}
use of com.axway.ats.common.filesystem.FileSystemOperationException in project ats-framework by Axway.
the class RemoteFileSystemOperations method copyDirectoryTo.
public void copyDirectoryTo(String fromDirName, String toMachine, String toDirName, boolean isRecursive, boolean failOnError) {
try {
InternalFileSystemOperations toRemoteFSOperations = new InternalFileSystemOperations(toMachine);
int port = toRemoteFSOperations.openFileTransferSocket();
remoteFileSystemOperations.sendDirectoryTo(fromDirName, toDirName, HostUtils.splitAddressHostAndPort(HostUtils.getAtsAgentIpAndPort(toMachine))[0], port, isRecursive, failOnError);
toRemoteFSOperations.waitForFileTransferCompletion(port);
} catch (Exception e) {
String message = new StringBuilder().append("Unable to copy directory ").append(fromDirName).append(" from ").append(this.atsAgent).append(" to ").append(toDirName).append(" on ").append(toMachine).toString();
throw new FileSystemOperationException(message, e);
}
}
Aggregations