@Override public long getObjectId() { return this.getTemplateId(); }
@Override public boolean equals(Object obj) { if (obj instanceof VMTemplateHostVO) { VMTemplateHostVO other = (VMTemplateHostVO)obj; return (this.templateId == other.getTemplateId() && this.hostId == other.getHostId()); } return false; }
@Override public void update(VMTemplateHostVO instance) { TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; try { Date now = new Date(); String sql = UPDATE_TEMPLATE_HOST_REF; pstmt = txn.prepareAutoCloseStatement(sql); pstmt.setString(1, instance.getDownloadState().toString()); pstmt.setInt(2, instance.getDownloadPercent()); pstmt.setString(3, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), now)); pstmt.setString(4, instance.getErrorString()); pstmt.setString(5, instance.getLocalDownloadPath()); pstmt.setString(6, instance.getJobId()); pstmt.setLong(7, instance.getHostId()); pstmt.setLong(8, instance.getTemplateId()); pstmt.executeUpdate(); } catch (Exception e) { s_logger.warn("Exception: ", e); } }
@Override public boolean templateIsDeleteable(VMTemplateHostVO templateHostRef) { VMTemplateVO template = _tmpltDao.findByIdIncludingRemoved(templateHostRef.getTemplateId()); long templateId = template.getId(); HostVO secondaryStorageHost = _hostDao.findById(templateHostRef.getHostId());
TemplateSearch.and("template_id", TemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ); TemplateSearch.and("destroyed", TemplateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); TemplateSearch.done(); HostTemplateSearch.and("template_id", HostTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ); HostTemplateSearch.and("destroyed", HostTemplateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); HostTemplateSearch.done(); TemplateStatusSearch.and("template_id", TemplateStatusSearch.entity().getTemplateId(), SearchCriteria.Op.EQ); TemplateStatusSearch.and("download_state", TemplateStatusSearch.entity().getDownloadState(), SearchCriteria.Op.EQ); TemplateStatusSearch.and("destroyed", TemplateStatusSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); TemplateStatesSearch.and("template_id", TemplateStatesSearch.entity().getTemplateId(), SearchCriteria.Op.EQ); TemplateStatesSearch.and("states", TemplateStatesSearch.entity().getDownloadState(), SearchCriteria.Op.IN); TemplateStatesSearch.and("destroyed", TemplateStatesSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); HostTemplateStateSearch.and("template_id", HostTemplateStateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ); HostTemplateStateSearch.and("host_id", HostTemplateStateSearch.entity().getHostId(), SearchCriteria.Op.EQ); HostTemplateStateSearch.and("states", HostTemplateStateSearch.entity().getDownloadState(), SearchCriteria.Op.IN);
@Override public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { boolean result = super.configure(name, params); ZoneTemplateSearch = createSearchBuilder(); ZoneTemplateSearch.and("template_id", ZoneTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ); ZoneTemplateSearch.and("state", ZoneTemplateSearch.entity().getDownloadState(), SearchCriteria.Op.EQ); SearchBuilder<HostVO> hostSearch = _hostDao.createSearchBuilder(); hostSearch.and("zone_id", hostSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); ZoneTemplateSearch.join("tmplHost", hostSearch, hostSearch.entity().getId(), ZoneTemplateSearch.entity().getHostId(), JoinBuilder.JoinType.INNER); ZoneTemplateSearch.done(); LocalSecondaryStorageSearch = createSearchBuilder(); LocalSecondaryStorageSearch.and("template_id", LocalSecondaryStorageSearch.entity().getTemplateId(), SearchCriteria.Op.EQ); LocalSecondaryStorageSearch.and("state", LocalSecondaryStorageSearch.entity().getDownloadState(), SearchCriteria.Op.EQ); SearchBuilder<HostVO> localSecondaryHost = _hostDao.createSearchBuilder(); localSecondaryHost.and("private_ip_address", localSecondaryHost.entity().getPrivateIpAddress(), SearchCriteria.Op.EQ); localSecondaryHost.and("state", localSecondaryHost.entity().getStatus(), SearchCriteria.Op.EQ); localSecondaryHost.and("data_center_id", localSecondaryHost.entity().getDataCenterId(), SearchCriteria.Op.EQ); localSecondaryHost.and("type", localSecondaryHost.entity().getType(), SearchCriteria.Op.EQ); LocalSecondaryStorageSearch.join("host", localSecondaryHost, localSecondaryHost.entity().getId(), LocalSecondaryStorageSearch.entity().getHostId(), JoinBuilder.JoinType.INNER); LocalSecondaryStorageSearch.done(); return result; }