Re-absorb delta in master into vmsync

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3ecc52a4
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3ecc52a4
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3ecc52a4

Branch: refs/heads/vmsync
Commit: 3ecc52a4f34906c03825f1e3f6c2ce6590edb023
Parents: 306d090 43ab950
Author: Alex Huang <alex.hu...@gmail.com>
Authored: Wed Jul 3 17:58:38 2013 -0700
Committer: Alex Huang <alex.hu...@gmail.com>
Committed: Wed Jul 3 17:58:38 2013 -0700

----------------------------------------------------------------------
 .../agent/manager/allocator/PodAllocator.java   |  33 ++
 .../classes/resources/messages_ar.properties    |   2 +-
 .../classes/resources/messages_fr_FR.properties |  13 +-
 .../classes/resources/messages_it_IT.properties |   6 +-
 .../classes/resources/messages_ja.properties    | 540 ++++++++-----------
 .../classes/resources/messages_ko_KR.properties |   2 -
 .../classes/resources/messages_pt_BR.properties |   4 +-
 .../classes/resources/messages_ru_RU.properties |   2 -
 .../classes/resources/messages_zh_CN.properties | 422 +++++++--------
 .../src/com/cloud/resource/ResourceManager.java |  94 ++--
 .../agent/manager/allocator/PodAllocator.java   |  35 --
 .../allocator/impl/FirstFitAllocator.java       | 117 ++--
 .../allocator/impl/TestingAllocator.java        |   3 -
 .../impl/UserConcentratedAllocator.java         |  30 +-
 .../src/com/cloud/capacity/CapacityManager.java |   1 -
 .../com/cloud/resource/ResourceManagerImpl.java |   5 +-
 .../src/com/cloud/storage/StorageManager.java   |   5 +-
 .../com/cloud/storage/StorageManagerImpl.java   |   4 +-
 .../com/cloud/storage/VolumeManagerImpl.java    |   8 +-
 .../com/cloud/template/TemplateAdapterBase.java |  23 +-
 .../cloud/resource/MockResourceManagerImpl.java |  24 +-
 tools/marvin/marvin/deployDataCenter.py         |   3 +-
 ui/scripts/domains.js                           |  48 +-
 ui/scripts/zoneWizard.js                        |  49 +-
 utils/src/com/cloud/utils/net/NetUtils.java     |  20 +-
 25 files changed, 708 insertions(+), 785 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ecc52a4/engine/components-api/src/com/cloud/resource/ResourceManager.java
----------------------------------------------------------------------
diff --cc engine/components-api/src/com/cloud/resource/ResourceManager.java
index b0ab926,0000000..e35e89a
mode 100755,000000..100755
--- a/engine/components-api/src/com/cloud/resource/ResourceManager.java
+++ b/engine/components-api/src/com/cloud/resource/ResourceManager.java
@@@ -1,153 -1,0 +1,155 @@@
 +// Licensed to the Apache Software Foundation (ASF) under one
 +// or more contributor license agreements.  See the NOTICE file
 +// distributed with this work for additional information
 +// regarding copyright ownership.  The ASF licenses this file
 +// to you under the Apache License, Version 2.0 (the
 +// "License"); you may not use this file except in compliance
 +// with the License.  You may obtain a copy of the License at
 +//
 +//   http://www.apache.org/licenses/LICENSE-2.0
 +//
 +// Unless required by applicable law or agreed to in writing,
 +// software distributed under the License is distributed on an
 +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 +// KIND, either express or implied.  See the License for the
 +// specific language governing permissions and limitations
 +// under the License.
 +package com.cloud.resource;
 +
 +import java.util.List;
 +import java.util.Map;
 +import java.util.Set;
 +
 +import com.cloud.agent.api.StartupCommand;
 +import com.cloud.agent.api.StartupRoutingCommand;
 +import com.cloud.dc.DataCenterVO;
 +import com.cloud.dc.HostPodVO;
++import com.cloud.dc.Pod;
 +import com.cloud.dc.PodCluster;
 +import com.cloud.exception.AgentUnavailableException;
 +import com.cloud.host.Host;
 +import com.cloud.host.Host.Type;
 +import com.cloud.host.HostStats;
 +import com.cloud.host.HostVO;
 +import com.cloud.host.Status;
 +import com.cloud.hypervisor.Hypervisor.HypervisorType;
 +import com.cloud.resource.ResourceState.Event;
 +import com.cloud.service.ServiceOfferingVO;
 +import com.cloud.template.VirtualMachineTemplate;
 +import com.cloud.utils.Pair;
 +import com.cloud.utils.fsm.NoTransitionException;
 +
 +/**
 + * ResourceManager manages how physical resources are organized within the
 + * CloudStack. It also manages the life cycle of the physical resources.
 + */
