db: Cleanup obsolete tables (#5002)

* db: Cleanup unused tables

* Removing volume_host_ref references

* Removing template_host_ref references

* fix space issue

* Fix fk constraint

* Removing certificate table

* Revert "Removing certificate table"

This reverts commit fa24e6483f339903ce895e26e3409a1751620a3f.

* Addressing comments
This commit is contained in:
davidjumani 2021-06-25 01:20:31 +05:30 committed by GitHub
parent 1a7bfa98d8
commit 29109b4332
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 138 additions and 2710 deletions

View File

@ -30,7 +30,6 @@ import com.cloud.dc.DataCenterVO;
import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.StorageUnavailableException; import com.cloud.exception.StorageUnavailableException;
import com.cloud.storage.StoragePool; import com.cloud.storage.StoragePool;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStoragePoolVO; import com.cloud.storage.VMTemplateStoragePoolVO;
import com.cloud.storage.VMTemplateVO; import com.cloud.storage.VMTemplateVO;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
@ -102,8 +101,6 @@ public interface TemplateManager {
*/ */
void evictTemplateFromStoragePool(VMTemplateStoragePoolVO templatePoolVO); void evictTemplateFromStoragePool(VMTemplateStoragePoolVO templatePoolVO);
boolean templateIsDeleteable(VMTemplateHostVO templateHostRef);
boolean templateIsDeleteable(long templateId); boolean templateIsDeleteable(long templateId);
Pair<String, String> getAbsoluteIsoPath(long templateId, long dataCenterId); Pair<String, String> getAbsoluteIsoPath(long templateId, long dataCenterId);

View File

@ -1,334 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.storage;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
import com.cloud.utils.db.GenericDaoBase;
/**
* Join table for storage hosts and templates
*
*/
@Entity
@Table(name = "template_host_ref")
public class VMTemplateHostVO implements VMTemplateStorageResourceAssoc, DataObjectInStore {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@Column(name = "host_id")
private long hostId;
@Column(name = "template_id")
private long templateId;
@Column(name = GenericDaoBase.CREATED_COLUMN)
private Date created = null;
@Column(name = "last_updated")
@Temporal(value = TemporalType.TIMESTAMP)
private Date lastUpdated = null;
@Column(name = "download_pct")
private int downloadPercent;
@Column(name = "size")
private long size;
@Column(name = "physical_size")
private long physicalSize;
@Column(name = "download_state")
@Enumerated(EnumType.STRING)
private Status downloadState;
@Column(name = "local_path")
private String localDownloadPath;
@Column(name = "error_str")
private String errorString;
@Column(name = "job_id")
private String jobId;
@Column(name = "install_path")
private String installPath;
@Column(name = "url", length = 2048)
private String downloadUrl;
@Column(name = "is_copy")
private boolean isCopy = false;
@Column(name = "destroyed")
boolean destroyed = false;
@Column(name = "update_count", updatable = true, nullable = false)
protected long updatedCount;
@Column(name = "updated")
@Temporal(value = TemporalType.TIMESTAMP)
Date updated;
@Column(name = "state")
@Enumerated(EnumType.STRING)
ObjectInDataStoreStateMachine.State state;
@Override
public String getInstallPath() {
return installPath;
}
public long getHostId() {
return hostId;
}
public void setHostId(long hostId) {
this.hostId = hostId;
}
@Override
public long getTemplateId() {
return templateId;
}
@Override
public void setTemplateId(long templateId) {
this.templateId = templateId;
}
@Override
public int getDownloadPercent() {
return downloadPercent;
}
@Override
public void setDownloadPercent(int downloadPercent) {
this.downloadPercent = downloadPercent;
}
@Override
public void setDownloadState(Status downloadState) {
this.downloadState = downloadState;
}
@Override
public long getId() {
return id;
}
@Override
public Date getCreated() {
return created;
}
@Override
public Date getLastUpdated() {
return lastUpdated;
}
@Override
public void setLastUpdated(Date date) {
lastUpdated = date;
}
@Override
public void setInstallPath(String installPath) {
this.installPath = installPath;
}
@Override
public Status getDownloadState() {
return downloadState;
}
public VMTemplateHostVO(long hostId, long templateId) {
super();
this.hostId = hostId;
this.templateId = templateId;
this.state = ObjectInDataStoreStateMachine.State.Allocated;
}
public VMTemplateHostVO(long hostId, long templateId, Date lastUpdated, int downloadPercent, Status downloadState, String localDownloadPath, String errorString,
String jobId, String installPath, String downloadUrl) {
super();
this.hostId = hostId;
this.templateId = templateId;
this.lastUpdated = lastUpdated;
this.downloadPercent = downloadPercent;
this.downloadState = downloadState;
this.localDownloadPath = localDownloadPath;
this.errorString = errorString;
this.jobId = jobId;
this.installPath = installPath;
this.setDownloadUrl(downloadUrl);
}
protected VMTemplateHostVO() {
}
@Override
public void setLocalDownloadPath(String localPath) {
this.localDownloadPath = localPath;
}
@Override
public String getLocalDownloadPath() {
return localDownloadPath;
}
@Override
public void setErrorString(String errorString) {
this.errorString = errorString;
}
@Override
public String getErrorString() {
return errorString;
}
@Override
public void setJobId(String jobId) {
this.jobId = jobId;
}
@Override
public String getJobId() {
return jobId;
}
@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 int hashCode() {
Long tid = new Long(templateId);
Long hid = new Long(hostId);
return tid.hashCode() + hid.hashCode();
}
public void setSize(long size) {
this.size = size;
}
public long getSize() {
return size;
}
public void setPhysicalSize(long physicalSize) {
this.physicalSize = physicalSize;
}
public long getPhysicalSize() {
return physicalSize;
}
public void setDestroyed(boolean destroyed) {
this.destroyed = destroyed;
}
public boolean getDestroyed() {
return destroyed;
}
public void setDownloadUrl(String downloadUrl) {
this.downloadUrl = downloadUrl;
}
public String getDownloadUrl() {
return downloadUrl;
}
public void setCopy(boolean isCopy) {
this.isCopy = isCopy;
}
public boolean isCopy() {
return isCopy;
}
@Override
public long getTemplateSize() {
return -1;
}
@Override
public String toString() {
return new StringBuilder("TmplHost[").append(id).append("-").append(templateId).append("-").append(hostId).append(installPath).append("]").toString();
}
@Override
public ObjectInDataStoreStateMachine.State getState() {
// TODO Auto-generated method stub
return this.state;
}
public long getUpdatedCount() {
return this.updatedCount;
}
public void incrUpdatedCount() {
this.updatedCount++;
}
public void decrUpdatedCount() {
this.updatedCount--;
}
public Date getUpdated() {
return updated;
}
@Override
public long getObjectId() {
return this.getTemplateId();
}
@Override
public long getDataStoreId() {
return this.getHostId();
}
@Override
public State getObjectInStoreState() {
return this.state;
}
}

View File

@ -1,346 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.storage;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.cloudstack.api.InternalIdentity;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.utils.db.GenericDaoBase;
/**
* Join table for storage hosts and volumes
*
*/
@Entity
@Table(name = "volume_host_ref")
public class VolumeHostVO implements InternalIdentity, DataObjectInStore {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@Column(name = "host_id")
private long hostId;
@Column(name = "volume_id")
private long volumeId;
@Column(name = "zone_id")
private long zoneId;
@Column(name = GenericDaoBase.CREATED_COLUMN)
private Date created = null;
@Column(name = "last_updated")
@Temporal(value = TemporalType.TIMESTAMP)
private Date lastUpdated = null;
@Column(name = "download_pct")
private int downloadPercent;
@Column(name = "size")
private long size;
@Column(name = "physical_size")
private long physicalSize;
@Column(name = "download_state")
@Enumerated(EnumType.STRING)
private Status downloadState;
@Column(name = "checksum")
private String checksum;
@Column(name = "local_path")
private String localDownloadPath;
@Column(name = "error_str")
private String errorString;
@Column(name = "job_id")
private String jobId;
@Column(name = "install_path")
private String installPath;
@Column(name = "url", length = 2048)
private String downloadUrl;
@Column(name = "format")
private Storage.ImageFormat format;
@Column(name = "destroyed")
boolean destroyed = false;
@Column(name = "update_count", updatable = true, nullable = false)
protected long updatedCount;
@Column(name = "updated")
@Temporal(value = TemporalType.TIMESTAMP)
Date updated;
@Column(name = "state")
@Enumerated(EnumType.STRING)
ObjectInDataStoreStateMachine.State state;
@Override
public String getInstallPath() {
return installPath;
}
public long getHostId() {
return hostId;
}
public void setHostId(long hostId) {
this.hostId = hostId;
}
public long getVolumeId() {
return volumeId;
}
public void setVolumeId(long volumeId) {
this.volumeId = volumeId;
}
public long getZoneId() {
return zoneId;
}
public void setZoneId(long zoneId) {
this.zoneId = zoneId;
}
public int getDownloadPercent() {
return downloadPercent;
}
public void setDownloadPercent(int downloadPercent) {
this.downloadPercent = downloadPercent;
}
public void setDownloadState(Status downloadState) {
this.downloadState = downloadState;
}
@Override
public long getId() {
return id;
}
public Date getCreated() {
return created;
}
public Date getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(Date date) {
lastUpdated = date;
}
@Override
public void setInstallPath(String installPath) {
this.installPath = installPath;
}
public Status getDownloadState() {
return downloadState;
}
public String getChecksum() {
return checksum;
}
public void setChecksum(String checksum) {
this.checksum = checksum;
}
public VolumeHostVO(long hostId, long volumeId) {
super();
this.hostId = hostId;
this.volumeId = volumeId;
this.state = ObjectInDataStoreStateMachine.State.Allocated;
}
public VolumeHostVO(long hostId, long volumeId, long zoneId, Date lastUpdated, int downloadPercent, Status downloadState, String localDownloadPath,
String errorString, String jobId, String installPath, String downloadUrl, String checksum, ImageFormat format) {
// super();
this.hostId = hostId;
this.volumeId = volumeId;
this.zoneId = zoneId;
this.lastUpdated = lastUpdated;
this.downloadPercent = downloadPercent;
this.downloadState = downloadState;
this.localDownloadPath = localDownloadPath;
this.errorString = errorString;
this.jobId = jobId;
this.installPath = installPath;
this.setDownloadUrl(downloadUrl);
this.checksum = checksum;
this.format = format;
}
protected VolumeHostVO() {
}
public void setLocalDownloadPath(String localPath) {
this.localDownloadPath = localPath;
}
public String getLocalDownloadPath() {
return localDownloadPath;
}
public void setErrorString(String errorString) {
this.errorString = errorString;
}
public String getErrorString() {
return errorString;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
public String getJobId() {
return jobId;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof VolumeHostVO) {
VolumeHostVO other = (VolumeHostVO)obj;
return (this.volumeId == other.getVolumeId() && this.hostId == other.getHostId());
}
return false;
}
@Override
public int hashCode() {
Long tid = new Long(volumeId);
Long hid = new Long(hostId);
return tid.hashCode() + hid.hashCode();
}
public void setSize(long size) {
this.size = size;
}
public long getSize() {
return size;
}
public void setPhysicalSize(long physicalSize) {
this.physicalSize = physicalSize;
}
public long getPhysicalSize() {
return physicalSize;
}
public void setDestroyed(boolean destroyed) {
this.destroyed = destroyed;
}
public boolean getDestroyed() {
return destroyed;
}
public void setDownloadUrl(String downloadUrl) {
this.downloadUrl = downloadUrl;
}
public String getDownloadUrl() {
return downloadUrl;
}
public Storage.ImageFormat getFormat() {
return format;
}
public void setFormat(Storage.ImageFormat format) {
this.format = format;
}
public long getVolumeSize() {
return -1;
}
@Override
public String toString() {
return new StringBuilder("VolumeHost[").append(id).append("-").append(volumeId).append("-").append(hostId).append(installPath).append("]").toString();
}
public long getUpdatedCount() {
return this.updatedCount;
}
public void incrUpdatedCount() {
this.updatedCount++;
}
public void decrUpdatedCount() {
this.updatedCount--;
}
public Date getUpdated() {
return updated;
}
@Override
public ObjectInDataStoreStateMachine.State getState() {
// TODO Auto-generated method stub
return this.state;
}
@Override
public long getObjectId() {
return this.getVolumeId();
}
@Override
public long getDataStoreId() {
return this.getHostId();
}
@Override
public State getObjectInStoreState() {
return this.state;
}
}

View File

@ -72,14 +72,10 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
VMTemplateVO findRoutingTemplate(HypervisorType type, String templateName); VMTemplateVO findRoutingTemplate(HypervisorType type, String templateName);
List<Long> listPrivateTemplatesByHost(Long hostId);
public Long countTemplatesForAccount(long accountId); public Long countTemplatesForAccount(long accountId);
public List<VMTemplateVO> listUnRemovedTemplatesByStates(VirtualMachineTemplate.State ...states); public List<VMTemplateVO> listUnRemovedTemplatesByStates(VirtualMachineTemplate.State ...states);
List<VMTemplateVO> findTemplatesToSyncToS3();
void loadDetails(VMTemplateVO tmpl); void loadDetails(VMTemplateVO tmpl);
void saveDetails(VMTemplateVO tmpl); void saveDetails(VMTemplateVO tmpl);

View File

@ -16,9 +16,6 @@
// under the License. // under the License.
package com.cloud.storage.dao; package com.cloud.storage.dao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -79,13 +76,6 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
@Inject @Inject
TemplateDataStoreDao _templateDataStoreDao; TemplateDataStoreDao _templateDataStoreDao;
private static final String SELECT_S3_CANDIDATE_TEMPLATES = "SELECT t.id, t.unique_name, t.name, t.public, t.featured, "
+ "t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, t.checksum, t.display_text, "
+ "t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type "
+ "FROM vm_template t JOIN template_host_ref r ON t.id=r.template_id JOIN host h ON h.id=r.host_id "
+ "WHERE t.hypervisor_type IN (SELECT hypervisor_type FROM host) AND r.download_state = 'DOWNLOADED' AND "
+ "r.template_id NOT IN (SELECT template_id FROM template_s3_ref) AND r.destroyed = 0 AND t.type <> 'PERHOST'";
protected SearchBuilder<VMTemplateVO> TemplateNameSearch; protected SearchBuilder<VMTemplateVO> TemplateNameSearch;
protected SearchBuilder<VMTemplateVO> UniqueNameSearch; protected SearchBuilder<VMTemplateVO> UniqueNameSearch;
protected SearchBuilder<VMTemplateVO> tmpltTypeSearch; protected SearchBuilder<VMTemplateVO> tmpltTypeSearch;
@ -231,31 +221,6 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
return listBy(sc, filter); return listBy(sc, filter);
} }
@Override
public List<Long> listPrivateTemplatesByHost(Long hostId) {
String sql =
"select * from template_host_ref as thr INNER JOIN vm_template as t ON t.id=thr.template_id "
+ "where thr.host_id=? and t.public=0 and t.featured=0 and t.type='USER' and t.state='Active'";
List<Long> l = new ArrayList<Long>();
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setLong(1, hostId);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
l.add(rs.getLong(1));
}
} catch (SQLException e) {
s_logger.debug("Exception: ", e);
}
return l;
}
@Override @Override
public List<VMTemplateVO> listReadyTemplates() { public List<VMTemplateVO> listReadyTemplates() {
SearchCriteria<VMTemplateVO> sc = createSearchCriteria(); SearchCriteria<VMTemplateVO> sc = createSearchCriteria();
@ -466,320 +431,6 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
_templateDetailsDao.saveDetails(details); _templateDetailsDao.saveDetails(details);
} }
/*
* @Override public Set<Pair<Long, Long>> searchSwiftTemplates(String name,
* String keyword, TemplateFilter templateFilter, boolean isIso,
* List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long
* pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean
* onlyReady, boolean showDomr, List<Account> permittedAccounts, Account
* caller, Map<String, String> tags) {
*
* StringBuilder builder = new StringBuilder(); if
* (!permittedAccounts.isEmpty()) { for (Account permittedAccount :
* permittedAccounts) { builder.append(permittedAccount.getAccountId() +
* ","); } }
*
* String permittedAccountsStr = builder.toString();
*
* if (permittedAccountsStr.length() > 0) { // chop the "," off
* permittedAccountsStr = permittedAccountsStr.substring(0,
* permittedAccountsStr.length() - 1); }
*
* TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start();
*
* Set<Pair<Long, Long>> templateZonePairList = new HashSet<Pair<Long,
* Long>>(); PreparedStatement pstmt = null; ResultSet rs = null; String sql
* = SELECT_TEMPLATE_SWIFT_REF; try { String joinClause = ""; String
* whereClause = " WHERE t.removed IS NULL";
*
* if (isIso) { whereClause += " AND t.format = 'ISO'"; if
* (!hyperType.equals(HypervisorType.None)) { joinClause =
* " 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 += " AND goh.hypervisor_type = '" + hyperType.toString() +
* "'"; } } else { whereClause += " AND t.format <> 'ISO'"; if
* (hypers.isEmpty()) { return templateZonePairList; } else { StringBuilder
* relatedHypers = new StringBuilder(); for (HypervisorType hyper : hypers)
* { relatedHypers.append("'"); relatedHypers.append(hyper.toString());
* relatedHypers.append("'"); relatedHypers.append(","); }
* relatedHypers.setLength(relatedHypers.length() - 1); whereClause +=
* " AND t.hypervisor_type IN (" + relatedHypers + ")"; } } joinClause +=
* " INNER JOIN template_swift_ref tsr on (t.id = tsr.template_id)"; if
* (keyword != null) { whereClause += " AND t.name LIKE \"%" + keyword +
* "%\""; } else if (name != null) { whereClause += " AND t.name LIKE \"%" +
* name + "%\""; }
*
* if (bootable != null) { whereClause += " AND t.bootable = " + bootable; }
*
* if (!showDomr) { whereClause += " AND t.type != '" +
* Storage.TemplateType.SYSTEM.toString() + "'"; }
*
* if (templateFilter == TemplateFilter.featured) { whereClause +=
* " 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 +=
* " INNER JOIN account a on (t.account_id = a.id) INNER JOIN domain d on (a.domain_id = d.id)"
* ; whereClause += " AND d.path LIKE '" + domain.getPath() + "%'"; } else
* { whereClause += " AND t.account_id IN (" + permittedAccountsStr + ")"; }
* } else if ((templateFilter == TemplateFilter.shared || templateFilter ==
* TemplateFilter.sharedexecutable) && caller.getType() !=
* Account.ACCOUNT_TYPE_ADMIN) { if (caller.getType() ==
* Account.ACCOUNT_TYPE_NORMAL) { joinClause +=
* " LEFT JOIN launch_permission lp ON t.id = lp.template_id WHERE" +
* " (t.account_id IN (" + permittedAccountsStr + ") OR" +
* " lp.account_id IN (" + permittedAccountsStr + "))"; } else { joinClause
* += " INNER JOIN account a on (t.account_id = a.id) "; } } else if
* (templateFilter == TemplateFilter.executable &&
* !permittedAccounts.isEmpty()) { whereClause +=
* " AND (t.public = 1 OR t.account_id IN (" + permittedAccountsStr + "))";
* } else if (templateFilter == TemplateFilter.community) { whereClause +=
* " 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; }
*
* sql += joinClause + whereClause + getOrderByLimit(pageSize, startIndex);
* pstmt = txn.prepareStatement(sql); rs = pstmt.executeQuery(); while
* (rs.next()) { Pair<Long, Long> templateZonePair = new Pair<Long,
* Long>(rs.getLong(1), -1L); templateZonePairList.add(templateZonePair); }
*
* } catch (Exception e) { s_logger.warn("Error listing templates", e); }
* finally { try { if (rs != null) { rs.close(); } if (pstmt != null) {
* pstmt.close(); } txn.commit(); } catch (SQLException sqle) {
* s_logger.warn("Error in cleaning up", sqle); } }
*
* return templateZonePairList; }
*
*
* @Override public Set<Pair<Long, Long>> searchTemplates(String name,
* String keyword, TemplateFilter templateFilter, boolean isIso,
* List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long
* pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean
* onlyReady, boolean showDomr,List<Account> permittedAccounts, Account
* caller, ListProjectResourcesCriteria listProjectResourcesCriteria,
* Map<String, String> tags, String zoneType) { StringBuilder builder = new
* StringBuilder(); if (!permittedAccounts.isEmpty()) { for (Account
* permittedAccount : permittedAccounts) {
* builder.append(permittedAccount.getAccountId() + ","); } }
*
* String permittedAccountsStr = builder.toString();
*
* if (permittedAccountsStr.length() > 0) { //chop the "," off
* permittedAccountsStr = permittedAccountsStr.substring(0,
* permittedAccountsStr.length()-1); }
*
* TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start();
*
* // Use LinkedHashSet here to guarantee iteration order Set<Pair<Long,
* Long>> templateZonePairList = new LinkedHashSet<Pair<Long, Long>>();
* PreparedStatement pstmt = null; ResultSet rs = null; StringBuilder
* relatedDomainIds = new StringBuilder(); String sql =
* SELECT_TEMPLATE_ZONE_REF; String groupByClause = ""; try { //short
* accountType; //String accountId = null; String guestOSJoin = "";
* StringBuilder templateHostRefJoin = new StringBuilder(); String
* dataCenterJoin = "", lpjoin = ""; String tagsJoin = "";
*
* if (isIso && !hyperType.equals(HypervisorType.None)) { guestOSJoin =
* " 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) "
* ; } if (onlyReady){ templateHostRefJoin.append(
* " INNER JOIN template_host_ref thr on (t.id = thr.template_id) INNER JOIN host h on (thr.host_id = h.id)"
* ); sql = SELECT_TEMPLATE_HOST_REF; groupByClause =
* " GROUP BY t.id, h.data_center_id "; } if ((templateFilter ==
* TemplateFilter.featured) || (templateFilter == TemplateFilter.community))
* { dataCenterJoin =
* " INNER JOIN data_center dc on (h.data_center_id = dc.id)"; }
*
* if (zoneType != null) { dataCenterJoin =
* " INNER JOIN template_host_ref thr on (t.id = thr.template_id) INNER JOIN host h on (thr.host_id = h.id)"
* ; dataCenterJoin +=
* " INNER JOIN data_center dc on (h.data_center_id = dc.id)"; }
*
* if (templateFilter == TemplateFilter.sharedexecutable || templateFilter
* == TemplateFilter.shared ){ lpjoin =
* " INNER JOIN launch_permission lp ON t.id = lp.template_id "; }
*
* if (tags != null && !tags.isEmpty()) { tagsJoin =
* " INNER JOIN resource_tags r ON t.id = r.resource_id "; }
*
* sql += guestOSJoin + templateHostRefJoin + dataCenterJoin + lpjoin +
* tagsJoin; String whereClause = "";
*
* //All joins have to be made before we start setting the condition
* settings if ((listProjectResourcesCriteria ==
* ListProjectResourcesCriteria.SkipProjectResources ||
* (!permittedAccounts.isEmpty() && !(templateFilter ==
* TemplateFilter.community || templateFilter == TemplateFilter.featured)))
* && !(caller.getType() != Account.ACCOUNT_TYPE_NORMAL && templateFilter ==
* TemplateFilter.all)) { whereClause +=
* " INNER JOIN account a on (t.account_id = a.id)"; if ((templateFilter ==
* TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable)
* && (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN ||
* caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)) {
* whereClause +=
* " INNER JOIN domain d on (a.domain_id = d.id) WHERE d.path LIKE '" +
* domain.getPath() + "%'"; if (listProjectResourcesCriteria ==
* ListProjectResourcesCriteria.SkipProjectResources) { whereClause +=
* " AND a.type != " + Account.ACCOUNT_TYPE_PROJECT; } } else if
* (listProjectResourcesCriteria ==
* ListProjectResourcesCriteria.SkipProjectResources) { whereClause +=
* " WHERE a.type != " + Account.ACCOUNT_TYPE_PROJECT; } }
*
* if (!permittedAccounts.isEmpty()) { for (Account account :
* permittedAccounts) { //accountType = account.getType(); //accountId =
* Long.toString(account.getId()); DomainVO accountDomain =
* _domainDao.findById(account.getDomainId());
*
* // get all parent domain ID's all the way till root domain DomainVO
* domainTreeNode = accountDomain; while (true) {
* relatedDomainIds.append(domainTreeNode.getId());
* relatedDomainIds.append(","); if (domainTreeNode.getParent() != null) {
* domainTreeNode = _domainDao.findById(domainTreeNode.getParent()); } else
* { break; } }
*
* // get all child domain ID's if (isAdmin(account.getType()) ) {
* List<DomainVO> allChildDomains =
* _domainDao.findAllChildren(accountDomain.getPath(),
* accountDomain.getId()); for (DomainVO childDomain : allChildDomains) {
* relatedDomainIds.append(childDomain.getId());
* relatedDomainIds.append(","); } }
* relatedDomainIds.setLength(relatedDomainIds.length()-1); } }
*
* String attr = " AND "; if (whereClause.endsWith(" WHERE ")) { attr +=
* " WHERE "; }
*
* if (!isIso) { if ( hypers.isEmpty() ) { return templateZonePairList; }
* else { StringBuilder relatedHypers = new StringBuilder(); for
* (HypervisorType hyper : hypers ) { relatedHypers.append("'");
* relatedHypers.append(hyper.toString()); relatedHypers.append("'");
* relatedHypers.append(","); }
* relatedHypers.setLength(relatedHypers.length()-1); whereClause += attr +
* " t.hypervisor_type IN (" + relatedHypers + ")"; } }
*
* if (!permittedAccounts.isEmpty() && !(templateFilter ==
* TemplateFilter.featured || templateFilter == TemplateFilter.community ||
* templateFilter == TemplateFilter.executable || templateFilter ==
* TemplateFilter.shared || templateFilter ==
* TemplateFilter.sharedexecutable) && !isAdmin(caller.getType()) ) {
* whereClause += attr + "t.account_id IN (" + permittedAccountsStr + ")"; }
*
* if (templateFilter == TemplateFilter.featured) { whereClause += attr +
* "t.public = 1 AND t.featured = 1"; if (!permittedAccounts.isEmpty()) {
* whereClause += attr + "(dc.domain_id IN (" + relatedDomainIds +
* ") OR dc.domain_id is NULL)"; } } else if (templateFilter ==
* TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) {
* whereClause += " AND t.account_id IN (" + permittedAccountsStr + ")"; }
* else if (templateFilter == TemplateFilter.sharedexecutable ||
* templateFilter == TemplateFilter.shared ) { whereClause += " AND " +
* " (t.account_id IN (" + permittedAccountsStr + ") OR" +
* " lp.account_id IN (" + permittedAccountsStr + "))"; } else if
* (templateFilter == TemplateFilter.executable &&
* !permittedAccounts.isEmpty()) { whereClause += attr +
* "(t.public = 1 OR t.account_id IN (" + permittedAccountsStr + "))"; }
* else if (templateFilter == TemplateFilter.community) { whereClause +=
* attr + "t.public = 1 AND t.featured = 0"; if
* (!permittedAccounts.isEmpty()) { whereClause += attr +
* "(dc.domain_id IN (" + relatedDomainIds + ") OR dc.domain_id is NULL)"; }
* } else if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && !isIso) {
* return templateZonePairList; }
*
* if (tags != null && !tags.isEmpty()) { whereClause += " AND ("; boolean
* first = true; for (String key : tags.keySet()) { if (!first) {
* whereClause += " OR "; } whereClause += "(r.key=\"" + key +
* "\" and r.value=\"" + tags.get(key) + "\")"; first = false; } whereClause
* += ")"; }
*
* if (whereClause.equals("")) { whereClause += " WHERE "; } else if
* (!whereClause.equals(" WHERE ")) { whereClause += " AND "; }
*
* sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso,
* bootable, hyperType, zoneId, onlyReady, showDomr, zoneType) +
* groupByClause + getOrderByLimit(pageSize, startIndex);
*
* pstmt = txn.prepareStatement(sql); rs = pstmt.executeQuery();
*
* while (rs.next()) { Pair<Long, Long> templateZonePair = new Pair<Long,
* Long>(rs.getLong(1), rs.getLong(2));
* templateZonePairList.add(templateZonePair); } //for now, defaulting
* pageSize to a large val if null; may need to revisit post 2.2RC2 if(isIso
* && templateZonePairList.size() < (pageSize != null ? pageSize : 500) &&
* templateFilter != TemplateFilter.community && !(templateFilter ==
* TemplateFilter.self && !BaseCmd.isRootAdmin(caller.getType())) ){
* //evaluates to true If root admin and filter=self
*
* List<VMTemplateVO> publicIsos = publicIsoSearch(bootable, false, tags);
* List<VMTemplateVO> userIsos = userIsoSearch(false);
*
* //Listing the ISOs according to the page size.Restricting the total no.
* of ISOs on a page //to be less than or equal to the pageSize parameter
*
* int i=0;
*
* if (startIndex > userIsos.size()) { i=(int) (startIndex -
* userIsos.size()); }
*
* for (; i < publicIsos.size(); i++) { if(templateZonePairList.size() >=
* pageSize){ break; } else { if (keyword != null &&
* publicIsos.get(i).getName().contains(keyword)) {
* templateZonePairList.add(new Pair<Long,Long>(publicIsos.get(i).getId(),
* null)); continue; } else if (name != null &&
* publicIsos.get(i).getName().contains(name)) {
* templateZonePairList.add(new Pair<Long,Long>(publicIsos.get(i).getId(),
* null)); continue; } else if (keyword == null && name == null){
* templateZonePairList.add(new Pair<Long,Long>(publicIsos.get(i).getId(),
* null)); } } } } } catch (Exception e) {
* s_logger.warn("Error listing templates", e); } finally { try { if (rs !=
* null) { rs.close(); } if (pstmt != null) { pstmt.close(); } txn.commit();
* } catch( SQLException sqle) { s_logger.warn("Error in cleaning up",
* sqle); } }
*
* return templateZonePairList; }
*/
/*
* private String getExtrasWhere(TemplateFilter templateFilter, String name,
* String keyword, boolean isIso, Boolean bootable, HypervisorType
* hyperType, Long zoneId, boolean onlyReady, boolean showDomr, String
* zoneType) { String sql = ""; if (keyword != null) { sql +=
* " t.name LIKE \"%" + keyword + "%\" AND"; } else if (name != null) { sql
* += " t.name LIKE \"%" + name + "%\" AND"; }
*
* if (isIso) { sql += " t.format = 'ISO'"; if
* (!hyperType.equals(HypervisorType.None)) { sql +=
* " AND goh.hypervisor_type = '" + hyperType.toString() + "'"; } } else {
* sql += " t.format <> 'ISO'"; if (!hyperType.equals(HypervisorType.None))
* { sql += " AND t.hypervisor_type = '" + hyperType.toString() + "'"; } }
*
* if (bootable != null) { sql += " AND t.bootable = " + bootable; }
*
* if (onlyReady){ sql += " AND thr.download_state = '"
* +Status.DOWNLOADED.toString() + "'" + " AND thr.destroyed=0 "; if (zoneId
* != null){ sql += " AND h.data_center_id = " +zoneId; } }else if (zoneId
* != null){ sql += " AND tzr.zone_id = " +zoneId+
* " AND tzr.removed is null" ; }else{ sql += " AND tzr.removed is null "; }
*
* if (zoneType != null){ sql += " AND dc.networktype = '" + zoneType + "'";
* }
*
* if (!showDomr){ sql += " AND t.type != '"
* +Storage.TemplateType.SYSTEM.toString() + "'"; }
*
* sql += " AND t.removed IS NULL";
*
* return sql; }
*
* private String getOrderByLimit(Long pageSize, Long startIndex) { Boolean
* isAscending =
* Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
* isAscending = (isAscending == null ? true : isAscending);
*
* String sql; if (isAscending) { sql = " ORDER BY t.sort_key ASC"; } else {
* sql = " ORDER BY t.sort_key DESC"; }
*
* if ((pageSize != null) && (startIndex != null)) { sql += " LIMIT " +
* startIndex.toString() + "," + pageSize.toString(); } return sql; }
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
@DB @DB
@ -973,102 +624,6 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
return result; return result;
} }
@Override
public List<VMTemplateVO> findTemplatesToSyncToS3() {
return executeList(SELECT_S3_CANDIDATE_TEMPLATES, new Object[] {});
}
/*
* @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 @Override
public boolean updateState( public boolean updateState(
com.cloud.template.VirtualMachineTemplate.State currentState, com.cloud.template.VirtualMachineTemplate.State currentState,

View File

@ -1,68 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.storage.dao;
import java.util.List;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.fsm.StateDao;
public interface VMTemplateHostDao extends GenericDao<VMTemplateHostVO, Long>,
StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, DataObjectInStore> {
List<VMTemplateHostVO> listByHostId(long id);
List<VMTemplateHostVO> listByTemplateId(long templateId);
List<VMTemplateHostVO> listByOnlyTemplateId(long templateId);
VMTemplateHostVO findByHostTemplate(long hostId, long templateId);
VMTemplateHostVO findByTemplateId(long templateId);
VMTemplateHostVO findByHostTemplate(long hostId, long templateId, boolean lock);
List<VMTemplateHostVO> listByHostTemplate(long hostId, long templateId);
void update(VMTemplateHostVO instance);
List<VMTemplateHostVO> listByTemplateStatus(long templateId, VMTemplateHostVO.Status downloadState);
List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId, VMTemplateHostVO.Status downloadState);
List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateHostVO.Status downloadState);
List<VMTemplateHostVO> listByTemplateStates(long templateId, VMTemplateHostVO.Status... states);
List<VMTemplateHostVO> listDestroyed(long hostId);
boolean templateAvailable(long templateId, long hostId);
List<VMTemplateHostVO> listByZoneTemplate(long dcId, long templateId, boolean readyOnly);
void deleteByHost(Long hostId);
VMTemplateHostVO findLocalSecondaryStorageByHostTemplate(long hostId, long templateId);
List<VMTemplateHostVO> listByTemplateHostStatus(long templateId, long hostId, Status... states);
List<VMTemplateHostVO> listByState(Status state);
}

View File

@ -1,431 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.storage.dao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.utils.DateUtil;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.JoinBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.db.UpdateBuilder;
@Component
public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long> implements VMTemplateHostDao {
public static final Logger s_logger = Logger.getLogger(VMTemplateHostDaoImpl.class.getName());
@Inject
HostDao _hostDao;
protected final SearchBuilder<VMTemplateHostVO> HostSearch;
protected final SearchBuilder<VMTemplateHostVO> TemplateSearch;
protected final SearchBuilder<VMTemplateHostVO> HostTemplateSearch;
protected final SearchBuilder<VMTemplateHostVO> HostTemplateStateSearch;
protected final SearchBuilder<VMTemplateHostVO> HostDestroyedSearch;
protected final SearchBuilder<VMTemplateHostVO> TemplateStatusSearch;
protected final SearchBuilder<VMTemplateHostVO> TemplateStatesSearch;
protected final SearchBuilder<VMTemplateHostVO> updateStateSearch;
protected SearchBuilder<VMTemplateHostVO> ZoneTemplateSearch;
protected SearchBuilder<VMTemplateHostVO> LocalSecondaryStorageSearch;
protected static final String UPDATE_TEMPLATE_HOST_REF = "UPDATE template_host_ref SET download_state = ?, download_pct= ?, last_updated = ? "
+ ", error_str = ?, local_path = ?, job_id = ? " + "WHERE host_id = ? and type_id = ?";
protected static final String DOWNLOADS_STATE_DC = "SELECT t.id, t.host_id, t.template_id, t.created, t.last_updated, t.job_id, "
+ "t.download_pct, t.size, t.physical_size, t.download_state, t.error_str, t.local_path, "
+ "t.install_path, t.url, t.destroyed, t.is_copy FROM template_host_ref t, host h " + "where t.host_id = h.id and h.data_center_id=? "
+ " and t.template_id=? and t.download_state = ?";
protected static final String DOWNLOADS_STATE_DC_POD = "SELECT * FROM template_host_ref t, host h where t.host_id = h.id and h.data_center_id=? and h.pod_id=? "
+ " and t.template_id=? and t.download_state=?";
protected static final String DOWNLOADS_STATE = "SELECT * FROM template_host_ref t " + " where t.template_id=? and t.download_state=?";
public VMTemplateHostDaoImpl() {
HostSearch = createSearchBuilder();
HostSearch.and("host_id", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
HostSearch.done();
TemplateSearch = createSearchBuilder();
TemplateSearch.and("template_id", TemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
TemplateSearch.and("destroyed", TemplateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
TemplateSearch.done();
HostTemplateSearch = createSearchBuilder();
HostTemplateSearch.and("host_id", HostTemplateSearch.entity().getHostId(), SearchCriteria.Op.EQ);
HostTemplateSearch.and("template_id", HostTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
HostTemplateSearch.and("destroyed", HostTemplateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
HostTemplateSearch.done();
HostDestroyedSearch = createSearchBuilder();
HostDestroyedSearch.and("host_id", HostDestroyedSearch.entity().getHostId(), SearchCriteria.Op.EQ);
HostDestroyedSearch.and("destroyed", HostDestroyedSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
HostDestroyedSearch.done();
TemplateStatusSearch = createSearchBuilder();
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);
TemplateStatusSearch.done();
TemplateStatesSearch = createSearchBuilder();
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);
TemplateStatesSearch.done();
HostTemplateStateSearch = createSearchBuilder();
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);
HostTemplateStateSearch.and("destroyed", HostTemplateStateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
HostTemplateStateSearch.done();
updateStateSearch = this.createSearchBuilder();
updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ);
updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ);
updateStateSearch.and("updatedCount", updateStateSearch.entity().getUpdatedCount(), Op.EQ);
updateStateSearch.done();
}
@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;
}
@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 List<VMTemplateHostVO> listByHostId(long id) {
SearchCriteria<VMTemplateHostVO> sc = HostSearch.create();
sc.setParameters("host_id", id);
return listIncludingRemovedBy(sc);
}
@Override
public List<VMTemplateHostVO> listByTemplateId(long templateId) {
SearchCriteria<VMTemplateHostVO> sc = TemplateSearch.create();
sc.setParameters("template_id", templateId);
sc.setParameters("destroyed", false);
return listIncludingRemovedBy(sc);
}
@Override
public List<VMTemplateHostVO> listByOnlyTemplateId(long templateId) {
SearchCriteria<VMTemplateHostVO> sc = TemplateSearch.create();
sc.setParameters("template_id", templateId);
sc.setParameters("destroyed", false);
return listIncludingRemovedBy(sc);
}
@Override
public VMTemplateHostVO findByHostTemplate(long hostId, long templateId) {
SearchCriteria<VMTemplateHostVO> sc = HostTemplateSearch.create();
sc.setParameters("host_id", hostId);
sc.setParameters("template_id", templateId);
sc.setParameters("destroyed", false);
return findOneIncludingRemovedBy(sc);
}
@Override
public VMTemplateHostVO findByTemplateId(long templateId) {
SearchCriteria<VMTemplateHostVO> sc = HostTemplateSearch.create();
sc.setParameters("template_id", templateId);
sc.setParameters("destroyed", false);
return findOneIncludingRemovedBy(sc);
}
@Override
public List<VMTemplateHostVO> listByTemplateStatus(long templateId, VMTemplateHostVO.Status downloadState) {
SearchCriteria<VMTemplateHostVO> sc = TemplateStatusSearch.create();
sc.setParameters("template_id", templateId);
sc.setParameters("download_state", downloadState.toString());
sc.setParameters("destroyed", false);
return listIncludingRemovedBy(sc);
}
@Override
public List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId, VMTemplateHostVO.Status downloadState) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
List<VMTemplateHostVO> result = new ArrayList<VMTemplateHostVO>();
try {
String sql = DOWNLOADS_STATE_DC;
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setLong(1, datacenterId);
pstmt.setLong(2, templateId);
pstmt.setString(3, downloadState.toString());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
result.add(toEntityBean(rs, false));
}
} catch (Exception e) {
s_logger.warn("Exception: ", e);
}
return result;
}
@Override
public List<VMTemplateHostVO> listByTemplateHostStatus(long templateId, long hostId, VMTemplateHostVO.Status... states) {
SearchCriteria<VMTemplateHostVO> sc = HostTemplateStateSearch.create();
sc.setParameters("template_id", templateId);
sc.setParameters("host_id", hostId);
sc.setParameters("states", (Object[])states);
return search(sc, null);
}
@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
long id = rs.getLong(1); // ID column
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;
}
@Override
public boolean templateAvailable(long templateId, long hostId) {
VMTemplateHostVO tmpltHost = findByHostTemplate(hostId, templateId);
if (tmpltHost == null)
return false;
return tmpltHost.getDownloadState() == Status.DOWNLOADED;
}
@Override
public List<VMTemplateHostVO> listByTemplateStates(long templateId, VMTemplateHostVO.Status... states) {
SearchCriteria<VMTemplateHostVO> sc = TemplateStatesSearch.create();
sc.setParameters("states", (Object[])states);
sc.setParameters("template_id", templateId);
sc.setParameters("destroyed", false);
return search(sc, null);
}
@Override
public List<VMTemplateHostVO> listByState(VMTemplateHostVO.Status state) {
SearchCriteria<VMTemplateHostVO> sc = createSearchCriteria();
sc.addAnd("downloadState", SearchCriteria.Op.EQ, state);
sc.addAnd("destroyed", SearchCriteria.Op.EQ, false);
return search(sc, null);
}
@Override
public List<VMTemplateHostVO> listByHostTemplate(long hostId, long templateId) {
SearchCriteria<VMTemplateHostVO> sc = HostTemplateSearch.create();
sc.setParameters("host_id", hostId);
sc.setParameters("template_id", templateId);
sc.setParameters("destroyed", false);
return listIncludingRemovedBy(sc);
}
@Override
public List<VMTemplateHostVO> listByZoneTemplate(long dcId, long templateId, boolean readyOnly) {
SearchCriteria<VMTemplateHostVO> sc = ZoneTemplateSearch.create();
sc.setParameters("template_id", templateId);
sc.setJoinParameters("tmplHost", "zone_id", dcId);
if (readyOnly) {
sc.setParameters("state", VMTemplateHostVO.Status.DOWNLOADED);
}
return listBy(sc);
}
@Override
public List<VMTemplateHostVO> listDestroyed(long hostId) {
SearchCriteria<VMTemplateHostVO> sc = HostDestroyedSearch.create();
sc.setParameters("host_id", hostId);
sc.setParameters("destroyed", true);
return listIncludingRemovedBy(sc);
}
@Override
public VMTemplateHostVO findByHostTemplate(long hostId, long templateId, boolean lock) {
SearchCriteria<VMTemplateHostVO> sc = HostTemplateSearch.create();
sc.setParameters("host_id", hostId);
sc.setParameters("template_id", templateId);
sc.setParameters("destroyed", false);
if (!lock)
return findOneIncludingRemovedBy(sc);
else
return lockOneRandomRow(sc, true);
}
// 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);
}
@Override
public void deleteByHost(Long hostId) {
List<VMTemplateHostVO> tmpltHosts = listByHostId(hostId);
for (VMTemplateHostVO tmpltHost : tmpltHosts) {
remove(tmpltHost.getId());
}
}
@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;
}
}

View File

@ -62,7 +62,7 @@ public class VMTemplatePoolDaoImpl extends GenericDaoBase<VMTemplateStoragePoolV
protected final SearchBuilder<VMTemplateStoragePoolVO> updateStateSearch; protected final SearchBuilder<VMTemplateStoragePoolVO> updateStateSearch;
protected final SearchBuilder<VMTemplateStoragePoolVO> templatePathSearch; protected final SearchBuilder<VMTemplateStoragePoolVO> templatePathSearch;
protected static final String UPDATE_TEMPLATE_HOST_REF = "UPDATE template_spool_ref SET download_state = ?, download_pct= ?, last_updated = ? " protected static final String UPDATE_TEMPLATE_SPOOL_HOST_REF = "UPDATE template_spool_ref SET download_state = ?, download_pct= ?, last_updated = ? "
+ ", error_str = ?, local_path = ?, job_id = ? " + "WHERE pool_id = ? and template_id = ?"; + ", error_str = ?, local_path = ?, job_id = ? " + "WHERE pool_id = ? and template_id = ?";
protected static final String DOWNLOADS_STATE_DC = "SELECT * FROM template_spool_ref t, storage_pool p where t.pool_id = p.id and p.data_center_id=? " protected static final String DOWNLOADS_STATE_DC = "SELECT * FROM template_spool_ref t, storage_pool p where t.pool_id = p.id and p.data_center_id=? "

View File

@ -1,41 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.storage.dao;
import java.util.List;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import com.cloud.storage.VolumeHostVO;
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.fsm.StateDao;
public interface VolumeHostDao extends GenericDao<VolumeHostVO, Long>,
StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, DataObjectInStore> {
VolumeHostVO findByHostVolume(long hostId, long volumeId);
VolumeHostVO findByVolumeId(long volumeId);
List<VolumeHostVO> listBySecStorage(long sserverId);
List<VolumeHostVO> listDestroyed(long hostId);
VolumeHostVO findVolumeByZone(long zoneId, long volumeId);
}

View File

@ -1,181 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.storage.dao;
import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
import com.cloud.storage.VolumeHostVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.UpdateBuilder;
@Component
public class VolumeHostDaoImpl extends GenericDaoBase<VolumeHostVO, Long> implements VolumeHostDao {
private static final Logger s_logger = Logger.getLogger(VolumeHostDaoImpl.class);
protected final SearchBuilder<VolumeHostVO> HostVolumeSearch;
protected final SearchBuilder<VolumeHostVO> ZoneVolumeSearch;
protected final SearchBuilder<VolumeHostVO> VolumeSearch;
protected final SearchBuilder<VolumeHostVO> HostSearch;
protected final SearchBuilder<VolumeHostVO> HostDestroyedSearch;
protected final SearchBuilder<VolumeHostVO> updateStateSearch;
public VolumeHostDaoImpl() {
HostVolumeSearch = createSearchBuilder();
HostVolumeSearch.and("host_id", HostVolumeSearch.entity().getHostId(), SearchCriteria.Op.EQ);
HostVolumeSearch.and("volume_id", HostVolumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
HostVolumeSearch.and("destroyed", HostVolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
HostVolumeSearch.done();
ZoneVolumeSearch = createSearchBuilder();
ZoneVolumeSearch.and("zone_id", ZoneVolumeSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
ZoneVolumeSearch.and("volume_id", ZoneVolumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
ZoneVolumeSearch.and("destroyed", ZoneVolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
ZoneVolumeSearch.done();
HostSearch = createSearchBuilder();
HostSearch.and("host_id", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
HostSearch.and("destroyed", HostSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
HostSearch.done();
VolumeSearch = createSearchBuilder();
VolumeSearch.and("volume_id", VolumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
VolumeSearch.and("destroyed", VolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
VolumeSearch.done();
HostDestroyedSearch = createSearchBuilder();
HostDestroyedSearch.and("host_id", HostDestroyedSearch.entity().getHostId(), SearchCriteria.Op.EQ);
HostDestroyedSearch.and("destroyed", HostDestroyedSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
HostDestroyedSearch.done();
updateStateSearch = this.createSearchBuilder();
updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ);
updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ);
updateStateSearch.and("updatedCount", updateStateSearch.entity().getUpdatedCount(), Op.EQ);
updateStateSearch.done();
}
@Override
public VolumeHostVO findByHostVolume(long hostId, long volumeId) {
SearchCriteria<VolumeHostVO> sc = HostVolumeSearch.create();
sc.setParameters("host_id", hostId);
sc.setParameters("volume_id", volumeId);
sc.setParameters("destroyed", false);
return findOneIncludingRemovedBy(sc);
}
@Override
public VolumeHostVO findVolumeByZone(long volumeId, long zoneId) {
SearchCriteria<VolumeHostVO> sc = ZoneVolumeSearch.create();
sc.setParameters("zone_id", zoneId);
sc.setParameters("volume_id", volumeId);
sc.setParameters("destroyed", false);
return findOneIncludingRemovedBy(sc);
}
@Override
public VolumeHostVO findByVolumeId(long volumeId) {
SearchCriteria<VolumeHostVO> sc = VolumeSearch.create();
sc.setParameters("volume_id", volumeId);
sc.setParameters("destroyed", false);
return findOneBy(sc);
}
@Override
public List<VolumeHostVO> listBySecStorage(long ssHostId) {
SearchCriteria<VolumeHostVO> sc = HostSearch.create();
sc.setParameters("host_id", ssHostId);
sc.setParameters("destroyed", false);
return listAll();
}
@Override
public List<VolumeHostVO> listDestroyed(long hostId) {
SearchCriteria<VolumeHostVO> sc = HostDestroyedSearch.create();
sc.setParameters("host_id", hostId);
sc.setParameters("destroyed", true);
return listIncludingRemovedBy(sc);
}
@Override
public boolean updateState(State currentState, Event event, State nextState, DataObjectInStore vo, Object data) {
VolumeHostVO volHost = (VolumeHostVO)vo;
Long oldUpdated = volHost.getUpdatedCount();
Date oldUpdatedTime = volHost.getUpdated();
SearchCriteria<VolumeHostVO> sc = updateStateSearch.create();
sc.setParameters("id", volHost.getId());
sc.setParameters("state", currentState);
sc.setParameters("updatedCount", volHost.getUpdatedCount());
volHost.incrUpdatedCount();
UpdateBuilder builder = getUpdateBuilder(vo);
builder.set(vo, "state", nextState);
builder.set(vo, "updated", new Date());
int rows = update((VolumeHostVO)vo, sc);
if (rows == 0 && s_logger.isDebugEnabled()) {
VolumeHostVO dbVol = findByIdIncludingRemoved(volHost.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(volHost.getId())
.append("; state=")
.append(nextState)
.append("; event=")
.append(event)
.append("; updatecount=")
.append(volHost.getUpdatedCount())
.append("; updatedTime=")
.append(volHost.getUpdated());
str.append(": stale Data={id=")
.append(volHost.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=" + volHost.getId() + ", as there is no such object exists in the database anymore");
}
}
return rows > 0;
}
}

View File

@ -1,98 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.usage;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name = "external_public_ip_statistics")
@PrimaryKeyJoinColumn(name = "id")
public class ExternalPublicIpStatisticsVO implements InternalIdentity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "data_center_id", updatable = false)
private long zoneId;
@Column(name = "account_id", updatable = false)
private long accountId;
@Column(name = "public_ip_address")
private String publicIpAddress;
@Column(name = "current_bytes_received")
private long currentBytesReceived;
@Column(name = "current_bytes_sent")
private long currentBytesSent;
protected ExternalPublicIpStatisticsVO() {
}
public ExternalPublicIpStatisticsVO(long zoneId, long accountId, String publicIpAddress) {
this.zoneId = zoneId;
this.accountId = accountId;
this.publicIpAddress = publicIpAddress;
this.currentBytesReceived = 0;
this.currentBytesSent = 0;
}
@Override
public long getId() {
return id;
}
public long getZoneId() {
return zoneId;
}
public long getAccountId() {
return accountId;
}
public String getPublicIpAddress() {
return publicIpAddress;
}
public long getCurrentBytesReceived() {
return currentBytesReceived;
}
public void setCurrentBytesReceived(long currentBytesReceived) {
this.currentBytesReceived = currentBytesReceived;
}
public long getCurrentBytesSent() {
return currentBytesSent;
}
public void setCurrentBytesSent(long currentBytesSent) {
this.currentBytesSent = currentBytesSent;
}
}

View File

@ -1,32 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.usage.dao;
import java.util.List;
import com.cloud.usage.ExternalPublicIpStatisticsVO;
import com.cloud.utils.db.GenericDao;
public interface ExternalPublicIpStatisticsDao extends GenericDao<ExternalPublicIpStatisticsVO, Long> {
ExternalPublicIpStatisticsVO lock(long accountId, long zoneId, String publicIpAddress);
ExternalPublicIpStatisticsVO findBy(long accountId, long zoneId, String publicIpAddress);
List<ExternalPublicIpStatisticsVO> listBy(long accountId, long zoneId);
}

View File

@ -1,76 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.usage.dao;
import java.util.List;
import org.springframework.stereotype.Component;
import com.cloud.usage.ExternalPublicIpStatisticsVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@Component
public class ExternalPublicIpStatisticsDaoImpl extends GenericDaoBase<ExternalPublicIpStatisticsVO, Long> implements ExternalPublicIpStatisticsDao {
private final SearchBuilder<ExternalPublicIpStatisticsVO> AccountZoneSearch;
private final SearchBuilder<ExternalPublicIpStatisticsVO> SingleRowSearch;
public ExternalPublicIpStatisticsDaoImpl() {
AccountZoneSearch = createSearchBuilder();
AccountZoneSearch.and("accountId", AccountZoneSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
AccountZoneSearch.and("zoneId", AccountZoneSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
AccountZoneSearch.done();
SingleRowSearch = createSearchBuilder();
SingleRowSearch.and("accountId", SingleRowSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
SingleRowSearch.and("zoneId", SingleRowSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
SingleRowSearch.and("publicIp", SingleRowSearch.entity().getPublicIpAddress(), SearchCriteria.Op.EQ);
SingleRowSearch.done();
}
@Override
public ExternalPublicIpStatisticsVO lock(long accountId, long zoneId, String publicIpAddress) {
SearchCriteria<ExternalPublicIpStatisticsVO> sc = getSingleRowSc(accountId, zoneId, publicIpAddress);
return lockOneRandomRow(sc, true);
}
@Override
public ExternalPublicIpStatisticsVO findBy(long accountId, long zoneId, String publicIpAddress) {
SearchCriteria<ExternalPublicIpStatisticsVO> sc = getSingleRowSc(accountId, zoneId, publicIpAddress);
return findOneBy(sc);
}
private SearchCriteria<ExternalPublicIpStatisticsVO> getSingleRowSc(long accountId, long zoneId, String publicIpAddress) {
SearchCriteria<ExternalPublicIpStatisticsVO> sc = SingleRowSearch.create();
sc.setParameters("accountId", accountId);
sc.setParameters("zoneId", zoneId);
sc.setParameters("publicIp", publicIpAddress);
return sc;
}
@Override
public List<ExternalPublicIpStatisticsVO> listBy(long accountId, long zoneId) {
SearchCriteria<ExternalPublicIpStatisticsVO> sc = AccountZoneSearch.create();
sc.setParameters("accountId", accountId);
sc.setParameters("zoneId", zoneId);
return search(sc, null);
}
}

View File

@ -1,96 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.region;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import com.cloud.utils.db.GenericDao;
@Entity
@Table(name = "region_sync")
public class RegionSyncVO implements RegionSync {
@Id
@Column(name = "id")
private long id;
@Column(name = "region_id")
private int regionId;
@Column(name = "api")
private String api;
@Column(name = GenericDao.CREATED_COLUMN)
private Date createDate;
@Column(name = "processed")
boolean processed;
public RegionSyncVO() {
}
public RegionSyncVO(int regionId, String api) {
this.regionId = regionId;
this.api = api;
}
@Override
public int getRegionId() {
return regionId;
}
public void setRegionId(int regionId) {
this.regionId = regionId;
}
@Override
public String getApi() {
return api;
}
public void setApi(String api) {
this.api = api;
}
@Override
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public boolean isProcessed() {
return processed;
}
public void setProcessed(boolean processed) {
this.processed = processed;
}
@Override
public long getId() {
return id;
}
}

View File

@ -87,7 +87,6 @@
<bean id="eventJoinDaoImpl" class="com.cloud.event.dao.EventJoinDaoImpl" /> <bean id="eventJoinDaoImpl" class="com.cloud.event.dao.EventJoinDaoImpl" />
<bean id="externalFirewallDeviceDaoImpl" class="com.cloud.network.dao.ExternalFirewallDeviceDaoImpl" /> <bean id="externalFirewallDeviceDaoImpl" class="com.cloud.network.dao.ExternalFirewallDeviceDaoImpl" />
<bean id="externalLoadBalancerDeviceDaoImpl" class="com.cloud.network.dao.ExternalLoadBalancerDeviceDaoImpl" /> <bean id="externalLoadBalancerDeviceDaoImpl" class="com.cloud.network.dao.ExternalLoadBalancerDeviceDaoImpl" />
<bean id="externalPublicIpStatisticsDaoImpl" class="com.cloud.usage.dao.ExternalPublicIpStatisticsDaoImpl" />
<bean id="firewallRulesDaoImpl" class="com.cloud.network.dao.FirewallRulesDaoImpl" /> <bean id="firewallRulesDaoImpl" class="com.cloud.network.dao.FirewallRulesDaoImpl" />
<bean id="firewallRulesCidrsDaoImpl" class="com.cloud.network.dao.FirewallRulesCidrsDaoImpl" /> <bean id="firewallRulesCidrsDaoImpl" class="com.cloud.network.dao.FirewallRulesCidrsDaoImpl" />
<bean id="firewallRulesDcidrsDaoImpl" class="com.cloud.network.dao.FirewallRulesDcidrsDaoImpl" /> <bean id="firewallRulesDcidrsDaoImpl" class="com.cloud.network.dao.FirewallRulesDcidrsDaoImpl" />
@ -240,14 +239,12 @@
<bean id="vMSnapshotDaoImpl" class="com.cloud.vm.snapshot.dao.VMSnapshotDaoImpl" /> <bean id="vMSnapshotDaoImpl" class="com.cloud.vm.snapshot.dao.VMSnapshotDaoImpl" />
<bean id="vMSnapshotDetailsDaoImpl" class="com.cloud.vm.snapshot.dao.VMSnapshotDetailsDaoImpl" /> <bean id="vMSnapshotDetailsDaoImpl" class="com.cloud.vm.snapshot.dao.VMSnapshotDetailsDaoImpl" />
<bean id="vMTemplateDetailsDaoImpl" class="com.cloud.storage.dao.VMTemplateDetailsDaoImpl" /> <bean id="vMTemplateDetailsDaoImpl" class="com.cloud.storage.dao.VMTemplateDetailsDaoImpl" />
<bean id="vMTemplateHostDaoImpl" class="com.cloud.storage.dao.VMTemplateHostDaoImpl" />
<bean id="vMTemplatePoolDaoImpl" class="com.cloud.storage.dao.VMTemplatePoolDaoImpl" /> <bean id="vMTemplatePoolDaoImpl" class="com.cloud.storage.dao.VMTemplatePoolDaoImpl" />
<bean id="vMTemplateZoneDaoImpl" class="com.cloud.storage.dao.VMTemplateZoneDaoImpl" /> <bean id="vMTemplateZoneDaoImpl" class="com.cloud.storage.dao.VMTemplateZoneDaoImpl" />
<bean id="virtualRouterProviderDaoImpl" class="com.cloud.network.dao.VirtualRouterProviderDaoImpl" /> <bean id="virtualRouterProviderDaoImpl" class="com.cloud.network.dao.VirtualRouterProviderDaoImpl" />
<bean id="vmRulesetLogDaoImpl" class="com.cloud.network.security.dao.VmRulesetLogDaoImpl" /> <bean id="vmRulesetLogDaoImpl" class="com.cloud.network.security.dao.VmRulesetLogDaoImpl" />
<bean id="volumeDaoImpl" class="com.cloud.storage.dao.VolumeDaoImpl" /> <bean id="volumeDaoImpl" class="com.cloud.storage.dao.VolumeDaoImpl" />
<bean id="volumeDetailsDaoImpl" class="com.cloud.storage.dao.VolumeDetailsDaoImpl" /> <bean id="volumeDetailsDaoImpl" class="com.cloud.storage.dao.VolumeDetailsDaoImpl" />
<bean id="volumeHostDaoImpl" class="com.cloud.storage.dao.VolumeHostDaoImpl" />
<bean id="volumeJoinDaoImpl" class="com.cloud.api.query.dao.VolumeJoinDaoImpl" /> <bean id="volumeJoinDaoImpl" class="com.cloud.api.query.dao.VolumeJoinDaoImpl" />
<bean id="volumeReservationDaoImpl" class="org.apache.cloudstack.engine.cloud.entity.api.db.dao.VolumeReservationDaoImpl" /> <bean id="volumeReservationDaoImpl" class="org.apache.cloudstack.engine.cloud.entity.api.db.dao.VolumeReservationDaoImpl" />
<bean id="vpcDaoImpl" class="com.cloud.network.vpc.dao.VpcDaoImpl" /> <bean id="vpcDaoImpl" class="com.cloud.network.vpc.dao.VpcDaoImpl" />

View File

@ -405,3 +405,17 @@ UPDATE `cloud`.`configuration` SET name='denied.routes', description='Routes tha
ALTER TABLE `cloud`.`kubernetes_cluster` CHANGE master_node_count control_node_count bigint NOT NULL default '0' COMMENT 'the number of the control nodes deployed for this Kubernetes cluster'; ALTER TABLE `cloud`.`kubernetes_cluster` CHANGE master_node_count control_node_count bigint NOT NULL default '0' COMMENT 'the number of the control nodes deployed for this Kubernetes cluster';
UPDATE `cloud`.`domain_router` SET redundant_state = 'PRIMARY' WHERE redundant_state = 'MASTER'; UPDATE `cloud`.`domain_router` SET redundant_state = 'PRIMARY' WHERE redundant_state = 'MASTER';
DROP TABLE IF EXISTS `cloud`.`external_bigswitch_vns_devices`;
DROP TABLE IF EXISTS `cloud`.`template_s3_ref`;
DROP TABLE IF EXISTS `cloud`.`template_swift_ref`;
DROP TABLE IF EXISTS `cloud`.`template_ovf_properties`;
DROP TABLE IF EXISTS `cloud`.`op_host_upgrade`;
DROP TABLE IF EXISTS `cloud`.`stack_maid`;
DROP TABLE IF EXISTS `cloud`.`volume_host_ref`;
DROP TABLE IF EXISTS `cloud`.`template_host_ref`;
DROP TABLE IF EXISTS `cloud`.`swift`;
ALTER TABLE `cloud`.`snapshots` DROP FOREIGN KEY `fk_snapshots__s3_id` ;
ALTER TABLE `cloud`.`snapshots` DROP COLUMN `s3_id` ;
DROP TABLE IF EXISTS `cloud`.`s3`;

View File

@ -137,24 +137,6 @@ public class TemplateObject implements TemplateInfo {
if (dataStore == null) { if (dataStore == null) {
return imageVO.getSize(); return imageVO.getSize();
} }
/*
*
* // If the template that was passed into this allocator is not
* installed in the storage pool, // add 3 * (template size on secondary
* storage) to the running total VMTemplateHostVO templateHostVO =
* _storageMgr.findVmTemplateHost(templateForVmCreation.getId(), null);
*
* if (templateHostVO == null) { VMTemplateSwiftVO templateSwiftVO =
* _swiftMgr.findByTmpltId(templateForVmCreation.getId()); if
* (templateSwiftVO != null) { long templateSize =
* templateSwiftVO.getPhysicalSize(); if (templateSize == 0) {
* templateSize = templateSwiftVO.getSize(); } totalAllocatedSize +=
* (templateSize + _extraBytesPerVolume); } } else { long templateSize =
* templateHostVO.getPhysicalSize(); if ( templateSize == 0 ){
* templateSize = templateHostVO.getSize(); } totalAllocatedSize +=
* (templateSize + _extraBytesPerVolume); }
*/
VMTemplateVO image = imageDao.findById(imageVO.getId()); VMTemplateVO image = imageDao.findById(imageVO.getId());
return image.getSize(); return image.getSize();
} }

