cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [46/50] [abbrv] Merged master to vmsync
Date Tue, 14 May 2013 00:43:09 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d4039743/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/server/ManagementServerImpl.java
index 17a9d58,86c1a64..612a4a0
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@@ -40,73 -41,372 +41,373 @@@ import java.util.concurrent.TimeUnit
  import javax.crypto.Mac;
  import javax.crypto.spec.SecretKeySpec;
  import javax.inject.Inject;
- import javax.management.InstanceAlreadyExistsException;
- import javax.management.MBeanRegistrationException;
- import javax.management.MalformedObjectNameException;
- import javax.management.NotCompliantMBeanException;
  import javax.naming.ConfigurationException;
  
- import com.cloud.storage.dao.*;
++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.affinity.AffinityGroupProcessor;
+ import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
  import org.apache.cloudstack.api.ApiConstants;
- 
- import com.cloud.event.ActionEventUtils;
  import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd;
- import org.apache.cloudstack.api.command.admin.account.*;
- import org.apache.cloudstack.api.command.admin.autoscale.*;
- import org.apache.cloudstack.api.command.admin.cluster.*;
- import org.apache.cloudstack.api.command.admin.config.*;
- import org.apache.cloudstack.api.command.admin.domain.*;
- import org.apache.cloudstack.api.command.admin.host.*;
- import org.apache.cloudstack.api.command.admin.ldap.*;
- import org.apache.cloudstack.api.command.admin.network.*;
- import org.apache.cloudstack.api.command.admin.offering.*;
- import org.apache.cloudstack.api.command.admin.pod.*;
- import org.apache.cloudstack.api.command.admin.region.*;
- import org.apache.cloudstack.api.command.admin.resource.*;
- import org.apache.cloudstack.api.command.admin.router.*;
- import org.apache.cloudstack.api.command.admin.storage.*;
- import org.apache.cloudstack.api.command.admin.swift.*;
- import org.apache.cloudstack.api.command.admin.systemvm.*;
- import org.apache.cloudstack.api.command.admin.template.*;
- import org.apache.cloudstack.api.command.admin.usage.*;
- import org.apache.cloudstack.api.command.admin.user.*;
- import org.apache.cloudstack.api.command.admin.vlan.*;
- import org.apache.cloudstack.api.command.admin.vm.*;
- import org.apache.cloudstack.api.command.admin.vpc.*;
- import org.apache.cloudstack.api.command.admin.zone.*;
- import org.apache.cloudstack.api.command.user.account.*;
- import org.apache.cloudstack.api.command.user.address.*;
- import org.apache.cloudstack.api.command.user.autoscale.*;
- import org.apache.cloudstack.api.command.user.config.*;
- import org.apache.cloudstack.api.command.user.event.*;
- import org.apache.cloudstack.api.command.user.firewall.*;
- import org.apache.cloudstack.api.command.user.guest.*;
- import org.apache.cloudstack.api.command.user.iso.*;
- import org.apache.cloudstack.api.command.user.job.*;
- import org.apache.cloudstack.api.command.user.loadbalancer.*;
- import org.apache.cloudstack.api.command.user.nat.*;
- import org.apache.cloudstack.api.command.user.network.*;
- import org.apache.cloudstack.api.command.user.offering.*;
- import org.apache.cloudstack.api.command.user.project.*;
- import org.apache.cloudstack.api.command.user.region.*;
- import org.apache.cloudstack.api.command.user.resource.*;
- import org.apache.cloudstack.api.command.user.securitygroup.*;
- import org.apache.cloudstack.api.command.user.snapshot.*;
- import org.apache.cloudstack.api.command.user.ssh.*;
- import org.apache.cloudstack.api.command.user.tag.*;
- import org.apache.cloudstack.api.command.user.template.*;
- import org.apache.cloudstack.api.command.user.vm.*;
- import org.apache.cloudstack.api.command.user.vmgroup.*;
- import org.apache.cloudstack.api.command.user.volume.*;
- import org.apache.cloudstack.api.command.user.vpc.*;
- import org.apache.cloudstack.api.command.user.vpn.*;
- import org.apache.cloudstack.api.command.user.zone.*;
+ import org.apache.cloudstack.api.command.admin.account.CreateAccountCmd;
+ import org.apache.cloudstack.api.command.admin.account.DeleteAccountCmd;
+ import org.apache.cloudstack.api.command.admin.account.DisableAccountCmd;
+ import org.apache.cloudstack.api.command.admin.account.EnableAccountCmd;
+ import org.apache.cloudstack.api.command.admin.account.LockAccountCmd;
+ import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
+ 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.domain.CreateDomainCmd;
+ import org.apache.cloudstack.api.command.admin.domain.DeleteDomainCmd;
+ import org.apache.cloudstack.api.command.admin.domain.ListDomainChildrenCmd;
+ import org.apache.cloudstack.api.command.admin.domain.ListDomainsCmd;
+ import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
+ import org.apache.cloudstack.api.command.admin.host.AddHostCmd;
+ import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd;
+ import org.apache.cloudstack.api.command.admin.host.CancelMaintenanceCmd;
+ import org.apache.cloudstack.api.command.admin.host.DeleteHostCmd;
+ import org.apache.cloudstack.api.command.admin.host.FindHostsForMigrationCmd;
+ import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
+ import org.apache.cloudstack.api.command.admin.host.PrepareForMaintenanceCmd;
+ import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd;
+ import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd;
+ import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
+ import org.apache.cloudstack.api.command.admin.internallb.ConfigureInternalLoadBalancerElementCmd;
+ import org.apache.cloudstack.api.command.admin.internallb.CreateInternalLoadBalancerElementCmd;
+ import org.apache.cloudstack.api.command.admin.internallb.ListInternalLBVMsCmd;
+ import org.apache.cloudstack.api.command.admin.internallb.ListInternalLoadBalancerElementsCmd;
+ import org.apache.cloudstack.api.command.admin.internallb.StartInternalLBVMCmd;
+ import org.apache.cloudstack.api.command.admin.internallb.StopInternalLBVMCmd;
+ 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.network.AddNetworkDeviceCmd;
+ import org.apache.cloudstack.api.command.admin.network.AddNetworkServiceProviderCmd;
+ import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd;
+ import org.apache.cloudstack.api.command.admin.network.CreatePhysicalNetworkCmd;
+ import org.apache.cloudstack.api.command.admin.network.CreateStorageNetworkIpRangeCmd;
+ import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
+ import org.apache.cloudstack.api.command.admin.network.DeleteNetworkDeviceCmd;
+ import org.apache.cloudstack.api.command.admin.network.DeleteNetworkOfferingCmd;
+ import org.apache.cloudstack.api.command.admin.network.DeleteNetworkServiceProviderCmd;
+ import org.apache.cloudstack.api.command.admin.network.DeletePhysicalNetworkCmd;
+ import org.apache.cloudstack.api.command.admin.network.DeleteStorageNetworkIpRangeCmd;
+ import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd;
+ import org.apache.cloudstack.api.command.admin.network.ListNetworkDeviceCmd;
+ import org.apache.cloudstack.api.command.admin.network.ListNetworkIsolationMethodsCmd;
+ import org.apache.cloudstack.api.command.admin.network.ListNetworkServiceProvidersCmd;
+ import org.apache.cloudstack.api.command.admin.network.ListPhysicalNetworksCmd;
+ import org.apache.cloudstack.api.command.admin.network.ListStorageNetworkIpRangeCmd;
+ import org.apache.cloudstack.api.command.admin.network.ListSupportedNetworkServicesCmd;
+ import org.apache.cloudstack.api.command.admin.network.ReleaseDedicatedGuestVlanRangeCmd;
+ import org.apache.cloudstack.api.command.admin.network.UpdateNetworkOfferingCmd;
+ import org.apache.cloudstack.api.command.admin.network.UpdateNetworkServiceProviderCmd;
+ import org.apache.cloudstack.api.command.admin.network.UpdatePhysicalNetworkCmd;
+ import org.apache.cloudstack.api.command.admin.network.UpdateStorageNetworkIpRangeCmd;
+ import org.apache.cloudstack.api.command.admin.offering.CreateDiskOfferingCmd;
+ import org.apache.cloudstack.api.command.admin.offering.CreateServiceOfferingCmd;
+ import org.apache.cloudstack.api.command.admin.offering.DeleteDiskOfferingCmd;
+ import org.apache.cloudstack.api.command.admin.offering.DeleteServiceOfferingCmd;
+ import org.apache.cloudstack.api.command.admin.offering.UpdateDiskOfferingCmd;
+ import org.apache.cloudstack.api.command.admin.offering.UpdateServiceOfferingCmd;
+ 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.region.AddRegionCmd;
+ 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;
+ import org.apache.cloudstack.api.command.admin.resource.ListCapacityCmd;
+ import org.apache.cloudstack.api.command.admin.resource.UploadCustomCertificateCmd;
+ import org.apache.cloudstack.api.command.admin.router.ConfigureVirtualRouterElementCmd;
+ import org.apache.cloudstack.api.command.admin.router.CreateVirtualRouterElementCmd;
+ import org.apache.cloudstack.api.command.admin.router.DestroyRouterCmd;
+ import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
+ import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
+ import org.apache.cloudstack.api.command.admin.router.RebootRouterCmd;
+ import org.apache.cloudstack.api.command.admin.router.StartRouterCmd;
+ import org.apache.cloudstack.api.command.admin.router.StopRouterCmd;
+ import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
+ import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd;
+ import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
+ import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
+ import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
+ import org.apache.cloudstack.api.command.admin.storage.FindStoragePoolsForMigrationCmd;
+ import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd;
+ import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
+ import org.apache.cloudstack.api.command.admin.storage.ListStorageProvidersCmd;
+ import org.apache.cloudstack.api.command.admin.storage.PreparePrimaryStorageForMaintenanceCmd;
+ import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
+ 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.systemvm.DestroySystemVmCmd;
+ import org.apache.cloudstack.api.command.admin.systemvm.ListSystemVMsCmd;
+ import org.apache.cloudstack.api.command.admin.systemvm.MigrateSystemVMCmd;
+ import org.apache.cloudstack.api.command.admin.systemvm.RebootSystemVmCmd;
+ import org.apache.cloudstack.api.command.admin.systemvm.StartSystemVMCmd;
+ import org.apache.cloudstack.api.command.admin.systemvm.StopSystemVmCmd;
+ import org.apache.cloudstack.api.command.admin.systemvm.UpgradeSystemVMCmd;
+ import org.apache.cloudstack.api.command.admin.template.PrepareTemplateCmd;
+ import org.apache.cloudstack.api.command.admin.usage.AddTrafficMonitorCmd;
+ import org.apache.cloudstack.api.command.admin.usage.AddTrafficTypeCmd;
+ import org.apache.cloudstack.api.command.admin.usage.DeleteTrafficMonitorCmd;
+ import org.apache.cloudstack.api.command.admin.usage.DeleteTrafficTypeCmd;
+ import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd;
+ import org.apache.cloudstack.api.command.admin.usage.GetUsageRecordsCmd;
+ import org.apache.cloudstack.api.command.admin.usage.ListTrafficMonitorsCmd;
+ import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
+ import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypesCmd;
+ import org.apache.cloudstack.api.command.admin.usage.ListUsageTypesCmd;
+ import org.apache.cloudstack.api.command.admin.usage.UpdateTrafficTypeCmd;
+ import org.apache.cloudstack.api.command.admin.user.CreateUserCmd;
+ import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
+ import org.apache.cloudstack.api.command.admin.user.DisableUserCmd;
+ import org.apache.cloudstack.api.command.admin.user.EnableUserCmd;
+ import org.apache.cloudstack.api.command.admin.user.GetUserCmd;
+ import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
+ import org.apache.cloudstack.api.command.admin.user.LockUserCmd;
+ import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
+ import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
+ import org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd;
+ import org.apache.cloudstack.api.command.admin.vlan.DedicatePublicIpRangeCmd;
+ 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.vlan.ReleasePublicIpRangeCmd;
+ 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.vpc.CreatePrivateGatewayCmd;
+ import org.apache.cloudstack.api.command.admin.vpc.CreateVPCOfferingCmd;
+ import org.apache.cloudstack.api.command.admin.vpc.DeletePrivateGatewayCmd;
+ import org.apache.cloudstack.api.command.admin.vpc.DeleteVPCOfferingCmd;
+ import org.apache.cloudstack.api.command.admin.vpc.UpdateVPCOfferingCmd;
+ 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.affinitygroup.CreateAffinityGroupCmd;
+ import org.apache.cloudstack.api.command.user.affinitygroup.DeleteAffinityGroupCmd;
+ import org.apache.cloudstack.api.command.user.affinitygroup.ListAffinityGroupTypesCmd;
+ import org.apache.cloudstack.api.command.user.affinitygroup.ListAffinityGroupsCmd;
+ import org.apache.cloudstack.api.command.user.affinitygroup.UpdateVMAffinityGroupCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.CreateAutoScalePolicyCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.CreateAutoScaleVmGroupCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.CreateAutoScaleVmProfileCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.CreateConditionCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.DeleteAutoScalePolicyCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.DeleteAutoScaleVmGroupCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.DeleteAutoScaleVmProfileCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.DeleteConditionCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.DisableAutoScaleVmGroupCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.EnableAutoScaleVmGroupCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.ListAutoScalePoliciesCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.ListAutoScaleVmGroupsCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.ListAutoScaleVmProfilesCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.ListConditionsCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.ListCountersCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScalePolicyCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScaleVmGroupCmd;
+ import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScaleVmProfileCmd;
+ 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.firewall.CreateEgressFirewallRuleCmd;
+ import org.apache.cloudstack.api.command.user.firewall.CreateFirewallRuleCmd;
+ import org.apache.cloudstack.api.command.user.firewall.CreatePortForwardingRuleCmd;
+ import org.apache.cloudstack.api.command.user.firewall.DeleteEgressFirewallRuleCmd;
+ import org.apache.cloudstack.api.command.user.firewall.DeleteFirewallRuleCmd;
+ import org.apache.cloudstack.api.command.user.firewall.DeletePortForwardingRuleCmd;
+ import org.apache.cloudstack.api.command.user.firewall.ListEgressFirewallRulesCmd;
+ import org.apache.cloudstack.api.command.user.firewall.ListFirewallRulesCmd;
+ import org.apache.cloudstack.api.command.user.firewall.ListPortForwardingRulesCmd;
+ import org.apache.cloudstack.api.command.user.firewall.UpdatePortForwardingRuleCmd;
+ 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.iso.AttachIsoCmd;
+ import org.apache.cloudstack.api.command.user.iso.CopyIsoCmd;
+ import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
+ import org.apache.cloudstack.api.command.user.iso.DetachIsoCmd;
+ import org.apache.cloudstack.api.command.user.iso.ExtractIsoCmd;
+ import org.apache.cloudstack.api.command.user.iso.ListIsoPermissionsCmd;
+ import org.apache.cloudstack.api.command.user.iso.ListIsosCmd;
+ import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
+ import org.apache.cloudstack.api.command.user.iso.UpdateIsoCmd;
+ import org.apache.cloudstack.api.command.user.iso.UpdateIsoPermissionsCmd;
+ 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.loadbalancer.AssignToLoadBalancerRuleCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.CreateApplicationLoadBalancerCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.CreateLBHealthCheckPolicyCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.CreateLBStickinessPolicyCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.DeleteApplicationLoadBalancerCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.DeleteLBHealthCheckPolicyCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.DeleteLBStickinessPolicyCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.DeleteLoadBalancerRuleCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.ListApplicationLoadBalancersCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.ListLBHealthCheckPoliciesCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.ListLBStickinessPoliciesCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRuleInstancesCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRulesCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.RemoveFromLoadBalancerRuleCmd;
+ import org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRuleCmd;
+ import org.apache.cloudstack.api.command.user.nat.CreateIpForwardingRuleCmd;
+ import org.apache.cloudstack.api.command.user.nat.DeleteIpForwardingRuleCmd;
+ import org.apache.cloudstack.api.command.user.nat.DisableStaticNatCmd;
+ import org.apache.cloudstack.api.command.user.nat.EnableStaticNatCmd;
+ import org.apache.cloudstack.api.command.user.nat.ListIpForwardingRulesCmd;
+ import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
+ import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
+ import org.apache.cloudstack.api.command.user.network.DeleteNetworkACLCmd;
+ import org.apache.cloudstack.api.command.user.network.DeleteNetworkCmd;
+ import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd;
+ import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd;
+ import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
+ import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd;
+ import org.apache.cloudstack.api.command.user.network.UpdateNetworkCmd;
+ 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.project.ActivateProjectCmd;
+ import org.apache.cloudstack.api.command.user.project.CreateProjectCmd;
+ import org.apache.cloudstack.api.command.user.project.DeleteProjectCmd;
+ import org.apache.cloudstack.api.command.user.project.DeleteProjectInvitationCmd;
+ import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd;
+ import org.apache.cloudstack.api.command.user.project.ListProjectsCmd;
+ import org.apache.cloudstack.api.command.user.project.SuspendProjectCmd;
+ import org.apache.cloudstack.api.command.user.project.UpdateProjectCmd;
+ import org.apache.cloudstack.api.command.user.project.UpdateProjectInvitationCmd;
+ import org.apache.cloudstack.api.command.user.region.ListRegionsCmd;
+ import org.apache.cloudstack.api.command.user.region.ha.gslb.AssignToGlobalLoadBalancerRuleCmd;
+ import org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd;
+ import org.apache.cloudstack.api.command.user.region.ha.gslb.DeleteGlobalLoadBalancerRuleCmd;
+ import org.apache.cloudstack.api.command.user.region.ha.gslb.ListGlobalLoadBalancerRuleCmd;
+ import org.apache.cloudstack.api.command.user.region.ha.gslb.RemoveFromGlobalLoadBalancerRuleCmd;
+ import org.apache.cloudstack.api.command.user.resource.GetCloudIdentifierCmd;
+ import org.apache.cloudstack.api.command.user.resource.ListHypervisorsCmd;
+ import org.apache.cloudstack.api.command.user.resource.ListResourceLimitsCmd;
+ import org.apache.cloudstack.api.command.user.resource.UpdateResourceCountCmd;
+ import org.apache.cloudstack.api.command.user.resource.UpdateResourceLimitCmd;
+ import org.apache.cloudstack.api.command.user.securitygroup.AuthorizeSecurityGroupEgressCmd;
+ import org.apache.cloudstack.api.command.user.securitygroup.AuthorizeSecurityGroupIngressCmd;
+ import org.apache.cloudstack.api.command.user.securitygroup.CreateSecurityGroupCmd;
+ import org.apache.cloudstack.api.command.user.securitygroup.DeleteSecurityGroupCmd;
+ import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd;
+ import org.apache.cloudstack.api.command.user.securitygroup.RevokeSecurityGroupEgressCmd;
+ import org.apache.cloudstack.api.command.user.securitygroup.RevokeSecurityGroupIngressCmd;
+ import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotCmd;
+ import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotPolicyCmd;
+ import org.apache.cloudstack.api.command.user.snapshot.DeleteSnapshotCmd;
+ import org.apache.cloudstack.api.command.user.snapshot.DeleteSnapshotPoliciesCmd;
+ import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd;
+ import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd;
+ 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.template.CopyTemplateCmd;
+ import org.apache.cloudstack.api.command.user.template.CreateTemplateCmd;
+ import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd;
+ import org.apache.cloudstack.api.command.user.template.ExtractTemplateCmd;
+ import org.apache.cloudstack.api.command.user.template.ListTemplatePermissionsCmd;
+ import org.apache.cloudstack.api.command.user.template.ListTemplatesCmd;
+ import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
+ import org.apache.cloudstack.api.command.user.template.UpdateTemplateCmd;
+ import org.apache.cloudstack.api.command.user.template.UpdateTemplatePermissionsCmd;
+ import org.apache.cloudstack.api.command.user.vm.AddIpToVmNicCmd;
+ import org.apache.cloudstack.api.command.user.vm.AddNicToVMCmd;
+ import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
+ import org.apache.cloudstack.api.command.user.vm.DestroyVMCmd;
+ import org.apache.cloudstack.api.command.user.vm.GetVMPasswordCmd;
+ import org.apache.cloudstack.api.command.user.vm.ListNicsCmd;
+ import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
+ import org.apache.cloudstack.api.command.user.vm.RebootVMCmd;
+ import org.apache.cloudstack.api.command.user.vm.RemoveIpFromVmNicCmd;
+ import org.apache.cloudstack.api.command.user.vm.RemoveNicFromVMCmd;
+ import org.apache.cloudstack.api.command.user.vm.ResetVMPasswordCmd;
+ import org.apache.cloudstack.api.command.user.vm.ResetVMSSHKeyCmd;
+ import org.apache.cloudstack.api.command.user.vm.RestoreVMCmd;
+ import org.apache.cloudstack.api.command.user.vm.ScaleVMCmd;
+ import org.apache.cloudstack.api.command.user.vm.StartVMCmd;
+ import org.apache.cloudstack.api.command.user.vm.StopVMCmd;
+ import org.apache.cloudstack.api.command.user.vm.UpdateDefaultNicForVMCmd;
+ import org.apache.cloudstack.api.command.user.vm.UpdateVMCmd;
+ 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.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.vmsnapshot.RevertToVMSnapshotCmd;
+ import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
+ import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
+ import org.apache.cloudstack.api.command.user.volume.DeleteVolumeCmd;
+ import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
+ import org.apache.cloudstack.api.command.user.volume.ExtractVolumeCmd;
+ import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
+ import org.apache.cloudstack.api.command.user.volume.MigrateVolumeCmd;
+ import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
+ import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd;
+ import org.apache.cloudstack.api.command.user.vpc.CreateStaticRouteCmd;
+ import org.apache.cloudstack.api.command.user.vpc.CreateVPCCmd;
+ import org.apache.cloudstack.api.command.user.vpc.DeleteStaticRouteCmd;
+ import org.apache.cloudstack.api.command.user.vpc.DeleteVPCCmd;
+ import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd;
+ import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd;
+ import org.apache.cloudstack.api.command.user.vpc.ListVPCOfferingsCmd;
+ import org.apache.cloudstack.api.command.user.vpc.ListVPCsCmd;
+ import org.apache.cloudstack.api.command.user.vpc.RestartVPCCmd;
+ import org.apache.cloudstack.api.command.user.vpc.UpdateVPCCmd;
+ import org.apache.cloudstack.api.command.user.vpn.AddVpnUserCmd;
+ import org.apache.cloudstack.api.command.user.vpn.CreateRemoteAccessVpnCmd;
+ import org.apache.cloudstack.api.command.user.vpn.CreateVpnConnectionCmd;
+ import org.apache.cloudstack.api.command.user.vpn.CreateVpnCustomerGatewayCmd;
+ import org.apache.cloudstack.api.command.user.vpn.CreateVpnGatewayCmd;
+ import org.apache.cloudstack.api.command.user.vpn.DeleteRemoteAccessVpnCmd;
+ import org.apache.cloudstack.api.command.user.vpn.DeleteVpnConnectionCmd;
+ import org.apache.cloudstack.api.command.user.vpn.DeleteVpnCustomerGatewayCmd;
+ import org.apache.cloudstack.api.command.user.vpn.DeleteVpnGatewayCmd;
+ import org.apache.cloudstack.api.command.user.vpn.ListRemoteAccessVpnsCmd;
+ import org.apache.cloudstack.api.command.user.vpn.ListVpnConnectionsCmd;
+ import org.apache.cloudstack.api.command.user.vpn.ListVpnCustomerGatewaysCmd;
+ import org.apache.cloudstack.api.command.user.vpn.ListVpnGatewaysCmd;
+ import org.apache.cloudstack.api.command.user.vpn.ListVpnUsersCmd;
+ import org.apache.cloudstack.api.command.user.vpn.RemoveVpnUserCmd;
+ import org.apache.cloudstack.api.command.user.vpn.ResetVpnConnectionCmd;
+ 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.commons.codec.binary.Base64;
- import org.apache.log4j.Logger;
- import org.springframework.stereotype.Component;
+ 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.commons.codec.binary.Base64;
 -import org.apache.log4j.Logger;
  
  import com.cloud.agent.AgentManager;
  import com.cloud.agent.api.GetVncPortAnswer;
