use of org.ow2.proactive.scheduler.common.SchedulerEvent in project scheduling by ow2-proactive.
the class SchedulerEventBroadcaster method schedulerStateUpdatedEvent.
@Override
public void schedulerStateUpdatedEvent(SchedulerEvent schedulerEvent) {
logEvent(schedulerEvent);
broadcast(new EventNotification(EventNotification.Action.SCHEDULER_STATE_UPDATED, schedulerEvent.name(), null));
}
use of org.ow2.proactive.scheduler.common.SchedulerEvent in project scheduling by ow2-proactive.
the class SchedulerFrontendState method addEventListener.
SchedulerState addEventListener(SchedulerEventListener sel, boolean myEventsOnly, boolean getCurrentState, SchedulerEvent... events) throws NotConnectedException, PermissionException {
// checking permissions
ListeningUser uIdent = checkPermissionReturningListeningUser("addEventListener", YOU_DO_NOT_HAVE_PERMISSION_TO_ADD_A_LISTENER);
// check if listener is not null
if (sel == null) {
String msg = "Scheduler listener must be not null";
logger.info(msg);
throw new IllegalArgumentException(msg);
}
// check if the listener is a reified remote object
if (!MOP.isReifiedObject(sel)) {
String msg = "Scheduler listener must be a remote object";
logger.info(msg);
throw new IllegalArgumentException(msg);
}
// get the scheduler State
SchedulerState currentState = null;
if (getCurrentState) {
// check get state permission is checked in getState method
currentState = getState(myEventsOnly);
} else {
// check get state permission
handleOnlyMyJobsPermission(myEventsOnly, uIdent.getUser(), YOU_DO_NOT_HAVE_PERMISSION_TO_ADD_A_LISTENER);
}
// prepare user for receiving events
uIdent.getUser().setUserEvents(events);
// set if the user wants to get its events only or every events
uIdent.getUser().setMyEventsOnly(myEventsOnly);
// add the listener to the list of listener for this user.
UniqueID id = PAActiveObject.getContext().getCurrentRequest().getSourceBodyID();
uIdent.setListener(new ClientRequestHandler(this, id, sel));
// cancel timer for this user : session is now managed by events
uIdent.getUser().cancelSession();
// return to the user
return currentState;
}
use of org.ow2.proactive.scheduler.common.SchedulerEvent in project scheduling by ow2-proactive.
the class LiveJobs method endJob.
private void endJob(JobData jobData, TerminationData terminationData, InternalTask task, TaskResultImpl taskResult, String errorMsg, JobStatus jobStatus) {
JobId jobId = jobData.job.getId();
jobs.remove(jobId);
terminationData.addJobToTerminate(jobId, jobData.job.getGenericInformation(), jobData.job.getCredentials());
InternalJob job = jobData.job;
SchedulerEvent event;
if (job.getStatus() == JobStatus.PENDING) {
event = SchedulerEvent.JOB_PENDING_TO_FINISHED;
} else {
event = SchedulerEvent.JOB_RUNNING_TO_FINISHED;
}
if (task != null) {
jlogger.info(job.getId(), "ending request caused by task " + task.getId());
} else {
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
if (jobStatus == JobStatus.KILLED) {
Set<TaskId> tasksToUpdate = job.failed(null, jobStatus);
dbManager.killJob(job);
updateTasksInSchedulerState(job, tasksToUpdate);
} else {
// finished state (failed/canceled)
if (jobStatus != JobStatus.FINISHED) {
Set<TaskId> tasksToUpdate = job.failed(task.getId(), jobStatus);
// store the exception into jobResult / To prevent from empty
// task result (when job canceled), create one
boolean noResult = (jobStatus == JobStatus.CANCELED && taskResult == null);
if (jobStatus == JobStatus.FAILED || noResult) {
taskResult = new TaskResultImpl(task.getId(), new Exception(errorMsg), new SimpleTaskLogs("", errorMsg), -1);
}
dbManager.updateAfterJobFailed(job, task, taskResult, tasksToUpdate);
updateTasksInSchedulerState(job, tasksToUpdate);
}
}
// Cleaning job signals
cleanJobSignals(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());
}
use of org.ow2.proactive.scheduler.common.SchedulerEvent in project scheduling by ow2-proactive.
the class SchedulerEventReceiver method openAndReceive.
@SuppressWarnings("rawtypes")
private void openAndReceive(final SchedulerEventListener eventListener, boolean myEventsOnly, SchedulerEvent... events) throws IOException {
Client client = ClientFactory.getDefault().newClient();
AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
if (insecure) {
builder = builder.setAcceptAnyCertificate(true).setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}
AsyncHttpClientConfig httpClientConfig = builder.build();
AsyncHttpClient httpClient = new AsyncHttpClient(httpClientConfig);
socket = client.create(client.newOptionsBuilder().runtime(httpClient).reconnect(false).build());
EventNotificationHandler notificationHandler = new EventNotificationHandler(eventListener);
socket.on(Event.MESSAGE, notificationHandler);
socket.on(Event.CLOSE, new Function() {
public void on(Object t) {
SchedulerEventReceiver.logger.info("#### Websocket connection is closed ####");
if (eventListener instanceof DisconnectionAwareSchedulerEventListener) {
((DisconnectionAwareSchedulerEventListener) eventListener).notifyDisconnection();
}
}
});
// initialize the connection
RequestBuilder requestBuilder = client.newRequestBuilder();
requestBuilder.method(Request.METHOD.GET);
requestBuilder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
// authentication header
requestBuilder.header("sessionid", sessionId);
requestBuilder.uri(eventingUrl(restServerUrl));
requestBuilder.encoder(new EventSubscriptionEncoder());
requestBuilder.decoder(new EventNotificationDecoder());
requestBuilder.transport(Request.TRANSPORT.WEBSOCKET);
socket.open(requestBuilder.build());
// submit subscription request
EventSubscription eventSubscription = new EventSubscription(myEventsOnly, asStringArray(events));
socket.fire(EventCodecUtil.toJsonString(eventSubscription));
}
use of org.ow2.proactive.scheduler.common.SchedulerEvent in project scheduling by ow2-proactive.
the class SchedulerEventReceiver method asStringArray.
private static List<String> asStringArray(SchedulerEvent... schedulerEvents) {
List<String> result;
if (schedulerEvents == null) {
return Collections.emptyList();
}
result = Lists.newArrayListWithCapacity(schedulerEvents.length);
for (SchedulerEvent event : schedulerEvents) {
result.add(event.name());
}
return result;
}
Aggregations