From 84179cd561be56e541f8c867c940af7b97720a84 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Wed, 15 Sep 2010 16:49:22 -0700 Subject: [PATCH] add missing files --- .../com/cloud/deploy/DeployDestination.java | 56 ++++++++ .../cloud/deploy/DeploymentDispatcher.java | 13 ++ api/src/com/cloud/org/RunningIn.java | 11 ++ api/src/com/cloud/resource/Concierge.java | 10 ++ api/src/com/cloud/resource/Resource.java | 59 +++++++++ .../profiler/ControlNetworkProfiler.java | 123 ++++++++++++++++++ .../profiler/PodBasedNetworkProfiler.java | 99 ++++++++++++++ .../cloud/network/profiler/ProfilerUtils.java | 9 ++ .../profiler/PublicNetworkProfiler.java | 80 ++++++++++++ .../network/router/DomainRouterManager.java | 10 ++ .../router/DomainRouterManagerImpl.java | 35 +++++ 11 files changed, 505 insertions(+) create mode 100644 api/src/com/cloud/deploy/DeployDestination.java create mode 100644 api/src/com/cloud/deploy/DeploymentDispatcher.java create mode 100644 api/src/com/cloud/org/RunningIn.java create mode 100644 api/src/com/cloud/resource/Concierge.java create mode 100644 api/src/com/cloud/resource/Resource.java create mode 100644 server/src/com/cloud/network/profiler/ControlNetworkProfiler.java create mode 100644 server/src/com/cloud/network/profiler/PodBasedNetworkProfiler.java create mode 100644 server/src/com/cloud/network/profiler/ProfilerUtils.java create mode 100644 server/src/com/cloud/network/profiler/PublicNetworkProfiler.java create mode 100644 server/src/com/cloud/network/router/DomainRouterManager.java create mode 100644 server/src/com/cloud/network/router/DomainRouterManagerImpl.java diff --git a/api/src/com/cloud/deploy/DeployDestination.java b/api/src/com/cloud/deploy/DeployDestination.java new file mode 100644 index 00000000000..4417086c324 --- /dev/null +++ b/api/src/com/cloud/deploy/DeployDestination.java @@ -0,0 +1,56 @@ +/** + * + */ +package com.cloud.deploy; + +import java.util.Map; + +import com.cloud.dc.DataCenter; +import com.cloud.dc.Pod; +import com.cloud.host.Host; +import com.cloud.org.Cluster; +import com.cloud.storage.StoragePool; +import com.cloud.storage.Volume; +import com.cloud.utils.NumbersUtil; + +public class DeployDestination { + DataCenter _dc; + Pod _pod; + Cluster _cluster; + Host _host; + Map _storage; + + public DataCenter getDataCenter() { + return _dc; + } + + public Pod getPod() { + return _pod; + } + + public Cluster getCluster() { + return _cluster; + } + + public Host getHost() { + return _host; + } + + public Map getStorageForDisks() { + return _storage; + } + + public DeployDestination() { + } + + @Override + public int hashCode() { + return NumbersUtil.hash(_host.getId()); + } + + @Override + public boolean equals(Object obj) { + assert false : "Not implemented correctly yet."; + return false; + } +} diff --git a/api/src/com/cloud/deploy/DeploymentDispatcher.java b/api/src/com/cloud/deploy/DeploymentDispatcher.java new file mode 100644 index 00000000000..4265b559f62 --- /dev/null +++ b/api/src/com/cloud/deploy/DeploymentDispatcher.java @@ -0,0 +1,13 @@ +/** + * + */ +package com.cloud.deploy; + +import java.util.Set; + +import com.cloud.utils.component.Adapter; +import com.cloud.vm.VirtualMachineProfile; + +public interface DeploymentDispatcher extends Adapter { + DeployDestination plan(VirtualMachineProfile vm, DeploymentPlan plan, Set avoid); +} diff --git a/api/src/com/cloud/org/RunningIn.java b/api/src/com/cloud/org/RunningIn.java new file mode 100644 index 00000000000..f8b93e3afa5 --- /dev/null +++ b/api/src/com/cloud/org/RunningIn.java @@ -0,0 +1,11 @@ +/** + * + */ +package com.cloud.org; + +public interface RunningIn { + long getDataCenterId(); + long getPodId(); + Long getClusterId(); + Long getHostId(); +} diff --git a/api/src/com/cloud/resource/Concierge.java b/api/src/com/cloud/resource/Concierge.java new file mode 100644 index 00000000000..04b1538ef5b --- /dev/null +++ b/api/src/com/cloud/resource/Concierge.java @@ -0,0 +1,10 @@ +/** + * + */ +package com.cloud.resource; + +import com.cloud.utils.component.Adapter; + +public interface Concierge extends Adapter { + +} diff --git a/api/src/com/cloud/resource/Resource.java b/api/src/com/cloud/resource/Resource.java new file mode 100644 index 00000000000..3269fcd2382 --- /dev/null +++ b/api/src/com/cloud/resource/Resource.java @@ -0,0 +1,59 @@ +/** + * + */ +package com.cloud.resource; + +import java.util.Date; + +/** + * Indicates a resource in CloudStack. + * Any resource that requires an reservation and release system + * must implement this interface. + * + */ +public interface Resource { + enum State { + Allocated, // The resource is allocated but not re + Reserving, + Reserved, + Releasing, + } + + /** + * @return id in the CloudStack database + */ + long getId(); + + /** + * @return reservation id returned by the allocation source. This can be the + * String version of the database id if the allocation source does not need it's + * own implementation of the reservation id. This is passed back to the + * allocation source to release the resource. + */ + String getReservationId(); + + /** + * @return unique name for the allocation source. + */ + String getReserver(); + + /** + * @return the time a reservation request was made to the allocation source. + */ + Date getUpdateTime(); + + /** + * @return the expected reservation interval. -1 indicates + */ + int getExpectedReservationInterval(); + + /** + * @return the expected release interval. + */ + int getExpectedReleaseInterval(); + + /** + * @return the reservation state of the resource. + */ + State getState(); +} diff --git a/server/src/com/cloud/network/profiler/ControlNetworkProfiler.java b/server/src/com/cloud/network/profiler/ControlNetworkProfiler.java new file mode 100644 index 00000000000..4c7cbe07b43 --- /dev/null +++ b/server/src/com/cloud/network/profiler/ControlNetworkProfiler.java @@ -0,0 +1,123 @@ +/** + * + */ +package com.cloud.network.profiler; + +import java.util.Map; + +import javax.ejb.Local; +import javax.naming.ConfigurationException; + +import org.apache.log4j.Logger; + +import com.cloud.configuration.Config; +import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.deploy.DeployDestination; +import com.cloud.deploy.DeploymentPlan; +import com.cloud.exception.InsufficientAddressCapacityException; +import com.cloud.exception.InsufficientVirtualNetworkCapcityException; +import com.cloud.network.Network.BroadcastDomainType; +import com.cloud.network.Network.Mode; +import com.cloud.network.Network.TrafficType; +import com.cloud.network.NetworkConfiguration; +import com.cloud.network.NetworkConfigurationVO; +import com.cloud.network.NetworkProfiler; +import com.cloud.offering.NetworkOffering; +import com.cloud.user.Account; +import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.component.Inject; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.NetworkConcierge; +import com.cloud.vm.Nic; +import com.cloud.vm.NicProfile; +import com.cloud.vm.VirtualMachine; + +@Local(value=NetworkProfiler.class) +public class ControlNetworkProfiler extends AdapterBase implements NetworkProfiler, NetworkConcierge { + private static final Logger s_logger = Logger.getLogger(ControlNetworkProfiler.class); + @Inject DataCenterDao _dcDao; + String _cidr; + String _gateway; + + @Override + public NetworkConfiguration convert(NetworkOffering offering, DeploymentPlan plan, Map params, Account owner) { + if (offering.getTrafficType() != TrafficType.Control) { + return null; + } + + NetworkConfigurationVO config = new NetworkConfigurationVO(offering.getTrafficType(), Mode.Static, BroadcastDomainType.LinkLocal, offering.getId(), plan.getDataCenterId()); + config.setCidr(_cidr); + config.setGateway(_gateway); + + return config; + } + + protected ControlNetworkProfiler() { + super(); + } + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + + ComponentLocator locator = ComponentLocator.getCurrentLocator(); + + ConfigurationDao configDao = locator.getDao(ConfigurationDao.class); + Map dbParams = configDao.getConfiguration(params); + + _cidr = dbParams.get(Config.ControlCidr); + if (_cidr == null) { + _cidr = "169.254.0.0/16"; + } + + _gateway = dbParams.get(Config.ControlGateway); + if (_gateway == null) { + _gateway = "169.254.0.1"; + } + + s_logger.info("Control network setup: cidr=" + _cidr + "; gateway = " + _gateway); + + return true; + } + + @Override + public String getUniqueName() { + return getName(); + } + + @Override + public NicProfile allocate(VirtualMachine vm, NetworkConfiguration config, NicProfile nic) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException { + if (config.getTrafficType() != TrafficType.Control) { + return null; + } + + if (nic != null) { + throw new CloudRuntimeException("Does not support nic specification at this time: " + nic); + } + + return new NicProfile(null, null, null); + } + + @Override + public boolean create(Nic nic) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { + return true; + } + + @Override + public String reserve(long vmId, NicProfile nic, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException { + String ip = _dcDao.allocateLinkLocalPrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), vmId); + nic.setIp4Address(ip); + nic.setMacAddress("FE:FF:FF:FF:FF:FF"); + return Long.toString(nic.getId()); + } + + @Override + public boolean release(String uniqueName, String uniqueId) { + _dcDao.releaseLinkLocalPrivateIpAddress(Long.parseLong(uniqueId)); + return true; + } +} diff --git a/server/src/com/cloud/network/profiler/PodBasedNetworkProfiler.java b/server/src/com/cloud/network/profiler/PodBasedNetworkProfiler.java new file mode 100644 index 00000000000..d36f9c06b34 --- /dev/null +++ b/server/src/com/cloud/network/profiler/PodBasedNetworkProfiler.java @@ -0,0 +1,99 @@ +/** + * + */ +package com.cloud.network.profiler; + +import java.util.Map; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.dc.Pod; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.deploy.DeployDestination; +import com.cloud.deploy.DeploymentPlan; +import com.cloud.exception.InsufficientAddressCapacityException; +import com.cloud.exception.InsufficientVirtualNetworkCapcityException; +import com.cloud.network.Network.BroadcastDomainType; +import com.cloud.network.Network.Mode; +import com.cloud.network.Network.TrafficType; +import com.cloud.network.NetworkConfiguration; +import com.cloud.network.NetworkConfigurationVO; +import com.cloud.network.NetworkProfiler; +import com.cloud.offering.NetworkOffering; +import com.cloud.user.Account; +import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.component.Inject; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.NetworkConcierge; +import com.cloud.vm.Nic; +import com.cloud.vm.NicProfile; +import com.cloud.vm.VirtualMachine; + +@Local(value=NetworkProfiler.class) +public class PodBasedNetworkProfiler extends AdapterBase implements NetworkProfiler, NetworkConcierge { + private static final Logger s_logger = Logger.getLogger(PodBasedNetworkProfiler.class); + @Inject DataCenterDao _dcDao; + + @Override + public NetworkConfiguration convert(NetworkOffering offering, DeploymentPlan plan, Map params, Account owner) { + TrafficType type = offering.getTrafficType(); + + if (type != TrafficType.Management && type != TrafficType.Storage) { + return null; + } + + NetworkConfigurationVO config = new NetworkConfigurationVO(type, Mode.Static, BroadcastDomainType.Native, offering.getId(), plan.getDataCenterId()); + + return config; + } + + protected PodBasedNetworkProfiler() { + super(); + } + + @Override + public String getUniqueName() { + return getName(); + } + + @Override + public NicProfile allocate(VirtualMachine vm, NetworkConfiguration config, NicProfile nic) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException { + TrafficType trafficType = config.getTrafficType(); + if (trafficType != TrafficType.Storage && trafficType != TrafficType.Management) { + return null; + } + + if (nic != null) { + throw new CloudRuntimeException("Does not support nic configuration"); + } + + NicProfile profile = new NicProfile(null, null, null); + return profile; + } + + @Override + public boolean create(Nic nic) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { + return true; + } + + @Override + public String reserve(long vmId, NicProfile nic, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException { + Pod pod = dest.getPod(); + String ip = _dcDao.allocatePrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), nic.getId()); + nic.setIp4Address(ip); + nic.setCidr(pod.getCidrAddress() + "/" + pod.getCidrSize()); + + return Long.toString(nic.getId()); + } + + @Override + public boolean release(String uniqueName, String uniqueId) { + _dcDao.releasePrivateIpAddress(Long.parseLong(uniqueId)); + return true; + } + +} diff --git a/server/src/com/cloud/network/profiler/ProfilerUtils.java b/server/src/com/cloud/network/profiler/ProfilerUtils.java new file mode 100644 index 00000000000..905d1208424 --- /dev/null +++ b/server/src/com/cloud/network/profiler/ProfilerUtils.java @@ -0,0 +1,9 @@ +/** + * + */ +package com.cloud.network.profiler; + +public final class ProfilerUtils { + + +} diff --git a/server/src/com/cloud/network/profiler/PublicNetworkProfiler.java b/server/src/com/cloud/network/profiler/PublicNetworkProfiler.java new file mode 100644 index 00000000000..ad1c7c1bcee --- /dev/null +++ b/server/src/com/cloud/network/profiler/PublicNetworkProfiler.java @@ -0,0 +1,80 @@ +/** + * + */ +package com.cloud.network.profiler; + +import java.util.Map; + +import javax.ejb.Local; + +import com.cloud.deploy.DeployDestination; +import com.cloud.deploy.DeploymentPlan; +import com.cloud.exception.InsufficientAddressCapacityException; +import com.cloud.exception.InsufficientVirtualNetworkCapcityException; +import com.cloud.network.Network.BroadcastDomainType; +import com.cloud.network.Network.Mode; +import com.cloud.network.Network.TrafficType; +import com.cloud.network.NetworkConfiguration; +import com.cloud.network.NetworkConfigurationVO; +import com.cloud.network.NetworkProfiler; +import com.cloud.offering.NetworkOffering; +import com.cloud.user.Account; +import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.NetworkConcierge; +import com.cloud.vm.Nic; +import com.cloud.vm.NicProfile; +import com.cloud.vm.VirtualMachine; + +@Local(value=NetworkProfiler.class) +public class PublicNetworkProfiler extends AdapterBase implements NetworkProfiler, NetworkConcierge { + + @Override + public NetworkConfiguration convert(NetworkOffering offering, DeploymentPlan plan, Map params, Account owner) { + if (offering.getTrafficType() != TrafficType.Public) { + return null; + } + + return new NetworkConfigurationVO(offering.getTrafficType(), Mode.Static, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId()); + } + + protected PublicNetworkProfiler() { + super(); + } + + @Override + public String getUniqueName() { + return getName(); + } + + @Override + public NicProfile allocate(VirtualMachine vm, NetworkConfiguration config, NicProfile nic) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException { + if (config.getTrafficType() != TrafficType.Public) { + return null; + } + + if (nic != null) { + throw new CloudRuntimeException("Unsupported nic settings"); + } + + return new NicProfile(null, null, null); + } + + @Override + public boolean create(Nic nic) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { + return true; + } + + @Override + public String reserve(long vmId, NicProfile ch, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException { + + return null; + } + + @Override + public boolean release(String uniqueName, String uniqueId) { + return false; + } +} diff --git a/server/src/com/cloud/network/router/DomainRouterManager.java b/server/src/com/cloud/network/router/DomainRouterManager.java new file mode 100644 index 00000000000..e8ec0add3f3 --- /dev/null +++ b/server/src/com/cloud/network/router/DomainRouterManager.java @@ -0,0 +1,10 @@ +/** + * + */ +package com.cloud.network.router; + +import com.cloud.utils.component.Manager; + +public interface DomainRouterManager extends Manager { + +} diff --git a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java new file mode 100644 index 00000000000..6374652e535 --- /dev/null +++ b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java @@ -0,0 +1,35 @@ +/** + * + */ +package com.cloud.network.router; + +import java.util.Map; + +import javax.ejb.Local; +import javax.naming.ConfigurationException; + +@Local(value=DomainRouterManager.class) +public class DomainRouterManagerImpl implements DomainRouterManager { + String _name; + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + _name = name; + return true; + } + + @Override + public boolean start() { + return true; + } + + @Override + public boolean stop() { + return true; + } + + @Override + public String getName() { + return _name; + } +}