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 0C8F5DE5B for ; Sun, 19 May 2013 16:14:56 +0000 (UTC) Received: (qmail 63131 invoked by uid 500); 19 May 2013 16:14:55 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 62960 invoked by uid 500); 19 May 2013 16:14:55 -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 62809 invoked by uid 99); 19 May 2013 16:14:55 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 May 2013 16:14:55 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id D9704319C4E; Sun, 19 May 2013 16:14:54 +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: Sun, 19 May 2013 16:14:54 -0000 Message-Id: <0ab41a3aab73401d83dd93d18f5314c5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [01/16] Moved VirtualMachineManagement into orchestration Updated Branches: refs/heads/vmsync cbdc4063c -> f49257cce http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/server/src/com/cloud/configuration/ConfigurationManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index fdc0ffb..702c38c 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -5,7 +5,7 @@ // 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, @@ -39,11 +39,8 @@ import javax.naming.NamingException; import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext; +import org.apache.log4j.Logger; -import com.cloud.dc.*; -import com.cloud.dc.dao.*; -import com.cloud.user.*; -import com.cloud.event.UsageEventUtils; import org.apache.cloudstack.acl.SecurityChecker; import org.apache.cloudstack.api.ApiConstants.LDAPParams; import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd; @@ -72,15 +69,26 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import com.cloud.alert.AlertManager; import com.cloud.api.ApiDBUtils; import com.cloud.capacity.dao.CapacityDao; import com.cloud.configuration.Resource.ResourceType; import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.dc.AccountVlanMapVO; +import com.cloud.dc.ClusterDetailsDao; +import com.cloud.dc.ClusterDetailsVO; +import com.cloud.dc.ClusterVO; +import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.NetworkType; +import com.cloud.dc.DataCenterIpAddressVO; +import com.cloud.dc.DataCenterLinkLocalIpAddressVO; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.DcDetailVO; +import com.cloud.dc.HostPodVO; +import com.cloud.dc.Pod; +import com.cloud.dc.PodVlanMapVO; +import com.cloud.dc.Vlan; import com.cloud.dc.Vlan.VlanType; import com.cloud.dc.VlanVO; import com.cloud.dc.dao.AccountVlanMapDao; @@ -92,13 +100,13 @@ import com.cloud.dc.dao.DcDetailsDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.PodVlanMapDao; import com.cloud.dc.dao.VlanDao; - import com.cloud.deploy.DataCenterDeployment; import com.cloud.domain.Domain; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.event.ActionEvent; import com.cloud.event.EventTypes; +import com.cloud.event.UsageEventUtils; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; @@ -154,6 +162,14 @@ import com.cloud.storage.s3.S3Manager; import com.cloud.storage.secondary.SecondaryStorageVmManager; import com.cloud.storage.swift.SwiftManager; import com.cloud.test.IPRangeConfig; +import com.cloud.user.Account; +import com.cloud.user.AccountDetailVO; +import com.cloud.user.AccountDetailsDao; +import com.cloud.user.AccountManager; +import com.cloud.user.AccountVO; +import com.cloud.user.ResourceLimitService; +import com.cloud.user.User; +import com.cloud.user.UserContext; import com.cloud.user.dao.AccountDao; import com.cloud.utils.NumbersUtil; import com.cloud.utils.StringUtils; @@ -170,7 +186,6 @@ import com.cloud.vm.dao.NicDao; import edu.emory.mathcs.backport.java.util.Arrays; -@Component @Local(value = { ConfigurationManager.class, ConfigurationService.class }) public class ConfigurationManagerImpl extends ManagerBase implements ConfigurationManager, ConfigurationService { public static final Logger s_logger = Logger.getLogger(ConfigurationManagerImpl.class.getName()); @@ -220,7 +235,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Inject AlertManager _alertMgr; // @com.cloud.utils.component.Inject(adapter = SecurityChecker.class) - @Inject + @Inject List _secChecker; @Inject @@ -270,11 +285,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override public boolean configure(final String name, final Map params) throws ConfigurationException { String maxVolumeSizeInGbString = _configDao.getValue(Config.MaxVolumeSize.key()); - _maxVolumeSizeInGb = NumbersUtil.parseInt(maxVolumeSizeInGbString, + _maxVolumeSizeInGb = NumbersUtil.parseInt(maxVolumeSizeInGbString, Integer.parseInt(Config.MaxVolumeSize.getDefaultValue())); String defaultPageSizeString = _configDao.getValue(Config.DefaultPageSize.key()); - _defaultPageSize = NumbersUtil.parseLong(defaultPageSizeString, + _defaultPageSize = NumbersUtil.parseLong(defaultPageSizeString, Long.parseLong(Config.DefaultPageSize.getDefaultValue())); populateConfigValuesForValidationSet(); @@ -611,12 +626,12 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (swift != null) { return " can not change " + Config.SwiftEnable.key() + " after you have added Swift"; } - if (this._s3Mgr.isS3Enabled()) { + if (_s3Mgr.isS3Enabled()) { return String.format("Swift is not supported when S3 is enabled."); } } if (Config.S3Enable.key().equals(name)) { - if (this._swiftMgr.isSwiftEnabled()) { + if (_swiftMgr.isSwiftEnabled()) { return String.format("S3-backed Secondary Storage is not supported when Swift is enabled."); } } @@ -1812,7 +1827,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati userNetwork.setBroadcastDomainType(broadcastDomainType); userNetwork.setNetworkDomain(networkDomain); - _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, false, + _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, false, Domain.ROOT_DOMAIN, null, null, null); } } @@ -2352,7 +2367,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati Account caller = UserContext.current().getCaller(); if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) { throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId); - } + } if (zone.isSecurityGroupEnabled() && zone.getNetworkType() != DataCenter.NetworkType.Basic && forVirtualNetwork) { throw new InvalidParameterValueException("Can't add virtual ip range into a zone with security group enabled"); @@ -2454,7 +2469,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati Transaction txn = Transaction.currentTxn(); txn.start(); - Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP, + Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP, endIP, vlanGateway, vlanNetmask, vlanId, vlanOwner, startIPv6, endIPv6, ip6Gateway, ip6Cidr); txn.commit(); @@ -2464,7 +2479,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override @DB - public Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId, boolean forVirtualNetwork, Long podId, + public Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId, boolean forVirtualNetwork, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, String vlanId, Account vlanOwner, String startIPv6, String endIPv6, String vlanIp6Gateway, String vlanIp6Cidr) { Network network = _networkModel.getNetwork(networkId); @@ -2508,8 +2523,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } //pod vlans can be created in basic zone only if (zone.getNetworkType() != NetworkType.Basic || network.getTrafficType() != TrafficType.Guest) { - throw new InvalidParameterValueException("Pod id can be specified only for the networks of type " - + TrafficType.Guest + " in zone of type " + NetworkType.Basic); + throw new InvalidParameterValueException("Pod id can be specified only for the networks of type " + + TrafficType.Guest + " in zone of type " + NetworkType.Basic); } } @@ -2613,7 +2628,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati List vlans = _vlanDao.listByZone(zone.getId()); for (VlanVO vlan : vlans) { String otherVlanGateway = vlan.getVlanGateway(); - // Continue if it's not IPv4 + // Continue if it's not IPv4 if (otherVlanGateway == null) { continue; } @@ -2715,7 +2730,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // IPv6 use a used ip map, is different from ipv4, no need to save public ip range if (ipv4) { if (!savePublicIPRange(startIP, endIP, zoneId, vlan.getId(), networkId, physicalNetworkId)) { - throw new CloudRuntimeException("Failed to save IPv4 range. Please contact Cloud Support."); + throw new CloudRuntimeException("Failed to save IPv4 range. Please contact Cloud Support."); } } @@ -2762,7 +2777,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati List ips = _publicIpAddressDao.listByVlanId(vlanDbId); boolean success = true; if (allocIpCount > 0) { - if (isAccountSpecific) { + if (isAccountSpecific) { try { vlan = _vlanDao.acquireInLockTable(vlanDbId, 30); if (vlan == null) { @@ -2775,7 +2790,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati for (IPAddressVO ip : ips) { if (ip.isOneToOneNat()) { - throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + + throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + " as ip " + ip + " belonging to the range is used for static nat purposes. Cleanup the rules first"); } @@ -2786,7 +2801,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (_firewallDao.countRulesByIpId(ip.getId()) > 0) { - throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + + throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + " as ip " + ip + " belonging to the range has firewall rules applied. Cleanup the rules first"); } //release public ip address here @@ -2797,7 +2812,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } } finally { _vlanDao.releaseFromLockTable(vlanDbId); - } + } } else { throw new InvalidParameterValueException("The IP range can't be deleted because it has allocated public IP addresses."); } @@ -3580,7 +3595,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("Unknown specified value for " + Capability.LbSchemes.getName()); } } else { - throw new InvalidParameterValueException("Only " + Capability.SupportedLBIsolation.getName() + + throw new InvalidParameterValueException("Only " + Capability.SupportedLBIsolation.getName() + ", " + Capability.ElasticLb.getName() + ", " + Capability.InlineMode.getName() + ", " + Capability.LbSchemes.getName() + " capabilities can be sepcified for LB service"); } @@ -3688,7 +3703,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (availability == NetworkOffering.Availability.Required) { boolean canOffBeRequired = (type == GuestType.Isolated && serviceProviderMap.containsKey(Service.SourceNat)); if (!canOffBeRequired) { - throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with " + Service.SourceNat.getName() + " enabled"); } @@ -3696,7 +3711,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // only one network offering in the system can be Required List offerings = _networkOfferingDao.listByAvailability(Availability.Required, false); if (!offerings.isEmpty()) { - throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required); } } @@ -3757,14 +3772,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if ((sourceNatServiceCapabilityMap != null) && (!sourceNatServiceCapabilityMap.isEmpty())) { String sourceNatType = sourceNatServiceCapabilityMap.get(Capability.SupportedSourceNatTypes); if (sourceNatType != null) { - _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, + _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.SupportedSourceNatTypes, sourceNatType); sharedSourceNat = sourceNatType.contains("perzone"); } String param = sourceNatServiceCapabilityMap.get(Capability.RedundantRouter); if (param != null) { - _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, + _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.RedundantRouter, param); redundantRouter = param.contains("true"); } @@ -3783,7 +3798,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } } - NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, + NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges, inline, isPersistent, associatePublicIp, publicLb, internalLb); @@ -3852,7 +3867,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati break; } } - } + } if (lbProvider == null) { throw new InvalidParameterValueException("Invalid value " + details.get(detail) @@ -4025,7 +4040,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // filter by supported services boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty()); boolean checkIfProvidersAreEnabled = (zoneId != null); - boolean parseOfferings = (listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled + boolean parseOfferings = (listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled || forVpc != null || network != null); if (parseOfferings) { @@ -4192,14 +4207,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } } if (availability == null) { - throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " + throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " + Availability.Required + ", " + Availability.Optional); } else { if (availability == NetworkOffering.Availability.Required) { - boolean canOffBeRequired = (offeringToUpdate.getGuestType() == GuestType.Isolated + boolean canOffBeRequired = (offeringToUpdate.getGuestType() == GuestType.Isolated && _networkModel.areServicesSupportedByNetworkOffering(offeringToUpdate.getId(), Service.SourceNat)); if (!canOffBeRequired) { - throw new InvalidParameterValueException("Availability can be " + + throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with " + Service.SourceNat.getName() + " enabled"); } @@ -4207,7 +4222,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // only one network offering in the system can be Required List offerings = _networkOfferingDao.listByAvailability(Availability.Required, false); if (!offerings.isEmpty() && offerings.get(0).getId() != offeringToUpdate.getId()) { - throw new InvalidParameterValueException("System already has network offering id=" + + throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required); } } @@ -4389,8 +4404,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati }else { DataCenterVO zone = ApiDBUtils.findZoneById(cluster.getDataCenterId()); return zone.getAllocationState(); - } - } + } + } @Override public AllocationState findPodAllocationState(HostPodVO pod){ @@ -4400,7 +4415,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati }else { DataCenterVO zone = ApiDBUtils.findZoneById(pod.getDataCenterId()); return zone.getAllocationState(); - } + } } private boolean allowIpRangeOverlap(VlanVO vlan, boolean forVirtualNetwork, long networkId) { @@ -4468,4 +4483,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati return null; } + + @Override + public ConfigValue getConfig(Config config, Class clazz) { + return new ConfigValue(_configDao, config); + } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/server/src/com/cloud/dao/EntityManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dao/EntityManagerImpl.java b/server/src/com/cloud/dao/EntityManagerImpl.java index a3ab5b3..18302d9 100644 --- a/server/src/com/cloud/dao/EntityManagerImpl.java +++ b/server/src/com/cloud/dao/EntityManagerImpl.java @@ -23,10 +23,10 @@ import java.util.Map; import javax.ejb.Local; import javax.naming.ConfigurationException; -import org.springframework.stereotype.Component; - import net.sf.ehcache.Cache; +import org.springframework.stereotype.Component; + import com.cloud.utils.component.ManagerBase; import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDaoBase; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/server/src/com/cloud/network/NetworkManager.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java deleted file mode 100755 index 34a092a..0000000 --- a/server/src/com/cloud/network/NetworkManager.java +++ /dev/null @@ -1,352 +0,0 @@ -// 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.network; - -import java.util.List; -import java.util.Map; - -import org.apache.cloudstack.acl.ControlledEntity.ACLType; - -import com.cloud.dc.DataCenter; -import com.cloud.dc.Pod; -import com.cloud.dc.Vlan.VlanType; -import com.cloud.deploy.DataCenterDeployment; -import com.cloud.deploy.DeployDestination; -import com.cloud.deploy.DeploymentPlan; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientAddressCapacityException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.InsufficientVirtualNetworkCapcityException; -import com.cloud.exception.ResourceAllocationException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.Network.Provider; -import com.cloud.network.Network.Service; -import com.cloud.network.addr.PublicIp; -import com.cloud.network.dao.IPAddressVO; -import com.cloud.network.dao.NetworkVO; -import com.cloud.network.element.LoadBalancingServiceProvider; -import com.cloud.network.element.StaticNatServiceProvider; -import com.cloud.network.element.UserDataServiceProvider; -import com.cloud.network.guru.NetworkGuru; -import com.cloud.network.rules.FirewallRule; -import com.cloud.network.rules.LoadBalancerContainer.Scheme; -import com.cloud.network.rules.StaticNat; -import com.cloud.offering.NetworkOffering; -import com.cloud.offerings.NetworkOfferingVO; -import com.cloud.user.Account; -import com.cloud.user.User; -import com.cloud.utils.Pair; -import com.cloud.vm.Nic; -import com.cloud.vm.NicProfile; -import com.cloud.vm.NicVO; -import com.cloud.vm.ReservationContext; -import com.cloud.vm.VMInstanceVO; -import com.cloud.vm.VirtualMachine; -import com.cloud.vm.VirtualMachine.Type; -import com.cloud.vm.VirtualMachineProfile; - -/** - * NetworkManager manages the network for the different end users. - * - */ -public interface NetworkManager { - /** - * Assigns a new public ip address. - * - * @param dcId - * @param podId - * TODO - * @param owner - * @param type - * @param networkId - * @param requestedIp - * TODO - * @param allocatedBy - * TODO - * @return - * @throws InsufficientAddressCapacityException - */ - - PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, - boolean isSystem) throws InsufficientAddressCapacityException; - - - /** - * Do all of the work of releasing public ip addresses. Note that if this method fails, there can be side effects. - * - * @param userId - * @param caller - * TODO - * @param IpAddress - * @return true if it did; false if it didn't - */ - public boolean disassociatePublicIpAddress(long id, long userId, Account caller); - - List setupNetwork(Account owner, NetworkOffering offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) - throws ConcurrentOperationException; - - List setupNetwork(Account owner, NetworkOffering offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, - ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException; - - void allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException, ConcurrentOperationException; - - void prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, - ResourceUnavailableException; - - void release(VirtualMachineProfile vmProfile, boolean forced) throws - ConcurrentOperationException, ResourceUnavailableException; - - void cleanupNics(VirtualMachineProfile vm); - - void expungeNics(VirtualMachineProfile vm); - - List getNicProfiles(VirtualMachine vm); - - boolean applyRules(List rules, FirewallRule.Purpose purpose, NetworkRuleApplier applier, boolean continueOnError) throws ResourceUnavailableException; - - Pair implementNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, - InsufficientCapacityException; - - void prepareNicForMigration(VirtualMachineProfile vm, DeployDestination dest); - - boolean shutdownNetwork(long networkId, ReservationContext context, boolean cleanupElements); - - boolean destroyNetwork(long networkId, ReservationContext context); - - Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, - String vlanId, String networkDomain, Account owner, Long domainId, PhysicalNetwork physicalNetwork, - long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId, String ip6Gateway, String ip6Cidr) - throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException; - - /** - * @throws ResourceAllocationException TODO - * @throws InsufficientCapacityException - * Associates an ip address list to an account. The list of ip addresses are all addresses associated - * with the - * given vlan id. - * @param userId - * @param accountId - * @param zoneId - * @param vlanId - * @throws InsufficientAddressCapacityException - * @throws - */ - boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId, Network guestNetwork) throws InsufficientCapacityException, ConcurrentOperationException, - ResourceUnavailableException, ResourceAllocationException; - - UserDataServiceProvider getPasswordResetProvider(Network network); - - UserDataServiceProvider getSSHKeyResetProvider(Network network); - - boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException; - - boolean applyIpAssociations(Network network, boolean rulesRevoked, boolean continueOnError, List publicIps) throws ResourceUnavailableException; - - boolean startNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; - - IPAddressVO markIpAsUnavailable(long addrId); - - public String acquireGuestIpAddress(Network network, String requestedIp); - - boolean applyStaticNats(List staticNats, boolean continueOnError) throws ResourceUnavailableException; - - boolean reallocate(VirtualMachineProfile vm, - DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException; - - IpAddress assignSystemIp(long networkId, Account owner, - boolean forElasticLb, boolean forElasticIp) - throws InsufficientAddressCapacityException; - - boolean handleSystemIpRelease(IpAddress ip); - - void allocateDirectIp(NicProfile nic, DataCenter dc, - VirtualMachineProfile vm, - Network network, String requestedIpv4, String requestedIpv6) - throws InsufficientVirtualNetworkCapcityException, - InsufficientAddressCapacityException; - - /** - * @param owner - * @param guestNetwork - * @return - * @throws ConcurrentOperationException - * @throws InsufficientAddressCapacityException - */ - PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) throws InsufficientAddressCapacityException, ConcurrentOperationException; - - - /** - * @param requested - * @param network - * @param isDefaultNic - * @param deviceId - * @param vm - * @return - * @throws InsufficientVirtualNetworkCapcityException - * @throws InsufficientAddressCapacityException - * @throws ConcurrentOperationException - */ - Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, int deviceId, - VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, - InsufficientAddressCapacityException, ConcurrentOperationException; - - - /** - * @param vmProfile - * @param dest - * @param context - * @param nicId - * @param network - * @return - * @throws InsufficientVirtualNetworkCapcityException - * @throws InsufficientAddressCapacityException - * @throws ConcurrentOperationException - * @throws InsufficientCapacityException - * @throws ResourceUnavailableException - */ - NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, - ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException, - InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; - - - /** - * @param vm - * @param nic TODO - */ - void removeNic(VirtualMachineProfile vm, Nic nic); - - - /** - * @param ipAddrId - * @param networkId - * @param releaseOnFailure TODO - */ - IPAddressVO associateIPToGuestNetwork(long ipAddrId, long networkId, boolean releaseOnFailure) throws ResourceAllocationException, ResourceUnavailableException, - InsufficientAddressCapacityException, ConcurrentOperationException; - - - /** - * @param network - * @param provider - * @return - */ - boolean setupDns(Network network, Provider provider); - - - /** - * @param vmProfile - * @param nic TODO - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - */ - void releaseNic(VirtualMachineProfile vmProfile, Nic nic) - throws ConcurrentOperationException, ResourceUnavailableException; - - - /** - * @param network - * @param requested - * @param context - * @param vmProfile - * @param prepare TODO - * @return - * @throws InsufficientVirtualNetworkCapcityException - * @throws InsufficientAddressCapacityException - * @throws ConcurrentOperationException - * @throws InsufficientCapacityException - * @throws ResourceUnavailableException - */ - NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfile vmProfile, boolean prepare) throws InsufficientVirtualNetworkCapcityException, - InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; - - - PublicIp assignVpnGatewayIpAddress(long dcId, Account owner, long vpcId) throws InsufficientAddressCapacityException, ConcurrentOperationException; - - - /** - * @param addr - */ - void markPublicIpAsAllocated(IPAddressVO addr); - - - /** - * @param owner - * @param guestNtwkId - * @param vpcId - * @param dcId - * @param isSourceNat - * @return - * @throws ConcurrentOperationException - * @throws InsufficientAddressCapacityException - */ - PublicIp assignDedicateIpAddress(Account owner, Long guestNtwkId, Long vpcId, long dcId, boolean isSourceNat) throws ConcurrentOperationException, InsufficientAddressCapacityException; - - NetworkProfile convertNetworkToNetworkProfile(long networkId); - - /** - * @return - */ - int getNetworkLockTimeout(); - - - boolean cleanupIpResources(long addrId, long userId, Account caller); - - - boolean restartNetwork(Long networkId, Account callerAccount, - User callerUser, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; - - - boolean shutdownNetworkElementsAndResources(ReservationContext context, - boolean b, NetworkVO network); - - - void implementNetworkElementsAndResources(DeployDestination dest, - ReservationContext context, NetworkVO network, - NetworkOfferingVO findById) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException; - - - IpAddress allocateIp(Account ipOwner, boolean isSystem, Account caller, long callerId, - DataCenter zone) throws ConcurrentOperationException, ResourceAllocationException, InsufficientAddressCapacityException; - - - Map finalizeServicesAndProvidersForNetwork(NetworkOffering offering, - Long physicalNetworkId); - - - List getProvidersForServiceInNetwork(Network network, Service service); - - StaticNatServiceProvider getStaticNatProviderForNetwork(Network network); - boolean isNetworkInlineMode(Network network); - - int getRuleCountForIp(Long addressId, FirewallRule.Purpose purpose, FirewallRule.State state); - - LoadBalancingServiceProvider getLoadBalancingProviderForNetwork(Network network, Scheme lbScheme); - - - boolean isSecondaryIpSetForNic(long nicId); - - public String allocateGuestIP(Account ipOwner, boolean isSystem, long zoneId, Long networkId, String requestedIp) - throws InsufficientAddressCapacityException; - - - List listVmNics(Long vmId, Long nicId); - String allocatePublicIpForGuestNic(Long networkId, DataCenter dc, Pod pod, Account caller, String requestedIp) throws InsufficientAddressCapacityException; - boolean removeVmSecondaryIpsOfNic(long nicId); - - NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType); - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/server/src/com/cloud/network/NetworkRuleApplier.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/NetworkRuleApplier.java b/server/src/com/cloud/network/NetworkRuleApplier.java deleted file mode 100644 index 31763d0..0000000 --- a/server/src/com/cloud/network/NetworkRuleApplier.java +++ /dev/null @@ -1,28 +0,0 @@ -// 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.network; - -import java.util.List; - -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.rules.FirewallRule; - -public interface NetworkRuleApplier { - public boolean applyRules(Network network, FirewallRule.Purpose purpose, List rules) throws ResourceUnavailableException; - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/server/src/com/cloud/network/addr/PublicIp.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/addr/PublicIp.java b/server/src/com/cloud/network/addr/PublicIp.java deleted file mode 100644 index 25e9d30..0000000 --- a/server/src/com/cloud/network/addr/PublicIp.java +++ /dev/null @@ -1,222 +0,0 @@ -// 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.network.addr; - -import java.util.Date; - -import com.cloud.dc.VlanVO; -import com.cloud.network.PublicIpAddress; -import com.cloud.network.dao.IPAddressVO; -import com.cloud.utils.net.Ip; -import com.cloud.utils.net.NetUtils; - -/** - */ -public class PublicIp implements PublicIpAddress { - IPAddressVO _addr; - VlanVO _vlan; - String macAddress; - - public PublicIp(IPAddressVO addr, VlanVO vlan, long macAddress) { - _addr = addr; - _vlan = vlan; - this.macAddress = NetUtils.long2Mac(macAddress); - } - - public static PublicIp createFromAddrAndVlan(IPAddressVO addr, VlanVO vlan) { - return new PublicIp(addr, vlan, NetUtils.createSequenceBasedMacAddress(addr.getMacAddress())); - } - - @Override - public Ip getAddress() { - return _addr.getAddress(); - } - - @Override - public String getNetmask() { - return _vlan.getVlanNetmask(); - } - - @Override - public String getGateway() { - return _vlan.getVlanGateway(); - } - - @Override - public String getVlanTag() { - return _vlan.getVlanTag(); - } - - @Override - public long getDataCenterId() { - return _addr.getDataCenterId(); - } - - @Override - public boolean readyToUse() { - return _addr.getAllocatedTime() != null && _addr.getState() == State.Allocated; - } - - @Override - public boolean isSourceNat() { - return _addr.isSourceNat(); - } - - @Override - public boolean isOneToOneNat() { - return _addr.isOneToOneNat(); - } - - @Override - public Long getAssociatedWithVmId() { - return _addr.getAssociatedWithVmId(); - } - - @Override - public Date getAllocatedTime() { - return _addr.getAllocatedTime(); - } - - @Override - public long getAccountId() { - return _addr.getAccountId(); - } - - @Override - public long getDomainId() { - return _addr.getDomainId(); - } - - @Override - public long getVlanId() { - return _vlan.getId(); - } - - @Override - public State getState() { - return _addr.getState(); - } - - public IPAddressVO ip() { - return _addr; - } - - public VlanVO vlan() { - return _vlan; - } - - @Override - public String getMacAddress() { - return macAddress; - } - - @Override - public Long getAssociatedWithNetworkId() { - return _addr.getAssociatedWithNetworkId(); - } - - @Override - public Long getNetworkId() { - return _vlan.getNetworkId(); - } - - @Override - public String getVlanGateway() { - return _vlan.getVlanGateway(); - } - - @Override - public String getVlanNetmask() { - return _vlan.getVlanNetmask(); - } - - @Override - public String getIpRange() { - return _vlan.getIpRange(); - } - - @Override - public VlanType getVlanType() { - return _vlan.getVlanType(); - } - - @Override - public long getId() { - return _addr.getId(); - } - - - @Override - public String getUuid() { - return _addr.getUuid(); - } - - @Override - public String toString() { - return _addr.getAddress().toString(); - } - - @Override - public Long getPhysicalNetworkId() { - return _vlan.getPhysicalNetworkId(); - } - - @Override - public void setState(State state) { - _addr.setState(state); - } - - @Override - public Long getAllocatedToAccountId() { - return _addr.getAllocatedToAccountId(); - } - - @Override - public Long getAllocatedInDomainId() { - return _addr.getAllocatedInDomainId(); - } - - @Override - public boolean getSystem() { - return _addr.getSystem(); - } - - @Override - public Long getVpcId() { - return _addr.getVpcId(); - } - - @Override - public String getIp6Gateway() { - return _vlan.getIp6Gateway(); - } - - @Override - public String getIp6Cidr() { - return _vlan.getIp6Cidr(); - } - - @Override - public String getIp6Range() { - return _vlan.getIp6Range(); - } - - @Override - public String getVmIp() { - return _addr.getVmIp(); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/server/src/com/cloud/resource/ResourceManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 0ab35dd..519e195 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -30,6 +30,9 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd; import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd; @@ -46,8 +49,6 @@ import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd; import org.apache.cloudstack.api.command.admin.swift.ListSwiftsCmd; 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; @@ -61,6 +62,7 @@ import com.cloud.agent.api.StartupRoutingCommand; import com.cloud.agent.api.UnsupportedAnswer; import com.cloud.agent.api.UpdateHostPasswordCommand; import com.cloud.agent.manager.AgentAttache; +import com.cloud.agent.manager.AttacheHandler; import com.cloud.agent.manager.ClusteredAgentManagerImpl; import com.cloud.agent.manager.allocator.PodAllocator; import com.cloud.agent.transport.Request; @@ -212,6 +214,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, protected HighAvailabilityManager _haMgr; @Inject protected StorageService _storageSvr; + protected AttacheHandler _attacheHandler; // FIXME: Get rid of me! protected List _discoverers; public List getDiscoverers() { @@ -667,12 +670,12 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, @Override public S3 discoverS3(final AddS3Cmd cmd) throws DiscoveryException { - return this._s3Mgr.addS3(cmd); + return _s3Mgr.addS3(cmd); } @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, @@ -743,7 +746,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, // already have a lot of information // in cluster object, to simplify user input, we will construct // neccessary information here - Map clusterDetails = this._clusterDetailsDao + Map clusterDetails = _clusterDetailsDao .findDetails(clusterId); username = clusterDetails.get("username"); assert (username != null); @@ -925,7 +928,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, * concurrently, return. And consider the situation of CloudStack * shutdown during delete. A global lock? */ - AgentAttache attache = _agentMgr.findAttache(hostId); + 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! @@ -1536,6 +1539,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, throws ConfigurationException { _defaultSystemVMHypervisor = HypervisorType.getType(_configDao .getValue(Config.SystemVMDefaultHypervisor.toString())); + _attacheHandler = (AttacheHandler)_agentMgr; return true; } @@ -1990,7 +1994,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, hostTags, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT); if (host != null) { - attache = _agentMgr.handleDirectConnectAgent(host, cmds, + attache = _attacheHandler.handleDirectConnectAgent(host, cmds, resource, forRebalance); /* reload myself from database */ host = _hostDao.findById(host.getId()); @@ -2075,7 +2079,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, if (host != null) { 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 @@ -2144,8 +2148,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, Map details = hostDetails; String guid = details.get("guid"); - List currentHosts = this - .listAllUpAndEnabledHostsInOneZoneByType(hostType, zoneId); + List currentHosts = listAllUpAndEnabledHostsInOneZoneByType(hostType, zoneId); for (HostVO currentHost : currentHosts) { if (currentHost.getGuid().equals(guid)) { return currentHost; @@ -2525,7 +2528,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } private boolean doUpdateHostPassword(long hostId) { - AgentAttache attache = _agentMgr.findAttache(hostId); + AgentAttache attache = _attacheHandler.findAttache(hostId); if (attache == null) { return false; } @@ -2556,7 +2559,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, 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 { /* http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/server/src/com/cloud/vm/VirtualMachineGuru.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/VirtualMachineGuru.java b/server/src/com/cloud/vm/VirtualMachineGuru.java deleted file mode 100644 index b3fafe3..0000000 --- a/server/src/com/cloud/vm/VirtualMachineGuru.java +++ /dev/null @@ -1,125 +0,0 @@ -// 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.vm; - -import com.cloud.agent.api.StopAnswer; -import com.cloud.agent.api.to.NicTO; -import com.cloud.agent.api.to.VirtualMachineTO; -import com.cloud.agent.manager.Commands; -import com.cloud.deploy.DeployDestination; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.InsufficientNetworkCapacityException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.Network; - -/** - * A VirtualMachineGuru knows how to process a certain type of virtual machine. - * - */ -public interface VirtualMachineGuru { - /** - * Find the virtual machine by name. - * @param name - * @return virtual machine. - */ - T findByName(String name); - - T findById(long id); - - T persist(T vm); - - boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context); - - /** - * finalize the virtual machine deployment. - * @param cmds commands that were created. - * @param profile virtual machine profile. - * @param dest destination to send the command. - * @return true if everything checks out. false if not and we should try again. - */ - boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException; - - /** - * Check the deployment results. - * @param cmds commands and answers that were sent. - * @param profile virtual machine profile. - * @param dest destination it was sent to. - * @return true if deployment was fine; false if it didn't go well. - */ - boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context); - - boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile); - - void finalizeStop(VirtualMachineProfile profile, StopAnswer answer); - - void finalizeExpunge(T vm); - - /** - * Returns the id parsed from the name. If it cannot parse the name, - * then return null. This method is used to determine if this is - * the right handler for this vm. - * - * @param vmName vm name coming form the agent. - * @return id if the handler works for this vm and can parse id. null if not. - */ - Long convertToId(String vmName); - - /** - * Prepare for a nic to be plugged into the network. - * @param network - * @param nic - * @param vm - * @param context - * @param dest TODO - * @return - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - * @throws InsufficientNetworkCapacityException - */ - boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, - ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, - ResourceUnavailableException, InsufficientCapacityException; - - /** - * A nic is unplugged from this network. - * @param network - * @param nic - * @param vm - * @param context - * @param dest TODO - * @return - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - */ - boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, - ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException; - - /** - * Prepare Vm for Stop - * @param profile - * @return - */ - void prepareStop(VirtualMachineProfile profile); - - /** - * VM work handlers - * @param work - */ - void vmWorkStart(VmWork work); - void vmWorkStop(VmWork work); -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/server/src/com/cloud/vm/VirtualMachineManager.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java deleted file mode 100644 index 2e1503a..0000000 --- a/server/src/com/cloud/vm/VirtualMachineManager.java +++ /dev/null @@ -1,218 +0,0 @@ -// 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.vm; - -import java.net.URI; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; - -import com.cloud.agent.api.to.NicTO; -import com.cloud.agent.api.to.VirtualMachineTO; -import com.cloud.deploy.DeployDestination; -import com.cloud.deploy.DeploymentPlan; -import com.cloud.exception.AgentUnavailableException; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.InsufficientServerCapacityException; -import com.cloud.exception.ManagementServerException; -import com.cloud.exception.OperationTimedoutException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.exception.VirtualMachineMigrationException; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.network.Network; -import com.cloud.network.dao.NetworkVO; -import com.cloud.offering.ServiceOffering; -import com.cloud.service.ServiceOfferingVO; -import com.cloud.storage.DiskOfferingVO; -import com.cloud.storage.StoragePool; -import com.cloud.storage.VMTemplateVO; -import com.cloud.storage.VolumeVO; -import com.cloud.user.Account; -import com.cloud.user.User; -import com.cloud.utils.Pair; -import com.cloud.utils.component.Manager; -import com.cloud.utils.fsm.NoTransitionException; - -/** - * Manages allocating resources to vms. - */ -public interface VirtualMachineManager extends Manager { - - T allocate(T vm, - VMTemplateVO template, - ServiceOfferingVO serviceOffering, - Pair rootDiskOffering, - List> dataDiskOfferings, - List> networks, - Map params, - DeploymentPlan plan, - HypervisorType hyperType, - Account owner) throws InsufficientCapacityException; - - T allocate(T vm, - VMTemplateVO template, - ServiceOfferingVO serviceOffering, - Long rootSize, - Pair dataDiskOffering, - List> networks, - DeploymentPlan plan, - HypervisorType hyperType, - Account owner) throws InsufficientCapacityException; - - T allocate(T vm, - VMTemplateVO template, - ServiceOfferingVO serviceOffering, - List> networkProfiles, - DeploymentPlan plan, - HypervisorType hyperType, - Account owner) throws InsufficientCapacityException; - - T start(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException; - - T start(T vm, Map params, User caller, Account account, DeploymentPlan planToDeploy) throws InsufficientCapacityException, ResourceUnavailableException; - - boolean stop(T vm, User caller, Account account) throws ResourceUnavailableException; - - boolean expunge(T vm, User caller, Account account) throws ResourceUnavailableException; - - void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru); - - Collection> getRegisteredGurus(); - - VirtualMachineGuru getVmGuru(T vm); - - boolean stateTransitTo(VMInstanceVO vm, VirtualMachine.Event e, Long hostId) throws NoTransitionException; - - T advanceStart(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException; - - T advanceStart(T vm, Map params, User caller, Account account, DeploymentPlan planToDeploy) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException; - - boolean advanceStop(T vm, boolean forced, User caller, Account account) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException; - - boolean advanceExpunge(T vm, User caller, Account account) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException; - - boolean remove(T vm, User caller, Account account); - - boolean destroy(T vm, User caller, Account account) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException; - - boolean migrateAway(VirtualMachine.Type type, long vmid, long hostId) throws InsufficientServerCapacityException, VirtualMachineMigrationException; - - T migrate(T vm, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException; - - T migrateWithStorage(T vm, long srcId, long destId, Map volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException; - - T reboot(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException; - - T advanceReboot(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException; - - VMInstanceVO findByIdAndType(VirtualMachine.Type type, long vmId); - - /** - * Check to see if a virtual machine can be upgraded to the given service offering - * - * @param vm - * @param offering - * @return true if the host can handle the upgrade, false otherwise - */ - boolean isVirtualMachineUpgradable(final VirtualMachine vm, final ServiceOffering offering); - - VMInstanceVO findById(long vmId); - - T storageMigration(T vm, StoragePool storagePoolId); - - /** - * @param vmInstance - * @param newServiceOfferingId - */ - void checkIfCanUpgrade(VirtualMachine vmInstance, long newServiceOfferingId); - - /** - * @param vmId - * @param serviceOfferingId - * @return - */ - boolean upgradeVmDb(long vmId, long serviceOfferingId); - - /** - * @param vm - * @param network - * @param requested TODO - * @return - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - * @throws InsufficientCapacityException - */ - NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException, - ResourceUnavailableException, InsufficientCapacityException; - - /** - * @param vm - * @param nic - * @return - * @throws ResourceUnavailableException - * @throws ConcurrentOperationException - */ - boolean removeNicFromVm(VirtualMachine vm, NicVO nic) throws ConcurrentOperationException, ResourceUnavailableException; - - /** - * @param vm - * @param network - * @param broadcastUri TODO - * @return - * @throws ResourceUnavailableException - * @throws ConcurrentOperationException - */ - boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException; - - /** - * @param nic - * @param hypervisorType - * @return - */ - NicTO toNicTO(NicProfile nic, HypervisorType hypervisorType); - - /** - * @param profile - * @param hvGuru - * @return - */ - VirtualMachineTO toVmTO(VirtualMachineProfile profile); - - - VMInstanceVO reConfigureVm(VMInstanceVO vm, ServiceOffering newServiceOffering, boolean sameHost) - throws ResourceUnavailableException, ConcurrentOperationException; - - VMInstanceVO findHostAndMigrate(VirtualMachine.Type vmType, VMInstanceVO vm, Long newSvcOfferingId) throws InsufficientCapacityException, - ConcurrentOperationException, ResourceUnavailableException, - VirtualMachineMigrationException, ManagementServerException; - - T migrateForScale(T vm, long srcHostId, DeployDestination dest, Long newSvcOfferingId) - throws ResourceUnavailableException, ConcurrentOperationException, - ManagementServerException, VirtualMachineMigrationException; - - // - // VM work handlers - // - T processVmStartWork(T vm, Map params, User caller, Account account, DeploymentPlan planToDeploy) - throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException; - - boolean processVmStopWork(T vm, boolean forced, User user, Account account) - throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException; -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/server/src/com/cloud/vm/VirtualMachineProfileImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/VirtualMachineProfileImpl.java b/server/src/com/cloud/vm/VirtualMachineProfileImpl.java index 24f44cb..19039f6 100644 --- a/server/src/com/cloud/vm/VirtualMachineProfileImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineProfileImpl.java @@ -21,7 +21,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - import com.cloud.agent.api.to.VolumeTO; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.offering.ServiceOffering; @@ -99,7 +98,7 @@ public class VirtualMachineProfileImpl implements Virtua _params.put(name, value); } - @Override + @Override public void setBootLoaderType(BootloaderType bootLoader) { this._bootloader = bootLoader; } @@ -198,7 +197,8 @@ public class VirtualMachineProfileImpl implements Virtua static ServiceOfferingDao s_offeringDao; static VMTemplateDao s_templateDao; static AccountDao s_accountDao; - static void setComponents(ServiceOfferingDao offeringDao, VMTemplateDao templateDao, AccountDao accountDao) { + + public static void setComponents(ServiceOfferingDao offeringDao, VMTemplateDao templateDao, AccountDao accountDao) { s_offeringDao = offeringDao; s_templateDao = templateDao; s_accountDao = accountDao; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/server/src/com/cloud/vm/VmWork.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/VmWork.java b/server/src/com/cloud/vm/VmWork.java deleted file mode 100644 index 733bfe7..0000000 --- a/server/src/com/cloud/vm/VmWork.java +++ /dev/null @@ -1,50 +0,0 @@ -// 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.vm; - -public class VmWork { - long userId; - long accountId; - long vmId; - - public VmWork() { - } - - public long getUserId() { - return userId; - } - - public void setUserId(long userId) { - this.userId = userId; - } - - public long getAccountId() { - return accountId; - } - - public void setAccountId(long accountId) { - this.accountId = accountId; - } - - public long getVmId() { - return vmId; - } - - public void setVmId(long vmId) { - this.vmId = vmId; - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/server/test/com/cloud/agent/MockAgentManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/agent/MockAgentManagerImpl.java b/server/test/com/cloud/agent/MockAgentManagerImpl.java index 7e3462d..0575bc6 100755 --- a/server/test/com/cloud/agent/MockAgentManagerImpl.java +++ b/server/test/com/cloud/agent/MockAgentManagerImpl.java @@ -25,16 +25,12 @@ import org.springframework.stereotype.Component; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; -import com.cloud.agent.api.StartupCommand; -import com.cloud.agent.manager.AgentAttache; import com.cloud.agent.manager.Commands; import com.cloud.exception.AgentUnavailableException; -import com.cloud.exception.ConnectionException; import com.cloud.exception.OperationTimedoutException; import com.cloud.host.HostVO; import com.cloud.host.Status.Event; import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.resource.ServerResource; import com.cloud.utils.component.ManagerBase; @Component @@ -147,24 +143,12 @@ public class MockAgentManagerImpl extends ManagerBase implements AgentManager { } @Override - public AgentAttache handleDirectConnectAgent(HostVO host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance) throws ConnectionException { - // TODO Auto-generated method stub - return null; - } - - @Override public boolean agentStatusTransitTo(HostVO host, Event e, long msId) { // TODO Auto-generated method stub return false; } @Override - public AgentAttache findAttache(long hostId) { - // TODO Auto-generated method stub - return null; - } - - @Override public void pullAgentToMaintenance(long hostId) { // TODO Auto-generated method stub http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java index 9058798..d221f3c 100755 --- a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java +++ b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java @@ -25,7 +25,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import javax.naming.NamingException; -import com.cloud.configuration.ConfigurationVO; import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd; import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd; import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd; @@ -48,8 +47,9 @@ import org.apache.cloudstack.api.command.admin.zone.CreateZoneCmd; import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd; import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd; import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd; -import org.springframework.stereotype.Component; +import com.cloud.configuration.Config; +import com.cloud.configuration.ConfigValue; import com.cloud.configuration.Configuration; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.ConfigurationService; @@ -75,17 +75,14 @@ import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.Availability; import com.cloud.offering.ServiceOffering; import com.cloud.offerings.NetworkOfferingVO; -import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.offerings.dao.NetworkOfferingDaoImpl; import com.cloud.org.Grouping.AllocationState; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.DiskOfferingVO; import com.cloud.user.Account; -import com.cloud.utils.component.Manager; import com.cloud.utils.component.ManagerBase; import com.cloud.vm.VirtualMachine.Type; -@Component @Local(value = { ConfigurationManager.class, ConfigurationService.class }) public class MockConfigurationManagerImpl extends ManagerBase implements ConfigurationManager, ConfigurationService { @Inject @@ -636,4 +633,10 @@ public class MockConfigurationManagerImpl extends ManagerBase implements Configu return false; } + @Override + public ConfigValue getConfig(Config config, Class clazz) { + // TODO Auto-generated method stub + return null; + } + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/utils/src/com/cloud/cluster/ManagementServerNode.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/cluster/ManagementServerNode.java b/utils/src/com/cloud/cluster/ManagementServerNode.java new file mode 100755 index 0000000..56cb4af --- /dev/null +++ b/utils/src/com/cloud/cluster/ManagementServerNode.java @@ -0,0 +1,62 @@ +// 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.cluster; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.component.ComponentLifecycle; +import com.cloud.utils.component.SystemIntegrityChecker; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.net.MacAddress; + +@Local(value = {SystemIntegrityChecker.class}) +public class ManagementServerNode extends AdapterBase implements SystemIntegrityChecker { + private final Logger s_logger = Logger.getLogger(ManagementServerNode.class); + + private static final long s_nodeId = MacAddress.getMacAddress().toLong(); + + public static enum State { Up, Down }; + + public ManagementServerNode() { + setRunLevel(ComponentLifecycle.RUN_LEVEL_FRAMEWORK_BOOTSTRAP); + } + + @Override + public void check() { + if (s_nodeId <= 0) { + throw new CloudRuntimeException("Unable to get the management server node id"); + } + } + + public static long getManagementServerId() { + return s_nodeId; + } + + @Override + public boolean start() { + try { + check(); + } catch (Exception e) { + s_logger.error("System integrity check exception", e); + System.exit(1); + } + return true; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9340690f/utils/src/com/cloud/utils/component/ComponentLifecycleBase.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/component/ComponentLifecycleBase.java b/utils/src/com/cloud/utils/component/ComponentLifecycleBase.java index 8c7d09d..98cabe7 100644 --- a/utils/src/com/cloud/utils/component/ComponentLifecycleBase.java +++ b/utils/src/com/cloud/utils/component/ComponentLifecycleBase.java @@ -65,6 +65,8 @@ public class ComponentLifecycleBase implements ComponentLifecycle { @Override public boolean configure(String name, Map params) throws ConfigurationException { + _name = name; + _configParams = params; return true; }