Search in sources :

Example 26 with AgentException

use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.

the class ActionQueue method executeQueuedActions.

/**
    * Execute all queued actions in multiple threads
    *
    * @param atsAgents the hosts to execute to
    * @param threadingPattern the multithreading pattern
    * @param loaderDataConfig the loader variable data configuration
    * @throws AgentException on error
    */
public void executeQueuedActions(List<String> atsAgents, ThreadingPattern threadingPattern, LoaderDataConfig loaderDataConfig) throws AgentException {
    if (threadingPattern == null) {
        throw new AgentException("Threading pattern is not specified. You must specify one");
    }
    isQueueFinished = false;
    //create an empty instance of the config
    if (loaderDataConfig == null) {
        loaderDataConfig = new LoaderDataConfig();
    }
    if (atsAgents == null || atsAgents.size() == 0) {
        //local execution
        LocalLoadExecutor localLoadExecutor = new LocalLoadExecutor(name, sequence, threadingPattern, loaderDataConfig);
        localLoadExecutor.executeActions(queuedActions);
    } else {
        if (threadingPattern.getThreadCount() < atsAgents.size()) {
            String firstHost = atsAgents.get(0);
            log.warn("The total number of threads [" + threadingPattern.getThreadCount() + "] is less than the number of remote execution hosts [" + atsAgents.size() + "], so all threads will be run on just one host [" + firstHost + "]");
            atsAgents = new ArrayList<String>();
            atsAgents.add(firstHost);
        }
        //distributed remote execution
        DistributedLoadExecutor distributedLoadExecutor = new DistributedLoadExecutor(name, sequence, atsAgents, threadingPattern, loaderDataConfig);
        distributedLoadExecutor.executeActions(queuedActions);
    }
    if (threadingPattern.isBlockUntilCompletion()) {
        isQueueFinished = true;
    }
    inQueueMode = false;
}
Also used : DistributedLoadExecutor(com.axway.ats.agent.webapp.client.executors.DistributedLoadExecutor) AgentException(com.axway.ats.agent.core.exceptions.AgentException) LocalLoadExecutor(com.axway.ats.agent.webapp.client.executors.LocalLoadExecutor) LoaderDataConfig(com.axway.ats.agent.core.threading.data.config.LoaderDataConfig)

Example 27 with AgentException

use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.

the class ComponentEnvironment method backup.

public void backup(String folderPath) throws AgentException {
    log.info("Backuping environment for component " + componentName);
    try {
        String currentBackupFolder = backupFolder;
        if (folderPath != null) {
            currentBackupFolder = folderPath;
        }
        //if the current backup folder already exists and is not empty, we will rename it in order to have
        //a clean backup and to save the previous backup data
        File backupDir = new File(currentBackupFolder);
        if (backupDir.isDirectory() && backupDir.list().length > 0) {
            String backupFolderPath = currentBackupFolder;
            if (currentBackupFolder.endsWith("/") || currentBackupFolder.endsWith("\\")) {
                backupFolderPath = currentBackupFolder.substring(0, currentBackupFolder.length() - 1);
            }
            backupFolderPath = backupFolderPath + BACKUP_DATE_FORMATTER.format(new Date());
            backupFolderPath = IoUtils.normalizeDirPath(backupFolderPath);
            log.info("In order to have a clean backup, we'll rename the current backup folder: " + backupFolderPath);
            backupDir.renameTo(new File(backupFolderPath));
        }
        for (EnvironmentUnit environmentUnit : environmentUnits) {
            environmentUnit.setTempBackupDir(folderPath);
            environmentUnit.backup();
        }
    } catch (EnvironmentCleanupException ece) {
        throw new AgentException("Could not backup environment for component " + componentName + recurseCauses(ece), ece);
    }
}
Also used : EnvironmentCleanupException(com.axway.ats.environment.EnvironmentCleanupException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) FileEnvironmentUnit(com.axway.ats.environment.file.FileEnvironmentUnit) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) DirectoryEnvironmentUnit(com.axway.ats.environment.file.DirectoryEnvironmentUnit) File(java.io.File) Date(java.util.Date)

