use of org.objectweb.proactive.core.ProActiveTimeoutException in project scheduling by ow2-proactive.
the class TestJobWithInvalidSelectionScript method testJobWithInvalidSelectionScript.
@Test
public void testJobWithInvalidSelectionScript() throws Throwable {
String task1Name = "task1";
String task2Name = "task2";
String task3Name = "task3";
// cannot use SchedulerTHelper.testJobsubmission because
// task 3 is never executed so no event can received
// regarding this task.
JobId id = schedulerHelper.submitJob(new File(jobDescriptor.toURI()).getAbsolutePath());
// check events reception
log("Job submitted, id " + id.toString());
log("Waiting for jobSubmitted");
schedulerHelper.waitForEventJobSubmitted(id);
log("Waiting for job running");
schedulerHelper.waitForEventJobRunning(id);
log("Waiting for task running : " + task1Name);
schedulerHelper.waitForEventTaskRunning(id, task1Name);
log("Waiting for task finished : " + task1Name);
schedulerHelper.waitForEventTaskFinished(id, task1Name);
// second task will not even start
try {
log("Waiting for task *running : " + task2Name);
schedulerHelper.waitForEventTaskRunning(id, task2Name, 2000);
log("Waiting for task *finished : " + task2Name);
schedulerHelper.waitForEventTaskFinished(id, task2Name, 2000);
// should always go in the catch
fail();
} catch (ProActiveTimeoutException expected) {
}
// task 3 should not be started
boolean task3Started = false;
try {
schedulerHelper.waitForEventTaskRunning(id, task3Name, 1000);
// should always go in the catch
fail();
} catch (ProActiveTimeoutException e) {
}
schedulerHelper.killJob(id.toString());
JobInfo jobInfo = schedulerHelper.waitForEventJobFinished(id);
JobResult res = schedulerHelper.getJobResult(id);
Map<String, TaskResult> results = res.getAllResults();
// check that all tasks results are defined
assertNotNull(results.get("task1").value());
assertNull(results.get("task2"));
assertNull(results.get("task3"));
assertEquals(JobStatus.KILLED, jobInfo.getStatus());
assertEquals(1, jobInfo.getNumberOfFinishedTasks());
assertEquals(0, jobInfo.getNumberOfRunningTasks());
assertEquals(0, jobInfo.getNumberOfPendingTasks());
}
use of org.objectweb.proactive.core.ProActiveTimeoutException in project scheduling by ow2-proactive.
the class Connection method waitAndConnect.
/**
* Connects to the service with a specified timeout value. A timeout of
* zero is interpreted as an infinite timeout. The connection will then
* block until established or an error occurs.
*
* @param url the url on which to connect
* @param timeout the maximum amount of time to wait if it cannot connect
* @return the authentication if connection succeed
* @throws Exception if something wrong append
*/
public T waitAndConnect(String url, long timeout) throws Exception {
T authentication = null;
long leftTime = timeout == 0 ? Long.MAX_VALUE : timeout;
try {
// obtaining authentication active object
while (leftTime > 0) {
long startTime = System.currentTimeMillis();
try {
authentication = lookupAuthentication(url);
if (authentication == null) {
// simulating an exception during lookup
throw new Exception(ERROR_CANNOT_LOOKUP_AUTH);
}
// success
break;
} catch (NotBoundException e) {
// expected NotBoundException is not printed in the log
leftTime = sleepOrThrow(startTime, leftTime, e);
} catch (IOException e) {
leftTime = sleepOrThrow(startTime, leftTime, e);
} catch (Exception e) {
// unexpected Exception
logger.error("", e);
leftTime = sleepOrThrow(startTime, leftTime, e);
}
}
// waiting until scheduling is initialized
while (leftTime > 0) {
long startTime = System.currentTimeMillis();
BooleanWrapper future = authentication.isActivated();
try {
PAFuture.waitFor(future, leftTime);
} catch (ProActiveTimeoutException e) {
String errorMessage = "The ProActive server can not send a reply to the Node (usually due to a firewall). Please check the server logs for more information.";
logger.error(errorMessage, e);
throw new ProActiveRuntimeException(errorMessage, e);
}
if (authentication.isActivated().getBooleanValue()) {
// success
break;
} else {
leftTime = sleepOrThrow(startTime, leftTime, new Exception(ERROR_NOT_ACTIVATED));
}
}
} catch (InterruptedException e) {
throw new Exception(ERROR_CONNECTION_INTERRUPTED);
}
// TODO two cycles has the same pattern => the code can be unified
return authentication;
}
use of org.objectweb.proactive.core.ProActiveTimeoutException in project scheduling by ow2-proactive.
the class TestSmartProxy method waitWithMonitor.
protected void waitWithMonitor(EventMonitor monitor, long timeout) throws ProActiveTimeoutException {
TimeoutAccounter counter = TimeoutAccounter.getAccounter(timeout);
synchronized (monitor) {
monitor.setTimeouted(false);
while (!counter.isTimeoutElapsed()) {
if (monitor.eventOccured())
return;
try {
functionaltests.utils.SchedulerTHelper.log("waiting for event monitor " + monitor);
monitor.wait(counter.getRemainingTimeout());
} catch (InterruptedException e) {
// spurious wake-up, nothing to do
e.printStackTrace();
}
}
if (monitor.eventOccured())
return;
monitor.setTimeouted(true);
}
throw new ProActiveTimeoutException("timeout elapsed");
}
use of org.objectweb.proactive.core.ProActiveTimeoutException in project scheduling by ow2-proactive.
the class ScriptExecutor method executeScripts.
/**
* Runs selection scripts and process the results
* returns node if it matches, null otherwise
*/
private Node executeScripts() {
boolean selectionScriptSpecified = selectionScriptList != null && selectionScriptList.size() > 0;
boolean nodeMatch = true;
ScriptException exception = null;
boolean atLeastOneScriptExecuted = false;
if (selectionScriptSpecified) {
// initializing parallel script execution
for (SelectionScript script : selectionScriptList) {
if (manager.isPassed(script, criteria.getBindings(), rmnode)) {
// already executed static script
logger.debug(rmnode.getNodeURL() + " : " + script.hashCode() + " skipping script execution");
continue;
}
logger.info(rmnode.getNodeURL() + " : " + script.hashCode() + " executing");
try {
atLeastOneScriptExecuted = true;
ScriptResult<Boolean> scriptResult = rmnode.executeScript(script, criteria.getBindings());
// processing the results
if (!MOP.isReifiedObject(scriptResult) && scriptResult.getException() != null) {
// could not create script execution handler
// probably the node id down
logger.warn(rmnode.getNodeURL() + " : " + script.hashCode() + " exception", scriptResult.getException());
logger.warn(rmnode.getNodeURL() + " : pinging the node");
rmnode.getNodeSource().pingNode(rmnode.getNode());
nodeMatch = false;
break;
} else {
try {
PAFuture.waitFor(scriptResult, PAResourceManagerProperties.RM_SELECT_SCRIPT_TIMEOUT.getValueAsLong());
} catch (ProActiveTimeoutException e) {
logger.warn("Timeout on " + rmnode.getNodeURL());
// do not produce an exception here
nodeMatch = false;
break;
}
// display the script result and output in the scheduler logs
if (scriptResult != null && logger.isInfoEnabled()) {
logger.info(rmnode.getNodeURL() + " : " + script.hashCode() + " result " + scriptResult.getResult());
if (scriptResult.getOutput() != null && scriptResult.getOutput().length() > 0) {
logger.info(rmnode.getNodeURL() + " : " + script.hashCode() + " output\n" + scriptResult.getOutput());
}
}
if (scriptResult != null && scriptResult.errorOccured()) {
nodeMatch = false;
exception = new ScriptException(scriptResult.getException());
logger.warn(rmnode.getNodeURL() + " : exception during the script execution", scriptResult.getException());
}
// selection manager at the same time. Returns whether node is selected.
if (!manager.processScriptResult(script, criteria.getBindings(), scriptResult, rmnode)) {
nodeMatch = false;
break;
}
}
} catch (Exception ex) {
// proactive or network exception occurred when script was executed
logger.warn(rmnode.getNodeURL() + " : " + script.hashCode() + " exception", ex);
nodeMatch = false;
exception = new ScriptException(ex);
break;
}
}
}
if (selectionScriptSpecified && logger.isDebugEnabled()) {
if (nodeMatch) {
logger.debug(rmnode.getNodeURL() + " : selected");
} else {
logger.debug(rmnode.getNodeURL() + " : not selected");
}
}
if (atLeastOneScriptExecuted) {
try {
rmnode.clean();
} catch (Throwable t) {
logger.warn(rmnode.getNodeURL() + " : exception in cleaning", t);
logger.warn(rmnode.getNodeURL() + " : pinging the node");
try {
// 'pingNode' call can fail with exception if NodeSource was destroyed
rmnode.getNodeSource().pingNode(rmnode.getNode());
} catch (Throwable pingError) {
logger.warn(rmnode.getNodeURL() + " : nodeSource " + rmnode.getNodeSourceName() + " seems to be removed ", pingError);
}
return null;
}
}
manager.scriptExecutionFinished(rmnode.getNodeURL());
if (exception != null) {
throw exception;
}
if (nodeMatch) {
return rmnode.getNode();
} else {
return null;
}
}
use of org.objectweb.proactive.core.ProActiveTimeoutException in project scheduling by ow2-proactive.
the class TestAdminAddingNodes method testAddNodes.
@Test
public void testAddNodes() throws Exception {
final String NS_NAME = "TestAdminAddingNodes";
int pingFrequency = 6000;
ResourceManager resourceManager = rmHelper.getResourceManager();
resourceManager.createNodeSource(NS_NAME, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, NS_NAME);
resourceManager.setNodeSourcePingFrequency(pingFrequency, NS_NAME);
log("Test 1 : add a node");
String node1Name = "node1";
TestNode testNode1 = RMTHelper.createNode(node1Name);
testNodes.add(testNode1);
String node1URL = testNode1.getNodeURL();
resourceManager.addNode(node1URL, NS_NAME);
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
// wait for the node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getTotalAliveNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 2 : remove an already deployed node");
// preemptive removal is useless for this case, because node is free
resourceManager.removeNode(node1URL, false);
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node1URL);
assertEquals(0, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getTotalAliveNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
log("Test 3 : add a node, kill this node, node is detected down, and add a node that has the same URL");
// Test seems to have a race condition at this step
String node2Name = "node2";
TestNode testNode2 = RMTHelper.createNode(node2Name);
testNodes.add(testNode2);
String node2URL = testNode2.getNodeURL();
resourceManager.addNode(node2URL, NS_NAME);
// wait the node added event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
assertEquals(1, resourceManager.getState().getTotalAliveNodesNumber());
testNode2.kill();
testNodes.remove(testNode2);
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(evt.getNodeState(), NodeState.DOWN);
// wait the node down event
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
assertEquals(0, resourceManager.getState().getTotalAliveNodesNumber());
// create another node with the same URL, and add it to Resource manager
testNode2 = RMTHelper.createNode(node2Name, new URI(node2URL).getPort());
testNodes.add(testNode2);
node2URL = testNode2.getNodeURL();
resourceManager.addNode(node2URL, NS_NAME);
// wait the node added event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
assertEquals(1, resourceManager.getState().getTotalAliveNodesNumber());
log("Test 4 : add a node, keep this node free, kill this node, and add a node that has the same URL");
// put a large ping frequency in order to avoid down nodes detection
resourceManager.setNodeSourcePingFrequency(Integer.MAX_VALUE, NS_NAME);
// wait the end of last ping sequence
Thread.sleep(pingFrequency * 2);
// node2 is free, kill the node
testNode2.kill();
testNodes.remove(testNode2);
// create another node with the same URL, and add it to Resource manager
testNode2 = RMTHelper.createNode(node2Name, new URI(node2URL).getPort());
testNodes.add(testNode2);
node2URL = testNode2.getNodeURL();
resourceManager.addNode(node2URL, NS_NAME);
NodeFactory.getNode(node2URL);
// wait the node added event, node added is configuring
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 5 : add a node, put this node busy, kill this node, and add a node that has the same URL");
// put the the node to busy state
NodeSet nodes = resourceManager.getAtMostNodes(1, null);
PAFuture.waitFor(nodes);
// wait the node busy event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(evt.getNodeState(), NodeState.BUSY);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
// node2 is busy, kill the node
testNode2.kill();
testNodes.remove(testNode2);
// create another node with the same URL, and add it to Resource manager
testNode2 = RMTHelper.createNode(node2Name, new URI(node2URL).getPort());
testNodes.add(testNode2);
node2URL = testNode2.getNodeURL();
resourceManager.addNode(node2URL, NS_NAME);
NodeFactory.getNode(node2URL);
// wait the node added event, node added is configuring
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 6 : add a node, put this node toRelease, kill this node, and add a node that has the same URL");
// put the the node to busy state
nodes = resourceManager.getAtMostNodes(1, null);
PAFuture.waitFor(nodes);
// wait the node busy event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(evt.getNodeState(), NodeState.BUSY);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
// put the node in to Release state
resourceManager.removeNode(node2URL, false);
// wait the node to release event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(evt.getNodeState(), NodeState.TO_BE_REMOVED);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
testNode2.kill();
testNodes.remove(testNode2);
// create another node with the same URL, and add it to Resource manager
testNode2 = RMTHelper.createNode(node2Name, new URI(node2URL).getPort());
testNodes.add(testNode2);
node2URL = testNode2.getNodeURL();
resourceManager.addNode(node2URL, NS_NAME);
NodeFactory.getNode(node2URL);
// wait the node added event, node added is configuring
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(evt.getNodeState(), NodeState.FREE);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 7");
// add the same node twice and check that RM will not kill the node. If it does
// second attempt will fail
BooleanWrapper result = resourceManager.addNode(node2URL, NS_NAME);
assertFalse(result.getBooleanValue());
try {
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL, 8000);
fail("Should timeout");
} catch (ProActiveTimeoutException expected) {
// expected
}
}
Aggregations