Search in sources :

Example 1 with UpdateBuilder

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

the class EngineHostDaoImpl method updateState.

@Override
public boolean updateState(State currentState, DataCenterResourceEntity.State.Event event, State nextState, DataCenterResourceEntity hostEntity, Object data) {
    EngineHostVO vo = findById(hostEntity.getId());
    Date oldUpdatedTime = vo.getLastUpdated();
    SearchCriteria<EngineHostVO> sc = StateChangeSearch.create();
    sc.setParameters("id", hostEntity.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()) {
        EngineHostVO dbHost = findByIdIncludingRemoved(vo.getId());
        if (dbHost != null) {
            StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
            str.append(": DB Data={id=").append(dbHost.getId()).append("; state=").append(dbHost.getState()).append(";updatedTime=").append(dbHost.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 : EngineHostVO(org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Example 2 with UpdateBuilder

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

the class NetworkOpDaoImpl method changeActiveNicsBy.

@Override
public void changeActiveNicsBy(long networkId, int count) {
    SearchCriteria<NetworkOpVO> sc = AllFieldsSearch.create();
    sc.setParameters("network", networkId);
    NetworkOpVO vo = createForUpdate();
    UpdateBuilder builder = getUpdateBuilder(vo);
    builder.incr(_activeNicsAttribute, count);
    update(builder, sc, null);
}
Also used : UpdateBuilder(com.cloud.utils.db.UpdateBuilder)

Example 3 with UpdateBuilder

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

the class VMTemplateDaoImpl method updateState.

/*
     * @Override public Set<Pair<Long, Long>> searchS3Templates(final String
     * name, final String keyword, final TemplateFilter templateFilter, final
     * boolean isIso, final List<HypervisorType> hypers, final Boolean bootable,
     * final DomainVO domain, final Long pageSize, final Long startIndex, final
     * Long zoneId, final HypervisorType hyperType, final boolean onlyReady,
     * final boolean showDomr, final List<Account> permittedAccounts, final
     * Account caller, final Map<String, String> tags) {
     *
     * final String permittedAccountsStr = join(",", permittedAccounts);
     *
     * final TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start();
     *
     * Set<Pair<Long, Long>> templateZonePairList = new HashSet<Pair<Long,
     * Long>>(); PreparedStatement pstmt = null; ResultSet rs = null; try {
     *
     * final StringBuilder joinClause = new StringBuilder(); final StringBuilder
     * whereClause = new StringBuilder(" WHERE t.removed IS NULL");
     *
     * if (isIso) { whereClause.append(" AND t.format = 'ISO'"); if
     * (!hyperType.equals(HypervisorType.None)) { joinClause.append(
     * " INNER JOIN guest_os guestOS on (guestOS.id = t.guest_os_id) INNER JOIN guest_os_hypervisor goh on ( goh.guest_os_id = guestOS.id) "
     * ); whereClause.append(" AND goh.hypervisor_type = '");
     * whereClause.append(hyperType); whereClause.append("'"); } } else {
     * whereClause.append(" AND t.format <> 'ISO'"); if (hypers.isEmpty()) {
     * return templateZonePairList; } else { final StringBuilder relatedHypers =
     * new StringBuilder(); for (HypervisorType hyper : hypers) {
     * relatedHypers.append("'"); relatedHypers.append(hyper.toString());
     * relatedHypers.append("'"); relatedHypers.append(","); }
     * relatedHypers.setLength(relatedHypers.length() - 1);
     * whereClause.append(" AND t.hypervisor_type IN (");
     * whereClause.append(relatedHypers); whereClause.append(")"); } }
     *
     * joinClause.append(
     * " INNER JOIN  template_s3_ref tsr on (t.id = tsr.template_id)");
     *
     * whereClause.append("AND t.name LIKE \"%"); whereClause.append(keyword ==
     * null ? keyword : name); whereClause.append("%\"");
     *
     * if (bootable != null) { whereClause.append(" AND t.bootable = ");
     * whereClause.append(bootable); }
     *
     * if (!showDomr) { whereClause.append(" AND t.type != '");
     * whereClause.append(Storage.TemplateType.SYSTEM); whereClause.append("'");
     * }
     *
     * if (templateFilter == TemplateFilter.featured) {
     * whereClause.append(" AND t.public = 1 AND t.featured = 1"); } else if
     * ((templateFilter == TemplateFilter.self || templateFilter ==
     * TemplateFilter.selfexecutable) && caller.getType() !=
     * Account.ACCOUNT_TYPE_ADMIN) { if (caller.getType() ==
     * Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() ==
     * Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { joinClause.append(
     * " INNER JOIN account a on (t.account_id = a.id) INNER JOIN domain d on (a.domain_id = d.id)"
     * ); whereClause.append("  AND d.path LIKE '");
     * whereClause.append(domain.getPath()); whereClause.append("%'"); } else {
     * whereClause.append(" AND t.account_id IN (");
     * whereClause.append(permittedAccountsStr); whereClause.append(")"); } }
     * else if (templateFilter == TemplateFilter.sharedexecutable &&
     * caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { if (caller.getType() ==
     * Account.ACCOUNT_TYPE_NORMAL) { joinClause.append(
     * " LEFT JOIN launch_permission lp ON t.id = lp.template_id WHERE (t.account_id IN ("
     * ); joinClause.append(permittedAccountsStr);
     * joinClause.append(") OR lp.account_id IN (");
     * joinClause.append(permittedAccountsStr); joinClause.append("))"); } else
     * { joinClause.append(" INNER JOIN account a on (t.account_id = a.id) "); }
     * } else if (templateFilter == TemplateFilter.executable &&
     * !permittedAccounts.isEmpty()) {
     * whereClause.append(" AND (t.public = 1 OR t.account_id IN (");
     * whereClause.append(permittedAccountsStr); whereClause.append("))"); }
     * else if (templateFilter == TemplateFilter.community) {
     * whereClause.append(" AND t.public = 1 AND t.featured = 0"); } else if
     * (templateFilter == TemplateFilter.all && caller.getType() ==
     * Account.ACCOUNT_TYPE_ADMIN) { } else if (caller.getType() !=
     * Account.ACCOUNT_TYPE_ADMIN) { return templateZonePairList; }
     *
     * final StringBuilder sql = new StringBuilder(SELECT_TEMPLATE_S3_REF);
     * sql.append(joinClause); sql.append(whereClause);
     * sql.append(getOrderByLimit(pageSize, startIndex));
     *
     * pstmt = txn.prepareStatement(sql.toString()); rs = pstmt.executeQuery();
     * while (rs.next()) { final Pair<Long, Long> templateZonePair = new
     * Pair<Long, Long>( rs.getLong(1), -1L);
     * templateZonePairList.add(templateZonePair); } txn.commit(); } catch
     * (Exception e) { s_logger.warn("Error listing S3 templates", e); if (txn
     * != null) { txn.rollback(); } } finally { closeResources(pstmt, rs); if
     * (txn != null) { txn.close(); } }
     *
     * return templateZonePairList; }
     */
@Override
public boolean updateState(com.cloud.template.VirtualMachineTemplate.State currentState, com.cloud.template.VirtualMachineTemplate.Event event, com.cloud.template.VirtualMachineTemplate.State nextState, VirtualMachineTemplate vo, Object data) {
    Long oldUpdated = vo.getUpdatedCount();
    Date oldUpdatedTime = vo.getUpdated();
    SearchCriteria<VMTemplateVO> 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((VMTemplateVO) vo, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        VMTemplateVO dbTemplate = findByIdIncludingRemoved(vo.getId());
        if (dbTemplate != null) {
            StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
            str.append(": DB Data={id=").append(dbTemplate.getId()).append("; state=").append(dbTemplate.getState()).append("; updatecount=").append(dbTemplate.getUpdatedCount()).append(";updatedTime=").append(dbTemplate.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 template: id=" + vo.getId() + ", as no such template exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : VMTemplateVO(com.cloud.storage.VMTemplateVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Example 4 with UpdateBuilder

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

the class VolumeDaoImpl method updateState.

@Override
public boolean updateState(com.cloud.storage.Volume.State currentState, Event event, com.cloud.storage.Volume.State nextState, Volume vo, Object data) {
    Long oldUpdated = vo.getUpdatedCount();
    Date oldUpdatedTime = vo.getUpdated();
    SearchCriteria<VolumeVO> 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((VolumeVO) vo, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        VolumeVO 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 volume: id=" + vo.getId() + ", as there is no such volume exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Example 5 with UpdateBuilder

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

the class SnapshotDaoImpl method updateVolumeIds.

@Override
public void updateVolumeIds(long oldVolId, long newVolId) {
    SearchCriteria<SnapshotVO> sc = VolumeIdSearch.create();
    sc.setParameters("volumeId", oldVolId);
    SnapshotVO snapshot = createForUpdate();
    snapshot.setVolumeId(newVolId);
    UpdateBuilder ub = getUpdateBuilder(snapshot);
    update(ub, sc, null);
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder)

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