- public interface ResourceManager extends ResourceService{
++public interface ResourceManager extends ResourceService {
 +    /**
 +     * Register a listener for different types of resource life cycle events.
 +     * There can only be one type of listener per type of host.
 +     * 
 +     * @param Event type see ResourceListener.java, allow combination of 
multiple events.
 +     * @param listener the listener to notify.
 +     */
 +    public void registerResourceEvent(Integer event, ResourceListener 
listener);
-     
++
 +    public void unregisterResourceEvent(ResourceListener listener);
-     
++
 +    /**
 +     * 
 +     * @param name of adapter
 +     * @param adapter
-      * @param hates, a list of names which will be eliminated by this 
adapter. Especially for the case where 
++     * @param hates, a list of names which will be eliminated by this 
adapter. Especially for the case where
 +     * can be only one adapter responds to an event, e.g. startupCommand
 +     */
 +    public void registerResourceStateAdapter(String name, 
ResourceStateAdapter adapter);
-     
++
 +    public void unregisterResourceStateAdapter(String name);
-     
-       public Host createHostAndAgent(Long hostId, ServerResource resource, 
Map<String, String> details, boolean old, List<String> hostTags,
-               boolean forRebalance);
-       
-       public Host addHost(long zoneId, ServerResource resource, Type 
hostType, Map<String, String> hostDetails);
-       
-       public HostVO createHostVOForConnectedAgent(StartupCommand[] cmds);
-       
-       public void checkCIDR(HostPodVO pod, DataCenterVO dc, String 
serverPrivateIP, String serverPrivateNetmask);
-       
-       public HostVO fillRoutingHostVO(HostVO host, StartupRoutingCommand 
ssCmd, HypervisorType hyType, Map<String, String> details, List<String> 
hostTags);
-       
-       public void deleteRoutingHost(HostVO host, boolean isForced, boolean 
forceDestroyStorage) throws UnableDeleteHostException;
-       
++
++    public Host createHostAndAgent(Long hostId, ServerResource resource, 
Map<String, String> details, boolean old, List<String> hostTags,
++            boolean forRebalance);
++
++    public Host addHost(long zoneId, ServerResource resource, Type hostType, 
Map<String, String> hostDetails);
++
++    public HostVO createHostVOForConnectedAgent(StartupCommand[] cmds);
++
++    public void checkCIDR(HostPodVO pod, DataCenterVO dc, String 
serverPrivateIP, String serverPrivateNetmask);
++
++    public HostVO fillRoutingHostVO(HostVO host, StartupRoutingCommand ssCmd, 
HypervisorType hyType, Map<String, String> details, List<String> hostTags);
++
++    public void deleteRoutingHost(HostVO host, boolean isForced, boolean 
forceDestroyStorage) throws UnableDeleteHostException;
++
 +    public boolean executeUserRequest(long hostId, ResourceState.Event event) 
throws AgentUnavailableException;
 +
-       boolean resourceStateTransitTo(Host host, Event event, long msId) 
throws NoTransitionException;
++    boolean resourceStateTransitTo(Host host, Event event, long msId) throws 
NoTransitionException;
++
++    boolean umanageHost(long hostId);
++
++    boolean maintenanceFailed(long hostId);
 +
-       boolean umanageHost(long hostId);
++    public boolean maintain(final long hostId) throws 
AgentUnavailableException;
 +
-       boolean maintenanceFailed(long hostId);
-       
-       public boolean maintain(final long hostId) throws 
AgentUnavailableException;
-       
 +    @Override
 +    public boolean deleteHost(long hostId, boolean isForced, boolean 
isForceDeleteStorage);
-     
++
 +    public List<HostVO> findDirectlyConnectedHosts();
-     
++
 +    public List<HostVO> listAllUpAndEnabledHosts(Host.Type type, Long 
clusterId, Long podId, long dcId);
-     
++
 +    public List<HostVO> listAllHostsInCluster(long clusterId);
-     
++
 +    public List<HostVO> listHostsInClusterByStatus(long clusterId, Status 
status);
-     
++
 +    public List<HostVO> listAllUpAndEnabledHostsInOneZoneByType(Host.Type 
type, long dcId);
++
 +    public List<HostVO> 
listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType type, long dcId);
-     
++
 +    public List<HostVO> listAllHostsInOneZoneByType(Host.Type type, long 
dcId);
-     
++
 +    public List<HostVO> listAllHostsInAllZonesByType(Type type);
-     
++
 +    public List<HypervisorType> listAvailHypervisorInZone(Long hostId, Long 
zoneId);
-     
++
 +    public HostVO findHostByGuid(String guid);
-     
++
 +    public HostVO findHostByName(String name);
-     
++
 +    public List<HostVO> listHostsByNameLike(String name);
-     
++
 +    /**
 +     * Find a pod based on the user id, template, and data center.
 +     * 
 +     * @param template
 +     * @param dc
 +     * @param userId
 +     * @return
 +     */
-     Pair<HostPodVO, Long> findPod(VirtualMachineTemplate template, 
ServiceOfferingVO offering, DataCenterVO dc, long accountId, Set<Long> avoids);
-     
++    Pair<Pod, Long> findPod(VirtualMachineTemplate template, 
ServiceOfferingVO offering, DataCenterVO dc, long accountId, Set<Long> avoids);
++
 +    HostStats getHostStatistics(long hostId);
-     
++
 +    Long getGuestOSCategoryId(long hostId);
-     
++
 +    String getHostTags(long hostId);
-     
++
 +    List<PodCluster> listByDataCenter(long dcId);
 +
-       List<HostVO> listAllNotInMaintenanceHostsInOneZone(Type type, Long 
dcId);
++    List<HostVO> listAllNotInMaintenanceHostsInOneZone(Type type, Long dcId);
 +
-       HypervisorType getDefaultHypervisor(long zoneId);
++    HypervisorType getDefaultHypervisor(long zoneId);
 +
-       HypervisorType getAvailableHypervisor(long zoneId);
++    HypervisorType getAvailableHypervisor(long zoneId);
 +
 +    Discoverer getMatchingDiscover(HypervisorType hypervisorType);
 +
-       List<HostVO> findHostByGuid(long dcId, String guid);
++    List<HostVO> findHostByGuid(long dcId, String guid);
 +
 +    /**
 +     * @param type
 +     * @param clusterId
 +     * @param podId
 +     * @param dcId
 +     * @return
 +     */
 +    List<HostVO> listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, 
Long podId, long dcId);
 +}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ecc52a4/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
