mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Swift : list Template
This commit is contained in:
parent
4116d0d4e4
commit
2b039530c0
@ -196,13 +196,13 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
||||
String lPath = parent + "/template/tmpl/" + accountId.toString() + "/" + templateId.toString();
|
||||
if (!_storage.isFile(lPath + "/template.properties")) {
|
||||
String errMsg = cmd + " Command failed due to template doesn't exist ";
|
||||
s_logger.warn(errMsg);
|
||||
s_logger.debug(errMsg);
|
||||
return new Answer(cmd, false, errMsg);
|
||||
}
|
||||
String result = swiftUpload(swift, "T-" + templateId.toString(), lPath, "*");
|
||||
if (result != null) {
|
||||
String errMsg = "failed to download template from Swift to secondary storage " + lPath + " , err=" + result;
|
||||
s_logger.warn(errMsg);
|
||||
s_logger.debug(errMsg);
|
||||
return new Answer(cmd, false, errMsg);
|
||||
}
|
||||
return new Answer(cmd, true, "success");
|
||||
|
||||
@ -88,6 +88,7 @@ import com.cloud.storage.StoragePoolVO;
|
||||
import com.cloud.storage.StorageStats;
|
||||
import com.cloud.storage.UploadVO;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateSwiftVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.Volume.Type;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
@ -99,6 +100,7 @@ import com.cloud.storage.dao.StoragePoolDao;
|
||||
import com.cloud.storage.dao.UploadDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
import com.cloud.storage.dao.VMTemplateSwiftDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountVO;
|
||||
@ -157,6 +159,7 @@ public class ApiDBUtils {
|
||||
private static StoragePoolDao _storagePoolDao;
|
||||
private static VMTemplateDao _templateDao;
|
||||
private static VMTemplateHostDao _templateHostDao;
|
||||
private static VMTemplateSwiftDao _templateSwiftDao;
|
||||
private static UploadDao _uploadDao;
|
||||
private static UserDao _userDao;
|
||||
private static UserStatisticsDao _userStatsDao;
|
||||
@ -204,6 +207,7 @@ public class ApiDBUtils {
|
||||
_storagePoolDao = locator.getDao(StoragePoolDao.class);
|
||||
_templateDao = locator.getDao(VMTemplateDao.class);
|
||||
_templateHostDao = locator.getDao(VMTemplateHostDao.class);
|
||||
_templateSwiftDao = locator.getDao(VMTemplateSwiftDao.class);
|
||||
_uploadDao = locator.getDao(UploadDao.class);
|
||||
_userDao = locator.getDao(UserDao.class);
|
||||
_userStatsDao = locator.getDao(UserStatisticsDao.class);
|
||||
@ -476,6 +480,12 @@ public class ApiDBUtils {
|
||||
return _storageMgr.getTemplateHostRef(zoneId, templateId, readyOnly);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static VMTemplateSwiftVO findTemplateSwiftRef(long templateId) {
|
||||
return _templateSwiftDao.findOneByTemplateId(templateId);
|
||||
}
|
||||
|
||||
public static UploadVO findUploadById(Long id) {
|
||||
return _uploadDao.findById(id);
|
||||
|
||||
@ -153,6 +153,7 @@ import com.cloud.storage.Swift;
|
||||
import com.cloud.storage.UploadVO;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.VMTemplateSwiftVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
@ -1375,8 +1376,79 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private List<TemplateResponse> createSwiftTemplateResponses(long templateId) {
|
||||
VirtualMachineTemplate template = findTemplateById(templateId);
|
||||
List<TemplateResponse> responses = new ArrayList<TemplateResponse>();
|
||||
VMTemplateSwiftVO templateSwiftRef = ApiDBUtils.findTemplateSwiftRef(templateId);
|
||||
if (templateSwiftRef == null) {
|
||||
return responses;
|
||||
}
|
||||
|
||||
TemplateResponse templateResponse = new TemplateResponse();
|
||||
templateResponse.setId(template.getId());
|
||||
templateResponse.setName(template.getName());
|
||||
templateResponse.setDisplayText(template.getDisplayText());
|
||||
templateResponse.setPublic(template.isPublicTemplate());
|
||||
templateResponse.setCreated(templateSwiftRef.getCreated());
|
||||
|
||||
templateResponse.setReady(true);
|
||||
templateResponse.setFeatured(template.isFeatured());
|
||||
templateResponse.setExtractable(template.isExtractable() && !(template.getTemplateType() == TemplateType.SYSTEM));
|
||||
templateResponse.setPasswordEnabled(template.getEnablePassword());
|
||||
templateResponse.setCrossZones(template.isCrossZones());
|
||||
templateResponse.setFormat(template.getFormat());
|
||||
if (template.getTemplateType() != null) {
|
||||
templateResponse.setTemplateType(template.getTemplateType().toString());
|
||||
}
|
||||
templateResponse.setHypervisor(template.getHypervisorType().toString());
|
||||
|
||||
GuestOS os = ApiDBUtils.findGuestOSById(template.getGuestOSId());
|
||||
if (os != null) {
|
||||
templateResponse.setOsTypeId(os.getId());
|
||||
templateResponse.setOsTypeName(os.getDisplayName());
|
||||
} else {
|
||||
templateResponse.setOsTypeId(-1L);
|
||||
templateResponse.setOsTypeName("");
|
||||
}
|
||||
|
||||
Account account = ApiDBUtils.findAccountByIdIncludingRemoved(template.getAccountId());
|
||||
populateAccount(templateResponse, account.getId());
|
||||
populateDomain(templateResponse, account.getDomainId());
|
||||
|
||||
Account caller = UserContext.current().getCaller();
|
||||
boolean isAdmin = false;
|
||||
if ((caller == null) || BaseCmd.isAdmin(caller.getType())) {
|
||||
isAdmin = true;
|
||||
}
|
||||
|
||||
// If the user is an Admin, add the template download status
|
||||
if (isAdmin || caller.getId() == template.getAccountId()) {
|
||||
// add download status
|
||||
templateResponse.setStatus("Successfully Installed");
|
||||
}
|
||||
|
||||
Long templateSize = templateSwiftRef.getSize();
|
||||
if (templateSize > 0) {
|
||||
templateResponse.setSize(templateSize);
|
||||
}
|
||||
|
||||
templateResponse.setChecksum(template.getChecksum());
|
||||
templateResponse.setSourceTemplateId(template.getSourceTemplateId());
|
||||
|
||||
templateResponse.setChecksum(template.getChecksum());
|
||||
|
||||
templateResponse.setTemplateTag(template.getTemplateTag());
|
||||
|
||||
templateResponse.setObjectName("template");
|
||||
responses.add(templateResponse);
|
||||
return responses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateResponse> createTemplateResponses(long templateId, long zoneId, boolean readyOnly) {
|
||||
if (zoneId == 0) {
|
||||
return createSwiftTemplateResponses(templateId);
|
||||
}
|
||||
VirtualMachineTemplate template = findTemplateById(templateId);
|
||||
List<TemplateResponse> responses = new ArrayList<TemplateResponse>();
|
||||
VMTemplateHostVO templateHostRef = ApiDBUtils.findTemplateHostRef(templateId, zoneId, readyOnly);
|
||||
@ -2437,8 +2509,10 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
|
||||
Domain domain = ApiDBUtils.findDomainById(object.getDomainId());
|
||||
response.setDomainId(domain.getId());
|
||||
response.setDomainName(domain.getName());
|
||||
if (domain != null) {
|
||||
response.setDomainId(domain.getId());
|
||||
response.setDomainName(domain.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void populateAccount(ControlledEntityResponse response, long accountId) {
|
||||
|
||||
@ -29,7 +29,8 @@ public interface ClusterDao extends GenericDao<ClusterVO, Long> {
|
||||
ClusterVO findBy(String name, long podId);
|
||||
List<ClusterVO> listByHyTypeWithoutGuid(String hyType);
|
||||
List<ClusterVO> listByZoneId(long zoneId);
|
||||
List<HypervisorType> getAvailableHypervisorInZone(long zoneId);
|
||||
|
||||
List<HypervisorType> getAvailableHypervisorInZone(Long zoneId);
|
||||
List<ClusterVO> listByDcHyType(long dcId, String hyType);
|
||||
Map<Long, List<Long>> getPodClusterIdMap(List<Long> clusterIds);
|
||||
List<Long> listDisabledClusters(long zoneId, Long podId);
|
||||
|
||||
@ -27,7 +27,6 @@ import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
@ -39,12 +38,9 @@ import com.cloud.utils.db.JoinBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.UpdateBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.SecondaryStorageVmVO;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
@Local(value=ClusterDao.class)
|
||||
public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements ClusterDao {
|
||||
@ -130,9 +126,11 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HypervisorType> getAvailableHypervisorInZone(long zoneId) {
|
||||
public List<HypervisorType> getAvailableHypervisorInZone(Long zoneId) {
|
||||
SearchCriteria<ClusterVO> sc = AvailHyperSearch.create();
|
||||
sc.setParameters("zoneId", zoneId);
|
||||
if (zoneId != null) {
|
||||
sc.setParameters("zoneId", zoneId);
|
||||
}
|
||||
List<ClusterVO> clusters = listBy(sc);
|
||||
List<HypervisorType> hypers = new ArrayList<HypervisorType>(4);
|
||||
for (ClusterVO cluster : clusters) {
|
||||
|
||||
@ -1383,23 +1383,31 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
hypers = _hostDao.getAvailHypervisorInZone(null, null);
|
||||
}
|
||||
Set<Pair<Long, Long>> templateZonePairSet = new HashSet<Pair<Long, Long>>();
|
||||
|
||||
if (template == null) {
|
||||
Boolean swiftEnable = Boolean.valueOf(_configDao.getValue(Config.SwiftEnable.key()));
|
||||
if (swiftEnable) {
|
||||
Boolean swiftEnable = Boolean.valueOf(_configDao.getValue(Config.SwiftEnable.key()));
|
||||
if (swiftEnable) {
|
||||
if (template == null) {
|
||||
templateZonePairSet = _templateDao.searchSwiftTemplates(name, keyword, templateFilter, isIso, hypers, bootable, domain, pageSize, startIndex, zoneId, hyperType, onlyReady, showDomr,
|
||||
permittedAccounts, caller);
|
||||
} else {
|
||||
templateZonePairSet = _templateDao.searchTemplates(name, keyword, templateFilter, isIso, hypers, bootable, domain, pageSize, startIndex, zoneId, hyperType, onlyReady, showDomr,
|
||||
permittedAccounts, caller);
|
||||
// if template is not public, perform permission check here
|
||||
if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
|
||||
Account owner = _accountMgr.getAccount(template.getAccountId());
|
||||
_accountMgr.checkAccess(caller, null, owner);
|
||||
}
|
||||
templateZonePairSet.add(new Pair<Long, Long>(template.getId(), 0L));
|
||||
}
|
||||
} else {
|
||||
// if template is not public, perform permission check here
|
||||
if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
|
||||
Account owner = _accountMgr.getAccount(template.getAccountId());
|
||||
_accountMgr.checkAccess(caller, null, owner);
|
||||
if (template == null) {
|
||||
templateZonePairSet = _templateDao.searchTemplates(name, keyword, templateFilter, isIso, hypers, bootable, domain, pageSize, startIndex, zoneId, hyperType, onlyReady, showDomr,
|
||||
permittedAccounts, caller);
|
||||
} else {
|
||||
// if template is not public, perform permission check here
|
||||
if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
|
||||
Account owner = _accountMgr.getAccount(template.getAccountId());
|
||||
_accountMgr.checkAccess(caller, null, owner);
|
||||
}
|
||||
templateZonePairSet.add(new Pair<Long, Long>(template.getId(), zoneId));
|
||||
}
|
||||
templateZonePairSet.add(new Pair<Long, Long>(template.getId(), zoneId));
|
||||
}
|
||||
|
||||
return templateZonePairSet;
|
||||
|
||||
@ -67,7 +67,7 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long> {
|
||||
public long addTemplateToZone(VMTemplateVO tmplt, long zoneId);
|
||||
public List<VMTemplateVO> listAllInZone(long dataCenterId);
|
||||
|
||||
public List<VMTemplateVO> listByHypervisorType(HypervisorType hyperType);
|
||||
public List<VMTemplateVO> listByHypervisorType(List<HypervisorType> hyperTypes);
|
||||
public List<VMTemplateVO> publicIsoSearch(Boolean bootable);
|
||||
VMTemplateVO findSystemVMTemplate(long zoneId);
|
||||
VMTemplateVO findSystemVMTemplate(long zoneId, HypervisorType hType);
|
||||
|
||||
@ -82,6 +82,9 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
private final String SELECT_TEMPLATE_ZONE_REF = "SELECT t.id, tzr.zone_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 INNER JOIN template_zone_ref tzr on (t.id = tzr.template_id) ";
|
||||
|
||||
private final String SELECT_TEMPLATE_SWIFT_REF = "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";
|
||||
|
||||
protected SearchBuilder<VMTemplateVO> TemplateNameSearch;
|
||||
protected SearchBuilder<VMTemplateVO> UniqueNameSearch;
|
||||
protected SearchBuilder<VMTemplateVO> tmpltTypeSearch;
|
||||
@ -209,9 +212,9 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VMTemplateVO> listByHypervisorType(HypervisorType hyperType) {
|
||||
public List<VMTemplateVO> listByHypervisorType(List<HypervisorType> hyperTypes) {
|
||||
SearchCriteria<VMTemplateVO> sc = createSearchCriteria();
|
||||
sc.addAnd("hypervisor_type", SearchCriteria.Op.EQ, hyperType.toString());
|
||||
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, hyperTypes.toArray());
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@ -327,26 +330,19 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
Set<Pair<Long, Long>> templateZonePairList = new HashSet<Pair<Long, Long>>();
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = SELECT_TEMPLATE_HOST_REF;
|
||||
String groupByClause = "";
|
||||
String sql = SELECT_TEMPLATE_SWIFT_REF;
|
||||
try {
|
||||
// short accountType;
|
||||
// String accountId = null;
|
||||
String guestOSJoin = "";
|
||||
StringBuilder templateHostRefJoin = new StringBuilder();
|
||||
String dataCenterJoin = "";
|
||||
String joinClause = "";
|
||||
String whereClause = " WHERE t.removed IS NULL";
|
||||
|
||||
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_swift_ref tsr on (t.id = tsr.template_id)");
|
||||
}
|
||||
|
||||
sql += guestOSJoin + templateHostRefJoin + dataCenterJoin;
|
||||
String whereClause = "";
|
||||
|
||||
if (!isIso) {
|
||||
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 {
|
||||
@ -361,72 +357,57 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
whereClause += " AND t.hypervisor_type IN (" + relatedHypers + ")";
|
||||
}
|
||||
}
|
||||
if (onlyReady) {
|
||||
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 += " WHERE t.public = 1 AND t.featured = 1";
|
||||
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) {
|
||||
whereClause += " INNER JOIN account a on (t.account_id = a.id) INNER JOIN domain d on (a.domain_id = d.id) WHERE d.path LIKE '" + domain.getPath() + "%'";
|
||||
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 += " WHERE t.account_id IN (" + permittedAccountsStr + ")";
|
||||
whereClause += " AND t.account_id IN (" + permittedAccountsStr + ")";
|
||||
}
|
||||
} else if (templateFilter == TemplateFilter.sharedexecutable && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
|
||||
whereClause += " LEFT JOIN launch_permission lp ON t.id = lp.template_id WHERE" + " (t.account_id IN (" + permittedAccountsStr + ") OR" + " lp.account_id IN ("
|
||||
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 {
|
||||
whereClause += " INNER JOIN account a on (t.account_id = a.id) ";
|
||||
joinClause += " INNER JOIN account a on (t.account_id = a.id) ";
|
||||
}
|
||||
} else if (templateFilter == TemplateFilter.executable && !permittedAccounts.isEmpty()) {
|
||||
whereClause += " WHERE (t.public = 1 OR t.account_id IN (" + permittedAccountsStr + "))";
|
||||
whereClause += " AND (t.public = 1 OR t.account_id IN (" + permittedAccountsStr + "))";
|
||||
} else if (templateFilter == TemplateFilter.community) {
|
||||
whereClause += " WHERE t.public = 1 AND t.featured = 0";
|
||||
whereClause += " AND t.public = 1 AND t.featured = 0";
|
||||
} else if (templateFilter == TemplateFilter.all && caller.getType() == Account.ACCOUNT_TYPE_ADMIN) {
|
||||
whereClause += " WHERE ";
|
||||
} else if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
|
||||
return templateZonePairList;
|
||||
}
|
||||
|
||||
if (whereClause.equals("")) {
|
||||
whereClause += " WHERE ";
|
||||
} else if (!whereClause.equals(" WHERE ")) {
|
||||
whereClause += " AND ";
|
||||
}
|
||||
|
||||
sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso, bootable, hyperType, zoneId, onlyReady, showDomr) + groupByClause + getOrderByLimit(pageSize, startIndex);
|
||||
|
||||
sql += joinClause + whereClause;
|
||||
pstmt = txn.prepareStatement(sql);
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
Pair<Long, Long> templateZonePair = new Pair<Long, Long>(rs.getLong(1), rs.getLong(2));
|
||||
Pair<Long, Long> templateZonePair = new Pair<Long, Long>(rs.getLong(1), 0L);
|
||||
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);
|
||||
for (int i = 0; i < publicIsos.size(); i++) {
|
||||
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 {
|
||||
|
||||
@ -59,6 +59,7 @@ import com.cloud.configuration.Resource.ResourceType;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.ActionEvent;
|
||||
@ -169,6 +170,8 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
VMTemplateSwiftDao _tmpltSwiftDao;
|
||||
@Inject
|
||||
ConfigurationDao _configDao;
|
||||
@Inject
|
||||
ClusterDao _clusterDao;
|
||||
@Inject DomainDao _domainDao;
|
||||
@Inject UploadDao _uploadDao;
|
||||
long _routerTemplateId = -1;
|
||||
@ -446,6 +449,10 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
return errMsg;
|
||||
}
|
||||
|
||||
if (template.getTemplateType() == TemplateType.PERHOST) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SwiftTO swift = _swiftDao.getSwiftTO(null);
|
||||
if (swift == null) {
|
||||
String errMsg = " There is no Swift in this setup ";
|
||||
@ -466,14 +473,17 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
try {
|
||||
answer = _agentMgr.sendToSSVM(secHost.getDataCenterId(), cmd);
|
||||
if (answer == null || !answer.getResult()) {
|
||||
String errMsg = "Failed to upload template to Swift from secondary storage due to " + ((answer == null) ? "null" : answer.getDetails());
|
||||
s_logger.warn(errMsg);
|
||||
throw new CloudRuntimeException(errMsg);
|
||||
if (template.getTemplateType() != TemplateType.SYSTEM) {
|
||||
String errMsg = "Failed to upload template " + templateId + " to Swift from secondary storage due to " + ((answer == null) ? "null" : answer.getDetails());
|
||||
s_logger.warn(errMsg);
|
||||
throw new CloudRuntimeException(errMsg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
VMTemplateSwiftVO tmpltSwift = new VMTemplateSwiftVO(swift.getId(), secHost.getId(), new Date(), templateHostRef.getSize(), templateHostRef.getPhysicalSize());
|
||||
VMTemplateSwiftVO tmpltSwift = new VMTemplateSwiftVO(swift.getId(), templateHostRef.getTemplateId(), new Date(), templateHostRef.getSize(), templateHostRef.getPhysicalSize());
|
||||
_tmpltSwiftDao.persist(tmpltSwift);
|
||||
} catch (Exception e) {
|
||||
String errMsg = "Failed to upload template to Swift from secondary storage due to " + e.toString();
|
||||
String errMsg = "Failed to upload template " + templateId + " to Swift from secondary storage due to " + e.toString();
|
||||
s_logger.warn(errMsg);
|
||||
throw new CloudRuntimeException(errMsg);
|
||||
}
|
||||
@ -807,17 +817,26 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
}
|
||||
|
||||
void swiftTemplateSync() {
|
||||
Boolean swiftEnable = Boolean.valueOf(_configDao.getValue(Config.SwiftEnable.key()));
|
||||
if (!swiftEnable) {
|
||||
return;
|
||||
}
|
||||
GlobalLock swiftTemplateSyncLock = GlobalLock.getInternLock("templatemgr.swiftTemplateSync");
|
||||
try {
|
||||
Boolean swiftEnable = Boolean.valueOf(_configDao.getValue(Config.SwiftEnable.key()));
|
||||
if (!swiftEnable) {
|
||||
return;
|
||||
}
|
||||
List<HypervisorType> hypers = _clusterDao.getAvailableHypervisorInZone(null);
|
||||
List<VMTemplateVO> templates = _tmpltDao.listByHypervisorType(hypers);
|
||||
List<Long> templateIds = new ArrayList<Long>();
|
||||
for (VMTemplateVO template : templates) {
|
||||
templateIds.add(template.getId());
|
||||
}
|
||||
if (swiftTemplateSyncLock.lock(3)) {
|
||||
try {
|
||||
List<VMTemplateHostVO> templtHostRefs = _tmpltHostDao.listByState(VMTemplateHostVO.Status.DOWNLOADED);
|
||||
List<VMTemplateSwiftVO> templtSwiftRefs = _tmpltSwiftDao.listAll();
|
||||
for (VMTemplateHostVO templtHostRef : templtHostRefs) {
|
||||
if (!templateIds.contains(templtHostRef.getId())) {
|
||||
continue;
|
||||
}
|
||||
boolean found = false;
|
||||
for (VMTemplateSwiftVO templtSwiftRef : templtSwiftRefs) {
|
||||
if (templtHostRef.getTemplateId() == templtSwiftRef.getTemplateId()) {
|
||||
@ -839,6 +858,8 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
swiftTemplateSyncLock.unlock();
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
s_logger.error("Problem with sync swift template due to " + e.toString(), e);
|
||||
} finally {
|
||||
swiftTemplateSyncLock.releaseRef();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user