Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 31A45E5AC for ; Mon, 24 Jun 2013 23:51:49 +0000 (UTC) Received: (qmail 84415 invoked by uid 500); 24 Jun 2013 23:51:40 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 84317 invoked by uid 500); 24 Jun 2013 23:51:40 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 83919 invoked by uid 99); 24 Jun 2013 23:51:39 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Jun 2013 23:51:39 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 7401282F639; Mon, 24 Jun 2013 23:51:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ahuang@apache.org To: commits@cloudstack.apache.org Date: Mon, 24 Jun 2013 23:52:16 -0000 Message-Id: In-Reply-To: <6053f9ef3d3046c9b32fcf382af8d360@git.apache.org> References: <6053f9ef3d3046c9b32fcf382af8d360@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [40/50] [abbrv] merge is complete http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7b7db056/server/src/com/cloud/network/NetworkServiceImpl.java ---------------------------------------------------------------------- diff --cc server/src/com/cloud/network/NetworkServiceImpl.java index 1897ef6,5e900bb..cfb870d --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@@ -1281,10 -1298,14 +1283,14 @@@ public class NetworkServiceImpl extend throw new InvalidParameterValueException("Unable to find specified NetworkACL"); } + if(aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) { + //ACL is not default DENY/ALLOW + // ACL should be associated with a VPC - if(!vpcId.equals(acl.getVpcId())){ - throw new InvalidParameterValueException("ACL: "+aclId+" do not belong to the VPC"); - } + if(!vpcId.equals(acl.getVpcId())){ + throw new InvalidParameterValueException("ACL: "+aclId+" do not belong to the VPC"); } } ++ } network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, aclId, caller, displayNetwork); } else { @@@ -2476,11 -2497,11 +2482,11 @@@ addDefaultVpcVirtualRouterToPhysicalNetwork(pNetwork.getId()); // add baremetal as the defualt network service provider - /* addDefaultBaremetalProvidersToPhysicalNetwork(pNetwork.getId()); */ + addDefaultBaremetalProvidersToPhysicalNetwork(pNetwork.getId()); - + //Add Internal Load Balancer element as a default network service provider addDefaultInternalLbProviderToPhysicalNetwork(pNetwork.getId()); - + txn.commit(); return pNetwork; } catch (Exception ex) { @@@ -3013,27 -3037,48 +3022,48 @@@ List vlanTokens = getVlanFromRange(guestVlanMap.getGuestVlanRange()); int dedicatedStartVlan = vlanTokens.get(0).intValue(); int dedicatedEndVlan = vlanTokens.get(1).intValue(); - guestVlanMapId = guestVlanMap.getId(); - guestVlanMapAccountId = guestVlanMap.getAccountId(); - - // Verify if range is already dedicated - if (startVlan >= dedicatedStartVlan && endVlan <= dedicatedEndVlan) { - if (guestVlanMap.getAccountId() != vlanOwner.getAccountId()) { - throw new InvalidParameterValueException("Vlan range is already dedicated to another account. Cannot dedicate guest vlan range " + vlan); - } else { - s_logger.debug("Vlan range " + vlan +" is already dedicated to the specified account" + accountName); - return guestVlanMap; + if ((startVlan < dedicatedStartVlan & endVlan >= dedicatedStartVlan) || + (startVlan >= dedicatedStartVlan & startVlan <= dedicatedEndVlan)) { + throw new InvalidParameterValueException("Vlan range is already dedicated. Cannot" + + " dedicate guest vlan range " + vlan); + } } - // Verify if range overlaps with an existing range - if (startVlan < dedicatedStartVlan & endVlan+1 >= dedicatedStartVlan & endVlan <= dedicatedEndVlan) { // extend to the left - updatedVlanRange = startVlan + "-" + dedicatedEndVlan; - } + + // Sort the existing dedicated vlan ranges + Collections.sort(guestVlanMaps, new Comparator() { + @Override + public int compare( AccountGuestVlanMapVO obj1 , AccountGuestVlanMapVO obj2) { + List vlanTokens1 = getVlanFromRange(obj1.getGuestVlanRange()); + List vlanTokens2 = getVlanFromRange(obj2.getGuestVlanRange()); + return vlanTokens1.get(0).compareTo(vlanTokens2.get(0)); + } + }); + + // Verify if vlan range extends an already dedicated range + for (int i=0; i < guestVlanMaps.size(); i++) { + guestVlanMapId = guestVlanMaps.get(i).getId(); + guestVlanMapAccountId = guestVlanMaps.get(i).getAccountId(); + List vlanTokens1 = getVlanFromRange(guestVlanMaps.get(i).getGuestVlanRange()); + // Range extends a dedicated vlan range to the left + if (endVlan == (vlanTokens1.get(0).intValue()-1)) { + if(guestVlanMapAccountId == vlanOwnerId) { + updatedVlanRange = startVlan + "-" + vlanTokens1.get(1).intValue(); + } break; - } else if (startVlan >= dedicatedStartVlan & startVlan-1 <= dedicatedEndVlan & endVlan > dedicatedEndVlan) { // extend to right - updatedVlanRange = dedicatedStartVlan + "-" + endVlan; + } + // Range extends a dedicated vlan range to the right + if (startVlan == (vlanTokens1.get(1).intValue()+1) & guestVlanMapAccountId == vlanOwnerId) { + if (i != (guestVlanMaps.size()-1)) { + List vlanTokens2 = getVlanFromRange(guestVlanMaps.get(i+1).getGuestVlanRange()); + // Range extends 2 vlan ranges, both to the right and left + if (endVlan == (vlanTokens2.get(0).intValue()-1) & guestVlanMaps.get(i+1).getAccountId() == vlanOwnerId) { + _datacneter_vnet.releaseDedicatedGuestVlans(guestVlanMaps.get(i+1).getId()); + _accountGuestVlanMapDao.remove(guestVlanMaps.get(i+1).getId()); + updatedVlanRange = vlanTokens1.get(0).intValue() + "-" + vlanTokens2.get(1).intValue(); - break; + break; - } else if (startVlan < dedicatedStartVlan & endVlan > dedicatedEndVlan){ // extend to the left and right - updatedVlanRange = startVlan + "-" + endVlan; + } + } + updatedVlanRange = vlanTokens1.get(0).intValue() + "-" + endVlan; break; } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7b7db056/server/src/com/cloud/network/NetworkUsageManagerImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7b7db056/server/src/com/cloud/network/element/CloudZonesNetworkElement.java ---------------------------------------------------------------------- diff --cc server/src/com/cloud/network/element/CloudZonesNetworkElement.java index f5d4268,bdd8e61..4e107a8 --- a/server/src/com/cloud/network/element/CloudZonesNetworkElement.java +++ b/server/src/com/cloud/network/element/CloudZonesNetworkElement.java @@@ -215,7 -217,7 +215,8 @@@ public class CloudZonesNetworkElement e Commands cmds = new Commands(OnError.Continue); if (password != null && nic.isDefaultNic()) { final String encodedPassword = PasswordGenerator.rot13(password); - SavePasswordCommand cmd = new SavePasswordCommand(encodedPassword, nic.getIp4Address(), uservm.getHostName()); - SavePasswordCommand cmd = new SavePasswordCommand(encodedPassword, nic.getIp4Address(), uservm.getVirtualMachine().getHostName(), _networkMgr.getExecuteInSeqNtwkElmtCmd()); ++ SavePasswordCommand cmd = new SavePasswordCommand(encodedPassword, nic.getIp4Address(), uservm.getHostName(), ++ _networkMgr.getExecuteInSeqNtwkElmtCmd()); cmds.addCommand("password", cmd); } String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(uservm.getServiceOfferingId()).getDisplayText(); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7b7db056/server/src/com/cloud/network/firewall/FirewallManagerImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7b7db056/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java ---------------------------------------------------------------------- diff --cc server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index efd247b,5a8cf5d..9bceb32 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@@ -787,19 -788,19 +789,19 @@@ public class VirtualNetworkApplianceMan protected VirtualNetworkApplianceManagerImpl() { } - @Override - public Long convertToId(final String vmName) { - if (!VirtualMachineName.isValidRouterName(vmName, _instance)) { - return null; - } - - return VirtualMachineName.getRouterId(vmName); - } +// @Override +// public Long convertToId(final String vmName) { +// if (!VirtualMachineName.isValidRouterName(vmName, _instance)) { +// return null; +// } +// +// return VirtualMachineName.getRouterId(vmName); +// } - private VmDataCommand generateVmDataCommand(VirtualRouter router, String vmPrivateIpAddress, String userData, + private VmDataCommand generateVmDataCommand(VirtualRouter router, String vmPrivateIpAddress, String userData, String serviceOffering, String zoneName, String guestIpAddress, String vmName, String vmInstanceName, long vmId, String vmUuid, String publicKey, long guestNetworkId) { - VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress, vmName); + VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress, vmName, _networkModel.getExecuteInSeqNtwkElmtCmd()); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(guestNetworkId, router.getId())); @@@ -1606,59 -1598,61 +1603,63 @@@ DomainRouterVO router = null; for (Iterator iter = hypervisors.iterator(); iter.hasNext();) { HypervisorType hType = iter.next(); - s_logger.debug("Allocating the domR with the hypervisor type " + hType); - try { - long id = _routerDao.getNextInSequence(Long.class, "id"); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Allocating the VR i="+ id + " in datacenter " + dest.getDataCenter() + "with the hypervisor type " + hType); - } ++ long id = _routerDao.getNextInSequence(Long.class, "id"); ++ if (s_logger.isDebugEnabled()) { ++ s_logger.debug("Allocating the VR i="+ id + " in datacenter " + dest.getDataCenter() + "with the hypervisor type " + hType); ++ } + - String templateName = null; - switch (hType) { - case XenServer: - templateName = _configServer.getConfigValue(Config.RouterTemplateXen.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); - break; - case KVM: - templateName = _configServer.getConfigValue(Config.RouterTemplateKVM.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); - break; - case VMware: - templateName = _configServer.getConfigValue(Config.RouterTemplateVmware.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); - break; - case Hyperv: - templateName = _configServer.getConfigValue(Config.RouterTemplateHyperv.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); - break; - case LXC: - templateName = _configServer.getConfigValue(Config.RouterTemplateLXC.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); - break; - default: break; - } - VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName); + String templateName = null; + switch (hType) { + case XenServer: + templateName = _configServer.getConfigValue(Config.RouterTemplateXen.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + break; + case KVM: + templateName = _configServer.getConfigValue(Config.RouterTemplateKVM.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + break; + case VMware: + templateName = _configServer + .getConfigValue(Config.RouterTemplateVmware.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + break; + case Hyperv: + templateName = _configServer + .getConfigValue(Config.RouterTemplateHyperv.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + break; + case LXC: + templateName = _configServer.getConfigValue(Config.RouterTemplateLXC.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + break; + default: + break; + } + VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName); - if (template == null) { - s_logger.debug(hType + " won't support system vm, skip it"); - continue; - } - - boolean offerHA = routerOffering.getOfferHA(); - /* We don't provide HA to redundant router VMs, admin should own it all, and redundant router themselves are HA */ - if (isRedundant) { - offerHA = false; - } + if (template == null) { + s_logger.debug(hType + " won't support system vm, skip it"); + continue; + } - router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(), - VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), - template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false, - RedundantState.UNKNOWN, offerHA, false, vpcId); - router.setRole(Role.VIRTUAL_ROUTER); - router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner); - } catch (InsufficientCapacityException ex) { + boolean offerHA = routerOffering.getOfferHA(); + /* We don't provide HA to redundant router VMs, admin should own it all, and redundant router themselves are HA */ + if (isRedundant) { + offerHA = false; + } + + router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(), + VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), + template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false, + RedundantState.UNKNOWN, offerHA, false, vpcId); + router.setRole(Role.VIRTUAL_ROUTER); + router = _routerDao.persist(router); + try { + _itMgr.allocate(router.getInstanceName(), template, routerOffering, networks, plan, null, owner); + } catch (CloudRuntimeException e) { if (allocateRetry < 2 && iter.hasNext()) { - s_logger.debug("Failed to allocate the VR with hypervisor type " + hType + ", retrying one more time"); + _routerDao.remove(router.getId()); + allocateRetry++; + s_logger.debug("Failed to allocate the VR with hypervisor type " + hType + ", retrying one more time: " + e.toString()); continue; - } else { - throw ex; } - } finally { - allocateRetry++; } - + router = _routerDao.findById(router.getId()); if (startRouter) { try { @@@ -2350,8 -2352,9 +2351,9 @@@ cmds.addCommand("getDomRVersion", command); // Network usage command to create iptables rules - boolean forVpc = profile.getVirtualMachine().getVpcId() != null; + boolean forVpc = router.getVpcId() != null; + if (!forVpc) - cmds.addCommand("networkUsage", new NetworkUsageCommand(controlNic.getIp4Address(), router.getHostName(), "create", forVpc)); + cmds.addCommand("networkUsage", new NetworkUsageCommand(controlNic.getIp4Address(), router.getHostName(), "create", forVpc)); } protected void finalizeUserDataAndDhcpOnStart(Commands cmds, DomainRouterVO router, Provider provider, Long guestNetworkId) { @@@ -3346,7 -3358,7 +3349,7 @@@ // password should be set only on default network element if (password != null && nic.isDefaultNic()) { String encodedPassword = PasswordGenerator.rot13(password); -- // We would unset password for BACKUP router in the RvR, to prevent user from accidently reset the ++ // We would unset password for BACKUP router in the RvR, to prevent user from accidently reset the // password again after BACKUP become MASTER if (router.getIsRedundantRouter() && router.getRedundantState() != RedundantState.MASTER) { encodedPassword = PasswordGenerator.rot13("saved_password"); @@@ -3390,9 -3401,9 +3393,9 @@@ } } } - + private void createDhcpEntryCommand(VirtualRouter router, UserVm vm, NicVO nic, Commands cmds) { - DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), vm.getHostName(), nic.getIp6Address()); + DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), vm.getHostName(), nic.getIp6Address(), _networkModel.getExecuteInSeqNtwkElmtCmd()); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); Nic defaultNic = findGatewayIp(vm.getId()); String gatewayIp = defaultNic.getGateway(); @@@ -3675,14 -3691,13 +3685,13 @@@ rulesTO = new ArrayList(); for (FirewallRule rule : rules) { FirewallRule.TrafficType traffictype = rule.getTrafficType(); - if(traffictype == FirewallRule.TrafficType.Ingress){ + if (traffictype == FirewallRule.TrafficType.Ingress) { IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId()); - FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, sourceIp.getAddress().addr(),Purpose.Firewall,traffictype); + FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, sourceIp.getAddress().addr(), Purpose.Firewall, traffictype); rulesTO.add(ruleTO); - } - else if (rule.getTrafficType() == FirewallRule.TrafficType.Egress) { - assert (rule.getSourceIpAddressId() == null) : "ipAddressId should be null for egress firewall rule. "; - FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, "", Purpose.Firewall, traffictype); + } else if (rule.getTrafficType() == FirewallRule.TrafficType.Egress){ + assert (rule.getSourceIpAddressId()==null) : "ipAddressId should be null for egress firewall rule. "; + FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null,"",Purpose.Firewall, traffictype); rulesTO.add(ruleTO); } } @@@ -3861,7 -3888,9 +3880,7 @@@ } @Override - public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance) throws ConnectionException { + public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException { - UserContext context = UserContext.current(); - context.setAccountId(1); List routers = _routerDao.listIsolatedByHostId(host.getId()); for (DomainRouterVO router : routers) { if (router.isStopPending()) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7b7db056/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7b7db056/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7b7db056/server/src/com/cloud/network/vpc/VpcManagerImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7b7db056/server/src/com/cloud/resource/ResourceManagerImpl.java ---------------------------------------------------------------------- diff --cc server/src/com/cloud/resource/ResourceManagerImpl.java index effc4e0,fe91cb3..757843c --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@@ -47,9 -45,11 +47,10 @@@ import org.apache.cloudstack.api.comman import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd; import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd; import org.apache.cloudstack.api.command.admin.swift.ListSwiftsCmd; +import org.apache.cloudstack.context.CallContext; + import org.apache.cloudstack.region.dao.RegionDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; import com.cloud.agent.AgentManager.TapAgentsAction; @@@ -169,32 -167,32 +170,31 @@@ import com.cloud.vm.dao.VMInstanceDao @Component @Local({ ResourceManager.class, ResourceService.class }) - public class ResourceManagerImpl extends ManagerBase implements ResourceManager, ResourceService, - Manager { - private static final Logger s_logger = Logger - .getLogger(ResourceManagerImpl.class); + public class ResourceManagerImpl extends ManagerBase implements ResourceManager, ResourceService, Manager { + private static final Logger s_logger = Logger.getLogger(ResourceManagerImpl.class); @Inject - AccountManager _accountMgr; + AccountManager _accountMgr; @Inject - AgentManager _agentMgr; + AgentManager _agentMgr; @Inject - StorageManager _storageMgr; + StorageManager _storageMgr; @Inject - protected SecondaryStorageVmManager _secondaryStorageMgr; + protected SecondaryStorageVmManager _secondaryStorageMgr; - + @Inject + protected RegionDao _regionDao; @Inject - protected DataCenterDao _dcDao; + protected DataCenterDao _dcDao; @Inject - protected HostPodDao _podDao; + protected HostPodDao _podDao; @Inject - protected ClusterDetailsDao _clusterDetailsDao; + protected ClusterDetailsDao _clusterDetailsDao; @Inject - protected ClusterDao _clusterDao; + protected ClusterDao _clusterDao; @Inject - protected CapacityDao _capacityDao; + protected CapacityDao _capacityDao; @Inject - protected HostDao _hostDao; + protected HostDao _hostDao; @Inject protected SwiftManager _swiftMgr; @Inject @@@ -229,34 -225,38 +229,38 @@@ protected DedicatedResourceDao _dedicatedDao; protected List _discoverers; + public List getDiscoverers() { - return _discoverers; - } + return _discoverers; + } + - public void setDiscoverers(List _discoverers) { - this._discoverers = _discoverers; - } + public void setDiscoverers(List _discoverers) { + this._discoverers = _discoverers; + } + @Inject + protected ClusterManager _clusterMgr; @Inject - protected ClusterManager _clusterMgr; - @Inject - protected StoragePoolHostDao _storagePoolHostDao; + protected StoragePoolHostDao _storagePoolHostDao; - protected List _podAllocators; + protected List _podAllocators; + public List getPodAllocators() { - return _podAllocators; - } + return _podAllocators; + } + - public void setPodAllocators(List _podAllocators) { - this._podAllocators = _podAllocators; - } + public void setPodAllocators(List _podAllocators) { + this._podAllocators = _podAllocators; + } + @Inject + protected VMTemplateDao _templateDao; @Inject - protected VMTemplateDao _templateDao; - @Inject - protected ConfigurationManager _configMgr; + protected ConfigurationManager _configMgr; @Inject - protected ClusterVSMMapDao _clusterVSMMapDao; + protected ClusterVSMMapDao _clusterVSMMapDao; - protected long _nodeId = ManagementServerNode.getManagementServerId(); + protected long _nodeId = ManagementServerNode.getManagementServerId(); protected HashMap _resourceStateAdapters = new HashMap(); @@@ -404,11 -387,10 +391,10 @@@ throw ex; } - Account account = UserContext.current().getCaller(); + Account account = CallContext.current().getCallingAccount(); - if (Grouping.AllocationState.Disabled == zone.getAllocationState() - && !_accountMgr.isRootAdmin(account.getType())) { + if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) { - PermissionDeniedException ex = new PermissionDeniedException( - "Cannot perform this operation, Zone with specified id is currently disabled"); + PermissionDeniedException ex = new PermissionDeniedException( + "Cannot perform this operation, Zone with specified id is currently disabled"); ex.addProxyObject(zone.getUuid(), "dcId"); throw ex; } @@@ -510,9 -478,8 +482,8 @@@ cluster = _clusterDao.persist(cluster); } catch (Exception e) { // no longer tolerate exception during the cluster creation phase - CloudRuntimeException ex = new CloudRuntimeException( - "Unable to create cluster " + clusterName + CloudRuntimeException ex = new CloudRuntimeException("Unable to create cluster " + clusterName - + " in pod and data center with specified ids", e); + + " in pod and data center with specified ids", e); // Get the pod VO object's table name. ex.addProxyObject(pod.getUuid(), "podId"); ex.addProxyObject(zone.getUuid(), "dcId"); @@@ -576,16 -535,14 +539,14 @@@ List hosts = new ArrayList(); Map> resources = null; - resources = discoverer.find(dcId, podId, clusterId, uri, username, - password, null); + resources = discoverer.find(dcId, podId, clusterId, uri, username, password, null); if (resources != null) { - for (Map.Entry> entry : resources - .entrySet()) { + for (Map.Entry> entry : resources.entrySet()) { ServerResource resource = entry.getKey(); - // For Hyper-V, we are here means agent have already started - // and connected to management server + // For Hyper-V, we are here means agent have already started + // and connected to management server if (hypervisorType == Hypervisor.HypervisorType.Hyperv) { break; } @@@ -614,12 -569,11 +573,11 @@@ } @Override - public Discoverer getMatchingDiscover( - Hypervisor.HypervisorType hypervisorType) { + public Discoverer getMatchingDiscover(Hypervisor.HypervisorType hypervisorType) { - for (Discoverer discoverer : _discoverers) { - if (discoverer.getHypervisorType() == hypervisorType) + for (Discoverer discoverer : _discoverers) { + if (discoverer.getHypervisorType() == hypervisorType) return discoverer; - } + } return null; } @@@ -636,8 -588,7 +592,7 @@@ String password = cmd.getPassword(); List hostTags = cmd.getHostTags(); - dcId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current() - .getCallingAccount(), dcId); - dcId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), dcId); ++ dcId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), dcId); // this is for standalone option if (clusterName == null && clusterId == null) { @@@ -668,9 -620,8 +624,8 @@@ } @Override - public List discoverHosts(AddSecondaryStorageCmd cmd) - throws IllegalArgumentException, DiscoveryException, + public List discoverHosts(AddSecondaryStorageCmd cmd) throws IllegalArgumentException, DiscoveryException, - InvalidParameterValueException { + InvalidParameterValueException { Long dcId = cmd.getZoneId(); String url = cmd.getUrl(); return discoverHostsFull(dcId, null, null, null, url, null, null, "SecondaryStorage", null, null, false); @@@ -694,25 -645,25 +649,25 @@@ @Override public List listS3s(final ListS3sCmd cmd) { - return this._s3Mgr.listS3s(cmd); + return _s3Mgr.listS3s(cmd); } - private List discoverHostsFull(Long dcId, Long podId, Long clusterId, String clusterName, String url, String username, String password, String hypervisorType, List hostTags, - Map params, boolean deferAgentCreation) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException { + + private List discoverHostsFull(Long dcId, Long podId, Long clusterId, String clusterName, String url, String username, String password, + String hypervisorType, List hostTags, Map params, boolean deferAgentCreation) throws IllegalArgumentException, + DiscoveryException, InvalidParameterValueException { URI uri = null; // Check if the zone exists in the system DataCenterVO zone = _dcDao.findById(dcId); if (zone == null) { - throw new InvalidParameterValueException("Can't find zone by id " - + dcId); + throw new InvalidParameterValueException("Can't find zone by id " + dcId); } - Account account = UserContext.current().getCaller(); + Account account = CallContext.current().getCallingAccount(); - if (Grouping.AllocationState.Disabled == zone.getAllocationState() - && !_accountMgr.isRootAdmin(account.getType())) { + if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) { - PermissionDeniedException ex = new PermissionDeniedException( - "Cannot perform this operation, Zone with specified id is currently disabled"); + PermissionDeniedException ex = new PermissionDeniedException( + "Cannot perform this operation, Zone with specified id is currently disabled"); ex.addProxyObject(zone.getUuid(), "dcId"); throw ex; } @@@ -755,23 -702,20 +706,20 @@@ if (clusterId != null) { if (_clusterDao.findById(clusterId) == null) { - throw new InvalidParameterValueException( - "Can't find cluster by id " + clusterId); + throw new InvalidParameterValueException("Can't find cluster by id " + clusterId); - } + } - if (hypervisorType.equalsIgnoreCase(HypervisorType.VMware - .toString())) { + if (hypervisorType.equalsIgnoreCase(HypervisorType.VMware.toString())) { - // VMware only allows adding host to an existing cluster, as we - // already have a lot of information - // in cluster object, to simplify user input, we will construct - // neccessary information here - Map clusterDetails = this._clusterDetailsDao.findDetails(clusterId); + // VMware only allows adding host to an existing cluster, as we + // already have a lot of information + // in cluster object, to simplify user input, we will construct + // neccessary information here - Map clusterDetails = _clusterDetailsDao - .findDetails(clusterId); ++ Map clusterDetails = _clusterDetailsDao.findDetails(clusterId); username = clusterDetails.get("username"); - assert (username != null); + assert (username != null); password = clusterDetails.get("password"); - assert (password != null); + assert (password != null); try { uri = new URI(UriUtils.encodeURIComponent(url)); @@@ -808,11 -750,11 +754,11 @@@ } } clusterId = cluster.getId(); - if (_clusterDetailsDao.findDetail(clusterId,"cpuOvercommitRatio") == null) { - ClusterDetailsVO cluster_cpu_detail = new ClusterDetailsVO(clusterId,"cpuOvercommitRatio","1"); - ClusterDetailsVO cluster_memory_detail = new ClusterDetailsVO(clusterId,"memoryOvercommitRatio","1"); + if (_clusterDetailsDao.findDetail(clusterId, "cpuOvercommitRatio") == null) { + ClusterDetailsVO cluster_cpu_detail = new ClusterDetailsVO(clusterId, "cpuOvercommitRatio", "1"); + ClusterDetailsVO cluster_memory_detail = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", "1"); - _clusterDetailsDao.persist(cluster_cpu_detail); - _clusterDetailsDao.persist(cluster_memory_detail); + _clusterDetailsDao.persist(cluster_cpu_detail); + _clusterDetailsDao.persist(cluster_memory_detail); } } @@@ -836,10 -773,9 +777,9 @@@ } List hosts = new ArrayList(); - s_logger.info("Trying to add a new host at " + url + " in data center " - + dcId); + s_logger.info("Trying to add a new host at " + url + " in data center " + dcId); boolean isHypervisorTypeSupported = false; - for (Discoverer discoverer : _discoverers) { + for (Discoverer discoverer : _discoverers) { if (params != null) { discoverer.putParam(params); } @@@ -850,43 -786,35 +790,35 @@@ isHypervisorTypeSupported = true; Map> resources = null; - processResourceEvent(ResourceListener.EVENT_DISCOVER_BEFORE, dcId, - podId, clusterId, uri, username, password, hostTags); + processResourceEvent(ResourceListener.EVENT_DISCOVER_BEFORE, dcId, podId, clusterId, uri, username, password, hostTags); try { - resources = discoverer.find(dcId, podId, clusterId, uri, - username, password, hostTags); + resources = discoverer.find(dcId, podId, clusterId, uri, username, password, hostTags); - } catch (DiscoveryException e) { + } catch (DiscoveryException e) { throw e; } catch (Exception e) { - s_logger.info("Exception in host discovery process with discoverer: " - + discoverer.getName() + s_logger.info("Exception in host discovery process with discoverer: " + discoverer.getName() - + ", skip to another discoverer if there is any"); + + ", skip to another discoverer if there is any"); } - processResourceEvent(ResourceListener.EVENT_DISCOVER_AFTER, - resources); + processResourceEvent(ResourceListener.EVENT_DISCOVER_AFTER, resources); if (resources != null) { - for (Map.Entry> entry : resources - .entrySet()) { + for (Map.Entry> entry : resources.entrySet()) { ServerResource resource = entry.getKey(); /* - * For KVM, if we go to here, that means kvm agent is - * already connected to mgt svr. + * For KVM, if we go to here, that means kvm agent is + * already connected to mgt svr. */ if (resource instanceof KvmDummyResourceBase) { Map details = entry.getValue(); String guid = details.get("guid"); - List kvmHosts = listAllUpAndEnabledHosts( - Host.Type.Routing, clusterId, podId, dcId); + List kvmHosts = listAllUpAndEnabledHosts(Host.Type.Routing, clusterId, podId, dcId); for (HostVO host : kvmHosts) { if (host.getGuid().equalsIgnoreCase(guid)) { - if (hostTags != null) { - if (s_logger.isTraceEnabled()) { + if (hostTags != null) { + if (s_logger.isTraceEnabled()) { - s_logger.trace("Adding Host Tags for KVM host, tags: :" - + hostTags); + s_logger.trace("Adding Host Tags for KVM host, tags: :" + hostTags); } - _hostTagsDao - .persist(host.getId(), hostTags); + _hostTagsDao.persist(host.getId(), hostTags); } hosts.add(host); return hosts; @@@ -928,42 -854,33 +858,33 @@@ } @DB - protected boolean doDeleteHost(long hostId, boolean isForced, - boolean isForceDeleteStorage) { - User caller = _accountMgr.getActiveUser(CallContext.current() - .getCallingUserId()); + protected boolean doDeleteHost(long hostId, boolean isForced, boolean isForceDeleteStorage) { - User caller = _accountMgr.getActiveUser(UserContext.current().getCallerUserId()); ++ User caller = _accountMgr.getActiveUser(CallContext.current().getCallingUserId()); // Verify that host exists HostVO host = _hostDao.findById(hostId); if (host == null) { - throw new InvalidParameterValueException("Host with id " + hostId - + " doesn't exist"); + throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist"); } - _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current() - .getCallingAccount(), host.getDataCenterId()); - _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), host.getDataCenterId()); ++ _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), host.getDataCenterId()); /* - * TODO: check current agent status and updateAgentStatus to removed. If - * it was already removed, that means someone is deleting host - * concurrently, return. And consider the situation of CloudStack - * shutdown during delete. A global lock? + * TODO: check current agent status and updateAgentStatus to removed. If + * it was already removed, that means someone is deleting host + * concurrently, return. And consider the situation of CloudStack + * shutdown during delete. A global lock? */ - AgentAttache attache = _agentMgr.findAttache(hostId); - // Get storage pool host mappings here because they can be removed as a - // part of handleDisconnect later - // TODO: find out the bad boy, what's a buggy logic! + AgentAttache attache = _attacheHandler.findAttache(hostId); + // Get storage pool host mappings here because they can be removed as a + // part of handleDisconnect later + // TODO: find out the bad boy, what's a buggy logic! - List pools = _storagePoolHostDao - .listByHostIdIncludingRemoved(hostId); + List pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId); - ResourceStateAdapter.DeleteHostAnswer answer = (ResourceStateAdapter.DeleteHostAnswer) dispatchToStateAdapters( + ResourceStateAdapter.DeleteHostAnswer answer = (ResourceStateAdapter.DeleteHostAnswer) dispatchToStateAdapters( - ResourceStateAdapter.Event.DELETE_HOST, false, host, - new Boolean(isForced), new Boolean(isForceDeleteStorage)); + ResourceStateAdapter.Event.DELETE_HOST, false, host, new Boolean(isForced), new Boolean(isForceDeleteStorage)); if (answer == null) { - throw new CloudRuntimeException( - "No resource adapter respond to DELETE_HOST event for " - + host.getName() + " id = " + hostId - + ", hypervisorType is " + host.getHypervisorType() - + ", host type is " + host.getType()); + throw new CloudRuntimeException("No resource adapter respond to DELETE_HOST event for " + host.getName() + " id = " + hostId + + ", hypervisorType is " + host.getHypervisorType() + ", host type is " + host.getType()); } if (answer.getIsException()) { @@@ -1082,37 -987,29 +991,29 @@@ List hosts = listAllHostsInCluster(cmd.getId()); if (hosts.size() > 0) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Cluster: " + cmd.getId() - + " still has hosts, can't remove"); + s_logger.debug("Cluster: " + cmd.getId() + " still has hosts, can't remove"); } txn.rollback(); - throw new CloudRuntimeException("Cluster: " + cmd.getId() - + " cannot be removed. Cluster still has hosts"); + throw new CloudRuntimeException("Cluster: " + cmd.getId() + " cannot be removed. Cluster still has hosts"); } - // don't allow to remove the cluster if it has non-removed storage - // pools + // don't allow to remove the cluster if it has non-removed storage + // pools - List storagePools = _storagePoolDao - .listPoolsByCluster(cmd.getId()); + List storagePools = _storagePoolDao.listPoolsByCluster(cmd.getId()); if (storagePools.size() > 0) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Cluster: " + cmd.getId() - + " still has storage pools, can't remove"); + s_logger.debug("Cluster: " + cmd.getId() + " still has storage pools, can't remove"); } txn.rollback(); - throw new CloudRuntimeException("Cluster: " + cmd.getId() - + " cannot be removed. Cluster still has storage pools"); + throw new CloudRuntimeException("Cluster: " + cmd.getId() + " cannot be removed. Cluster still has storage pools"); } - if (_clusterDao.remove(cmd.getId())) { + if (_clusterDao.remove(cmd.getId())) { _capacityDao.removeBy(null, null, null, cluster.getId(), null); - // If this cluster is of type vmware, and if the nexus vswitch - // global parameter setting is turned + // If this cluster is of type vmware, and if the nexus vswitch + // global parameter setting is turned // on, remove the row in cluster_vsm_map for this cluster id. - if (hypervisorType == HypervisorType.VMware - && Boolean.parseBoolean(_configDao - .getValue(Config.VmwareUseNexusVSwitch - .toString()))) { + if (hypervisorType == HypervisorType.VMware && Boolean.parseBoolean(_configDao.getValue(Config.VmwareUseNexusVSwitch.toString()))) { _clusterVSMMapDao.removeByClusterId(cmd.getId()); } // remove from dedicated resources @@@ -1255,21 -1133,13 +1137,13 @@@ cluster.setManagedState(Managed.ManagedState.PrepareUnmanaged); _clusterDao.update(cluster.getId(), cluster); txn.commit(); - List hosts = listAllUpAndEnabledHosts( - Host.Type.Routing, cluster.getId(), - cluster.getPodId(), cluster.getDataCenterId()); + List hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId()); - for (HostVO host : hosts) { + for (HostVO host : hosts) { - if (host.getType().equals(Host.Type.Routing) - && !host.getStatus().equals(Status.Down) - && !host.getStatus() - .equals(Status.Disconnected) - && !host.getStatus().equals(Status.Up) + if (host.getType().equals(Host.Type.Routing) && !host.getStatus().equals(Status.Down) + && !host.getStatus().equals(Status.Disconnected) && !host.getStatus().equals(Status.Up) - && !host.getStatus().equals(Status.Alert)) { + && !host.getStatus().equals(Status.Alert)) { - String msg = "host " + host.getPrivateIpAddress() - + " should not be in " - + host.getStatus().toString() + " status"; - throw new CloudRuntimeException( - "PrepareUnmanaged Failed due to " + msg); + String msg = "host " + host.getPrivateIpAddress() + " should not be in " + host.getStatus().toString() + " status"; + throw new CloudRuntimeException("PrepareUnmanaged Failed due to " + msg); } } @@@ -1286,13 -1156,9 +1160,9 @@@ Thread.sleep(5 * 1000); } catch (Exception e) { } - hosts = listAllUpAndEnabledHosts(Host.Type.Routing, - cluster.getId(), cluster.getPodId(), - cluster.getDataCenterId()); + hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId()); - for (HostVO host : hosts) { + for (HostVO host : hosts) { - if (!host.getStatus().equals(Status.Down) - && !host.getStatus().equals( - Status.Disconnected) + if (!host.getStatus().equals(Status.Down) && !host.getStatus().equals(Status.Disconnected) && !host.getStatus().equals(Status.Alert)) { lsuccess = false; break; @@@ -1368,27 -1227,20 +1231,20 @@@ ResourceState currentState = host.getResourceState(); ResourceState nextState = currentState.getNextState(event); if (nextState == null) { - throw new NoTransitionException( - "No next resource state found for current state =" - + currentState + " event =" + event); + throw new NoTransitionException("No next resource state found for current state =" + currentState + " event =" + event); } - // TO DO - Make it more granular and have better conversion into - // capacity type + // TO DO - Make it more granular and have better conversion into + // capacity type - if (host.getType() == Type.Routing && host.getClusterId() != null) { + if (host.getType() == Type.Routing && host.getClusterId() != null) { - AllocationState capacityState = _configMgr - .findClusterAllocationState(ApiDBUtils.findClusterById(host - .getClusterId())); - if (capacityState == AllocationState.Enabled - && nextState != ResourceState.Enabled) { + AllocationState capacityState = _configMgr.findClusterAllocationState(ApiDBUtils.findClusterById(host.getClusterId())); + if (capacityState == AllocationState.Enabled && nextState != ResourceState.Enabled) { capacityState = AllocationState.Disabled; } - _capacityDao.updateCapacityState(null, null, null, host.getId(), - capacityState.toString()); + _capacityDao.updateCapacityState(null, null, null, host.getId(), capacityState.toString()); } - return _hostDao.updateResourceState(currentState, event, nextState, - host); + return _hostDao.updateResourceState(currentState, event, nextState, host); } private boolean doMaintain(final long hostId) { @@@ -1453,17 -1299,12 +1303,12 @@@ if (host == null) { s_logger.debug("Unable to find host " + hostId); - throw new InvalidParameterValueException( - "Unable to find host with ID: " + hostId - + ". Please specify a valid host ID."); + throw new InvalidParameterValueException("Unable to find host with ID: " + hostId + ". Please specify a valid host ID."); } - if (_hostDao.countBy(host.getClusterId(), - ResourceState.PrepareForMaintenance, - ResourceState.ErrorInMaintenance) > 0) { - throw new InvalidParameterValueException( - "There are other servers in PrepareForMaintenance OR ErrorInMaintenance STATUS in cluster " + if (_hostDao.countBy(host.getClusterId(), ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance) > 0) { + throw new InvalidParameterValueException("There are other servers in PrepareForMaintenance OR ErrorInMaintenance STATUS in cluster " - + host.getClusterId()); + + host.getClusterId()); } if (_storageMgr.isLocalStorageActiveOnHost(host.getId())) { @@@ -2016,15 -1799,9 +1803,9 @@@ } } - host = createHostVO( - cmds, - resource, - details, - hostTags, - ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT); + host = createHostVO(cmds, resource, details, hostTags, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT); if (host != null) { - attache = _attacheHandler.handleDirectConnectAgent(host, cmds, - resource, forRebalance); - attache = _agentMgr.handleDirectConnectAgent(host, cmds, resource, forRebalance); ++ attache = _attacheHandler.handleDirectConnectAgent(host, cmds, resource, forRebalance); /* reload myself from database */ host = _hostDao.findById(host.getId()); } @@@ -2107,8 -1908,10 +1912,10 @@@ } if (host != null) { - if (!deferAgentCreation) { // if first host in cluster then create agent otherwise defer it to scan task + if (!deferAgentCreation) { // if first host in cluster then + // create agent otherwise defer it to + // scan task - attache = _agentMgr.handleDirectConnectAgent(host, cmds, resource, forRebalance); + attache = _attacheHandler.handleDirectConnectAgent(host, cmds, resource, forRebalance); host = _hostDao.findById(host.getId()); // reload } else { host = _hostDao.findById(host.getId()); // reload @@@ -2156,12 -1960,10 +1964,10 @@@ } @Override - public Host createHostAndAgent(Long hostId, ServerResource resource, - Map details, boolean old, List hostTags, + public Host createHostAndAgent(Long hostId, ServerResource resource, Map details, boolean old, List hostTags, - boolean forRebalance) { + boolean forRebalance) { _agentMgr.tapLoadingAgents(hostId, TapAgentsAction.Add); - Host host = createHostAndAgent(resource, details, old, hostTags, - forRebalance); + Host host = createHostAndAgent(resource, details, old, hostTags, forRebalance); _agentMgr.tapLoadingAgents(hostId, TapAgentsAction.Del); return host; } @@@ -2177,7 -1977,7 +1981,7 @@@ Map details = hostDetails; String guid = details.get("guid"); - List currentHosts = listAllUpAndEnabledHostsInOneZoneByType(hostType, zoneId); - List currentHosts = this.listAllUpAndEnabledHostsInOneZoneByType(hostType, zoneId); ++ List currentHosts = listAllUpAndEnabledHostsInOneZoneByType(hostType, zoneId); for (HostVO currentHost : currentHosts) { if (currentHost.getGuid().equals(guid)) { return currentHost; @@@ -2200,23 -1998,16 +2002,16 @@@ // a host-only private network. Don't check for conflicts with the // private IP address table. if (serverPrivateIP != serverPublicIP) { - if (!_privateIPAddressDao.mark(dc.getId(), pod.getId(), - serverPrivateIP)) { + if (!_privateIPAddressDao.mark(dc.getId(), pod.getId(), serverPrivateIP)) { // If the server's private IP address is already in the // database, return false - List existingPrivateIPs = _privateIPAddressDao - .listByPodIdDcIdIpAddress(pod.getId(), dc.getId(), + List existingPrivateIPs = _privateIPAddressDao.listByPodIdDcIdIpAddress(pod.getId(), dc.getId(), - serverPrivateIP); + serverPrivateIP); - assert existingPrivateIPs.size() <= 1 : " How can we get more than one ip address with " - + serverPrivateIP; + assert existingPrivateIPs.size() <= 1 : " How can we get more than one ip address with " + serverPrivateIP; if (existingPrivateIPs.size() > 1) { - throw new IllegalArgumentException( - "The private ip address of the server (" - + serverPrivateIP - + ") is already in use in pod: " - + pod.getName() + " and zone: " - + dc.getName()); + throw new IllegalArgumentException("The private ip address of the server (" + serverPrivateIP + ") is already in use in pod: " + + pod.getName() + " and zone: " + dc.getName()); } if (existingPrivateIPs.size() == 1) { DataCenterIpAddressVO vo = existingPrivateIPs.get(0); @@@ -2232,33 -2019,23 +2023,23 @@@ } } - if (serverPublicIP != null - && !_publicIPAddressDao - .mark(dc.getId(), new Ip(serverPublicIP))) { + if (serverPublicIP != null && !_publicIPAddressDao.mark(dc.getId(), new Ip(serverPublicIP))) { // If the server's public IP address is already in the database, // return false - List existingPublicIPs = _publicIPAddressDao - .listByDcIdIpAddress(dc.getId(), serverPublicIP); + List existingPublicIPs = _publicIPAddressDao.listByDcIdIpAddress(dc.getId(), serverPublicIP); if (existingPublicIPs.size() > 0) { - throw new IllegalArgumentException( - "The public ip address of the server (" - + serverPublicIP - + ") is already in use in zone: " + throw new IllegalArgumentException("The public ip address of the server (" + serverPublicIP + ") is already in use in zone: " - + dc.getName()); + + dc.getName()); } } } @Override - public HostVO fillRoutingHostVO(HostVO host, StartupRoutingCommand ssCmd, - HypervisorType hyType, Map details, + public HostVO fillRoutingHostVO(HostVO host, StartupRoutingCommand ssCmd, HypervisorType hyType, Map details, - List hostTags) { + List hostTags) { if (host.getPodId() == null) { - s_logger.error("Host " + ssCmd.getPrivateIpAddress() - + " sent incorrect pod, pod id is null"); - throw new IllegalArgumentException("Host " - + ssCmd.getPrivateIpAddress() - + " sent incorrect pod, pod id is null"); + s_logger.error("Host " + ssCmd.getPrivateIpAddress() + " sent incorrect pod, pod id is null"); + throw new IllegalArgumentException("Host " + ssCmd.getPrivateIpAddress() + " sent incorrect pod, pod id is null"); } ClusterVO clusterVO = _clusterDao.findById(host.getClusterId()); @@@ -2305,49 -2074,35 +2078,35 @@@ } if (s_logger.isDebugEnabled()) { - s_logger.debug("Deleting Host: " + host.getId() + " Guid:" - + host.getGuid()); + s_logger.debug("Deleting Host: " + host.getId() + " Guid:" + host.getGuid()); } - User caller = _accountMgr.getActiveUser(CallContext.current() - .getCallingUserId()); - User caller = _accountMgr.getActiveUser(UserContext.current().getCallerUserId()); ++ User caller = _accountMgr.getActiveUser(CallContext.current().getCallingUserId()); - if (forceDestroyStorage) { - // put local storage into mainenance mode, will set all the VMs on - // this local storage into stopped state + if (forceDestroyStorage) { + // put local storage into mainenance mode, will set all the VMs on + // this local storage into stopped state - StoragePoolVO storagePool = _storageMgr.findLocalStorageOnHost(host - .getId()); + StoragePoolVO storagePool = _storageMgr.findLocalStorageOnHost(host.getId()); if (storagePool != null) { - if (storagePool.getStatus() == StoragePoolStatus.Up - || storagePool.getStatus() == StoragePoolStatus.ErrorInMaintenance) { + if (storagePool.getStatus() == StoragePoolStatus.Up || storagePool.getStatus() == StoragePoolStatus.ErrorInMaintenance) { - try { + try { - StoragePool pool = _storageSvr - .preparePrimaryStorageForMaintenance(storagePool - .getId()); + StoragePool pool = _storageSvr.preparePrimaryStorageForMaintenance(storagePool.getId()); - if (pool == null) { - s_logger.debug("Failed to set primary storage into maintenance mode"); + if (pool == null) { + s_logger.debug("Failed to set primary storage into maintenance mode"); - throw new UnableDeleteHostException( - "Failed to set primary storage into maintenance mode"); + throw new UnableDeleteHostException("Failed to set primary storage into maintenance mode"); } } catch (Exception e) { - s_logger.debug("Failed to set primary storage into maintenance mode, due to: " - + e.toString()); - throw new UnableDeleteHostException( - "Failed to set primary storage into maintenance mode, due to: " - + e.toString()); + s_logger.debug("Failed to set primary storage into maintenance mode, due to: " + e.toString()); + throw new UnableDeleteHostException("Failed to set primary storage into maintenance mode, due to: " + e.toString()); } } - List vmsOnLocalStorage = _storageMgr - .listByStoragePool(storagePool.getId()); + List vmsOnLocalStorage = _storageMgr.listByStoragePool(storagePool.getId()); for (VMInstanceVO vm : vmsOnLocalStorage) { try { - if (!_vmMgr.destroy(vm, caller, _accountMgr.getAccount(vm.getAccountId()))) { + if (!_vmMgr.destroy(vm.getUuid())) { - String errorMsg = "There was an error Destory the vm: " - + vm - + " as a part of hostDelete id=" - + host.getId(); + String errorMsg = "There was an error Destory the vm: " + vm + " as a part of hostDelete id=" + host.getId(); s_logger.warn(errorMsg); throw new UnableDeleteHostException(errorMsg); } @@@ -2369,28 -2121,21 +2125,17 @@@ // Stop HA disabled vms and HA enabled vms in Stopping state // Restart HA enabled vms for (VMInstanceVO vm : vms) { - if (!vm.isHaEnabled() - || vm.getState() == State.Stopping) { - s_logger.debug("Stopping vm: " + vm - + " as a part of deleteHost id=" - + host.getId()); + if (!vm.isHaEnabled() || vm.getState() == State.Stopping) { + s_logger.debug("Stopping vm: " + vm + " as a part of deleteHost id=" + host.getId()); try { - if (!_vmMgr.advanceStop(vm, true, caller, _accountMgr.getAccount(vm.getAccountId()))) { - String errorMsg = "There was an error stopping the vm: " + vm + " as a part of hostDelete id=" + host.getId(); - s_logger.warn(errorMsg); - throw new UnableDeleteHostException(errorMsg); - } + _vmMgr.easyStop(vm.getUuid()); } catch (Exception e) { - String errorMsg = "There was an error stopping the vm: " - + vm - + " as a part of hostDelete id=" - + host.getId(); + String errorMsg = "There was an error stopping the vm: " + vm + " as a part of hostDelete id=" + host.getId(); s_logger.debug(errorMsg, e); - throw new UnableDeleteHostException(errorMsg - + "," + e.getMessage()); - } - } else if (vm.isHaEnabled() - && (vm.getState() == State.Running || vm - .getState() == State.Starting)) { - s_logger.debug("Scheduling restart for vm: " + vm - + " " + vm.getState() + " on the host id=" - + host.getId()); + throw new UnableDeleteHostException(errorMsg + "," + e.getMessage()); + } + } else if (vm.isHaEnabled() && (vm.getState() == State.Running || vm.getState() == State.Starting)) { + s_logger.debug("Scheduling restart for vm: " + vm + " " + vm.getState() + " on the host id=" + host.getId()); _haMgr.scheduleRestart(vm, false); } } @@@ -2412,19 -2155,17 +2155,17 @@@ return true; } - /* - * TODO: think twice about returning true or throwing out exception, I - * really prefer to exception that always exposes bugs - */ + /* + * TODO: think twice about returning true or throwing out exception, I + * really prefer to exception that always exposes bugs + */ - if (host.getResourceState() != ResourceState.PrepareForMaintenance - && host.getResourceState() != ResourceState.Maintenance + if (host.getResourceState() != ResourceState.PrepareForMaintenance && host.getResourceState() != ResourceState.Maintenance - && host.getResourceState() != ResourceState.ErrorInMaintenance) { + && host.getResourceState() != ResourceState.ErrorInMaintenance) { - throw new CloudRuntimeException( - "Cannot perform cancelMaintenance when resource state is " - + host.getResourceState() + ", hostId = " + hostId); + throw new CloudRuntimeException("Cannot perform cancelMaintenance when resource state is " + host.getResourceState() + ", hostId = " + + hostId); } - /* TODO: move to listener */ + /* TODO: move to listener */ _haMgr.cancelScheduledMigrations(host); List vms = _haMgr.findTakenMigrationWork(); for (VMInstanceVO vm : vms) { @@@ -2436,11 -2176,10 +2176,10 @@@ } try { - resourceStateTransitTo(host, - ResourceState.Event.AdminCancelMaintenance, _nodeId); + resourceStateTransitTo(host, ResourceState.Event.AdminCancelMaintenance, _nodeId); _agentMgr.pullAgentOutMaintenance(hostId); - // for kvm, need to log into kvm host, restart cloudstack-agent + // for kvm, need to log into kvm host, restart cloudstack-agent if (host.getHypervisorType() == HypervisorType.KVM) { _hostDao.loadDetails(host); String password = host.getDetail("password"); @@@ -2577,15 -2300,14 +2300,14 @@@ return doUpdateHostPassword(cmd.getHostId()); } else { // get agents for the cluster - List hosts = this.listAllHostsInCluster(cmd.getClusterId()); + List hosts = listAllHostsInCluster(cmd.getClusterId()); for (HostVO h : hosts) { try { - /* - * FIXME: this is a buggy logic, check with alex. Shouldn't - * return if propagation return non null - */ + /* + * FIXME: this is a buggy logic, check with alex. Shouldn't + * return if propagation return non null + */ - Boolean result = _clusterMgr.propagateResourceEvent( - h.getId(), ResourceState.Event.UpdatePassword); + Boolean result = _clusterMgr.propagateResourceEvent(h.getId(), ResourceState.Event.UpdatePassword); if (result != null) { return result; } @@@ -2702,17 -2407,14 +2407,14 @@@ } @Override - public List listAllNotInMaintenanceHostsInOneZone(Type type, - Long dcId) { - SearchCriteriaService sc = SearchCriteria2 - .create(HostVO.class); + public List listAllNotInMaintenanceHostsInOneZone(Type type, Long dcId) { + SearchCriteriaService sc = SearchCriteria2.create(HostVO.class); - if (dcId != null) { + if (dcId != null) { sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dcId); } sc.addAnd(sc.getEntity().getType(), Op.EQ, type); - sc.addAnd(sc.getEntity().getResourceState(), Op.NIN, - ResourceState.Maintenance, ResourceState.ErrorInMaintenance, + sc.addAnd(sc.getEntity().getResourceState(), Op.NIN, ResourceState.Maintenance, ResourceState.ErrorInMaintenance, - ResourceState.PrepareForMaintenance, ResourceState.Error); + ResourceState.PrepareForMaintenance, ResourceState.Error); return sc.list(); } @@@ -2779,12 -2474,10 +2474,10 @@@ } @Override - public Pair findPod(VirtualMachineTemplate template, - ServiceOfferingVO offering, DataCenterVO dc, long accountId, + public Pair findPod(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, long accountId, - Set avoids) { - for (PodAllocator allocator : _podAllocators) { + Set avoids) { + for (PodAllocator allocator : _podAllocators) { - final Pair pod = allocator.allocateTo(template, - offering, dc, accountId, avoids); + final Pair pod = allocator.allocateTo(template, offering, dc, accountId, avoids); if (pod != null) { return pod; } @@@ -2860,11 -2551,9 +2551,9 @@@ return pcs; } - @Override + @Override - public List listAllUpAndEnabledHostsInOneZoneByHypervisor( - HypervisorType type, long dcId) { - SearchCriteriaService sc = SearchCriteria2 - .create(HostVO.class); + public List listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType type, long dcId) { + SearchCriteriaService sc = SearchCriteria2.create(HostVO.class); sc.addAnd(sc.getEntity().getHypervisorType(), Op.EQ, type); sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dcId); sc.addAnd(sc.getEntity().getStatus(), Op.EQ, Status.Up); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7b7db056/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java ---------------------------------------------------------------------- diff --cc server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java index d0a4797,b5c060d..9cfb84b --- a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java +++ b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java @@@ -29,12 -29,12 +29,14 @@@ import javax.ejb.Local import javax.inject.Inject; import javax.naming.ConfigurationException; - import org.apache.cloudstack.acl.SecurityChecker.AccessType; - import org.apache.cloudstack.context.CallContext; - +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + + import org.apache.cloudstack.acl.SecurityChecker.AccessType; ++import org.apache.cloudstack.context.CallContext; + import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; + import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; + import com.cloud.alert.AlertManager; import com.cloud.configuration.Config; import com.cloud.configuration.Resource; @@@ -65,12 -66,12 +67,10 @@@ import com.cloud.projects.dao.ProjectAc import com.cloud.projects.dao.ProjectDao; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; --import com.cloud.storage.VMTemplateHostVO; import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.dao.SnapshotDao; import com.cloud.storage.dao.VMTemplateDao; --import com.cloud.storage.dao.VMTemplateHostDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.storage.dao.VolumeDaoImpl.SumCount; import com.cloud.user.Account;