Search in sources :

Example 26 with Validator

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

the class FileSystemOperations method getFilePermissions.

/**
     * Get the permissions ( in octal format ) of a file or directory. E.g. 0644 or 1750 or 7605
     *
     * @param filePath the file to work with
     * @return the permissions
     */
@PublicAtsApi
public String getFilePermissions(@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.getFilePermissions(filePath);
    // log the result of the operation
    log.debug("Successfully got the permissions 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 27 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 is set by the user.
     *
     * @param filePath the file to work with
     * @param fileContent the text that will be parsed in the file
     * @param userId the identification number of the user this file should belong to
     * @param groupId the identification number of the group this file should belong to
     */
@PublicAtsApi
public void createFile(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "fileContent", type = ValidationType.NOT_NULL) String fileContent, @Validate(name = "userId", type = ValidationType.NUMBER_POSITIVE) int userId, @Validate(name = "groupId", type = ValidationType.NUMBER_POSITIVE) int groupId) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, fileContent, userId, groupId });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.createFile(filePath, fileContent, userId, groupId);
    // log the result of the operation
    String message = new StringBuilder().append("Successfully created file by the name of ").append(filePath).append(" with content ").append(fileContent).append(" and UID/GID ").append(userId).append("/").append(groupId).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 28 with Validator

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

the class FileSystemOperations method computeMd5Sum.

/**
     * Compute a file's MD5 sum
     *
     * @param filePath the file to work with
     * @param mode mode for computing the MD5 sum
     * <blockquote>
     * ASCII mode - the line endings will be ignored when computing the sum.
     * E.g. same file with Windows and Linux style line endings will give same MD5 sum <br/>
     * BINARY mode - each byte is affecting the returned result
     * </blockquote>
     * @return the MD5 sum in hex format
     */
@PublicAtsApi
public String computeMd5Sum(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, Md5SumMode mode) {
    String md5 = null;
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, Md5SumMode.BINARY });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    md5 = operations.computeMd5Sum(filePath, mode);
    // log the result of the operation
    log.debug("Successfully extracted the MD5 sum '" + md5 + "' of " + filePath + getHostDescriptionSuffix());
    return md5;
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 29 with Validator

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

the class MachineInfoAgent method updateMachineInfo.

/**
     * Retrieves static info about a machine and stores this info into the
     * log DB
     *
     * @param atsAgent the address of the ATS Agent running on the machine of interest
     * @param dbMachineName the name of the machine as it appears in the DB
     * @throws Exception
     */
@PublicAtsApi
public void updateMachineInfo(@Validate(name = "atsAgent", type = ValidationType.STRING_SERVER_WITH_PORT) String atsAgent, @Validate(name = "dbMachineName", type = ValidationType.STRING_NOT_EMPTY) String dbMachineName) throws Exception {
    // validate input parameters
    atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent);
    new Validator().validateMethodParameters(new Object[] { atsAgent, dbMachineName });
    log.info("Retrieving info about " + dbMachineName + " from " + atsAgent);
    MachineDescriptionOperations mm = new MachineDescriptionOperations(atsAgent);
    String machineDescriptionString = mm.getDescription();
    log.info("Saving retrieved info about " + dbMachineName + " into the Test Explorer database");
    DbWriteAccess dbAccess = new DbAccessFactory().getNewDbWriteAccessObject();
    dbAccess.updateMachineInfo(dbMachineName, machineDescriptionString, true);
    log.info("Successfully updated the info about " + dbMachineName);
}
Also used : DbAccessFactory(com.axway.ats.log.autodb.DbAccessFactory) MachineDescriptionOperations(com.axway.ats.agent.components.monitoring.operations.clients.MachineDescriptionOperations) DbWriteAccess(com.axway.ats.log.autodb.DbWriteAccess) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 30 with Validator

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

the class SystemMonitor method scheduleProcessMonitoring.

/**
     * Schedule monitoring on a system process. This method specifies the name of the user who started the process to monitor.
     * </br>No statistics collection will be triggered until the startMonitor method is called.
     *
     * @param monitoredHost the host where the monitored process lives
     * @param processPattern the pattern to use in order to find the process among all system processes.
     * <br><b>Note: </b>We match the processes by finding the given processPattern in the start command of the process.
     * <br>This means that it is possible to match more than one process. In this case a number is appended to the processAlias.
     * <br>For example if the processPattern is "my_process" matching 2 processes will give "my_process" and "my_process [2]"
     * @param processAlias the process alias to use when logging into the database
     * @param processUsername the name of the user who started this process
     * @param processReadingTypes what kind of data to collect. Use some of the SystemMonitor.MONITOR_PROCESS_* constants
     */
@PublicAtsApi
public void scheduleProcessMonitoring(@Validate(name = "monitoredHost", type = ValidationType.STRING_SERVER_WITH_PORT) String monitoredHost, @Validate(name = "processPattern", type = ValidationType.STRING_NOT_EMPTY) String processPattern, @Validate(name = "processAlias", type = ValidationType.STRING_NOT_EMPTY) String processAlias, @Validate(name = "processUsername", type = ValidationType.STRING_NOT_EMPTY) String processUsername, @Validate(name = "processReadingTypes", type = ValidationType.NOT_NULL) String[] processReadingTypes) {
    // validate input parameters
    monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost);
    new Validator().validateMethodParameters(new Object[] { monitoredHost, processPattern, processAlias, processUsername, processReadingTypes });
    scheduleProcessMonitoring(monitoredHost, null, processPattern, processAlias, processUsername, processReadingTypes);
}
Also used : 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