cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [48/50] [abbrv] Merged from master
Date Mon, 10 Jun 2013 00:54:37 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/api/ApiResponseHelper.java
index 7d7493a,bcc1605..65214f6
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@@ -3448,114 -3323,125 +3316,125 @@@ public class ApiResponseHelper implemen
      }
  
  
 -    @Override
 -    public UsageRecordResponse createUsageResponse(Usage usageRecord) {
 -        UsageRecordResponse usageRecResponse = new UsageRecordResponse();
 -
 -        Account account = ApiDBUtils.findAccountByIdIncludingRemoved(usageRecord.getAccountId());
 -        if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
 -            //find the project
 -            Project project = ApiDBUtils.findProjectByProjectAccountIdIncludingRemoved(account.getId());
 -            usageRecResponse.setProjectId(project.getUuid());
 -            usageRecResponse.setProjectName(project.getName());
 -        } else {
 -            usageRecResponse.setAccountId(account.getUuid());
 -            usageRecResponse.setAccountName(account.getAccountName());
 -        }
 -
 -        Domain domain = ApiDBUtils.findDomainById(usageRecord.getDomainId());
 -        if (domain != null) {
 -            usageRecResponse.setDomainId(domain.getUuid());
 -        }
 -
 -        if (usageRecord.getZoneId() != null) {
 -            DataCenter zone = ApiDBUtils.findZoneById(usageRecord.getZoneId());
 -            if (zone != null) {
 -                usageRecResponse.setZoneId(zone.getUuid());
 -            }
 -        }
 -        usageRecResponse.setDescription(usageRecord.getDescription());
 -        usageRecResponse.setUsage(usageRecord.getUsageDisplay());
 -        usageRecResponse.setUsageType(usageRecord.getUsageType());
 -        if (usageRecord.getVmInstanceId() != null) {
 -            VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getVmInstanceId());
 -            usageRecResponse.setVirtualMachineId(vm.getUuid());
 -        }
 -        usageRecResponse.setVmName(usageRecord.getVmName());
 -        if (usageRecord.getTemplateId() != null) {
 -            VMTemplateVO template = ApiDBUtils.findTemplateById(usageRecord.getTemplateId());
 -            if (template != null) {
 -                usageRecResponse.setTemplateId(template.getUuid());
 -            }
 -        }
 -
 -        if(usageRecord.getUsageType() == UsageTypes.RUNNING_VM || usageRecord.getUsageType() == UsageTypes.ALLOCATED_VM){
 -            ServiceOfferingVO svcOffering = _entityMgr.findByIdIncludingRemoved(ServiceOfferingVO.class, usageRecord.getOfferingId().toString());
 -            //Service Offering Id
 -            usageRecResponse.setOfferingId(svcOffering.getUuid());
 -            //VM Instance ID
 -            VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getUsageId().toString());
 -            usageRecResponse.setUsageId(vm.getUuid());
 -            //Hypervisor Type
 -            usageRecResponse.setType(usageRecord.getType());
 -
 -        } else if(usageRecord.getUsageType() == UsageTypes.IP_ADDRESS){
 -            //isSourceNAT
 -            usageRecResponse.setSourceNat((usageRecord.getType().equals("SourceNat"))?true:false);
 -            //isSystem
 -            usageRecResponse.setSystem((usageRecord.getSize() == 1)?true:false);
 -            //IP Address ID
 -            IPAddressVO ip = _entityMgr.findByIdIncludingRemoved(IPAddressVO.class, usageRecord.getUsageId().toString());
 -            usageRecResponse.setUsageId(ip.getUuid());
 -
 -        } else if(usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_SENT || usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_RECEIVED){
 -            //Device Type
 -            usageRecResponse.setType(usageRecord.getType());
 -            if(usageRecord.getType().equals("DomainRouter")){
 -                //Domain Router Id
 -                VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getUsageId().toString());
 -                usageRecResponse.setUsageId(vm.getUuid());
 -            } else {
 -                //External Device Host Id
 -                HostVO host = _entityMgr.findByIdIncludingRemoved(HostVO.class, usageRecord.getUsageId().toString());
 -                usageRecResponse.setUsageId(host.getUuid());
 -            }
 -            //Network ID
 -            NetworkVO network = _entityMgr.findByIdIncludingRemoved(NetworkVO.class, usageRecord.getNetworkId().toString());
 -            usageRecResponse.setNetworkId(network.getUuid());
 +	@Override
 +	public UsageRecordResponse createUsageResponse(Usage usageRecord) {
 +		UsageRecordResponse usageRecResponse = new UsageRecordResponse();
 +
 +		Account account = ApiDBUtils.findAccountByIdIncludingRemoved(usageRecord.getAccountId());
 +		if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
 +			//find the project
 +			Project project = ApiDBUtils.findProjectByProjectAccountIdIncludingRemoved(account.getId());
 +			usageRecResponse.setProjectId(project.getUuid());
 +			usageRecResponse.setProjectName(project.getName());
 +		} else {
 +			usageRecResponse.setAccountId(account.getUuid());
 +			usageRecResponse.setAccountName(account.getAccountName());
 +		}
 +
 +		Domain domain = ApiDBUtils.findDomainById(usageRecord.getDomainId());
 +		if (domain != null) {
 +			usageRecResponse.setDomainId(domain.getUuid());
 +		}
 +
 +		if (usageRecord.getZoneId() != null) {
 +			DataCenter zone = ApiDBUtils.findZoneById(usageRecord.getZoneId());
 +			if (zone != null) {
 +				usageRecResponse.setZoneId(zone.getUuid());
 +			}
 +		}
 +		usageRecResponse.setDescription(usageRecord.getDescription());
 +		usageRecResponse.setUsage(usageRecord.getUsageDisplay());
 +		usageRecResponse.setUsageType(usageRecord.getUsageType());
 +		if (usageRecord.getVmInstanceId() != null) {
 +			VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getVmInstanceId());
 +			usageRecResponse.setVirtualMachineId(vm.getUuid());
 +		}
 +		usageRecResponse.setVmName(usageRecord.getVmName());
 +		if (usageRecord.getTemplateId() != null) {
 +			VMTemplateVO template = ApiDBUtils.findTemplateById(usageRecord.getTemplateId());
 +			if (template != null) {
 +				usageRecResponse.setTemplateId(template.getUuid());
 +			}
 +		}
 +
 +		if(usageRecord.getUsageType() == UsageTypes.RUNNING_VM || usageRecord.getUsageType() == UsageTypes.ALLOCATED_VM){
 +			ServiceOfferingVO svcOffering = _entityMgr.findByIdIncludingRemoved(ServiceOfferingVO.class, usageRecord.getOfferingId().toString());
 +			//Service Offering Id
 +			usageRecResponse.setOfferingId(svcOffering.getUuid());
 +			//VM Instance ID
 +			VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getUsageId().toString());
 +			usageRecResponse.setUsageId(vm.getUuid());
 +			//Hypervisor Type
 +			usageRecResponse.setType(usageRecord.getType());
 +
 +		} else if(usageRecord.getUsageType() == UsageTypes.IP_ADDRESS){
 +			//isSourceNAT
 +			usageRecResponse.setSourceNat((usageRecord.getType().equals("SourceNat"))?true:false);
 +			//isSystem
 +			usageRecResponse.setSystem((usageRecord.getSize() == 1)?true:false);
 +			//IP Address ID
 +			IPAddressVO ip = _entityMgr.findByIdIncludingRemoved(IPAddressVO.class, usageRecord.getUsageId().toString());
 +			usageRecResponse.setUsageId(ip.getUuid());
 +
 +		} else if(usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_SENT || usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_RECEIVED){
 +			//Device Type
 +			usageRecResponse.setType(usageRecord.getType());
 +			if(usageRecord.getType().equals("DomainRouter")){
 +				//Domain Router Id
 +				VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getUsageId().toString());
 +				usageRecResponse.setUsageId(vm.getUuid());
 +			} else {
 +				//External Device Host Id
 +				HostVO host = _entityMgr.findByIdIncludingRemoved(HostVO.class, usageRecord.getUsageId().toString());
 +				usageRecResponse.setUsageId(host.getUuid());
 +			}
 +			//Network ID
 +			NetworkVO network = _entityMgr.findByIdIncludingRemoved(NetworkVO.class, usageRecord.getNetworkId().toString());
 +			usageRecResponse.setNetworkId(network.getUuid());
  
