Search in sources :

Example 11 with UpdateBuilder

use of com.cloud.utils.db.UpdateBuilder in project cloudstack by apache.

the class VolumeDataStoreDaoImpl method updateState.

@Override
public boolean updateState(State currentState, Event event, State nextState, DataObjectInStore vo, Object data) {
    VolumeDataStoreVO dataObj = (VolumeDataStoreVO) vo;
    Long oldUpdated = dataObj.getUpdatedCount();
    Date oldUpdatedTime = dataObj.getUpdated();
    SearchCriteria<VolumeDataStoreVO> sc = updateStateSearch.create();
    sc.setParameters("id", dataObj.getId());
    sc.setParameters("state", currentState);
    sc.setParameters("updatedCount", dataObj.getUpdatedCount());
    dataObj.incrUpdatedCount();
    UpdateBuilder builder = getUpdateBuilder(dataObj);
    builder.set(dataObj, "state", nextState);
    builder.set(dataObj, "updated", new Date());
    if (nextState == State.Destroyed) {
        builder.set(dataObj, "destroyed", true);
    }
    int rows = update(dataObj, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        VolumeDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId());
        if (dbVol != null) {
            StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
            str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=").append(dbVol.getUpdated());
            str.append(": New Data={id=").append(dataObj.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount()).append("; updatedTime=").append(dataObj.getUpdated());
            str.append(": stale Data={id=").append(dataObj.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated).append("; updatedTime=").append(oldUpdatedTime);
        } else {
            s_logger.debug("Unable to update objectIndatastore: id=" + dataObj.getId() + ", as there is no such object exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Example 12 with UpdateBuilder

use of com.cloud.utils.db.UpdateBuilder in project cloudstack by apache.

the class AsyncJobJoinMapDaoImpl method completeJoin.

@Override
public void completeJoin(long joinJobId, JobInfo.Status joinStatus, String joinResult, long completeMsid) {
    AsyncJobJoinMapVO record = createForUpdate();
    record.setJoinStatus(joinStatus);
    record.setJoinResult(joinResult);
    record.setCompleteMsid(completeMsid);
    record.setLastUpdated(DateUtil.currentGMTTime());
    UpdateBuilder ub = getUpdateBuilder(record);
    SearchCriteria<AsyncJobJoinMapVO> sc = CompleteJoinSearch.create();
    sc.setParameters("joinJobId", joinJobId);
    update(ub, sc, null);
}
Also used : AsyncJobJoinMapVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobJoinMapVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder)

Example 13 with UpdateBuilder

use of com.cloud.utils.db.UpdateBuilder in project cloudstack by apache.

the class HostDaoImpl method updateResourceState.

@Override
public boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo) {
    HostVO host = (HostVO) vo;
    SearchBuilder<HostVO> sb = createSearchBuilder();
    sb.and("resource_state", sb.entity().getResourceState(), SearchCriteria.Op.EQ);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.done();
    SearchCriteria<HostVO> sc = sb.create();
    sc.setParameters("resource_state", oldState);
    sc.setParameters("id", host.getId());
    UpdateBuilder ub = getUpdateBuilder(host);
    ub.set(host, _resourceStateAttr, newState);
    int result = update(ub, sc, null);
    assert result <= 1 : "How can this update " + result + " rows? ";
    if (state_logger.isDebugEnabled() && result == 0) {
        HostVO ho = findById(host.getId());
        assert ho != null : "How how how? : " + host.getId();
        StringBuilder str = new StringBuilder("Unable to update resource state: [");
        str.append("m = " + host.getId());
        str.append("; name = " + host.getName());
        str.append("; old state = " + oldState);
        str.append("; event = " + event);
        str.append("; new state = " + newState + "]");
        state_logger.debug(str.toString());
    } else {
        StringBuilder msg = new StringBuilder("Resource state update: [");
        msg.append("id = " + host.getId());
        msg.append("; name = " + host.getName());
        msg.append("; old state = " + oldState);
        msg.append("; event = " + event);
        msg.append("; new state = " + newState + "]");
        state_logger.debug(msg.toString());
    }
    return result > 0;
}
Also used : UpdateBuilder(com.cloud.utils.db.UpdateBuilder) HostVO(com.cloud.host.HostVO)

Example 14 with UpdateBuilder

use of com.cloud.utils.db.UpdateBuilder in project cloudstack by apache.

the class VMSnapshotDaoImpl method updateState.

@Override
public boolean updateState(State currentState, Event event, State nextState, VMSnapshot vo, Object data) {
    Long oldUpdated = vo.getUpdatedCount();
    Date oldUpdatedTime = vo.getUpdated();
    SearchCriteria<VMSnapshotVO> sc = AllFieldsSearch.create();
    sc.setParameters("id", vo.getId());
    sc.setParameters("state", currentState);
    sc.setParameters("updatedCount", vo.getUpdatedCount());
    vo.incrUpdatedCount();
    UpdateBuilder builder = getUpdateBuilder(vo);
    builder.set(vo, "state", nextState);
    builder.set(vo, "updated", new Date());
    int rows = update((VMSnapshotVO) vo, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        VMSnapshotVO dbVol = findByIdIncludingRemoved(vo.getId());
        if (dbVol != null) {
            StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
            str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=").append(dbVol.getUpdated());
            str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(vo.getUpdatedCount()).append("; updatedTime=").append(vo.getUpdated());
            str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated).append("; updatedTime=").append(oldUpdatedTime);
        } else {
            s_logger.debug("Unable to update VM snapshot: id=" + vo.getId() + ", as there is no such snapshot exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Example 15 with UpdateBuilder

use of com.cloud.utils.db.UpdateBuilder in project cloudstack by apache.

the class DomainRouterDaoImpl method remove.

@Override
public boolean remove(final Long id) {
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    final DomainRouterVO router = createForUpdate();
    router.setPublicIpAddress(null);
    final UpdateBuilder ub = getUpdateBuilder(router);
    ub.set(router, "state", State.Destroyed);
    update(id, ub, router);
    final boolean result = super.remove(id);
    txn.commit();
    return result;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

UpdateBuilder (com.cloud.utils.db.UpdateBuilder)27 Date (java.util.Date)17 HostVO (com.cloud.host.HostVO)3 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)3 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)2 SnapshotVO (com.cloud.storage.SnapshotVO)1 VMTemplateHostVO (com.cloud.storage.VMTemplateHostVO)1 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 VolumeHostVO (com.cloud.storage.VolumeHostVO)1 VolumeVO (com.cloud.storage.VolumeVO)1 Pair (com.cloud.utils.Pair)1 ConsoleProxyVO (com.cloud.vm.ConsoleProxyVO)1 DomainRouterVO (com.cloud.vm.DomainRouterVO)1 SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)1 EngineClusterVO (org.apache.cloudstack.engine.datacenter.entity.api.db.EngineClusterVO)1 EngineDataCenterVO (org.apache.cloudstack.engine.datacenter.entity.api.db.EngineDataCenterVO)1 EngineHostPodVO (org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostPodVO)1