mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Moving createDiskOffering to configurationManager, make AssignToLoadBalancer async
This commit is contained in:
		
							parent
							
								
									06881fa28f
								
							
						
					
					
						commit
						96f76062f9
					
				| @ -1826,18 +1826,6 @@ public interface ManagementServer { | |||||||
|      */ |      */ | ||||||
|     List<DiskOfferingVO> searchForDiskOfferings(Criteria c); |     List<DiskOfferingVO> searchForDiskOfferings(Criteria c); | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Create a disk offering |  | ||||||
|      * @param domainId the id of the domain in which the disk offering is valid |  | ||||||
|      * @param name the name of the disk offering |  | ||||||
|      * @param description a string description of the disk offering |  | ||||||
|      * @param numGibibytes the number of gibibytes in the disk offering (1 gibibyte = 1024 MB) |  | ||||||
|      * @param mirrored boolean value of whether or not the offering provides disk mirroring |  | ||||||
|      * @param tags Comma separated string to indicate special tags for the disk offering. |  | ||||||
|      * @return the created disk offering, null if failed to create |  | ||||||
|      */ |  | ||||||
|     DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException; |  | ||||||
| 
 |  | ||||||
|     /** |     /** | ||||||
|      * Delete a disk offering |      * Delete a disk offering | ||||||
|      * @param id id of the disk offering to delete |      * @param id id of the disk offering to delete | ||||||
|  | |||||||
| @ -13,6 +13,7 @@ import java.util.StringTokenizer; | |||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| 
 | 
 | ||||||
| import com.cloud.api.BaseCmd.CommandType; | import com.cloud.api.BaseCmd.CommandType; | ||||||
|  | import com.cloud.configuration.ConfigurationManager; | ||||||
| import com.cloud.network.NetworkManager; | import com.cloud.network.NetworkManager; | ||||||
| import com.cloud.server.ManagementServer; | import com.cloud.server.ManagementServer; | ||||||
| import com.cloud.storage.StorageManager; | import com.cloud.storage.StorageManager; | ||||||
| @ -27,6 +28,7 @@ import com.cloud.vm.UserVmManager; | |||||||
| public class ApiDispatcher { | public class ApiDispatcher { | ||||||
|     private static final Logger s_logger = Logger.getLogger(ApiDispatcher.class.getName()); |     private static final Logger s_logger = Logger.getLogger(ApiDispatcher.class.getName()); | ||||||
| 
 | 
 | ||||||
|  |     private ConfigurationManager _configMgr; | ||||||
|     private ManagementServer _mgmtServer; |     private ManagementServer _mgmtServer; | ||||||
|     private NetworkManager _networkMgr; |     private NetworkManager _networkMgr; | ||||||
|     private StorageManager _storageMgr; |     private StorageManager _storageMgr; | ||||||
| @ -35,6 +37,7 @@ public class ApiDispatcher { | |||||||
|     public ApiDispatcher() { |     public ApiDispatcher() { | ||||||
|         ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); |         ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); | ||||||
|         _mgmtServer = (ManagementServer)ComponentLocator.getComponent(ManagementServer.Name); |         _mgmtServer = (ManagementServer)ComponentLocator.getComponent(ManagementServer.Name); | ||||||
|  |         _configMgr = locator.getManager(ConfigurationManager.class); | ||||||
|         _networkMgr = locator.getManager(NetworkManager.class); |         _networkMgr = locator.getManager(NetworkManager.class); | ||||||
|         _storageMgr = locator.getManager(StorageManager.class); |         _storageMgr = locator.getManager(StorageManager.class); | ||||||
|         _userVmMgr = locator.getManager(UserVmManager.class); |         _userVmMgr = locator.getManager(UserVmManager.class); | ||||||
| @ -80,6 +83,9 @@ public class ApiDispatcher { | |||||||
|         String methodName = impl.method(); |         String methodName = impl.method(); | ||||||
|         Object mgr = _mgmtServer; |         Object mgr = _mgmtServer; | ||||||
|         switch (impl.manager()) { |         switch (impl.manager()) { | ||||||
|  |         case ConfigManager: | ||||||
|  |             mgr = _configMgr; | ||||||
|  |             break; | ||||||
|         case NetworkManager: |         case NetworkManager: | ||||||
|             mgr = _networkMgr; |             mgr = _networkMgr; | ||||||
|             break; |             break; | ||||||
|  | |||||||
| @ -48,7 +48,7 @@ public abstract class BaseCmd { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public enum Manager { |     public enum Manager { | ||||||
|     	ManagementServer, NetworkManager, StorageManager, UserVmManager |     	ConfigManager, ManagementServer, NetworkManager, StorageManager, UserVmManager | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // FIXME:  Extract these out into a separate file |     // FIXME:  Extract these out into a separate file | ||||||
|  | |||||||
| @ -15,20 +15,19 @@ | |||||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  *  |  *  | ||||||
|  */ |  */ | ||||||
| 
 |  | ||||||
| package com.cloud.api.commands; | package com.cloud.api.commands; | ||||||
| 
 | 
 | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| 
 | 
 | ||||||
| import com.cloud.api.BaseCmd; | import com.cloud.api.BaseAsyncCmd; | ||||||
| import com.cloud.api.BaseCmd.Manager; | import com.cloud.api.BaseCmd.Manager; | ||||||
| import com.cloud.api.Implementation; | import com.cloud.api.Implementation; | ||||||
| import com.cloud.api.Parameter; | import com.cloud.api.Parameter; | ||||||
| 
 | 
 | ||||||
| @Implementation(method="assignToLoadBalancer", manager=Manager.NetworkManager) | @Implementation(method="assignToLoadBalancer", manager=Manager.NetworkManager) | ||||||
| public class AssignToLoadBalancerRuleCmd extends BaseCmd { | public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd { | ||||||
|     public static final Logger s_logger = Logger.getLogger(AssignToLoadBalancerRuleCmd.class.getName()); |     public static final Logger s_logger = Logger.getLogger(AssignToLoadBalancerRuleCmd.class.getName()); | ||||||
| 
 | 
 | ||||||
|     private static final String s_name = "assigntoloadbalancerruleresponse"; |     private static final String s_name = "assigntoloadbalancerruleresponse"; | ||||||
|  | |||||||
| @ -18,36 +18,24 @@ | |||||||
| 
 | 
 | ||||||
| package com.cloud.api.commands; | package com.cloud.api.commands; | ||||||
| 
 | 
 | ||||||
| import java.util.ArrayList; | import java.util.Date; | ||||||
| import java.util.List; |  | ||||||
| import java.util.Map; |  | ||||||
| 
 | 
 | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| 
 | 
 | ||||||
| import com.cloud.api.BaseCmd; | import com.cloud.api.BaseCmd; | ||||||
|  | import com.cloud.api.BaseCmd.Manager; | ||||||
|  | import com.cloud.api.Implementation; | ||||||
| import com.cloud.api.Parameter; | import com.cloud.api.Parameter; | ||||||
| import com.cloud.api.ServerApiException; | import com.cloud.api.ServerApiException; | ||||||
| import com.cloud.domain.DomainVO; | import com.cloud.serializer.Param; | ||||||
| import com.cloud.exception.InvalidParameterValueException; | import com.cloud.serializer.SerializerHelper; | ||||||
| import com.cloud.storage.DiskOfferingVO; | import com.cloud.storage.DiskOfferingVO; | ||||||
| import com.cloud.utils.Pair; | 
 | ||||||
| 
 | @Implementation(method="createDiskOffering", manager=Manager.ConfigManager) | ||||||
| public class CreateDiskOfferingCmd extends BaseCmd { | public class CreateDiskOfferingCmd extends BaseCmd { | ||||||
|     public static final Logger s_logger = Logger.getLogger(CreateDiskOfferingCmd.class.getName()); |     public static final Logger s_logger = Logger.getLogger(CreateDiskOfferingCmd.class.getName()); | ||||||
| 
 | 
 | ||||||
|     private static final String s_name = "creatediskofferingresponse"; |     private static final String s_name = "creatediskofferingresponse"; | ||||||
|     private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>(); |  | ||||||
| 
 |  | ||||||
|     static { |  | ||||||
|     	s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.TRUE)); |  | ||||||
|         s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DISPLAY_TEXT, Boolean.TRUE)); |  | ||||||
|         s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DISK_SIZE, Boolean.TRUE)); |  | ||||||
| //        s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.IS_MIRRORED, Boolean.FALSE)); |  | ||||||
|         s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE)); |  | ||||||
|         s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.USER_ID, Boolean.FALSE)); |  | ||||||
|         s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE)); |  | ||||||
|         s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.TAGS, Boolean.FALSE)); |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     ///////////////////////////////////////////////////// |     ///////////////////////////////////////////////////// | ||||||
|     //////////////// API parameters ///////////////////// |     //////////////// API parameters ///////////////////// | ||||||
| @ -68,7 +56,6 @@ public class CreateDiskOfferingCmd extends BaseCmd { | |||||||
|     @Parameter(name="tags", type=CommandType.STRING) |     @Parameter(name="tags", type=CommandType.STRING) | ||||||
|     private String tags; |     private String tags; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     ///////////////////////////////////////////////////// |     ///////////////////////////////////////////////////// | ||||||
|     /////////////////// Accessors /////////////////////// |     /////////////////// Accessors /////////////////////// | ||||||
|     ///////////////////////////////////////////////////// |     ///////////////////////////////////////////////////// | ||||||
| @ -93,60 +80,128 @@ public class CreateDiskOfferingCmd extends BaseCmd { | |||||||
|         return tags; |         return tags; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     ///////////////////////////////////////////////////// |     ///////////////////////////////////////////////////// | ||||||
|     /////////////// API Implementation/////////////////// |     /////////////// API Implementation/////////////////// | ||||||
|     ///////////////////////////////////////////////////// |     ///////////////////////////////////////////////////// | ||||||
| 
 | 
 | ||||||
|  |     private DiskOfferingVO responseObject = null; | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public String getName() { |     public String getName() { | ||||||
|         return s_name; |         return s_name; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public List<Pair<Enum, Boolean>> getProperties() { |     public String getResponse() { | ||||||
|         return s_properties; |         DiskOfferingResponse response = new DiskOfferingResponse(); | ||||||
|  |         if (responseObject != null) { | ||||||
|  |             response.setId(responseObject.getId()); | ||||||
|  |             response.setCreated(responseObject.getCreated()); | ||||||
|  |             response.setDiskSize(responseObject.getDiskSize()); | ||||||
|  |             response.setDisplayText(responseObject.getDisplayText()); | ||||||
|  |             response.setDomainId(responseObject.getDomainId()); | ||||||
|  |             // FIXME:  domain name in the response | ||||||
|  | //            response.setDomain(responseObject.getDomain()); | ||||||
|  |             response.setName(responseObject.getName()); | ||||||
|  |             response.setTags(responseObject.getTags()); | ||||||
|  |         } else { | ||||||
|  |             throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create disk offering"); | ||||||
|  |         } | ||||||
|  |         return SerializerHelper.toSerializedString(responseObject); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setResponseObject(DiskOfferingVO diskOffering) { | ||||||
|  |         responseObject = diskOffering; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     // helper class for the response object | ||||||
|     public List<Pair<String, Object>> execute(Map<String, Object> params) { |     private class DiskOfferingResponse { | ||||||
|         // FIXME: add domain-private disk offerings |         @Param(name="id") | ||||||
| //        Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName()); |         private Long id; | ||||||
| //        Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName()); | 
 | ||||||
|         Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName()); |         @Param(name="domainid") | ||||||
|         String name = (String)params.get(BaseCmd.Properties.NAME.getName()); |         private Long domainId; | ||||||
|         String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName()); | 
 | ||||||
|         Long numGB = (Long) params.get(BaseCmd.Properties.DISK_SIZE.getName()); |         @Param(name="domain") | ||||||
| //        Boolean isMirrored = (Boolean)params.get(BaseCmd.Properties.IS_MIRRORED.getName()); |         private String domain; | ||||||
|         String tags = (String)params.get(BaseCmd.Properties.TAGS.getName()); | 
 | ||||||
| 
 |         @Param(name="name") | ||||||
| //        if (isMirrored == null) { |         private String name; | ||||||
| //            isMirrored = Boolean.FALSE; | 
 | ||||||
| //        } |         @Param(name="displaytext") | ||||||
|         if (domainId == null) { |         private String displayText; | ||||||
|             domainId = DomainVO.ROOT_DOMAIN; | 
 | ||||||
|         } |         @Param(name="disksize") | ||||||
| 
 |         private Long diskSize; | ||||||
|         DiskOfferingVO diskOffering = null; | 
 | ||||||
|         try { |         @Param(name="created") | ||||||
|         	diskOffering = getManagementServer().createDiskOffering(domainId.longValue(), name, displayText, numGB.intValue(),tags); |         private Date created; | ||||||
|         } catch (InvalidParameterValueException ex) { | 
 | ||||||
|         	throw new ServerApiException (BaseCmd.VM_INVALID_PARAM_ERROR, ex.getMessage()); |         @Param(name="tags") | ||||||
|         } |         private String tags; | ||||||
|          | 
 | ||||||
|         if (diskOffering == null) { |         public Long getId() { | ||||||
|             throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create disk offering"); |             return id; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>(); |         public void setId(Long id) { | ||||||
|         returnValues.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), Long.toString(diskOffering.getId()))); |             this.id = id; | ||||||
|         returnValues.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN_ID.getName(), diskOffering.getDomainId())); |         } | ||||||
|         returnValues.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN.getName(), getManagementServer().findDomainIdById(diskOffering.getDomainId()).getName())); | 
 | ||||||
|         returnValues.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), diskOffering.getName())); |         public Long getDomainId() { | ||||||
|         returnValues.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), diskOffering.getDisplayText())); |             return domainId; | ||||||
|         returnValues.add(new Pair<String, Object>(BaseCmd.Properties.DISK_SIZE.getName(), diskOffering.getDiskSizeInBytes())); |         } | ||||||
| //        returnValues.add(new Pair<String, Object>(BaseCmd.Properties.IS_MIRRORED.getName(), diskOffering.isMirrored())); | 
 | ||||||
