You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/06/12 20:22:55 UTC

[46/50] [abbrv] Merge branch 'master' (up to commit c30d9be3cea30339cfff40c1002906634291b373) into object_store.

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18aeef3e/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/vm/UserVmManagerImpl.java
index cefaee5,b919f12..6cfb078
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@@ -32,9 -32,7 +32,10 @@@ import javax.ejb.Local
  import javax.inject.Inject;
  import javax.naming.ConfigurationException;
  
 +import org.apache.commons.codec.binary.Base64;
 +import org.apache.log4j.Logger;
 +
+ import com.cloud.server.ConfigurationServer;
  import org.apache.cloudstack.acl.ControlledEntity.ACLType;
  import org.apache.cloudstack.acl.SecurityChecker.AccessType;
  import org.apache.cloudstack.affinity.AffinityGroupVO;
@@@ -78,10 -77,11 +81,11 @@@ import com.cloud.agent.api.StartAnswer
  import com.cloud.agent.api.StopAnswer;
  import com.cloud.agent.api.UnPlugNicAnswer;
  import com.cloud.agent.api.UnPlugNicCommand;
+ import com.cloud.agent.api.VmDiskStatsEntry;
  import com.cloud.agent.api.VmStatsEntry;
 +import com.cloud.agent.api.to.DiskTO;
  import com.cloud.agent.api.to.NicTO;
  import com.cloud.agent.api.to.VirtualMachineTO;
 -import com.cloud.agent.api.to.VolumeTO;
  import com.cloud.agent.manager.Commands;
  import com.cloud.alert.AlertManager;
  import com.cloud.api.ApiDBUtils;
@@@ -399,7 -416,9 +413,11 @@@ public class UserVmManagerImpl extends 
      @Inject
      AffinityGroupDao _affinityGroupDao;
      @Inject
 +    TemplateDataFactory templateFactory;
++    @Inject
+     DedicatedResourceDao _dedicatedDao;
+     @Inject
+     ConfigurationServer _configServer;
  
      protected ScheduledExecutorService _executor = null;
      protected int _expungeInterval;
@@@ -1089,8 -1112,43 +1111,43 @@@
          }
  
      }
 -    
 +
      @Override
+     public HashMap<Long, List<VmDiskStatsEntry>> getVmDiskStatistics(long hostId, String hostName, List<Long> vmIds) throws CloudRuntimeException {
+         HashMap<Long, List<VmDiskStatsEntry>> vmDiskStatsById = new HashMap<Long, List<VmDiskStatsEntry>>();
+ 
+         if (vmIds.isEmpty()) {
+             return vmDiskStatsById;
+         }
+ 
+         List<String> vmNames = new ArrayList<String>();
+ 
+         for (Long vmId : vmIds) {
+             UserVmVO vm = _vmDao.findById(vmId);
+             vmNames.add(vm.getInstanceName());
+         }
+ 
+         Answer answer = _agentMgr.easySend(hostId, new GetVmDiskStatsCommand(vmNames, _hostDao.findById(hostId).getGuid(), hostName));
+         if (answer == null || !answer.getResult()) {
+             s_logger.warn("Unable to obtain VM disk statistics.");
+             return null;
+         } else {
+             HashMap<String, List<VmDiskStatsEntry>> vmDiskStatsByName = ((GetVmDiskStatsAnswer)answer).getVmDiskStatsMap();
+ 
+             if (vmDiskStatsByName == null) {
+                 s_logger.warn("Unable to obtain VM disk statistics.");
+                 return null;
+             }
+ 
+             for (String vmName : vmDiskStatsByName.keySet()) {
+                 vmDiskStatsById.put(vmIds.get(vmNames.indexOf(vmName)), vmDiskStatsByName.get(vmName));
+             }
+         }
+ 
+         return vmDiskStatsById;
+     }
+ 
+     @Override
      public boolean upgradeVirtualMachine(Long vmId, Long newServiceOfferingId) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException{
          Account caller = UserContext.current().getCaller();
  
@@@ -1151,8 -1240,17 +1239,17 @@@
                      s_logger.warn("Received exception while scaling ",e);
                  }finally{
                      if(!success){
-                         _itMgr.upgradeVmDb(vmId, oldServiceOffering.getId()); // rollback
+                         _itMgr.upgradeVmDb(vmId, currentServiceOffering.getId()); // rollback
+                         // Decrement CPU and Memory count accordingly.
+                         if (newCpu > currentCpu) {
+                             _resourceLimitMgr.decrementResourceCount(caller.getAccountId(), ResourceType.cpu, new Long (newCpu - currentCpu));
 -                        }
 +                    }
+                         if (newMemory > currentMemory) {
+                             _resourceLimitMgr.decrementResourceCount(caller.getAccountId(), ResourceType.memory, new Long (newMemory - currentMemory));
+                         }
+                     }
+ 
+ 
                  }
              }
          }
@@@ -3257,9 -3413,125 +3390,125 @@@
          } else {
              CloudRuntimeException ex = new CloudRuntimeException(
                      "Failed to destroy vm with specified vmId");
-             ex.addProxyObject(vm, vmId, "vmId");
+             ex.addProxyObject(vm.getUuid(), "vmId");
              throw ex;
          }
