Search in sources :

Example 6 with AgentService

use of com.axway.ats.agent.webapp.client.AgentService in project ats-framework by Axway.

the class DistributedLoadExecutor method waitUntilQueueFinishOnAllLoaders.

private void waitUntilQueueFinishOnAllLoaders() {
    try {
        log.info("Action queue '" + queueName + "' is running on " + atsAgents.toString());
        for (int i = 0; i < atsAgents.size(); i++) {
            String host = atsAgents.get(i);
            log.info("Waiting until queue '" + queueName + "' finish on '" + host + "'");
            AgentService agentServicePort = AgentServicePool.getInstance().getClient(host);
            agentServicePort.waitUntilQueueFinish(queueName);
            log.info("Finished executing action queue '" + queueName + "' on '" + host + "'");
        }
        // the queue finished but there might be some failed actions
        // check if the wanted actions pass rate is met
        LoadQueueResult queueResult = getQueueResult(threadingPattern.getQueuePassRate(), atsAgents);
        TestcaseStateEventsDispacher.getInstance().setQueueFinishedAsFailed(queueResult == LoadQueueResult.FAILED);
        // end the queue in the log
        log.endLoadQueue(queueName, queueResult);
        log.info("Finished executing action queue '" + queueName + "' on all agents " + atsAgents.toString());
    } catch (Exception e) {
        String msg = "Error waiting for action queue '" + queueName + "' completion";
        log.error(msg, e);
        log.endLoadQueue(queueName, LoadQueueResult.FAILED);
        cancelAllActions();
        throw new RuntimeException(msg, e);
    }
}
Also used : AgentService(com.axway.ats.agent.webapp.client.AgentService) LoadQueueResult(com.axway.ats.log.model.LoadQueueResult) 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)

Example 7 with AgentService

use of com.axway.ats.agent.webapp.client.AgentService in project ats-framework by Axway.

the class TestcaseStateListener method cleanupInternalObjectResources.

/**
     * Called to release the internal object resources on the agent side
     */
@Override
public void cleanupInternalObjectResources(String atsAgent, String internalObjectResourceId) {
    try {
        AgentService agentServicePort = AgentServicePool.getInstance().getClient(atsAgent);
        agentServicePort.cleanupInternalObjectResources(internalObjectResourceId);
    } catch (Exception e) {
    // As this code is triggered when the garbage collector disposes the client side object
    // at the Test Executor side, the following message seems confusing:
    // log.error( "Can't cleanup resource with identifier " + internalObjectResourceId + " on ATS agent '" + atsAgent + "'", e );
    }
}
Also used : AgentService(com.axway.ats.agent.webapp.client.AgentService) AgentException(com.axway.ats.agent.core.exceptions.AgentException) AgentException_Exception(com.axway.ats.agent.webapp.client.AgentException_Exception)

Example 8 with AgentService

use of com.axway.ats.agent.webapp.client.AgentService in project ats-framework by Axway.

the class TestcaseStateListener method onConfigureAtsAgents.

/**
     * This event is send right before running a regular action or starting
     * an action queue.
     *
     * It is also expected to be send between onTestStart and onTestEnd events.
     */
@Override
public void onConfigureAtsAgents(List<String> atsAgents) throws Exception {
    if (configuredAgents == null) {
        // No TestCase is started so we won't configure the remote agents
        return;
    }
    for (String atsAgent : atsAgents) {
        // configure only not configured agents
        if (!configuredAgents.contains(atsAgent)) {
            // We will try to prevent that adding a 'unique' prefix
            synchronized (("ATS_STRING_LOCK-" + atsAgent).intern()) {
                if (!configuredAgents.contains(atsAgent)) {
                    // Pass the logging configuration to the remote agent
                    RemoteLoggingConfigurator remoteLoggingConfigurator = new RemoteLoggingConfigurator(atsAgent);
                    new RemoteConfigurationManager().pushConfiguration(atsAgent, remoteLoggingConfigurator);
                    try {
                        AgentService agentServicePort = AgentServicePool.getInstance().getClient(atsAgent);
                        agentServicePort.onTestStart(getCurrentTestCaseState());
                    } catch (AgentException_Exception ae) {
                        throw new AgentException(ae.getMessage());
                    }
                    configuredAgents.add(atsAgent);
                }
            }
        }
    }
}
Also used : RemoteLoggingConfigurator(com.axway.ats.agent.core.configuration.RemoteLoggingConfigurator) AgentService(com.axway.ats.agent.webapp.client.AgentService) AgentException(com.axway.ats.agent.core.exceptions.AgentException) AgentException_Exception(com.axway.ats.agent.webapp.client.AgentException_Exception) RemoteConfigurationManager(com.axway.ats.agent.webapp.client.configuration.RemoteConfigurationManager)