@@@ -119,7 -421,11 +422,10 @@@ import com.cloud.alert.AlertManager
  import com.cloud.alert.AlertVO;
  import com.cloud.alert.dao.AlertDao;
  import com.cloud.api.ApiDBUtils;
- import com.cloud.async.*;
 -import com.cloud.async.AsyncJobExecutor;
++import com.cloud.async.AsyncJob;
++import com.cloud.async.AsyncJobConstants;
++import com.cloud.async.AsyncJobExecutionContext;
+ import com.cloud.async.AsyncJobManager;
 -import com.cloud.async.AsyncJobResult;
 -import com.cloud.async.AsyncJobVO;
 -import com.cloud.async.BaseAsyncJobExecutor;
  import com.cloud.capacity.Capacity;
  import com.cloud.capacity.CapacityVO;
  import com.cloud.capacity.dao.CapacityDao;
@@@ -423,10 -678,10 +678,10 @@@ public class ManagementServerImpl exten
      private LoadBalancerDao _loadbalancerDao;
      @Inject
      private HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
- 
      private List<HostAllocator> _hostAllocators;
- 
+     @Inject
+     private List<StoragePoolAllocator> _storagePoolAllocators;
 -    @Inject
 +	@Inject
      private ConfigurationManager _configMgr;
      @Inject
      private ResourceTagDao _resourceTagDao;