|         returnValues.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), diskOffering.getCreated())); |         public void setDomainId(Long domainId) { | ||||||
|         returnValues.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), diskOffering.getTags())); |             this.domainId = domainId; | ||||||
|         return returnValues; |         } | ||||||
|  | 
 | ||||||
|  |         public String getDomain() { | ||||||
|  |             return domain; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public void setDomain(String domain) { | ||||||
|  |             this.domain = domain; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public String getName() { | ||||||
|  |             return name; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public void setName(String name) { | ||||||
|  |             this.name = name; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public String getDisplayText() { | ||||||
|  |             return displayText; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public void setDisplayText(String displayText) { | ||||||
|  |             this.displayText = displayText; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public Long getDiskSize() { | ||||||
|  |             return diskSize; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public void setDiskSize(Long diskSize) { | ||||||
|  |             this.diskSize = diskSize; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public Date getCreated() { | ||||||
|  |             return created; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public void setCreated(Date created) { | ||||||
|  |             this.created = created; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public String getTags() { | ||||||
|  |             return tags; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public void setTags(String tags) { | ||||||
|  |             this.tags = tags; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -19,10 +19,11 @@ package com.cloud.configuration; | |||||||
| 
 | 
 | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
|  | import com.cloud.api.commands.CreateDiskOfferingCmd; | ||||||
| import com.cloud.dc.DataCenterVO; | import com.cloud.dc.DataCenterVO; | ||||||
| import com.cloud.dc.HostPodVO; | import com.cloud.dc.HostPodVO; | ||||||
| import com.cloud.dc.VlanVO; |  | ||||||
| import com.cloud.dc.Vlan.VlanType; | import com.cloud.dc.Vlan.VlanType; | ||||||
|  | import com.cloud.dc.VlanVO; | ||||||
| import com.cloud.exception.InternalErrorException; | import com.cloud.exception.InternalErrorException; | ||||||
| import com.cloud.exception.InvalidParameterValueException; | import com.cloud.exception.InvalidParameterValueException; | ||||||
| import com.cloud.service.ServiceOfferingVO; | import com.cloud.service.ServiceOfferingVO; | ||||||
| @ -99,7 +100,7 @@ public interface ConfigurationManager extends Manager { | |||||||
| 	 * @param size | 	 * @param size | ||||||
| 	 * @return ID | 	 * @return ID | ||||||
| 	 */ | 	 */ | ||||||
| 	DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags); | 	DiskOfferingVO createDiskOffering(CreateDiskOfferingCmd cmd) throws InvalidParameterValueException; | ||||||
| 	 | 	 | ||||||
| 	/** | 	/** | ||||||
| 	 * Creates a new pod | 	 * Creates a new pod | ||||||
|  | |||||||
| @ -22,7 +22,6 @@ import java.sql.PreparedStatement; | |||||||
| import java.sql.ResultSet; | import java.sql.ResultSet; | ||||||
| import java.sql.SQLException; | import java.sql.SQLException; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.Date; |  | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| @ -32,20 +31,22 @@ import javax.naming.ConfigurationException; | |||||||
| 
 | 
 | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| 
 | 
 | ||||||
|  | import com.cloud.api.commands.CreateDiskOfferingCmd; | ||||||
| import com.cloud.configuration.dao.ConfigurationDao; | import com.cloud.configuration.dao.ConfigurationDao; | ||||||
| import com.cloud.dc.AccountVlanMapVO; | import com.cloud.dc.AccountVlanMapVO; | ||||||
| import com.cloud.dc.DataCenterVO; | import com.cloud.dc.DataCenterVO; | ||||||
| import com.cloud.dc.HostPodVO; | import com.cloud.dc.HostPodVO; | ||||||
| import com.cloud.dc.PodVlanMapVO; | import com.cloud.dc.PodVlanMapVO; | ||||||
| import com.cloud.dc.Vlan; | import com.cloud.dc.Vlan; | ||||||
| import com.cloud.dc.VlanVO; |  | ||||||
| import com.cloud.dc.Vlan.VlanType; | import com.cloud.dc.Vlan.VlanType; | ||||||
|  | import com.cloud.dc.VlanVO; | ||||||
| import com.cloud.dc.dao.AccountVlanMapDao; | import com.cloud.dc.dao.AccountVlanMapDao; | ||||||
| import com.cloud.dc.dao.DataCenterDao; | import com.cloud.dc.dao.DataCenterDao; | ||||||
| import com.cloud.dc.dao.DataCenterIpAddressDaoImpl; | import com.cloud.dc.dao.DataCenterIpAddressDaoImpl; | ||||||
| import com.cloud.dc.dao.HostPodDao; | import com.cloud.dc.dao.HostPodDao; | ||||||
| import com.cloud.dc.dao.PodVlanMapDao; | import com.cloud.dc.dao.PodVlanMapDao; | ||||||
| import com.cloud.dc.dao.VlanDao; | import com.cloud.dc.dao.VlanDao; | ||||||
|  | import com.cloud.domain.DomainVO; | ||||||
| import com.cloud.event.EventTypes; | import com.cloud.event.EventTypes; | ||||||
| import com.cloud.event.EventVO; | import com.cloud.event.EventVO; | ||||||
| import com.cloud.event.dao.EventDao; | import com.cloud.event.dao.EventDao; | ||||||
| @ -61,6 +62,7 @@ import com.cloud.user.AccountVO; | |||||||
| import com.cloud.user.UserVO; | import com.cloud.user.UserVO; | ||||||
| import com.cloud.user.dao.AccountDao; | import com.cloud.user.dao.AccountDao; | ||||||
| import com.cloud.user.dao.UserDao; | import com.cloud.user.dao.UserDao; | ||||||
|  | import com.cloud.utils.NumbersUtil; | ||||||
| import com.cloud.utils.component.Inject; | import com.cloud.utils.component.Inject; | ||||||
| import com.cloud.utils.db.DB; | import com.cloud.utils.db.DB; | ||||||
| import com.cloud.utils.db.Transaction; | import com.cloud.utils.db.Transaction; | ||||||
| @ -91,14 +93,21 @@ public class ConfigurationManagerImpl implements ConfigurationManager { | |||||||
| 	@Inject EventDao _eventDao; | 	@Inject EventDao _eventDao; | ||||||
| 	@Inject UserDao _userDao; | 	@Inject UserDao _userDao; | ||||||
| 	public boolean _premium; | 	public boolean _premium; | ||||||
|   | 
 | ||||||
|  | 	private int _maxVolumeSizeInGb; | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException { |     public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException { | ||||||
|     	_name = name; |     	_name = name; | ||||||
|          |          | ||||||
|         Object premium = params.get("premium"); |         Object premium = params.get("premium"); | ||||||
|         _premium = (premium != null) && ((String) premium).equals("true"); |         _premium = (premium != null) && ((String) premium).equals("true"); | ||||||
|          | 
 | ||||||
|  |         String maxVolumeSizeInGbString = _configDao.getValue("max.volume.size.gb"); | ||||||
|  |         int maxVolumeSizeGb = NumbersUtil.parseInt(maxVolumeSizeInGbString, 2000); | ||||||
|  | 
 | ||||||
|  |         _maxVolumeSizeInGb = maxVolumeSizeGb; | ||||||
|  | 
 | ||||||
|     	return true; |     	return true; | ||||||
|     } |     } | ||||||
|      |      | ||||||
| @ -897,9 +906,26 @@ public class ConfigurationManagerImpl implements ConfigurationManager { | |||||||
|     		return false; |     		return false; | ||||||
|     	} |     	} | ||||||
|     } |     } | ||||||
|      | 
 | ||||||
|     public DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) { |     @Override | ||||||
|     	long diskSize = numGibibytes * 1024; |     public DiskOfferingVO createDiskOffering(CreateDiskOfferingCmd cmd) throws InvalidParameterValueException { | ||||||
|  |         Long domainId = cmd.getDomainId(); | ||||||
|  |         String name = cmd.getOfferingName(); | ||||||
|  |         String description = cmd.getDisplayText(); | ||||||
|  |         int numGibibytes = cmd.getDiskSize().intValue(); | ||||||
|  |         String tags = cmd.getTags(); | ||||||
|  | 
 | ||||||
|  |         if (domainId == null) { | ||||||
|  |             domainId = Long.valueOf(DomainVO.ROOT_DOMAIN); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if ((numGibibytes != 0) && (numGibibytes < 1)) { | ||||||
|  |             throw new InvalidParameterValueException("Please specify a disk size of at least 1 Gb."); | ||||||
|  |         } else if (numGibibytes > _maxVolumeSizeInGb) { | ||||||
|  |             throw new InvalidParameterValueException("The maximum size for a disk is " + _maxVolumeSizeInGb + " Gb."); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         long diskSize = numGibibytes * 1024; | ||||||
|     	tags = cleanupTags(tags); |     	tags = cleanupTags(tags); | ||||||
| 		DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags); | 		DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags); | ||||||
| 		return _diskOfferingDao.persist(newDiskOffering); | 		return _diskOfferingDao.persist(newDiskOffering); | ||||||
|  | |||||||
| @ -355,7 +355,6 @@ public class ManagementServerImpl implements ManagementServer { | |||||||
|     private final int _proxyRamSize; |     private final int _proxyRamSize; | ||||||
|     private final int _ssRamSize; |     private final int _ssRamSize; | ||||||
| 
 | 
 | ||||||
|     private final int _maxVolumeSizeInGb; |  | ||||||
|     private final Map<String, Boolean> _availableIdsMap; |     private final Map<String, Boolean> _availableIdsMap; | ||||||
| 
 | 
 | ||||||
| 	private boolean _networkGroupsEnabled = false; | 	private boolean _networkGroupsEnabled = false; | ||||||
| @ -457,11 +456,6 @@ public class ManagementServerImpl implements ManagementServer { | |||||||
|         // Parse the max number of UserVMs and public IPs from server-setup.xml, |         // Parse the max number of UserVMs and public IPs from server-setup.xml, | ||||||
|         // and set them in the right places |         // and set them in the right places | ||||||
| 
 | 
 | ||||||
|         String maxVolumeSizeInGbString = _configs.get("max.volume.size.gb"); |  | ||||||
|         int maxVolumeSizeGb = NumbersUtil.parseInt(maxVolumeSizeInGbString, 2000); |  | ||||||
| 
 |  | ||||||
|         _maxVolumeSizeInGb = maxVolumeSizeGb; |  | ||||||
| 
 |  | ||||||
|         _routerRamSize = NumbersUtil.parseInt(_configs.get("router.ram.size"),NetworkManager.DEFAULT_ROUTER_VM_RAMSIZE); |         _routerRamSize = NumbersUtil.parseInt(_configs.get("router.ram.size"),NetworkManager.DEFAULT_ROUTER_VM_RAMSIZE); | ||||||
|         _proxyRamSize = NumbersUtil.parseInt(_configs.get("consoleproxy.ram.size"), ConsoleProxyManager.DEFAULT_PROXY_VM_RAMSIZE); |         _proxyRamSize = NumbersUtil.parseInt(_configs.get("consoleproxy.ram.size"), ConsoleProxyManager.DEFAULT_PROXY_VM_RAMSIZE); | ||||||
|         _ssRamSize = NumbersUtil.parseInt(_configs.get("secstorage.ram.size"), SecondaryStorageVmManager.DEFAULT_SS_VM_RAMSIZE); |         _ssRamSize = NumbersUtil.parseInt(_configs.get("secstorage.ram.size"), SecondaryStorageVmManager.DEFAULT_SS_VM_RAMSIZE); | ||||||
| @ -6733,17 +6727,6 @@ public class ManagementServerImpl implements ManagementServer { | |||||||
|         return _diskOfferingDao.search(sc, searchFilter); |         return _diskOfferingDao.search(sc, searchFilter); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |  | ||||||
|     public DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException { |  | ||||||
|         if (numGibibytes!=0 && numGibibytes < 1) { |  | ||||||
|             throw new InvalidParameterValueException("Please specify a disk size of at least 1 Gb."); |  | ||||||
|         } else if (numGibibytes > _maxVolumeSizeInGb) { |  | ||||||
|         	throw new InvalidParameterValueException("The maximum size for a disk is " + _maxVolumeSizeInGb + " Gb."); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return _configMgr.createDiskOffering(domainId, name, description, numGibibytes, tags); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |     @Override | ||||||
|     public DiskOfferingVO updateDiskOffering(long userId, long diskOfferingId, String name, String description, String tags) { |     public DiskOfferingVO updateDiskOffering(long userId, long diskOfferingId, String name, String description, String tags) { | ||||||
|     	return _configMgr.updateDiskOffering(userId, diskOfferingId, name, description, tags); |     	return _configMgr.updateDiskOffering(userId, diskOfferingId, name, description, tags); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user