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);
}
}
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;
}
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);
}
}
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);
}
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);
}
}
Aggregations