use of org.ow2.proactive.scheduler.common.Scheduler in project scheduling by ow2-proactive.
the class LiveJobs method taskTerminatedWithResult.
public TerminationData taskTerminatedWithResult(TaskId taskId, TaskResultImpl result) {
JobData jobData = lockJob(taskId.getJobId());
if (jobData == null) {
return emptyResult(taskId);
}
try {
InternalTask task;
try {
task = jobData.job.getTask(taskId);
} catch (UnknownTaskException e) {
logger.error("Unexpected exception", e);
return emptyResult(taskId);
}
if (task.getStatus() != TaskStatus.RUNNING) {
tlogger.info(taskId, "task isn't running anymore");
return emptyResult(taskId);
}
TaskIdWrapper taskIdWrapper = TaskIdWrapper.wrap(taskId);
RunningTaskData taskData = runningTasksData.remove(taskIdWrapper);
if (taskData == null) {
tlogger.info(taskId, "Task " + taskId + " terminates after a recovery of the scheduler");
taskData = new RunningTaskData(task, jobData.job.getOwner(), jobData.job.getCredentials(), task.getExecuterInformation().getLauncher());
}
TerminationData terminationData = createAndFillTerminationData(result, taskData, jobData.job, TerminationData.TerminationStatus.NORMAL);
boolean errorOccurred = result.hadException();
tlogger.info(taskId, "finished with" + (errorOccurred ? "" : "out") + " errors");
if (errorOccurred) {
tlogger.error(taskId, "task has terminated with an error", result.getException());
task.decreaseNumberOfExecutionLeft();
boolean requiresPauseJobOnError = onErrorPolicyInterpreter.requiresPauseJobOnError(task);
int numberOfExecutionLeft = task.getNumberOfExecutionLeft();
if (numberOfExecutionLeft <= 0 && onErrorPolicyInterpreter.requiresCancelJobOnError(task)) {
tlogger.info(taskId, "no retry left and task is tagged with cancel job on error");
jobData.job.increaseNumberOfFaultyTasks(taskId);
endJob(jobData, terminationData, task, result, "An error occurred in your task and the maximum number of executions has been reached. " + "You also ask to cancel the job in such a situation!", JobStatus.CANCELED);
jlogger.info(taskId.getJobId(), "job has been canceled");
return terminationData;
} else if (numberOfExecutionLeft > 0) {
tlogger.info(taskId, "number of execution left is " + numberOfExecutionLeft);
if (onErrorPolicyInterpreter.requiresPauseTaskOnError(task) || requiresPauseJobOnError) {
long waitTime = jobData.job.getNextWaitingTime(task.getMaxNumberOfExecution() - numberOfExecutionLeft);
restartTaskOnError(jobData, task, TaskStatus.WAITING_ON_ERROR, result, waitTime, terminationData);
tlogger.info(taskId, "new restart is scheduled");
return terminationData;
} else {
jobData.job.increaseNumberOfFaultyTasks(taskId);
long waitTime = jobData.job.getNextWaitingTime(task.getMaxNumberOfExecution() - numberOfExecutionLeft);
restartTaskOnError(jobData, task, TaskStatus.WAITING_ON_ERROR, result, waitTime, terminationData);
tlogger.info(taskId, "new restart is scheduled");
return terminationData;
}
} else if (numberOfExecutionLeft <= 0) {
if (!onErrorPolicyInterpreter.requiresPauseTaskOnError(task) && !onErrorPolicyInterpreter.requiresPauseJobOnError(task) && !onErrorPolicyInterpreter.requiresCancelJobOnError(task)) {
jobData.job.increaseNumberOfFaultyTasks(taskId);
// remove the parent tasks results if task fails and job is canceled
task.removeParentTasksResults();
} else if (onErrorPolicyInterpreter.requiresPauseTaskOnError(task)) {
suspendTaskOnError(jobData, task, result.getTaskDuration());
tlogger.info(taskId, "Task always contains errors after automatic restart, so it stays in In_Error state");
return terminationData;
} else if (requiresPauseJobOnError) {
suspendTaskOnError(jobData, task, result.getTaskDuration());
pauseJob(task.getJobId());
logger.info("Task always contains errors after automatic restart, so Job is always paused on error");
return terminationData;
}
if (requiresPauseJobOnError) {
pauseJob(task.getJobId());
}
}
} else {
// remove the parent tasks results if task finished with no error
task.removeParentTasksResults();
}
terminateTask(jobData, task, errorOccurred, result, terminationData);
return terminationData;
} finally {
jobData.unlock();
}
}
use of org.ow2.proactive.scheduler.common.Scheduler in project scheduling by ow2-proactive.
the class SchedulerClientExample method main.
public static void main(String[] args) throws Exception {
// LOGIN IN
SchedulerRestClient client = new SchedulerRestClient("http://localhost:9191/rest/rest/");
SchedulerRestInterface scheduler = client.getScheduler();
String sessionId = scheduler.login("admin", "admin");
// JOB SUBMISSION
File xmlJobFile = new File("/home/ybonnaffe/src/cloud_service_provider_conectors/cloudstack/vminfo_job.xml");
JobIdData xmlJob;
try (FileInputStream inputStream = new FileInputStream(xmlJobFile)) {
xmlJob = client.submitXml(sessionId, inputStream);
}
System.out.println(xmlJob.getReadableName() + " " + xmlJob.getId());
// FLAT JOB SUBMISSION
JobIdData flatJob = scheduler.submitFlat(sessionId, "echo hello", "test-hello", null, null);
System.out.println("Jobid=" + flatJob);
String serverlog = scheduler.jobServerLog(sessionId, Long.toString(flatJob.getId()));
System.out.println(serverlog);
while (true) {
JobStateData jobState2 = scheduler.listJobs(sessionId, Long.toString(flatJob.getId()));
System.out.println(jobState2);
if (jobState2.getJobInfo().getStatus().name().equals("FINISHED")) {
break;
}
Thread.sleep(100);
}
JobResultData jobResultData = scheduler.jobResult(sessionId, Long.toString(flatJob.getId()));
System.out.println(jobResultData);
TaskResultData taskresult = scheduler.taskResult(sessionId, Long.toString(flatJob.getId()), "task_1");
System.out.println(taskresult);
List<TaskStateData> jobTaskStates = scheduler.getJobTaskStates(sessionId, Long.toString(flatJob.getId())).getList();
System.out.println(jobTaskStates);
TaskStateData task_1 = scheduler.jobTask(sessionId, Long.toString(flatJob.getId()), "task_1");
System.out.println(task_1);
// OTHER CALLS
List<SchedulerUserData> users = scheduler.getUsers(sessionId);
System.out.println(users);
System.out.println(users.size());
RestMapPage<Long, ArrayList<UserJobData>> page = scheduler.revisionAndJobsInfo(sessionId, 0, 50, true, true, true, true);
Map<Long, ArrayList<UserJobData>> map = page.getMap();
System.out.println(map);
System.out.println(scheduler.getSchedulerStatus(sessionId));
System.out.println(scheduler.getUsageOnMyAccount(sessionId, new Date(), new Date()));
// FAILING CALL
try {
JobStateData jobState = scheduler.listJobs(sessionId, "601");
System.out.println(jobState);
} catch (UnknownJobRestException e) {
System.err.println("exception! " + e.getMessage());
e.printStackTrace();
}
}
use of org.ow2.proactive.scheduler.common.Scheduler in project scheduling by ow2-proactive.
the class SchedulerRestClient method pullFile.
public void pullFile(String sessionId, String space, String path, String outputPath) throws Exception {
String uriTmpl = (new StringBuilder(restEndpointURL)).append(addSlashIfMissing(restEndpointURL)).append("scheduler/dataspace/").append(space).append(URLEncoder.encode(path, "UTF-8")).toString();
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(providerFactory).build();
ResteasyWebTarget target = client.target(uriTmpl);
Response response = target.request().header("sessionid", sessionId).get();
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("Cannot retrieve the file. Status code: %s", response.getStatus()), response);
}
}
try {
File file = new File(outputPath);
if (response.hasEntity()) {
copyInputStreamToFile(response.readEntity(InputStream.class), file);
} else {
// creates an empty file
file.createNewFile();
}
} catch (Exception e) {
throw e;
} finally {
if (response != null) {
response.close();
}
if (!client.isClosed()) {
client.close();
}
}
}
use of org.ow2.proactive.scheduler.common.Scheduler in project scheduling by ow2-proactive.
the class SchedulerRestClient method pushFile.
public boolean pushFile(String sessionId, String space, String path, String fileName, InputStream fileContent) throws Exception {
String uriTmpl = (new StringBuilder(restEndpointURL)).append(addSlashIfMissing(restEndpointURL)).append("scheduler/dataspace/").append(space).append(URLEncoder.encode(path, "UTF-8")).toString();
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(providerFactory).build();
ResteasyWebTarget target = client.target(uriTmpl);
MultipartFormDataOutput formData = new MultipartFormDataOutput();
formData.addFormData("fileName", fileName, MediaType.TEXT_PLAIN_TYPE);
formData.addFormData("fileContent", fileContent, MediaType.APPLICATION_OCTET_STREAM_TYPE);
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("File upload failed. Status code: %d", response.getStatus()), response);
}
}
return response.readEntity(Boolean.class);
}
use of org.ow2.proactive.scheduler.common.Scheduler in project scheduling by ow2-proactive.
the class SchedulerRestClient method submit.
private JobIdData submit(String sessionId, InputStream job, MediaType mediaType, Map<String, String> variables) throws Exception {
String uriTmpl = restEndpointURL + addSlashIfMissing(restEndpointURL) + "scheduler/submit";
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(providerFactory).build();
ResteasyWebTarget target = client.target(uriTmpl);
if (variables != null) {
for (String key : variables.keySet()) {
target = target.matrixParam(key, variables.get(key));
}
}
MultipartFormDataOutput formData = new MultipartFormDataOutput();
formData.addFormData("file", job, mediaType);
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