Search in sources :

Example 1 with HaWorkVO

use of com.cloud.ha.HaWorkVO in project cloudstack by apache.

the class HighAvailabilityDaoImpl method take.

@Override
public HaWorkVO take(final long serverId) {
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    try {
        final SearchCriteria<HaWorkVO> sc = TBASearch.create();
        sc.setParameters("time", System.currentTimeMillis() >> 10);
        sc.setParameters("step", Step.Done, Step.Cancelled);
        final Filter filter = new Filter(HaWorkVO.class, null, true, 0l, 1l);
        txn.start();
        final List<HaWorkVO> vos = lockRows(sc, filter, true);
        if (vos.size() == 0) {
            txn.commit();
            return null;
        }
        final HaWorkVO work = vos.get(0);
        work.setServerId(serverId);
        work.setDateTaken(new Date());
        update(work.getId(), work);
        txn.commit();
        return work;
    } catch (final Throwable e) {
        throw new CloudRuntimeException("Unable to execute take", e);
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Filter(com.cloud.utils.db.Filter) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HaWorkVO(com.cloud.ha.HaWorkVO) Date(java.util.Date)

Example 2 with HaWorkVO

use of com.cloud.ha.HaWorkVO in project cloudstack by apache.

the class HighAvailabilityDaoImpl method deleteMigrationWorkItems.

@Override
public void deleteMigrationWorkItems(final long hostId, final WorkType type, final long serverId) {
    final SearchCriteria<HaWorkVO> sc = UntakenMigrationSearch.create();
    sc.setParameters("host", hostId);
    sc.setParameters("type", type.toString());
    HaWorkVO work = createForUpdate();
    Date date = new Date();
    work.setDateTaken(date);
    work.setServerId(serverId);
    work.setStep(Step.Cancelled);
    update(work, sc);
}
Also used : HaWorkVO(com.cloud.ha.HaWorkVO) Date(java.util.Date)

Example 3 with HaWorkVO

use of com.cloud.ha.HaWorkVO in project cloudstack by apache.

the class HighAvailabilityDaoImpl method releaseWorkItems.

@Override
public int releaseWorkItems(long nodeId) {
    SearchCriteria<HaWorkVO> sc = ReleaseSearch.create();
    sc.setParameters("server", nodeId);
    sc.setParameters("step", Step.Done, Step.Cancelled, Step.Error);
    HaWorkVO vo = createForUpdate();
    vo.setDateTaken(null);
    vo.setServerId(null);
    return update(vo, sc);
}
Also used : HaWorkVO(com.cloud.ha.HaWorkVO)

Aggregations

HaWorkVO (com.cloud.ha.HaWorkVO)3 Date (java.util.Date)2 Filter (com.cloud.utils.db.Filter)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1