use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class NodeSource method initActivity.
/**
* Initialization of node source. Creates and activates a pinger to monitor nodes.
*
* @param body active object body
*/
public void initActivity(Body body) {
this.stub = (NodeSource) PAActiveObject.getStubOnThis();
this.infrastructureManager.setNodeSource(this);
// Infrastructure has been configured and linked to the node source, so we can now persist the runtime
// variables of the infrastructure for the first time (they have been initialized during the creation of the
// infrastructure, in its configuration.
this.infrastructureManager.persistInfrastructureVariables();
this.activePolicy.setNodeSource((NodeSource) PAActiveObject.getStubOnThis());
// Set permissions again according to the activated node source policy
// node source admin permission
// it's the PrincipalPermission of the user who created the node source
this.adminPermission = new PrincipalPermission(this.administrator.getName(), this.administrator.getSubject().getPrincipals(UserNamePrincipal.class));
// creating node source provider permission
// could be one of the following: PrincipalPermission (NS creator) or PrincipalPermission (NS creator groups)
// or PrincipalPermission (anyone)
this.providerPermission = new PrincipalPermission(this.administrator.getName(), this.activePolicy.getProviderAccessType().getIdentityPrincipals(this.administrator));
this.nodeUserAccessType = this.activePolicy.getUserAccessType();
Thread.currentThread().setName("Node Source \"" + this.name + "\"");
}
use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class NodeSource method detectedPingedDownNode.
/**
* Marks node as down. Remove it from node source node set. It remains in rmcore nodes list until
* user decides to remove them or node source is shutdown.
* @see NodeSource#detectedPingedDownNode(String, String)
*/
public void detectedPingedDownNode(String nodeName, String nodeUrl) {
if (toShutdown) {
logger.warn("[" + name + "] detectedPingedDownNode request discarded because node source is shutting down");
return;
}
Node downNode = nodes.remove(nodeUrl);
if (downNode != null) {
logger.warn("[" + name + "] Detected down node: " + nodeUrl);
downNodes.put(nodeUrl, downNode);
try {
RMCore.topologyManager.removeNode(downNode);
infrastructureManager.internalNotifyDownNode(nodeName, nodeUrl, downNode);
} catch (RMException e) {
logger.error("Error while removing down node: " + nodeUrl, e);
}
} else if (removedNodes.containsKey(nodeUrl)) {
logger.info("[" + name + "] Detected down node has already been removed: " + nodeUrl);
// node has been removed, ping detection is ignored
} else {
logger.warn("[" + name + "] Detected down node: " + nodeUrl);
// almost no information about the node apart from its name and url
try {
infrastructureManager.internalNotifyDownNode(nodeName, nodeUrl, null);
} catch (RMException e) {
logger.error("New empty node " + nodeUrl + " could not be created to handle down node", e);
}
}
rmcore.setDownNode(nodeUrl);
}
use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class AutoUpdateInfrastructure method startNodeImpl.
/**
* Internal node acquisition method
* <p>
* Starts a PA runtime on remote host using a custom script, register it
* manually in the nodesource.
*
* @param hostTracker The host on which one the node will be started
* @param nbNodes number of nodes to deploy
* @param depNodeURLs list of deploying or lost nodes urls created
* @throws org.ow2.proactive.resourcemanager.exception.RMException
* acquisition failed
*/
protected void startNodeImpl(HostTracker hostTracker, int nbNodes, final List<String> depNodeURLs) throws RMException {
final String nodeName = this.nodeSource.getName() + "-" + ProActiveCounter.getUniqID();
String credentials = "";
try {
credentials = new String(nodeSource.getAdministrator().getCredentials().getBase64());
} catch (KeyException e) {
logger.error("Invalid credentials");
return;
}
Properties localProperties = new Properties();
localProperties.put(NODE_NAME, nodeName);
localProperties.put(HOST_NAME, hostTracker.getResolvedAddress().getHostName());
localProperties.put(NODESOURCE_CREDENTIALS, credentials);
localProperties.put(NODESOURCE_NAME, nodeSource.getName());
localProperties.put(NB_NODES, nbNodes);
String filledCommand = replaceProperties(command, localProperties);
filledCommand = replaceProperties(filledCommand, System.getProperties());
final List<String> createdNodeNames = RMNodeStarter.getWorkersNodeNames(nodeName, nbNodes);
depNodeURLs.addAll(addMultipleDeployingNodes(createdNodeNames, filledCommand, "Deploying node on host " + hostTracker.getResolvedAddress(), this.nodeTimeOut));
addTimeouts(depNodeURLs);
Process p;
try {
logger.debug("Deploying node: " + nodeName);
logger.debug("Launching the command: " + filledCommand);
p = Runtime.getRuntime().exec(new String[] { "bash", "-c", filledCommand });
} catch (IOException e1) {
multipleDeclareDeployingNodeLost(depNodeURLs, "Cannot run command: " + filledCommand + " - \n The following exception occurred: " + getStackTraceAsString(e1));
throw new RMException("Cannot run command: " + filledCommand, e1);
}
String lf = System.lineSeparator();
int circuitBreakerThreshold = 5;
while (!anyTimedOut(depNodeURLs) && circuitBreakerThreshold > 0) {
try {
int exitCode = p.exitValue();
if (exitCode != 0) {
logger.error("Child process at " + hostTracker.getResolvedAddress().getHostName() + " exited abnormally (" + exitCode + ").");
} else {
logger.error("Launching node script has exited normally whereas it shouldn't.");
}
String pOutPut = Utils.extractProcessOutput(p);
String pErrPut = Utils.extractProcessErrput(p);
final String description = "Script failed to launch a node on host " + hostTracker.getResolvedAddress().getHostName() + lf + " >Error code: " + exitCode + lf + " >Errput: " + pErrPut + " >Output: " + pOutPut;
logger.error(description);
if (super.checkNodeIsAcquiredAndDo(nodeName, null, new Runnable() {
public void run() {
multipleDeclareDeployingNodeLost(depNodeURLs, description);
}
})) {
return;
} else {
// there isn't any race regarding node registration
throw new RMException("A node " + nodeName + " is not expected anymore because of an error.");
}
} catch (IllegalThreadStateException e) {
logger.trace("IllegalThreadStateException while waiting for " + nodeName + " registration");
}
if (super.checkNodeIsAcquiredAndDo(nodeName, null, null)) {
// registration is ok, we destroy the process
logger.debug("Destroying the process: " + p);
try {
ProcessTree.get().get(p).kill();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return;
}
try {
Thread.sleep(1000);
} catch (Exception e) {
circuitBreakerThreshold--;
logger.trace("An exception occurred while monitoring a child process", e);
}
}
// if we exit because of a timeout
if (anyTimedOut(depNodeURLs)) {
// we remove it
removeTimeouts(depNodeURLs);
// we destroy the process
p.destroy();
throw new RMException("Deploying Node " + nodeName + " not expected any more");
}
if (circuitBreakerThreshold <= 0) {
logger.error("Circuit breaker threshold reached while monitoring a child process.");
throw new RMException("Several exceptions occurred while monitoring a child process.");
}
}
use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class InfrastructureManager method emitNodeEvent.
// **********************************************************************************************//
// *********************** Package private accessors & Helpers
// **********************************//
// **********************************************************************************************//
/**
* To emit a node event and register it in the database
*/
private void emitNodeEvent(final RMNodeEvent event) {
NodeSource nsStub = this.nodeSource.getStub();
nsStub.internalEmitDeployingNodeEvent(event);
}
Aggregations