@@@ -462,6 -720,19 +720,19 @@@
  
      @Inject ClusterManager _clusterMgr;
      private String _hashKey = null;
+     private String _encryptionKey = null;
+     private String _encryptionIV = null;
+     
+     @Inject
+     protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
+ 
+     protected List<AffinityGroupProcessor> _affinityProcessors;
+     public List<AffinityGroupProcessor> getAffinityGroupProcessors() {
+         return _affinityProcessors;
+     }
+     public void setAffinityGroupProcessors(List<AffinityGroupProcessor> affinityProcessors) {
 -        this._affinityProcessors = affinityProcessors;
++        _affinityProcessors = affinityProcessors;
+     }
  
      public ManagementServerImpl() {
      	setRunLevel(ComponentLifecycle.RUN_LEVEL_APPLICATION_MAINLOOP);
@@@ -667,22 -938,39 +938,39 @@@
  
      @Override
      public Pair<List<? extends Cluster>, Integer> searchForClusters(ListClustersCmd cmd) {
-         Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
-         SearchCriteria<ClusterVO> sc = _clusterDao.createSearchCriteria();
- 
 -    	Object id = cmd.getId();
 +        Object id = cmd.getId();
          Object name = cmd.getClusterName();
          Object podId = cmd.getPodId();
          Long zoneId = cmd.getZoneId();
          Object hypervisorType = cmd.getHypervisorType();
          Object clusterType = cmd.getClusterType();
          Object allocationState = cmd.getAllocationState();
+         String zoneType = cmd.getZoneType();
          String keyword = cmd.getKeyword();
- 
          zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
 -    	
 +
+         
+     	Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
+         
 -        SearchBuilder<ClusterVO> sb = _clusterDao.createSearchBuilder();        
 -        sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);        
 -        sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);  
 -        sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);          
 -        sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);         
