You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/07/04 00:26:27 UTC

[48/50] [abbrv] Another merge to pull in object store fix. Also to check how changes that are applied to both master and vmsync are merged

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/capacity/CapacityManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/capacity/CapacityManagerImpl.java
index 4f185c2,b2f10f2..1ac7708
--- a/server/src/com/cloud/capacity/CapacityManagerImpl.java
+++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java
@@@ -632,7 -630,15 +631,15 @@@ public class CapacityManagerImpl extend
                      host.getTotalMemory(),
                      CapacityVO.CAPACITY_TYPE_MEMORY);
              capacity.setReservedCapacity(reservedMemory);
+             CapacityState capacityState = CapacityState.Enabled;
+             if (host.getClusterId() != null) {
+                 ClusterVO cluster = ApiDBUtils.findClusterById(host.getClusterId());
+                 if (cluster != null) {
+                     capacityState = _configMgr.findClusterAllocationState(cluster) == AllocationState.Disabled ? CapacityState.Disabled
+                             : CapacityState.Enabled;
 -                    capacity.setCapacityState(capacityState);
 +            capacity.setCapacityState(capacityState);
+                 }
+             }
              _capacityDao.persist(capacity);
  
              capacity = new CapacityVO(

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index e1a35ac,8d8b126..1ad9c88
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@@ -3115,22 -3108,22 +3115,22 @@@ public class ConfigurationManagerImpl e
                          throw new InvalidParameterValueException(
                                  "The IPv6 range with tag: "
                                          + vlan.getVlanTag()
 -                                        + " already has IPs that overlap with the new range. Please specify a different start IP/end IP.");
 -                    }
 +        						+ " already has IPs that overlap with the new range. Please specify a different start IP/end IP.");
 +        			}
  
 -                    if (!vlanIp6Gateway.equals(vlan.getIp6Gateway())) {
 +        			if (!vlanIp6Gateway.equals(vlan.getIp6Gateway())) {
                          throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag()
                                  + " has already been added with gateway " + vlan.getIp6Gateway()
 -                                + ". Please specify a different tag.");
 -                    }
 -                }
 -            }
 +        						+ ". Please specify a different tag.");
 +        			}
 +        		}
 +        	}
          }
  
-         // Check if a guest VLAN is using the same tag
+         // Check if the vlan is being used 
          if (_zoneDao.findVnet(zoneId, physicalNetworkId, vlanId).size() > 0) {
              throw new InvalidParameterValueException("The VLAN tag " + vlanId
-                     + " is already being used for the guest network in zone " + zone.getName());
+                     + " is already being used for dynamic vlan allocation for the guest network in zone " + zone.getName());
          }
  
          String ipRange = null;

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

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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/StorageManagerImpl.java
index ac04886,9ddcb78..13eb98a
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@@ -894,16 -892,24 +894,24 @@@ public class StorageManagerImpl extend
          if (capacities.size() == 0) {
              CapacityVO capacity = new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(), storagePool.getPodId(),
                      storagePool.getClusterId(), allocated, totalOverProvCapacity, capacityType);
-             AllocationState allocationState = null;
+ 
              if (storagePool.getScope() == ScopeType.ZONE) {
                  DataCenterVO dc = ApiDBUtils.findZoneById(storagePool.getDataCenterId());
-                 allocationState = dc.getAllocationState();
+                 AllocationState allocationState = dc.getAllocationState();
+                 CapacityState capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled
+                         : CapacityState.Enabled;
+                 capacity.setCapacityState(capacityState);
              } else {
-                 allocationState = _configMgr.findClusterAllocationState(ApiDBUtils.findClusterById(storagePool.getClusterId()));
-             }
-             CapacityState capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
-             
+                 if (storagePool.getClusterId() != null) {
+                     ClusterVO cluster = ApiDBUtils.findClusterById(storagePool.getClusterId());
+                     if (cluster != null) {
+                         AllocationState allocationState = _configMgr.findClusterAllocationState(cluster);
+                         CapacityState capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled
+                                 : CapacityState.Enabled;
 -                        capacity.setCapacityState(capacityState);
 +            capacity.setCapacityState(capacityState);
+                     }
+                 }
+             }
              _capacityDao.persist(capacity);
          } else {
              CapacityVO capacity = capacities.get(0);
@@@ -1526,7 -1522,13 +1524,13 @@@
          }
  
          long futureIops = currentIops + requestedIops;
 -        
 +
