Search in sources :

Example 1 with SchedulerEventListener

use of org.ow2.proactive.scheduler.common.SchedulerEventListener 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 2 with SchedulerEventListener

use of org.ow2.proactive.scheduler.common.SchedulerEventListener in project scheduling by ow2-proactive.

the class SchedulerFrontendState method addEventListener.

synchronized 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().getSession().cancel();
    // return to the user
    return currentState;
}
Also used : UniqueID(org.objectweb.proactive.core.UniqueID) SchedulerState(org.ow2.proactive.scheduler.common.SchedulerState)

Example 3 with SchedulerEventListener

use of org.ow2.proactive.scheduler.common.SchedulerEventListener in project scheduling by ow2-proactive.

the class AbstractSchedulerUser method registerListener.

public void registerListener(boolean getInitialState, boolean myEventsOnly, String listenerClazzName) throws SchedulerException, ProActiveException {
    try {
        if (this.scheduler == null)
            throw new IllegalStateException("The user is not connected to the Scheduler yet. " + "Consider calling the connectToScheduler() method first");
        SchedulerEventListener schedulerListener = createEventListener(listenerClazzName);
        logger.trace("Trying to expose the listener as a remote object");
        slExposer = new SchedulerListenerExposer(schedulerListener);
        SchedulerEventListener schedulerListenerRemoteRef = slExposer.createRemoteReference();
        logger.trace("Trying to register the listener to the Scheduler");
        // for the moment, listens only to the Jobs-related events
        SchedulerState initialState = scheduler.addEventListener(schedulerListenerRemoteRef, myEventsOnly, getInitialState, // job-related events
        SchedulerEvent.JOB_SUBMITTED, SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_PENDING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_PAUSED, SchedulerEvent.JOB_RESUMED, SchedulerEvent.JOB_RESTARTED_FROM_ERROR, SchedulerEvent.JOB_CHANGE_PRIORITY, // task-related events
        SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.TASK_WAITING_FOR_RESTART, SchedulerEvent.USERS_UPDATE, // Scheduler state related events
        SchedulerEvent.FROZEN, SchedulerEvent.RESUMED, SchedulerEvent.SHUTDOWN, SchedulerEvent.SHUTTING_DOWN, SchedulerEvent.STARTED, SchedulerEvent.STOPPED, SchedulerEvent.KILLED);
        if (getInitialState) {
            logger.info("Initial state of the scheduler is: " + initialState);
        }
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException("Class " + listenerClazzName + " is not available on this SchedulerUser's side", e);
    } catch (InstantiationException e) {
        throw new IllegalArgumentException("Cannot instantiate listener of type " + listenerClazzName, e);
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException("Cannot instantiate listener of type " + listenerClazzName, e);
    }
}
Also used : SchedulerListenerExposer(scalabilityTests.framework.listeners.SchedulerListenerExposer) SchedulerState(org.ow2.proactive.scheduler.common.SchedulerState) SchedulerEventListener(org.ow2.proactive.scheduler.common.SchedulerEventListener)

Example 4 with SchedulerEventListener

use of org.ow2.proactive.scheduler.common.SchedulerEventListener in project scheduling by ow2-proactive.

the class SchedulerJobSubmitter method createEventListener.

@Override
protected SchedulerEventListener createEventListener(String listenerClazzName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    logger.trace("Trying to load the listener class " + listenerClazzName);
    Class listenerClazz = Class.forName(listenerClazzName);
    logger.trace("Trying to instantiate a listener of type " + listenerClazzName);
    SchedulerEventListener schedulerListener = (SchedulerEventListener) listenerClazz.newInstance();
    logger.trace("Decorating the event listener with " + JobResultDecorator.class.getName());
    this.jrListener = new JobResultDecorator(schedulerListener, (AbstractSchedulerUser<JobId>) PAActiveObject.getStubOnThis());
    return this.jrListener;
}
Also used : JobResultDecorator(scalabilityTests.framework.listeners.JobResultDecorator) SchedulerEventListener(org.ow2.proactive.scheduler.common.SchedulerEventListener)

Example 5 with SchedulerEventListener

use of org.ow2.proactive.scheduler.common.SchedulerEventListener in project scheduling by ow2-proactive.

the class SchedulerUser method createEventListener.

@Override
protected SchedulerEventListener createEventListener(String listenerClazzName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    logger.trace("Trying to load the listener class " + listenerClazzName);
    Class listenerClazz = Class.forName(listenerClazzName);
    logger.trace("Trying to instantiate a listener of type " + listenerClazzName);
    SchedulerEventListener ret = (SchedulerEventListener) listenerClazz.newInstance();
    // ugly but necessary; getJobResult MUST be called from the SchedulerUser AO !!
    if (ret instanceof JobResultSchedulerListener)
        ((JobResultSchedulerListener) ret).setResultFetcher((SchedulerUser<JobId>) PAActiveObject.getStubOnThis());
    return ret;
}
Also used : JobResultSchedulerListener(scalabilityTests.framework.listeners.JobResultSchedulerListener) SchedulerEventListener(org.ow2.proactive.scheduler.common.SchedulerEventListener)

Aggregations

SchedulerEventListener (org.ow2.proactive.scheduler.common.SchedulerEventListener)3 SchedulerState (org.ow2.proactive.scheduler.common.SchedulerState)2 AsyncHttpClient (com.ning.http.client.AsyncHttpClient)1 AsyncHttpClientConfig (com.ning.http.client.AsyncHttpClientConfig)1 Client (org.atmosphere.wasync.Client)1 Function (org.atmosphere.wasync.Function)1 RequestBuilder (org.atmosphere.wasync.RequestBuilder)1 UniqueID (org.objectweb.proactive.core.UniqueID)1 EventSubscription (org.ow2.proactive_grid_cloud_portal.scheduler.dto.eventing.EventSubscription)1 JobResultDecorator (scalabilityTests.framework.listeners.JobResultDecorator)1 JobResultSchedulerListener (scalabilityTests.framework.listeners.JobResultSchedulerListener)1 SchedulerListenerExposer (scalabilityTests.framework.listeners.SchedulerListenerExposer)1