View File

@ -73,11 +73,9 @@ import com.cloud.storage.dao.StoragePoolHostDaoImpl;
import com.cloud.storage.dao.StoragePoolWorkDaoImpl; import com.cloud.storage.dao.StoragePoolWorkDaoImpl;
import com.cloud.storage.dao.VMTemplateDaoImpl; import com.cloud.storage.dao.VMTemplateDaoImpl;
import com.cloud.storage.dao.VMTemplateDetailsDaoImpl; import com.cloud.storage.dao.VMTemplateDetailsDaoImpl;
import com.cloud.storage.dao.VMTemplateHostDaoImpl;
import com.cloud.storage.dao.VMTemplatePoolDaoImpl; import com.cloud.storage.dao.VMTemplatePoolDaoImpl;
import com.cloud.storage.dao.VMTemplateZoneDaoImpl; import com.cloud.storage.dao.VMTemplateZoneDaoImpl;
import com.cloud.storage.dao.VolumeDaoImpl; import com.cloud.storage.dao.VolumeDaoImpl;
import com.cloud.storage.dao.VolumeHostDaoImpl;
import com.cloud.storage.download.DownloadMonitorImpl; import com.cloud.storage.download.DownloadMonitorImpl;
import com.cloud.tags.dao.ResourceTagsDaoImpl; import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.template.TemplateManager; import com.cloud.template.TemplateManager;
@ -96,7 +94,7 @@ import com.cloud.vm.dao.VMInstanceDaoImpl;
import com.cloud.vm.snapshot.dao.VMSnapshotDaoImpl; import com.cloud.vm.snapshot.dao.VMSnapshotDaoImpl;
@Configuration @Configuration
@ComponentScan(basePackageClasses = {NicDaoImpl.class, VMInstanceDaoImpl.class, VMTemplateHostDaoImpl.class, VolumeHostDaoImpl.class, VolumeDaoImpl.class, @ComponentScan(basePackageClasses = {NicDaoImpl.class, VMInstanceDaoImpl.class, VolumeDaoImpl.class,
VMTemplatePoolDaoImpl.class, ResourceTagsDaoImpl.class, VMTemplateDaoImpl.class, MockStorageMotionStrategy.class, ConfigurationDaoImpl.class, VMTemplatePoolDaoImpl.class, ResourceTagsDaoImpl.class, VMTemplateDaoImpl.class, MockStorageMotionStrategy.class, ConfigurationDaoImpl.class,
ClusterDaoImpl.class, HostPodDaoImpl.class, VMTemplateZoneDaoImpl.class, VMTemplateDetailsDaoImpl.class, HostDetailsDaoImpl.class, ClusterDaoImpl.class, HostPodDaoImpl.class, VMTemplateZoneDaoImpl.class, VMTemplateDetailsDaoImpl.class, HostDetailsDaoImpl.class,
HostTagsDaoImpl.class, HostTransferMapDaoImpl.class, DataCenterIpAddressDaoImpl.class, DataCenterLinkLocalIpAddressDaoImpl.class, HostTagsDaoImpl.class, HostTransferMapDaoImpl.class, DataCenterIpAddressDaoImpl.class, DataCenterLinkLocalIpAddressDaoImpl.class,

View File

@ -251,25 +251,6 @@ public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, L
@Override @Override
public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException { public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
/*if(forRebalance)
return;
if ( Host.Type.SecondaryStorage == host.getType() ) {
List<VMTemplateVO> tmplts = _vmTemplateDao.listAll();
for( VMTemplateVO tmplt : tmplts ) {
VMTemplateHostVO vmTemplateHost = _vmTemplateHostDao.findByHostTemplate(host.getId(), tmplt.getId());
if (vmTemplateHost == null) {
vmTemplateHost = new VMTemplateHostVO(host.getId(), tmplt.getId(), new Date(), 100,
com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, null, null, null, null, tmplt.getUrl());
_vmTemplateHostDao.persist(vmTemplateHost);
} else {
vmTemplateHost.setDownloadState(com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
vmTemplateHost.setDownloadPercent(100);
_vmTemplateHostDao.update(vmTemplateHost.getId(), vmTemplateHost);
}
}
}*/
} }
@Override @Override

View File

@ -256,10 +256,8 @@ import com.cloud.storage.dao.StoragePoolHostDaoImpl;
import com.cloud.storage.dao.UploadDaoImpl; import com.cloud.storage.dao.UploadDaoImpl;
import com.cloud.storage.dao.VMTemplateDaoImpl; import com.cloud.storage.dao.VMTemplateDaoImpl;
import com.cloud.storage.dao.VMTemplateDetailsDaoImpl; import com.cloud.storage.dao.VMTemplateDetailsDaoImpl;
import com.cloud.storage.dao.VMTemplateHostDaoImpl;
import com.cloud.storage.dao.VMTemplateZoneDaoImpl; import com.cloud.storage.dao.VMTemplateZoneDaoImpl;
import com.cloud.storage.dao.VolumeDaoImpl; import com.cloud.storage.dao.VolumeDaoImpl;
import com.cloud.storage.dao.VolumeHostDaoImpl;
import com.cloud.storage.snapshot.SnapshotApiService; import com.cloud.storage.snapshot.SnapshotApiService;
import com.cloud.storage.snapshot.SnapshotManager; import com.cloud.storage.snapshot.SnapshotManager;
import com.cloud.tags.dao.ResourceTagDao; import com.cloud.tags.dao.ResourceTagDao;
@ -332,8 +330,8 @@ import com.cloud.vm.snapshot.dao.VMSnapshotDaoImpl;
StoragePoolJoinDaoImpl.class, SyncQueueItemDaoImpl.class, TemplateDataStoreDaoImpl.class, TemplateJoinDaoImpl.class, UploadDaoImpl.class, UsageEventDaoImpl.class, StoragePoolJoinDaoImpl.class, SyncQueueItemDaoImpl.class, TemplateDataStoreDaoImpl.class, TemplateJoinDaoImpl.class, UploadDaoImpl.class, UsageEventDaoImpl.class,
UserAccountJoinDaoImpl.class, UserDaoImpl.class, UserIpv6AddressDaoImpl.class, UserStatisticsDaoImpl.class, UserStatsLogDaoImpl.class, UserAccountJoinDaoImpl.class, UserDaoImpl.class, UserIpv6AddressDaoImpl.class, UserStatisticsDaoImpl.class, UserStatsLogDaoImpl.class,
UserVmCloneSettingDaoImpl.class, UserVmDaoImpl.class, UserVmDetailsDaoImpl.class, UserVmJoinDaoImpl.class, UserVmManagerImpl.class, VMInstanceDaoImpl.class, VMSnapshotDaoImpl.class, UserVmCloneSettingDaoImpl.class, UserVmDaoImpl.class, UserVmDetailsDaoImpl.class, UserVmJoinDaoImpl.class, UserVmManagerImpl.class, VMInstanceDaoImpl.class, VMSnapshotDaoImpl.class,
VMTemplateDaoImpl.class, VMTemplateDetailsDaoImpl.class, VMTemplateHostDaoImpl.class, VMTemplateZoneDaoImpl.class, VirtualMachineManagerImpl.class, VirtualRouterProviderDaoImpl.class, VMTemplateDaoImpl.class, VMTemplateDetailsDaoImpl.class, VMTemplateZoneDaoImpl.class, VirtualMachineManagerImpl.class, VirtualRouterProviderDaoImpl.class,
VlanDaoImpl.class, VmDiskStatisticsDaoImpl.class, VmRulesetLogDaoImpl.class, VolumeDaoImpl.class, VolumeHostDaoImpl.class, VolumeJoinDaoImpl.class, VpcDaoImpl.class, VlanDaoImpl.class, VmDiskStatisticsDaoImpl.class, VmRulesetLogDaoImpl.class, VolumeDaoImpl.class, VolumeJoinDaoImpl.class, VpcDaoImpl.class,
VpcGatewayDaoImpl.class, VpcManagerImpl.class, VpcOfferingDaoImpl.class, VpcOfferingServiceMapDaoImpl.class, VpcServiceMapDaoImpl.class, VpcGatewayDaoImpl.class, VpcManagerImpl.class, VpcOfferingDaoImpl.class, VpcOfferingServiceMapDaoImpl.class, VpcServiceMapDaoImpl.class,
VpcVirtualNetworkApplianceManagerImpl.class, VpnUserDaoImpl.class, XenServerGuru.class}, includeFilters = {@Filter(value = IntegrationTestConfiguration.ComponentFilter.class, VpcVirtualNetworkApplianceManagerImpl.class, VpnUserDaoImpl.class, XenServerGuru.class}, includeFilters = {@Filter(value = IntegrationTestConfiguration.ComponentFilter.class,
type = FilterType.CUSTOM)}, useDefaultFilters = false) type = FilterType.CUSTOM)}, useDefaultFilters = false)