+         // getCapacityIops returns a Long so we need to check for null
+         if (pool.getCapacityIops() == null) {
+             s_logger.warn("Storage pool " + pool.getName() + " (" + pool.getId() + ") does not supply Iops capacity, assuming enough capacity");
+             return true;
+         }
+         
          return futureIops <= pool.getCapacityIops();
      }
  

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/storage/StoragePoolAutomationImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/StoragePoolAutomationImpl.java
index cb085cc,f6b39f1..158a01f
--- a/server/src/com/cloud/storage/StoragePoolAutomationImpl.java
+++ b/server/src/com/cloud/storage/StoragePoolAutomationImpl.java
@@@ -98,17 -100,46 +99,46 @@@ public class StoragePoolAutomationImpl 
      @Inject
      ManagementServer server;
      @Inject DataStoreProviderManager providerMgr;
 -
 +    
      @Override
      public boolean maintain(DataStore store) {
 -        Long userId = UserContext.current().getCallerUserId();
 +        Long userId = CallContext.current().getCallingUserId();
          User user = _userDao.findById(userId);
 -        Account account = UserContext.current().getCaller();
 -        StoragePoolVO pool = this.primaryDataStoreDao.findById(store.getId());
 +        Account account = CallContext.current().getCallingAccount();
 +        StoragePoolVO pool = primaryDataStoreDao.findById(store.getId());
          try {
+             List<StoragePoolVO> spes = null;
+             // Handling Zone and Cluster wide storage scopes.
+             // if the storage is ZONE wide then we pass podid and cluster id as null as they will be empty for ZWPS 
+             if (pool.getScope() == ScopeType.ZONE) {
+                 spes = primaryDataStoreDao.listBy(
+                         pool.getDataCenterId(), null,
+                         null, ScopeType.ZONE);
+             }
+             else {
+                 spes = primaryDataStoreDao.listBy(
+                         pool.getDataCenterId(), pool.getPodId(),
+                         pool.getClusterId(), ScopeType.CLUSTER);
+             }
+             for (StoragePoolVO sp : spes) {
+                 if (sp.getStatus() == StoragePoolStatus.PrepareForMaintenance) {
+                     throw new CloudRuntimeException("Only one storage pool in a cluster can be in PrepareForMaintenance mode, " + sp.getId()
+                             + " is already in  PrepareForMaintenance mode ");
+                 }
+             }
              StoragePool storagePool = (StoragePool) store;
-             List<HostVO> hosts = _resourceMgr.listHostsInClusterByStatus(
+ 
+             //Handeling the Zone wide and cluster wide primay storage
+             List<HostVO> hosts = new ArrayList<HostVO>();
+             // if the storage scope is ZONE wide, then get all the hosts for which hypervisor ZWSP created to send Modifystoragepoolcommand
+             //TODO: if it's zone wide, this code will list a lot of hosts in the zone, which may cause performance/OOM issue.
+             if (pool.getScope().equals(ScopeType.ZONE)) {
+                 hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(pool.getHypervisor() , pool.getDataCenterId());
+             } else {
+                 hosts = _resourceMgr.listHostsInClusterByStatus(
 -                        pool.getClusterId(), Status.Up);
 +                    pool.getClusterId(), Status.Up);
+             }
+ 
              if (hosts == null || hosts.size() == 0) {
                  pool.setStatus(StoragePoolStatus.Maintenance);
                  primaryDataStoreDao.update(pool.getId(), pool);
@@@ -244,11 -342,11 +274,10 @@@
                      }
                  }
              }
-             
          } catch(Exception e) {
 -            s_logger.error(
 -                    "Exception in enabling primary storage maintenance:", e);
 +            s_logger.error("Exception in enabling primary storage maintenance:", e);
              pool.setStatus(StoragePoolStatus.ErrorInMaintenance);
 -            this.primaryDataStoreDao.update(pool.getId(), pool);
 +            primaryDataStoreDao.update(pool.getId(), pool);
              throw new CloudRuntimeException(e.getMessage());
          }
          return true;