++        SearchBuilder<ClusterVO> sb = _clusterDao.createSearchBuilder();
++        sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
++        sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
++        sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
++        sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+         sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
+         sb.and("clusterType", sb.entity().getClusterType(), SearchCriteria.Op.EQ);
+         sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ);
+         
+         if(zoneType != null) {
+             SearchBuilder<DataCenterVO> zoneSb = _dcDao.createSearchBuilder();
 -            zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ);    
++            zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ);
+             sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER);
+         }
+         
+         
 -        SearchCriteria<ClusterVO> sc = sb.create();        
++        SearchCriteria<ClusterVO> sc = sb.create();
          if (id != null) {
-             sc.addAnd("id", SearchCriteria.Op.EQ, id);
 -            sc.setParameters("id", id);            
++            sc.setParameters("id", id);
          }
  
          if (name != null) {
@@@ -706,9 -994,13 +994,13 @@@
          }
  
          if (allocationState != null) {
-             sc.addAnd("allocationState", SearchCriteria.Op.EQ, allocationState);
+             sc.setParameters("allocationState", allocationState);
+         }
+ 
+         if(zoneType != null) {
 -            sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);          
++            sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
          }
 -                
 +
          if (keyword != null) {
              SearchCriteria<ClusterVO> ssc = _clusterDao.createSearchCriteria();
              ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
@@@ -792,32 -1081,73 +1081,73 @@@
              ex.addProxyObject(vm, vmId, "vmId");
              throw ex;
          }