----------------------------------------------------------------------
diff --cc 
server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
index 778ec84,4329c70..a6b92cf
--- a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
+++ b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
@@@ -86,42 -101,43 +101,42 @@@ public class FirstFitAllocator extends 
      float _factor = 1;
      boolean _checkHvm = true;
      protected String _allocationAlgorithm = "random";
-     @Inject CapacityManager _capacityMgr;
-     
+     @Inject
+     CapacityManager _capacityMgr;
 -
 +    
 +      @Override
 +    public List<Host> allocateTo(VirtualMachineProfile vmProfile, 
DeploymentPlan plan, Type type,
 +                      ExcludeList avoid, int returnUpTo) {
 +          return allocateTo(vmProfile, plan, type, avoid, returnUpTo, true);
 +      }
 +      
      @Override
 -    public List<Host> allocateTo(VirtualMachineProfile<? extends 
VirtualMachine> vmProfile, DeploymentPlan plan, Type type,
 -            ExcludeList avoid, int returnUpTo) {
 -        return allocateTo(vmProfile, plan, type, avoid, returnUpTo, true);
 -    }
 -
 -    @Override
 -    public List<Host> allocateTo(VirtualMachineProfile<? extends 
VirtualMachine> vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, 
int returnUpTo,
 -            boolean considerReservedCapacity) {
 -
 -        long dcId = plan.getDataCenterId();
 -        Long podId = plan.getPodId();
 -        Long clusterId = plan.getClusterId();
 -        ServiceOffering offering = vmProfile.getServiceOffering();
 -        VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate();
 -        Account account = vmProfile.getOwner();
 +    public List<Host> allocateTo(VirtualMachineProfile vmProfile, 
DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean 
considerReservedCapacity) {
 +      
 +          long dcId = plan.getDataCenterId();
 +              Long podId = plan.getPodId();
 +              Long clusterId = plan.getClusterId();
 +              ServiceOffering offering = vmProfile.getServiceOffering();
 +              VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate();
 +              Account account = vmProfile.getOwner();
  
          if (type == Host.Type.Storage) {
              // FirstFitAllocator should be used for user VMs only since it 
won't care whether the host is capable of routing or not
 -            return new ArrayList<Host>();
 +              return new ArrayList<Host>();
          }
 -
 +        
-         if(s_logger.isDebugEnabled()){
-             s_logger.debug("Looking for hosts in dc: " + dcId + "  pod:" + 
podId + "  cluster:" + clusterId );
+         if (s_logger.isDebugEnabled()) {
+             s_logger.debug("Looking for hosts in dc: " + dcId + "  pod:" + 
podId + "  cluster:" + clusterId);
          }
 -
 +        
          String hostTagOnOffering = offering.getHostTag();
          String hostTagOnTemplate = template.getTemplateTag();
 -
 +        
          boolean hasSvcOfferingTag = hostTagOnOffering != null ? true : false;
          boolean hasTemplateTag = hostTagOnTemplate != null ? true : false;
 -
 -        List<HostVO> clusterHosts = new ArrayList<HostVO>();
 -
 +        
 +        List<? extends Host> clusterHosts = new ArrayList<Host>();
 +        
          String haVmTag = 
(String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
          if (haVmTag != null) {
              clusterHosts = _hostDao.listByHostTag(type, clusterId, podId, 
dcId, haVmTag);
@@@ -145,21 -161,21 +160,21 @@@
                          s_logger.debug("Looking for hosts having tag 
specified on Template:" + hostTagOnTemplate);
                      }
                      hostsMatchingTemplateTag = _hostDao.listByHostTag(type, 
clusterId, podId, dcId, hostTagOnTemplate);
-                     if (s_logger.isDebugEnabled()){
-                         s_logger.debug("Hosts with tag '" + 
hostTagOnTemplate+"' are:" + hostsMatchingTemplateTag);
+                     if (s_logger.isDebugEnabled()) {
+                         s_logger.debug("Hosts with tag '" + hostTagOnTemplate 
+ "' are:" + hostsMatchingTemplateTag);
                      }
                  }
 -
 +                
-                 if (hasSvcOfferingTag && hasTemplateTag){
+                 if (hasSvcOfferingTag && hasTemplateTag) {
                      
hostsMatchingOfferingTag.retainAll(hostsMatchingTemplateTag);
                      clusterHosts = _hostDao.listByHostTag(type, clusterId, 
podId, dcId, hostTagOnTemplate);
-                     if (s_logger.isDebugEnabled()){
-                         s_logger.debug("Found "+ 
hostsMatchingOfferingTag.size() +" Hosts satisfying both tags, host ids are:" + 
hostsMatchingOfferingTag);
+                     if (s_logger.isDebugEnabled()) {
+                         s_logger.debug("Found " + 
hostsMatchingOfferingTag.size() + " Hosts satisfying both tags, host ids are:" 
+ hostsMatchingOfferingTag);
                      }
 -
 +                    
                      clusterHosts = hostsMatchingOfferingTag;
                  } else {
-                     if (hasSvcOfferingTag){
+                     if (hasSvcOfferingTag) {
                          clusterHosts = hostsMatchingOfferingTag;
                      } else {
                          clusterHosts = hostsMatchingTemplateTag;
@@@ -228,16 -244,16 +243,16 @@@
      protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering 
offering, VMTemplateVO template, ExcludeList avoid, List<? extends Host> hosts, 
int returnUpTo,
              boolean considerReservedCapacity, Account account) {
          if (_allocationAlgorithm.equals("random") || 
_allocationAlgorithm.equals("userconcentratedpod_random")) {
 -            // Shuffle this so that we don't check the hosts in the same 
order.
 +              // Shuffle this so that we don't check the hosts in the same 
order.
              Collections.shuffle(hosts);
-         }else if(_allocationAlgorithm.equals("userdispersing")){
+         } else if (_allocationAlgorithm.equals("userdispersing")) {
              hosts = reorderHostsByNumberOfVms(plan, hosts, account);
          }
 -
 -        if (s_logger.isDebugEnabled()) {
 +      
 +      if (s_logger.isDebugEnabled()) {
-             s_logger.debug("FirstFitAllocator has " + hosts.size() + " hosts 
to check for allocation: "+hosts);
+             s_logger.debug("FirstFitAllocator has " + hosts.size() + " hosts 
to check for allocation: " + hosts);
          }
 -
 +        
          // We will try to reorder the host lists such that we give priority 
to hosts that have
          // the minimums to support a VM's requirements
          hosts = prioritizeHosts(template, hosts);
@@@ -253,31 -269,32 +268,32 @@@
          List<Host> suitableHosts = new ArrayList<Host>();
  
          for (Host host : hosts) {
-               if(suitableHosts.size() == returnUpTo){
+             if (suitableHosts.size() == returnUpTo) {
 -                break;
 -            }
 +                      break;
 +              }
              if (avoid.shouldAvoid(host)) {
                  if (s_logger.isDebugEnabled()) {
-                     s_logger.debug("Host name: " + host.getName() + ", 
hostId: "+ host.getId() +" is in avoid set, skipping this and trying other 
available hosts");
+                     s_logger.debug("Host name: " + host.getName() + ", 
hostId: " + host.getId() + " is in avoid set, skipping this and trying other 
available hosts");
                  }
                  continue;
              }
 -
 +                        
              //find number of guest VMs occupying capacity on this host.
-             if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)){
+             if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)) {
                  if (s_logger.isDebugEnabled()) {
-                     s_logger.debug("Host name: " + host.getName() + ", 
hostId: "+ host.getId() +" already has max Running VMs(count includes system 
VMs), skipping this and trying other available hosts");
+                     s_logger.debug("Host name: " + host.getName() + ", 
hostId: " + host.getId()
+                             + " already has max Running VMs(count includes 
system VMs), skipping this and trying other available hosts");
                  }
                  continue;
              }
  
              boolean numCpusGood = host.getCpus().intValue() >= 
offering.getCpu();
              boolean cpuFreqGood = host.getSpeed().intValue() >= 
offering.getSpeed();
 -            int cpu_requested = offering.getCpu() * offering.getSpeed();
 -            long ram_requested = offering.getRamSize() * 1024L * 1024L;
 +              int cpu_requested = offering.getCpu() * offering.getSpeed();
 +              long ram_requested = offering.getRamSize() * 1024L * 1024L;
              Cluster cluster = _clusterDao.findById(host.getClusterId());
-             ClusterDetailsVO clusterDetailsCpuOvercommit = 
_clusterDetailsDao.findDetail(cluster.getId(),"cpuOvercommitRatio");
-             ClusterDetailsVO clusterDetailsRamOvercommmt = 
_clusterDetailsDao.findDetail(cluster.getId(),"memoryOvercommitRatio");
+             ClusterDetailsVO clusterDetailsCpuOvercommit = 
_clusterDetailsDao.findDetail(cluster.getId(), "cpuOvercommitRatio");
+             ClusterDetailsVO clusterDetailsRamOvercommmt = 
_clusterDetailsDao.findDetail(cluster.getId(), "memoryOvercommitRatio");
              Float cpuOvercommitRatio = 
Float.parseFloat(clusterDetailsCpuOvercommit.getValue());
              Float memoryOvercommitRatio = 
Float.parseFloat(clusterDetailsRamOvercommmt.getValue());
  
@@@ -295,11 -313,11 +312,11 @@@
                  avoid.addHost(host.getId());
              }
          }
 -
 +        
          if (s_logger.isDebugEnabled()) {
-             s_logger.debug("Host Allocator returning "+suitableHosts.size() 
+" suitable hosts");
+             s_logger.debug("Host Allocator returning " + suitableHosts.size() 
+ " suitable hosts");
          }
 -
 +        
          return suitableHosts;
      }
  
@@@ -310,26 -328,26 +327,26 @@@
          long dcId = plan.getDataCenterId();
          Long podId = plan.getPodId();
          Long clusterId = plan.getClusterId();
 -
 +        
          List<Long> hostIdsByVmCount = 
_vmInstanceDao.listHostIdsByVmCount(dcId, podId, clusterId, 
account.getAccountId());
          if (s_logger.isDebugEnabled()) {
-             s_logger.debug("List of hosts in ascending order of number of 
VMs: "+ hostIdsByVmCount);
+             s_logger.debug("List of hosts in ascending order of number of 
VMs: " + hostIdsByVmCount);
          }
 -
 +        
          //now filter the given list of Hosts by this ordered list
          Map<Long, Host> hostMap = new HashMap<Long, Host>();
          for (Host host : hosts) {
              hostMap.put(host.getId(), host);
          }
          List<Long> matchingHostIds = new ArrayList<Long>(hostMap.keySet());
 -
 +        
          hostIdsByVmCount.retainAll(matchingHostIds);
 -
 +        
          List<Host> reorderedHosts = new ArrayList<Host>();
-         for(Long id: hostIdsByVmCount){
+         for (Long id : hostIdsByVmCount) {
              reorderedHosts.add(hostMap.get(id));
          }
 -
 +        
          return reorderedHosts;
      }
  
@@@ -341,120 -359,120 +358,120 @@@
      }
  
      protected List<? extends Host> prioritizeHosts(VMTemplateVO template, 
List<? extends Host> hosts) {
 -        if (template == null) {
 -            return hosts;
 -        }
 -
 -        // Determine the guest OS category of the template
 -        String templateGuestOSCategory = getTemplateGuestOSCategory(template);
 -
 +      if (template == null) {
 +              return hosts;
 +      }
 +      
 +      // Determine the guest OS category of the template
 +      String templateGuestOSCategory = getTemplateGuestOSCategory(template);
 +      
          List<Host> prioritizedHosts = new ArrayList<Host>();
          List<Host> noHvmHosts = new ArrayList<Host>();
 -
 -        // If a template requires HVM and a host doesn't support HVM, remove 
it from consideration
 +      
 +      // If a template requires HVM and a host doesn't support HVM, remove it 
from consideration
          List<Host> hostsToCheck = new ArrayList<Host>();
 -        if (template.isRequiresHvm()) {
 +      if (template.isRequiresHvm()) {
              for (Host host : hosts) {
 -                if (hostSupportsHVM(host)) {
 -                    hostsToCheck.add(host);
 -                } else {
 -                    noHvmHosts.add(host);
 -                }
 -            }
 -        } else {
 -            hostsToCheck.addAll(hosts);
 -        }
 -
 -        if (s_logger.isDebugEnabled()) {
 -            if (noHvmHosts.size() > 0) {
 +                      if (hostSupportsHVM(host)) {
 +                              hostsToCheck.add(host);
 +                      } else {
 +                              noHvmHosts.add(host);
 +                      }
 +              }
 +      } else {
 +              hostsToCheck.addAll(hosts);
 +      }
 +      
 +      if (s_logger.isDebugEnabled()) {
 +              if (noHvmHosts.size() > 0) {
-                       s_logger.debug("Not considering hosts: "  + noHvmHosts 
+ "  to deploy template: " + template +" as they are not HVM enabled");
+                 s_logger.debug("Not considering hosts: " + noHvmHosts + "  to 
deploy template: " + template + " as they are not HVM enabled");
 -            }
 -        }
 -        // If a host is tagged with the same guest OS category as the 
template, move it to a high priority list
 -        // If a host is tagged with a different guest OS category than the 
template, move it to a low priority list
 +              }
 +      }
 +      // If a host is tagged with the same guest OS category as the template, 
move it to a high priority list
 +      // If a host is tagged with a different guest OS category than the 
template, move it to a low priority list
          List<Host> highPriorityHosts = new ArrayList<Host>();
          List<Host> lowPriorityHosts = new ArrayList<Host>();
          for (Host host : hostsToCheck) {
 -            String hostGuestOSCategory = getHostGuestOSCategory(host);
 -            if (hostGuestOSCategory == null) {
 -                continue;
 -            } else if (templateGuestOSCategory.equals(hostGuestOSCategory)) {
 -                highPriorityHosts.add(host);
 -            } else {
 -                lowPriorityHosts.add(host);
 -            }
 -        }
 -
 -        hostsToCheck.removeAll(highPriorityHosts);
 -        hostsToCheck.removeAll(lowPriorityHosts);
 -
 -        // Prioritize the remaining hosts by HVM capability
 +              String hostGuestOSCategory = getHostGuestOSCategory(host);
 +              if (hostGuestOSCategory == null) {
 +                      continue;
 +              } else if (templateGuestOSCategory.equals(hostGuestOSCategory)) 
{
 +                      highPriorityHosts.add(host);
 +              } else {
 +                      lowPriorityHosts.add(host);
 +              }
 +      }
 +      
 +      hostsToCheck.removeAll(highPriorityHosts);
 +      hostsToCheck.removeAll(lowPriorityHosts);
 +      
 +      // Prioritize the remaining hosts by HVM capability
          for (Host host : hostsToCheck) {
 -            if (!template.isRequiresHvm() && !hostSupportsHVM(host)) {
 -                // Host and template both do not support hvm, put it as first 
consideration
 -                prioritizedHosts.add(0, host);
 -            } else {
 -                // Template doesn't require hvm, but the machine supports it, 
make it last for consideration
 -                prioritizedHosts.add(host);
 -            }
 -        }
 -
 -        // Merge the lists
 -        prioritizedHosts.addAll(0, highPriorityHosts);
 -        prioritizedHosts.addAll(lowPriorityHosts);
 -
 -        return prioritizedHosts;
 +              if (!template.isRequiresHvm() && !hostSupportsHVM(host)) {
 +                      // Host and template both do not support hvm, put it as 
first consideration
 +                      prioritizedHosts.add(0, host);
 +              } else {
 +                      // Template doesn't require hvm, but the machine 
supports it, make it last for consideration
 +                      prioritizedHosts.add(host);
 +              }
 +      }
 +      
 +      // Merge the lists
 +      prioritizedHosts.addAll(0, highPriorityHosts);
 +      prioritizedHosts.addAll(lowPriorityHosts);
 +      
 +      return prioritizedHosts;
      }
 -
 +    
      protected boolean hostSupportsHVM(Host host) {
-         if ( !_checkHvm ) {
+         if (!_checkHvm) {
              return true;
          }
 -        // Determine host capabilities
 -        String caps = host.getCapabilities();
 -
 -        if (caps != null) {
 +      // Determine host capabilities
 +              String caps = host.getCapabilities();
 +              
 +              if (caps != null) {
              String[] tokens = caps.split(",");
              for (String token : tokens) {
 -                if (token.contains("hvm")) {
 -                    return true;
 -                }
 +              if (token.contains("hvm")) {
 +                  return true;
 +              }
              }
 -        }
 -
 -        return false;
 +              }
 +              
 +              return false;
      }
 -
 +    
      protected String getHostGuestOSCategory(Host host) {
 -        DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(), 
"guest.os.category.id");
 -        if (hostDetail != null) {
 -            String guestOSCategoryIdString = hostDetail.getValue();
 -            long guestOSCategoryId;
 -
 -            try {
 -                guestOSCategoryId = Long.parseLong(guestOSCategoryIdString);
 -            } catch (Exception e) {
 -                return null;
 -            }
 -
 -            GuestOSCategoryVO guestOSCategory = 
_guestOSCategoryDao.findById(guestOSCategoryId);
 -
 -            if (guestOSCategory != null) {
 -                return guestOSCategory.getName();
 -            } else {
 -                return null;
 -            }
 -        } else {
 -            return null;
 -        }
 +              DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(), 
"guest.os.category.id");
 +              if (hostDetail != null) {
 +                      String guestOSCategoryIdString = hostDetail.getValue();
 +                      long guestOSCategoryId;
 +                      
 +                      try {
 +                              guestOSCategoryId = 
Long.parseLong(guestOSCategoryIdString);
 +                      } catch (Exception e) {
 +                              return null;
 +                      }
 +                      
 +                      GuestOSCategoryVO guestOSCategory = 
_guestOSCategoryDao.findById(guestOSCategoryId);
 +                      
 +                      if (guestOSCategory != null) {
 +                              return guestOSCategory.getName();
 +                      } else {
 +                              return null;
 +                      }
 +              } else {
 +                      return null;
 +              }
      }
 -
 +    
      protected String getTemplateGuestOSCategory(VMTemplateVO template) {
 -        long guestOSId = template.getGuestOSId();
 -        GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
 -        long guestOSCategoryId = guestOS.getCategoryId();
 -        GuestOSCategoryVO guestOSCategory = 
_guestOSCategoryDao.findById(guestOSCategoryId);
 -        return guestOSCategory.getName();
 +      long guestOSId = template.getGuestOSId();
 +      GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
 +      long guestOSCategoryId = guestOS.getCategoryId();
 +      GuestOSCategoryVO guestOSCategory = 
_guestOSCategoryDao.findById(guestOSCategoryId);
 +      return guestOSCategory.getName();
      }
  
      @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ecc52a4/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ecc52a4/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/resource/ResourceManagerImpl.java
index c0e4254,054ac40..428febc
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@@ -2468,10 -2470,10 +2469,10 @@@ public class ResourceManagerImpl extend
      }
  
      @Override
-     public Pair<HostPodVO, Long> findPod(VirtualMachineTemplate template, 
ServiceOfferingVO offering, DataCenterVO dc, long accountId,
+     public Pair<Pod, Long> findPod(VirtualMachineTemplate template, 
ServiceOfferingVO offering, DataCenterVO dc, long accountId,
 -            Set<Long> avoids) {
 -        for (PodAllocator allocator : _podAllocators) {
 +                      Set<Long> avoids) {
 +              for (PodAllocator allocator : _podAllocators) {
-             final Pair<HostPodVO, Long> pod = allocator.allocateTo(template, 
offering, dc, accountId, avoids);
+             final Pair<Pod, Long> pod = allocator.allocateTo(template, 
offering, dc, accountId, avoids);
              if (pod != null) {
                  return pod;
              }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ecc52a4/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/StorageManagerImpl.java
index 13eb98a,d9ef853..c6233db
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@@ -401,22 -400,22 +401,22 @@@ public class StorageManagerImpl extend
      }
  
      @Override
-     public StoragePool findStoragePool(DiskProfile dskCh, final DataCenterVO 
dc, HostPodVO pod, Long clusterId, Long hostId, VMInstanceVO vm,
+     public StoragePool findStoragePool(DiskProfile dskCh, final DataCenterVO 
dc, Pod pod, Long clusterId, Long hostId, VMInstanceVO vm,
 -                                       final Set<StoragePool> avoid) {
 +            final Set<StoragePool> avoid) {
  
 -        VirtualMachineProfile<VMInstanceVO> profile = new 
VirtualMachineProfileImpl<VMInstanceVO>(vm);
 +        VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
          for (StoragePoolAllocator allocator : _storagePoolAllocators) {
 -
 -            ExcludeList avoidList = new ExcludeList();
 +              
 +              ExcludeList avoidList = new ExcludeList();
              for (StoragePool pool : avoid) {
 -                avoidList.addPool(pool.getId());
 -            }
 -            DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), 
pod.getId(), clusterId, hostId, null, null);
 -
 -            final List<StoragePool> poolList = 
allocator.allocateToPool(dskCh, profile, plan, avoidList, 1);
 -            if (poolList != null && !poolList.isEmpty()) {
 +                      avoidList.addPool(pool.getId());
 +              }
 +              DataCenterDeployment plan = new 
DataCenterDeployment(dc.getId(), pod.getId(), clusterId, hostId, null, null);
 +              
 +              final List<StoragePool> poolList = 
allocator.allocateToPool(dskCh, profile, plan, avoidList, 1);
 +              if (poolList != null && !poolList.isEmpty()) {
                  return (StoragePool) 
dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
 -            }
 +              }
          }
          return null;
      }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ecc52a4/server/src/com/cloud/storage/VolumeManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/VolumeManagerImpl.java
index 0554f22,d63e631..31a0ac2
--- a/server/src/com/cloud/storage/VolumeManagerImpl.java
+++ b/server/src/com/cloud/storage/VolumeManagerImpl.java
@@@ -549,10 -549,9 +548,9 @@@ public class VolumeManagerImpl extends 
              while ((pool = storageMgr.findStoragePool(dskCh, dc, pod.first(), 
null, null,
                      null, poolsToAvoid)) != null) {
                  break;
-                 
              }
          }
 -
 +        
          if (pool == null) {
              String msg = "There are no available storage pools to store the 
volume in";
              s_logger.info(msg);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ecc52a4/server/src/com/cloud/template/TemplateAdapterBase.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/template/TemplateAdapterBase.java
index 88909d8,fce2506..b67d759
--- a/server/src/com/cloud/template/TemplateAdapterBase.java
+++ b/server/src/com/cloud/template/TemplateAdapterBase.java
@@@ -21,17 -21,16 +21,17 @@@ import java.util.Map
  
  import javax.inject.Inject;
  
++import org.apache.log4j.Logger;
++
  import org.apache.cloudstack.api.ApiConstants;
  import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
  import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
  import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd;
- import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
  import org.apache.cloudstack.api.command.user.template.ExtractTemplateCmd;
+ import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
 -import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 +import org.apache.cloudstack.context.CallContext;
- import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
  import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
--import org.apache.log4j.Logger;
  
  import com.cloud.api.ApiDBUtils;
  import com.cloud.configuration.Config;
@@@ -289,9 -291,16 +291,16 @@@ public abstract class TemplateAdapterBa
  
                                if ((template != null)
                                                && 
(!template.isPublicTemplate() && (account.getId() != template.getAccountId()) 
&& (template.getTemplateType() != TemplateType.PERHOST))) {
+                                   //special handling for the project case
+                                   Account owner = 
_accountMgr.getAccount(template.getAccountId());
+                                   if (owner.getType() == 
Account.ACCOUNT_TYPE_PROJECT) {
+                                       if 
(!_projectMgr.canAccessProjectAccount(account, owner.getId())) {
+                               throw new PermissionDeniedException(msg + ". 
Permission denied. The caller can't access project's template");
+                                       }
+                           } else {
 -                              throw new PermissionDeniedException(msg + ". 
Permission denied.");
 -                          }
 +                                      throw new PermissionDeniedException(msg 
+ ". Permission denied.");
 +                              }
- 
+                               }
                        } else {
                                if ((vmInstanceCheck != null) && 
!_domainDao.isChildDomain(account.getDomainId(), 
vmInstanceCheck.getDomainId())) {
                                        throw new PermissionDeniedException(msg 
+ ". Permission denied.");
@@@ -337,9 -346,9 +346,10 @@@
                return new TemplateProfile(userId, template, zoneId);
        }
  
--      public TemplateProfile prepareExtractTemplate(ExtractTemplateCmd cmd) {
++      @Override
++    public TemplateProfile prepareExtractTemplate(ExtractTemplateCmd cmd) {
                Long templateId = cmd.getId();
 -              Long userId = UserContext.current().getCallerUserId();
 +              Long userId = CallContext.current().getCallingUserId();
                Long zoneId = cmd.getZoneId();
  
                VMTemplateVO template = 
_tmpltDao.findById(templateId.longValue());
@@@ -349,12 -358,12 +359,13 @@@
                return new TemplateProfile(userId, template, zoneId);
        }
  
--      public TemplateProfile prepareDelete(DeleteIsoCmd cmd) {
++      @Override
++    public TemplateProfile prepareDelete(DeleteIsoCmd cmd) {
                Long templateId = cmd.getId();
 -        Long userId = UserContext.current().getCallerUserId();
 -        Account account = UserContext.current().getCaller();
 +        Long userId = CallContext.current().getCallingUserId();
 +        Account account = CallContext.current().getCallingAccount();
          Long zoneId = cmd.getZoneId();
 -
 +        
          VMTemplateVO template = _tmpltDao.findById(templateId.longValue());
          if (template == null) {
              throw new InvalidParameterValueException("unable to find iso with 
id " + templateId);

Reply via email to