Example 9 with AgentService

use of com.axway.ats.agent.webapp.client.AgentService 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)

Example 10 with AgentService

use of com.axway.ats.agent.webapp.client.AgentService in project ats-framework by Axway.

the class DistributedLoadExecutor method runNotSynchedIterations.

// TODO When running non blocking, this method is started from a dedicated thread,
// so throwing an error does not affect the main test execution thread,
// so the test does not fail.
// We can keep this errors in some structure which can be checked when
// closing the test case, so we can fail it when needed
private void runNotSynchedIterations(boolean blockUntilCompletion) {
    log.info("Start executing action queue '" + queueName + "' on " + atsAgents.toString() + ". " + (blockUntilCompletion ? "And wait to finish." : "Will not wait to finish."));
    try {
        // start the actions on all loaders
        for (int i = 0; i < atsAgents.size(); i++) {
            String host = atsAgents.get(i);
            AgentService agentServicePort = AgentServicePool.getInstance().getClient(host);
            agentServicePort.startQueue(queueName);
        }
    } catch (Exception e) {
        String msg = "Error starting action queue '" + queueName + "'";
        log.error(msg, e);
        throw new RuntimeException(msg, e);
    }
    try {
        //wait until finished
        if (blockUntilCompletion) {
            waitUntilQueueFinishOnAllLoaders();
        } else {
            // and then wait in another thread until the queue finish
            ImportantThread helpThread = new ImportantThread(new Runnable() {

                @Override
                public void run() {
                    waitUntilQueueFinishOnAllLoaders();
                }
            });
            helpThread.setDescription(queueName);
            helpThread.start();
        }
    } catch (Exception e) {
        String msg = "Error waiting for completion of action queue '" + queueName + "'";
        log.error(msg, e);
        throw new RuntimeException(msg, e);
    }
}
Also used : AgentService(com.axway.ats.agent.webapp.client.AgentService) 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)

Aggregations

AgentException (com.axway.ats.agent.core.exceptions.AgentException)14 AgentException_Exception (com.axway.ats.agent.webapp.client.AgentException_Exception)14 AgentService (com.axway.ats.agent.webapp.client.AgentService)14 IOException (java.io.IOException)11 InternalComponentException (com.axway.ats.agent.webapp.client.InternalComponentException)10 InternalComponentException_Exception (com.axway.ats.agent.webapp.client.InternalComponentException_Exception)10 ArrayList (java.util.ArrayList)5 ImportantThread (com.axway.ats.agent.core.threading.ImportantThread)2 LoadQueueResult (com.axway.ats.log.model.LoadQueueResult)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 ActionRequest (com.axway.ats.agent.core.action.ActionRequest)1 Configurator (com.axway.ats.agent.core.configuration.Configurator)1 RemoteLoggingConfigurator (com.axway.ats.agent.core.configuration.RemoteLoggingConfigurator)1 LoaderDataConfig (com.axway.ats.agent.core.threading.data.config.LoaderDataConfig)1 ThreadingPattern (com.axway.ats.agent.core.threading.patterns.ThreadingPattern)1 ActionWrapper (com.axway.ats.agent.webapp.client.ActionWrapper)1 ArgumentWrapper (com.axway.ats.agent.webapp.client.ArgumentWrapper)1