Bug 7473: host tags

Code changes and schema changes for adding/updating hostTags for hosts and serviceOffering. New local storage allocator 'HostTagBasedLocalStoragePoolAllocator' is added to search for storage pools that have associated hosts having the specified host tag.
This commit is contained in:
prachi 2010-12-23 14:11:24 -08:00
parent dcf335de6c
commit a94e8db110
20 changed files with 110 additions and 167 deletions

View File

@ -161,7 +161,7 @@ public interface AgentManager extends Manager {
* @param guestOSCategoryId
* @param hostTags
*/
void updateHost(long hostId, long guestOSCategoryId, String hostTags) throws UnsupportedOperationException;
void updateHost(long hostId, long guestOSCategoryId);
/**
* Deletes a host

View File

@ -1,14 +1,10 @@
package com.cloud.host;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
@Entity

View File

@ -32,5 +32,4 @@ public interface DetailsDao extends GenericDao<DetailVO, Long> {
void deleteDetails(long hostId);
List<String> findHostDetailsbyValue(long hostId, String value);
}

View File

@ -17,10 +17,6 @@
*/
package com.cloud.host.dao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -32,14 +28,12 @@ import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
@Local(value=DetailsDao.class)
public class DetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implements DetailsDao {
protected final SearchBuilder<DetailVO> HostSearch;
protected final SearchBuilder<DetailVO> DetailSearch;
private final String FindHostDetailsByValue = "SELECT host_details.name FROM host_details WHERE host_id = ? and value = ?";
protected DetailsDaoImpl() {
HostSearch = createSearchBuilder();
@ -85,30 +79,6 @@ public class DetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implements De
}
}
public List<String> findHostDetailsbyValue(long hostId, String value){
StringBuilder sql = new StringBuilder(FindHostDetailsByValue);
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, hostId);
pstmt.setString(2, value);
ResultSet rs = pstmt.executeQuery();
List<String> detailNames = new ArrayList<String>();
while (rs.next()) {
detailNames.add(rs.getString("name"));
}
return detailNames;
} catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + pstmt.toString(), e);
}
}
@Override
public void persist(long hostId, Map<String, String> details) {

View File

@ -826,7 +826,7 @@ public interface ManagementServer {
* @param hostId
* @param guestOSCategoryId
*/
void updateHost(long hostId, long guestOSCategoryId, String hostTags) throws InvalidParameterValueException, UnsupportedOperationException;
void updateHost(long hostId, long guestOSCategoryId) throws InvalidParameterValueException;
/**
* Deletes a host
@ -964,7 +964,7 @@ public interface ManagementServer {
* @param useVirtualNetwork
* @return the new ServiceOfferingVO
*/
ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags);
ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags, String hostTag);
/**
* Persists a pricing object

View File

@ -76,6 +76,6 @@ public interface ServiceOffering {
/*
* @return tag that should be present on the host needed ; optional parameter
*/
public String getHostTag();
String getHostTag();
}

View File

@ -61,8 +61,8 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
protected ServiceOfferingVO() {
super();
}
}
public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags) {
super(name, displayText, false, tags, recreatable, useLocalStorage);
this.cpu = cpu;
@ -72,6 +72,11 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
this.multicastRateMbps = multicastRateMbps;
this.offerHA = offerHA;
this.guestIpType = guestIpType;
}
public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags, String hostTag) {
this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, displayText, guestIpType, useLocalStorage, recreatable, tags);
this.hostTag = hostTag;
}
@Override
@ -145,6 +150,10 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
return guestIpType;
}
public void setHostTag(String hostTag) {
this.hostTag = hostTag;
}
public String getHostTag() {
return hostTag;
}

View File

