Search in sources :

Example 11 with RestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException in project scheduling by ow2-proactive.

the class SchedulerStateRest method addExternalEndpointUrl.

@Override
public void addExternalEndpointUrl(String sessionId, String jobId, String endpointName, String externalEndpointUrl, String endpointIconUri) throws RestException {
    Scheduler s = checkAccess(sessionId, "/scheduler/jobs/" + jobId + "/externalendpointurl");
    Session ss = sessionStore.get(sessionId);
    if (endpointName == null) {
        throw new IllegalArgumentException("endpointName cannot be null");
    }
    if (externalEndpointUrl == null) {
        throw new IllegalArgumentException("externalEndpointUrl cannot be null");
    }
    try {
        ss.getScheduler().addExternalEndpointUrl(jobId, endpointName, externalEndpointUrl, endpointIconUri);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Example 12 with RestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException in project scheduling by ow2-proactive.

the class SchedulerStateRest method getSchedulerPropertiesFromSessionId.

@Override
public Map<String, Object> getSchedulerPropertiesFromSessionId(String sessionId) throws RestException {
    SchedulerProxyUserInterface scheduler = checkAccess(sessionId, "properties");
    Map<String, Object> schedulerProperties;
    try {
        schedulerProperties = scheduler.getSchedulerProperties();
        schedulerProperties.putAll(WebProperties.getPropertiesAsHashMap());
        schedulerProperties.putAll(PortalConfiguration.getPropertiesAsHashMap());
    } catch (SchedulerException e) {
        logger.warn("Attempt to retrieve scheduler properties but failed because connection exception", e);
        throw RestException.wrapExceptionToRest(e);
    }
    return schedulerProperties;
}
Also used : SchedulerProxyUserInterface(org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) FileObject(org.apache.commons.vfs2.FileObject)

Example 13 with RestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException in project scheduling by ow2-proactive.

the class SchedulerStateRest method getTaskIdsByTag.

@Override
public RestPage<String> getTaskIdsByTag(String sessionId, String taskTag, long from, long to, boolean mytasks, String statusFilter, int offset, int limit) throws RestException {
    Scheduler s = checkAccess(sessionId, "tasks");
    PageBoundaries boundaries = Pagination.getTasksPageBoundaries(offset, limit, TASKS_PAGE_SIZE);
    try {
        final Set<TaskStatus> statuses = TaskStatus.expandAggregatedStatusesToRealStatuses(Stream.of(statusFilter.split(";")).collect(Collectors.toList()));
        Page<TaskId> page = s.getTaskIds(taskTag, from, to, mytasks, statuses, boundaries.getOffset(), boundaries.getLimit());
        List<TaskId> taskIds = page.getList();
        List<String> taskNames = new ArrayList<>(taskIds.size());
        for (TaskId taskId : taskIds) {
            taskNames.add(taskId.getReadableName());
        }
        return new RestPage<>(taskNames, page.getSize());
    } catch (SchedulerException e) {
        throw RestException.wrapExceptionToRest(e);
    }
}
Also used : PageBoundaries(org.ow2.proactive.scheduler.common.util.PageBoundaries)

Example 14 with RestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException in project scheduling by ow2-proactive.

the class SchedulerStateRest method publish.

/**
 * Accepts an {@link EventSubscription} instance which specifies the types
 * of SchedulerEvents which interest the client. When such Scheduler event
 * occurs, it will be communicated to the client in the form of
 * {@link EventNotification} utilizing the WebSocket channel initialized
 * previously.
 */
@POST
@Path("/events")
@Produces("application/json")
public EventNotification publish(@Context HttpServletRequest req, EventSubscription subscription) throws RestException {
    HttpSession session = req.getSession();
    String broadcasterId = (String) session.getAttribute(ATM_BROADCASTER_ID);
    final SchedulerProxyUserInterface scheduler = checkAccess(broadcasterId);
    SchedulerEventBroadcaster eventListener = new SchedulerEventBroadcaster(broadcasterId);
    try {
        final SchedulerEventBroadcaster activedEventListener = PAActiveObject.turnActive(eventListener);
        scheduler.addEventListener(activedEventListener, subscription.isMyEventsOnly(), EventUtil.toSchedulerEvents(subscription.getEvents()));
        AtmosphereResource atmResource = getAtmosphereResourceFactory().find((String) session.getAttribute(ATM_RESOURCE_ID));
        atmResource.addEventListener(new WebSocketEventListenerAdapter() {

            @Override
            public void onDisconnect(@SuppressWarnings("rawtypes") WebSocketEvent event) {
                try {
                    logger.info("#### websocket disconnected remove listener ####");
                    scheduler.removeEventListener();
                } catch (Exception e) {
                    logger.error(e);
                }
                PAActiveObject.terminateActiveObject(activedEventListener, true);
            }
        });
    } catch (SchedulerException e) {
        throw RestException.wrapExceptionToRest(e);
    } catch (ActiveObjectCreationException | NodeException e) {
        throw new RuntimeException(e);
    }
    return new EventNotification(EventNotification.Action.NONE, null, null);
}
Also used : EventNotification(org.ow2.proactive_grid_cloud_portal.scheduler.dto.eventing.EventNotification) WebSocketEventListenerAdapter(org.atmosphere.websocket.WebSocketEventListenerAdapter) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) HttpSession(javax.servlet.http.HttpSession) SchedulerProxyUserInterface(org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface) NodeException(org.objectweb.proactive.core.node.NodeException) LoginException(javax.security.auth.login.LoginException) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) KeyException(java.security.KeyException) URISyntaxException(java.net.URISyntaxException) LogForwardingException(org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException) NodeException(org.objectweb.proactive.core.node.NodeException) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException)

Example 15 with RestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException in project scheduling by ow2-proactive.

the class SchedulerStateRest method removeExternalEndpointUrl.

@Override
public void removeExternalEndpointUrl(String sessionId, String jobId, String endpointName) throws RestException {
    Scheduler s = checkAccess(sessionId, "delete /scheduler/jobs/" + jobId + "/externalendpointurl");
    Session ss = sessionStore.get(sessionId);
    try {
        ss.getScheduler().removeExternalEndpointUrl(jobId, endpointName);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Aggregations

NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)8 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)7 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)7 HttpSession (javax.servlet.http.HttpSession)6 RestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException)6 Logger (org.apache.log4j.Logger)5 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)5 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)5 Session (org.ow2.proactive_grid_cloud_portal.common.Session)5 SchedulerRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException)3 URISyntaxException (java.net.URISyntaxException)2 KeyException (java.security.KeyException)2 ArrayList (java.util.ArrayList)2 LoginException (javax.security.auth.login.LoginException)2 Level (org.apache.log4j.Level)2 RMException (org.ow2.proactive.resourcemanager.exception.RMException)2 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)2 Page (org.ow2.proactive.scheduler.common.Page)2 TaskStatesPage (org.ow2.proactive.scheduler.common.task.TaskStatesPage)2 SchedulerProxyUserInterface (org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface)2