use of com.axway.ats.core.filesystem.LocalFileSystemOperations in project ats-framework by Axway.
the class FileSystemOperations method copyDirectoryTo.
/**
* Copies the contents of a directory to a new one
*
* @param fromDirName the source file to copy
* @param toDirName the destination file to copy to
* @param isRecursive whether to copy recursively or not
*/
@PublicAtsApi
public void copyDirectoryTo(@Validate(name = "fromDirName", type = ValidationType.STRING_NOT_EMPTY) String fromDirName, @Validate(name = "toDirName", type = ValidationType.STRING_NOT_EMPTY) String toDirName, @Validate(name = "isRecursive", type = ValidationType.NONE) boolean isRecursive) {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { fromDirName, toDirName, isRecursive });
// execute action
IFileSystemOperations operations = getOperationsImplementationFor(this.atsAgent);
if (operations instanceof LocalFileSystemOperations) {
((LocalFileSystemOperations) operations).copyDirectory(fromDirName, toDirName, isRecursive, this.failOnError);
log.info("Successfully copied directory " + fromDirName + " to " + toDirName);
} else {
RemoteFileSystemOperations rfso = (RemoteFileSystemOperations) operations;
rfso.setCopyInPassiveMode(copyInPassiveMode);
rfso.copyDirectory(fromDirName, toDirName, isRecursive, this.failOnError);
log.info("Successfully copied directory " + fromDirName + " from local host to " + toDirName + " on " + this.atsAgent);
}
}
use of com.axway.ats.core.filesystem.LocalFileSystemOperations in project ats-framework by Axway.
the class FileSystemOperations method copyRemoteDirectory.
/**
* Copies the contents of a directory located on a remote host to another remote host
*
* @param fromHost the address of the ATS agent on the source host
* @param fromDirectory the source file to copy
* @param toHost the address of the ATS agent on the destination host
* @param toDirectory the destination file to copy to
* @param isRecursive whether to copy recursively or not
*/
@PublicAtsApi
public void copyRemoteDirectory(@Validate(name = "fromHost", type = ValidationType.STRING_SERVER_WITH_PORT) String fromHost, @Validate(name = "fromDirectory", type = ValidationType.STRING_NOT_EMPTY) String fromDirectory, @Validate(name = "toHost", type = ValidationType.STRING_SERVER_WITH_PORT) String toHost, @Validate(name = "toDirectory", type = ValidationType.STRING_NOT_EMPTY) String toDirectory, @Validate(name = "isRecursive", type = ValidationType.NONE) boolean isRecursive) {
// replace to pass validation
if (fromHost == null) {
fromHost = LOCAL_HOST_NAME_AND_PORT;
}
if (toHost == null) {
toHost = LOCAL_HOST_NAME_AND_PORT;
}
// validate input parameters
fromHost = HostUtils.getAtsAgentIpAndPort(fromHost);
toHost = HostUtils.getAtsAgentIpAndPort(toHost);
new Validator().validateMethodParameters(new Object[] { fromHost, fromDirectory, toHost, toDirectory, isRecursive });
// execute action
IFileSystemOperations fromHostOperations = getOperationsImplementationFor(fromHost);
if (fromHostOperations instanceof LocalFileSystemOperations) {
IFileSystemOperations toHostOperations = getOperationsImplementationFor(toHost);
if (toHostOperations instanceof LocalFileSystemOperations) {
((LocalFileSystemOperations) toHostOperations).copyDirectory(fromDirectory, toDirectory, isRecursive, this.failOnError);
log.info("Successfully copied directory " + fromDirectory + " to " + toDirectory);
} else {
((RemoteFileSystemOperations) toHostOperations).copyDirectory(fromDirectory, toDirectory, isRecursive, this.failOnError);
log.info("Successfully copied directory " + fromDirectory + " from local host to " + toDirectory + " on " + toHost);
}
} else {
IFileSystemOperations toHostOperations = getOperationsImplementationFor(toHost);
if (toHostOperations instanceof LocalFileSystemOperations) {
((RemoteFileSystemOperations) fromHostOperations).copyDirectoryFrom(fromDirectory, toDirectory, isRecursive, this.failOnError);
log.info("Successfully copied directory " + fromDirectory + " from " + fromHost + " to " + toDirectory + " on the local host");
} else {
if (fromHost.equalsIgnoreCase(toHost)) {
// source and target hosts are remote, but they are same host indeed
((RemoteFileSystemOperations) fromHostOperations).copyDirectoryLocally(fromDirectory, toDirectory, isRecursive, this.failOnError);
} else {
((RemoteFileSystemOperations) fromHostOperations).copyDirectoryTo(fromDirectory, toHost, toDirectory, isRecursive, this.failOnError);
}
log.info("Successfully copied directory " + fromDirectory + " from " + fromHost + " to " + toDirectory + " on " + toHost);
}
}
}
use of com.axway.ats.core.filesystem.LocalFileSystemOperations in project ats-framework by Axway.
the class FileSystemOperations method copyDirectoryFrom.
/**
* Copies the contents of a directory <code>fromDirName</code> in atsAgent host to a new one on the local host. <br>
* <b>Note:</b> If no atsAgent is used or it is local, then the source directory is searched on the local host.
*
* @param fromDirName the source directory to be copied
* @param toDirName the destination directory
* @param isRecursive whether to copy recursively or not
*/
@PublicAtsApi
public void copyDirectoryFrom(@Validate(name = "fromDirName", type = ValidationType.STRING_NOT_EMPTY) String fromDirName, @Validate(name = "toDirName", type = ValidationType.STRING_NOT_EMPTY) String toDirName, @Validate(name = "isRecursive", type = ValidationType.NONE) boolean isRecursive) {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { fromDirName, toDirName, isRecursive });
// execute action
IFileSystemOperations operations = getOperationsImplementationFor(this.atsAgent);
if (operations instanceof LocalFileSystemOperations) {
((LocalFileSystemOperations) operations).copyDirectory(fromDirName, toDirName, isRecursive, this.failOnError);
log.info("Successfully copied directory " + fromDirName + " to " + toDirName);
} else {
((RemoteFileSystemOperations) operations).copyDirectoryFrom(fromDirName, toDirName, isRecursive, this.failOnError);
log.info("Successfully copied directory " + fromDirName + " from " + this.atsAgent + " to " + toDirName + " on the local host");
}
}
use of com.axway.ats.core.filesystem.LocalFileSystemOperations in project ats-framework by Axway.
the class FileSystemOperations method copyFileTo.
/**
* Copies the contents of a file from the local host (Test Executor) to a new file on the atsAgent host
*
* @param fromFile the source file to copy
* @param toFile the destination file name path (not just the directory) to copy to. Absolute path is expected
*/
@PublicAtsApi
public void copyFileTo(@Validate(name = "fromFile", type = ValidationType.STRING_NOT_EMPTY) String fromFile, @Validate(name = "toFile", type = ValidationType.STRING_NOT_EMPTY) String toFile) {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { fromFile, toFile });
try {
checkIfFileExistsAndIsFile(fromFile);
} catch (Exception e) {
throw new FileSystemOperationException("Unable to copy '" + fromFile + "' to '" + toFile + "'", e);
}
// execute action
IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
if (operations instanceof LocalFileSystemOperations) {
((LocalFileSystemOperations) operations).copyFile(fromFile, toFile, this.failOnError);
log.info("Successfully copied " + fromFile + " to " + toFile);
} else {
RemoteFileSystemOperations rfso = (RemoteFileSystemOperations) operations;
rfso.setCopyInPassiveMode(copyInPassiveMode);
rfso.copyFile(fromFile, toFile, this.failOnError);
log.info("Successfully copied " + fromFile + " from local host to file " + toFile + " on " + atsAgent);
}
}
use of com.axway.ats.core.filesystem.LocalFileSystemOperations in project ats-framework by Axway.
the class FileSystemOperations method copyFileFrom.
/**
* Copies the contents of a file <strong>from</strong> atsAgent host to a new file on the local host (Test Executor).
* <br>
* <b>Note:</b> If no atsAgent is specified in constructor or it is local, then the source files is searched on the
* local host.
*
* @param fromFile the source file located on the ATS Agent
* @param toFile the local destination file
*/
@PublicAtsApi
public void copyFileFrom(@Validate(name = "fromFile", type = ValidationType.STRING_NOT_EMPTY) String fromFile, @Validate(name = "toFile", type = ValidationType.STRING_NOT_EMPTY) String toFile) {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { fromFile, toFile });
// execute action
IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
if (operations instanceof LocalFileSystemOperations) {
((LocalFileSystemOperations) operations).copyFile(fromFile, toFile, this.failOnError);
log.info("Successfully copied " + fromFile + " to " + toFile);
} else {
((RemoteFileSystemOperations) operations).copyFileFrom(fromFile, toFile, this.failOnError);
log.info("Successfully copied " + fromFile + " from " + atsAgent + " to file " + toFile + " on the localhost");
}
}
Aggregations