-         Long cluster = srcHost.getClusterId();
-         Type hostType = srcHost.getType();
-         if (s_logger.isDebugEnabled()) {
-             s_logger.debug("Searching for all hosts in cluster: " + cluster + " for migrating VM " + vm);
+ 
+         // Check if the vm can be migrated with storage.
+         boolean canMigrateWithStorage = false;
+         HypervisorCapabilitiesVO capabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(
+                 srcHost.getHypervisorType(), srcHost.getHypervisorVersion());
+         if (capabilities != null) {
+             canMigrateWithStorage = capabilities.isStorageMotionSupported();
          }
  
-         Pair<List<HostVO>, Integer> allHostsInClusterPair = searchForServers(startIndex, pageSize, null, hostType, null, null, null, cluster, null, null, null, null);
+         // Check if the vm is using any disks on local storage.
+         VirtualMachineProfile<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
+         List<VolumeVO> volumes = _volumeDao.findCreatedByInstance(vmProfile.getId());
+         boolean usesLocal = false;
+         for (VolumeVO volume : volumes) {
+             DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
+             DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
+             if (diskProfile.useLocalStorage()) {
+                 usesLocal = true;
+                 break;
+             }
+         }
  
-         // filter out the current host
-         List<HostVO> allHostsInCluster = allHostsInClusterPair.first();
-         allHostsInCluster.remove(srcHost);
-         Pair<List<? extends Host>, Integer> otherHostsInCluster = new Pair<List <? extends Host>, Integer>(allHostsInCluster, new Integer(allHostsInClusterPair.second().intValue()-1));
+         if (!canMigrateWithStorage && usesLocal) {
+             throw new InvalidParameterValueException("Unsupported operation, VM uses Local storage, cannot migrate");
+         }
  
-         if (s_logger.isDebugEnabled()) {
-             s_logger.debug("Other Hosts in this cluster: " + allHostsInCluster);
+         Type hostType = srcHost.getType();
+         Pair<List<HostVO>, Integer> allHostsPair = null;
+         List<HostVO> allHosts = null;
+         Map<Host, Boolean> requiresStorageMotion = new HashMap<Host, Boolean>();
+         DataCenterDeployment plan = null;
+         if (canMigrateWithStorage) {
+             allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, srcHost.getDataCenterId(), null,
+                     null, null, null, null, null, srcHost.getHypervisorType(), srcHost.getHypervisorVersion());
+             allHosts = allHostsPair.first();
+             allHosts.remove(srcHost);
+ 
+             // Check if the host has storage pools for all the volumes of the vm to be migrated.
+             for (Host host : allHosts) {
+                 Map<Volume, List<StoragePool>> volumePools = findSuitablePoolsForVolumes(vmProfile, host);
+                 if (volumePools.isEmpty()) {
+                     allHosts.remove(host);
+                 } else {
+                     if (host.getClusterId() != srcHost.getClusterId() || usesLocal) {
+                         requiresStorageMotion.put(host, true);
+                     }
+                 }
 -            }
 +        }
  
+             plan = new DataCenterDeployment(srcHost.getDataCenterId(), null, null, null, null, null);
+         } else {
+             Long cluster = srcHost.getClusterId();
 -            if (s_logger.isDebugEnabled()) {
 +        if (s_logger.isDebugEnabled()) {
-             s_logger.debug("Calling HostAllocators to search for hosts in cluster: " + cluster + " having enough capacity and suitable for migration");
+                 s_logger.debug("Searching for all hosts in cluster " + cluster + " for migrating VM " + vm);
+             }
+             allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, null, null, cluster, null, null,
+                     null, null, null, null);
+             // Filter out the current host.
+             allHosts = allHostsPair.first();
+             allHosts.remove(srcHost);
+             plan = new DataCenterDeployment(srcHost.getDataCenterId(), srcHost.getPodId(), srcHost.getClusterId(),
+                     null, null, null);
          }
  
