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;
}
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);
}
}
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);
}
}
}
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;
}
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;
}
Aggregations