Search in sources :

Example 31 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 32 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 33 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)

Example 34 with AgentException

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

the class ConfigurationParser method parseBackupFolder.

/**
     *
     * @param environmentNode the environment node
     * @return backup folder (with the right slashes and slash at the end)
     * @throws AgentException if the backup folder is duplicated in other environments
     */
private String parseBackupFolder(Node environmentNode) throws AgentException {
    Node unixBackupFolderItem = environmentNode.getAttributes().getNamedItem("backupFolder");
    Node winBackupFolderItem = environmentNode.getAttributes().getNamedItem("windowsBackupFolder");
    String backupFolder = null;
    boolean isUnix = OperatingSystemType.getCurrentOsType().isUnix();
    if (isUnix) {
        if (unixBackupFolderItem != null) {
            String unixBackupFolder = unixBackupFolderItem.getNodeValue();
            if (unixBackupFolder != null && unixBackupFolder.trim().length() > 0) {
                backupFolder = unixBackupFolder.trim();
            }
        }
    } else if (winBackupFolderItem != null) {
        String winBackupFolder = winBackupFolderItem.getNodeValue();
        if (winBackupFolder != null && winBackupFolder.trim().length() > 0) {
            backupFolder = winBackupFolder.trim();
        }
    }
    if (backupFolder == null) {
        String tempFolder = IoUtils.normalizeDirPath(AtsSystemProperties.SYSTEM_USER_TEMP_DIR);
        backupFolder = IoUtils.normalizeDirPath(tempFolder + "agent_components_backup");
        log.warn("No valid '" + (isUnix ? "backupFolder" : "windowsBackupFolder") + "' environment attribute for '" + componentName + "' component. Backup folder '" + backupFolder + "' will be used instead.");
    } else {
        backupFolder = IoUtils.normalizeDirPath(backupFolder);
    }
    if (backupFolders.contains(backupFolder)) {
        throw new AgentException("There is more than one environment configuration with the same backup folder '" + backupFolder + "'");
    }
    backupFolders.add(backupFolder);
    return backupFolder;
}
Also used : AgentException(com.axway.ats.agent.core.exceptions.AgentException) Node(org.w3c.dom.Node)

Example 35 with AgentException

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

the class DistributedLoadExecutor method executeActions.

@Override
public void executeActions(List<ActionRequest> actionRequests) throws AgentException {
    //set the block until completion param to false
    //this way we'll be able to start all the loaders on all boxes at the same time
    //and then wait for all of them to finish
    final boolean blockUntilCompletion = threadingPattern.isBlockUntilCompletion();
    threadingPattern.setBlockUntilCompletion(false);
    int maxHostCount = atsAgents.size();
    // distribute the threading pattern for each agent host
    final List<ThreadingPattern> distributedPatterns = threadingPattern.distribute(maxHostCount);
    if (distributedPatterns.size() < maxHostCount) {
        log.warn("Threading pattern cannot be distributed accross all agents, only the first " + distributedPatterns.size() + " agents will execute");
    }
    // distribute the data configurators for each agent host
    final List<LoaderDataConfig> distributedLoaderDataConfigs = loaderDataConfig.distribute(distributedPatterns.size());
    // start queue in the database and retrieve its ID
    int queueId = retrieveQueueId(queueSequence, getHostsList());
    //call the web service now
    try {
        //first schedule the loaders on all hosts
        for (int i = 0; i < distributedPatterns.size(); i++) {
            //serialize the threading pattern - it's easier to pass it to the web service that way
            byte[] serializedThreadingPattern = serializeObject(distributedPatterns.get(i));
            byte[] serializedLoaderDataConfig = serializeObject(distributedLoaderDataConfigs.get(i));
            //wrap all the action requests
            List<ActionWrapper> actionWrappers = new ArrayList<ActionWrapper>();
            for (ActionRequest actionRequest : actionRequests) {
                actionWrappers.add(wrapActionRequest(actionRequest));
            }
            //schedule the actions, but do not execute
            //get the client
            AgentService agentServicePort = AgentServicePool.getInstance().getClient(atsAgents.get(i));
            agentServicePort.scheduleActionsInMultipleThreads(queueName, queueId, actionWrappers, serializedThreadingPattern, serializedLoaderDataConfig, distributedPatterns.get(0).isUseSynchronizedIterations());
        }
        boolean useSynchronizedIterations = distributedPatterns.get(0).isUseSynchronizedIterations();
        if (useSynchronizedIterations && !blockUntilCompletion) {
            // It is non blocking, but synchronized - we have to wait until the queue finish its execution.
            // We first start the queue. This assures the queue is created before the user have the chance
            // to say "wait for completion"
            startSynchedIterations();
            // and then wait in another thread until the queue finish
            ImportantThread helpThread = new ImportantThread(new Runnable() {

                @Override
                public void run() {
                    runSynchedIterations();
                }
            });
            helpThread.setDescription(queueName);
            helpThread.start();
        } else {
            if (useSynchronizedIterations) {
                // it is blocking - we can wait until the queue finish it execution
                startSynchedIterations();
                runSynchedIterations();
            } else {
                // if blocking - we can wait until the queue finish it execution
                // if non blocking - as it is not synchronized, we will wait only until the queue is started
                runNotSynchedIterations(blockUntilCompletion);
            }
        }
    } catch (AgentException_Exception ae) {
        throw new AgentException(ae.getMessage());
    } catch (InternalComponentException_Exception ice) {
        //we need to get internal component exception info from the soap fault
        InternalComponentException faultInfo = ice.getFaultInfo();
        //then construct and throw a real InternalComponentException (not the JAXB mapping type above)
        throw new com.axway.ats.agent.core.exceptions.InternalComponentException(faultInfo.getComponentName(), faultInfo.getActionName(), faultInfo.getExceptionMessage(), faultInfo.getHostIp());
    } catch (Exception e) {
        throw new AgentException(e.getMessage(), e);
    }
    // restore this flag
    threadingPattern.setBlockUntilCompletion(blockUntilCompletion);
}
Also used : AgentException(com.axway.ats.agent.core.exceptions.AgentException) InternalComponentException_Exception(com.axway.ats.agent.webapp.client.InternalComponentException_Exception) ArrayList(java.util.ArrayList) ActionWrapper(com.axway.ats.agent.webapp.client.ActionWrapper) InternalComponentException(com.axway.ats.agent.webapp.client.InternalComponentException) ImportantThread(com.axway.ats.agent.core.threading.ImportantThread) InternalComponentException_Exception(com.axway.ats.agent.webapp.client.InternalComponentException_Exception) InternalComponentException(com.axway.ats.agent.webapp.client.InternalComponentException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) IOException(java.io.IOException) AgentException_Exception(com.axway.ats.agent.webapp.client.AgentException_Exception) LoaderDataConfig(com.axway.ats.agent.core.threading.data.config.LoaderDataConfig) ThreadingPattern(com.axway.ats.agent.core.threading.patterns.ThreadingPattern) AgentService(com.axway.ats.agent.webapp.client.AgentService) ActionRequest(com.axway.ats.agent.core.action.ActionRequest) AgentException_Exception(com.axway.ats.agent.webapp.client.AgentException_Exception)

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