Search in sources :

Example 31 with FileSystemOperationException

use of com.axway.ats.common.filesystem.FileSystemOperationException in project ats-framework by Axway.

the class PropertiesFileSnapshot method loadPropertiesFile.

private Properties loadPropertiesFile(String agent, String filePath) {
    // load the file as a String
    String fileContent = loadFileContent(agent, filePath);
    Properties properties = new Properties();
    StringReader reader = new StringReader(fileContent);
    try {
        properties.load(new StringReader(fileContent));
    } catch (IOException ex) {
        // the other option is to add a difference to the FileTrace object, instead of throwing an exception here
        throw new FileSystemOperationException("Error loading '" + filePath + "' properties file.");
    } finally {
        IoUtils.closeStream(reader, "Could not close a stream while reading from '" + filePath + "'");
    }
    return properties;
}
Also used : FileSystemOperationException(com.axway.ats.common.filesystem.FileSystemOperationException) StringReader(java.io.StringReader) IOException(java.io.IOException) Properties(java.util.Properties)

Example 32 with FileSystemOperationException

use of com.axway.ats.common.filesystem.FileSystemOperationException in project ats-framework by Axway.

the class Test_LocalFileSystemOperationsRealFiles method executeExternalProcess.

private String[] executeExternalProcess(String[] command) {
    String stdOut = "";
    String stdErr = "";
    String exitCode = "";
    try {
        // start the external process
        Process process = Runtime.getRuntime().exec(command);
        // read the external process output streams
        // reading both streams helps releasing OS resources
        stdOut = IoUtils.streamToString(process.getInputStream()).trim();
        stdErr = IoUtils.streamToString(process.getErrorStream()).trim();
        // process.getOutputStream().close();
        exitCode = String.valueOf(process.waitFor());
    } catch (Exception e) {
        StringBuilder err = new StringBuilder();
        err.append("Error executing command '");
        err.append(Arrays.toString(command));
        err.append("'");
        if (!StringUtils.isNullOrEmpty(stdOut)) {
            err.append("\nSTD OUT: ");
            err.append(stdOut);
        }
        if (!StringUtils.isNullOrEmpty(stdErr)) {
            err.append("\nSTD ERR: ");
            err.append(stdErr);
        }
        if (!StringUtils.isNullOrEmpty(exitCode)) {
            err.append("\nexit code: ");
            err.append(exitCode);
        }
        throw new FileSystemOperationException(err.toString(), e);
    }
    return new String[] { stdOut, stdErr, exitCode };
}
Also used : FileSystemOperationException(com.axway.ats.common.filesystem.FileSystemOperationException) IOException(java.io.IOException) FileDoesNotExistException(com.axway.ats.core.filesystem.exceptions.FileDoesNotExistException) FileSystemOperationException(com.axway.ats.common.filesystem.FileSystemOperationException)

Example 33 with FileSystemOperationException

use of com.axway.ats.common.filesystem.FileSystemOperationException in project ats-framework by Axway.

the class RemoteFileSystemOperations method copyFileTo.

public void copyFileTo(String fromFile, String toMachine, String toFile, boolean failOnError) {
    try {
        Integer copyFileStartPort = getCopyFilePortProperty(ActionLibraryConfigurator.getInstance().getCopyFileStartPort());
        Integer copyFileEndPort = getCopyFilePortProperty(ActionLibraryConfigurator.getInstance().getCopyFileEndPort());
        InternalFileSystemOperations toRemoteFSOperations = new InternalFileSystemOperations(toMachine);
        if (copyFileStartPort != null && copyFileStartPort > 0 && copyFileEndPort != null && copyFileEndPort > 0) {
            toRemoteFSOperations.setCopyFilePortRange(copyFileStartPort, copyFileEndPort);
        }
        int port = toRemoteFSOperations.openFileTransferSocket();
        this.remoteFileSystemOperations.sendFileTo(fromFile, toFile, HostUtils.splitAddressHostAndPort(HostUtils.getAtsAgentIpAndPort(toMachine))[0], port, failOnError);
        toRemoteFSOperations.waitForFileTransferCompletion(port);
    } catch (Exception e) {
        String message = new StringBuilder().append("Unable to copy file ").append(fromFile).append(" from ").append(this.atsAgent).append(" to file ").append(toFile).append(" on ").append(toMachine).toString();
        throw new FileSystemOperationException(message, e);
    }
}
Also used : FileSystemOperationException(com.axway.ats.common.filesystem.FileSystemOperationException) InternalFileSystemOperations(com.axway.ats.agent.components.system.operations.clients.InternalFileSystemOperations) FileSystemOperationException(com.axway.ats.common.filesystem.FileSystemOperationException)