+ 
+     }
+ 
+     @Override
+     public void collectVmDiskStatistics (UserVmVO userVm) {
+     	// Collect vm disk statistics from host before stopping Vm
+     	long hostId = userVm.getHostId();
+     	List<String> vmNames = new ArrayList<String>();
+     	vmNames.add(userVm.getInstanceName());
+     	HostVO host = _hostDao.findById(hostId);
 -    	
++
+     	GetVmDiskStatsAnswer diskStatsAnswer = null;
+     	try {
+     		diskStatsAnswer = (GetVmDiskStatsAnswer) _agentMgr.easySend(hostId, new GetVmDiskStatsCommand(vmNames, host.getGuid(), host.getName()));
+     	} catch (Exception e) {
+             s_logger.warn("Error while collecting disk stats for vm: " + userVm.getHostName() + " from host: " + host.getName(), e);
+             return;
+         }
+         if (diskStatsAnswer != null) {
+             if (!diskStatsAnswer.getResult()) {
+                 s_logger.warn("Error while collecting disk stats vm: " + userVm.getHostName() + " from host: " + host.getName() + "; details: " + diskStatsAnswer.getDetails());
+                 return;
+             }
+             Transaction txn = Transaction.open(Transaction.CLOUD_DB);
+             try {
+                 txn.start();
+                 HashMap<String, List<VmDiskStatsEntry>> vmDiskStatsByName = diskStatsAnswer.getVmDiskStatsMap();
+                 List<VmDiskStatsEntry> vmDiskStats = vmDiskStatsByName.get(userVm.getInstanceName());
 -                
++
+                 if (vmDiskStats == null)
+ 		    return;
 -	        	
++
+ 	        for (VmDiskStatsEntry vmDiskStat:vmDiskStats) {
+                     SearchCriteria<VolumeVO> sc_volume = _volsDao.createSearchCriteria();
+                     sc_volume.addAnd("path", SearchCriteria.Op.EQ, vmDiskStat.getPath());
+                     VolumeVO volume = _volsDao.search(sc_volume, null).get(0);
+ 	            VmDiskStatisticsVO previousVmDiskStats = _vmDiskStatsDao.findBy(userVm.getAccountId(), userVm.getDataCenterId(), userVm.getId(), volume.getId());
+ 	            VmDiskStatisticsVO vmDiskStat_lock = _vmDiskStatsDao.lock(userVm.getAccountId(), userVm.getDataCenterId(), userVm.getId(), volume.getId());
 -	                
++
+ 	                if ((vmDiskStat.getIORead() == 0) && (vmDiskStat.getIOWrite() == 0) && (vmDiskStat.getBytesRead() == 0) && (vmDiskStat.getBytesWrite() == 0)) {
+ 	                    s_logger.debug("Read/Write of IO and Bytes are both 0. Not updating vm_disk_statistics");
+ 	                    continue;
+ 	                }
 -	                
++
+ 	                if (vmDiskStat_lock == null) {
+ 	                    s_logger.warn("unable to find vm disk stats from host for account: " + userVm.getAccountId() + " with vmId: " + userVm.getId()+ " and volumeId:" + volume.getId());
+ 	                    continue;
+ 	                }
 -	
++
+ 	                if (previousVmDiskStats != null
+ 	                        && ((previousVmDiskStats.getCurrentIORead() != vmDiskStat_lock.getCurrentIORead())
+ 	                        || ((previousVmDiskStats.getCurrentIOWrite() != vmDiskStat_lock.getCurrentIOWrite())
+ 	                        || (previousVmDiskStats.getCurrentBytesRead() != vmDiskStat_lock.getCurrentBytesRead())
+ 	    	                || (previousVmDiskStats.getCurrentBytesWrite() != vmDiskStat_lock.getCurrentBytesWrite())))) {
+ 	                    s_logger.debug("vm disk stats changed from the time GetVmDiskStatsCommand was sent. " +
 -	                            "Ignoring current answer. Host: " + host.getName() + " . VM: " + vmDiskStat.getVmName() + 
++	                            "Ignoring current answer. Host: " + host.getName() + " . VM: " + vmDiskStat.getVmName() +
+ 	                            " IO Read: " + vmDiskStat.getIORead() + " IO Write: " + vmDiskStat.getIOWrite() +
+ 	                            " Bytes Read: " + vmDiskStat.getBytesRead() + " Bytes Write: " + vmDiskStat.getBytesWrite());
+ 	                    continue;
+ 	                }
 -	
++
+ 	                if (vmDiskStat_lock.getCurrentIORead() > vmDiskStat.getIORead()) {
+ 	                    if (s_logger.isDebugEnabled()) {
+ 	                        s_logger.debug("Read # of IO that's less than the last one.  " +
+ 	                                "Assuming something went wrong and persisting it. Host: " + host.getName() + " . VM: " + vmDiskStat.getVmName() +
+ 	                                " Reported: " + vmDiskStat.getIORead() + " Stored: " + vmDiskStat_lock.getCurrentIORead());
+ 	                    }
+ 	                    vmDiskStat_lock.setNetIORead(vmDiskStat_lock.getNetIORead() + vmDiskStat_lock.getCurrentIORead());
+ 	                }
+ 	                vmDiskStat_lock.setCurrentIORead(vmDiskStat.getIORead());
+ 	                if (vmDiskStat_lock.getCurrentIOWrite() > vmDiskStat.getIOWrite()) {
+ 	                    if (s_logger.isDebugEnabled()) {
+ 	                        s_logger.debug("Write # of IO that's less than the last one.  " +
+ 	                                "Assuming something went wrong and persisting it. Host: " + host.getName() + " . VM: " + vmDiskStat.getVmName() +
+ 	                                " Reported: " + vmDiskStat.getIOWrite() + " Stored: " + vmDiskStat_lock.getCurrentIOWrite());
+ 	                    }
+ 	                    vmDiskStat_lock.setNetIOWrite(vmDiskStat_lock.getNetIOWrite() + vmDiskStat_lock.getCurrentIOWrite());
+ 	                }
+ 	                vmDiskStat_lock.setCurrentIOWrite(vmDiskStat.getIOWrite());
+ 	                if (vmDiskStat_lock.getCurrentBytesRead() > vmDiskStat.getBytesRead()) {
+ 	                    if (s_logger.isDebugEnabled()) {
+ 	                        s_logger.debug("Read # of Bytes that's less than the last one.  " +
+ 	                                "Assuming something went wrong and persisting it. Host: " + host.getName() + " . VM: " + vmDiskStat.getVmName() +
+ 	                                " Reported: " + vmDiskStat.getBytesRead() + " Stored: " + vmDiskStat_lock.getCurrentBytesRead());
+ 	                    }
+ 	                    vmDiskStat_lock.setNetBytesRead(vmDiskStat_lock.getNetBytesRead() + vmDiskStat_lock.getCurrentBytesRead());
+ 	                }
+ 	                vmDiskStat_lock.setCurrentBytesRead(vmDiskStat.getBytesRead());
+ 	                if (vmDiskStat_lock.getCurrentBytesWrite() > vmDiskStat.getBytesWrite()) {
+ 	                    if (s_logger.isDebugEnabled()) {
+ 	                        s_logger.debug("Write # of Bytes that's less than the last one.  " +
+ 	                                "Assuming something went wrong and persisting it. Host: " + host.getName() + " . VM: " + vmDiskStat.getVmName() +
+ 	                                " Reported: " + vmDiskStat.getBytesWrite() + " Stored: " + vmDiskStat_lock.getCurrentBytesWrite());
+ 	                    }
+ 	                    vmDiskStat_lock.setNetBytesWrite(vmDiskStat_lock.getNetBytesWrite() + vmDiskStat_lock.getCurrentBytesWrite());
+ 	                }
+ 	                vmDiskStat_lock.setCurrentBytesWrite(vmDiskStat.getBytesWrite());
 -	                
++
+ 	                if (! _dailyOrHourly) {
 -	                    //update agg bytes 
++	                    //update agg bytes
+ 	                	vmDiskStat_lock.setAggIORead(vmDiskStat_lock.getNetIORead() + vmDiskStat_lock.getCurrentIORead());
+ 	                	vmDiskStat_lock.setAggIOWrite(vmDiskStat_lock.getNetIOWrite() + vmDiskStat_lock.getCurrentIOWrite());
+ 	                	vmDiskStat_lock.setAggBytesRead(vmDiskStat_lock.getNetBytesRead() + vmDiskStat_lock.getCurrentBytesRead());
+ 	                	vmDiskStat_lock.setAggBytesWrite(vmDiskStat_lock.getNetBytesWrite() + vmDiskStat_lock.getCurrentBytesWrite());
+ 	                }
 -	
++
+ 	                _vmDiskStatsDao.update(vmDiskStat_lock.getId(), vmDiskStat_lock);
+ 	        	}
+ 	        	txn.commit();
+             } catch (Exception e) {
+                 txn.rollback();
+                 s_logger.warn("Unable to update vm disk statistics for vm: " + userVm.getId() + " from host: " + hostId, e);
+             } finally {
+                 txn.close();
+             }
+         }
      }
  
  
@@@ -4267,13 -4582,21 +4559,21 @@@
              }
          }
  
-         /* If new template is provided allocate a new volume from new template otherwise allocate new volume from original template */
+         /* If new template/ISO is provided allocate a new volume from new template/ISO otherwise allocate new volume from original template/ISO */
          VolumeVO newVol = null;
