use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.
the class FileSystemOperations method getFileGroup.
/**
* Get the group of a file or directory
*
* @param filePath the file to work with
* @return the group
*/
@PublicAtsApi
public String getFileGroup(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath) {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { filePath });
String result = null;
// execute action
IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
result = operations.getFileGroup(filePath);
// log the result of the operation
log.debug("Successfully got the group of " + filePath + getHostDescriptionSuffix());
return result;
}
use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.
the class FileSystemOperations method copyRemoteFile.
/**
* Copies the contents of a file from one remote host to another remote host
*
* @param fromHost the address of the ATS agent on the source host.<br />
* If you provide null then local host will be used. In such case it is recommended to use
* {@link #copyFileTo(String, String)} method after FileSytemOperations is constructed with target agent (toHost)
* @param fromFile the source file to copy
* @param toHost the address of the ATS agent on the destination host.<br />
* If you provide null then local host will be used. In such case it is recommended to use
* {@link #copyFileFrom(String, String)} method after FileSytemOperations is constructed with target agent (fromHost)
* @param toFile the destination file to copy to
*/
@PublicAtsApi
public void copyRemoteFile(@Validate(name = "fromHost", type = ValidationType.STRING_SERVER_WITH_PORT) String fromHost, @Validate(name = "fromFile", type = ValidationType.STRING_NOT_EMPTY) String fromFile, @Validate(name = "toHost", type = ValidationType.STRING_SERVER_WITH_PORT) String toHost, @Validate(name = "toFile", type = ValidationType.STRING_NOT_EMPTY) String toFile) {
// 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, fromFile, toHost, toFile });
// execute action
IFileSystemOperations fromHostOperations = getOperationsImplementationFor(fromHost);
if (fromHostOperations instanceof LocalFileSystemOperations) {
IFileSystemOperations toHostOperations = getOperationsImplementationFor(toHost);
if (toHostOperations instanceof LocalFileSystemOperations) {
((LocalFileSystemOperations) toHostOperations).copyFile(fromFile, toFile, this.failOnError);
log.info("Successfully copied " + fromFile + " to " + toFile);
} else {
((RemoteFileSystemOperations) toHostOperations).copyFile(fromFile, toFile, this.failOnError);
log.info("Successfully copied " + fromFile + " from local host to file " + toFile + " on " + toHost);
}
} else {
IFileSystemOperations toHostOperations = getOperationsImplementationFor(toHost);
if (toHostOperations instanceof LocalFileSystemOperations) {
((RemoteFileSystemOperations) fromHostOperations).copyFileFrom(fromFile, toFile, this.failOnError);
log.info("Successfully copied " + fromFile + " from " + fromHost + " to file " + toFile + " on the localhost");
} else {
if (fromHost.equalsIgnoreCase(toHost)) {
// source and target hosts are remote, but they are same host indeed
((RemoteFileSystemOperations) fromHostOperations).copyFileLocally(fromFile, toFile, this.failOnError);
} else {
((RemoteFileSystemOperations) fromHostOperations).copyFileTo(fromFile, toHost, toFile, this.failOnError);
}
log.info("Successfully copied " + fromFile + " from " + fromHost + " to file " + toFile + " on " + toHost);
}
}
}
use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.
the class FileSystemOperations method unzip.
/**
* Unzip archive to local or remote machine, if the machine is UNIX-like it will preserve the permissions
*
* @param zipFilePath the ZIP file path
* @param outputDirPath output directory which is used as base directory for extracted files
* Temporary means that it will be automatically deleted.This will happen only when the JVM terminates normally.
*/
@PublicAtsApi
public void unzip(@Validate(name = "zipFilePath", type = ValidationType.STRING_NOT_EMPTY) String zipFilePath, @Validate(name = "outputDirPath", type = ValidationType.STRING_NOT_EMPTY) String outputDirPath) throws FileSystemOperationException {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { zipFilePath, outputDirPath });
// execute action
IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
operations.unzip(zipFilePath, outputDirPath);
}
use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.
the class FileSystemOperations method setFileModificationTime.
/**
* Set the last modification time for a specified file
*
* @param filePath the file to work with
* @param modificationTime the modification time to set as a timestamp in milliseconds
*/
@PublicAtsApi
public void setFileModificationTime(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "modificationTime", type = ValidationType.NUMBER_POSITIVE) long modificationTime) {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { filePath, modificationTime });
// execute action
IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
operations.setFileModificationTime(filePath, modificationTime);
// log the result of the operation
log.info("Successfully set the last modification timestamp of file '" + filePath + "'" + getHostDescriptionSuffix());
}
use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.
the class FileSystemOperations method lockFile.
/**
* <pre>
* Acquires an exclusive lock on a file
*
* <b>Platform dependencies</b>
*
* - In Windows it works as expected
* - In Linux it depends on the locking mechanism of the system. The file locking types are two - advisory and mandatory:
*
* a) <b>Advisory locking</b> - advisory locking will work, only if the participating process are cooperative.
* Advisory locking sometimes also called as "unenforced" locking.
*
* b) <b>Mandatory locking</b> - mandatory locking doesn’t require cooperation from the participating processes.
* It causes the kernel to check every open, read and write to verify that the calling process isn’t
* violating a lock on the given file. To enable mandatory locking in Linux, you need to enable it on
* a file system level and also on the individual files. The steps to be followed are:
* 1. Mount the file system with "<i>-o mand</i>" option
* 2. For the lock_file, turn on the set-group-ID bit and turn off the group-execute bit, to enable
* mandatory locking on that particular file. (This way has been chosen because when you turn off
* the group-execute bit, set-group-ID has no real meaning to it )
*
* How to do mandatory locking:
* Note: You need to be root to execute the below command
* <i># mount -oremount,mand /</i>
* <i># touch mandatory.txt</i>
* <i># chmod g+s,g-x mandatory.txt</i>
* </pre>
*
* @param fileName file name
*/
@PublicAtsApi
public void lockFile(@Validate(name = "fileName", type = ValidationType.STRING_NOT_EMPTY) String fileName) {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { fileName });
// execute action
IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
operations.lockFile(fileName);
// log the result of the operation
log.info("File '" + fileName + "'" + getHostDescriptionSuffix() + " is successfully locked");
}
Aggregations