Search in sources :

Example 1 with AdditionalAction

use of com.axway.ats.environment.AdditionalAction in project ats-framework by Axway.

the class ConfigurationParser method parseDirectoryEnvironment.

/**
     * Parse the directory environment node in the Agent descriptor.
     *
     * @param directoryEnvironmentNode the directory environment node.
     * @throws AgentException on error.
     */
private EnvironmentUnit parseDirectoryEnvironment(Node directoryEnvironmentNode, String backupFolder) {
    String originalDir = directoryEnvironmentNode.getAttributes().getNamedItem("path").getNodeValue();
    originalDir = IoUtils.normalizeDirPath(originalDir);
    String backupName;
    if (directoryEnvironmentNode.getAttributes().getNamedItem("backupName") != null) {
        backupName = directoryEnvironmentNode.getAttributes().getNamedItem("backupName").getNodeValue();
    } else {
        // remove the last slash and get the directory name as a file name
        backupName = IoUtils.getFileName(originalDir.substring(0, originalDir.length() - 1));
    }
    // get the optional addition actions to executed on directory restore
    List<AdditionalAction> additionalActions = parseAdditionalActions(directoryEnvironmentNode);
    DirectoryEnvironmentUnit directoryEnvironment = new DirectoryEnvironmentUnit(originalDir, backupFolder, backupName);
    directoryEnvironment.addAdditionalActions(additionalActions);
    return directoryEnvironment;
}
Also used : DirectoryEnvironmentUnit(com.axway.ats.environment.file.DirectoryEnvironmentUnit) AdditionalAction(com.axway.ats.environment.AdditionalAction)

Example 2 with AdditionalAction

use of com.axway.ats.environment.AdditionalAction in project ats-framework by Axway.

the class ConfigurationParser method parseAdditionalActions.

/**
     * @param environmentNode
     * @return
     */
private List<AdditionalAction> parseAdditionalActions(Node environmentNode) {
    NodeList environmentNodeChildren = environmentNode.getChildNodes();
    List<AdditionalAction> actions = new ArrayList<AdditionalAction>();
    for (int i = 0; i < environmentNodeChildren.getLength(); i++) {
        Node environmentNodeChild = environmentNodeChildren.item(i);
        if (environmentNodeChild.getNodeName().equals("action")) {
            String shellCommand;
            int sleepInterval;
            Node shellCommandNode = environmentNodeChild.getAttributes().getNamedItem("command");
            Node sleepNode = environmentNodeChild.getAttributes().getNamedItem("sleep");
            if (shellCommandNode != null && sleepNode != null) {
                shellCommand = shellCommandNode.getNodeValue();
                sleepInterval = Integer.parseInt(sleepNode.getNodeValue().trim());
                actions.add(new SystemProcessAction(shellCommand, sleepInterval));
            }
        }
    }
    return actions;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) SystemProcessAction(com.axway.ats.environment.process.SystemProcessAction) AdditionalAction(com.axway.ats.environment.AdditionalAction)

Example 3 with AdditionalAction

use of com.axway.ats.environment.AdditionalAction in project ats-framework by Axway.

the class ConfigurationParser method parseFileEnvironment.

/**
     * Parse the file environment node in the Agent descriptor.
     *
     * @param fileEnvironmentNode the file environment node.
     * @throws AgentException on error.
     */
private EnvironmentUnit parseFileEnvironment(Node fileEnvironmentNode, String backupFolder) {
    // get the original file
    String originalFile = fileEnvironmentNode.getAttributes().getNamedItem("path").getNodeValue();
    originalFile = IoUtils.normalizeUnixFile(originalFile);
    // get the backup file
    String backupName;
    if (fileEnvironmentNode.getAttributes().getNamedItem("backupName") != null) {
        backupName = fileEnvironmentNode.getAttributes().getNamedItem("backupName").getNodeValue();
    } else {
        backupName = IoUtils.getFileName(originalFile);
    }
    // get the optional addition actions to executed on file restore
    List<AdditionalAction> additionalActions = parseAdditionalActions(fileEnvironmentNode);
    FileEnvironmentUnit fileEnvironment = new FileEnvironmentUnit(originalFile, backupFolder, backupName);
    fileEnvironment.addAdditionalActions(additionalActions);
    return fileEnvironment;
}
Also used : FileEnvironmentUnit(com.axway.ats.environment.file.FileEnvironmentUnit) AdditionalAction(com.axway.ats.environment.AdditionalAction)

Aggregations

AdditionalAction (com.axway.ats.environment.AdditionalAction)3 DirectoryEnvironmentUnit (com.axway.ats.environment.file.DirectoryEnvironmentUnit)1 FileEnvironmentUnit (com.axway.ats.environment.file.FileEnvironmentUnit)1 SystemProcessAction (com.axway.ats.environment.process.SystemProcessAction)1 ArrayList (java.util.ArrayList)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1