Search in sources :

Example 56 with Validator

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

the class FileSystemOperations method deleteDirectoryContent.

/**
     * Deletes all directory's content, but does not touch the directory itself<br/>
     * <b>Note: </b>It does nothing if the directory does not exist
     *
     * @param directoryPath the directory to work with
     */
@PublicAtsApi
public void deleteDirectoryContent(@Validate(name = "directoryPath", type = ValidationType.STRING_NOT_EMPTY) String directoryPath) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { directoryPath });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.purgeDirectoryContents(directoryPath);
    // log the result of the operation
    log.info("Successfully deleted the content of directory by the name of " + directoryPath + 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 57 with Validator

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

the class FileSystemOperations method createFile.

/**
     * Creates a file. The content of the file is the letters of the English alphabet.
     * The letters themselves are either alphabetically sorted, or randomly generated,
     * depending on the value of the randomContent parameter.
     *
     * @param filePath the file to work with
     * @param size the size of the generated file
     * @param eolStyle the EOL style for this file. If null it uses the EOL style of the current system
     * @param randomContent if true the method would generate a file with a random content
     */
@PublicAtsApi
public void createFile(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "size", type = ValidationType.NUMBER_POSITIVE) long size, EndOfLineStyle eolStyle, boolean randomContent) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, size, null, randomContent });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.createFile(filePath, size, randomContent, eolStyle);
    // log the result of the operation
    log.info("Successfully created file by the name of " + filePath + " with size " + size);
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 58 with Validator

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

Example 59 with Validator

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

Example 60 with Validator

use of com.axway.ats.core.validation.Validator 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);
}
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