Example 34 with FileSystemOperationException

use of com.axway.ats.common.filesystem.FileSystemOperationException in project ats-framework by Axway.

the class RemoteFileSystemOperations method getCopyFilePortProperty.

private Integer getCopyFilePortProperty(String property) {
    Integer port = null;
    String errorMsg = "Port for file copy operation \"" + port + "\"is illegal !";
    if (StringUtils.isNullOrEmpty(property)) {
        return null;
    }
    try {
        port = Integer.parseInt(property);
    } catch (NumberFormatException nfe) {
        throw new FileSystemOperationException(errorMsg + " It must be a valid positive number from 1 to 65535");
    }
    if (port > 65535 || port < 1) {
        throw new FileSystemOperationException(errorMsg + " It must be in range from 1 to 65535.");
    }
    return port;
}
Also used : FileSystemOperationException(com.axway.ats.common.filesystem.FileSystemOperationException)

Example 35 with FileSystemOperationException

use of com.axway.ats.common.filesystem.FileSystemOperationException in project ats-framework by Axway.

the class RemoteFileSystemOperations method copyDirectoryTo.

public void copyDirectoryTo(String fromDirName, String toMachine, String toDirName, boolean isRecursive, boolean failOnError) {
    try {
        InternalFileSystemOperations toRemoteFSOperations = new InternalFileSystemOperations(toMachine);
        int port = toRemoteFSOperations.openFileTransferSocket();
        remoteFileSystemOperations.sendDirectoryTo(fromDirName, toDirName, HostUtils.splitAddressHostAndPort(HostUtils.getAtsAgentIpAndPort(toMachine))[0], port, isRecursive, failOnError);
        toRemoteFSOperations.waitForFileTransferCompletion(port);
    } catch (Exception e) {
        String message = new StringBuilder().append("Unable to copy directory ").append(fromDirName).append(" from ").append(this.atsAgent).append(" to ").append(toDirName).append(" on ").append(toMachine).toString();
        throw new FileSystemOperationException(message, e);
    }
}
Also used : FileSystemOperationException(com.axway.ats.common.filesystem.FileSystemOperationException) InternalFileSystemOperations(com.axway.ats.agent.components.system.operations.clients.InternalFileSystemOperations) FileSystemOperationException(com.axway.ats.common.filesystem.FileSystemOperationException)

Aggregations

FileSystemOperationException (com.axway.ats.common.filesystem.FileSystemOperationException)58 IOException (java.io.IOException)32 File (java.io.File)31 RandomAccessFile (java.io.RandomAccessFile)29 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)29 FileDoesNotExistException (com.axway.ats.core.filesystem.exceptions.FileDoesNotExistException)16 FileNotFoundException (java.io.FileNotFoundException)16 SocketTimeoutException (java.net.SocketTimeoutException)14 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 AttributeNotSupportedException (com.axway.ats.core.filesystem.exceptions.AttributeNotSupportedException)13 EOFException (java.io.EOFException)13 OverlappingFileLockException (java.nio.channels.OverlappingFileLockException)13 FileOutputStream (java.io.FileOutputStream)10 FileInputStream (java.io.FileInputStream)9 BufferedOutputStream (java.io.BufferedOutputStream)8 DataOutputStream (java.io.DataOutputStream)8 BaseTest (com.axway.ats.action.BaseTest)7 LocalFileSystemOperations (com.axway.ats.core.filesystem.LocalFileSystemOperations)7 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7