Search in sources :

Example 1 with VMTemplateHostVO

use of com.cloud.storage.VMTemplateHostVO in project cloudstack by apache.

the class VMTemplateHostDaoImpl method listByTemplateStatus.

@Override
public List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateHostVO.Status downloadState) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    List<VMTemplateHostVO> result = new ArrayList<VMTemplateHostVO>();
    String sql = DOWNLOADS_STATE_DC_POD;
    try (PreparedStatement pstmt = txn.prepareStatement(sql)) {
        pstmt.setLong(1, datacenterId);
        pstmt.setLong(2, podId);
        pstmt.setLong(3, templateId);
        pstmt.setString(4, downloadState.toString());
        try (ResultSet rs = pstmt.executeQuery()) {
            while (rs.next()) {
                // result.add(toEntityBean(rs, false)); TODO: this is buggy in
                // GenericDaoBase for hand constructed queries
                // ID column
                long id = rs.getLong(1);
                result.add(findById(id));
            }
        } catch (SQLException e) {
            s_logger.warn("listByTemplateStatus:Exception: " + e.getMessage(), e);
        }
    } catch (Exception e) {
        s_logger.warn("listByTemplateStatus:Exception: " + e.getMessage(), e);
    }
    return result;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) VMTemplateHostVO(com.cloud.storage.VMTemplateHostVO) ConfigurationException(javax.naming.ConfigurationException) SQLException(java.sql.SQLException)

Example 2 with VMTemplateHostVO

use of com.cloud.storage.VMTemplateHostVO in project cloudstack by apache.

the class VMTemplateHostDaoImpl method findLocalSecondaryStorageByHostTemplate.

// Based on computing node host id, and template id, find out the
// corresponding template_host_ref, assuming local secondary storage and
// computing node is in the same zone, and private ip
@Override
public VMTemplateHostVO findLocalSecondaryStorageByHostTemplate(long hostId, long templateId) {
    HostVO computingHost = _hostDao.findById(hostId);
    SearchCriteria<VMTemplateHostVO> sc = LocalSecondaryStorageSearch.create();
    sc.setJoinParameters("host", "private_ip_address", computingHost.getPrivateIpAddress());
    sc.setJoinParameters("host", "state", com.cloud.host.Status.Up);
    sc.setJoinParameters("host", "data_center_id", computingHost.getDataCenterId());
    sc.setJoinParameters("host", "type", Host.Type.LocalSecondaryStorage);
    sc.setParameters("template_id", templateId);
    sc.setParameters("state", VMTemplateHostVO.Status.DOWNLOADED);
    sc.setParameters("destroyed", false);
    return findOneBy(sc);
}
Also used : VMTemplateHostVO(com.cloud.storage.VMTemplateHostVO) VMTemplateHostVO(com.cloud.storage.VMTemplateHostVO) HostVO(com.cloud.host.HostVO)

Example 3 with VMTemplateHostVO

use of com.cloud.storage.VMTemplateHostVO 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 4 with VMTemplateHostVO

use of com.cloud.storage.VMTemplateHostVO in project cloudstack by apache.

the class TemplateManagerImpl method templateIsDeleteable.

@Override
public boolean templateIsDeleteable(VMTemplateHostVO templateHostRef) {
    VMTemplateVO template = _tmpltDao.findByIdIncludingRemoved(templateHostRef.getTemplateId());
    long templateId = template.getId();
    HostVO secondaryStorageHost = _hostDao.findById(templateHostRef.getHostId());
    long zoneId = secondaryStorageHost.getDataCenterId();
    DataCenterVO zone = _dcDao.findById(zoneId);
    // Check if there are VMs running in the template host ref's zone that
    // use the template
    List<VMInstanceVO> nonExpungedVms = _vmInstanceDao.listNonExpungedByZoneAndTemplate(zoneId, templateId);
    if (!nonExpungedVms.isEmpty()) {
        s_logger.debug("Template " + template.getName() + " in zone " + zone.getName() + " is not deleteable because there are non-expunged VMs deployed from this template.");
        return false;
    }
    List<UserVmVO> userVmUsingIso = _userVmDao.listByIsoId(templateId);
    // check if there is any VM using this ISO.
    if (!userVmUsingIso.isEmpty()) {
        s_logger.debug("ISO " + template.getName() + " in zone " + zone.getName() + " is not deleteable because it is attached to " + userVmUsingIso.size() + " VMs");
        return false;
    }
    // Check if there are any snapshots for the template in the template
    // host ref's zone
    List<VolumeVO> volumes = _volumeDao.findByTemplateAndZone(templateId, zoneId);
    for (VolumeVO volume : volumes) {
        List<SnapshotVO> snapshots = _snapshotDao.listByVolumeIdVersion(volume.getId(), "2.1");
        if (!snapshots.isEmpty()) {
            s_logger.debug("Template " + template.getName() + " in zone " + zone.getName() + " is not deleteable because there are 2.1 snapshots using this template.");
            return false;
        }
    }
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) UserVmVO(com.cloud.vm.UserVmVO) SnapshotVO(com.cloud.storage.SnapshotVO) VolumeVO(com.cloud.storage.VolumeVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) VMTemplateHostVO(com.cloud.storage.VMTemplateHostVO) HostVO(com.cloud.host.HostVO)

Aggregations

VMTemplateHostVO (com.cloud.storage.VMTemplateHostVO)4 HostVO (com.cloud.host.HostVO)2 DataCenterVO (com.cloud.dc.DataCenterVO)1 SnapshotVO (com.cloud.storage.SnapshotVO)1 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 VolumeVO (com.cloud.storage.VolumeVO)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 UpdateBuilder (com.cloud.utils.db.UpdateBuilder)1 UserVmVO (com.cloud.vm.UserVmVO)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)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 ConfigurationException (javax.naming.ConfigurationException)1