+         } else if(usageRecord.getUsageType() == UsageTypes.VM_DISK_IO_READ || usageRecord.getUsageType() == UsageTypes.VM_DISK_IO_WRITE ||
+                   usageRecord.getUsageType() == UsageTypes.VM_DISK_BYTES_READ || usageRecord.getUsageType() == UsageTypes.VM_DISK_BYTES_WRITE){
+             //Device Type
+             usageRecResponse.setType(usageRecord.getType());
+             //VM Instance Id
+             VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getUsageId().toString());
+             usageRecResponse.setUsageId(vm.getUuid());
+             //Volume ID
+             VolumeVO volume = _entityMgr.findByIdIncludingRemoved(VolumeVO.class, usageRecord.getUsageId().toString());
+             usageRecResponse.setUsageId(volume.getUuid());
+ 
 -        } else if(usageRecord.getUsageType() == UsageTypes.VOLUME){
 -            //Volume ID
 -            VolumeVO volume = _entityMgr.findByIdIncludingRemoved(VolumeVO.class, usageRecord.getUsageId().toString());
 -            usageRecResponse.setUsageId(volume.getUuid());
 -            //Volume Size
 -            usageRecResponse.setSize(usageRecord.getSize());
 -            //Disk Offering Id
 -            if(usageRecord.getOfferingId() != null){
 -                DiskOfferingVO diskOff = _entityMgr.findByIdIncludingRemoved(DiskOfferingVO.class, usageRecord.getOfferingId().toString());
 -                usageRecResponse.setOfferingId(diskOff.getUuid());
 -            }
 -
 -        } else if(usageRecord.getUsageType() == UsageTypes.TEMPLATE || usageRecord.getUsageType() == UsageTypes.ISO){
 -            //Template/ISO ID
 -            VMTemplateVO tmpl = _entityMgr.findByIdIncludingRemoved(VMTemplateVO.class, usageRecord.getUsageId().toString());
 -            usageRecResponse.setUsageId(tmpl.getUuid());
 -            //Template/ISO Size
 -            usageRecResponse.setSize(usageRecord.getSize());
 -
 -        } else if(usageRecord.getUsageType() == UsageTypes.SNAPSHOT){
 -            //Snapshot ID
 -            SnapshotVO snap = _entityMgr.findByIdIncludingRemoved(SnapshotVO.class, usageRecord.getUsageId().toString());
 -            usageRecResponse.setUsageId(snap.getUuid());
 -            //Snapshot Size
 -            usageRecResponse.setSize(usageRecord.getSize());
 -
 -        } else if(usageRecord.getUsageType() == UsageTypes.LOAD_BALANCER_POLICY){
 -            //Load Balancer Policy ID
 +		} else if(usageRecord.getUsageType() == UsageTypes.VOLUME){
 +			//Volume ID
 +			VolumeVO volume = _entityMgr.findByIdIncludingRemoved(VolumeVO.class, usageRecord.getUsageId().toString());
 +			usageRecResponse.setUsageId(volume.getUuid());
 +			//Volume Size
 +			usageRecResponse.setSize(usageRecord.getSize());
 +			//Disk Offering Id
 +			if(usageRecord.getOfferingId() != null){
 +				DiskOfferingVO diskOff = _entityMgr.findByIdIncludingRemoved(DiskOfferingVO.class, usageRecord.getOfferingId().toString());
 +				usageRecResponse.setOfferingId(diskOff.getUuid());
 +			}
 +
 +		} else if(usageRecord.getUsageType() == UsageTypes.TEMPLATE || usageRecord.getUsageType() == UsageTypes.ISO){
 +			//Template/ISO ID
 +			VMTemplateVO tmpl = _entityMgr.findByIdIncludingRemoved(VMTemplateVO.class, usageRecord.getUsageId().toString());
 +			usageRecResponse.setUsageId(tmpl.getUuid());
 +			//Template/ISO Size
 +			usageRecResponse.setSize(usageRecord.getSize());
 +
 +		} else if(usageRecord.getUsageType() == UsageTypes.SNAPSHOT){
 +			//Snapshot ID
 +			SnapshotVO snap = _entityMgr.findByIdIncludingRemoved(SnapshotVO.class, usageRecord.getUsageId().toString());
 +			usageRecResponse.setUsageId(snap.getUuid());
 +			//Snapshot Size
 +			usageRecResponse.setSize(usageRecord.getSize());
 +
 +		} else if(usageRecord.getUsageType() == UsageTypes.LOAD_BALANCER_POLICY){
 +			//Load Balancer Policy ID
              LoadBalancerVO lb = _entityMgr.findByIdIncludingRemoved(LoadBalancerVO.class, usageRecord.getUsageId().toString());
              usageRecResponse.setUsageId(lb.getUuid());
 -        } else if(usageRecord.getUsageType() == UsageTypes.PORT_FORWARDING_RULE){
 -            //Port Forwarding Rule ID
 +		} else if(usageRecord.getUsageType() == UsageTypes.PORT_FORWARDING_RULE){
 +			//Port Forwarding Rule ID
              PortForwardingRuleVO pf = _entityMgr.findByIdIncludingRemoved(PortForwardingRuleVO.class, usageRecord.getUsageId().toString());
              usageRecResponse.setUsageId(pf.getUuid());
  

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/api/query/QueryManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/api/query/QueryManagerImpl.java
index 1caddb7,beda75e..6280cbf
--- a/server/src/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/com/cloud/api/query/QueryManagerImpl.java
@@@ -2383,12 -2413,12 +2413,12 @@@ public class QueryManagerImpl extends M
  
  
      public Pair<List<AffinityGroupJoinVO>, Integer> listAffinityGroupsInternal(Long affinityGroupId,
-             String affinityGroupName, String affinityGroupType, Long vmId, Long startIndex, Long pageSize) {
+             String affinityGroupName, String affinityGroupType, Long vmId, String accountName, Long domainId,
+             boolean isRecursive, boolean listAll, Long startIndex, Long pageSize) {
  
 -        Account caller = UserContext.current().getCaller();
 +        Account caller = CallContext.current().getCallingAccount();
  
          Long accountId = caller.getAccountId();
-         Long domainId = caller.getDomainId();
  
          if (vmId != null) {
              UserVmVO userVM = _userVmDao.findById(vmId);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/api/query/ViewResponseHelper.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/api/query/ViewResponseHelper.java
index 1124e69,a61da69..3daa1c1
--- a/server/src/com/cloud/api/query/ViewResponseHelper.java
+++ b/server/src/com/cloud/api/query/ViewResponseHelper.java
@@@ -16,11 -16,28 +16,13 @@@
  // under the License.
  package com.cloud.api.query;
  
 -import com.cloud.api.ApiDBUtils;
 -import com.cloud.api.query.vo.AccountJoinVO;
 -import com.cloud.api.query.vo.AffinityGroupJoinVO;
 -import com.cloud.api.query.vo.AsyncJobJoinVO;
 -import com.cloud.api.query.vo.DataCenterJoinVO;
 -import com.cloud.api.query.vo.DiskOfferingJoinVO;
 -import com.cloud.api.query.vo.DomainRouterJoinVO;
 -import com.cloud.api.query.vo.EventJoinVO;
 -import com.cloud.api.query.vo.HostJoinVO;
 -import com.cloud.api.query.vo.InstanceGroupJoinVO;
 -import com.cloud.api.query.vo.ProjectAccountJoinVO;
 -import com.cloud.api.query.vo.ProjectInvitationJoinVO;
 -import com.cloud.api.query.vo.ProjectJoinVO;
 -import com.cloud.api.query.vo.ResourceTagJoinVO;
 -import com.cloud.api.query.vo.SecurityGroupJoinVO;
 -import com.cloud.api.query.vo.ServiceOfferingJoinVO;
 -import com.cloud.api.query.vo.StoragePoolJoinVO;
 -import com.cloud.api.query.vo.UserAccountJoinVO;
 -import com.cloud.api.query.vo.UserVmJoinVO;
 -import com.cloud.api.query.vo.VolumeJoinVO;
 -import com.cloud.user.Account;
 -import com.cloud.user.UserContext;
 +import java.util.ArrayList;
 +import java.util.EnumSet;
 +import java.util.Hashtable;
 +import java.util.List;
 +
++import org.apache.log4j.Logger;
++
  import org.apache.cloudstack.affinity.AffinityGroupResponse;
  import org.apache.cloudstack.api.ApiConstants.HostDetails;
  import org.apache.cloudstack.api.ApiConstants.VMDetails;
@@@ -44,31 -60,12 +45,29 @@@ import org.apache.cloudstack.api.respon
  import org.apache.cloudstack.api.response.UserVmResponse;
  import org.apache.cloudstack.api.response.VolumeResponse;
  import org.apache.cloudstack.api.response.ZoneResponse;
 -import org.apache.log4j.Logger;
 +import org.apache.cloudstack.context.CallContext;
  
- import org.apache.log4j.Logger;
- 
 -import java.util.ArrayList;
 -import java.util.EnumSet;
 -import java.util.Hashtable;
 -import java.util.List;
 +import com.cloud.api.ApiDBUtils;
 +import com.cloud.api.query.vo.AccountJoinVO;
 +import com.cloud.api.query.vo.AffinityGroupJoinVO;
 +import com.cloud.api.query.vo.AsyncJobJoinVO;
 +import com.cloud.api.query.vo.DataCenterJoinVO;
 +import com.cloud.api.query.vo.DiskOfferingJoinVO;
 +import com.cloud.api.query.vo.DomainRouterJoinVO;
 +import com.cloud.api.query.vo.EventJoinVO;
 +import com.cloud.api.query.vo.HostJoinVO;
 +import com.cloud.api.query.vo.InstanceGroupJoinVO;
 +import com.cloud.api.query.vo.ProjectAccountJoinVO;
 +import com.cloud.api.query.vo.ProjectInvitationJoinVO;
 +import com.cloud.api.query.vo.ProjectJoinVO;
 +import com.cloud.api.query.vo.ResourceTagJoinVO;
 +import com.cloud.api.query.vo.SecurityGroupJoinVO;
 +import com.cloud.api.query.vo.ServiceOfferingJoinVO;
 +import com.cloud.api.query.vo.StoragePoolJoinVO;
 +import com.cloud.api.query.vo.UserAccountJoinVO;
 +import com.cloud.api.query.vo.UserVmJoinVO;
 +import com.cloud.api.query.vo.VolumeJoinVO;
 +import com.cloud.user.Account;
  
  /**
   * Helper class to generate response from DB view VO objects.

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
index e21f537,421e53f..67ffa18
--- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@@ -558,8 -558,7 +558,11 @@@ public class ConsoleProxyManagerImpl ex
              }
  
              if (proxy.getState() == VirtualMachine.State.Stopped) {
 -                return _itMgr.start(proxy, null, systemUser, systemAcct);
 +                _itMgr.start(proxy.getUuid(), null, systemUser, systemAcct);
-                 return _consoleProxyDao.findById(proxyVmId);
++                proxy = _consoleProxyDao.findById(proxyVmId);
++                if (proxy.getState() == State.Running) {
++                    return null;
++                }
              }
  
              // For VMs that are in Stopping, Starting, Migrating state, let client to wait by returning null

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
index fa326d8,eb895e5..4dd257e
--- a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
+++ b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
@@@ -29,9 -29,9 +29,10 @@@ import javax.ejb.Local
  import javax.inject.Inject;
  import javax.naming.ConfigurationException;
  
 -import org.apache.cloudstack.affinity.AffinityGroupProcessor;
 -import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
 +import org.apache.log4j.Logger;
  
 +import org.apache.cloudstack.affinity.AffinityGroupProcessor;
++import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
  import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
  import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
@@@ -60,9 -54,12 +61,12 @@@ import com.cloud.dc.ClusterDetailsVO
  import com.cloud.dc.ClusterVO;
  import com.cloud.dc.DataCenter;
  import com.cloud.dc.DataCenterVO;
 -import com.cloud.dc.DedicatedResourceVO;
 -import com.cloud.dc.HostPodVO;
++import com.cloud.dc.DedicatedResourceVO;
++import com.cloud.dc.HostPodVO;
  import com.cloud.dc.Pod;
  import com.cloud.dc.dao.ClusterDao;
  import com.cloud.dc.dao.DataCenterDao;
 -import com.cloud.dc.dao.DedicatedResourceDao;
++import com.cloud.dc.dao.DedicatedResourceDao;
  import com.cloud.dc.dao.HostPodDao;
  import com.cloud.deploy.DeploymentPlanner.ExcludeList;
  import com.cloud.deploy.DeploymentPlanner.PlannerResourceUsage;
@@@ -98,6 -95,7 +102,7 @@@ import com.cloud.utils.component.Manage
  import com.cloud.utils.component.ManagerBase;
  import com.cloud.utils.db.DB;
  import com.cloud.utils.db.Transaction;
 -import com.cloud.utils.exception.CloudRuntimeException;
++import com.cloud.utils.exception.CloudRuntimeException;
  import com.cloud.vm.DiskProfile;
  import com.cloud.vm.ReservationContext;
  import com.cloud.vm.VMInstanceVO;
@@@ -428,6 -437,60 +435,60 @@@ public class DeploymentPlanningManagerI
          return dest;
      }
  
 -    private void checkForNonDedicatedResources(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DataCenter dc, ExcludeList avoids) {
++    private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, DataCenter dc, ExcludeList avoids) {
+         boolean isExplicit = false;
+         VirtualMachine vm = vmProfile.getVirtualMachine();
+         // check affinity group of type Explicit dedication exists
+         List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), "ExplicitDedication");
+ 
+         if (vmGroupMappings != null && !vmGroupMappings.isEmpty()){
+             isExplicit = true;
+         }
+ 
+         if (!isExplicit && vm.getType() == VirtualMachine.Type.User) {
+             //add explicitly dedicated resources in avoidList
+             DedicatedResourceVO dedicatedZone = _dedicatedDao.findByZoneId(dc.getId());
+             if (dedicatedZone != null) {
+                 long accountDomainId = vmProfile.getOwner().getDomainId();
+                 if (dedicatedZone.getDomainId() != null && !dedicatedZone.getDomainId().equals(accountDomainId)) {
+                     throw new CloudRuntimeException("Failed to deploy VM. Zone " + dc.getName() + " is dedicated.");
+                 }
+             }
+ 
+             List<HostPodVO> podsInDc = _podDao.listByDataCenterId(dc.getId());
+             for (HostPodVO pod : podsInDc) {
+                 DedicatedResourceVO dedicatedPod = _dedicatedDao.findByPodId(pod.getId());
+                 if (dedicatedPod != null) {
+                     avoids.addPod(dedicatedPod.getPodId());
+                     if (s_logger.isDebugEnabled()) {
+                         s_logger.debug("Cannot use this dedicated pod " + pod.getName() + ".");
+                     }
+                 }
+             }
+ 
+             List<ClusterVO> clusterInDc = _clusterDao.listClustersByDcId(dc.getId());
+             for (ClusterVO cluster : clusterInDc) {
+                 DedicatedResourceVO dedicatedCluster = _dedicatedDao.findByClusterId(cluster.getId());
+                 if (dedicatedCluster != null) {
+                     avoids.addCluster(dedicatedCluster.getClusterId());
+                     if (s_logger.isDebugEnabled()) {
+                         s_logger.debug("Cannot use this dedicated Cluster " + cluster.getName() + ".");
+                     }
+                 }
+             }
+             List<HostVO> hostInDc = _hostDao.listByDataCenterId(dc.getId());
+             for (HostVO host : hostInDc) {
+                 DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(host.getId());
+                 if (dedicatedHost != null) {
+                     avoids.addHost(dedicatedHost.getHostId());
+                     if (s_logger.isDebugEnabled()) {
+                         s_logger.debug("Cannot use this dedicated host " + host.getName() + ".");
+                     }
+                 }
+             }
+         }
+     }
+ 
      private void resetAvoidSet(ExcludeList avoidSet, ExcludeList removeSet) {
          if (avoidSet.getDataCentersToAvoid() != null && removeSet.getDataCentersToAvoid() != null) {
              avoidSet.getDataCentersToAvoid().removeAll(removeSet.getDataCentersToAvoid());
@@@ -446,14 -509,14 +507,15 @@@
          }
      }
  
-     private PlannerResourceUsage getPlannerUsage(DeploymentPlanner planner) {
 -    private PlannerResourceUsage getPlannerUsage(DeploymentPlanner planner, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException {
++    private PlannerResourceUsage getPlannerUsage(DeploymentPlanner planner, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids)
++            throws InsufficientServerCapacityException {
          if (planner != null && planner instanceof DeploymentClusterPlanner) {
-             return ((DeploymentClusterPlanner) planner).getResourceUsage();
+             return ((DeploymentClusterPlanner) planner).getResourceUsage(vmProfile, plan, avoids);
          } else {
              return DeploymentPlanner.PlannerResourceUsage.Shared;
 -        }
 +            }
  
 -    }
 +        }
  
      @DB
      private boolean checkIfHostFitsPlannerUsage(long hostId, PlannerResourceUsage resourceUsageRequired) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/deploy/FirstFitPlanner.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/deploy/FirstFitPlanner.java
index bc5cedb,7124de2..15da8ba
--- a/server/src/com/cloud/deploy/FirstFitPlanner.java
+++ b/server/src/com/cloud/deploy/FirstFitPlanner.java
@@@ -494,10 -514,11 +494,11 @@@ public class FirstFitPlanner extends Pl
              ExcludeList avoid) throws InsufficientServerCapacityException {
          // TODO Auto-generated method stub
          return null;
 -    }
 +        }
  
      @Override
-     public PlannerResourceUsage getResourceUsage() {
 -    public PlannerResourceUsage getResourceUsage(VirtualMachineProfile<? extends VirtualMachine> vmProfile,
++    public PlannerResourceUsage getResourceUsage(VirtualMachineProfile vmProfile,
+             DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
          return PlannerResourceUsage.Shared;
      }
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/NetworkManagerImpl.java
index 4ce8c6d,d6a6450..0cbe99c
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@@ -4312,41 -4297,42 +4297,42 @@@ public class NetworkManagerImpl extend
  
  
      private boolean removeVmSecondaryIpsOfNic(long nicId) {
 -       Transaction txn = Transaction.currentTxn();
 -       txn.start();
 -       List <NicSecondaryIpVO> ipList = _nicSecondaryIpDao.listByNicId(nicId);
 -       if (ipList != null) {
 -           for (NicSecondaryIpVO ip: ipList) {
 -               _nicSecondaryIpDao.remove(ip.getId());
 +           Transaction txn = Transaction.currentTxn();
 +           txn.start();
 +           List <NicSecondaryIpVO> ipList = _nicSecondaryIpDao.listByNicId(nicId);
 +           if (ipList != null) {
 +               for (NicSecondaryIpVO ip: ipList) {
 +                   _nicSecondaryIpDao.remove(ip.getId());
 +               }
 +               s_logger.debug("Revoving nic secondary ip entry ...");
             }
 -           s_logger.debug("Revoving nic secondary ip entry ...");
 -       }
 -       txn.commit();
 -       return true;
 -    }
 +           txn.commit();
 +           return true;
 +        }
  
  
 -    @Override
 -    public String allocatePublicIpForGuestNic(Long networkId, DataCenter dc, Pod pod,Account owner,
 -            String requestedIp) throws InsufficientAddressCapacityException {
 -        PublicIp ip = assignPublicIpAddress(dc.getId(), null, owner, VlanType.DirectAttached, networkId, requestedIp, false);
 -        if (ip == null) {
 -            s_logger.debug("There is no free public ip address");
 -            return null;
 +        @Override
 +        public String allocatePublicIpForGuestNic(Long networkId, DataCenter dc, Pod pod,Account owner,
 +                String requestedIp) throws InsufficientAddressCapacityException {
 +            PublicIp ip = assignPublicIpAddress(dc.getId(), null, owner, VlanType.DirectAttached, networkId, requestedIp, false);
 +            if (ip == null) {
 +                s_logger.debug("There is no free public ip address");
 +                return null;
 +            }
 +            Ip ipAddr = ip.getAddress();
 +            return ipAddr.addr();
          }
 -        Ip ipAddr = ip.getAddress();
 -        return ipAddr.addr();
 -    }
 -
 +        
  
 -    @Override
 +        @Override
-         public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) {
+     public NicVO savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType) {
 -        NicVO nic = new NicVO(null, null, network.getId(), null); 
 -        nic.setIp4Address(ip4Address);
 +            NicVO nic = new NicVO(null, null, network.getId(), null);
 +            nic.setIp4Address(ip4Address);
+         nic.setIp6Address(ip6Address);
 -        nic.setReservationStrategy(ReservationStrategy.PlaceHolder);
 -        nic.setState(Nic.State.Reserved);
 -        nic.setVmType(vmType);
 -        return _nicDao.persist(nic);
 -    }
 +            nic.setReservationStrategy(ReservationStrategy.PlaceHolder);
 +            nic.setState(Nic.State.Reserved);
 +            nic.setVmType(vmType);
 +            return _nicDao.persist(nic);
 +        }
          
   }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/firewall/FirewallManagerImpl.java
index d34e1a8,f7275b0..85f6b71
--- a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
+++ b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
@@@ -160,8 -159,9 +160,9 @@@ public class FirewallManagerImpl extend
                  rule.getIcmpType(), null, rule.getType(), rule.getNetworkId(), rule.getTrafficType());
      }
  
+     @Override
      public FirewallRule createIngressFirewallRule(FirewallRule rule) throws NetworkRuleConflictException {
 -         Account caller = UserContext.current().getCaller();
 +         Account caller = CallContext.current().getCallingAccount();
          Long sourceIpAddressId = rule.getSourceIpAddressId();
   
          return createFirewallRule(sourceIpAddressId, caller, rule.getXid(), rule.getSourcePortStart(), 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/network/guru/DirectNetworkGuru.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index df1687b,db4786a..742a3c1
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@@ -196,7 -168,7 +196,6 @@@ import com.cloud.resource.ResourceManag
  import com.cloud.server.ConfigurationServer;
  import com.cloud.service.ServiceOfferingVO;
  import com.cloud.service.dao.ServiceOfferingDao;
--import com.cloud.storage.GuestOSVO;
  import com.cloud.storage.VMTemplateVO;
  import com.cloud.storage.Volume.Type;
  import com.cloud.storage.VolumeVO;
@@@ -1444,12 -1436,10 +1443,10 @@@ public class VirtualNetworkApplianceMan
                      guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: "
                      + guestNetwork;
              assert guestNetwork.getTrafficType() == TrafficType.Guest;
 -        
 +
              // 1) Get deployment plan and find out the list of routers
-             boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic ||
-                     _networkModel.areServicesSupportedInNetwork(guestNetwork.getId(), Service.SecurityGroup))
-                     && guestNetwork.getTrafficType() == TrafficType.Guest;
+             boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic);
 -        
 +
              // dest has pod=null, for Basic Zone findOrDeployVRs for all Pods
              List<DeployDestination> destinations = new ArrayList<DeployDestination>();
  
@@@ -1749,33 -1740,37 +1746,37 @@@
              s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork);
              String defaultNetworkStartIp = null, defaultNetworkStartIpv6 = null;
              if (!setupPublicNetwork) {
-                 if (guestNetwork.getCidr() != null) {
 -            	Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, plan.getPodId());
 +                    Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, plan.getPodId());
-                     if (placeholder != null) {
-                         s_logger.debug("Requesting ip address " + placeholder.getIp4Address() + " stored in placeholder nic for the network " + guestNetwork);
+             	if (guestNetwork.getCidr() != null) {
+             		if (placeholder != null && placeholder.getIp4Address() != null) {
+             			s_logger.debug("Requesting ipv4 address " + placeholder.getIp4Address() + " stored in placeholder nic for the network " + guestNetwork);
 -            			defaultNetworkStartIp = placeholder.getIp4Address(); 
 -            		} else {
 -            			String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
 -            			if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
 -            				defaultNetworkStartIp = startIp;
 +                        defaultNetworkStartIp = placeholder.getIp4Address();
 +                    } else {
 +                        String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
 +                        if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
 +                            defaultNetworkStartIp = startIp;
-                         } else if (s_logger.isDebugEnabled()) {
-                             s_logger.debug("First ip " + startIp + " in network id=" + guestNetwork.getId() +
+             			} else if (s_logger.isDebugEnabled()){
+             				s_logger.debug("First ipv4 " + startIp + " in network id=" + guestNetwork.getId() + 
 -            						" is already allocated, can't use it for domain router; will get random ip address from the range");
 -            			}
 -            		}
 -            	}
 +                                    " is already allocated, can't use it for domain router; will get random ip address from the range");
 +                        }
 +                    }
 +                }
  
-                 //FIXME - get ipv6 stored in the placeholder
 -            	if (guestNetwork.getIp6Cidr() != null) {
 +                if (guestNetwork.getIp6Cidr() != null) {
+             		if (placeholder != null && placeholder.getIp6Address() != null) {
+             			s_logger.debug("Requesting ipv6 address " + placeholder.getIp6Address() + " stored in placeholder nic for the network " + guestNetwork);
+             			defaultNetworkStartIpv6 = placeholder.getIp6Address(); 
+             		} else {
 -            			String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
 -            			if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(), startIpv6) == null) {
 -            				defaultNetworkStartIpv6 = startIpv6;
 -            			} else if (s_logger.isDebugEnabled()){
 -            				s_logger.debug("First ipv6 " + startIpv6 + " in network id=" + guestNetwork.getId() + 
 -            						" is already allocated, can't use it for domain router; will get random ipv6 address from the range");
 -            			}
 -            		}
 -            	}
 +                    String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
 +                    if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(), startIpv6) == null) {
 +                        defaultNetworkStartIpv6 = startIpv6;
 +                    } else if (s_logger.isDebugEnabled()) {
 +                        s_logger.debug("First ipv6 " + startIpv6 + " in network id=" + guestNetwork.getId() +
 +                                " is already allocated, can't use it for domain router; will get random ipv6 address from the range");
 +                    }
 +                }
 +            }
+             }
  
              NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp, defaultNetworkStartIpv6);
              if (setupPublicNetwork) {
@@@ -2487,7 -2488,10 +2488,10 @@@
              for (NicIpAliasVO aliasVO : aliasVOs) {
                     activeIpAliasTOs.add(new IpAliasTO(aliasVO.getIp4Address(), aliasVO.getNetmask(), aliasVO.getAliasCount().toString()));
              }
+             if (revokedIpAliasTOs.size() != 0 || activeIpAliasTOs.size() != 0){
 -                createDeleteIpAliasCommand(router, revokedIpAliasTOs, activeIpAliasTOs, guestNetworkId, cmds);
 +            createDeleteIpAliasCommand(router, revokedIpAliasTOs, activeIpAliasTOs, guestNetworkId, cmds);
+                 configDnsMasq(router, _networkDao.findById(guestNetworkId), cmds);
+             }
  
          }
      }
@@@ -2789,7 -2800,13 +2793,13 @@@
                          for (VlanVO vlan : vlanList) {
                              vlanDbIdList.add(vlan.getId());
                          }
+                         if (dc.getNetworkType() == NetworkType.Basic) {
 -                            routerPublicIP = _networkMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), vm.getPodIdToDeployIn(), caller, Vlan.VlanType.DirectAttached, vlanDbIdList, nic.getNetworkId(), null, false);
 +                        routerPublicIP = _networkMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), vm.getPodIdToDeployIn(), caller, Vlan.VlanType.DirectAttached, vlanDbIdList, nic.getNetworkId(), null, false);
+                         }
+                         else {
+                             routerPublicIP = _networkMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), null, caller, Vlan.VlanType.DirectAttached, vlanDbIdList, nic.getNetworkId(), null, false);
+                         }
+ 
                          routerAliasIp = routerPublicIP.getAddress().addr();
                      }
                  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
index 1d1ae4d,7115499..c4742f7
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@@ -874,9 -949,9 +874,9 @@@ public class VpcVirtualNetworkAppliance
          if (router.getVpcId() != null) {
              if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.NetworkACL, Provider.VPCVirtualRouter)) {
                  List<NetworkACLItemVO> networkACLs = _networkACLMgr.listNetworkACLItems(guestNetworkId);
+                 if ((networkACLs != null) && !networkACLs.isEmpty()) {
 -                    s_logger.debug("Found " + networkACLs.size() + " network ACLs to apply as a part of VPC VR " + router
 -                            + " start for guest network id=" + guestNetworkId);
 +                s_logger.debug("Found " + networkACLs.size() + " network ACLs to apply as a part of VPC VR " + router
 +                        + " start for guest network id=" + guestNetworkId);
-                 if (!networkACLs.isEmpty()) {
                      createNetworkACLsCommands(networkACLs, router, cmds, guestNetworkId, false);
                  }
              }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/network/rules/RulesManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/rules/RulesManagerImpl.java
index d3280ad,41bf2b3..05df39f
--- a/server/src/com/cloud/network/rules/RulesManagerImpl.java
+++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java
@@@ -24,11 -24,8 +24,10 @@@ import java.util.Set
  
  import javax.ejb.Local;
  import javax.inject.Inject;
- import javax.naming.ConfigurationException;
  
  import org.apache.cloudstack.api.command.user.firewall.ListPortForwardingRulesCmd;
 +import org.apache.cloudstack.context.CallContext;
 +
  import org.apache.log4j.Logger;
  import org.springframework.stereotype.Component;
  

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
index a89b414,4ad22d9..5489366
--- a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
+++ b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
@@@ -304,29 -303,31 +304,31 @@@ public class NetworkACLServiceImpl exte
          }
  
          //Validate Protocol
+         if(protocol != null){
 -            //Check if protocol is a number
 -            if(StringUtils.isNumeric(protocol)){
 -                int protoNumber = Integer.parseInt(protocol);
 -                if(protoNumber < 0 || protoNumber > 255){
 -                    throw new InvalidParameterValueException("Invalid protocol number: " + protoNumber);
 -                }
 -            } else {
 -                //Protocol is not number
 -                //Check for valid protocol strings
 -                String supportedProtocols = "tcp,udp,icmp,all";
 -                if(!supportedProtocols.contains(protocol.toLowerCase())){
 -                    throw new InvalidParameterValueException("Invalid protocol: " + protocol);
 -                }
 +        //Check if protocol is a number
 +        if(StringUtils.isNumeric(protocol)){
 +            int protoNumber = Integer.parseInt(protocol);
 +            if(protoNumber < 0 || protoNumber > 255){
 +                throw new InvalidParameterValueException("Invalid protocol number: " + protoNumber);
              }
 -
 -            // icmp code and icmp type can't be passed in for any other protocol rather than icmp
 -            if (!protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (icmpCode != null || icmpType != null)) {
 -                throw new InvalidParameterValueException("Can specify icmpCode and icmpType for ICMP protocol only");
 +        } else {
 +            //Protocol is not number
 +            //Check for valid protocol strings
 +            String supportedProtocols = "tcp,udp,icmp,all";
 +            if(!supportedProtocols.contains(protocol.toLowerCase())){
 +                throw new InvalidParameterValueException("Invalid protocol: " + protocol);
              }
 +        }
  
 -            if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (portStart != null || portEnd != null)) {
 -                throw new InvalidParameterValueException("Can't specify start/end port when protocol is ICMP");
 -            }
 +        // icmp code and icmp type can't be passed in for any other protocol rather than icmp
 +        if (!protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (icmpCode != null || icmpType != null)) {
 +            throw new InvalidParameterValueException("Can specify icmpCode and icmpType for ICMP protocol only");
 +        }
 +
 +        if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (portStart != null || portEnd != null)) {
 +            throw new InvalidParameterValueException("Can't specify start/end port when protocol is ICMP");
 +        }
+         }
  
          //validate icmp code and type
          if (icmpType != null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/vpc/VpcManagerImpl.java
index 869054d,b41003a..7a2520b
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@@ -16,29 -16,6 +16,29 @@@
  // under the License.
  package com.cloud.network.vpc;
  
 +import java.util.ArrayList;
 +import java.util.Arrays;
 +import java.util.HashMap;
 +import java.util.HashSet;
 +import java.util.List;
 +import java.util.Map;
 +import java.util.Set;
 +import java.util.concurrent.Executors;
 +import java.util.concurrent.ScheduledExecutorService;
 +import java.util.concurrent.TimeUnit;
 +
 +import javax.ejb.Local;
 +import javax.inject.Inject;
 +import javax.naming.ConfigurationException;
 +
++import org.apache.log4j.Logger;
++import org.springframework.stereotype.Component;
++
 +import org.apache.cloudstack.acl.ControlledEntity.ACLType;
 +import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd;
 +import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd;
 +import org.apache.cloudstack.context.CallContext;
 +
- import org.apache.log4j.Logger;
- import org.springframework.stereotype.Component;
- 
  import com.cloud.configuration.Config;
  import com.cloud.configuration.ConfigurationManager;
  import com.cloud.configuration.Resource.ResourceType;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/resource/ResourceManagerImpl.java
index afc2609,c6e8d7d..4da572e
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@@ -79,8 -77,8 +79,10 @@@ import com.cloud.configuration.dao.Conf
  import com.cloud.dc.ClusterDetailsDao;
  import com.cloud.dc.ClusterDetailsVO;
  import com.cloud.dc.ClusterVO;
++import com.cloud.dc.DataCenter.NetworkType;
  import com.cloud.dc.DataCenterIpAddressVO;
  import com.cloud.dc.DataCenterVO;
++import com.cloud.dc.DedicatedResourceVO;
  import com.cloud.dc.HostPodVO;
  import com.cloud.dc.PodCluster;
  import com.cloud.dc.dao.ClusterDao;
@@@ -163,7 -163,7 +166,6 @@@ import com.cloud.vm.VMInstanceVO
  import com.cloud.vm.VirtualMachine.State;
  import com.cloud.vm.VirtualMachineManager;
  import com.cloud.vm.dao.VMInstanceDao;
--import com.cloud.dc.DataCenter.NetworkType;
  
  @Component
  @Local({ ResourceManager.class, ResourceService.class })
@@@ -220,9 -220,9 +222,11 @@@ public class ResourceManagerImpl extend
      @Inject
      protected StorageService                 _storageSvr;
      @Inject
 +    protected AttacheHandler _attacheHandler; // FIXME: Get rid of me!
 +    @Inject
      PlannerHostReservationDao _plannerHostReserveDao;
+     @Inject
+     protected DedicatedResourceDao           _dedicatedDao;
  
      protected List<? extends Discoverer> _discoverers;
      public List<? extends Discoverer> getDiscoverers() {
@@@ -1104,11 -1109,16 +1113,16 @@@
  						&& Boolean.parseBoolean(_configDao
  								.getValue(Config.VmwareUseNexusVSwitch
  										.toString()))) {
 -				    _clusterVSMMapDao.removeByClusterId(cmd.getId());
 -				}
 +                    _clusterVSMMapDao.removeByClusterId(cmd.getId());
 +                }
+ 				// remove from dedicated resources
+ 				DedicatedResourceVO dr = _dedicatedDao.findByClusterId(cluster.getId());
+ 				if (dr != null) {
+ 				    _dedicatedDao.remove(dr.getId());
+ 				}
 -			}
 +            }
  
 -			txn.commit();
 +            txn.commit();
              return true;
  		} catch (CloudRuntimeException e) {
              throw e;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/server/ManagementServerImpl.java
index ffa2779,96c72e4..a365f7a
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@@ -43,19 -44,18 +44,11 @@@ import javax.crypto.spec.SecretKeySpec
  import javax.inject.Inject;
  import javax.naming.ConfigurationException;
  
 -import com.cloud.exception.*;
 -import com.cloud.vm.*;
 -import org.apache.cloudstack.acl.ControlledEntity;
 -import org.apache.cloudstack.acl.SecurityChecker.AccessType;
 -import org.apache.cloudstack.api.ApiConstants;
 -
 -import com.cloud.event.ActionEventUtils;
 -import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd;
 -import org.apache.cloudstack.api.command.admin.region.*;
 -import org.apache.cloudstack.api.response.ExtractResponse;
  import org.apache.commons.codec.binary.Base64;
  import org.apache.log4j.Logger;
 +
 +import org.apache.cloudstack.acl.ControlledEntity;
 +import org.apache.cloudstack.acl.SecurityChecker.AccessType;
- import org.apache.cloudstack.api.ApiConstants;
- 
- import com.cloud.event.ActionEventUtils;
- import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd;
- import org.apache.cloudstack.api.command.admin.region.*;
- import org.apache.cloudstack.api.response.ExtractResponse;
- import org.apache.commons.codec.binary.Base64;
- import org.apache.log4j.Logger;
  import org.apache.cloudstack.affinity.AffinityGroupProcessor;
  import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
  import org.apache.cloudstack.api.ApiConstants;
@@@ -134,6 -133,6 +127,12 @@@ import org.apache.cloudstack.api.comman
  import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd;
  import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
  import org.apache.cloudstack.api.command.admin.pod.UpdatePodCmd;
++import org.apache.cloudstack.api.command.admin.region.AddRegionCmd;
++import org.apache.cloudstack.api.command.admin.region.CreatePortableIpRangeCmd;
++import org.apache.cloudstack.api.command.admin.region.DeletePortableIpRangeCmd;
++import org.apache.cloudstack.api.command.admin.region.ListPortableIpRangesCmd;
++import org.apache.cloudstack.api.command.admin.region.RemoveRegionCmd;
++import org.apache.cloudstack.api.command.admin.region.UpdateRegionCmd;
  import org.apache.cloudstack.api.command.admin.resource.ArchiveAlertsCmd;
  import org.apache.cloudstack.api.command.admin.resource.DeleteAlertsCmd;
  import org.apache.cloudstack.api.command.admin.resource.ListAlertsCmd;
@@@ -421,13 -403,12 +420,14 @@@ import org.apache.cloudstack.api.comman
  import org.apache.cloudstack.api.command.user.vpn.UpdateVpnCustomerGatewayCmd;
  import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd;
  import org.apache.cloudstack.api.response.ExtractResponse;
++import org.apache.cloudstack.context.CallContext;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
  import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
 +import org.apache.cloudstack.framework.jobs.AsyncJob;
 +import org.apache.cloudstack.framework.jobs.AsyncJobConstants;
 +import org.apache.cloudstack.framework.jobs.AsyncJobManager;
  import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
  import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 -import org.apache.commons.codec.binary.Base64;
 -import org.apache.log4j.Logger;
  
  import com.cloud.agent.AgentManager;
  import com.cloud.agent.api.GetVncPortAnswer;
@@@ -602,79 -569,78 +602,6 @@@ import com.cloud.vm.dao.VMInstanceDao
  import edu.emory.mathcs.backport.java.util.Arrays;
  import edu.emory.mathcs.backport.java.util.Collections;
  
--import org.apache.cloudstack.acl.ControlledEntity;
--import org.apache.cloudstack.api.command.admin.autoscale.CreateCounterCmd;
--import org.apache.cloudstack.api.command.admin.autoscale.DeleteCounterCmd;
--import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
--import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
--import org.apache.cloudstack.api.command.admin.cluster.ListClustersCmd;
--import org.apache.cloudstack.api.command.admin.cluster.UpdateClusterCmd;
--import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd;
--import org.apache.cloudstack.api.command.admin.config.ListHypervisorCapabilitiesCmd;
--import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
--import org.apache.cloudstack.api.command.admin.config.UpdateHypervisorCapabilitiesCmd;
--import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd;
--import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd;
--import org.apache.cloudstack.api.command.admin.pod.CreatePodCmd;
--import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd;
--import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
--import org.apache.cloudstack.api.command.admin.pod.UpdatePodCmd;
--import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd;
--import org.apache.cloudstack.api.command.admin.swift.ListSwiftsCmd;
--import org.apache.cloudstack.api.command.admin.template.PrepareTemplateCmd;
--import org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd;
--import org.apache.cloudstack.api.command.admin.vlan.DeleteVlanIpRangeCmd;
--import org.apache.cloudstack.api.command.admin.vlan.ListVlanIpRangesCmd;
--import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd;
--import org.apache.cloudstack.api.command.admin.vm.MigrateVMCmd;
--import org.apache.cloudstack.api.command.admin.vm.MigrateVirtualMachineWithVolumeCmd;
--import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd;
--import org.apache.cloudstack.api.command.admin.zone.CreateZoneCmd;
--import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd;
--import org.apache.cloudstack.api.command.admin.zone.MarkDefaultZoneForAccountCmd;
--import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
--import org.apache.cloudstack.api.command.user.account.AddAccountToProjectCmd;
--import org.apache.cloudstack.api.command.user.account.DeleteAccountFromProjectCmd;
--import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
--import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
--import org.apache.cloudstack.api.command.user.address.AssociateIPAddrCmd;
--import org.apache.cloudstack.api.command.user.address.DisassociateIPAddrCmd;
--import org.apache.cloudstack.api.command.user.address.ListPublicIpAddressesCmd;
--import org.apache.cloudstack.api.command.user.config.ListCapabilitiesCmd;
--import org.apache.cloudstack.api.command.user.event.ArchiveEventsCmd;
--import org.apache.cloudstack.api.command.user.event.DeleteEventsCmd;
--import org.apache.cloudstack.api.command.user.event.ListEventTypesCmd;
--import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
--import org.apache.cloudstack.api.command.user.guest.ListGuestOsCategoriesCmd;
--import org.apache.cloudstack.api.command.user.guest.ListGuestOsCmd;
--import org.apache.cloudstack.api.command.user.job.ListAsyncJobsCmd;
--import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
--import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
--import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
--import org.apache.cloudstack.api.command.user.region.ListRegionsCmd;
--import org.apache.cloudstack.api.command.user.region.ha.gslb.*;
--import org.apache.cloudstack.api.command.user.ssh.CreateSSHKeyPairCmd;
--import org.apache.cloudstack.api.command.user.ssh.DeleteSSHKeyPairCmd;
--import org.apache.cloudstack.api.command.user.ssh.ListSSHKeyPairsCmd;
--import org.apache.cloudstack.api.command.user.ssh.RegisterSSHKeyPairCmd;
--import org.apache.cloudstack.api.command.user.tag.CreateTagsCmd;
--import org.apache.cloudstack.api.command.user.tag.DeleteTagsCmd;
--import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
--import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd;
--import org.apache.cloudstack.api.command.user.vmgroup.DeleteVMGroupCmd;
--import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
--import org.apache.cloudstack.api.command.user.vmgroup.UpdateVMGroupCmd;
--import org.apache.cloudstack.api.command.user.vmsnapshot.CreateVMSnapshotCmd;
--import org.apache.cloudstack.api.command.user.vmsnapshot.DeleteVMSnapshotCmd;
--import org.apache.cloudstack.api.command.user.vmsnapshot.ListVMSnapshotCmd;
--import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd;
--import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
--import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
--import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
--import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
--import org.apache.cloudstack.api.command.admin.config.ListDeploymentPlannersCmd;
- import org.apache.cloudstack.context.CallContext;
--
  public class ManagementServerImpl extends ManagerBase implements ManagementServer {
      public static final Logger s_logger = Logger.getLogger(ManagementServerImpl.class.getName());
  

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/storage/VolumeManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/VolumeManagerImpl.java
index 3284eb3,43f3681..b75f461
--- a/server/src/com/cloud/storage/VolumeManagerImpl.java
+++ b/server/src/com/cloud/storage/VolumeManagerImpl.java
@@@ -147,8 -128,11 +147,10 @@@ import com.cloud.template.TemplateManag
  import com.cloud.user.Account;
  import com.cloud.user.AccountManager;
  import com.cloud.user.ResourceLimitService;
+ import com.cloud.user.VmDiskStatisticsVO;
 -import com.cloud.user.UserContext;
  import com.cloud.user.dao.AccountDao;
  import com.cloud.user.dao.UserDao;
+ import com.cloud.user.dao.VmDiskStatisticsDao;
  import com.cloud.uservm.UserVm;
  import com.cloud.utils.EnumUtils;
  import com.cloud.utils.NumbersUtil;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/user/AccountManagerImpl.java
index 2033a78,6b4bf0e..b623dd2
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@@ -49,10 -46,11 +49,10 @@@ import org.apache.cloudstack.api.comman
  import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
  import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
  import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
 +import org.apache.cloudstack.context.CallContext;
+ import org.apache.cloudstack.region.gslb.GlobalLoadBalancerRuleDao;
 -import org.apache.commons.codec.binary.Base64;
 -import org.apache.log4j.Logger;
  
  import com.cloud.api.ApiDBUtils;
- import com.cloud.api.query.dao.UserAccountJoinDao;
  import com.cloud.api.query.vo.ControlledViewEntity;
  import com.cloud.configuration.Config;
  import com.cloud.configuration.ConfigurationManager;
@@@ -102,8 -104,8 +104,7 @@@ import com.cloud.projects.ProjectManage
  import com.cloud.projects.ProjectVO;
  import com.cloud.projects.dao.ProjectAccountDao;
  import com.cloud.projects.dao.ProjectDao;
 -import com.cloud.region.ha.GlobalLoadBalancingRulesService;
  import com.cloud.server.auth.UserAuthenticator;
- import com.cloud.storage.StorageManager;
  import com.cloud.storage.VMTemplateVO;
  import com.cloud.storage.Volume;
  import com.cloud.storage.VolumeManager;
@@@ -1587,22 -1623,14 +1616,14 @@@ public class AccountManagerImpl extend
      }
  
      @Override
-     public Account getActiveAccountById(Long accountId) {
-         if (accountId == null) {
-             throw new InvalidParameterValueException("AccountId is required by account search");
-         } else {
+     public Account getActiveAccountById(long accountId) {
 -        return _accountDao.findById(accountId);
 -    }
 +            return _accountDao.findById(accountId);
 +        }
-     }
  
      @Override
-     public Account getAccount(Long accountId) {
-         if (accountId == null) {
-             throw new InvalidParameterValueException("AccountId is required by account search");
-         } else {
+     public Account getAccount(long accountId) {
 -        return _accountDao.findByIdIncludingRemoved(accountId);
 -    }
 +            return _accountDao.findByIdIncludingRemoved(accountId);
 +        }
-     }
  
      @Override
      public RoleType getRoleType(Account account) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/user/DomainManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/vm/UserVmManager.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/vm/UserVmManagerImpl.java
index 7798dd8,b919f12..6b840a9
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@@ -58,20 -56,28 +58,23 @@@ import org.apache.cloudstack.api.comman
  import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd;
  import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd;
  import org.apache.cloudstack.api.command.user.vmgroup.DeleteVMGroupCmd;
 +import org.apache.cloudstack.context.CallContext;
  import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity;
  import org.apache.cloudstack.engine.service.api.OrchestrationService;
 +import org.apache.cloudstack.framework.jobs.AsyncJobManager;
  import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
  import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 -import org.apache.commons.codec.binary.Base64;
 -import org.apache.log4j.Logger;
  
  import com.cloud.agent.AgentManager;
 -import com.cloud.agent.AgentManager.OnError;
  import com.cloud.agent.api.Answer;
+ import com.cloud.agent.api.GetVmDiskStatsAnswer;
+ import com.cloud.agent.api.GetVmDiskStatsCommand;
  import com.cloud.agent.api.GetVmStatsAnswer;
  import com.cloud.agent.api.GetVmStatsCommand;
  import com.cloud.agent.api.PvlanSetupCommand;
  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.NicTO;
  import com.cloud.agent.api.to.VirtualMachineTO;
@@@ -206,7 -214,9 +211,8 @@@ import com.cloud.user.ResourceLimitServ
  import com.cloud.user.SSHKeyPair;
  import com.cloud.user.SSHKeyPairVO;
  import com.cloud.user.User;
 -import com.cloud.user.UserContext;
  import com.cloud.user.UserVO;
+ import com.cloud.user.VmDiskStatisticsVO;
  import com.cloud.user.dao.AccountDao;
  import com.cloud.user.dao.SSHKeyPairDao;
  import com.cloud.user.dao.UserDao;
@@@ -732,12 -754,12 +749,13 @@@ public class UserVmManagerImpl extends 
              return null;
          }
  
-         try {
+         if (vm.getState() == State.Running && vm.getHostId() != null) {
+             collectVmDiskStatistics(vm);
 -            return _itMgr.reboot(vm, null, caller, owner);
 +            _itMgr.reboot(vm.getUuid(), caller, owner);
 +            return _vmDao.findById(vmId);
-         } catch (CloudRuntimeException e) {
-             // FIXME: Not even sure if this should be here but got to conform to how it worked before.
-             s_logger.warn("Unable to reboot virtual machine " + vm);
+         } else {
+             s_logger.error("Vm id=" + vmId
+                     + " is not in Running state, failed to reboot");
              return null;
          }
      }
@@@ -1089,13 -1112,48 +1108,48 @@@
          }
  
      }
 -    
 +
      @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();
 +        Account caller = CallContext.current().getCallingAccount();
  
          // Verify input parameters
 -        VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
 +        VirtualMachine vmInstance = _vmInstanceDao.findById(vmId);
          if(vmInstance.getHypervisorType() != HypervisorType.XenServer && vmInstance.getHypervisorType() != HypervisorType.VMware){
              throw new InvalidParameterValueException("This operation not permitted for this hypervisor of the vm");
          }
@@@ -3314,6 -3416,122 +3404,122 @@@
              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();
+             }
+         }
      }
  
  
@@@ -3686,9 -3919,23 +3907,22 @@@
                              + " already has max Running VMs(count includes system VMs), cannot migrate to this host");
          }
  
+         collectVmDiskStatistics(vm);
 -        VMInstanceVO migratedVm = _itMgr.migrate(vm, srcHostId, dest);
 -        return migratedVm;
 +        return _itMgr.migrate(vm.getUuid(), srcHostId, dest);
      }
  
+     private boolean checkIfHostIsDedicated(HostVO host) {
+         long hostId = host.getId();
+         DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId);
+         DedicatedResourceVO dedicatedClusterOfHost = _dedicatedDao.findByClusterId(host.getClusterId());
+         DedicatedResourceVO dedicatedPodOfHost = _dedicatedDao.findByPodId(host.getPodId());
+         if(dedicatedHost != null || dedicatedClusterOfHost != null || dedicatedPodOfHost != null) {
+             return true;
+         } else {
+             return false;
+         }
+     }
+ 
      @Override
      @ActionEvent(eventType = EventTypes.EVENT_VM_MIGRATE, eventDescription = "migrating VM", async = true)
      public VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinationHost,
@@@ -4397,15 -4650,68 +4631,9 @@@
      }
  
      @Override
 -    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
 -            ReservationContext context, DeployDestination dest)
 -                    throws ConcurrentOperationException, ResourceUnavailableException,
 -                    InsufficientCapacityException {
 -        UserVmVO vmVO = _vmDao.findById(vm.getId());
 -        if (vmVO.getState() == State.Running) {
 -            try {
 -                PlugNicCommand plugNicCmd = new PlugNicCommand(nic,vm.getName(), vm.getType());
 -                Commands cmds = new Commands(OnError.Stop);
 -                cmds.addCommand("plugnic",plugNicCmd);
 -                _agentMgr.send(dest.getHost().getId(),cmds);
 -                PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class);
 -                if (!(plugNicAnswer != null && plugNicAnswer.getResult())) {
 -                    s_logger.warn("Unable to plug nic for " + vmVO + " due to: " + " due to: " + plugNicAnswer.getDetails());
 -                    return false;
 -                }
 -            } catch (OperationTimedoutException e) {
 -                throw new AgentUnavailableException("Unable to plug nic for " + vmVO + " in network " + network, dest.getHost().getId(), e);
 -            }
 -        } else if (vmVO.getState() == State.Stopped || vmVO.getState() == State.Stopping) {
 -            s_logger.warn(vmVO + " is Stopped, not sending PlugNicCommand.  Currently " + vmVO.getState());
 -        } else {
 -            s_logger.warn("Unable to plug nic, " + vmVO + " is not in the right state " + vmVO.getState());
 -            throw new ResourceUnavailableException("Unable to plug nic on the backend," +
 -                    vmVO + " is not in the right state", DataCenter.class, vmVO.getDataCenterId());
 -        }
 -        return true;
 -    }
 -
 -    @Override
 -    public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
 -            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
 -        UserVmVO vmVO = _vmDao.findById(vm.getId());
 -        if (vmVO.getState() == State.Running) {
 -            try {
 -                UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(nic,vm.getName());
 -                Commands cmds = new Commands(OnError.Stop);
 -                cmds.addCommand("unplugnic",unplugNicCmd);
 -                _agentMgr.send(dest.getHost().getId(),cmds);
 -                UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class);
 -                if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) {
 -                    s_logger.warn("Unable to unplug nic for " + vmVO + " due to: " + unplugNicAnswer.getDetails());
 -                    return false;
 -                }
 -            } catch (OperationTimedoutException e) {
 -                throw new AgentUnavailableException("Unable to unplug nic for " + vmVO + " in network " + network, dest.getHost().getId(), e);
 -            }
 -        } else if (vmVO.getState() == State.Stopped || vmVO.getState() == State.Stopping) {
 -            s_logger.warn(vmVO + " is Stopped, not sending UnPlugNicCommand.  Currently " + vmVO.getState());
 -        } else {
 -            s_logger.warn("Unable to unplug nic, " + vmVO + " is not in the right state " + vmVO.getState());
 -            throw new ResourceUnavailableException("Unable to unplug nic on the backend," +
 -                    vmVO + " is not in the right state", DataCenter.class, vmVO.getDataCenterId());
 -        }
 -        return true;
 -    }
 -
 -    @Override
 -    public void prepareStop(VirtualMachineProfile<UserVmVO> profile) {
 +    public void prepareStop(VirtualMachineProfile profile) {
+         UserVmVO vm = _vmDao.findById(profile.getId());
+         if (vm.getState() == State.Running)
+             collectVmDiskStatistics(vm);
      }
-     
- //    @Override
- //    public void vmWorkStart(VmWork work) {
- //    }
- //
- //    @Override
- //    public void vmWorkStop(VmWork work) {
- //    }
--
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 1774e1b,568fe55..56f066a
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@@ -3234,13 -2836,13 +3234,13 @@@ 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());
 -                    return nic;
 -                } else {
 -                    s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network);
 -                    return null;
 -                }
 +                return nic;
 +            } else {
 +                s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network);
 +                return null;
 +            }
              }finally{
                  if(!result){
                      _networkMgr.removeNic(vmProfile, _nicsDao.findById(nic.getId()));

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaa16af2/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --cc server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index b6bd71d,5211279..47413cf
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@@ -126,10 -125,9 +126,9 @@@ public class AffinityGroupServiceImpl e
      @DB
      @Override
      @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_DELETE, eventDescription = "Deleting affinity group")
-     public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName)
-             throws ResourceInUseException {
+     public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName) {
  
 -        Account caller = UserContext.current().getCaller();
 +        Account caller = CallContext.current().getCallingAccount();
          Account owner = _accountMgr.finalizeOwner(caller, account, domainId, null);
  
          AffinityGroupVO group = null;


Mime
View raw message