Search in sources :

Example 21 with UpdateBuilder

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

the class VMTemplateHostDaoImpl method updateState.

@Override
public boolean updateState(State currentState, Event event, State nextState, DataObjectInStore vo, Object data) {
    VMTemplateHostVO templateHost = (VMTemplateHostVO) vo;
    Long oldUpdated = templateHost.getUpdatedCount();
    Date oldUpdatedTime = templateHost.getUpdated();
    SearchCriteria<VMTemplateHostVO> sc = updateStateSearch.create();
    sc.setParameters("id", templateHost.getId());
    sc.setParameters("state", currentState);
    sc.setParameters("updatedCount", templateHost.getUpdatedCount());
    templateHost.incrUpdatedCount();
    UpdateBuilder builder = getUpdateBuilder(vo);
    builder.set(vo, "state", nextState);
    builder.set(vo, "updated", new Date());
    int rows = update((VMTemplateHostVO) vo, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        VMTemplateHostVO dbVol = findByIdIncludingRemoved(templateHost.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(templateHost.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(templateHost.getUpdatedCount()).append("; updatedTime=").append(templateHost.getUpdated());
            str.append(": stale Data={id=").append(templateHost.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=" + templateHost.getId() + ", as there is no such object exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : UpdateBuilder(com.cloud.utils.db.UpdateBuilder) VMTemplateHostVO(com.cloud.storage.VMTemplateHostVO) Date(java.util.Date)

Example 22 with UpdateBuilder

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

the class VMTemplatePoolDaoImpl method updateState.

@Override
public boolean updateState(State currentState, Event event, State nextState, DataObjectInStore vo, Object data) {
    VMTemplateStoragePoolVO templatePool = (VMTemplateStoragePoolVO) vo;
    Long oldUpdated = templatePool.getUpdatedCount();
    Date oldUpdatedTime = templatePool.getUpdated();
    SearchCriteria<VMTemplateStoragePoolVO> sc = updateStateSearch.create();
    sc.setParameters("id", templatePool.getId());
    sc.setParameters("state", currentState);
    sc.setParameters("updatedCount", templatePool.getUpdatedCount());
    templatePool.incrUpdatedCount();
    UpdateBuilder builder = getUpdateBuilder(vo);
    builder.set(vo, "state", nextState);
    builder.set(vo, "updated", new Date());
    int rows = update((VMTemplateStoragePoolVO) vo, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        VMTemplateStoragePoolVO dbVol = findByIdIncludingRemoved(templatePool.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(templatePool.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(templatePool.getUpdatedCount()).append("; updatedTime=").append(templatePool.getUpdated());
            str.append(": stale Data={id=").append(templatePool.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=" + templatePool.getId() + ", as there is no such object exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Example 23 with UpdateBuilder

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

the class VMInstanceDaoImpl method updateState.

@Override
public boolean updateState(State oldState, Event event, State newState, VirtualMachine vm, Object opaque) {
    if (newState == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("There's no way to transition from old state: " + oldState.toString() + " event: " + event.toString());
        }
        return false;
    }
    @SuppressWarnings("unchecked") Pair<Long, Long> hosts = (Pair<Long, Long>) opaque;
    Long newHostId = hosts.second();
    VMInstanceVO vmi = (VMInstanceVO) vm;
    Long oldHostId = vmi.getHostId();
    Long oldUpdated = vmi.getUpdated();
    Date oldUpdateDate = vmi.getUpdateTime();
    if (newState.equals(oldState) && newHostId != null && newHostId.equals(oldHostId)) {
        // state is same, don't need to update
        return true;
    }
    // lock the target row at beginning to avoid lock-promotion caused deadlock
    lockRow(vm.getId(), true);
    SearchCriteria<VMInstanceVO> sc = StateChangeSearch.create();
    sc.setParameters("id", vmi.getId());
    sc.setParameters("states", oldState);
    sc.setParameters("host", vmi.getHostId());
    sc.setParameters("update", vmi.getUpdated());
    vmi.incrUpdated();
    UpdateBuilder ub = getUpdateBuilder(vmi);
    ub.set(vmi, "state", newState);
    ub.set(vmi, "hostId", newHostId);
    ub.set(vmi, "podIdToDeployIn", vmi.getPodIdToDeployIn());
    ub.set(vmi, _updateTimeAttr, new Date());
    int result = update(vmi, sc);
    if (result == 0) {
        VMInstanceVO vo = findByIdIncludingRemoved(vm.getId());
        if (s_logger.isDebugEnabled()) {
            if (vo != null) {
                StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
                str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated()).append("; time=").append(vo.getUpdateTime());
                str.append("} New Data: {Host=").append(vm.getHostId()).append("; State=").append(vm.getState().toString()).append("; updated=").append(vmi.getUpdated()).append("; time=").append(vo.getUpdateTime());
                str.append("} Stale Data: {Host=").append(oldHostId).append("; State=").append(oldState).append("; updated=").append(oldUpdated).append("; time=").append(oldUpdateDate).append("}");
                s_logger.debug(str.toString());
            } else {
                s_logger.debug("Unable to update the vm id=" + vm.getId() + "; the vm either doesn't exist or already removed");
            }
        }
        if (vo != null && vo.getState() == newState) {
            // allow for concurrent update if target state has already been matched
            s_logger.debug("VM " + vo.getInstanceName() + " state has been already been updated to " + newState);
            return true;
        }
    }
    return result > 0;
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date) Pair(com.cloud.utils.Pair)

Example 24 with UpdateBuilder

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

the class EngineHostPodDaoImpl method updateState.

@Override
public boolean updateState(State currentState, Event event, State nextState, DataCenterResourceEntity podEntity, Object data) {
    EngineHostPodVO vo = findById(podEntity.getId());
    Date oldUpdatedTime = vo.getLastUpdated();
    SearchCriteria<EngineHostPodVO> sc = StateChangeSearch.create();
    sc.setParameters("id", vo.getId());
    sc.setParameters("state", currentState);
    UpdateBuilder builder = getUpdateBuilder(vo);
    builder.set(vo, "state", nextState);
    builder.set(vo, "lastUpdated", new Date());
    int rows = update(vo, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        EngineHostPodVO dbDC = findByIdIncludingRemoved(vo.getId());
        if (dbDC != null) {
            StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
            str.append(": DB Data={id=").append(dbDC.getId()).append("; state=").append(dbDC.getState()).append(";updatedTime=").append(dbDC.getLastUpdated());
            str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatedTime=").append(vo.getLastUpdated());
            str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatedTime=").append(oldUpdatedTime);
        } else {
            s_logger.debug("Unable to update dataCenter: id=" + vo.getId() + ", as there is no such dataCenter exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : EngineHostPodVO(org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostPodVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Example 25 with UpdateBuilder

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

the class EngineDataCenterDaoImpl method updateState.

@Override
public boolean updateState(State currentState, Event event, State nextState, DataCenterResourceEntity zoneEntity, Object data) {
    EngineDataCenterVO vo = findById(zoneEntity.getId());
    Date oldUpdatedTime = vo.getLastUpdated();
    SearchCriteria<EngineDataCenterVO> sc = StateChangeSearch.create();
    sc.setParameters("id", vo.getId());
    sc.setParameters("state", currentState);
    UpdateBuilder builder = getUpdateBuilder(vo);
    builder.set(vo, "state", nextState);
    builder.set(vo, "lastUpdated", new Date());
    int rows = update(vo, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        EngineDataCenterVO dbDC = findByIdIncludingRemoved(vo.getId());
        if (dbDC != null) {
            StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
            str.append(": DB Data={id=").append(dbDC.getId()).append("; state=").append(dbDC.getState()).append(";updatedTime=").append(dbDC.getLastUpdated());
            str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatedTime=").append(vo.getLastUpdated());
            str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatedTime=").append(oldUpdatedTime);
        } else {
            s_logger.debug("Unable to update dataCenter: id=" + vo.getId() + ", as there is no such dataCenter exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : UpdateBuilder(com.cloud.utils.db.UpdateBuilder) EngineDataCenterVO(org.apache.cloudstack.engine.datacenter.entity.api.db.EngineDataCenterVO) Date(java.util.Date)

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