From a94e8db110c08daf5aac33d7cf2da16809c01b85 Mon Sep 17 00:00:00 2001 From: prachi Date: Thu, 23 Dec 2010 14:11:24 -0800 Subject: [PATCH] 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. --- core/src/com/cloud/agent/AgentManager.java | 2 +- core/src/com/cloud/host/HostTagVO.java | 4 -- core/src/com/cloud/host/dao/DetailsDao.java | 1 - .../com/cloud/host/dao/DetailsDaoImpl.java | 30 ---------- .../com/cloud/server/ManagementServer.java | 4 +- .../com/cloud/service/ServiceOffering.java | 2 +- .../com/cloud/service/ServiceOfferingVO.java | 13 ++++- .../com/cloud/storage/dao/StoragePoolDao.java | 2 +- .../cloud/storage/dao/StoragePoolDaoImpl.java | 47 +++++++++------ .../cloud/agent/manager/AgentManagerImpl.java | 45 ++------------ .../commands/CreateServiceOfferingCmd.java | 11 ++-- .../com/cloud/api/commands/ListHostsCmd.java | 5 +- .../api/commands/ListServiceOfferingsCmd.java | 3 +- .../com/cloud/api/commands/UpdateHostCmd.java | 9 +-- .../configuration/ConfigurationManager.java | 2 +- .../ConfigurationManagerImpl.java | 6 +- .../cloud/migration/ServiceOffering21VO.java | 17 ++++++ .../cloud/server/ConfigurationServerImpl.java | 8 +-- .../cloud/server/ManagementServerImpl.java | 8 +-- ...HostTagBasedLocalStoragePoolAllocator.java | 58 ++++++------------- 20 files changed, 110 insertions(+), 167 deletions(-) diff --git a/core/src/com/cloud/agent/AgentManager.java b/core/src/com/cloud/agent/AgentManager.java index aa86b553307..28ed394bedd 100755 --- a/core/src/com/cloud/agent/AgentManager.java +++ b/core/src/com/cloud/agent/AgentManager.java @@ -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 diff --git a/core/src/com/cloud/host/HostTagVO.java b/core/src/com/cloud/host/HostTagVO.java index 3b1e898703a..97d9150f382 100644 --- a/core/src/com/cloud/host/HostTagVO.java +++ b/core/src/com/cloud/host/HostTagVO.java @@ -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 diff --git a/core/src/com/cloud/host/dao/DetailsDao.java b/core/src/com/cloud/host/dao/DetailsDao.java index ba7a87f7f4a..ca014a57252 100644 --- a/core/src/com/cloud/host/dao/DetailsDao.java +++ b/core/src/com/cloud/host/dao/DetailsDao.java @@ -32,5 +32,4 @@ public interface DetailsDao extends GenericDao { void deleteDetails(long hostId); - List findHostDetailsbyValue(long hostId, String value); } diff --git a/core/src/com/cloud/host/dao/DetailsDaoImpl.java b/core/src/com/cloud/host/dao/DetailsDaoImpl.java index 86e77a0a8e0..dd1d9d4d183 100644 --- a/core/src/com/cloud/host/dao/DetailsDaoImpl.java +++ b/core/src/com/cloud/host/dao/DetailsDaoImpl.java @@ -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 implements DetailsDao { protected final SearchBuilder HostSearch; protected final SearchBuilder 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 implements De } } - public List 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 detailNames = new ArrayList(); - - 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 details) { diff --git a/core/src/com/cloud/server/ManagementServer.java b/core/src/com/cloud/server/ManagementServer.java index 7202fc1d336..4400fc9189f 100644 --- a/core/src/com/cloud/server/ManagementServer.java +++ b/core/src/com/cloud/server/ManagementServer.java @@ -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 diff --git a/core/src/com/cloud/service/ServiceOffering.java b/core/src/com/cloud/service/ServiceOffering.java index c968f097ec6..c20b85c1739 100755 --- a/core/src/com/cloud/service/ServiceOffering.java +++ b/core/src/com/cloud/service/ServiceOffering.java @@ -76,6 +76,6 @@ public interface ServiceOffering { /* * @return tag that should be present on the host needed ; optional parameter */ - public String getHostTag(); + String getHostTag(); } diff --git a/core/src/com/cloud/service/ServiceOfferingVO.java b/core/src/com/cloud/service/ServiceOfferingVO.java index 49bc993c99b..2793cee50ed 100644 --- a/core/src/com/cloud/service/ServiceOfferingVO.java +++ b/core/src/com/cloud/service/ServiceOfferingVO.java @@ -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; } diff --git a/core/src/com/cloud/storage/dao/StoragePoolDao.java b/core/src/com/cloud/storage/dao/StoragePoolDao.java index b5b8de1b957..6d0212edcb7 100644 --- a/core/src/com/cloud/storage/dao/StoragePoolDao.java +++ b/core/src/com/cloud/storage/dao/StoragePoolDao.java @@ -77,7 +77,7 @@ public interface StoragePoolDao extends GenericDao { List findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared); - List findPoolsByHostTags(long dcId, long podId, Long clusterId, String[] hostTags, Boolean shared); + List findPoolsByHostTag(long dcId, long podId, Long clusterId, String hostTag); /** * Find pool by UUID. diff --git a/core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java b/core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java index 7f0adfcf35e..73b9c57050f 100644 --- a/core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java +++ b/core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java @@ -62,6 +62,10 @@ public class StoragePoolDaoImpl extends GenericDaoBase 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 imp } @Override - public List findPoolsByHostTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared) { - List storagePools = null; - if (tags == null || tags.length == 0) { - storagePools = listBy(dcId, podId, clusterId); - } else { - Map details = tagsToDetails(tags); - storagePools = findPoolsByDetails(dcId, podId, clusterId, details); + public List 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 filteredStoragePools = new ArrayList(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 pools = new ArrayList(); + while (rs.next()) { + pools.add(toEntityBean(rs, false)); + } + return pools; + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e); } + } @Override diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index 4eaae1cb8c4..d780eb82f3b 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -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 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 newHostTags = _configMgr.csvTagsToList(hostTags); - List 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 newHostTags, List 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"); diff --git a/server/src/com/cloud/api/commands/CreateServiceOfferingCmd.java b/server/src/com/cloud/api/commands/CreateServiceOfferingCmd.java index a8f596072dd..49797d5c161 100644 --- a/server/src/com/cloud/api/commands/CreateServiceOfferingCmd.java +++ b/server/src/com/cloud/api/commands/CreateServiceOfferingCmd.java @@ -46,7 +46,8 @@ public class CreateServiceOfferingCmd extends BaseCmd{ s_properties.add(new Pair(BaseCmd.Properties.OFFER_HA, Boolean.FALSE)); s_properties.add(new Pair(BaseCmd.Properties.USE_VIRTUAL_NETWORK, Boolean.FALSE)); s_properties.add(new Pair(BaseCmd.Properties.USER_ID, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.TAGS, Boolean.FALSE)); + s_properties.add(new Pair(BaseCmd.Properties.TAGS, Boolean.FALSE)); + s_properties.add(new Pair(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(BaseCmd.Properties.STORAGE_TYPE.getName(), storageType)); returnValues.add(new Pair(BaseCmd.Properties.OFFER_HA.getName(), offering.getOfferHA())); returnValues.add(new Pair(BaseCmd.Properties.USE_VIRTUAL_NETWORK.getName(), (offering.getGuestIpType().equals(GuestIpType.Virtualized)))); - returnValues.add(new Pair(BaseCmd.Properties.TAGS.getName(), offering.getTags())); + returnValues.add(new Pair(BaseCmd.Properties.TAGS.getName(), offering.getTags())); + returnValues.add(new Pair(BaseCmd.Properties.HOST_TAGS.getName(), offering.getHostTag())); } return returnValues; } diff --git a/server/src/com/cloud/api/commands/ListHostsCmd.java b/server/src/com/cloud/api/commands/ListHostsCmd.java index acd39d61a26..4b0cb28c1b3 100644 --- a/server/src/com/cloud/api/commands/ListHostsCmd.java +++ b/server/src/com/cloud/api/commands/ListHostsCmd.java @@ -181,7 +181,10 @@ public class ListHostsCmd extends BaseCmd { serverData.add(new Pair(BaseCmd.Properties.MEMORY_ALLOCATED.getName(), Long.valueOf(mem).toString())); // calculate memory utilized, we don't provide memory over commit - serverData.add(new Pair(BaseCmd.Properties.MEMORY_USED.getName(), mem)); + serverData.add(new Pair(BaseCmd.Properties.MEMORY_USED.getName(), mem)); + + //host_tags + serverData.add(new Pair(BaseCmd.Properties.HOST_TAGS.getName(), getManagementServer().getHostTags(server.getId()))); } if (server.getType().toString().equals("Storage")) { serverData.add(new Pair(BaseCmd.Properties.DISK_SIZE_TOTAL.getName(), Long.valueOf(server.getTotalSize()).toString())); diff --git a/server/src/com/cloud/api/commands/ListServiceOfferingsCmd.java b/server/src/com/cloud/api/commands/ListServiceOfferingsCmd.java index f1ef7a221a0..d301f9a8955 100644 --- a/server/src/com/cloud/api/commands/ListServiceOfferingsCmd.java +++ b/server/src/com/cloud/api/commands/ListServiceOfferingsCmd.java @@ -119,7 +119,8 @@ public class ListServiceOfferingsCmd extends BaseCmd { offeringData.add(new Pair(BaseCmd.Properties.STORAGE_TYPE.getName(), storageType)); offeringData.add(new Pair(BaseCmd.Properties.OFFER_HA.getName(), offering.getOfferHA())); offeringData.add(new Pair(BaseCmd.Properties.USE_VIRTUAL_NETWORK.getName(), (offering.getGuestIpType().equals(GuestIpType.Virtualized)))); - offeringData.add(new Pair(BaseCmd.Properties.TAGS.getName(), (offering.getTags()))); + offeringData.add(new Pair(BaseCmd.Properties.TAGS.getName(), (offering.getTags()))); + offeringData.add(new Pair(BaseCmd.Properties.HOST_TAGS.getName(), (offering.getHostTag()))); soTag[i++] = offeringData; } diff --git a/server/src/com/cloud/api/commands/UpdateHostCmd.java b/server/src/com/cloud/api/commands/UpdateHostCmd.java index 35e4978d21e..12225ded9de 100644 --- a/server/src/com/cloud/api/commands/UpdateHostCmd.java +++ b/server/src/com/cloud/api/commands/UpdateHostCmd.java @@ -50,8 +50,6 @@ public class UpdateHostCmd extends BaseCmd { static { s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.TRUE)); s_properties.add(new Pair(BaseCmd.Properties.OS_CATEGORY_ID, Boolean.FALSE)); - //host_tags - s_properties.add(new Pair(BaseCmd.Properties.HOST_TAGS, Boolean.FALSE)); } @Override @@ -71,8 +69,6 @@ public class UpdateHostCmd extends BaseCmd { public List> execute(Map 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> returnValues = new ArrayList>(); 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()); diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index 1633a1e636a..049640a0921 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -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 diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 6e3bc31a4be..ce38c622135 100644 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -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; diff --git a/server/src/com/cloud/migration/ServiceOffering21VO.java b/server/src/com/cloud/migration/ServiceOffering21VO.java index 232a143d55c..2e10d36f5e0 100644 --- a/server/src/com/cloud/migration/ServiceOffering21VO.java +++ b/server/src/com/cloud/migration/ServiceOffering21VO.java @@ -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; + } } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index a88502238b7..e635415eecf 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -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); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 065fb4ed7a0..6a7664180b3 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -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 diff --git a/server/src/com/cloud/storage/allocator/HostTagBasedLocalStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/HostTagBasedLocalStoragePoolAllocator.java index 30a162b2d43..4641e5d4e35 100644 --- a/server/src/com/cloud/storage/allocator/HostTagBasedLocalStoragePoolAllocator.java +++ b/server/src/com/cloud/storage/allocator/HostTagBasedLocalStoragePoolAllocator.java @@ -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 findPools(DiskCharacteristicsTO dskCh, ServiceOffering offering, DataCenterVO dc, HostPodVO pod, Long clusterId){ - List pools = _storagePoolDao.findPoolsByHostTags(dc.getId(), pod.getId(), clusterId, dskCh.getTags(), null); + List pools = new ArrayList(); + 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; } }