+         Pair<List<? extends Host>, Integer> otherHosts = new Pair<List <? extends Host>, Integer>(allHosts,
+                 new Integer(allHosts.size()));
          List<Host> suitableHosts = new ArrayList<Host>();
- 
-         VirtualMachineProfile<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
- 
-         DataCenterDeployment plan = new DataCenterDeployment(srcHost.getDataCenterId(), srcHost.getPodId(), srcHost.getClusterId(), null, null, null);
          ExcludeList excludes = new ExcludeList();
          excludes.addHost(srcHostId);
  
@@@ -828,15 -1174,157 +1174,157 @@@
              }
          }
  
+         if (s_logger.isDebugEnabled()) {
 -            if (suitableHosts.isEmpty()) {
 -                s_logger.debug("No suitable hosts found");
 -            } else {
 +        if (suitableHosts.isEmpty()) {
 +            s_logger.debug("No suitable hosts found");
 +        } else {
-             if (s_logger.isDebugEnabled()) {
                  s_logger.debug("Hosts having capacity and suitable for migration: " + suitableHosts);
              }
          }
  
-         return new Pair<Pair<List<? extends Host>, Integer>, List<? extends Host>>(otherHostsInCluster, suitableHosts);
+         return new Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>> (otherHosts,
+                 suitableHosts, requiresStorageMotion);
+     }
+ 
+     private Map<Volume, List<StoragePool>> findSuitablePoolsForVolumes(VirtualMachineProfile<VMInstanceVO> vmProfile,
+             Host host) {
+         List<VolumeVO> volumes = _volumeDao.findCreatedByInstance(vmProfile.getId());
+         Map<Volume, List<StoragePool>> suitableVolumeStoragePools = new HashMap<Volume, List<StoragePool>>();
+ 
+         // For each volume find list of suitable storage pools by calling the allocators
+         for (VolumeVO volume : volumes) {
+             DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
+             DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
+             DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(),
+                     host.getClusterId(), host.getId(), null, null);
+             ExcludeList avoid = new ExcludeList();
+ 
+             boolean foundPools = false;
+             for (StoragePoolAllocator allocator : _storagePoolAllocators) {
+                 List<StoragePool> poolList = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid,
+                         StoragePoolAllocator.RETURN_UPTO_ALL);
+                 if (poolList != null && !poolList.isEmpty()) {
+                     suitableVolumeStoragePools.put(volume, poolList);
+                     foundPools = true;
+                     break;
+                 }
+             }
+ 
+             if (!foundPools) {
+                 suitableVolumeStoragePools.clear();
+                 break;
+             }
+         }
+ 
+         return suitableVolumeStoragePools;
+     }
+ 
+     @Override
+     public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(Long volumeId) {
+         // Access check - only root administrator can migrate volumes.
+         Account caller = UserContext.current().getCaller();
+         if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
+             if (s_logger.isDebugEnabled()) {
+                 s_logger.debug("Caller is not a root admin, permission denied to migrate the volume");
+             }
+             throw new PermissionDeniedException("No permission to migrate volume, only root admin can migrate a volume");
+         }
+ 
+         VolumeVO volume = _volumeDao.findById(volumeId);
+         if (volume == null) {
+             InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find volume with" +
+                     " specified id.");
+             ex.addProxyObject(volume, volumeId, "volumeId");
+             throw ex;
+         }
+ 
+         // Volume must be attached to an instance for live migration.
+         List<StoragePool> allPools = new ArrayList<StoragePool>();
+         List<StoragePool> suitablePools = new ArrayList<StoragePool>();
+         Long instanceId = volume.getInstanceId();
+         VMInstanceVO vm = null;
+         if (instanceId != null) {
+             vm = _vmInstanceDao.findById(instanceId);
+         }
+ 
+         // Check that the VM is in correct state.
+         if (vm == null || vm.getState() != State.Running) {
+             s_logger.info("Volume " + volume + " isn't attached to any running vm. Only volumes attached to a running" +
+                     " VM can be migrated.");
+             return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
+         }
+ 
+         // Volume must be in Ready state to be migrated.
+         if (!Volume.State.Ready.equals(volume.getState())) {
+             s_logger.info("Volume " + volume + " must be in ready state for migration.");
+             return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
+         }
+ 
+         if (!_volumeMgr.volumeOnSharedStoragePool(volume)) {
+             s_logger.info("Volume " + volume + " is on local storage. It cannot be migrated to another pool.");
+             return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
+         }
+ 
+         // Check if the underlying hypervisor supports storage motion.
+         boolean storageMotionSupported = false;
+         Long hostId = vm.getHostId();
+         if (hostId != null) {
+             HostVO host = _hostDao.findById(hostId);
+             HypervisorCapabilitiesVO capabilities = null;
+             if (host != null) {
+                 capabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(host.getHypervisorType(),
+                         host.getHypervisorVersion());
+             } else {
+                 s_logger.error("Details of the host on which the vm " + vm + ", to which volume "+ volume + " is "
+                         + "attached, couldn't be retrieved.");
+             }
+ 
+             if (capabilities != null) {
+                 storageMotionSupported = capabilities.isStorageMotionSupported();
+             } else {
+                 s_logger.error("Capabilities for host " + host + " couldn't be retrieved.");
+             }
+         }
+ 
+         if (storageMotionSupported) {
+             // Source pool of the volume.
+             StoragePoolVO srcVolumePool = _poolDao.findById(volume.getPoolId());
+ 
+             // Get all the pools available. Only shared pools are considered because only a volume on a shared pools
+             // can be live migrated while the virtual machine stays on the same host.
+             List<StoragePoolVO> storagePools = _poolDao.findPoolsByTags(volume.getDataCenterId(),
+                     volume.getPodId(), srcVolumePool.getClusterId(), null);
+             storagePools.remove(srcVolumePool);
+             for (StoragePoolVO pool : storagePools) {
+                 if (pool.isShared()) {
 -                    allPools.add((StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId()));
++                    allPools.add((StoragePool)dataStoreMgr.getPrimaryDataStore(pool.getId()));
+                 }
+             }
+ 
+             // Get all the suitable pools.
+             // Exclude the current pool from the list of pools to which the volume can be migrated.
+             ExcludeList avoid = new ExcludeList();
+             avoid.addPool(srcVolumePool.getId());
+ 
+             // Volume stays in the same cluster after migration.
+             DataCenterDeployment plan = new DataCenterDeployment(volume.getDataCenterId(), volume.getPodId(),
+                     srcVolumePool.getClusterId(), null, null, null);
+             VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
+ 
+             DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
+             DiskProfile diskProfile = new DiskProfile(volume, diskOffering, profile.getHypervisorType());
+ 
+             // Call the storage pool allocator to find the list of storage pools.
+             for (StoragePoolAllocator allocator : _storagePoolAllocators) {
+                 List<StoragePool> pools = allocator.allocateToPool(diskProfile, profile, plan, avoid,
+                         StoragePoolAllocator.RETURN_UPTO_ALL);
+                 if (pools != null && !pools.isEmpty()) {
+                     suitablePools.addAll(pools);
+                     break;
+                 }
+             }
+         }
+         return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
      }
  
      private Pair<List<HostVO>, Integer> searchForServers(Long startIndex, Long pageSize, Object name, Object type, Object state, Object zone, Object pod, Object cluster, Object id, Object keyword,
@@@ -915,17 -1411,29 +1411,29 @@@
  
      @Override
      public Pair<List<? extends Pod>, Integer> searchForPods(ListPodsByCmd cmd) {
-         Filter searchFilter = new Filter(HostPodVO.class, "dataCenterId", true, cmd.getStartIndex(), cmd.getPageSizeVal());
-         SearchCriteria<HostPodVO> sc = _hostPodDao.createSearchCriteria();
- 
          String podName = cmd.getPodName();
          Long id = cmd.getId();
 -        Long zoneId = cmd.getZoneId();        
 +        Long zoneId = cmd.getZoneId();
          Object keyword = cmd.getKeyword();
          Object allocationState = cmd.getAllocationState();
- 
+         String zoneType = cmd.getZoneType();
          zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
  
+     	
+     	Filter searchFilter = new Filter(HostPodVO.class, "dataCenterId", true, cmd.getStartIndex(), cmd.getPageSizeVal());
 -        SearchBuilder<HostPodVO> sb = _hostPodDao.createSearchBuilder();        
++        SearchBuilder<HostPodVO> sb = _hostPodDao.createSearchBuilder();
+         sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
 -        sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);          
 -        sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);         
