use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.
the class RMDeployingNodeTest method createDeployingNode.
private RMDeployingNode createDeployingNode(String name) {
Client client = Mockito.mock(Client.class);
NodeSource nodeSource = Mockito.mock(NodeSource.class);
return new RMDeployingNode(name, nodeSource, "command", client);
}
use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.
the class StaxJobFactory method setNativeExecutable.
/**
* Add the Native Executable to this native Task.
* The cursor is currently at the beginning of the 'ELEMENT_NATIVE_EXECUTABLE' tag.
*
* @param nativeTask the task in which to add the Native Executable.
* @param cursorExec the streamReader with the cursor on the 'ELEMENT_NATIVE_EXECUTABLE' tag.
*/
private void setNativeExecutable(NativeTask nativeTask, XMLStreamReader cursorExec) throws JobCreationException {
int i = 0;
String current = null;
try {
// one step ahead to go to the command (static or dynamic)
while (cursorExec.next() != XMLEvent.START_ELEMENT) ;
current = cursorExec.getLocalName();
ArrayList<String> command = new ArrayList<>(0);
if (XMLTags.NATIVE_TASK_STATIC_COMMAND.matches(cursorExec.getLocalName())) {
String attr_ = null;
String current_ = null;
try {
for (i = 0; i < cursorExec.getAttributeCount(); i++) {
String attrName = cursorExec.getAttributeLocalName(i);
attr_ = attrName;
if (XMLAttributes.TASK_COMMAND_VALUE.matches(attrName)) {
command.add((cursorExec.getAttributeValue(i)));
}
if (XMLAttributes.TASK_WORKDING_DIR.matches(attrName)) {
logger.warn(XMLAttributes.TASK_WORKDING_DIR.getXMLName() + " attribute no longer supported. Please use a forkEnvironment for defining a working directory.");
}
}
int eventType;
while (cursorExec.hasNext()) {
eventType = cursorExec.next();
switch(eventType) {
case XMLEvent.START_ELEMENT:
current_ = cursorExec.getLocalName();
if (XMLTags.SCRIPT_ARGUMENT.matches(cursorExec.getLocalName())) {
command.add((cursorExec.getAttributeValue(0)));
}
break;
case XMLEvent.END_ELEMENT:
if (XMLTags.NATIVE_EXECUTABLE.matches(cursorExec.getLocalName())) {
nativeTask.setCommandLine(command.toArray(new String[command.size()]));
return;
}
break;
}
}
} catch (Exception e) {
throw new JobCreationException(current_, attr_, e);
}
} else {
throw new RuntimeException("Unknown command type: " + cursorExec.getLocalName());
}
} catch (JobCreationException jce) {
jce.pushTag(current);
throw jce;
} catch (Exception e) {
String temporaryAttribute = null;
if (cursorExec.isStartElement() && cursorExec.getAttributeCount() > 0) {
temporaryAttribute = cursorExec.getAttributeLocalName(i);
}
throw new JobCreationException(current, temporaryAttribute, e);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.
the class BatchJobInfrastructure method removeNode.
/**
* {@inheritDoc}
*/
@Override
public void removeNode(Node node) throws RMException {
String deleteCmd = getDeleteJobCommand();
String jobID = null;
String nodeName = node.getNodeInformation().getName();
if ((jobID = getCurrentNode(nodeName)) != null) {
try {
deleteJob(jobID);
} catch (RMException e) {
logger.warn(deleteCmd + " command failed, cannot ensure job " + jobID + " is deleted. Anyway, node " + nodeName + " is removed from the infrastructure manager.", e);
}
// atomic remove is important, furthermore we ensure consistent
// trace
writeLock.lock();
try {
removeCurrentNode(nodeName);
logger.debug("Node " + nodeName + " removed. # of current nodes: " + getCurrentNodesSize() + " # of deploying nodes: " + getNbDeployingNodes());
} catch (RuntimeException e) {
logger.error("Exception while removing a node: " + e.getMessage());
throw e;
} finally {
writeLock.unlock();
}
} else {
logger.error("Node " + nodeName + " is not known as a Node belonging to this " + getClass().getSimpleName());
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.
the class BatchJobInfrastructure method handleFailedDeployment.
/**
* Creates a lost node to notify the user that the deployment
* has failed because of an error
*
* @param clb
* @param e
* the error that caused the deployment to failed.
* @throws RMException
*/
private void handleFailedDeployment(CommandLineBuilder clb, Throwable e) throws RMException {
String error = getStackTraceAsString(e);
String command = null;
try {
command = clb.buildCommandLine(false);
} catch (Exception ex) {
command = "Cannot determine the command used to start the node.";
}
String lostNode = super.addDeployingNode(clb.getNodeName(), command, "Cannot deploy the node because of an error:" + System.lineSeparator() + error, 60000);
super.declareDeployingNodeLost(lostNode, null);
throw new RMException("The deployment failed because of an error", e);
}
use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.
the class InfrastructureManager method addDeployingNode.
/**
* Creates a new RMDeployingNode's, stores it in a local ArrayList and
* notify the owning NodeSource of the RMDeployingNode creation
*
* @param name
* The RMDeployingNode's name.
* @param description
* The RMDeployingNode's description
* @param timeout
* after which one the deploying node will be declared lost. (
* node acquisition after this timeout is discarded )
* @return The newly created RMDeployingNode's URL.
* @throws UnsupportedOperationException
* if the infrastructure manager is shuting down
*/
protected final String addDeployingNode(String name, String command, String description, final long timeout) {
checkName(name);
checkTimeout(timeout);
if (shutDown.get()) {
throw new UnsupportedOperationException("The infrastructure manager is shuting down.");
}
// if the user calls this method, we use the require nodes/timeout
// mecanism
setUsingDeployingNodesWithLockAndPersist();
NodeSource nsStub = this.nodeSource.getStub();
RMDeployingNode deployingNode = RMDeployingNodeAccessor.getDefault().newRMDeployingNode(name, nsStub, command, nsStub.getAdministrator(), description);
final String deployingNodeUrl = deployingNode.getNodeURL();
addDeployingNodeWithLockAndPersist(deployingNodeUrl, deployingNode);
if (RM_NODES_LOCK_RESTORATION.getValueAsBoolean()) {
logger.debug("Checking lock status for node " + deployingNodeUrl);
nodeSource.setDeploying(deployingNode);
// The value for 'deployingNode' is retrieved before calling 'nodeSource.setDeploying'
// However, 'nodeSource.setDeploying' may lock the node that is currently handled
// (e.g. node lock restoration on RM startup) and thus update 'deployingNodes'.
// In such a case, the 'deployingNodes' collection is updated with a new deploying node instance which has the
// same URL as 'deployingNode' but different state information (e.g. lock status).
// This is due to deep copies made by ProActive Programming with method invocation on Active Objects.
// As a consequence, the 'deployingNode' variable must be updated with the last value available
// in the 'deployingNodes' collection
deployingNode = getDeployingOrLostNode(deployingNodeUrl);
}
if (logger.isTraceEnabled()) {
logger.trace("New DeployingNode " + name + " instantiated in IM");
}
RMNodeEvent event = deployingNode.createNodeEvent(RMEventType.NODE_ADDED, null, deployingNode.getProvider().getName());
emitEvent(event);
this.sched(new TimerTask() {
@Override
public void run() {
InfrastructureManager.this.timeout(deployingNodeUrl, timeout);
}
}, timeout);
return deployingNode.getNodeURL();
}
Aggregations