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);
}
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;
}
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();
}
}
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);
}
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()));
}
Aggregations