use of com.axway.ats.agent.core.threading.data.config.LoaderDataConfig 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);
}
use of com.axway.ats.agent.core.threading.data.config.LoaderDataConfig in project ats-framework by Axway.
the class Test_QueueCanceling method allAtOnce_BothThreadsRunning.
/**
* Both threads are canceled while running its 1st iteration
*/
@Test
public void allAtOnce_BothThreadsRunning() throws Exception {
expectedNumExecutions = 2;
actionRequests.add(new ActionRequest(TEST_COMPONENT_NAME, ACTION_SLEEP, new Object[] { "1000" }));
AllAtOncePattern pattern = new AllAtOncePattern(2, false, 2, 0);
QueueExecutionStatistics.getInstance().initActionExecutionResults(QUEUE_NAME);
actionHandler.scheduleActions(HOST, QUEUE_NAME, -1, actionRequests, pattern, new LoaderDataConfig(), false);
actionHandler.startQueue(QUEUE_NAME);
Thread.sleep(500);
}
use of com.axway.ats.agent.core.threading.data.config.LoaderDataConfig in project ats-framework by Axway.
the class Test_QueueCanceling method ramUp_OneThreadPaused_OneThreadNotStartedYet.
/**
* Cancel a ramp-up pattern while:
* - 1th thread has executed its first iteration and is sleeping before start the second iteration
* - the 2nd thread is waiting to start its first iteration
*/
@Test
public void ramUp_OneThreadPaused_OneThreadNotStartedYet() throws Exception {
expectedNumExecutions = 1;
actionRequests.add(new ActionRequest(TEST_COMPONENT_NAME, ACTION_SLEEP, new Object[] { "500" }));
RampUpPattern pattern = new RampUpPattern(2, false, 2, 1000, 2000, 1);
QueueExecutionStatistics.getInstance().initActionExecutionResults(QUEUE_NAME);
actionHandler.scheduleActions(HOST, QUEUE_NAME, -1, actionRequests, pattern, new LoaderDataConfig(), false);
actionHandler.startQueue(QUEUE_NAME);
Thread.sleep(1000);
}
use of com.axway.ats.agent.core.threading.data.config.LoaderDataConfig in project ats-framework by Axway.
the class Test_QueueCanceling method allAtOnce_SetMaxSpeed_BothThreadsPaused.
/**
* Both threads will do 1 iteration and will be paused for 30 seconds due to the max speed.
* At this moment we will cancel both threads.
*/
@Test
public void allAtOnce_SetMaxSpeed_BothThreadsPaused() throws Exception {
expectedNumExecutions = 2;
actionRequests.add(new ActionRequest(TEST_COMPONENT_NAME, ACTION_SLEEP, new Object[] { "500" }));
AllAtOncePattern pattern = new AllAtOncePattern(2, false, 5, 500);
pattern.setExecutionSpeed(30, 2);
QueueExecutionStatistics.getInstance().initActionExecutionResults(QUEUE_NAME);
actionHandler.scheduleActions(HOST, QUEUE_NAME, -1, actionRequests, pattern, new LoaderDataConfig(), false);
actionHandler.startQueue(QUEUE_NAME);
Thread.sleep(1500);
}
use of com.axway.ats.agent.core.threading.data.config.LoaderDataConfig in project ats-framework by Axway.
the class Test_QueueCanceling method allAtOnce_OneThreadRunning_OneThreadPaused.
/**
* We cancel 1 thread while running its 1st iteration and 2nd thread while waiting between its 1st and 2nd iterations
*/
@Test
public void allAtOnce_OneThreadRunning_OneThreadPaused() throws Exception {
expectedNumExecutions = 2;
ListDataConfig parameterData = new ListDataConfig("sleepTime", Arrays.asList(new String[] { "500", "2000" }), ParameterProviderLevel.PER_THREAD_STATIC);
LoaderDataConfig loaderDataConfig = new LoaderDataConfig();
loaderDataConfig.addParameterConfig(parameterData);
actionRequests.add(new ActionRequest(TEST_COMPONENT_NAME, ACTION_SLEEP, new Object[] { "sleepTime" }));
AllAtOncePattern pattern = new AllAtOncePattern(2, false, 2, 1000);
QueueExecutionStatistics.getInstance().initActionExecutionResults(QUEUE_NAME);
actionHandler.scheduleActions(HOST, QUEUE_NAME, -1, actionRequests, pattern, loaderDataConfig, false);
actionHandler.startQueue(QUEUE_NAME);
Thread.sleep(1000);
}
Aggregations