Example 28 with AgentException

use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.

the class ComponentRepository method initializeAllComponents.

public void initializeAllComponents() {
    //initialize the components
    List<Component> components = getAllComponents();
    for (Component component : components) {
        ComponentActionMap actionMap = component.getActionMap();
        Class<? extends InitializationHandler> initClass = actionMap.getInitializationHandler();
        //skip the initialization phase if the component has not declared a handler
        if (initClass != null) {
            String initClassName = initClass.getName();
            try {
                InitializationHandler initHandler = initClass.newInstance();
                initHandler.initializeComponent();
                log.info("Component '" + actionMap.getComponentName() + "' initialized successfully");
            } catch (IllegalAccessException iae) {
                log.error("Could not instantiate initialization handler '" + initClassName + "' - it should have a no-argument public constructor");
            } catch (InstantiationException ie) {
                log.error("Could not instantiate initialization handler '" + initClassName + "' - it should have a no-argument public constructor");
            } catch (Exception e) {
                log.error("Exception during initialization for component '" + actionMap.getComponentName() + "'", e);
            }
        } else {
            log.debug("Component '" + actionMap.getComponentName() + "' does not have an initialization handler");
        }
        //create the component backup if it does not exist yet
        try {
            List<ComponentEnvironment> componentEnvironments = component.getEnvironments();
            if (componentEnvironments != null) {
                for (ComponentEnvironment componentEnvironment : componentEnvironments) {
                    componentEnvironment.backupOnlyIfNotAlreadyDone();
                }
            }
        } catch (AgentException ae) {
            log.error(ae.getMessage(), ae);
        }
    }
}
Also used : AgentException(com.axway.ats.agent.core.exceptions.AgentException) InitializationHandler(com.axway.ats.agent.core.model.InitializationHandler) NoSuchEnvironmentException(com.axway.ats.agent.core.exceptions.NoSuchEnvironmentException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) NoSuchComponentException(com.axway.ats.agent.core.exceptions.NoSuchComponentException) ComponentAlreadyDefinedException(com.axway.ats.agent.core.exceptions.ComponentAlreadyDefinedException)

Example 29 with AgentException

use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.

the class ConfigurationParser method parseEnvironmentName.

private String parseEnvironmentName(Node environmentNode) throws AgentException {
    Node envNameItem = environmentNode.getAttributes().getNamedItem("name");
    String envName = null;
    if (envNameItem != null) {
        String name = envNameItem.getNodeValue();
        if (name != null && name.trim().length() > 0) {
            envName = name.trim();
        }
    }
    if ((envName == null && environmentNames.size() > 0) || environmentNames.contains(null)) {
        throw new AgentException("More than one environment is defined. In such case you must specify environment name.");
    }
    if (environmentNames.contains(envName)) {
        throw new AgentException("There is more than one environment with name '" + envName + "'");
    }
    environmentNames.add(envName);
    return envName;
}
Also used : AgentException(com.axway.ats.agent.core.exceptions.AgentException) Node(org.w3c.dom.Node)

Example 30 with AgentException

use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.

the class ConfigurationParser method parseDbEnvironment.

/**
     * Parse the database environment node in the Agent descriptor.
     *
     * @param dbEnvironmentNode the DB environment node.
     * @throws AgentException on error.
     */
