Search in sources :

Example 1 with SignalApi

use of org.ow2.proactive.scheduler.signal.SignalApi 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();
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SchedulerNodeClient(org.ow2.proactive.scheduler.task.client.SchedulerNodeClient) Node(org.objectweb.proactive.core.node.Node) RMNodeClient(org.ow2.proactive.resourcemanager.task.client.RMNodeClient) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) LoginException(javax.security.auth.login.LoginException) TaskLogger(org.ow2.proactive.scheduler.util.TaskLogger) RemoteSpace(org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) DataSpaceNodeClient(org.ow2.proactive.scheduler.task.client.DataSpaceNodeClient) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 2 with SignalApi

use of org.ow2.proactive.scheduler.signal.SignalApi 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);
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) LoginException(javax.security.auth.login.LoginException) ImmediateService(org.objectweb.proactive.annotation.ImmediateService)

Example 3 with SignalApi

use of org.ow2.proactive.scheduler.signal.SignalApi in project scheduling by ow2-proactive.

the class SignalApiTest method classInit.

@BeforeClass
public static void classInit() throws IOException, ActiveObjectCreationException, NodeException, AlreadyBoundException {
    CentralPAPropertyRepository.PA_CLASSLOADING_USEHTTP.setValue(false);
    if (System.getProperty("log4j.configuration") == null) {
        // While logger is not configured and it not set with sys properties, use Console logger
        Logger.getRootLogger().getLoggerRepository().resetConfiguration();
        BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%m%n")));
        Logger.getRootLogger().setLevel(Level.DEBUG);
    }
    Logger.getLogger(SignalApiImpl.class).setLevel(Level.TRACE);
    tempFolder = folder.newFolder("signal");
    Node localNode = ProActiveRuntimeImpl.getProActiveRuntime().createLocalNode("signal-node-0", true, "signal-v-node-0");
    synchronizationInternal = PAActiveObject.newActive(AOSynchronization.class, new Object[] { tempFolder.getAbsolutePath() }, localNode);
    synchronizationInternal.createChannelIfAbsent(USER, TASK_ID, SIGNALS_CHANNEL, true);
    signalApi = new SignalApiImpl(USER, TASK_ID, synchronizationInternal);
    executor = Executors.newFixedThreadPool(2);
}
Also used : AOSynchronization(org.ow2.proactive.scheduler.synchronization.AOSynchronization) Node(org.objectweb.proactive.core.node.Node) PAActiveObject(org.objectweb.proactive.api.PAActiveObject)

Aggregations

LoginException (javax.security.auth.login.LoginException)2 Node (org.objectweb.proactive.core.node.Node)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ImmediateService (org.objectweb.proactive.annotation.ImmediateService)1 PAActiveObject (org.objectweb.proactive.api.PAActiveObject)1 RMNodeClient (org.ow2.proactive.resourcemanager.task.client.RMNodeClient)1 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)1 RemoteSpace (org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace)1 AOSynchronization (org.ow2.proactive.scheduler.synchronization.AOSynchronization)1 DataSpaceNodeClient (org.ow2.proactive.scheduler.task.client.DataSpaceNodeClient)1 SchedulerNodeClient (org.ow2.proactive.scheduler.task.client.SchedulerNodeClient)1 Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)1 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)1 TaskLogger (org.ow2.proactive.scheduler.util.TaskLogger)1 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)1