@@@ -257,13 -355,23 +286,22 @@@
      @Override
      public boolean cancelMaintain(DataStore store) {
          // Change the storage state back to up
 -        Long userId = UserContext.current().getCallerUserId();
 +        Long userId = CallContext.current().getCallingUserId();
          User user = _userDao.findById(userId);
 -        Account account = UserContext.current().getCaller();
 -        StoragePoolVO poolVO = this.primaryDataStoreDao
 -                .findById(store.getId());
 +        Account account = CallContext.current().getCallingAccount();
 +        StoragePoolVO poolVO = primaryDataStoreDao.findById(store.getId());
          StoragePool pool = (StoragePool)store;
 -
 +       
-         List<HostVO> hosts = _resourceMgr.listHostsInClusterByStatus(pool.getClusterId(), Status.Up);
+         //Handeling the Zone wide and cluster wide primay storage
+         List<HostVO> hosts = new ArrayList<HostVO>();
+         // if the storage scope is ZONE wide, then get all the hosts for which hypervisor ZWSP created to send Modifystoragepoolcommand
+         if (poolVO.getScope().equals(ScopeType.ZONE)) {
+             hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(poolVO.getHypervisor(), pool.getDataCenterId());
+         } else {
+             hosts = _resourceMgr.listHostsInClusterByStatus(
+                 pool.getClusterId(), Status.Up);
+         }
+ 
          if (hosts == null || hosts.size() == 0) {
              return true;
          }

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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/template/TemplateManagerImpl.java
index d2a4730,5a54656..cb9059a
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@@ -404,18 -406,19 +404,19 @@@ public class TemplateManagerImpl extend
  
          return extract(caller, templateId, url, zoneId, mode, eventId, false);
      }
 -
 +    
      @Override
      public VirtualMachineTemplate prepareTemplate(long templateId, long zoneId) {
 -
 -        VMTemplateVO vmTemplate = _tmpltDao.findById(templateId);
 +    	
 +    	VMTemplateVO vmTemplate = _tmpltDao.findById(templateId);
-         if (vmTemplate == null)
+         if (vmTemplate == null) {
 -            throw new InvalidParameterValueException("Unable to find template id=" + templateId);
 +    		throw new InvalidParameterValueException("Unable to find template id=" + templateId);
+         }
 -
 -        _accountMgr.checkAccess(UserContext.current().getCaller(), AccessType.ModifyEntry, true, vmTemplate);
 -
 -        prepareTemplateInAllStoragePools(vmTemplate, zoneId);
 -        return vmTemplate;
 +    	
 +    	_accountMgr.checkAccess(CallContext.current().getCallingAccount(), AccessType.ModifyEntry, true, vmTemplate);
 +    	
 +    	prepareTemplateInAllStoragePools(vmTemplate, zoneId);
 +    	return vmTemplate;
      }
  
      private String extract(Account caller, Long templateId, String url, Long zoneId, String mode, Long eventId, boolean isISO) {
@@@ -717,15 -720,20 +718,20 @@@
              s_logger.debug("Template " + templateId + " is in region-wide secondary storage " + dstSecStore.getName() + " , don't need to copy");
              return template;
          }
 -
 +       
          _accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, template);
 -
 +        
          boolean success = copy(userId, template, srcSecStore, dstZone);
 -
 +        
          if (success) {
+             // increase resource count
+             long accountId = template.getAccountId();
+             if (template.getSize() != null) {
+                 _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.secondary_storage, template.getSize());
+             }
 -            return template;
 +        	return template;
          } else {
 -            throw new CloudRuntimeException("Failed to copy template");
 +        	throw new CloudRuntimeException("Failed to copy template");
          }
      }
  

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/vm/UserVmManagerImpl.java
index d34ba7d,e5faaf1..22eb4c1
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@@ -1171,31 -1177,37 +1171,37 @@@ public class UserVmManagerImpl extends 
          }
  
          // Dynamically upgrade the running vms
 -        boolean success = false;
 +            boolean success = false;
          if(vmInstance.getState().equals(State.Running)){
              int retry = _scaleRetry;
+             ExcludeList excludes = new ExcludeList();
              boolean enableDynamicallyScaleVm = Boolean.parseBoolean(_configServer.getConfigValue(Config.EnableDynamicallyScaleVm.key(), Config.ConfigurationParameterScope.zone.toString(), vmInstance.getDataCenterId()));
              if(!enableDynamicallyScaleVm){
                 throw new PermissionDeniedException("Dynamically scaling virtual machines is disabled for this zone, please contact your admin");
              }
  
+             while (retry-- != 0) { // It's != so that it can match -1.
+                 try{
+                     boolean existingHostHasCapacity = false;
+ 
 -                    // Increment CPU and Memory count accordingly.
 -                    if (newCpu > currentCpu) {
 -                        _resourceLimitMgr.incrementResourceCount(caller.getAccountId(), ResourceType.cpu, new Long (newCpu - currentCpu));
 -                    }
 -                    if (newMemory > currentMemory) {
 -                        _resourceLimitMgr.incrementResourceCount(caller.getAccountId(), ResourceType.memory, new Long (newMemory - currentMemory));
 -                    }
 +            // Increment CPU and Memory count accordingly.
 +            if (newCpu > currentCpu) {
 +                _resourceLimitMgr.incrementResourceCount(caller.getAccountId(), ResourceType.cpu, new Long (newCpu - currentCpu));
 +            }
 +            if (newMemory > currentMemory) {
 +                _resourceLimitMgr.incrementResourceCount(caller.getAccountId(), ResourceType.memory, new Long (newMemory - currentMemory));
 +            }
  
-             while (retry-- != 0) { // It's != so that it can match -1.
-                 try{
                      // #1 Check existing host has capacity
-                     boolean existingHostHasCapacity = _capacityMgr.checkIfHostHasCapacity(vmInstance.getHostId(), newServiceOffering.getSpeed() - currentServiceOffering.getSpeed(),
+                     if( !excludes.shouldAvoid(ApiDBUtils.findHostById(vmInstance.getHostId())) ){
+                         existingHostHasCapacity = _capacityMgr.checkIfHostHasCapacity(vmInstance.getHostId(), newServiceOffering.getSpeed() - currentServiceOffering.getSpeed(),
 -                                (newServiceOffering.getRamSize() - currentServiceOffering.getRamSize()) * 1024L * 1024L, false, ApiDBUtils.getCpuOverprovisioningFactor(), 1f, false); // TO DO fill it with mem.
 +                            (newServiceOffering.getRamSize() - currentServiceOffering.getRamSize()) * 1024L * 1024L, false, ApiDBUtils.getCpuOverprovisioningFactor(), 1f, false); // TO DO fill it with mem.
+                         excludes.addHost(vmInstance.getHostId());
+                     }
  
-                     // #2 migrate the vm if host doesn't have capacity
+                     // #2 migrate the vm if host doesn't have capacity or is in avoid set
                      if (!existingHostHasCapacity){
 -                        vmInstance = _itMgr.findHostAndMigrate(vmInstance.getType(), vmInstance, newServiceOfferingId, excludes);
 +                        _itMgr.findHostAndMigrate(vmInstance.getUuid(), newServiceOfferingId);
                      }
  
                      // #3 scale the vm now

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java
----------------------------------------------------------------------
diff --cc server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java
index 20e75cc,ad36fae..b8da758
--- a/server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java
+++ b/server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java
@@@ -517,9 -509,16 +522,16 @@@ public class GlobalLoadBalancingRulesSe
  
          Transaction txn = Transaction.currentTxn();
          txn.start();
+         if (algorithm != null) {
 -            gslbRule.setAlgorithm(algorithm);
 +        gslbRule.setAlgorithm(algorithm);
+         }
+         if (stickyMethod != null) {
 -            gslbRule.setPersistence(stickyMethod);
 +        gslbRule.setPersistence(stickyMethod);
+         }
+         if (description != null) {
 -            gslbRule.setDescription(description);
 +        gslbRule.setDescription(description);
+         }
+         gslbRule.setState(GlobalLoadBalancerRule.State.Add);
          _gslbRuleDao.update(gslbRule.getId(), gslbRule);
          txn.commit();
  

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/test/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --cc setup/db/db/schema-410to420.sql
index 578148f,8130999..821e8e0
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@@ -2012,24 -1946,21 +2014,21 @@@ CREATE VIEW `cloud`.`template_view` A
              left join
          `cloud`.`vm_template_details` ON vm_template_details.template_id = vm_template.id         
              left join
 -        `cloud`.`vm_template` source_template ON source_template.id = vm_template.source_template_id    
 +        `cloud`.`vm_template` source_template ON source_template.id = vm_template.source_template_id            
              left join
-         `cloud`.`template_zone_ref` ON template_zone_ref.template_id = vm_template.id
-             AND template_zone_ref.removed is null
+         `cloud`.`template_store_ref` ON template_store_ref.template_id = vm_template.id
              left join
-         `cloud`.`data_center` ON template_zone_ref.zone_id = data_center.id
+         `cloud`.`image_store` ON image_store.removed is NULL AND template_store_ref.store_id is not NULL AND image_store.id = template_store_ref.store_id 
 -        	left join
 +            left join
-         `cloud`.`image_store` ON image_store.removed is NULL AND (image_store.data_center_id = data_center.id OR image_store.scope = 'REGION')
+         `cloud`.`template_zone_ref` ON template_zone_ref.template_id = vm_template.id AND template_store_ref.store_id is NULL AND template_zone_ref.removed is null    
              left join
-         `cloud`.`template_store_ref` ON template_store_ref.template_id = vm_template.id AND template_store_ref.store_id = image_store.id
+         `cloud`.`data_center` ON (image_store.data_center_id = data_center.id OR template_zone_ref.zone_id = data_center.id)
              left join
          `cloud`.`launch_permission` ON launch_permission.template_id = vm_template.id
              left join
          `cloud`.`resource_tags` ON resource_tags.resource_id = vm_template.id
              and (resource_tags.resource_type = 'Template' or resource_tags.resource_type='ISO');
 -            
 +
- 
- 
  INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'midonet.apiserver.address', 'http://localhost:8081', 'Specify the address at which the Midonet API server can be contacted (if using Midonet)');
  INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'midonet.providerrouter.id', 'd7c5e6a3-e2f4-426b-b728-b7ce6a0448e5', 'Specifies the UUID of the Midonet provider router (if using Midonet)');