private EnvironmentUnit parseDbEnvironment(Node dbEnvironmentNode, String backupFolder) throws AgentException {
    //create the connection descriptor
    DbConnection dbConnection = createConnection(dbEnvironmentNode.getAttributes());
    //read the tables
    List<DbTable> dbTables = new ArrayList<DbTable>();
    NodeList dbChildNodes = dbEnvironmentNode.getChildNodes();
    for (int k = 0; k < dbChildNodes.getLength(); k++) {
        Node dbChildNode = dbChildNodes.item(k);
        if (dbChildNode.getNodeName().equals(TABLE)) {
            String tableName = dbChildNode.getAttributes().getNamedItem("name").getNodeValue();
            String[] columnsToExclude = {};
            if (dbChildNode.getAttributes().getNamedItem("columnsToExclude") != null) {
                columnsToExclude = dbChildNode.getAttributes().getNamedItem("columnsToExclude").getNodeValue().split(",");
            }
            DbTable dbTable = null;
            // parse db table 'lock' attribute
            if (dbChildNode.getAttributes().getNamedItem("lock") != null) {
                if (dbConnection.getDbType().equals(DbConnOracle.DATABASE_TYPE)) {
                    log.warn("Db table 'lock' attribute is NOT implemented for Oracle yet. " + "Table locking is skipped for the moment.");
                }
                String nodeValue = dbChildNode.getAttributes().getNamedItem("lock").getNodeValue().trim();
                if ("false".equalsIgnoreCase(nodeValue) || "true".equalsIgnoreCase(nodeValue)) {
                    dbTable = new DbTable(tableName, Arrays.asList(columnsToExclude), Boolean.parseBoolean(nodeValue));
                } else {
                    log.warn("Invalid db table 'lock' attribute value '" + nodeValue + "'. Valid values are 'true' and 'false'. The default value 'true' will be used.");
                }
            }
            if (dbTable == null) {
                dbTable = new DbTable(tableName, Arrays.asList(columnsToExclude));
            }
            // parse db table 'autoIncrementResetValue' attribute
            if (dbChildNode.getAttributes().getNamedItem(TABLE_ATTR_AUTOINCR_RESET_VALUE) != null) {
                if (dbConnection.getDbType().equals(DbConnOracle.DATABASE_TYPE)) {
                    throw new AgentException("Db table 'autoIncrementResetValue' attribute is NOT implemented for Oracle yet.");
                }
                String autoInrcResetValue = dbChildNode.getAttributes().getNamedItem(TABLE_ATTR_AUTOINCR_RESET_VALUE).getNodeValue().trim();
                try {
                    Integer.parseInt(autoInrcResetValue);
                } catch (NumberFormatException nfe) {
                    throw new AgentException("Ivalid db table 'autoIncrementResetValue' attribute value '" + autoInrcResetValue + "'. It must be valid number.");
                }
                dbTable.setAutoIncrementResetValue(autoInrcResetValue);
            }
            dbTables.add(dbTable);
        }
    }
    String backupFileName = componentName + "-" + dbConnection.getDb() + ".sql";
    //create the environment unit
    DatabaseEnvironmentUnit dbEnvironment = new DatabaseEnvironmentUnit(backupFolder, backupFileName, dbConnection, dbTables);
    return dbEnvironment;
}
Also used : AgentException(com.axway.ats.agent.core.exceptions.AgentException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) DbConnection(com.axway.ats.core.dbaccess.DbConnection) DbTable(com.axway.ats.environment.database.model.DbTable)

Aggregations

AgentException (com.axway.ats.agent.core.exceptions.AgentException)42 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)11 AgentException_Exception (com.axway.ats.agent.webapp.client.AgentException_Exception)9 AgentService (com.axway.ats.agent.webapp.client.AgentService)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ObjectOutputStream (java.io.ObjectOutputStream)7 NoSuchComponentException (com.axway.ats.agent.core.exceptions.NoSuchComponentException)6 InternalComponentException (com.axway.ats.agent.webapp.client.InternalComponentException)6 InternalComponentException_Exception (com.axway.ats.agent.webapp.client.InternalComponentException_Exception)6 ActionExecutionException (com.axway.ats.agent.core.exceptions.ActionExecutionException)5 InternalComponentException (com.axway.ats.agent.core.exceptions.InternalComponentException)5 NoCompatibleMethodFoundException (com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException)5 NoSuchActionException (com.axway.ats.agent.core.exceptions.NoSuchActionException)5 MonitoringException (com.axway.ats.monitoring.model.exceptions.MonitoringException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ObjectInputStream (java.io.ObjectInputStream)5 WebMethod (javax.jws.WebMethod)5 DatabaseEnvironmentUnit (com.axway.ats.environment.database.DatabaseEnvironmentUnit)4 File (java.io.File)4