use of org.ow2.proactive.scheduler.common.SchedulerEvent in project scheduling by ow2-proactive.
the class LiveJobs method killJobs.
/**
* @param jobIds terminated jobs with given id
* @return return TerminationData which is than used to kill all running tasks
*/
public TerminationData killJobs(List<JobId> jobIds) {
jobIds.forEach(jobId -> jlogger.info(jobId, "killing job"));
List<JobData> jobDatas = lockJobs(jobIds);
if (jobDatas == null || jobDatas.isEmpty()) {
return TerminationData.EMPTY;
}
try {
TaskResultImpl taskResult = null;
JobStatus jobStatus = JobStatus.KILLED;
Set<TaskId> tasksToUpdate = new HashSet<>();
TerminationData terminationData = TerminationData.newTerminationData();
for (JobData jobData : jobDatas) {
JobId jobId = jobData.job.getId();
jobs.remove(jobId);
terminationData.addJobToTerminate(jobId, jobData.job.getGenericInformation(), jobData.job.getCredentials());
InternalJob job = jobData.job;
jlogger.info(job.getId(), "ending request");
for (Iterator<RunningTaskData> i = runningTasksData.values().iterator(); i.hasNext(); ) {
RunningTaskData taskData = i.next();
if (taskData.getTask().getJobId().equals(jobId)) {
i.remove();
// remove previous read progress
taskData.getTask().setProgress(0);
terminationData.addTaskData(job, taskData, TerminationData.TerminationStatus.ABORTED, taskResult);
}
}
// if job has been killed
tasksToUpdate.addAll(job.failed(null, jobStatus));
}
dbManager.killJobs(jobDatas.stream().map(jobData -> jobData.job).collect(Collectors.toList()));
for (JobData jobData : jobDatas) {
InternalJob job = jobData.job;
updateTasksInSchedulerState(job, tasksToUpdate);
SchedulerEvent event;
if (job.getStatus() == JobStatus.PENDING) {
event = SchedulerEvent.JOB_PENDING_TO_FINISHED;
} else {
event = SchedulerEvent.JOB_RUNNING_TO_FINISHED;
}
// Cleaning job signals
cleanJobSignals(jobData.job.getId());
// update job and tasks events list and send it to front-end
updateJobInSchedulerState(job, event);
jlogger.info(job.getId(), "finished (" + jobStatus + ")");
jlogger.close(job.getId());
}
return terminationData;
} finally {
jobDatas.forEach(JobData::unlock);
}
}
use of org.ow2.proactive.scheduler.common.SchedulerEvent in project scheduling by ow2-proactive.
the class SchedulerMonitorsHandler method removeTaskEvent.
/**
* Remove, if exist a TaskEventMonitor to the list of memorized tasks events
* @param id
* @param taskName
* @param event
* @return
*/
private TaskEventMonitor removeTaskEvent(JobId id, String taskName, SchedulerEvent event) {
TaskEventMonitor tmp = new TaskEventMonitor(event, id, taskName);
for (Entry<TaskIdWrapper, List<TaskEventMonitor>> entry : tasksEvents.entrySet()) {
TaskId taskId = entry.getKey().getTaskId();
List<TaskEventMonitor> value = entry.getValue();
if (taskId.getJobId().equals(id) && taskId.getReadableName().equals(taskName) && value.contains(tmp)) {
return value.remove(value.indexOf(tmp));
}
}
return null;
}
use of org.ow2.proactive.scheduler.common.SchedulerEvent in project scheduling by ow2-proactive.
the class SchedulerMonitorsHandler method addTaskEvent.
/**
* Add a Task Event to the list of occurred events (memorize it).
* @param event type of task event
* @param taskInfo TaskEvent object associated to Event
*/
private void addTaskEvent(SchedulerEvent event, TaskInfo taskInfo) {
TaskIdWrapper taskId = TaskIdWrapper.wrap(taskInfo.getTaskId());
List<TaskEventMonitor> taskEventMonitors = tasksEvents.get(taskId);
if (taskEventMonitors == null) {
taskEventMonitors = new ArrayList<>();
tasksEvents.put(taskId, taskEventMonitors);
}
taskEventMonitors.add(new TaskEventMonitor(event, taskInfo));
}
use of org.ow2.proactive.scheduler.common.SchedulerEvent in project scheduling by ow2-proactive.
the class RestSmartProxyTest method testInErrorEventsReception.
@Test(timeout = TEN_MINUTES)
public void testInErrorEventsReception() throws Exception {
System.out.println("Begin testInErrorEventsReception ");
TaskFlowJob job = createInErrorJob();
final Semaphore semaphore = new Semaphore(0);
printJobXmlRepresentation(job);
final MutableBoolean taskHasBeenInError = new MutableBoolean(false);
final MutableBoolean taskMarkedAsFinished = new MutableBoolean(false);
SchedulerEventListenerExtended listener = new SchedulerEventListenerExtended() {
@Override
public void schedulerStateUpdatedEvent(SchedulerEvent eventType) {
System.out.println("RestSmartProxyTest.schedulerStateUpdatedEvent " + eventType);
}
@Override
public void jobSubmittedEvent(JobState job) {
System.out.println("RestSmartProxyTest.jobSubmittedEvent");
}
@Override
public void jobStateUpdatedEvent(NotificationData<JobInfo> notification) {
JobStatus status = notification.getData().getStatus();
System.out.println("RestSmartProxyTest.jobStateUpdatedEvent, eventType=" + notification.getEventType() + ", jobStatus=" + status);
if (status == JobStatus.IN_ERROR) {
semaphore.release();
}
}
@Override
public void taskStateUpdatedEvent(NotificationData<TaskInfo> notification) {
TaskStatus status = notification.getData().getStatus();
System.out.println("RestSmartProxyTest.taskStateUpdatedEvent, taskStatus=" + status);
if (status == TaskStatus.WAITING_ON_ERROR || status == TaskStatus.IN_ERROR) {
// IN_ERROR previously
taskHasBeenInError.setTrue();
}
if (status == TaskStatus.FINISHED && taskHasBeenInError.isTrue()) {
taskMarkedAsFinished.setTrue();
}
}
@Override
public void usersUpdatedEvent(NotificationData<UserIdentification> notification) {
System.out.println("RestSmartProxyTest.usersUpdatedEvent " + notification.getData());
}
@Override
public void pullDataFinished(String jobId, String taskName, String localFolderPath) {
System.out.println("RestSmartProxyTest.pullDataFinished");
}
@Override
public void pullDataFailed(String jobId, String taskName, String remoteFolder_URL, Throwable t) {
System.out.println("RestSmartProxyTest.pullDataFailed");
}
@Override
public void jobUpdatedFullDataEvent(JobState job) {
System.out.println("RestSmartProxyTest.jobUpdatedFullDataEvent");
}
};
restSmartProxy.addEventListener(listener);
JobId jobId = restSmartProxy.submit(job, inputLocalFolder.getAbsolutePath(), outputLocalFolder.getAbsolutePath(), false, false);
// the next line blocks until jobStateUpdatedEvent is called on the
// listener
// with job status set to IN_ERROR
semaphore.acquire();
String jobIdAsString = jobId.value();
System.out.println("Finish in-error task");
restSmartProxy.finishInErrorTask(jobIdAsString, inerrorTaskName);
waitForJobFinishState(jobIdAsString);
assertThat(taskHasBeenInError.booleanValue()).isTrue();
assertThat(taskMarkedAsFinished.booleanValue()).isTrue();
System.out.println("End testInErrorEventsReception");
}
use of org.ow2.proactive.scheduler.common.SchedulerEvent in project scheduling by ow2-proactive.
the class MyEventListener method jobStateUpdatedEvent.
@Override
public void jobStateUpdatedEvent(NotificationData<JobInfo> notification) {
System.out.println("MyEventListener.jobStateUpdatedEvent() " + notification);
JobId id = notification.getData().getJobId();
if (!id.equals(jobId))
return;
SchedulerEvent event = notification.getEventType();
if (event == SchedulerEvent.JOB_RUNNING_TO_FINISHED) {
jobFinished = true;
if (synchronous) {
synchronized (monitor) {
System.out.println("[MyEventListener] job finished event occured for " + jobId);
monitor.setEventOccured();
monitor.notifyAll();
}
}
}
}
Aggregations