@ -77,7 +77,7 @@ public interface StoragePoolDao extends GenericDao<StoragePoolVO, Long> {
List<StoragePoolVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared);
List<StoragePoolVO> findPoolsByHostTags(long dcId, long podId, Long clusterId, String[] hostTags, Boolean shared);
List<StoragePoolVO> findPoolsByHostTag(long dcId, long podId, Long clusterId, String hostTag);
/**
* Find pool by UUID.

View File

@ -62,6 +62,10 @@ public class StoragePoolDaoImpl extends GenericDaoBase<StoragePoolVO, Long> imp
private final String DetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING COUNT(storage_pool_details.name) >= ?";
private final String FindPoolTagDetails = "SELECT storage_pool_details.name FROM storage_pool_details WHERE pool_id = ? and value = ?";
private static final String PoolsByHostTag = "SELECT storage_pool.* from (host_tags JOIN storage_pool_host_ref ON host_tags.host_id = storage_pool_host_ref.host_id AND host_tags.tag = ?) JOIN storage_pool " +
"ON storage_pool.id = storage_pool_host_ref.pool_id WHERE storage_pool.removed is null and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null)";
protected StoragePoolDaoImpl() {
NameSearch = createSearchBuilder();
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
@ -304,27 +308,34 @@ public class StoragePoolDaoImpl extends GenericDaoBase<StoragePoolVO, Long> imp
}
@Override
public List<StoragePoolVO> findPoolsByHostTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared) {
List<StoragePoolVO> storagePools = null;
if (tags == null || tags.length == 0) {
storagePools = listBy(dcId, podId, clusterId);
} else {
Map<String, String> details = tagsToDetails(tags);
storagePools = findPoolsByDetails(dcId, podId, clusterId, details);
public List<StoragePoolVO> findPoolsByHostTag(long dcId, long podId, Long clusterId, String hostTag) {
StringBuilder sql = new StringBuilder(PoolsByHostTag);
if (clusterId != null) {
sql.append(" and (storage_pool.cluster_id = ? OR storage_pool.cluster_id IS NULL)");
}
if (shared == null) {
return storagePools;
} else {
List<StoragePoolVO> filteredStoragePools = new ArrayList<StoragePoolVO>(storagePools);
for (StoragePoolVO pool : storagePools) {
if (shared != pool.isShared()) {
filteredStoragePools.remove(pool);
}
}
return filteredStoragePools;
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = s_initStmt;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
int i = 1;
pstmt.setString(i++, hostTag);
pstmt.setLong(i++, dcId);
pstmt.setLong(i++, podId);
if (clusterId != null) {
pstmt.setLong(i++, clusterId);
}
ResultSet rs = pstmt.executeQuery();
List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
while (rs.next()) {
pools.add(toEntityBean(rs, false));
}
return pools;
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e);
}
}
@Override

View File

@ -1668,56 +1668,21 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
}
@Override
public void updateHost(long hostId, long guestOSCategoryId, String hostTags) throws UnsupportedOperationException{
public void updateHost(long hostId, long guestOSCategoryId){
GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
Map<String, String> hostDetails = _hostDetailsDao.findDetails(hostId);
boolean persistDetails = false;
String currentOSCategory = hostDetails.get("guest.os.category.id");
if (guestOSCategory != null) {
if(!String.valueOf(guestOSCategory.getId()).equals(currentOSCategory)){
// Save a new entry for guest.os.category.id
hostDetails.put("guest.os.category.id", String.valueOf(guestOSCategory.getId()));
persistDetails = true;
}
// Save a new entry for guest.os.category.id
hostDetails.put("guest.os.category.id", String.valueOf(guestOSCategory.getId()));
} else {
// Delete any existing entry for guest.os.category.id
if(currentOSCategory != null){
hostDetails.remove("guest.os.category.id");
persistDetails = true;
}
hostDetails.remove("guest.os.category.id");
}
if(persistDetails){
_hostDetailsDao.persist(hostId, hostDetails);
}
//update tags
List<String> newHostTags = _configMgr.csvTagsToList(hostTags);
List<String> oldHostTags = _hostTagsDao.gethostTags(hostId);
_hostDetailsDao.persist(hostId, hostDetails);
if(areExistingHostTagsRemoved(hostId, newHostTags, oldHostTags)){
//throw error - removing the existing host tags is not allowed
throw new UnsupportedOperationException("Invalid Operation: Cannot remove existing host tags");
}
//add the new tags to the host
newHostTags.removeAll(oldHostTags);
_hostTagsDao.persist(hostId, newHostTags);
}
private boolean areExistingHostTagsRemoved(long hostId, List<String> newHostTags, List<String> oldHostTags){
boolean tagsRemoved = false;
if(newHostTags.isEmpty() && !oldHostTags.isEmpty()){
tagsRemoved = true;
}else if(!newHostTags.isEmpty() && !oldHostTags.isEmpty()){
if(!newHostTags.containsAll(oldHostTags)){
tagsRemoved = true;
}
}
return tagsRemoved;
}
protected void updateHost(final HostVO host, final StartupCommand startup, final Host.Type type, final long msId) throws IllegalArgumentException {
s_logger.debug("updateHost() called");

View File

@ -46,7 +46,8 @@ public class CreateServiceOfferingCmd extends BaseCmd{
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.OFFER_HA, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.USE_VIRTUAL_NETWORK, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.USER_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.TAGS, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.TAGS, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.HOST_TAGS, Boolean.FALSE));
}
@Override
@ -75,7 +76,8 @@ public class CreateServiceOfferingCmd extends BaseCmd{
Boolean offerHA = (Boolean) params.get(BaseCmd.Properties.OFFER_HA.getName());
Boolean useVirtualNetwork = (Boolean) params.get(BaseCmd.Properties.USE_VIRTUAL_NETWORK.getName());
Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
String tags = (String)params.get(BaseCmd.Properties.TAGS.getName());
String tags = (String)params.get(BaseCmd.Properties.TAGS.getName());
String hostTag = (String)params.get(BaseCmd.Properties.HOST_TAGS.getName());
if (userId == null) {
userId = Long.valueOf(User.UID_SYSTEM);
@ -122,7 +124,7 @@ public class CreateServiceOfferingCmd extends BaseCmd{
ServiceOfferingVO offering = null;
try {
offering = getManagementServer().createServiceOffering(userId, name, cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), displayText, localStorageRequired, offerHA, useVirtualNetwork, tags);
offering = getManagementServer().createServiceOffering(userId, name, cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), displayText, localStorageRequired, offerHA, useVirtualNetwork, tags, hostTag);
} catch (Exception ex) {
s_logger.error("Exception creating service offering", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create service offering " + name + ": internal error.");
@ -143,7 +145,8 @@ public class CreateServiceOfferingCmd extends BaseCmd{
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE_TYPE.getName(), storageType));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.OFFER_HA.getName(), offering.getOfferHA()));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.USE_VIRTUAL_NETWORK.getName(), (offering.getGuestIpType().equals(GuestIpType.Virtualized))));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), offering.getTags()));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), offering.getTags()));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.HOST_TAGS.getName(), offering.getHostTag()));
}
return returnValues;
}

View File

@ -181,7 +181,10 @@ public class ListHostsCmd extends BaseCmd {
serverData.add(new Pair<String, Object>(BaseCmd.Properties.MEMORY_ALLOCATED.getName(), Long.valueOf(mem).toString()));
// calculate memory utilized, we don't provide memory over commit
serverData.add(new Pair<String, Object>(BaseCmd.Properties.MEMORY_USED.getName(), mem));
serverData.add(new Pair<String, Object>(BaseCmd.Properties.MEMORY_USED.getName(), mem));
//host_tags
serverData.add(new Pair<String, Object>(BaseCmd.Properties.HOST_TAGS.getName(), getManagementServer().getHostTags(server.getId())));
}
if (server.getType().toString().equals("Storage")) {
serverData.add(new Pair<String, Object>(BaseCmd.Properties.DISK_SIZE_TOTAL.getName(), Long.valueOf(server.getTotalSize()).toString()));

View File

@ -119,7 +119,8 @@ public class ListServiceOfferingsCmd extends BaseCmd {
offeringData.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE_TYPE.getName(), storageType));
offeringData.add(new Pair<String, Object>(BaseCmd.Properties.OFFER_HA.getName(), offering.getOfferHA()));
offeringData.add(new Pair<String, Object>(BaseCmd.Properties.USE_VIRTUAL_NETWORK.getName(), (offering.getGuestIpType().equals(GuestIpType.Virtualized))));
offeringData.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), (offering.getTags())));
offeringData.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), (offering.getTags())));
offeringData.add(new Pair<String, Object>(BaseCmd.Properties.HOST_TAGS.getName(), (offering.getHostTag())));
soTag[i++] = offeringData;
}

View File

@ -50,8 +50,6 @@ public class UpdateHostCmd extends BaseCmd {
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.OS_CATEGORY_ID, Boolean.FALSE));
//host_tags
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.HOST_TAGS, Boolean.FALSE));
}
@Override
@ -71,8 +69,6 @@ public class UpdateHostCmd extends BaseCmd {
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
Long guestOSCategoryId = (Long)params.get(BaseCmd.Properties.OS_CATEGORY_ID.getName());
//host_tags
String hostTags = (String)params.get(BaseCmd.Properties.HOST_TAGS.getName());
if (guestOSCategoryId == null) {
guestOSCategoryId = new Long(-1);
@ -88,10 +84,7 @@ public class UpdateHostCmd extends BaseCmd {
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
try {
getManagementServer().updateHost(id, guestOSCategoryId, hostTags);
} catch(UnsupportedOperationException uex){
s_logger.error("Failed to update host: ", uex);
throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "Failed to update host: " + uex.getMessage());
getManagementServer().updateHost(id, guestOSCategoryId);
} catch (Exception ex) {
s_logger.error("Failed to update host: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update host: " + ex.getMessage());

View File

@ -56,7 +56,7 @@ public interface ConfigurationManager extends Manager {
* @param useVirtualNetwork
* @return ID
*/
ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags);
ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags, String hostTag);
/**
* Updates a service offering

View File

@ -778,18 +778,18 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
return zone;
}
public ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags) {
public ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags, String hostTag) {
String networkRateStr = _configDao.getValue("network.throttling.rate");
String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr));
int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
GuestIpType guestIpType = useVirtualNetwork ? GuestIpType.Virtualized : GuestIpType.DirectSingle;
tags = cleanupTags(tags);
ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, guestIpType, localStorageRequired, false, tags);
ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, guestIpType, localStorageRequired, false, tags, hostTag);
if ((offering = _serviceOfferingDao.persist(offering)) != null) {
saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_CREATE, "Successfully created new service offering with name: " + name + ".", "soId=" + offering.getId(), "name=" + name, "numCPUs=" + cpu, "ram=" + ramSize, "cpuSpeed=" + speed,
"displayText=" + displayText, "guestIPType=" + guestIpType, "localStorageRequired=" + localStorageRequired, "offerHA=" + offerHA, "useVirtualNetwork=" + useVirtualNetwork, "tags=" + tags);
"displayText=" + displayText, "guestIPType=" + guestIpType, "localStorageRequired=" + localStorageRequired, "offerHA=" + offerHA, "useVirtualNetwork=" + useVirtualNetwork, "tags=" + tags, "host_tag=" + hostTag);
return offering;
} else {
return null;

View File

@ -10,6 +10,7 @@ import javax.persistence.Table;
import javax.persistence.Transient;
import com.cloud.service.ServiceOffering;
import com.cloud.service.ServiceOffering.GuestIpType;
@Entity
@Table(name="service_offering_21")
@ -38,6 +39,9 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe
@Enumerated(EnumType.STRING)
private GuestIpType guestIpType;
@Column(name="host_tag")
private String hostTag;
protected ServiceOffering21VO() {
super();
}
@ -52,6 +56,11 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe
this.offerHA = offerHA;
this.guestIpType = guestIpType;
}
public ServiceOffering21VO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags, String hostTag) {
this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, displayText, guestIpType, useLocalStorage, recreatable, tags);
this.hostTag = hostTag;
}
@Override
public boolean getOfferHA() {
@ -123,4 +132,12 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe
public GuestIpType getGuestIpType() {
return guestIpType;
}
public void setHostTag(String hostTag) {
this.hostTag = hostTag;
}
public String getHostTag() {
return hostTag;
}
}

View File

@ -132,8 +132,8 @@ public class ConfigurationServerImpl implements ConfigurationServer {
_snapPolicyDao.persist(snapPolicy);
// Save Virtual Networking service offerings
_configMgr.createServiceOffering(User.UID_SYSTEM, "Small Instance, Virtual Networking", 1, 512, 500, "Small Instance, Virtual Networking, $0.05 per hour", false, false, true, null);
_configMgr.createServiceOffering(User.UID_SYSTEM, "Medium Instance, Virtual Networking", 1, 1024, 1000, "Medium Instance, Virtual Networking, $0.10 per hour", false, false, true, null);
_configMgr.createServiceOffering(User.UID_SYSTEM, "Small Instance, Virtual Networking", 1, 512, 500, "Small Instance, Virtual Networking, $0.05 per hour", false, false, true, null, null);
_configMgr.createServiceOffering(User.UID_SYSTEM, "Medium Instance, Virtual Networking", 1, 1024, 1000, "Medium Instance, Virtual Networking, $0.10 per hour", false, false, true, null, null);
}
boolean externalIpAlloator = Boolean.parseBoolean(_configDao.getValue("direct.attach.network.externalIpAllocator.enabled"));
@ -144,8 +144,8 @@ public class ConfigurationServerImpl implements ConfigurationServer {
}
// Save Direct Networking service offerings
_configMgr.createServiceOffering(User.UID_SYSTEM, "Small Instance, Direct Networking", 1, 512, 500, "Small Instance, Direct Networking, $0.05 per hour", false, false, false, null);
_configMgr.createServiceOffering(User.UID_SYSTEM, "Medium Instance, Direct Networking", 1, 1024, 1000, "Medium Instance, Direct Networking, $0.10 per hour", false, false, false, null);
_configMgr.createServiceOffering(User.UID_SYSTEM, "Small Instance, Direct Networking", 1, 512, 500, "Small Instance, Direct Networking, $0.05 per hour", false, false, false, null, null);
_configMgr.createServiceOffering(User.UID_SYSTEM, "Medium Instance, Direct Networking", 1, 1024, 1000, "Medium Instance, Direct Networking, $0.10 per hour", false, false, false, null, null);
// Save default disk offerings
_configMgr.createDiskOffering(DomainVO.ROOT_DOMAIN, "Small", "Small Disk, 5 GB", 5, false, null);

View File

@ -2891,7 +2891,7 @@ public class ManagementServerImpl implements ManagementServer {
return _hostDao.findById(hostId);
}
public void updateHost(long hostId, long guestOSCategoryId, String hostTags) throws InvalidParameterValueException, UnsupportedOperationException {
public void updateHost(long hostId, long guestOSCategoryId) throws InvalidParameterValueException {
// Verify that the guest OS Category exists
if (guestOSCategoryId > 0) {
if (_guestOSCategoryDao.findById(guestOSCategoryId) == null) {
@ -2899,7 +2899,7 @@ public class ManagementServerImpl implements ManagementServer {
}
}
_agentMgr.updateHost(hostId, guestOSCategoryId, hostTags);
_agentMgr.updateHost(hostId, guestOSCategoryId);
}
public boolean deleteHost(long hostId) {
@ -4196,8 +4196,8 @@ public class ManagementServerImpl implements ManagementServer {
}
@Override
public ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags) {
return _configMgr.createServiceOffering(userId, name, cpu, ramSize, speed, displayText, localStorageRequired, offerHA, useVirtualNetwork, tags);
public ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags, String hostTag) {
return _configMgr.createServiceOffering(userId, name, cpu, ramSize, speed, displayText, localStorageRequired, offerHA, useVirtualNetwork, tags, hostTag);
}
@Override

View File

@ -17,56 +17,17 @@
*/
package com.cloud.storage.allocator;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.agent.manager.allocator.HostAllocator;
import com.cloud.agent.manager.allocator.impl.FirstFitAllocator;
import com.cloud.agent.api.to.DiskCharacteristicsTO;
import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.host.Host;
import com.cloud.service.ServiceOffering;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.ServiceOffering.GuestIpType;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.StoragePool;
import com.cloud.storage.StoragePoolHostVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.StoragePoolHostDao;
import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.vm.State;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VmCharacteristics;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao;
import com.cloud.storage.StoragePoolVO;
//
// TODO
// Rush to make LocalStoragePoolAllocator use static allocation status, we should revisit the overall
// allocation process to make it more reliable in next release. The code put in here is pretty ugly
//
@Local(value=StoragePoolAllocator.class)
public class HostTagBasedLocalStoragePoolAllocator extends LocalStoragePoolAllocator {
private static final Logger s_logger = Logger.getLogger(HostTagBasedLocalStoragePoolAllocator.class);
@ -76,7 +37,22 @@ public class HostTagBasedLocalStoragePoolAllocator extends LocalStoragePoolAlloc
@Override
protected List<StoragePoolVO> findPools(DiskCharacteristicsTO dskCh, ServiceOffering offering, DataCenterVO dc, HostPodVO pod, Long clusterId){
List<StoragePoolVO> pools = _storagePoolDao.findPoolsByHostTags(dc.getId(), pod.getId(), clusterId, dskCh.getTags(), null);
List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
if(offering != null && offering.getHostTag() != null){
String hostTag = offering.getHostTag();
pools = _storagePoolDao.findPoolsByHostTag(dc.getId(), pod.getId(), clusterId, hostTag);
if(pools.size() == 0){
if (s_logger.isInfoEnabled()) {
s_logger.info("No storage pools having associated Host with host tag: '"+ hostTag +"' available for pod id : " + pod.getId());
}
}else{
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found "+pools.size() +" storage pools having associated Host with host tag: '"+ hostTag +"' available for pod id : " + pod.getId());
}
}
}else{
pools = super.findPools(dskCh, offering, dc, pod, clusterId);
}
return pools;
}
}