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) {
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);
HashMap<String, Serializable> dictionary = new HashMap<>();
dictionary.putAll(variables.getScriptMap());
dictionary.putAll(variables.getInheritedMap());
dictionary.putAll(variables.getPropagatedVariables());
dictionary.putAll(variables.getScopeMap());
// start handler for binding
ScriptHandler handler = ScriptLoader.createHandler(nodes.get(0));
VariablesMap resolvedMap = new VariablesMap();
resolvedMap.setInheritedMap(VariableSubstitutor.resolveVariables(variables.getInheritedMap(), dictionary));
resolvedMap.setScopeMap(VariableSubstitutor.resolveVariables(variables.getScopeMap(), dictionary));
handler.addBinding(SchedulerConstants.VARIABLES_BINDING_NAME, (Serializable) resolvedMap);
handler.addBinding(SchedulerConstants.GENERIC_INFO_BINDING_NAME, (Serializable) genericInformation);
// 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);
handler.addBinding(SchedulerConstants.SCHEDULER_CLIENT_BINDING_NAME, (Serializable) client);
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.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);
releaseNodes(nodes).booleanValue();
}
}
use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class SchedulerStateRest method valueOfTaskResultByTag.
/**
* Returns the value of the task result for a set of tasks of the job
* <code>jobId</code> filtered by a given tag. <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/tag/{tasktag}/result/serializedvalue
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job
* @param taskTag
* the tag used to filter the tasks.
* @return the value of the task result
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result/value")
@Produces("application/json")
public Map<String, String> valueOfTaskResultByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws Throwable {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/tag/" + taskTag + "/result/value");
List<TaskResult> taskResults = s.getTaskResultsByTag(jobId, taskTag);
Map<String, String> result = new HashMap<String, String>(taskResults.size());
for (TaskResult currentTaskResult : taskResults) {
result.put(currentTaskResult.getTaskId().getReadableName(), getTaskResultValueAsStringOrExceptionStackTrace(currentTaskResult));
}
return result;
}
use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class RMRestTest method callGetStatHistory.
private JSONObject callGetStatHistory() throws Exception {
RMProxyUserInterface rmMock = mock(RMProxyUserInterface.class);
String sessionId = SharedSessionStoreTestUtils.createValidSession(rmMock);
AttributeList value = new AttributeList(Collections.singletonList(new Attribute("test", createRrdDb().getBytes())));
when(rmMock.getMBeanAttributes(Matchers.<ObjectName>any(), Matchers.<String[]>any())).thenReturn(value);
RMRestInterface client = ProxyFactory.create(RMRestInterface.class, "http://localhost:" + port + "/");
String statHistory = client.getStatHistory(sessionId, "hhhhh");
return (JSONObject) new JSONParser().parse(statHistory);
}
use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class RMCore method checkNodeAdminPermission.
/**
* Checks if the client is the node admin.
*
* @param rmnode is a node to be checked
* @param client is a client to be checked
* @return true if the client is an admin, SecurityException otherwise
*/
private boolean checkNodeAdminPermission(RMNode rmnode, Client client) {
NodeSource nodeSource = rmnode.getNodeSource();
String errorMessage = client.getName() + " is not authorized to manage node " + rmnode.getNodeURL() + " from " + rmnode.getNodeSourceName();
// a node provider
try {
// checking if the caller is an administrator
client.checkPermission(nodeSource.getAdminPermission(), errorMessage);
} catch (SecurityException ex) {
// the caller is not an administrator, so checking if it is a node provider
client.checkPermission(rmnode.getAdminPermission(), errorMessage);
}
return true;
}
use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class SchedulerRestClient method submit.
private JobIdData submit(String sessionId, InputStream job, MediaType mediaType, Map<String, String> variables, Map<String, String> genericInfos) throws NotConnectedRestException {
String uriTmpl = restEndpointURL + addSlashIfMissing(restEndpointURL) + "scheduler/submit";
ResteasyClient client = buildResteasyClient(providerFactory);
ResteasyWebTarget target = client.target(uriTmpl);
// Generic infos
if (genericInfos != null) {
for (String key : genericInfos.keySet()) {
target = target.queryParamNoTemplate(key, genericInfos.get(key));
}
}
// Multipart form
MultipartFormDataOutput formData = new MultipartFormDataOutput();
// Add job to multipart
formData.addFormData(FILE_KEY, job, mediaType);
// Add variables to multipart
if (variables != null && variables.size() > 0) {
formData.addFormData(VARIABLES_KEY, variables, MediaType.APPLICATION_JSON_TYPE);
}
// Multipart form entity
GenericEntity<MultipartFormDataOutput> entity = new GenericEntity<MultipartFormDataOutput>(formData) {
};
Response response = target.request().header("sessionid", sessionId).post(Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE));
if (response.getStatus() != HttpURLConnection.HTTP_OK) {
if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new NotConnectedRestException("User not authenticated or session timeout.");
} else {
throwException(String.format("Job submission failed status code: %d", response.getStatus()), response);
}
}
return response.readEntity(JobIdData.class);
}
Aggregations