Search in sources :

Example 1 with SchedulerEvent

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));
}
Also used : EventNotification(org.ow2.proactive_grid_cloud_portal.scheduler.dto.eventing.EventNotification)

Example 2 with SchedulerEvent

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;
}
Also used : UniqueID(org.objectweb.proactive.core.UniqueID) SchedulerState(org.ow2.proactive.scheduler.common.SchedulerState)

Example 3 with SchedulerEvent

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());
}
Also used : SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) JobId(org.ow2.proactive.scheduler.common.job.JobId) TaskAbortedException(org.ow2.proactive.scheduler.common.exception.TaskAbortedException) TaskPreemptedException(org.ow2.proactive.scheduler.common.exception.TaskPreemptedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException) TaskRestartedException(org.ow2.proactive.scheduler.common.exception.TaskRestartedException) SchedulerEvent(org.ow2.proactive.scheduler.common.SchedulerEvent)

Example 4 with SchedulerEvent

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));
}
Also used : RequestBuilder(org.atmosphere.wasync.RequestBuilder) RequestBuilder(org.atmosphere.wasync.RequestBuilder) Function(org.atmosphere.wasync.Function) EventSubscription(org.ow2.proactive_grid_cloud_portal.scheduler.dto.eventing.EventSubscription) AsyncHttpClientConfig(com.ning.http.client.AsyncHttpClientConfig) Client(org.atmosphere.wasync.Client) AsyncHttpClient(com.ning.http.client.AsyncHttpClient) AsyncHttpClient(com.ning.http.client.AsyncHttpClient)

Example 5 with SchedulerEvent

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;
}
Also used : SchedulerEvent(org.ow2.proactive.scheduler.common.SchedulerEvent)

Aggregations

SchedulerEvent (org.ow2.proactive.scheduler.common.SchedulerEvent)5 JobId (org.ow2.proactive.scheduler.common.job.JobId)4 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)3 JobStatus (org.ow2.proactive.scheduler.common.job.JobStatus)2 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)2 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)2 TaskIdWrapper (org.ow2.proactive.utils.TaskIdWrapper)2 AsyncHttpClient (com.ning.http.client.AsyncHttpClient)1 AsyncHttpClientConfig (com.ning.http.client.AsyncHttpClientConfig)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Semaphore (java.util.concurrent.Semaphore)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1 Client (org.atmosphere.wasync.Client)1 Function (org.atmosphere.wasync.Function)1 RequestBuilder (org.atmosphere.wasync.RequestBuilder)1 Test (org.junit.Test)1 UniqueID (org.objectweb.proactive.core.UniqueID)1 NotificationData (org.ow2.proactive.scheduler.common.NotificationData)1