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;
}
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);
}
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;
}
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;
}
Aggregations