-         if (newTemplateId != null){
+         if (newTemplateId != null) {
+             if (isISO) {
+                 newVol = volumeMgr.allocateDuplicateVolume(root, null);
+                 vm.setIsoId(newTemplateId);
+                 vm.setGuestOSId(template.getGuestOSId());
+                 vm.setTemplateId(newTemplateId);
+                 _vmDao.update(vmId, vm);
+             } else {
 -                newVol = volumeMgr.allocateDuplicateVolume(root, newTemplateId);
 -                vm.setGuestOSId(template.getGuestOSId());
 -                vm.setTemplateId(newTemplateId);
 -                _vmDao.update(vmId, vm);
 +            newVol = volumeMgr.allocateDuplicateVolume(root, newTemplateId);
 +            vm.setGuestOSId(template.getGuestOSId());
 +            vm.setTemplateId(newTemplateId);
 +            _vmDao.update(vmId, vm);
+             }
          } else {
              newVol = volumeMgr.allocateDuplicateVolume(root, null);
          }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18aeef3e/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 5dde711,568fe55..c938e78
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@@ -2836,8 -2836,8 +2836,8 @@@ public class VirtualMachineManagerImpl 
                      long isDefault = (nic.isDefaultNic()) ? 1 : 0;
                      // insert nic's Id into DB as resource_name
                      UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmVO.getAccountId(),
-                             vmVO.getDataCenterId(), vmVO.getId(), Long.toString(nic.getId()), nic.getNetworkId(),
+                             vmVO.getDataCenterId(), vmVO.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(),
 -                            null, isDefault, VirtualMachine.class.getName(), vmVO.getUuid());
 +                            null, isDefault, VirtualMachine.class.getName(), vmVO.getUuid());                     
                      return nic;
                  } else {
                      s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18aeef3e/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18aeef3e/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --cc setup/db/db/schema-410to420.sql
index fd2ac56,bcfbcc9..74d4cae
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@@ -33,13 -35,14 +35,14 @@@ INSERT IGNORE INTO `cloud`.`configurati
  INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'midonet.providerrouter.id', 'd7c5e6a3-e2f4-426b-b728-b7ce6a0448e5', 'Specifies the UUID of the Midonet provider router (if using Midonet)');
  ALTER TABLE `cloud`.`load_balancer_vm_map` ADD state VARCHAR(40) NULL COMMENT 'service status updated by LB healthcheck manager';
  
+ alter table storage_pool add hypervisor varchar(32);
  alter table storage_pool change storage_provider_id storage_provider_name varchar(255);
 -alter table template_host_ref add state varchar(255);
 -alter table template_host_ref add update_count bigint unsigned;
 -alter table template_host_ref add updated datetime;
 -alter table volume_host_ref add state varchar(255);
 -alter table volume_host_ref add update_count bigint unsigned;
 -alter table volume_host_ref add updated datetime;
 +-- alter table template_host_ref add state varchar(255);
 +-- alter table template_host_ref add update_count bigint unsigned;
 +-- alter table template_host_ref add updated datetime;
 +-- alter table volume_host_ref add state varchar(255);
 +-- alter table volume_host_ref add update_count bigint unsigned;
 +-- alter table volume_host_ref add updated datetime;
  alter table template_spool_ref add updated datetime;
  CREATE TABLE  `cloud`.`object_datastore_ref` (
    `id` bigint unsigned NOT NULL auto_increment,
@@@ -1943,8 -1765,92 +2001,92 @@@ update `cloud`.`vpc_gateways` set netwo
  
  INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'VpcManager', 'blacklisted.routes', NULL, 'Routes that are blacklisted, can not be used for Static Routes creation for the VPC Private Gateway');
  
+ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'enable.dynamic.scale.vm', 'false', 'Enables/Diables dynamically scaling a vm');
+ 
+ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'scale.retry', '2', 'Number of times to retry scaling up the vm');
+ 
+ UPDATE `cloud`.`snapshots` set swift_id=null where swift_id=0;
+ 
+ DROP TABLE IF EXISTS `cloud`.`vm_disk_statistics`;
+ CREATE TABLE `cloud`.`vm_disk_statistics` (
+   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+   `data_center_id` bigint(20) unsigned NOT NULL,
+   `account_id` bigint(20) unsigned NOT NULL,
+   `vm_id` bigint(20) unsigned NOT NULL,
+   `volume_id` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `net_io_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `net_io_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `current_io_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `current_io_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `agg_io_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `agg_io_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `net_bytes_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `net_bytes_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `current_bytes_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `current_bytes_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `agg_bytes_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `agg_bytes_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   PRIMARY KEY (`id`),
+   UNIQUE KEY `id` (`id`),
+   UNIQUE KEY `account_id` (`account_id`,`data_center_id`,`vm_id`,`volume_id`),
+   KEY `i_vm_disk_statistics__account_id` (`account_id`),
+   KEY `i_vm_disk_statistics__account_id_data_center_id` (`account_id`,`data_center_id`),
+   CONSTRAINT `fk_vm_disk_statistics__account_id` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE
+ ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
+ 
+ insert into `cloud`.`vm_disk_statistics`(data_center_id,account_id,vm_id,volume_id) 
+ select volumes.data_center_id, volumes.account_id, vm_instance.id, volumes.id from volumes,vm_instance where vm_instance.vm_type="User" and vm_instance.state<>"Expunging" and volumes.instance_id=vm_instance.id order by vm_instance.id;
+ 
+ DROP TABLE IF EXISTS `cloud_usage`.`vm_disk_statistics`;
+ CREATE TABLE `cloud_usage`.`vm_disk_statistics` (
+   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+   `data_center_id` bigint(20) unsigned NOT NULL,
+   `account_id` bigint(20) unsigned NOT NULL,
+   `vm_id` bigint(20) unsigned NOT NULL,
+   `volume_id` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `net_io_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `net_io_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `current_io_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `current_io_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `agg_io_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `agg_io_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `net_bytes_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `net_bytes_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `current_bytes_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `current_bytes_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `agg_bytes_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `agg_bytes_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   PRIMARY KEY (`id`),
+   UNIQUE KEY `id` (`id`),
+   UNIQUE KEY `account_id` (`account_id`,`data_center_id`,`vm_id`,`volume_id`)
+ ) ENGINE=InnoDB CHARSET=utf8;
+ 
+ insert into `cloud_usage`.`vm_disk_statistics` select * from `cloud`.`vm_disk_statistics`;
+ 
+ DROP TABLE IF EXISTS `cloud_usage`.`usage_vm_disk`;
+ CREATE TABLE `cloud_usage`.`usage_vm_disk` (
+   `account_id` bigint(20) unsigned NOT NULL,
+   `zone_id` bigint(20) unsigned NOT NULL,
+   `vm_id` bigint(20) unsigned NOT NULL,
+   `volume_id` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `io_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `io_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `agg_io_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `agg_io_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `bytes_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `bytes_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `agg_bytes_read` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `agg_bytes_write` bigint(20) unsigned NOT NULL DEFAULT '0',
+   `event_time_millis` bigint(20) unsigned NOT NULL DEFAULT '0',
+   PRIMARY KEY (`account_id`,`zone_id`,`vm_id`,`volume_id`,`event_time_millis`)
+ ) ENGINE=InnoDB CHARSET=utf8;
+ 
+ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'vm.disk.stats.interval', 0, 'Interval (in seconds) to report vm disk statistics.');
+ 
  
  -- Re-enable foreign key checking, at the end of the upgrade path
 -SET foreign_key_checks = 1;
 +SET foreign_key_checks = 1;			
- UPDATE `cloud`.`snapshot_policy` set uuid=id WHERE uuid is NULL;
  
+ UPDATE `cloud`.`snapshot_policy` set uuid=id WHERE uuid is NULL;
+ #update shared sg enabled network with not null name in Advance Security Group enabled network
+ UPDATE `cloud`.`networks` set name='Shared SG enabled network', display_text='Shared SG enabled network' WHERE name IS null AND traffic_type='Guest' AND data_center_id IN (select id from data_center where networktype='Advanced' and is_security_group_enabled=1) AND acl_type='Domain';

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18aeef3e/test/integration/smoke/test_volumes.py
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18aeef3e/tools/apidoc/gen_toc.py
----------------------------------------------------------------------
diff --cc tools/apidoc/gen_toc.py
index 5d7e3be,3dd526a..43dad99
--- a/tools/apidoc/gen_toc.py
+++ b/tools/apidoc/gen_toc.py
@@@ -141,13 -142,11 +142,15 @@@ known_categories = 
      'removeIpFromNic': 'Nic',
      'listNics':'Nic',
  	'AffinityGroup': 'Affinity Group',
 +    'addImageStore': 'Image Store',
 +    'listImageStore': 'Image Store',
 +    'deleteImageStore': 'Image Store',
 +    'createCacheStore': 'Image Store',
      'InternalLoadBalancer': 'Internal LB',
  	'DeploymentPlanners': 'Configuration',
-     'PortableIp': 'Portable IP'
+     'PortableIp': 'Portable IP',
+     'dedicateHost': 'Dedicate Resources',
+     'releaseDedicatedHost': 'Dedicate Resources'
      }
  
  

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18aeef3e/tools/devcloud/devcloud.cfg
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18aeef3e/tools/marvin/marvin/configGenerator.py
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18aeef3e/tools/marvin/marvin/deployDataCenter.py
----------------------------------------------------------------------
diff --cc tools/marvin/marvin/deployDataCenter.py
index e8e3a8f,cf5cf78..b42d79d
--- a/tools/marvin/marvin/deployDataCenter.py
+++ b/tools/marvin/marvin/deployDataCenter.py
@@@ -320,7 -300,8 +320,8 @@@ class deployDataCenters()
              createzone.securitygroupenabled = zone.securitygroupenabled
              createzone.localstorageenabled = zone.localstorageenabled
              createzone.networktype = zone.networktype
+             if zone.securitygroupenabled != "true":
 -                createzone.guestcidraddress = zone.guestcidraddress
 +            createzone.guestcidraddress = zone.guestcidraddress
              
              zoneresponse = self.apiClient.createZone(createzone)
              zoneId = zoneresponse.id
@@@ -358,9 -339,35 +359,36 @@@
                  self.createpods(zone.pods, zoneId)
                  self.createVlanIpRanges(zone.networktype, zone.ipranges, \
                                          zoneId)
+             elif zone.networktype == "Advanced" and zone.securitygroupenabled == "true":
+                 listnetworkoffering = listNetworkOfferings.listNetworkOfferingsCmd()
+                 listnetworkoffering.name = "DefaultSharedNetworkOfferingWithSGService"
+                 if zone.networkofferingname  is not None:
+                    listnetworkoffering.name = zone.networkofferingname
+ 
+                 listnetworkofferingresponse = \
+                     self.apiClient.listNetworkOfferings(listnetworkoffering)
+ 
+                 networkcmd = createNetwork.createNetworkCmd()
+                 networkcmd.displaytext = "Shared SG enabled network"
+                 networkcmd.name = "Shared SG enabled network"
+                 networkcmd.networkofferingid = listnetworkofferingresponse[0].id
+                 networkcmd.zoneid = zoneId
+ 
+                 ipranges = zone.ipranges
+                 if ipranges:
+                     iprange = ipranges.pop()
+                     networkcmd.startip = iprange.startip
+                     networkcmd.endip = iprange.endip
+                     networkcmd.gateway = iprange.gateway
+                     networkcmd.netmask = iprange.netmask
+                     networkcmd.vlan = iprange.vlan
+ 
+                 networkcmdresponse = self.apiClient.createNetwork(networkcmd)
+                 networkId = networkcmdresponse.id
+                 self.createpods(zone.pods, zoneId, networkId)
  
              self.createSecondaryStorages(zone.secondaryStorages, zoneId)
 +            self.createCacheStorages(zone.cacheStorages, zoneId)            
              
              enabled = getattr(zone, 'enabled', 'True')
              if enabled == 'True' or enabled is None:

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18aeef3e/ui/scripts/system.js
----------------------------------------------------------------------
diff --cc ui/scripts/system.js
index c62229c,f853ed5..a72b520
--- a/ui/scripts/system.js
+++ b/ui/scripts/system.js
@@@ -2115,7 -2118,169 +2118,169 @@@
                      }
                    }
                  }
+               },
+                   
+               dedicatedGuestVlanRanges : {
+                 title: 'Dedicated VLAN Ranges',
+                 listView: {
+                   section: 'dedicatedGuestVlanRanges',
+                   id: 'dedicatedGuestVlanRanges',
+                   fields: {
+                     guestvlanrange: { label: 'VLAN Range(s)' },
+                     domain: { label: 'label.domain' },
+                     account: { label: 'label.account' }                
+                   },
+                   dataProvider: function(args) {
+                     $.ajax({
+                       url: createURL('listDedicatedGuestVlanRanges'),
+                       data: {
+                         physicalnetworkid: args.context.physicalNetworks[0].id
+                       },
+                       success: function(json) {
+                         var items = json.listdedicatedguestvlanrangesresponse.dedicatedguestvlanrange;
+                         args.response.success({ data: items })
+                       }
+                     });                    
+                   },
+                   actions: {
+                     add: {
+                       label: 'Dedicate VLAN Range',
+                       messages: {                       
+                         notification: function(args) {
+                           return 'Dedicate VLAN Range';
+                         }
+                       },
+                       createForm: {
+                         title: 'Dedicate VLAN Range',
+                         fields: {
+                           vlanrange: { 
+                             label: 'VLAN Range', 
+                           /*  select: function(args) {
+                               var items = [];                             
+                               if(args.context.physicalNetworks[0].vlan != null && args.context.physicalNetworks[0].vlan.length > 0) {
+                                 var vlanranges = args.context.physicalNetworks[0].vlan.split(";");
+                                 for(var i = 0; i < vlanranges.length ; i++) {                                  
+                                   items.push({id: vlanranges[i], description: vlanranges[i]});
+                                 }                                
+                               }
+                               args.response.success({data: items});
+                             },*/
+                             validation: { required: true } 
+                           },                          
+                           account: { label: 'label.account', validation: { required: true } },
+                           domainid: {
+                             label: 'label.domain',     
+                             validation: { required: true },
+                             select: function(args) {
+                               $.ajax({
+                                 url: createURL('listDomains'),
+                                 data: { listAll: true },
+                                 success: function(json) {
+                                   args.response.success({
+                                     data: $.map(json.listdomainsresponse.domain, function(domain) {
+                                       return {
+                                         id: domain.id,
+                                         description: domain.path
+                                       };
+                                     })
+                                   });
+                                 }
+                               });
+                             }
+                           }                          
+                         }
+                       },
+                       action: function(args) {                       
+                         var data = {
+                           physicalnetworkid: args.context.physicalNetworks[0].id,
+                           vlanrange: args.data.vlanrange,
+                           domainid: args.data.domainid,
+                           account: args.data.account
+                         };                        
+                         $.ajax({
+                           url: createURL('dedicateGuestVlanRange'),
+                           data: data,                        
+                           success: function(json) {                       
+                             var item = json.dedicateguestvlanrangeresponse.dedicatedguestvlanrange;
+                             args.response.success({ data: item });                            
+                           }
+                         });
+                       },
+                       notification: {
+                         poll: function(args) {
+                           args.complete();
+                         }
+                       }  
+                     }
+                   },
+                                     
+                   detailView: {
+                     name: 'VLAN Range details',
+                     actions: {
+                       remove: {
+                         label: 'Release dedicated VLAN range',
+                         messages: {
+                           confirm: function(args) {
+                             return 'Please confirm you want to release dedicated VLAN range';
+                           },
+                           notification: function(args) {
+                             return 'Release dedicated VLAN range';
+                           }
+                         },
+                         action: function(args) {
+                           var data = {
+                             id: args.context.dedicatedGuestVlanRanges[0].id
+                           };                
+                           $.ajax({
+                             url: createURL('releaseDedicatedGuestVlanRange'),
+                             data: data,
+                             async: true,
+                             success: function(json) {                             
+                               var jid = json.releasededicatedguestvlanrangeresponse.jobid;
+                               args.response.success(
+                                 {
+                                   _custom: { jobId: jid }
+                                 }
+                               );                              
+                             }
+                           });
+                         },
+                         notification: {
+                           poll: pollAsyncJobResult
+                         }
+                       }
+                     },
+ 
+                     tabs: {
+                       details: {
+                         title: 'label.details',
+                         fields: [
+                           {
+                             guestvlanrange: { label: 'VLAN Range(s)' },
+                           },
+                           {
+                             domain: { label: 'label.domain' },
+                             account: { label: 'label.account' },                              
+                             id: { label: 'label.id' }
+                           }
+                         ],
+                         dataProvider: function(args) {   
+                           $.ajax({
+                             url: createURL('listDedicatedGuestVlanRanges'),
+                             data: {
+                               id: args.context.dedicatedGuestVlanRanges[0].id
+                             },
+                             success: function(json) {
+                               var item = json.listdedicatedguestvlanrangesresponse.dedicatedguestvlanrange[0];
+                               args.response.success({ data: item })
+                             }
+                           });   
+                         }
+                       }
+                     }
+                   }
+                 }
 -              }            
 +              }
              }
            }
          }
@@@ -5208,7 -5373,103 +5373,103 @@@
  
                detailView: {
                  isMaximized: true,
 -                actions: {                  
 +                actions: {
+                   addVmwareDc: {
+                     label: 'Add VMware datacenter',
+                     messages: {                      
+                       notification: function(args) {
+                         return 'Add VMware datacenter';
+                       }
+                     },
+                     createForm: {
+                       title: 'Add VMware datacenter',
+                       fields: {
+                         name: { 
+                           label: 'label.name',
+                           validation: { required: true }
+                         },
+                         vcenter: { 
+                           label: 'vcenter',
+                           validation: { required: true }
+                         },
+                         username: {
+                           label: 'label.username',
+                           validation: { required: false }
+                         },
+                         password: {
+                           label: 'label.password',
+                           isPassword: true,
+                           validation: { required: false }
+                         },
+                       }
+                     },                    
+                     action: function(args) {
+                       var data = {
+                         zoneid: args.context.physicalResources[0].id,
+                         name: args.data.name,
+                         vcenter: args.data.vcenter 
+                       };                                          
+                       
+                       if(args.data.username != null && args.data.username.length > 0) {
+                         $.extend(data, {
+                           username: args.data.username 
+                         })
+                       }
+                       if(args.data.password != null && args.data.password.length > 0) {
+                         $.extend(data, {
+                           password: args.data.password 
+                         })
+                       }
+                       
+                       $.ajax({
+                         url: createURL('addVmwareDc'),  
+                         data: data,                       
+                         success: function(json) {
+                           //var item = json.addvmwaredcresponse.vmwaredc;
+                           args.response.success();
+                         }
+                       });
+                     },
+                     notification: {
+                       poll: function(args) {
+                         args.complete();
+                       }
+                     }
+                   },
+                                     
+                   removeVmwareDc: {
+                     label: 'Remove VMware datacenter',
+                     messages: {
+                       confirm: function(args) {
+                         return 'Please confirm you want to remove VMware datacenter';
+                       },
+                       notification: function(args) {
+                         return 'Remove VMware datacenter';
+                       }
+                     },
+                     action: function(args) {
+                       var data = {
+                         zoneid: args.context.physicalResources[0].id
+                       };                      
+                       $.ajax({
+                         url: createURL('removeVmwareDc'),  
+                         data: data,
+                         success: function(json) {
+                           var item = json.updatezoneresponse.zone;
+                           args.response.success({
+                             actionFilter: zoneActionfilter,
+                             data:item
+                           });
+                         }
+                       });
+                     },
+                     notification: {
+                       poll: function(args) {
+                         args.complete();
+                       }
+                     }
+                   },                  
+                   
                    enable: {
                      label: 'label.action.enable.zone',
                      messages: {
@@@ -5271,6 -5532,117 +5532,117 @@@
                      }
                    },
  
+                   dedicateZone:{
+                    label: 'Dedicate Zone',
 -                messages: {
 -                  confirm: function(args) {
++                    messages: {
++                      confirm: function(args) {
+                     return 'Do you really want to dedicate this zone to a domain/account? ';
 -                  },
 -                  notification: function(args) {
++                      },
++                      notification: function(args) {
+                     return 'Zone Dedicated';
 -                  }
 -                },
++                      }
++                    },
+                 createForm:{
+                    title:'Dedicate Zone',
+                    fields:{
+                          domainId:{
+                       label:'Domain',
+                       validation:{required:true},
+                       select:function(args){
 -                         $.ajax({
++                      $.ajax({
+                               url:createURL("listDomains&listAll=true"),
+                               dataType:"json",
+                               async:false,
 -                               success: function(json) {
++                        success: function(json) {
+                                   var domainObjs= json.listdomainsresponse.domain;
+                                   var items=[];
+ 
+                                   $(domainObjs).each(function() {
+                                   items.push({id:this.id ,description:this.name });
+                                   });
+ 
+                                   args.response.success({
+                                   data: items
+                                 });
 -                               }
 -
 -
 -                        });
+                        }
 -                   },
+ 
++
++                      }); 
++                    }
++                  },
++                      
+                    accountId:{
+                      label:'Account',
+                      docID:'helpAccountForDedication',
+                      validation:{required:false}
+ 
+                   }
 -                     }
++                      }
+                 },
+             
+                action: function(args) {
+                      //EXPLICIT DEDICATION
+                       var array2 = [];
+                       if(args.data.accountId != "")
+                         array2.push("&account=" +todb(args.data.accountId));
 -
 -                    $.ajax({
++                      
++                      $.ajax({
+                     url: createURL("dedicateZone&zoneId=" + args.context.physicalResources[0].id + "&domainId=" +args.data.domainId + array2.join("") ),
 -                    dataType: "json",
 -                    success: function(json) {
++                        dataType: "json",
++                        success: function(json) {
+                        var jid = json.dedicatezoneresponse.jobid;
+                             args.response.success({
+                                _custom:
+                            {      jobId: jid
 -                             },
++                        },
+                             notification: {
+                                  poll: pollAsyncJobResult
+                               },
+                             actionFilter:zoneActionfilter
+ 
+                           });
+                     }
+                   });
+                 }
+ 
+               },
+ 
+               releaseDedicatedZone:{
+                 label:'Release Dedicated Zone',
+                 messages:{
+                    confirm: function(args) {
+                     return 'Do you want to release this dedicated zone ?';
+                   },
+                   notification: function(args) {
+                     return 'Zone dedication released';
+                   }
+                 },
+                action:function(args){
+                   $.ajax({
+                      url:createURL("releaseDedicatedZone&zoneid=" + args.context.physicalResources[0].id),
+                      dataType:"json",
+                      async:true,
+                       success:function(json){
+                        var jid = json.releasededicatedzoneresponse.jobid;
+                         args.response.success({
+                              _custom:
+                            {      jobId: jid
+                              },
+                             notification: {
+                                  poll: pollAsyncJobResult
+                               },
+                             actionFilter:zoneActionfilter
+ 
+                        });
+                      },
+                     error:function(json){
+                       args.response.error(parseXMLHttpResponse(json));
+                     }
+                   });
+ 
+                }
+               },
+ 
                    'remove': {
                      label: 'label.action.delete.zone',
                      messages: {
@@@ -5368,7 -5740,15 +5740,15 @@@
  												  isEditable: true,
  												  converter:cloudStack.converters.toBooleanText
                          }
+                       },
+ 
+                        {
+ 
+                        isdedicated:{label:'Dedicated'},
+                        domainid:{label:'Domain ID'}
+ 
 -                       }
 +                      }
+ 
                      ],
                      dataProvider: function(args) {
                        $.ajax({
@@@ -5377,12 -5757,32 +5757,32 @@@
                            id: args.context.physicalResources[0].id
                          },
                          success: function(json) {
 -                           selectedZoneObj = json.listzonesresponse.zone[0];
 +                          selectedZoneObj = json.listzonesresponse.zone[0];
+                              $.ajax({
+                                                     url:createURL("listDedicatedZones&zoneid=" +args.context.physicalResources[0].id),
+                                                     dataType:"json",
+                                                     async:false,
+                                                     success:function(json){
+                                                         if(json.listdedicatedzonesresponse.dedicatedzone != undefined){
+                                                           var zoneItem = json.listdedicatedzonesresponse.dedicatedzone[0];
+                                                             if (zoneItem.domainid != null) {
+                                                             $.extend(selectedZoneObj, zoneItem , { isdedicated: 'Yes' });
+                                                           }
+                                                         }
+                                                         else
+                                                             $.extend(selectedZoneObj,{ isdedicated: 'No' })
+ 
+                                                     },
+                                                   error:function(json){
+                                                        args.response.error(parseXMLHttpResponse(XMLHttpResponse));
+                                                   }
+                                               });
 -                                             args.response.success({
 +                          args.response.success({
-                             data: json.listzonesresponse.zone[0],
-                             actionFilter: zoneActionfilter
+                                                 actionFilter: zoneActionfilter,
+                                                 data: selectedZoneObj
 -                                            });
 +                          });
+ 
 -                           }
 +                        }
                        });
                      }
                    },
@@@ -8342,7 -8742,54 +8742,54 @@@
                      label: 'label.end.reserved.system.IP',
                      docID: 'helpPodEndIP',
                      validation: { required: false }
+                   },
+ 
+                    isDedicated:{
+                        label:'Dedicate',
+                        isBoolean:true,
+                        isChecked:false,
+                        docID:'helpDedicateResource'
+ 
+ 
+                    },
+ 
+                    domainId:{
+                       label:'Domain',
+                       isHidden:true,
+                       validation:{required:true},
+                       dependsOn:'isDedicated',
+                       select:function(args){
+                          $.ajax({
+                               url:createURL("listDomains&listAll=true"),
+                               dataType:"json",
+                               async:false,
+                                success: function(json) {
+                                   var domainObjs= json.listdomainsresponse.domain;
+                                   var items=[];
+ 
+                                   $(domainObjs).each(function() {
+                                   items.push({id:this.id ,description:this.name });
+                                   });
+ 
+                                   args.response.success({
+                                   data: items
+                                 });
 -                               }
++                  }
+ 
+ 
+                         });
+                       }
+                    },
+ 
+                     accountId:{
+                      label:'Account',
+                      isHidden:true,
+                      dependsOn:'isDedicated',
+                      docID:'helpAccountForDedication',
+                      validation:{required:false}
+ 
                    }
+ 
                  }
                },
  
@@@ -8366,16 -8813,51 +8813,51 @@@
                    dataType: "json",
                    success: function(json) {
                      var item = json.createpodresponse.pod;
+                     podId = json.createpodresponse.pod.id;
+ 
+                   //EXPLICIT DEDICATION
+                 if(args.$form.find('.form-item[rel=isDedicated]').find('input[type=checkbox]').is(':Checked')== true){
+                       var array2 = [];
+                       if(args.data.accountId != "")
+                         array2.push("&account=" +todb(args.data.accountId));
+ 
+                       if(podId != null){
+                       $.ajax({
+                          url:createURL("dedicatePod&podId=" +podId +"&domainId=" +args.data.domainId + array2.join("")),
+                          dataType:"json",
+                          success:function(json){
+                             var jid = json.dedicatepodresponse.jobid;
 -                            args.response.success({
 +                    args.response.success({
+                                _custom:
+                            {      jobId: jid
+                              },
+                             notification: {
+                                  poll: pollAsyncJobResult
+                               },
+ 
 -                             data:item
 -                          });
 +										  data:item
 +										});
+ 
+                          },
+ 
+                          error:function(json){
+ 
+                            args.response.error(parseXMLHttpResponse(XMLHttpResponse));
+                          }
+                        });
+ 
+                      }
+                     }
 -                 },
 -                 error: function(XMLHttpResponse) {
 +                  },
 +                  error: function(XMLHttpResponse) {
                      var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
                      args.response.error(errorMsg);
                    }
+ 
 -                });                 
 +                });
-               },
+ 
+                 
+               },
  
                notification: {
                  poll: function(args) {
@@@ -8544,23 -9143,56 +9143,56 @@@
                        },
                        label: 'label.allocation.state'
                      }
+                   },
+ 
+                    {
+ 
+                    isdedicated:{label:'Dedicated'},
+                    domainid:{label:'Domain ID'}
+ 
 -                   }
 +                  }
+ 
                  ],
  
                  dataProvider: function(args) {								  
+                 
 -                                                                        $.ajax({
 -                                                                                url: createURL("listPods&id=" + args.context.pods[0].id),
 -                                                                                dataType: "json",
 +									$.ajax({
 +										url: createURL("listPods&id=" + args.context.pods[0].id),
 +										dataType: "json",
- 										async: true,
+                                                                                 async: false,
 -                                                                                success: function(json) {
 -                                                                                     var  item = json.listpodsresponse.pod[0];
 +										success: function(json) {										  
 +											var item = json.listpodsresponse.pod[0];
- 											args.response.success({
- 												actionFilter: podActionfilter,
- 												data:item
- 											});
- 										}
- 									});									              
+ 
+ 
+                                                                                        $.ajax({
+                                                     url:createURL("listDedicatedPods&podid=" +args.context.pods[0].id),
+                                                     dataType:"json",
+                                                     async:false,
+                                                     success:function(json){
+                                                          if(json.listdedicatedpodsresponse.dedicatedpod != undefined){
+                                                             var podItem = json.listdedicatedpodsresponse.dedicatedpod[0];
+                                                         if (podItem.domainid != null) {
+                                                             $.extend(item, podItem , { isdedicated: 'Yes' });
+                                                         }
+                                                     }
+                                                       else
+                                                          $.extend(item ,{ isdedicated: 'No' })
+                                                  },
+                                                  error:function(json){
+                                                      args.response.error(parseXMLHttpResponse(XMLHttpResponse));
+ 
+                                                  }
+                                            });
+                                              args.response.success({
+                                                 actionFilter: podActionfilter,
+                                                 data: item
+                                             });
+ 
+                                          }
+                                                                         });
+ 
+ 
 -                 }
 +                }
                },
  
                ipAllocations: {
@@@ -8842,8 -9474,55 +9474,55 @@@
  
                     },
  
+                   
+                    isDedicated:{
+                        label:'Dedicate',
+                        isBoolean:true,
+                        isChecked:false,
+                        docID:'helpDedicateResource'
+ 
+ 
+                    },
+ 
+                    domainId:{
+                       label:'Domain',
+                       isHidden:true,
+                       validation:{required:true},
+                       dependsOn:'isDedicated',
+                       select:function(args){
+                          $.ajax({
+                               url:createURL("listDomains&listAll=true"),
+                               dataType:"json",
+                               async:false,
+                                success: function(json) {
+                                   var domainObjs= json.listdomainsresponse.domain;
+                                   var items=[];
+ 
+                                   $(domainObjs).each(function() {
+                                   items.push({id:this.id ,description:this.name });
+                                   });
+ 
+                                   args.response.success({
+                                   data: items
+                                 });
+                                }
+ 
+ 
+                         });
+                       }
+                    },
+ 
+                     accountId:{
+                      label:'Account',
+                      isHidden:true,
+                      dependsOn:'isDedicated',
+                      docID:'helpAccountForDedication',
+                      validation:{required:false}
+ 
+                   },
+ 
                    //hypervisor==VMWare begins here
 - 
 +
                    vCenterHost: {
                      label: 'label.vcenter.host',
                      docID: 'helpClustervCenterHost',
@@@ -9079,11 -9758,41 +9758,41 @@@
                    async: true,
                    success: function(json) {
                      var item = json.addclusterresponse.cluster[0];
+                     clusterId= json.addclusterresponse.cluster[0].id;
+                   
+                   //EXPLICIT DEDICATION
+                 if(args.$form.find('.form-item[rel=isDedicated]').find('input[type=checkbox]').is(':Checked')== true){
+                       var array2 = [];
+                       if(args.data.accountId != "")
+                         array2.push("&account=" +todb(args.data.accountId));
+                     }
+ 
+                     if(clusterId != null){
+                       $.ajax({
+                          url:createURL("dedicateCluster&clusterId=" +clusterId +"&domainId=" +args.data.domainId + array2.join("")),
+                          dataType:"json",
+                          success:function(json){
+                              var jid = json.dedicateclusterresponse.jobid;
 -                              args.response.success({
 +                    args.response.success({
- 										  data: $.extend(item, { state: 'Enabled' })
+                                  _custom:
+                                    {      jobId: jid
+                                     },
+                                   notification: {
+                                     poll: pollAsyncJobResult
+                                     },
+ 
+                                   data:$.extend(item, {state:'Enabled'})
 -                             });
 +										});
+ 
+                          },
+ 
+                          error:function(json){
+                            args.response.error(parseXMLHttpResponse(XMLHttpResponse));
+                          }
+                        });
+                    }
 -                 },
 -                 error: function(XMLHttpResponse) {
 +                  },
 +                  error: function(XMLHttpResponse) {
                      var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
                      args.response.error(errorMsg);
                    }
@@@ -9329,7 -10152,13 +10152,13 @@@
                      //allocationstate: { label: 'label.allocation.state' },
                      //managedstate: { label: 'Managed State' },
  										state: { label: 'label.state' }
+                   },
+ 
+                    {
+                     isdedicated:{label:'Dedicated'},
+                     domainid:{label:'Domain ID'}
 -                   }
 +                  }
+ 
                  ],
                  dataProvider: function(args) {
  									$.ajax({
@@@ -9338,14 -10167,40 +10167,40 @@@
  										success: function(json) {
  											var item = json.listclustersresponse.cluster[0];
  											addExtraPropertiesToClusterObject(item);
+ 								             $.ajax({
+                                                                                 url:createURL("listDedicatedClusters&clusterid=" +args.context.clusters[0].id),
+                                                                                 dataType:"json",
+                                                                                 async:false,
+                                                                                 success:function(json){
+                                                                                   if(json.listdedicatedclustersresponse.dedicatedcluster != undefined){
+                                                                                   var clusterItem = json.listdedicatedclustersresponse.dedicatedcluster[0];
+                                                                                   if (clusterItem.domainid != null) {
+                                                                                        $.extend(item, clusterItem , { isdedicated: 'Yes' });
+                                                                                      }
+                                                                                    }
+                                                                                   else
+                                                                                      $.extend(item ,{ isdedicated: 'No' })
+ 
+                                                                                     },
+                                                                                   error:function(json){
+                                                                                      args.response.error(parseXMLHttpResponse(XMLHttpResponse));
+                                                                                       }
+                                                                                    });
 -                                                                             args.response.success({
 -                                                                                   actionFilter: clusterActionfilter,
 -                                                                                   data: item
 -                                                                                });
 +											args.response.success({
 +												actionFilter: clusterActionfilter,
 +												data: item
 +											});
+ 
+                                                                            },
+ 
+                                                                             error:function(json){
+                                                                                args.response.error(parseXMLHttpResponse(XMLHttpResponse));
+ 
 -                                                                        }
 +										}
+ 
 -                 });
 -              }
 -          },
 +									});
 +                }
 +              },
                nexusVswitch: {
                  title:'label.nexusVswitch',
                  listView: {
@@@ -9831,7 -10686,55 +10686,55 @@@
                      validation: { required: true },
                      isHidden: true,
                      isPassword: true
 -                  }, 
 +                  },
+ 
+                    isDedicated:{
+                        label:'Dedicate',
+                        isBoolean:true,
+                        isChecked:false,
+                        docID:'helpDedicateResource'
+ 
+ 
+                    },
+ 
+                    domainId:{
+                       label:'Domain',
+                       isHidden:true,
+                       validation:{required:true},
+                       dependsOn:'isDedicated',
+                       select:function(args){
+                          $.ajax({
+                               url:createURL("listDomains&listAll=true"),
+                               dataType:"json",
+                               async:false,
+                                success: function(json) {
+                                   var domainObjs= json.listdomainsresponse.domain;
+                                   var items=[];
+ 
+                                   $(domainObjs).each(function() {
+                                   items.push({id:this.id ,description:this.name });
+                                   });
+ 
+                                   args.response.success({
+                                   data: items
+                                 });
+                                }
+ 
+ 
+                         });
+ 
+                       }
+                    },
+ 
+                    accountId:{
+                      label:'Account',
+                      isHidden:true,
+                      dependsOn:'isDedicated',
+                      docID:'helpAccountForDedication',
+                      validation:{required:false}
+ 
+                   },
+ 
                    //input_group="general" ends here
  
                    //input_group="VMWare" starts here
@@@ -9948,18 -10851,52 +10851,52 @@@
  										});									
                    }
                  }
 -             
 +
+                 var hostId = null;
                  $.ajax({
                    url: createURL("addHost"),
                    type: "POST",
  									data: data,
                    success: function(json) {
                      var item = json.addhostresponse.host[0];
+                     hostId = json.addhostresponse.host[0].id;
+ 
+ 
+                        //EXPLICIT DEDICATION
+                 if(args.$form.find('.form-item[rel=isDedicated]').find('input[type=checkbox]').is(':Checked')== true){
+                       var array2 = [];
+                       if(args.data.accountId != "")
+                         array2.push("&account=" +todb(args.data.accountId));
+                     }
+ 
+                     if(hostId != null){
+                       $.ajax({
+                          url:createURL("dedicateHost&hostId=" +hostId +"&domainId=" +args.data.domainId + array2.join("")),
+                          dataType:"json",
+                          success:function(json){
+                              var jid = json.dedicatehostresponse.host.jobid;
 -                              args.response.success({
 +                    args.response.success({
-                       data: item
+                                  _custom:
+                            {      jobId: jid
+                              },
+                             notification: {
+                                  poll: pollAsyncJobResult
+                               },
+ 
+                              data:item
+ 
 -                            });
 +                    });
+ 
 -                         },
 +                  },
+ 
+                          error:function(json){
+                            args.response.error(parseXMLHttpResponse(XMLHttpResponse));
+                          }
+                        });
+                    }
+                  },
+ 
 -                   error: function(XMLHttpResponse) {
 +                  error: function(XMLHttpResponse) {
                      var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
                      args.response.error(errorMsg);
                    }
@@@ -10228,20 -11282,49 +11282,49 @@@
                      ipaddress: { label: 'label.ip.address' },
                      version: { label: 'label.version' },
                      disconnected: { label: 'label.last.disconnected' }
+                   },
+ 
+                    {
+ 
+                    isdedicated:{label:'Dedicated'},
+                    domainid:{label:'Domain ID'}
+ 
 -                   }
 +                  }
+ 
+ 
                  ],
  
                  dataProvider: function(args) {								  
 -					        $.ajax({
 -							url: createURL("listHosts&id=" + args.context.hosts[0].id),
 -							dataType: "json",
 -							async: true,
 -							success: function(json) {										  
 -								var item = json.listhostsresponse.host[0];
 +									$.ajax({
 +										url: createURL("listHosts&id=" + args.context.hosts[0].id),
 +										dataType: "json",
 +										async: true,
 +										success: function(json) {										  
 +											var item = json.listhostsresponse.host[0];
+                                                                 $.ajax({
+                                                                   url:createURL("listDedicatedHosts&hostid=" +args.context.hosts[0].id),
+                                                                   dataType:"json",
+                                                                   async:false,
+                                                                   success:function(json){
+                                                                       if(json.listdedicatedhostsresponse.dedicatedhost != undefined){
+                                                                       var hostItem = json.listdedicatedhostsresponse.dedicatedhost[0];
+                                                                       if (hostItem.domainid != null) {
+                                                                              $.extend(item, hostItem , { isdedicated: 'Yes' });
+                                                                             }
+                                                                          }
+                                                                            else
+                                                                              $.extend(item ,{ isdedicated: 'No' })
+ 
+                                                                           },
+                                                                             error:function(json){
+                                                                                   args.response.error(parseXMLHttpResponse(XMLHttpResponse));
+                                                                                  }
+                                                                              });
 -                                                                                 args.response.success({
 -                                                                                   actionFilter: hostActionfilter,
 -                                                                                   data: item
 -                                                                                 }); 
 +											args.response.success({
 +												actionFilter: hostActionfilter,
 +												data: item
 +											});
+ 
  										}
  									});											
                  }
@@@ -10871,7 -11975,12 +11975,12 @@@
                  array1.push("&scope=" + todb(args.data.scope));
  
                  array1.push("&zoneid=" + args.data.zoneid);
 -
 +            
+                if(args.data.scope == 'zone'){
+                 
+                   array1.push("&hypervisor=" + args.data.hypervisor);
+                } 
+             
                 if(args.data.scope == 'cluster'){
  
                  array1.push("&podid=" + args.data.podId);
@@@ -11411,28 -12405,24 +12520,28 @@@
                      label: 'Zone',
                      docID: 'helpSecondaryStorageZone',
                      validation: { required: true },
 -                    select: function(args) {
 -                      var data = args.context.zones ?
 -                      { id: args.context.zones[0].id } : { listAll: true };
 -
 +                    select: function(args) {                      
                        $.ajax({
                          url: createURL('listZones'),
 -                        data: data,
 +                        data: { 
 +                          listAll: true 
 +                        },
                          success: function(json) {
-                           var zones = json.listzonesresponse.zone;
+                           var zones = json.listzonesresponse.zone ? json.listzonesresponse.zone : [];
  
 -                          args.response.success({
 -                            data: $.map(zones, function(zone) {
 -                              return {
 -                                id: zone.id,
 -                                description: zone.name
 -                              };
 -                            })
 -                          });
 +                          if(zones != null){ //$.map(items, fn) - items can not be null
 +                            args.response.success({
 +                              data: $.map(zones, function(zone) {
 +                                return {
 +                                  id: zone.id,
 +                                  description: zone.name
 +                                };
 +                              })
 +                            });
 +                          }
 +                          else {
 +                            args.response.success({data: null});
 +                          }                          
                          }
                        });
                      }
@@@ -12588,7 -13379,12 +13714,12 @@@
    var clusterActionfilter = function(args) {
      var jsonObj = args.context.item;
      var allowedActions = [];
 -     
 +
+      if(jsonObj.domainid != null)
+       allowedActions.push("release");
+      else
+       allowedActions.push("dedicate");
+ 
      if(jsonObj.state == "Enabled") {//managed, allocation enabled
  		  allowedActions.push("unmanage");
        allowedActions.push("disable");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/18aeef3e/ui/scripts/zoneWizard.js
----------------------------------------------------------------------
diff --cc ui/scripts/zoneWizard.js
index 12d7846,5870a7b..1601ac9
--- a/ui/scripts/zoneWizard.js
+++ b/ui/scripts/zoneWizard.js
@@@ -348,11 -348,18 +348,18 @@@
            
  	  }													
  										
-           setTimeout(function() {
+       /*    setTimeout(function() {
              if ($form.find('input[name=ispublic]').is(':checked')) {
+               $form.find('[rel=domain]').show();
+               $form.find('[rel=accountId]').show();
+             }
+  
+             else{
+ 
                $form.find('[rel=domain]').hide();
+               $form.find('[rel=accountId]').hide();
 -             }             
 +            }
-           });
+           });*/
          },
          fields: {
            name: {
@@@ -1217,26 -1233,21 +1233,21 @@@
                if(selectedHypervisorObj == null) {
                  return;
                }
 -                 
 +
-                 // ZWPS is supported only for KVM as the hypervisor
-              if(selectedHypervisorObj.hypervisortype != "KVM"){
+               //zone-wide-primary-storage is supported only for KVM and VMWare
+               if(selectedHypervisorObj.hypervisortype == "KVM" || selectedHypervisorObj.hypervisortype == "VMware"){
 -                var scope=[];
 +                       var scope=[];
+                 scope.push({ id: 'zone', description: _l('label.zone.wide') });
 -                scope.push({ id: 'cluster', description: _l('label.cluster') });                      
 -                args.response.success({data: scope});
 -              }
 -              else {     
 -                var scope=[];
 -                scope.push({ id: 'cluster', description: _l('label.cluster') });                       
 -                args.response.success({data: scope});                       
 -              }
 -            }
 -          },
 +                       scope.push({ id: 'cluster', description: _l('label.cluster') });
-                        //scope.push({ id: 'host', description: _l('label.host') });
 +                       args.response.success({data: scope});
 +                    }
- 
 +              else {
 +                       var scope=[];
-                        scope.push({ id: 'zone', description: _l('label.zone.wide') });
 +                       scope.push({ id: 'cluster', description: _l('label.cluster') });
-                       // scope.push({ id: 'host', description: _l('label.host') });
 +                       args.response.success({data: scope});
 +                    }
- 
 +                }
- 
 +              },
  
            protocol: {
              label: 'label.protocol',
@@@ -1756,7 -1607,9 +1769,9 @@@
  					
            if(args.data.zone.networkdomain != null && args.data.zone.networkdomain.length > 0)
              array1.push("&domain=" + todb(args.data.zone.networkdomain));
 -          
 +
+           var dedicatedZoneId = null;
+ 
            $.ajax({
              url: createURL("createZone" + array1.join("")),
              dataType: "json",
@@@ -3479,25 -3361,51 +3523,51 @@@
            }
            array1.push("&clustername=" + todb(clusterName));
  
+           if(args.data.cluster.hypervisor == "VMware"){
+             var vmwareData = {
+               zoneId: args.data.returnedZone.id,
+               username: args.data.cluster.vCenterUsername,
+               password: args.data.cluster.vCenterPassword,
+               name: args.data.cluster.vCenterDatacenter,
+               vcenter: args.data.cluster.vCenterHost
+             };
+             $.ajax({
+               url: createURL('addVmwareDc'),
+               data: vmwareData,
+               success: function(json) {
+                 var item = json.addvmwaredcresponse.vmwaredc;
+                 if(item.id != null){
 -                $.ajax({
 -                  url: createURL("addCluster" + array1.join("")),
 -                  dataType: "json",
 -                  async: true,
 -                  success: function(json) {
 +          $.ajax({
 +            url: createURL("addCluster" + array1.join("")),
 +            dataType: "json",
 +            async: true,
 +            success: function(json) {
-               if(args.data.cluster.hypervisor != "VMware") {
-                 stepFns.addHost({
+                     stepFns.addPrimaryStorage({ //skip "add host step" when hypervisor is VMware
 -                      data: $.extend(args.data, {
 -                      returnedCluster: json.addclusterresponse.cluster[0]
 -                    })
 -                    });
 +                  data: $.extend(args.data, {
 +                    returnedCluster: json.addclusterresponse.cluster[0]
 +                  })
 +                });
+                   },
+                   error: function(XMLHttpResponse) {
+                     var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
+                     error('addCluster', errorMsg, { fn: 'addCluster', args: args });
+                   }
+                 });
                }
-               else { 
-                 stepFns.addPrimaryStorage({
+             }
+           });
+          }
+          else{
+           $.ajax({
+             url: createURL("addCluster" + array1.join("")),
+             dataType: "json",
+             async: true,
+             success: function(json) {
+               stepFns.addHost({
 -                data: $.extend(args.data, {
 -                  returnedCluster: json.addclusterresponse.cluster[0]
 -                })
 -              });                            
 +                  data: $.extend(args.data, {
 +                    returnedCluster: json.addclusterresponse.cluster[0]
 +                  })
 +                });
-               }
              },
              error: function(XMLHttpResponse) {
                var errorMsg = parseXMLHttpResponse(XMLHttpResponse);