View File

@ -282,17 +282,6 @@ public class UserConcentratedAllocator extends AdapterBase implements PodAllocat
private boolean templateAvailableInPod(long templateId, long dcId, long podId) { private boolean templateAvailableInPod(long templateId, long dcId, long podId) {
return true; return true;
/*
* List<VMTemplateHostVO> thvoList = _templateHostDao.listByTemplateStatus(templateId, dcId, podId, Status.DOWNLOADED);
* List<VMTemplateStoragePoolVO> tpvoList = _templatePoolDao.listByTemplateStatus(templateId, dcId, podId,
* Status.DOWNLOADED);
*
* if (thvoList != null && thvoList.size() > 0) { if (s_logger.isDebugEnabled()) { s_logger.debug("Found " +
* thvoList.size() + " storage hosts in pod " + podId + " with template " + templateId); } return true; } else if
* (tpvoList != null && tpvoList.size() > 0) { if (s_logger.isDebugEnabled()) { s_logger.debug("Found " +
* tpvoList.size() + " storage pools in pod " + podId + " with template " + templateId); } return true; }else { return
* false; }
*/
} }
@Override @Override

View File

@ -53,7 +53,6 @@ import com.cloud.api.query.vo.TemplateJoinVO;
import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.Storage; import com.cloud.storage.Storage;
import com.cloud.storage.Storage.TemplateType; import com.cloud.storage.Storage.TemplateType;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.storage.VMTemplateVO; import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VMTemplateDao;
@ -134,7 +133,7 @@ public class TemplateJoinDaoImpl extends GenericDaoBaseWithTagInformation<Templa
String templateStatus = null; String templateStatus = null;
if (template.getDownloadState() != Status.DOWNLOADED) { if (template.getDownloadState() != Status.DOWNLOADED) {
templateStatus = "Processing"; templateStatus = "Processing";
if (template.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) { if (template.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
if (template.getDownloadPercent() == 100) { if (template.getDownloadPercent() == 100) {
templateStatus = "Installing Template"; templateStatus = "Installing Template";
} else { } else {
@ -147,7 +146,7 @@ public class TemplateJoinDaoImpl extends GenericDaoBaseWithTagInformation<Templa
}else { }else {
templateStatus = template.getErrorString(); templateStatus = template.getErrorString();
} }
} else if (template.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) { } else if (template.getDownloadState() == Status.DOWNLOADED) {
templateStatus = "Download Complete"; templateStatus = "Download Complete";
} else { } else {
templateStatus = "Successfully Installed"; templateStatus = "Successfully Installed";
@ -403,9 +402,9 @@ public class TemplateJoinDaoImpl extends GenericDaoBaseWithTagInformation<Templa
// add download status // add download status
if (iso.getDownloadState() != Status.DOWNLOADED) { if (iso.getDownloadState() != Status.DOWNLOADED) {
String isoStatus = "Processing"; String isoStatus = "Processing";
if (iso.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) { if (iso.getDownloadState() == Status.DOWNLOADED) {
isoStatus = "Download Complete"; isoStatus = "Download Complete";
} else if (iso.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) { } else if (iso.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
if (iso.getDownloadPercent() == 100) { if (iso.getDownloadPercent() == 100) {
isoStatus = "Installing ISO"; isoStatus = "Installing ISO";
} else { } else {

View File

@ -34,7 +34,6 @@ import com.cloud.api.ApiResponseHelper;
import com.cloud.api.query.vo.VolumeJoinVO; import com.cloud.api.query.vo.VolumeJoinVO;
import com.cloud.offering.ServiceOffering; import com.cloud.offering.ServiceOffering;
import com.cloud.storage.Storage; import com.cloud.storage.Storage;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.storage.Volume; import com.cloud.storage.Volume;
import com.cloud.user.AccountManager; import com.cloud.user.AccountManager;
@ -135,9 +134,6 @@ public class VolumeJoinDaoImpl extends GenericDaoBaseWithTagInformation<VolumeJo
volResponse.setState(volume.getState().toString()); volResponse.setState(volume.getState().toString());
} }
if (volume.getState() == Volume.State.UploadOp) { if (volume.getState() == Volume.State.UploadOp) {
// com.cloud.storage.VolumeHostVO volumeHostRef =
// ApiDBUtils.findVolumeHostRef(volume.getId(),
// volume.getDataCenterId());
volResponse.setSize(volume.getVolumeStoreSize()); volResponse.setSize(volume.getVolumeStoreSize());
volResponse.setCreated(volume.getCreatedOnStore()); volResponse.setCreated(volume.getCreatedOnStore());
@ -145,7 +141,7 @@ public class VolumeJoinDaoImpl extends GenericDaoBaseWithTagInformation<VolumeJo
volResponse.setHypervisor(ApiDBUtils.getHypervisorTypeFromFormat(volume.getDataCenterId(), volume.getFormat()).toString()); volResponse.setHypervisor(ApiDBUtils.getHypervisorTypeFromFormat(volume.getDataCenterId(), volume.getFormat()).toString());
if (volume.getDownloadState() != Status.DOWNLOADED) { if (volume.getDownloadState() != Status.DOWNLOADED) {
String volumeStatus = "Processing"; String volumeStatus = "Processing";
if (volume.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) { if (volume.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
if (volume.getDownloadPercent() == 100) { if (volume.getDownloadPercent() == 100) {
volumeStatus = "Checking Volume"; volumeStatus = "Checking Volume";
} else { } else {
@ -154,14 +150,14 @@ public class VolumeJoinDaoImpl extends GenericDaoBaseWithTagInformation<VolumeJo
volResponse.setState("Uploading"); volResponse.setState("Uploading");
} else { } else {
volumeStatus = volume.getErrorString(); volumeStatus = volume.getErrorString();
if (volume.getDownloadState() == VMTemplateHostVO.Status.NOT_DOWNLOADED) { if (volume.getDownloadState() == Status.NOT_DOWNLOADED) {
volResponse.setState("UploadNotStarted"); volResponse.setState("UploadNotStarted");
} else { } else {
volResponse.setState("UploadError"); volResponse.setState("UploadError");
} }
} }
volResponse.setStatus(volumeStatus); volResponse.setStatus(volumeStatus);
} else if (volume.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) { } else if (volume.getDownloadState() == Status.DOWNLOADED) {
volResponse.setStatus("Upload Complete"); volResponse.setStatus("Upload Complete");
volResponse.setState("Uploaded"); volResponse.setState("Uploaded");
} else { } else {

View File

@ -334,7 +334,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
_discoverers = discoverers; _discoverers = discoverers;
} }
protected SearchBuilder<VMTemplateHostVO> HostTemplateStatesSearch;
protected GenericSearchBuilder<StoragePoolHostVO, Long> UpHostsInPoolSearch; protected GenericSearchBuilder<StoragePoolHostVO, Long> UpHostsInPoolSearch;
protected SearchBuilder<VMInstanceVO> StoragePoolSearch; protected SearchBuilder<VMInstanceVO> StoragePoolSearch;
protected SearchBuilder<StoragePoolVO> LocalStorageSearch; protected SearchBuilder<StoragePoolVO> LocalStorageSearch;

View File

@ -55,7 +55,6 @@ import com.cloud.exception.ConnectionException;
import com.cloud.host.Host; import com.cloud.host.Host;
import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.resource.ResourceManager; import com.cloud.resource.ResourceManager;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.storage.download.DownloadState.DownloadEvent; import com.cloud.storage.download.DownloadState.DownloadEvent;
import com.cloud.storage.upload.UploadListener; import com.cloud.storage.upload.UploadListener;
@ -157,7 +156,7 @@ public class DownloadListener implements Listener {
return _callback; return _callback;
} }
public void setCurrState(VMTemplateHostVO.Status currState) { public void setCurrState(Status currState) {
_currState = getState(currState.toString()); _currState = getState(currState.toString());
} }

View File

@ -157,7 +157,6 @@ import com.cloud.storage.StoragePoolHostVO;
import com.cloud.storage.StoragePoolStatus; import com.cloud.storage.StoragePoolStatus;
import com.cloud.storage.TemplateProfile; import com.cloud.storage.TemplateProfile;
import com.cloud.storage.Upload; import com.cloud.storage.Upload;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStoragePoolVO; import com.cloud.storage.VMTemplateStoragePoolVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc; import com.cloud.storage.VMTemplateStorageResourceAssoc;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
@ -1094,44 +1093,6 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
protected TemplateManagerImpl() { protected TemplateManagerImpl() {
} }
@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;
}
@Override @Override
public boolean templateIsDeleteable(long templateId) { public boolean templateIsDeleteable(long templateId) {
List<UserVmJoinVO> userVmUsingIso = _userVmJoinDao.listActiveByIsoId(templateId); List<UserVmJoinVO> userVmUsingIso = _userVmJoinDao.listActiveByIsoId(templateId);

View File

@ -77,8 +77,6 @@
<dao name="Limit" class="com.cloud.configuration.dao.LimitDaoImpl" /> <dao name="Limit" class="com.cloud.configuration.dao.LimitDaoImpl" />
<dao name="UserAccount" class="com.cloud.user.dao.UserAccountDaoImpl" /> <dao name="UserAccount" class="com.cloud.user.dao.UserAccountDaoImpl" />
<dao name="Usage IPAddress" class="com.cloud.usage.dao.UsageIPAddressDaoImpl" /> <dao name="Usage IPAddress" class="com.cloud.usage.dao.UsageIPAddressDaoImpl" />
<dao name="VM Template Host" class="com.cloud.storage.dao.VMTemplateHostDaoImpl" />
<dao name="VM Template Swift" class="com.cloud.storage.dao.VMTemplateSwiftDaoImpl" />
<dao name="Upload" class="com.cloud.storage.dao.UploadDaoImpl" /> <dao name="Upload" class="com.cloud.storage.dao.UploadDaoImpl" />
<dao name="VM Template Pool" class="com.cloud.storage.dao.VMTemplatePoolDaoImpl" /> <dao name="VM Template Pool" class="com.cloud.storage.dao.VMTemplatePoolDaoImpl" />
<dao name="Launch Permission" class="com.cloud.storage.dao.LaunchPermissionDaoImpl" /> <dao name="Launch Permission" class="com.cloud.storage.dao.LaunchPermissionDaoImpl" />

View File

@ -86,7 +86,6 @@ import com.cloud.service.dao.ServiceOfferingDaoImpl;
import com.cloud.storage.dao.SnapshotDaoImpl; import com.cloud.storage.dao.SnapshotDaoImpl;
import com.cloud.storage.dao.VMTemplateDaoImpl; import com.cloud.storage.dao.VMTemplateDaoImpl;
import com.cloud.storage.dao.VMTemplateDetailsDaoImpl; import com.cloud.storage.dao.VMTemplateDetailsDaoImpl;
import com.cloud.storage.dao.VMTemplateHostDaoImpl;
import com.cloud.storage.dao.VMTemplateZoneDaoImpl; import com.cloud.storage.dao.VMTemplateZoneDaoImpl;
import com.cloud.storage.dao.VolumeDaoImpl; import com.cloud.storage.dao.VolumeDaoImpl;
import com.cloud.tags.dao.ResourceTagsDaoImpl; import com.cloud.tags.dao.ResourceTagsDaoImpl;
@ -116,7 +115,7 @@ import com.cloud.vpc.dao.MockVpcOfferingServiceMapDaoImpl;
UserStatisticsDaoImpl.class, PhysicalNetworkTrafficTypeDaoImpl.class, FirewallRulesCidrsDaoImpl.class, ResourceLimitManagerImpl.class, UserStatisticsDaoImpl.class, PhysicalNetworkTrafficTypeDaoImpl.class, FirewallRulesCidrsDaoImpl.class, ResourceLimitManagerImpl.class,
ResourceLimitDaoImpl.class, ResourceCountDaoImpl.class, DomainDaoImpl.class, UserVmDaoImpl.class, UserVmDetailsDaoImpl.class, NicDaoImpl.class, ResourceLimitDaoImpl.class, ResourceCountDaoImpl.class, DomainDaoImpl.class, UserVmDaoImpl.class, UserVmDetailsDaoImpl.class, NicDaoImpl.class,
SnapshotDaoImpl.class, VMInstanceDaoImpl.class, VolumeDaoImpl.class, UserIpv6AddressDaoImpl.class, NicSecondaryIpDaoImpl.class, SnapshotDaoImpl.class, VMInstanceDaoImpl.class, VolumeDaoImpl.class, UserIpv6AddressDaoImpl.class, NicSecondaryIpDaoImpl.class,
VpcServiceMapDaoImpl.class, ServiceOfferingDaoImpl.class, VMTemplateHostDaoImpl.class, MockVpcDaoImpl.class, VMTemplateDaoImpl.class, VpcServiceMapDaoImpl.class, ServiceOfferingDaoImpl.class, MockVpcDaoImpl.class, VMTemplateDaoImpl.class,
VMTemplateZoneDaoImpl.class, VMTemplateDetailsDaoImpl.class, DataCenterDaoImpl.class, DataCenterIpAddressDaoImpl.class, VMTemplateZoneDaoImpl.class, VMTemplateDetailsDaoImpl.class, DataCenterDaoImpl.class, DataCenterIpAddressDaoImpl.class,
DataCenterLinkLocalIpAddressDaoImpl.class, DataCenterVnetDaoImpl.class, PodVlanDaoImpl.class, DataCenterDetailsDaoImpl.class, DataCenterLinkLocalIpAddressDaoImpl.class, DataCenterVnetDaoImpl.class, PodVlanDaoImpl.class, DataCenterDetailsDaoImpl.class,
MockNetworkManagerImpl.class, MockVpcVirtualNetworkApplianceManager.class, EntityManagerImpl.class, LoadBalancerDaoImpl.class, MockNetworkManagerImpl.class, MockVpcVirtualNetworkApplianceManager.class, EntityManagerImpl.class, LoadBalancerDaoImpl.class,

View File

@ -27,9 +27,9 @@ import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.utils.net.Proxy; import com.cloud.utils.net.Proxy;
import com.cloud.agent.api.to.S3TO; import com.cloud.agent.api.to.S3TO;
import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.template.TemplateDownloader; import com.cloud.storage.template.TemplateDownloader;
import com.cloud.storage.template.TemplateProp; import com.cloud.storage.template.TemplateProp;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.utils.component.Manager; import com.cloud.utils.component.Manager;
public interface DownloadManager extends Manager { public interface DownloadManager extends Manager {
@ -67,7 +67,7 @@ public interface DownloadManager extends Manager {
* @param jobId job Id * @param jobId job Id
* @return status of the download job * @return status of the download job
*/ */
public VMTemplateHostVO.Status getDownloadStatus2(String jobId); public Status getDownloadStatus2(String jobId);
/** /**
* Get the download percent of a download job * Get the download percent of a download job

View File

@ -72,7 +72,6 @@ import com.cloud.agent.api.to.S3TO;
import com.cloud.exception.InternalErrorException; import com.cloud.exception.InternalErrorException;
import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageLayer; import com.cloud.storage.StorageLayer;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc; import com.cloud.storage.VMTemplateStorageResourceAssoc;
import com.cloud.storage.template.Processor.FormatInfo; import com.cloud.storage.template.Processor.FormatInfo;
import com.cloud.storage.template.TemplateDownloader.DownloadCompleteCallback; import com.cloud.storage.template.TemplateDownloader.DownloadCompleteCallback;
@ -701,31 +700,31 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager
return 0; return 0;
} }
public static VMTemplateHostVO.Status convertStatus(Status tds) { public static VMTemplateStorageResourceAssoc.Status convertStatus(Status tds) {
switch (tds) { switch (tds) {
case ABORTED: case ABORTED:
return VMTemplateHostVO.Status.NOT_DOWNLOADED; return VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED;
case DOWNLOAD_FINISHED: case DOWNLOAD_FINISHED:
return VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS; return VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS;
case IN_PROGRESS: case IN_PROGRESS:
return VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS; return VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS;
case NOT_STARTED: case NOT_STARTED:
return VMTemplateHostVO.Status.NOT_DOWNLOADED; return VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED;
case RECOVERABLE_ERROR: case RECOVERABLE_ERROR:
return VMTemplateHostVO.Status.NOT_DOWNLOADED; return VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED;
case UNKNOWN: case UNKNOWN:
return VMTemplateHostVO.Status.UNKNOWN; return VMTemplateStorageResourceAssoc.Status.UNKNOWN;
case UNRECOVERABLE_ERROR: case UNRECOVERABLE_ERROR:
return VMTemplateHostVO.Status.DOWNLOAD_ERROR; return VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR;
case POST_DOWNLOAD_FINISHED: case POST_DOWNLOAD_FINISHED:
return VMTemplateHostVO.Status.DOWNLOADED; return VMTemplateStorageResourceAssoc.Status.DOWNLOADED;
default: default:
return VMTemplateHostVO.Status.UNKNOWN; return VMTemplateStorageResourceAssoc.Status.UNKNOWN;
} }
} }
@Override @Override
public com.cloud.storage.VMTemplateHostVO.Status getDownloadStatus2(String jobId) { public com.cloud.storage.VMTemplateStorageResourceAssoc.Status getDownloadStatus2(String jobId) {
return convertStatus(getDownloadStatus(jobId)); return convertStatus(getDownloadStatus(jobId));
} }

View File

@ -169,45 +169,6 @@ under the License.
</item> </item>
</returnvalue> </returnvalue>
</command> </command>
<command>
<name>select download_state from template_host_ref</name>
<mysql>true</mysql>
<testcase>Getting volume path for the vm DATADISK volume</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item>
<name>download_state</name>
<value>DOWNLOADED</value>
</item>
</returnvalue>
</command>
<command>
<name>select install_path from template_host_ref</name>
<mysql>true</mysql>
<testcase>Getting install_path from the template</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item setparam="true">
<name>install_path</name>
<param>template_path</param>
</item>
</returnvalue>
</command>
<command> <command>
<name>listtemplate.sh</name> <name>listtemplate.sh</name>
<script>true</script> <script>true</script>
@ -294,26 +255,6 @@ under the License.
</parameters> </parameters>
</command> </command>
<command>
<name>select download_state from template_host_ref</name>
<mysql>true</mysql>
<testcase>Checking download state of the template in the DB after the template was deleted on secondary storage and management server process was restarted</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item>
<name>download_state</name>
<value>DOWNLOAD_ERROR</value>
</item>
</returnvalue>
</command>
<!-- Create template, corrupt it by removing lines from templates.properties file and restart management server --> <!-- Create template, corrupt it by removing lines from templates.properties file and restart management server -->
<command> <command>
<name>createTemplate</name> <name>createTemplate</name>
@ -352,44 +293,6 @@ under the License.
</returnvalue> </returnvalue>
</command> </command>
<command>
<name>select download_state from template_host_ref</name>
<mysql>true</mysql>
<testcase>Getting volume path for the vm DATADISK volume</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item>
<name>download_state</name>
<value>DOWNLOADED</value>
</item>
</returnvalue>
</command>
<command>
<name>select install_path from template_host_ref</name>
<mysql>true</mysql>
<testcase>Getting install_path from the template</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item setparam="true">
<name>install_path</name>
<param>template_path</param>
</item>
</returnvalue>
</command>
<command> <command>
<name>listtemplate.sh</name> <name>listtemplate.sh</name>
<script>true</script> <script>true</script>
@ -480,24 +383,6 @@ under the License.
</parameters> </parameters>
</command> </command>
<command>
<name>select download_state from template_host_ref</name>
<mysql>true</mysql>
<testcase>Checking download state of the template in the DB after the template was deleted on secondary storage and management server process was restarted</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item>
<name>download_state</name>
<value>DOWNLOAD_ERROR</value>
</item>
</returnvalue>
</command>
<command> <command>
<name>listtemplate.sh</name> <name>listtemplate.sh</name>
<script>true</script> <script>true</script>
@ -558,44 +443,6 @@ under the License.
</returnvalue> </returnvalue>
</command> </command>
<command>
<name>select download_state from template_host_ref</name>
<mysql>true</mysql>
<testcase>Getting volume path for the vm DATADISK volume</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item>
<name>download_state</name>
<value>DOWNLOADED</value>
</item>
</returnvalue>
</command>
<command>
<name>select install_path from template_host_ref</name>
<mysql>true</mysql>
<testcase>Getting install_path from the template</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item setparam="true">
<name>install_path</name>
<param>template_path</param>
</item>
</returnvalue>
</command>
<command> <command>
<name>listtemplate.sh</name> <name>listtemplate.sh</name>
<script>true</script> <script>true</script>
@ -750,44 +597,6 @@ under the License.
</returnvalue> </returnvalue>
</command> </command>
<command>
<name>select download_state from template_host_ref</name>
<mysql>true</mysql>
<testcase>Getting volume path for the vm DATADISK volume</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item>
<name>download_state</name>
<value>DOWNLOADED</value>
</item>
</returnvalue>
</command>
<command>
<name>select install_path from template_host_ref</name>
<mysql>true</mysql>
<testcase>Getting install_path from the template</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item setparam="true">
<name>install_path</name>
<param>template_path</param>
</item>
</returnvalue>
</command>
<command> <command>
<name>listtemplate.sh</name> <name>listtemplate.sh</name>
<script>true</script> <script>true</script>
@ -906,26 +715,6 @@ under the License.
</parameters> </parameters>
</command> </command>
<command>
<name>select download_state from template_host_ref</name>
<mysql>true</mysql>
<testcase>Checking download state of the template in the DB after the template was deleted on secondary storage and management server process was restarted</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item>
<name>download_state</name>
<value>DOWNLOAD_ERROR</value>
</item>
</returnvalue>
</command>
<!-- Create template, don't delete it and restart management server. Make sure that the template is still available, and you can stat a vm from it --> <!-- Create template, don't delete it and restart management server. Make sure that the template is still available, and you can stat a vm from it -->
<command> <command>
<name>createTemplate</name> <name>createTemplate</name>
@ -964,44 +753,6 @@ under the License.
</returnvalue> </returnvalue>
</command> </command>
<command>
<name>select download_state from template_host_ref</name>
<mysql>true</mysql>
<testcase>Getting volume path for the vm DATADISK volume</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item>
<name>download_state</name>
<value>DOWNLOADED</value>
</item>
</returnvalue>
</command>
<command>
<name>select install_path from template_host_ref</name>
<mysql>true</mysql>
<testcase>Getting install_path from the template</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item setparam="true">
<name>install_path</name>
<param>template_path</param>
</item>
</returnvalue>
</command>
<command> <command>
<name>listtemplate.sh</name> <name>listtemplate.sh</name>
<script>true</script> <script>true</script>
@ -1067,25 +818,6 @@ under the License.
</parameters> </parameters>
</command> </command>
<command>
<name>select download_state from template_host_ref</name>
<mysql>true</mysql>
<testcase>Checking download state of the template in the DB after the template was deleted on secondary storage and management server process was restarted</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item>
<name>download_state</name>
<value>DOWNLOADED</value>
</item>
</returnvalue>
</command>
<command> <command>
<name>deployVirtualMachine</name> <name>deployVirtualMachine</name>
<testcase>Deploy vm from private template after management server was rebooted</testcase> <testcase>Deploy vm from private template after management server was rebooted</testcase>
@ -1194,45 +926,6 @@ under the License.
</parameters> </parameters>
</command> </command>
<command>
<name>select download_state from template_host_ref</name>
<mysql>true</mysql>
<testcase>Getting volume path for the vm DATADISK volume</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item>
<name>download_state</name>
<value>DOWNLOADED</value>
</item>
</returnvalue>
</command>
<command>
<name>select install_path from template_host_ref</name>
<mysql>true</mysql>
<testcase>Getting install_path from the template</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item setparam="true">
<name>install_path</name>
<param>template_path</param>
</item>
</returnvalue>
</command>
<command> <command>
<name>listtemplate.sh</name> <name>listtemplate.sh</name>
<script>true</script> <script>true</script>
@ -1351,25 +1044,6 @@ under the License.
</parameters> </parameters>
</command> </command>
<command>
<name>select download_state from template_host_ref</name>
<mysql>true</mysql>
<testcase>Checking download state of the template in the DB after the template was deleted on secondary storage and management server process was restarted</testcase>
<parameters>
<item getparam="true">
<name>template_id</name>
<param>privatetemplateid</param>
</item>
</parameters>
<returnvalue>
<item>
<name>download_state</name>
<value>DOWNLOAD_IN_PROGRESS</value>
</item>
</returnvalue>
</command>
<!-- Execute a cleanup --> <!-- Execute a cleanup -->
<command> <command>
<name>destroyVirtualMachine</name> <name>destroyVirtualMachine</name>