++        sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
++        sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+         sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ);
+         
+         if(zoneType != null) {
+             SearchBuilder<DataCenterVO> zoneSb = _dcDao.createSearchBuilder();
 -            zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ);    
++            zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ);
+             sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER);
+         }
+                
+         SearchCriteria<HostPodVO> sc = sb.create();
          if (keyword != null) {
              SearchCriteria<HostPodVO> ssc = _hostPodDao.createSearchCriteria();
              ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
@@@ -935,21 -1443,25 +1443,25 @@@
          }
  
          if (id != null) {
-             sc.addAnd("id", SearchCriteria.Op.EQ, id);
+             sc.setParameters("id", id);
          }
 -        
 +
          if (podName != null) {
-             sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + podName + "%");
+             sc.setParameters("name", "%" + podName + "%");
          }
 -        
 +
          if (zoneId != null) {
-             sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
+             sc.setParameters("dataCenterId", zoneId);
          }
 -        
 +
          if (allocationState != null) {
-             sc.addAnd("allocationState", SearchCriteria.Op.EQ, allocationState);
+             sc.setParameters("allocationState", allocationState);
 -        }        
++        }
+     
+         if(zoneType != null) {
 -            sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);          
++            sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
          }
 -        
 +
          Pair<List<HostPodVO>, Integer> result = _hostPodDao.searchAndCount(sc, searchFilter);
          return new Pair<List<? extends Pod>, Integer>(result.first(), result.second());
      }
@@@ -2486,6 -3065,12 +3065,12 @@@
              sb.join("volumeSearch", volumeSearch, sb.entity().getId(), volumeSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER);
          }
  
+         if(zoneType != null) {
+             SearchBuilder<DataCenterVO> zoneSb = _dcDao.createSearchBuilder();
 -            zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ);    
++            zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ);
+             sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER);
 -        }        
++        }
+         
          SearchCriteria<VMInstanceVO> sc = sb.create();
  
          if (keyword != null) {
@@@ -2526,6 -3111,10 +3111,10 @@@
              sc.setJoinParameters("volumeSearch", "poolId", storageId);
          }
  
+         if(zoneType != null) {
 -            sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);          
++            sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
+         }
+         
          Pair<List<VMInstanceVO>, Integer> result = _vmInstanceDao.searchAndCount(sc, searchFilter);
          return new Pair<List<? extends VirtualMachine>, Integer>(result.first(), result.second());
      }
@@@ -2821,8 -3410,8 +3410,8 @@@
          }
  
          long accountId = volume.getAccountId();
