Search in sources :

Example 61 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class NodeSourcesTest method createNodeSource.

private NodeSourceData createNodeSource() {
    List<Serializable> infraParams = new ArrayList<>(1);
    infraParams.add("infrastructure");
    List<Serializable> policyParams = new ArrayList<>(1);
    policyParams.add("policy");
    return new NodeSourceData("ns1", DefaultInfrastructureManager.class.getName(), infraParams, StaticPolicy.class.getName(), policyParams, new Client(null, false), false, NodeSourceStatus.NODES_DEPLOYED, null);
}
Also used : Serializable(java.io.Serializable) DefaultInfrastructureManager(org.ow2.proactive.resourcemanager.nodesource.infrastructure.DefaultInfrastructureManager) StaticPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy) NodeSourceData(org.ow2.proactive.resourcemanager.db.NodeSourceData) Client(org.ow2.proactive.resourcemanager.authentication.Client)

Example 62 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class NodeSourcePriorityPolicy method arrangeNodes.

/**
 * Sort by node source priorities.
 *
 * @return the list arranged according to the node source priorities
 */
public List<RMNode> arrangeNodes(int number, List<RMNode> nodes, Client client) {
    if (nodeSources == null) {
        logger.error("The policy config was not loaded");
        return nodes;
    }
    if (nodeSources.size() == 0) {
        logger.debug("The policy config is empty");
        return nodes;
    }
    reloadConfig();
    logger.debug("Arranging nodes according to node sources priorities");
    HashMap<String, List<RMNode>> nodesMap = new HashMap<>();
    for (RMNode node : nodes) {
        if (!nodesMap.containsKey(node.getNodeSourceName())) {
            nodesMap.put(node.getNodeSourceName(), new LinkedList<RMNode>());
        }
        nodesMap.get(node.getNodeSourceName()).add(node);
    }
    List<RMNode> arranged = new LinkedList<>();
    for (String ns : nodeSources) {
        if (nodesMap.containsKey(ns)) {
            logger.debug("Adding " + nodesMap.get(ns).size() + " nodes from " + ns);
            arranged.addAll(nodesMap.get(ns));
            nodesMap.remove(ns);
            if (arranged.size() >= number) {
                break;
            }
        }
    }
    for (String ns : nodesMap.keySet()) {
        logger.debug("Adding nodes from " + ns);
        arranged.addAll(nodesMap.get(ns));
    }
    return arranged;
}
Also used : RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) HashMap(java.util.HashMap) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 63 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client 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 64 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class SchedulerStateRest method valueOfTaskResult.

/**
 * Returns the value of the task result of task <code>taskName</code> of the
 * job <code>jobId</code> <strong>the result is deserialized before sending
 * to the client, if the class is not found the content is replaced by the
 * string 'Unknown value type' </strong>. To get the serialized form of a
 * given result, one has to call the following restful service
 * jobs/{jobid}/tasks/{taskname}/result/serializedvalue
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskname
 *            the name of the task
 * @return the value of the task result
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/{taskname}/result/value")
@Produces("*/*")
public Serializable valueOfTaskResult(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("taskname") String taskname) throws Throwable {
    Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskname + "/result/value");
    TaskResult taskResult = s.getTaskResult(jobId, taskname);
    return getTaskResultValueAsStringOrExceptionStackTrace(taskResult);
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 65 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class RMCore method setBusyNode.

/**
 * Set a node state to busy. Set the node to busy, and move the node to the
 * internal busy nodes list. An event informing the node state's change is
 * thrown to RMMonitoring.
 *
 * @param owner
 * @param nodeUrl node to set
 */
public void setBusyNode(final String nodeUrl, Client owner) throws NotConnectedException {
    final RMNode rmNode = this.allNodes.get(nodeUrl);
    if (rmNode == null) {
        logger.error("Unknown node " + nodeUrl);
        return;
    }
    if (!clients.containsKey(owner.getId())) {
        logger.warn(nodeUrl + " cannot set busy as the client disconnected " + owner);
        throw new NotConnectedException("Client " + owner + " is not connected to the resource manager");
    }
    // If the node is already busy no need to go further
    if (rmNode.isBusy()) {
        return;
    }
    // Get the previous state of the node needed for the event
    final NodeState previousNodeState = rmNode.getState();
    rmNode.setBusy(owner);
    this.eligibleNodes.remove(rmNode);
    persistUpdatedRMNodeIfRecoveryEnabled(rmNode);
    // create the event
    this.registerAndEmitNodeEvent(rmNode.createNodeEvent(RMEventType.NODE_STATE_CHANGED, previousNodeState, owner.getName()));
}
Also used : RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) NodeState(org.ow2.proactive.resourcemanager.common.NodeState) NotConnectedException(org.ow2.proactive.resourcemanager.exception.NotConnectedException)

Aggregations

Test (org.junit.Test)69 ISchedulerClient (org.ow2.proactive.scheduler.rest.ISchedulerClient)36 Client (org.ow2.proactive.resourcemanager.authentication.Client)31 JobId (org.ow2.proactive.scheduler.common.job.JobId)30 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)28 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)25 SimpleJob (functionaltests.jobs.SimpleJob)25 Job (org.ow2.proactive.scheduler.common.job.Job)25 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)18 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)18 ListFile (org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile)18 File (java.io.File)17 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)13 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)13 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)11 Node (org.objectweb.proactive.core.node.Node)9 IOException (java.io.IOException)8 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)8 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)8 NodeSet (org.ow2.proactive.utils.NodeSet)7