use of org.ow2.proactive.scheduler.synchronization.Synchronization in project scheduling by ow2-proactive.
the class RMProxyActiveObject method handleCleaningScript.
/**
* Execute the given script on the given node.
* Also register a callback on {@link #cleanCallBack(Future, NodeSet)} method when script has returned.
* @param nodes the nodeset on which to start the script
* @param cleaningScript the script to be executed
* @param variables
* @param genericInformation
* @param taskId
* @param creds credentials with CredData containing third party credentials
*/
private void handleCleaningScript(NodeSet nodes, Script<?> cleaningScript, VariablesMap variables, Map<String, String> genericInformation, TaskId taskId, Credentials creds, Synchronization store, SignalApi signalAPI) {
TaskLogger instance = TaskLogger.getInstance();
try {
this.nodesTaskId.put(nodes, taskId);
// create a decrypter to access scheduler and retrieve Third Party User Credentials
String privateKeyPath = PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_AUTH_PRIVKEY_PATH.getValueAsString());
Decrypter decrypter = new Decrypter(Credentials.getPrivateKey(privateKeyPath));
decrypter.setCredentials(creds);
Node node = nodes.get(0);
String nodeUrl = node.getNodeInformation().getURL();
String nodeName = node.getNodeInformation().getName();
String hostName = node.getVMInformation().getHostName();
HashMap<String, Serializable> dictionary = new HashMap<>();
dictionary.putAll(variables.getScriptMap());
dictionary.putAll(variables.getInheritedMap());
dictionary.putAll(variables.getPropagatedVariables());
dictionary.putAll(variables.getScopeMap());
dictionary.put(SchedulerVars.PA_NODE_URL.toString(), nodeUrl);
dictionary.put(SchedulerVars.PA_NODE_NAME.toString(), nodeName);
dictionary.put(SchedulerVars.PA_NODE_HOST.toString(), hostName);
// start handler for binding
ScriptHandler handler = ScriptLoader.createHandler(node);
VariablesMap resolvedMap = new VariablesMap();
resolvedMap.setInheritedMap(VariableSubstitutor.resolveVariables(variables.getInheritedMap(), dictionary));
resolvedMap.setScopeMap(VariableSubstitutor.resolveVariables(variables.getScopeMap(), dictionary));
resolvedMap.put(SchedulerVars.PA_NODE_URL.toString(), nodeUrl);
resolvedMap.put(SchedulerVars.PA_NODE_NAME.toString(), nodeName);
resolvedMap.put(SchedulerVars.PA_NODE_HOST.toString(), hostName);
handler.addBinding(SchedulerConstants.VARIABLES_BINDING_NAME, (Serializable) resolvedMap);
handler.addBinding(SchedulerConstants.GENERIC_INFO_BINDING_NAME, (Serializable) genericInformation);
handler.addBinding(SchedulerConstants.SYNCHRONIZATION_API_BINDING_NAME, store);
handler.addBinding(SchedulerConstants.SIGNAL_API_BINDING_NAME, signalAPI);
// retrieve scheduler URL to bind with schedulerapi, globalspaceapi, and userspaceapi
String schedulerUrl = PASchedulerProperties.SCHEDULER_REST_URL.getValueAsString();
logger.debug("Binding schedulerapi...");
SchedulerNodeClient client = new SchedulerNodeClient(decrypter, schedulerUrl, taskId.getJobId(), Collections.emptyMap(), Collections.emptyMap());
handler.addBinding(SchedulerConstants.SCHEDULER_CLIENT_BINDING_NAME, client);
logger.debug("Binging rmapi...");
RMNodeClient rmNodeClient = new RMNodeClient(decrypter.decrypt(), schedulerUrl);
handler.addBinding(SchedulerConstants.RM_CLIENT_BINDING_NAME, rmNodeClient);
logger.debug("Binding globalspaceapi...");
RemoteSpace globalSpaceClient = new DataSpaceNodeClient(client, IDataSpaceClient.Dataspace.GLOBAL, schedulerUrl);
handler.addBinding(SchedulerConstants.DS_GLOBAL_API_BINDING_NAME, (Serializable) globalSpaceClient);
logger.debug("Binding userspaceapi...");
RemoteSpace userSpaceClient = new DataSpaceNodeClient(client, IDataSpaceClient.Dataspace.USER, schedulerUrl);
handler.addBinding(SchedulerConstants.DS_USER_API_BINDING_NAME, (Serializable) userSpaceClient);
logger.debug("Binding credentials...");
Map<String, String> resolvedThirdPartyCredentials = VariableSubstitutor.filterAndUpdate(decrypter.decrypt().getThirdPartyCredentials(), dictionary);
handler.addBinding(SchedulerConstants.CREDENTIALS_VARIABLE, (Serializable) resolvedThirdPartyCredentials);
ScriptResult<?> future = handler.handle(cleaningScript);
try {
PAEventProgramming.addActionOnFuture(future, "cleanCallBack", nodes);
} catch (IllegalArgumentException e) {
// TODO - linked to PROACTIVE-936 -> IllegalArgumentException is raised if method name is unknown
// should be replaced by checked exception
instance.error(taskId, "ERROR : Callback method won't be executed, node won't be released. This is a critical state, check the callback method name", e);
instance.close(taskId);
}
instance.info(taskId, "Cleaning Script started on node " + nodes.get(0).getNodeInformation().getURL());
} catch (Exception e) {
// if active object cannot be created or script has failed
instance.error(taskId, "Error while starting cleaning script for task " + taskId + " on " + nodes.get(0), e);
instance.close(taskId);
releaseNodes(nodes).booleanValue();
}
}
use of org.ow2.proactive.scheduler.synchronization.Synchronization in project scheduling by ow2-proactive.
the class RMProxyActiveObject method cleanCallBack.
/**
* Called when a script has returned (call is made as an active object call)
* <p>
* Check the nodes to release and release the one that have to (clean script has returned)
* Take care when renaming this method, method name is linked to
* {@link #handleCleaningScript(NodeSet, Script, VariablesMap, Map, TaskId, Credentials, Synchronization, SignalApi)}
*/
@ImmediateService
public synchronized void cleanCallBack(Future<ScriptResult<?>> future, NodeSet nodes) {
String nodeUrl = nodes.get(0).getNodeInformation().getURL();
ScriptResult<?> sResult = null;
TaskId taskId = nodesTaskId.get(nodes);
try {
sResult = future.get();
} catch (Exception e) {
logger.error("Exception occurred while executing cleaning script on node " + nodeUrl + ":", e);
}
printCleaningScriptInformations(nodes, sResult, taskId);
closeTaskLogger(taskId);
releaseNodes(nodes);
}
use of org.ow2.proactive.scheduler.synchronization.Synchronization in project scheduling by ow2-proactive.
the class SchedulerFrontend method startSynchronizationService.
private SynchronizationInternal startSynchronizationService() throws java.io.IOException, ProActiveException {
// Create and start the Synchronization Service Active Object
final AOSynchronization privateStore = PAActiveObject.newActive(AOSynchronization.class, new Object[] { PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_SYNCHRONIZATION_DATABASE.getValueAsString()) });
// Wait for the service to be actually started
privateStore.isStarted();
Runtime.getRuntime().addShutdownHook(new Thread(() -> PAActiveObject.terminateActiveObject(privateStore, true)));
// We use the following trick to obtain a ProActive Stub which only implements methods declared in the SynchronizationInternal interface.
// As this stub will be used remotely inside task, we make sure that it does not drag unnecessary dependencies (static fields, internal methods, etc)
SynchronizationInternal publicStore = PAActiveObject.lookupActive(SynchronizationInternal.class, PAActiveObject.getUrl(privateStore));
// register this service and give it a name
PAActiveObject.registerByName(publicStore, SchedulerConstants.SYNCHRONIZATION_DEFAULT_NAME);
return publicStore;
}
Aggregations