Search in sources :

Example 1 with SyncQueueItemVO

use of org.apache.cloudstack.framework.jobs.impl.SyncQueueItemVO in project cloudstack by apache.

the class SyncQueueItemDaoImpl method getActiveQueueItems.

@Override
public List<SyncQueueItemVO> getActiveQueueItems(Long msid, boolean exclusive) {
    SearchBuilder<SyncQueueItemVO> sb = createSearchBuilder();
    sb.and("lastProcessMsid", sb.entity().getLastProcessMsid(), SearchCriteria.Op.EQ);
    sb.done();
    SearchCriteria<SyncQueueItemVO> sc = sb.create();
    sc.setParameters("lastProcessMsid", msid);
    Filter filter = new Filter(SyncQueueItemVO.class, "created", true, null, null);
    if (exclusive)
        return lockRows(sc, filter, true);
    return listBy(sc, filter);
}
Also used : SyncQueueItemVO(org.apache.cloudstack.framework.jobs.impl.SyncQueueItemVO) Filter(com.cloud.utils.db.Filter)

Example 2 with SyncQueueItemVO

use of org.apache.cloudstack.framework.jobs.impl.SyncQueueItemVO in project cloudstack by apache.

the class SyncQueueItemDaoImpl method getNextQueueItem.

@Override
public SyncQueueItemVO getNextQueueItem(long queueId) {
    SearchBuilder<SyncQueueItemVO> sb = createSearchBuilder();
    sb.and("queueId", sb.entity().getQueueId(), SearchCriteria.Op.EQ);
    sb.and("lastProcessNumber", sb.entity().getLastProcessNumber(), SearchCriteria.Op.NULL);
    sb.done();
    SearchCriteria<SyncQueueItemVO> sc = sb.create();
    sc.setParameters("queueId", queueId);
    Filter filter = new Filter(SyncQueueItemVO.class, "created", true, 0L, 1L);
    List<SyncQueueItemVO> l = listBy(sc, filter);
    if (l != null && l.size() > 0)
        return l.get(0);
    return null;
}
Also used : SyncQueueItemVO(org.apache.cloudstack.framework.jobs.impl.SyncQueueItemVO) Filter(com.cloud.utils.db.Filter)

Example 3 with SyncQueueItemVO

use of org.apache.cloudstack.framework.jobs.impl.SyncQueueItemVO in project cloudstack by apache.

the class SyncQueueItemDaoImpl method getNextQueueItems.

@Override
public List<SyncQueueItemVO> getNextQueueItems(int maxItems) {
    List<SyncQueueItemVO> l = new ArrayList<SyncQueueItemVO>();
    String sql = "SELECT i.id, i.queue_id, i.content_type, i.content_id, i.created " + " FROM sync_queue AS q JOIN sync_queue_item AS i ON q.id = i.queue_id " + " WHERE i.queue_proc_number IS NULL " + " GROUP BY q.id " + " ORDER BY i.id " + " LIMIT 0, ?";
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    try {
        pstmt = txn.prepareAutoCloseStatement(sql);
        pstmt.setInt(1, maxItems);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            SyncQueueItemVO item = new SyncQueueItemVO();
            item.setId(rs.getLong(1));
            item.setQueueId(rs.getLong(2));
            item.setContentType(rs.getString(3));
            item.setContentId(rs.getLong(4));
            item.setCreated(DateUtil.parseDateString(TimeZone.getTimeZone("GMT"), rs.getString(5)));
            l.add(item);
        }
    } catch (SQLException e) {
        s_logger.error("Unexpected sql exception, ", e);
    } catch (Throwable e) {
        s_logger.error("Unexpected exception, ", e);
    }
    return l;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SyncQueueItemVO(org.apache.cloudstack.framework.jobs.impl.SyncQueueItemVO) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 4 with SyncQueueItemVO

use of org.apache.cloudstack.framework.jobs.impl.SyncQueueItemVO in project cloudstack by apache.

the class SyncQueueItemDaoImpl method getBlockedQueueItems.

@Override
public List<SyncQueueItemVO> getBlockedQueueItems(long thresholdMs, boolean exclusive) {
    Date cutTime = DateUtil.currentGMTTime();
    SearchBuilder<SyncQueueItemVO> sbItem = createSearchBuilder();
    sbItem.and("lastProcessMsid", sbItem.entity().getLastProcessMsid(), SearchCriteria.Op.NNULL);
    sbItem.and("lastProcessNumber", sbItem.entity().getLastProcessNumber(), SearchCriteria.Op.NNULL);
    sbItem.and("lastProcessTime", sbItem.entity().getLastProcessTime(), SearchCriteria.Op.NNULL);
    sbItem.and("lastProcessTime2", sbItem.entity().getLastProcessTime(), SearchCriteria.Op.LT);
    sbItem.done();
    SearchCriteria<SyncQueueItemVO> sc = sbItem.create();
    sc.setParameters("lastProcessTime2", new Date(cutTime.getTime() - thresholdMs));
    if (exclusive)
        return lockRows(sc, null, true);
    return listBy(sc, null);
}
Also used : SyncQueueItemVO(org.apache.cloudstack.framework.jobs.impl.SyncQueueItemVO) Date(java.util.Date)

Aggregations

SyncQueueItemVO (org.apache.cloudstack.framework.jobs.impl.SyncQueueItemVO)4 Filter (com.cloud.utils.db.Filter)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1