Search in sources :

Example 46 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class TaskDBUtils method fetchTaskData.

private static List<TaskData> fetchTaskData(Session session, DBTaskDataParameters params) {
    Set<TaskStatus> taskStatuses = params.getStatuses();
    boolean hasUser = params.hasUser();
    boolean hasTag = params.hasTag();
    boolean hasDateFrom = params.hasDateFrom();
    boolean hasDateTo = params.hasDateTo();
    String queryPrefix = "select T from TaskData T where ";
    Query query = getQuery(session, params, taskStatuses, hasUser, hasTag, hasDateFrom, hasDateTo, params.getSortParams(), queryPrefix);
    query.setMaxResults(params.getLimit());
    query.setFirstResult(params.getOffset());
    return query.list();
}
Also used : Query(org.hibernate.Query) TaskStatus(org.ow2.proactive.scheduler.common.task.TaskStatus)

Example 47 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class TransactionHelperTest method setUp.

@Before
public void setUp() {
    sessionFactory = mock(SessionFactory.class);
    session = mock(Session.class);
    transaction = mock(Transaction.class);
    when(sessionFactory.openSession()).thenReturn(session);
    when(session.beginTransaction()).thenReturn(transaction);
    when(session.getTransaction()).thenReturn(transaction);
    transactionHelper = new TransactionHelper(sessionFactory);
    sessionWork = mock(SessionWork.class);
}
Also used : SessionFactory(org.hibernate.SessionFactory) SessionWork(org.ow2.proactive.db.SessionWork) Transaction(org.hibernate.Transaction) TransactionHelper(org.ow2.proactive.db.TransactionHelper) Session(org.hibernate.Session) Before(org.junit.Before)

Example 48 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class SchedulerFrontendState method checkChangePolicy.

synchronized void checkChangePolicy() throws NotConnectedException, PermissionException {
    UniqueID id = checkAccess();
    UserIdentificationImpl ident = identifications.get(id).getUser();
    // renew session for this user
    renewUserSession(id, ident);
    try {
        ident.checkPermission(new ChangePolicyPermission(), ident.getUsername() + " does not have permissions to change the policy of the scheduler");
    } catch (PermissionException ex) {
        logger.info(ex.getMessage());
        throw ex;
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UniqueID(org.objectweb.proactive.core.UniqueID) ChangePolicyPermission(org.ow2.proactive.scheduler.permissions.ChangePolicyPermission) UserIdentificationImpl(org.ow2.proactive.scheduler.job.UserIdentificationImpl)

Example 49 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session 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 50 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class SchedulerStateRest method taskResultByTag.

/**
 * Returns the task results of the set of task filtered by a given tag and
 * owned by the job <code>jobId</code>
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskTag
 *            the tag used to filter the tasks.
 * @return the task results of the set of tasks filtered by the given tag.
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result")
@Produces("application/json")
public List<TaskResultData> taskResultByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskTag + "/result");
        List<TaskResult> taskResults = s.getTaskResultsByTag(jobId, taskTag);
        ArrayList<TaskResultData> results = new ArrayList<TaskResultData>(taskResults.size());
        for (TaskResult current : taskResults) {
            TaskResultData r = buildTaskResultData(PAFuture.getFutureValue(current));
            results.add(r);
        }
        return results;
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) ArrayList(java.util.ArrayList) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Aggregations

Path (javax.ws.rs.Path)49 Produces (javax.ws.rs.Produces)47 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)39 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)37 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)36 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)34 GET (javax.ws.rs.GET)32 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)29 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)25 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)24 GZIP (org.jboss.resteasy.annotations.GZIP)23 Session (org.ow2.proactive_grid_cloud_portal.common.Session)18 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)17 ArrayList (java.util.ArrayList)16 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)15 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)15 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)15 JobState (org.ow2.proactive.scheduler.common.job.JobState)12 IOException (java.io.IOException)11 POST (javax.ws.rs.POST)11