Search in sources :

Example 61 with Validator

use of com.axway.ats.core.validation.Validator 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());
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 62 with Validator

use of com.axway.ats.core.validation.Validator 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");
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 63 with Validator

use of com.axway.ats.core.validation.Validator in project ats-framework by Axway.

the class FileSystemOperations method renameFile.

/**
     * Renames a file
     *
     * @param sourceFile source file name
     * @param destinationFile destination file name
     * @param overwrite whether to override the destination file if already exists
     */
@PublicAtsApi
public void renameFile(@Validate(name = "sourceFile", type = ValidationType.STRING_NOT_EMPTY) String sourceFile, @Validate(name = "destinationFile", type = ValidationType.STRING_NOT_EMPTY) String destinationFile, @Validate(name = "overwrite", type = ValidationType.NONE) boolean overwrite) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { sourceFile, destinationFile, overwrite });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.renameFile(sourceFile, destinationFile, overwrite);
    // log the result of the operation
    log.info("Successfully renamed '" + sourceFile + "' to '" + destinationFile + "'" + getHostDescriptionSuffix());
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 64 with Validator

use of com.axway.ats.core.validation.Validator in project ats-framework by Axway.

the class FileSystemOperations method appendToFile.

/**
     * Appends content to existing file.
     * It simply appends the provided bytes to the file.
     * It does not touch the new line characters in the new content.
     *
     * <br/><b>Note:</b> It will fail if the file does not exist
     *
     * @param filePath the file to work with
     * @param contentToAdd the content to add
     */
@PublicAtsApi
public void appendToFile(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "contentToAdd", type = ValidationType.STRING_NOT_EMPTY) String contentToAdd) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, contentToAdd });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.appendToFile(filePath, contentToAdd);
    // log the result of the operation
    String message = new StringBuilder().append("Successfully appended ").append(contentToAdd.length()).append(" characters to file ").append(filePath).toString();
    log.info(message);
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 65 with Validator

use of com.axway.ats.core.validation.Validator in project ats-framework by Axway.

the class FileSystemOperations method setFilePermissions.

/**
     * Set the permissions ( in octal format ) of a file or directory. E.g. 0644 or 1750 or 7605
     *
     * @param filePath the file to work with
     * @param permissions the permissions to set
     */
@PublicAtsApi
public void setFilePermissions(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "permissions", type = ValidationType.STRING_NOT_EMPTY) String permissions) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, permissions });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.setFilePermissions(filePath, permissions);
    // log the result of the operation
    log.debug("Successfully set the permissions '" + permissions + "' of " + filePath + getHostDescriptionSuffix());
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

Validator (com.axway.ats.core.validation.Validator)67 PublicAtsApi (com.axway.ats.common.PublicAtsApi)66 IFileSystemOperations (com.axway.ats.core.filesystem.model.IFileSystemOperations)45 LocalFileSystemOperations (com.axway.ats.core.filesystem.LocalFileSystemOperations)6 ISystemOperations (com.axway.ats.core.system.model.ISystemOperations)4 FullReadingBean (com.axway.ats.common.performance.monitor.beans.FullReadingBean)3 MachineDescriptionOperations (com.axway.ats.agent.components.monitoring.operations.clients.MachineDescriptionOperations)1 InternalProcessOperations (com.axway.ats.agent.components.system.operations.clients.InternalProcessOperations)1 AgentException (com.axway.ats.agent.core.exceptions.AgentException)1 FileMatchInfo (com.axway.ats.common.filesystem.FileMatchInfo)1 ProcessExecutorException (com.axway.ats.common.process.ProcessExecutorException)1 DbAccessFactory (com.axway.ats.log.autodb.DbAccessFactory)1 DbWriteAccess (com.axway.ats.log.autodb.DbWriteAccess)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1