--        StoragePool srcPool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(volume.getPoolId());
--        HostVO sserver = this.templateMgr.getSecondaryStorageHost(zoneId);
++        StoragePool srcPool = (StoragePool)dataStoreMgr.getPrimaryDataStore(volume.getPoolId());
++        HostVO sserver = templateMgr.getSecondaryStorageHost(zoneId);
          String secondaryStorageURL = sserver.getStorageUrl();
  
          List<UploadVO> extractURLList = _uploadDao.listByTypeUploadStatus(volumeId, Upload.Type.VOLUME, UploadVO.Status.DOWNLOAD_URL_CREATED);
@@@ -3034,16 -3636,67 +3636,67 @@@
  
      @Override
      public String getHashKey() {
-         // although we may have race conditioning here, database transaction
-         // serialization should
+         // although we may have race conditioning here, database transaction serialization should
          // give us the same key
          if (_hashKey == null) {
-             _hashKey = _configDao.getValueAndInitIfNotExist(Config.HashKey.key(), Config.HashKey.getCategory(), UUID.randomUUID().toString());
 -            _hashKey = _configDao.getValueAndInitIfNotExist(Config.HashKey.key(), Config.HashKey.getCategory(), 
++            _hashKey = _configDao.getValueAndInitIfNotExist(Config.HashKey.key(), Config.HashKey.getCategory(),
+             	getBase64EncodedRandomKey(128));
          }
          return _hashKey;
      }
  
      @Override
+     public String getEncryptionKey() {
+         if (_encryptionKey == null) {
 -            _encryptionKey = _configDao.getValueAndInitIfNotExist(Config.EncryptionKey.key(), 
 -            	Config.EncryptionKey.getCategory(), 
++            _encryptionKey = _configDao.getValueAndInitIfNotExist(Config.EncryptionKey.key(),
++            	Config.EncryptionKey.getCategory(),
+             	getBase64EncodedRandomKey(128));
+         }
+         return _encryptionKey;
+     }
+     
+     @Override
+     public String getEncryptionIV() {
+         if (_encryptionIV == null) {
 -            _encryptionIV = _configDao.getValueAndInitIfNotExist(Config.EncryptionIV.key(), 
 -            	Config.EncryptionIV.getCategory(), 
++            _encryptionIV = _configDao.getValueAndInitIfNotExist(Config.EncryptionIV.key(),
++            	Config.EncryptionIV.getCategory(),
+             	getBase64EncodedRandomKey(128));
+         }
+         return _encryptionIV;
+     }
+     
+     @Override
+     @DB
+     public void resetEncryptionKeyIV() {
+     	
+     	SearchBuilder<ConfigurationVO> sb = _configDao.createSearchBuilder();
+     	sb.and("name1", sb.entity().getName(), SearchCriteria.Op.EQ);
+     	sb.or("name2", sb.entity().getName(), SearchCriteria.Op.EQ);
+     	sb.done();
+     	
+     	SearchCriteria<ConfigurationVO> sc = sb.create();
+     	sc.setParameters("name1", Config.EncryptionKey.key());
+     	sc.setParameters("name2", Config.EncryptionIV.key());
+     	
+     	_configDao.expunge(sc);
+     	_encryptionKey = null;
+     	_encryptionIV = null;
+     }
+     
+     private static String getBase64EncodedRandomKey(int nBits) {
+ 		SecureRandom random;
+ 		try {
+ 			random = SecureRandom.getInstance("SHA1PRNG");
+ 	        byte[] keyBytes = new byte[nBits/8];
+ 	        random.nextBytes(keyBytes);
+ 	        return Base64.encodeBase64URLSafeString(keyBytes);
+ 		} catch (NoSuchAlgorithmException e) {
+ 			s_logger.error("Unhandled exception: ", e);
+ 		}
+ 		return null;
+     }
+ 
+     @Override
      public SSHKeyPair createSSHKeyPair(CreateSSHKeyPairCmd cmd) {
          Account caller = UserContext.current().getCaller();
          String accountName = cmd.getAccountName();

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

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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d4039743/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/vm/UserVmManagerImpl.java
index 1b00997,f7f5fc7..245e804
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@@ -1052,8 -1082,8 +1082,8 @@@ public class UserVmManagerImpl extends 
          }
  
          // Dynamically upgrade the running vms
-         if(vmInstance.getState().equals(State.Running)){
 -        boolean success = false;
 +            boolean success = false;
+         if(vmInstance.getState().equals(State.Running)){
              int retry = _scaleRetry;
              while (retry-- != 0) { // It's != so that it can match -1.
                  try{
@@@ -2553,15 -2627,29 +2627,29 @@@
                  throw new InvalidParameterValueException(
                          "User data is not base64 encoded");
              }
-             if (userData.length() >= 2 * MAX_USER_DATA_LENGTH_BYTES) {
+             // If GET, use 4K. If POST, support upto 32K.
+             if (httpmethod.equals(HTTPMethod.GET)) {
+                 if (userData.length() >= MAX_HTTP_GET_LENGTH) {
+                     throw new InvalidParameterValueException(
+                             "User data is too long for an http GET request");
+                 }
+                 decodedUserData = Base64.decodeBase64(userData.getBytes());
+                 if (decodedUserData.length > MAX_HTTP_GET_LENGTH) {
+                     throw new InvalidParameterValueException(
+                         "User data is too long for GET request");
+                 }
+             } else if (httpmethod.equals(HTTPMethod.POST)) {
+                 if (userData.length() >= MAX_HTTP_POST_LENGTH) {
 -                    throw new InvalidParameterValueException(
 +                throw new InvalidParameterValueException(
-                         "User data is too long");
+                             "User data is too long for an http POST request");
 -                }
 -                decodedUserData = Base64.decodeBase64(userData.getBytes());
 +            }
 +            decodedUserData = Base64.decodeBase64(userData.getBytes());
-             if (decodedUserData.length > MAX_USER_DATA_LENGTH_BYTES) {
+                 if (decodedUserData.length > MAX_HTTP_POST_LENGTH) {
 -                    throw new InvalidParameterValueException(
 +                throw new InvalidParameterValueException(
-                         "User data is too long");
+                         "User data is too long for POST request");
 -                }
++            }
              }
+ 
              if (decodedUserData.length < 1) {
                  throw new InvalidParameterValueException(
                          "User data is too short");

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


Mime
View raw message