You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/01/09 14:26:48 UTC
[14/50] [abbrv] Merge branch 'api_refactoring' into javelin
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30f2565d/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
----------------------------------------------------------------------
diff --cc plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
index c2971f4,cc53ee1..78fa083
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
@@@ -46,11 -28,20 +29,21 @@@ import javax.inject.Inject
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
+ import com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer;
+ import com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterCommand;
+ import com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer;
+ import com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterCommand;
+ import com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterAnswer;
+ import com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterCommand;
+ import com.cloud.agent.api.CreateLogicalRouterAnswer;
+ import com.cloud.agent.api.CreateLogicalRouterCommand;
import com.cloud.agent.api.CreateLogicalSwitchPortAnswer;
import com.cloud.agent.api.CreateLogicalSwitchPortCommand;
+ import com.cloud.agent.api.DeleteLogicalRouterAnswer;
+ import com.cloud.agent.api.DeleteLogicalRouterCommand;
import com.cloud.agent.api.DeleteLogicalSwitchPortAnswer;
import com.cloud.agent.api.DeleteLogicalSwitchPortCommand;
import com.cloud.agent.api.FindLogicalSwitchPortAnswer;
@@@ -100,7 -105,9 +107,8 @@@ import com.cloud.resource.ResourceState
import com.cloud.resource.ResourceStateAdapter;
import com.cloud.resource.ServerResource;
import com.cloud.resource.UnableDeleteHostException;
+ import com.cloud.user.Account;
import com.cloud.utils.component.AdapterBase;
-import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
@@@ -111,435 -119,832 +120,833 @@@ import com.cloud.vm.VirtualMachine
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.NicDao;
+@Component
@Local(value = NetworkElement.class)
- public class NiciraNvpElement extends AdapterBase implements ConnectivityProvider, NiciraNvpElementService, ResourceStateAdapter {
- private static final Logger s_logger = Logger.getLogger(NiciraNvpElement.class);
+ public class NiciraNvpElement extends AdapterBase implements
+ ConnectivityProvider, SourceNatServiceProvider,
+ PortForwardingServiceProvider, StaticNatServiceProvider,
+ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
+ private static final Logger s_logger = Logger
+ .getLogger(NiciraNvpElement.class);
-
- private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
-
- @Inject
- NicDao _nicDao;
- @Inject
- ResourceManager _resourceMgr;
- @Inject
- PhysicalNetworkDao _physicalNetworkDao;
- @Inject
- PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
- @Inject
- NiciraNvpDao _niciraNvpDao;
- @Inject
- HostDetailsDao _hostDetailsDao;
- @Inject
- HostDao _hostDao;
- @Inject
- AgentManager _agentMgr;
- @Inject
- NiciraNvpNicMappingDao _niciraNvpNicMappingDao;
- @Inject
+
+ private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
+
-
+ @Inject
+ NicDao _nicDao;
+ @Inject
+ ResourceManager _resourceMgr;
+ @Inject
+ PhysicalNetworkDao _physicalNetworkDao;
+ @Inject
+ PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
+ @Inject
+ NiciraNvpDao _niciraNvpDao;
+ @Inject
+ HostDetailsDao _hostDetailsDao;
+ @Inject
+ HostDao _hostDao;
+ @Inject
+ AgentManager _agentMgr;
+ @Inject
+ NiciraNvpNicMappingDao _niciraNvpNicMappingDao;
+ @Inject
+ NiciraNvpRouterMappingDao _niciraNvpRouterMappingDao;
+ @Inject
- NetworkDao _networkDao;
+ NetworkDao _networkDao;
+ @Inject
+ NetworkManager _networkManager;
+ @Inject
+ ConfigurationManager _configMgr;
+ @Inject
+ NetworkServiceMapDao _ntwkSrvcDao;
+ @Inject
+ VlanDao _vlanDao;
-
- @Override
- public Map<Service, Map<Capability, String>> getCapabilities() {
- return capabilities;
- }
-
- @Override
- public Provider getProvider() {
- return Provider.NiciraNvp;
- }
-
+
+ @Override
+ public Map<Service, Map<Capability, String>> getCapabilities() {
+ return capabilities;
+ }
+
+ @Override
+ public Provider getProvider() {
+ return Provider.NiciraNvp;
+ }
+
- private boolean canHandle(Network network) {
+ protected boolean canHandle(Network network, Service service) {
+ s_logger.debug("Checking if NiciraNvpElement can handle service "
+ + service.getName() + " on network " + network.getDisplayText());
- if (network.getBroadcastDomainType() != BroadcastDomainType.Lswitch) {
- return false;
- }
-
+ if (network.getBroadcastDomainType() != BroadcastDomainType.Lswitch) {
+ return false;
+ }
+
+ if (!_networkManager.isProviderForNetwork(getProvider(),
+ network.getId())) {
+ s_logger.debug("NiciraNvpElement is not a provider for network "
+ + network.getDisplayText());
+ return false;
+ }
+
+ if (!_ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(),
+ service, Network.Provider.NiciraNvp)) {
+ s_logger.debug("NiciraNvpElement can't provide the "
+ + service.getName() + " service on network "
+ + network.getDisplayText());
+ return false;
+ }
+
- return true;
- }
-
- @Override
- public boolean configure(String name, Map<String, Object> params)
- throws ConfigurationException {
- super.configure(name, params);
+ return true;
+ }
+
+ @Override
+ public boolean configure(String name, Map<String, Object> params)
+ throws ConfigurationException {
+ super.configure(name, params);
- _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
+ _resourceMgr.registerResourceStateAdapter(this.getClass()
+ .getSimpleName(), this);
- return true;
- }
-
- @Override
- public boolean implement(Network network, NetworkOffering offering,
- DeployDestination dest, ReservationContext context)
- throws ConcurrentOperationException, ResourceUnavailableException,
- InsufficientCapacityException {
+ return true;
+ }
+
+ @Override
+ public boolean implement(Network network, NetworkOffering offering,
+ DeployDestination dest, ReservationContext context)
+ throws ConcurrentOperationException, ResourceUnavailableException,
+ InsufficientCapacityException {
+ s_logger.debug("entering NiciraNvpElement implement function for network "
+ + network.getDisplayText()
+ + " (state "
+ + network.getState()
+ + ")");
+
+ if (!canHandle(network, Service.Connectivity)) {
+ return false;
+ }
-
+
- if (!canHandle(network)) {
+ if (network.getBroadcastUri() == null) {
+ s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
- return false;
- }
-
+ return false;
+ }
+
+ List<NiciraNvpDeviceVO> devices = _niciraNvpDao
+ .listByPhysicalNetwork(network.getPhysicalNetworkId());
+ if (devices.isEmpty()) {
+ s_logger.error("No NiciraNvp Controller on physical network "
+ + network.getPhysicalNetworkId());
+ return false;
+ }
+ NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
+ HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
+ _hostDao.loadDetails(niciraNvpHost);
+
+ Account owner = context.getAccount();
+
+ /**
+ * Lock the network as we might need to do multiple operations that
+ * should be done only once.
+ */
+ Network lock = _networkDao.acquireInLockTable(network.getId(),
+ _networkManager.getNetworkLockTimeout());
+ if (lock == null) {
+ throw new ConcurrentOperationException("Unable to lock network "
+ + network.getId());
+ }
+ try {
+ // Implement SourceNat immediately as we have al the info already
+ if (_networkManager.isProviderSupportServiceInNetwork(
+ network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
+ s_logger.debug("Apparently we are supposed to provide SourceNat on this network");
+
+ PublicIp sourceNatIp = _networkManager
+ .assignSourceNatIpAddressToGuestNetwork(owner, network);
+ String publicCidr = sourceNatIp.getAddress().addr() + "/"
+ + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask());
+ String internalCidr = network.getGateway() + "/"
+ + network.getCidr().split("/")[1];
+ long vlanid = (Vlan.UNTAGGED.equals(sourceNatIp.getVlanTag())) ? 0
+ : Long.parseLong(sourceNatIp.getVlanTag());
+
+ CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(
+ niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid,
+ network.getBroadcastUri().getSchemeSpecificPart(),
+ "router-" + network.getDisplayText(), publicCidr,
+ sourceNatIp.getGateway(), internalCidr, context
+ .getDomain().getName()
+ + "-"
+ + context.getAccount().getAccountName());
+ CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer) _agentMgr
+ .easySend(niciraNvpHost.getId(), cmd);
+ if (answer.getResult() == false) {
+ s_logger.error("Failed to create Logical Router for network "
+ + network.getDisplayText());
+ return false;
+ }
+
+ // Store the uuid so we can easily find it during cleanup
+ NiciraNvpRouterMappingVO routermapping =
+ new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId());
+ _niciraNvpRouterMappingDao.persist(routermapping);
+ }
+ } finally {
+ if (lock != null) {
+ _networkDao.releaseFromLockTable(lock.getId());
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Lock is released for network id "
+ + lock.getId() + " as a part of router startup in "
+ + dest);
+ }
+ }
+ }
- return true;
- }
-
- @Override
- public boolean prepare(Network network, NicProfile nic,
- VirtualMachineProfile<? extends VirtualMachine> vm,
- DeployDestination dest, ReservationContext context)
- throws ConcurrentOperationException, ResourceUnavailableException,
- InsufficientCapacityException {
+ return true;
+ }
+ @Override
+ public boolean prepare(Network network, NicProfile nic,
+ VirtualMachineProfile<? extends VirtualMachine> vm,
+ DeployDestination dest, ReservationContext context)
+ throws ConcurrentOperationException, ResourceUnavailableException,
+ InsufficientCapacityException {
+
- if (!canHandle(network)) {
+ if (!canHandle(network, Service.Connectivity)) {
- return false;
- }
+ return false;
+ }
- if (network.getBroadcastUri() == null) {
- s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
- return false;
- }
+ if (network.getBroadcastUri() == null) {
+ s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
+ return false;
+ }
- NicVO nicVO = _nicDao.findById(nic.getId());
+ NicVO nicVO = _nicDao.findById(nic.getId());
- List<NiciraNvpDeviceVO> devices = _niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
+ List<NiciraNvpDeviceVO> devices = _niciraNvpDao
+ .listByPhysicalNetwork(network.getPhysicalNetworkId());
- if (devices.isEmpty()) {
+ if (devices.isEmpty()) {
- s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
+ s_logger.error("No NiciraNvp Controller on physical network "
+ + network.getPhysicalNetworkId());
- return false;
- }
- NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
- HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
+ return false;
+ }
+ NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
+ HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
- NiciraNvpNicMappingVO existingNicMap = _niciraNvpNicMappingDao.findByNicUuid(nicVO.getUuid());
+ NiciraNvpNicMappingVO existingNicMap = _niciraNvpNicMappingDao
+ .findByNicUuid(nicVO.getUuid());
- if (existingNicMap != null) {
+ if (existingNicMap != null) {
- FindLogicalSwitchPortCommand findCmd = new FindLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchUuid(),
+ FindLogicalSwitchPortCommand findCmd = new FindLogicalSwitchPortCommand(
+ existingNicMap.getLogicalSwitchUuid(),
- existingNicMap.getLogicalSwitchPortUuid());
+ existingNicMap.getLogicalSwitchPortUuid());
- FindLogicalSwitchPortAnswer answer = (FindLogicalSwitchPortAnswer) _agentMgr.easySend(niciraNvpHost.getId(), findCmd);
+ FindLogicalSwitchPortAnswer answer = (FindLogicalSwitchPortAnswer) _agentMgr
+ .easySend(niciraNvpHost.getId(), findCmd);
-
- if (answer.getResult()) {
+
+ if (answer.getResult()) {
- s_logger.warn("Existing Logical Switchport found for nic " + nic.getName() + " with uuid " + existingNicMap.getLogicalSwitchPortUuid());
- UpdateLogicalSwitchPortCommand cmd = new UpdateLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchPortUuid(),
- network.getBroadcastUri().getSchemeSpecificPart(), nicVO.getUuid(),
- context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName());
+ s_logger.warn("Existing Logical Switchport found for nic "
+ + nic.getName() + " with uuid "
+ + existingNicMap.getLogicalSwitchPortUuid());
+ UpdateLogicalSwitchPortCommand cmd = new UpdateLogicalSwitchPortCommand(
+ existingNicMap.getLogicalSwitchPortUuid(), network
+ .getBroadcastUri().getSchemeSpecificPart(),
+ nicVO.getUuid(), context.getDomain().getName() + "-"
+ + context.getAccount().getAccountName(),
+ nic.getName());
- _agentMgr.easySend(niciraNvpHost.getId(), cmd);
- return true;
+ _agentMgr.easySend(niciraNvpHost.getId(), cmd);
+ return true;
- }
- else {
- s_logger.error("Stale entry found for nic " + nic.getName() + " with logical switchport uuid " + existingNicMap.getLogicalSwitchPortUuid());
+ } else {
+ s_logger.error("Stale entry found for nic " + nic.getName()
+ + " with logical switchport uuid "
+ + existingNicMap.getLogicalSwitchPortUuid());
- _niciraNvpNicMappingDao.remove(existingNicMap.getId());
- }
- }
-
+ _niciraNvpNicMappingDao.remove(existingNicMap.getId());
+ }
+ }
+
- CreateLogicalSwitchPortCommand cmd = new CreateLogicalSwitchPortCommand(network.getBroadcastUri().getSchemeSpecificPart(), nicVO.getUuid(),
- context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName());
- CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
+ CreateLogicalSwitchPortCommand cmd = new CreateLogicalSwitchPortCommand(
+ network.getBroadcastUri().getSchemeSpecificPart(),
+ nicVO.getUuid(), context.getDomain().getName() + "-"
+ + context.getAccount().getAccountName(), nic.getName());
+ CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer) _agentMgr
+ .easySend(niciraNvpHost.getId(), cmd);
-
- if (answer == null || !answer.getResult()) {
+
+ if (answer == null || !answer.getResult()) {
- s_logger.error ("CreateLogicalSwitchPortCommand failed");
+ s_logger.error("CreateLogicalSwitchPortCommand failed");
- return false;
- }
-
+ return false;
+ }
+
- NiciraNvpNicMappingVO nicMap = new NiciraNvpNicMappingVO(network.getBroadcastUri().getSchemeSpecificPart(), answer.getLogicalSwitchPortUuid(), nicVO.getUuid());
+ NiciraNvpNicMappingVO nicMap = new NiciraNvpNicMappingVO(network
+ .getBroadcastUri().getSchemeSpecificPart(),
+ answer.getLogicalSwitchPortUuid(), nicVO.getUuid());
- _niciraNvpNicMappingDao.persist(nicMap);
+ _niciraNvpNicMappingDao.persist(nicMap);
- return true;
- }
+ return true;
+ }
- @Override
- public boolean release(Network network, NicProfile nic,
- VirtualMachineProfile<? extends VirtualMachine> vm,
- ReservationContext context) throws ConcurrentOperationException,
- ResourceUnavailableException {
+ @Override
+ public boolean release(Network network, NicProfile nic,
+ VirtualMachineProfile<? extends VirtualMachine> vm,
+ ReservationContext context) throws ConcurrentOperationException,
+ ResourceUnavailableException {
- if (!canHandle(network)) {
+ if (!canHandle(network, Service.Connectivity)) {
- return false;
- }
-
- if (network.getBroadcastUri() == null) {
- s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
- return false;
- }
+ return false;
+ }
- NicVO nicVO = _nicDao.findById(nic.getId());
+ if (network.getBroadcastUri() == null) {
+ s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
+ return false;
+ }
+
+ NicVO nicVO = _nicDao.findById(nic.getId());
- List<NiciraNvpDeviceVO> devices = _niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
+ List<NiciraNvpDeviceVO> devices = _niciraNvpDao
+ .listByPhysicalNetwork(network.getPhysicalNetworkId());
- if (devices.isEmpty()) {
+ if (devices.isEmpty()) {
- s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
+ s_logger.error("No NiciraNvp Controller on physical network "
+ + network.getPhysicalNetworkId());
- return false;
- }
- NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
- HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
-
+ return false;
+ }
+ NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
+ HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
+
- NiciraNvpNicMappingVO nicMap = _niciraNvpNicMappingDao.findByNicUuid(nicVO.getUuid());
+ NiciraNvpNicMappingVO nicMap = _niciraNvpNicMappingDao
+ .findByNicUuid(nicVO.getUuid());
- if (nicMap == null) {
- s_logger.error("No mapping for nic " + nic.getName());
- return false;
- }
-
+ if (nicMap == null) {
+ s_logger.error("No mapping for nic " + nic.getName());
+ return false;
+ }
+
- DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand(nicMap.getLogicalSwitchUuid(), nicMap.getLogicalSwitchPortUuid());
- DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
+ DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand(
+ nicMap.getLogicalSwitchUuid(),
+ nicMap.getLogicalSwitchPortUuid());
+ DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer) _agentMgr
+ .easySend(niciraNvpHost.getId(), cmd);
-
- if (answer == null || !answer.getResult()) {
+
+ if (answer == null || !answer.getResult()) {
- s_logger.error ("DeleteLogicalSwitchPortCommand failed");
+ s_logger.error("DeleteLogicalSwitchPortCommand failed");
- return false;
- }
-
- _niciraNvpNicMappingDao.remove(nicMap.getId());
-
- return true;
- }
-
- @Override
- public boolean shutdown(Network network, ReservationContext context,
- boolean cleanup) throws ConcurrentOperationException,
- ResourceUnavailableException {
+ return false;
+ }
+
+ _niciraNvpNicMappingDao.remove(nicMap.getId());
+
+ return true;
+ }
+
+ @Override
+ public boolean shutdown(Network network, ReservationContext context,
+ boolean cleanup) throws ConcurrentOperationException,
+ ResourceUnavailableException {
- if (!canHandle(network)) {
+ if (!canHandle(network, Service.Connectivity)) {
+ return false;
+ }
+
+ List<NiciraNvpDeviceVO> devices = _niciraNvpDao
+ .listByPhysicalNetwork(network.getPhysicalNetworkId());
+ if (devices.isEmpty()) {
+ s_logger.error("No NiciraNvp Controller on physical network "
+ + network.getPhysicalNetworkId());
+ return false;
+ }
+ NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
+ HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
+
+ if (_networkManager.isProviderSupportServiceInNetwork(network.getId(),
+ Service.SourceNat, Provider.NiciraNvp)) {
+ s_logger.debug("Apparently we were providing SourceNat on this network");
+
+ // Deleting the LogicalRouter will also take care of all provisioned
+ // nat rules.
+ NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao
+ .findByNetworkId(network.getId());
+ if (routermapping == null) {
+ s_logger.warn("No logical router uuid found for network "
+ + network.getDisplayText());
+ // This might be cause by a failed deployment, so don't make shutdown fail as well.
+ return true;
+ }
+
+ DeleteLogicalRouterCommand cmd = new DeleteLogicalRouterCommand(routermapping.getLogicalRouterUuid());
+ DeleteLogicalRouterAnswer answer =
+ (DeleteLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
+ if (answer.getResult() == false) {
+ s_logger.error("Failed to delete LogicalRouter for network "
+ + network.getDisplayText());
- return false;
- }
+ return false;
+ }
+ _niciraNvpRouterMappingDao.remove(routermapping.getId());
+ }
+
- return true;
- }
+ return true;
+ }
- @Override
+ @Override
- public boolean destroy(Network network)
+ public boolean destroy(Network network, ReservationContext context)
- throws ConcurrentOperationException, ResourceUnavailableException {
+ throws ConcurrentOperationException, ResourceUnavailableException {
- if (!canHandle(network)) {
+ if (!canHandle(network, Service.Connectivity)) {
- return false;
- }
+ return false;
+ }
- return true;
- }
+ return true;
+ }
- @Override
- public boolean isReady(PhysicalNetworkServiceProvider provider) {
- return true;
- }
+ @Override
+ public boolean isReady(PhysicalNetworkServiceProvider provider) {
+ return true;
+ }
- @Override
- public boolean shutdownProviderInstances(
- PhysicalNetworkServiceProvider provider, ReservationContext context)
- throws ConcurrentOperationException, ResourceUnavailableException {
- // Nothing to do here.
- return true;
- }
+ @Override
+ public boolean shutdownProviderInstances(
+ PhysicalNetworkServiceProvider provider, ReservationContext context)
+ throws ConcurrentOperationException, ResourceUnavailableException {
+ // Nothing to do here.
+ return true;
+ }
- @Override
- public boolean canEnableIndividualServices() {
+ @Override
+ public boolean canEnableIndividualServices() {
- return false;
+ return true;
- }
+ }
- @Override
- public boolean verifyServicesCombination(Set<Service> services) {
+ @Override
+ public boolean verifyServicesCombination(Set<Service> services) {
+ // This element can only function in a Nicra Nvp based
+ // SDN network, so Connectivity needs to be present here
+ if (!services.contains(Service.Connectivity)) {
+ s_logger.warn("Unable to provide services without Connectivity service enabled for this element");
+ return false;
+ }
+ if ((services.contains(Service.PortForwarding) || services.contains(Service.StaticNat)) && !services.contains(Service.SourceNat)) {
+ s_logger.warn("Unable to provide StaticNat and/or PortForwarding without the SourceNat service");
+ return false;
+ }
- return true;
- }
+ return true;
+ }
- private static Map<Service, Map<Capability, String>> setCapabilities() {
- Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
+ private static Map<Service, Map<Capability, String>> setCapabilities() {
+ Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
+ // L2 Support : SDN provisioning
- capabilities.put(Service.Connectivity, null);
+ capabilities.put(Service.Connectivity, null);
+
+ // L3 Support : Generic?
+ capabilities.put(Service.Gateway, null);
+
+ // L3 Support : SourceNat
+ Map<Capability, String> sourceNatCapabilities = new HashMap<Capability, String>();
+ sourceNatCapabilities.put(Capability.SupportedSourceNatTypes,
+ "peraccount");
+ sourceNatCapabilities.put(Capability.RedundantRouter, "false");
+ capabilities.put(Service.SourceNat, sourceNatCapabilities);
+
+ // L3 Support : Port Forwarding
+ capabilities.put(Service.PortForwarding, null);
+
+ // L3 support : StaticNat
+ capabilities.put(Service.StaticNat, null);
+
- return capabilities;
- }
+ return capabilities;
+ }
- @Override
+ @Override
- public String getPropertiesFile() {
- return "nicira-nvp_commands.properties";
+ public String[] getPropertiesFiles() {
+ return new String[] { "nicira-nvp_commands.properties" };
- }
+ }
- @Override
- @DB
- public NiciraNvpDeviceVO addNiciraNvpDevice(AddNiciraNvpDeviceCmd cmd) {
- ServerResource resource = new NiciraNvpResource();
- String deviceName = Network.Provider.NiciraNvp.getName();
+ @Override
+ @DB
+ public NiciraNvpDeviceVO addNiciraNvpDevice(AddNiciraNvpDeviceCmd cmd) {
+ ServerResource resource = new NiciraNvpResource();
+ String deviceName = Network.Provider.NiciraNvp.getName();
- NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
+ NetworkDevice networkDevice = NetworkDevice
+ .getNetworkDevice(deviceName);
- Long physicalNetworkId = cmd.getPhysicalNetworkId();
- NiciraNvpDeviceVO niciraNvpDevice = null;
-
+ Long physicalNetworkId = cmd.getPhysicalNetworkId();
+ NiciraNvpDeviceVO niciraNvpDevice = null;
+
- PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
+ PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
+ .findById(physicalNetworkId);
- if (physicalNetwork == null) {
+ if (physicalNetwork == null) {
- throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
+ throw new InvalidParameterValueException(
+ "Could not find phyical network with ID: "
+ + physicalNetworkId);
- }
- long zoneId = physicalNetwork.getDataCenterId();
+ }
+ long zoneId = physicalNetwork.getDataCenterId();
- PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
+ PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao
+ .findByServiceProvider(physicalNetwork.getId(),
+ networkDevice.getNetworkServiceProvder());
- if (ntwkSvcProvider == null) {
+ if (ntwkSvcProvider == null) {
- throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() +
- " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
+ throw new CloudRuntimeException("Network Service Provider: "
+ + networkDevice.getNetworkServiceProvder()
+ + " is not enabled in the physical network: "
+ + physicalNetworkId + "to add this device");
- } else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
+ } else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
- throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() +
- " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
+ throw new CloudRuntimeException("Network Service Provider: "
+ + ntwkSvcProvider.getProviderName()
+ + " is in shutdown state in the physical network: "
+ + physicalNetworkId + "to add this device");
- }
-
- if (_niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
+ }
+
+ if (_niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
- throw new CloudRuntimeException("A NiciraNvp device is already configured on this physical network");
+ throw new CloudRuntimeException(
+ "A NiciraNvp device is already configured on this physical network");
- }
-
+ }
+
- Map<String, String> params = new HashMap<String,String>();
+ Map<String, String> params = new HashMap<String, String>();
- params.put("guid", UUID.randomUUID().toString());
- params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
- params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
- params.put("name", "Nicira Controller - " + cmd.getHost());
- params.put("ip", cmd.getHost());
- params.put("adminuser", cmd.getUsername());
- params.put("adminpass", cmd.getPassword());
- params.put("transportzoneuuid", cmd.getTransportzoneUuid());
+ params.put("guid", UUID.randomUUID().toString());
+ params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
+ params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
+ params.put("name", "Nicira Controller - " + cmd.getHost());
+ params.put("ip", cmd.getHost());
+ params.put("adminuser", cmd.getUsername());
+ params.put("adminpass", cmd.getPassword());
+ params.put("transportzoneuuid", cmd.getTransportzoneUuid());
- params.put("transportzoneisotype", physicalNetwork.getIsolationMethods().get(0).toLowerCase()); // FIXME What to do with multiple isolation types
-
- Map<String, Object> hostdetails = new HashMap<String,Object>();
+ // FIXME What to do with multiple isolation types
+ params.put("transportzoneisotype",
+ physicalNetwork.getIsolationMethods().get(0).toLowerCase());
+ if (cmd.getL3GatewayServiceUuid() != null) {
+ params.put("l3gatewayserviceuuid", cmd.getL3GatewayServiceUuid());
+ }
+
+ Map<String, Object> hostdetails = new HashMap<String, Object>();
- hostdetails.putAll(params);
-
- Transaction txn = Transaction.currentTxn();
- try {
- resource.configure(cmd.getHost(), hostdetails);
-
+ hostdetails.putAll(params);
+
-
+ Transaction txn = Transaction.currentTxn();
+ try {
+ resource.configure(cmd.getHost(), hostdetails);
+
- Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
+ Host host = _resourceMgr.addHost(zoneId, resource,
+ Host.Type.L2Networking, params);
- if (host != null) {
- txn.start();
-
+ if (host != null) {
+ txn.start();
+
- niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
+ niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(),
+ physicalNetworkId, ntwkSvcProvider.getProviderName(),
+ deviceName);
- _niciraNvpDao.persist(niciraNvpDevice);
-
+ _niciraNvpDao.persist(niciraNvpDevice);
+
- DetailVO detail = new DetailVO(host.getId(), "niciranvpdeviceid", String.valueOf(niciraNvpDevice.getId()));
+ DetailVO detail = new DetailVO(host.getId(),
+ "niciranvpdeviceid", String.valueOf(niciraNvpDevice
+ .getId()));
- _hostDetailsDao.persist(detail);
+ _hostDetailsDao.persist(detail);
- txn.commit();
- return niciraNvpDevice;
- } else {
+ txn.commit();
+ return niciraNvpDevice;
+ } else {
- throw new CloudRuntimeException("Failed to add Nicira Nvp Device due to internal error.");
+ throw new CloudRuntimeException(
+ "Failed to add Nicira Nvp Device due to internal error.");
- }
- } catch (ConfigurationException e) {
- txn.rollback();
- throw new CloudRuntimeException(e.getMessage());
- }
- }
+ }
+ } catch (ConfigurationException e) {
+ txn.rollback();
+ throw new CloudRuntimeException(e.getMessage());
+ }
+ }
- @Override
- public NiciraNvpDeviceResponse createNiciraNvpDeviceResponse(
- NiciraNvpDeviceVO niciraNvpDeviceVO) {
+ @Override
+ public NiciraNvpDeviceResponse createNiciraNvpDeviceResponse(
+ NiciraNvpDeviceVO niciraNvpDeviceVO) {
+ HostVO niciraNvpHost = _hostDao.findById(niciraNvpDeviceVO.getHostId());
+ _hostDao.loadDetails(niciraNvpHost);
+
- NiciraNvpDeviceResponse response = new NiciraNvpDeviceResponse();
- response.setDeviceName(niciraNvpDeviceVO.getDeviceName());
+ NiciraNvpDeviceResponse response = new NiciraNvpDeviceResponse();
+ response.setDeviceName(niciraNvpDeviceVO.getDeviceName());
- response.setPhysicalNetworkId(niciraNvpDeviceVO.getPhysicalNetworkId());
- response.setId(niciraNvpDeviceVO.getId());
+ PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(niciraNvpDeviceVO.getPhysicalNetworkId());
+ if (pnw != null) {
+ response.setPhysicalNetworkId(pnw.getUuid());
+ }
+ response.setId(niciraNvpDeviceVO.getUuid());
- response.setProviderName(niciraNvpDeviceVO.getProviderName());
+ response.setProviderName(niciraNvpDeviceVO.getProviderName());
+ response.setHostName(niciraNvpHost.getDetail("ip"));
+ response.setTransportZoneUuid(niciraNvpHost.getDetail("transportzoneuuid"));
+ response.setL3GatewayServiceUuid(niciraNvpHost.getDetail("l3gatewayserviceuuid"));
+ response.setObjectName("niciranvpdevice");
- return response;
- }
-
- @Override
- public boolean deleteNiciraNvpDevice(DeleteNiciraNvpDeviceCmd cmd) {
- Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
+ return response;
+ }
+
+ @Override
+ public boolean deleteNiciraNvpDevice(DeleteNiciraNvpDeviceCmd cmd) {
+ Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
- NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao.findById(niciraDeviceId);
+ NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao
+ .findById(niciraDeviceId);
- if (niciraNvpDevice == null) {
+ if (niciraNvpDevice == null) {
- throw new InvalidParameterValueException("Could not find a nicira device with id " + niciraDeviceId);
+ throw new InvalidParameterValueException(
+ "Could not find a nicira device with id " + niciraDeviceId);
- }
-
- // Find the physical network we work for
- Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
+ }
+
+ // Find the physical network we work for
+ Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
- PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
+ PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
+ .findById(physicalNetworkId);
- if (physicalNetwork != null) {
- // Lets see if there are networks that use us
- // Find the nicira networks on this physical network
+ if (physicalNetwork != null) {
+ // Lets see if there are networks that use us
+ // Find the nicira networks on this physical network
- List<NetworkVO> networkList = _networkDao.listByPhysicalNetwork(physicalNetworkId);
+ List<NetworkVO> networkList = _networkDao
+ .listByPhysicalNetwork(physicalNetworkId);
-
- // Networks with broadcast type lswitch are ours
- for (NetworkVO network : networkList) {
- if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
+
+ // Networks with broadcast type lswitch are ours
+ for (NetworkVO network : networkList) {
+ if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
- if ((network.getState() != Network.State.Shutdown) && (network.getState() != Network.State.Destroy)) {
- throw new CloudRuntimeException("This Nicira Nvp device can not be deleted as there are one or more logical networks provisioned by cloudstack.");
+ if ((network.getState() != Network.State.Shutdown)
+ && (network.getState() != Network.State.Destroy)) {
+ throw new CloudRuntimeException(
+ "This Nicira Nvp device can not be deleted as there are one or more logical networks provisioned by cloudstack.");
- }
- }
- }
- }
-
- HostVO niciraHost = _hostDao.findById(niciraNvpDevice.getHostId());
- Long hostId = niciraHost.getId();
-
- niciraHost.setResourceState(ResourceState.Maintenance);
- _hostDao.update(hostId, niciraHost);
- _resourceMgr.deleteHost(hostId, false, false);
-
- _niciraNvpDao.remove(niciraDeviceId);
- return true;
- }
-
- @Override
+ }
+ }
+ }
+ }
+
+ HostVO niciraHost = _hostDao.findById(niciraNvpDevice.getHostId());
+ Long hostId = niciraHost.getId();
+
+ niciraHost.setResourceState(ResourceState.Maintenance);
+ _hostDao.update(hostId, niciraHost);
+ _resourceMgr.deleteHost(hostId, false, false);
+
+ _niciraNvpDao.remove(niciraDeviceId);
-
+ return true;
+ }
+
+ @Override
- public List<NiciraNvpDeviceVO> listNiciraNvpDevices(ListNiciraNvpDevicesCmd cmd) {
+ public List<NiciraNvpDeviceVO> listNiciraNvpDevices(
+ ListNiciraNvpDevicesCmd cmd) {
- Long physicalNetworkId = cmd.getPhysicalNetworkId();
- Long niciraNvpDeviceId = cmd.getNiciraNvpDeviceId();
- List<NiciraNvpDeviceVO> responseList = new ArrayList<NiciraNvpDeviceVO>();
-
- if (physicalNetworkId == null && niciraNvpDeviceId == null) {
+ Long physicalNetworkId = cmd.getPhysicalNetworkId();
+ Long niciraNvpDeviceId = cmd.getNiciraNvpDeviceId();
+ List<NiciraNvpDeviceVO> responseList = new ArrayList<NiciraNvpDeviceVO>();
+
+ if (physicalNetworkId == null && niciraNvpDeviceId == null) {
- throw new InvalidParameterValueException("Either physical network Id or nicira device Id must be specified");
+ throw new InvalidParameterValueException(
+ "Either physical network Id or nicira device Id must be specified");
- }
-
- if (niciraNvpDeviceId != null) {
+ }
+
+ if (niciraNvpDeviceId != null) {
- NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao.findById(niciraNvpDeviceId);
+ NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao
+ .findById(niciraNvpDeviceId);
- if (niciraNvpDevice == null) {
+ if (niciraNvpDevice == null) {
- throw new InvalidParameterValueException("Could not find Nicira Nvp device with id: " + niciraNvpDevice);
+ throw new InvalidParameterValueException(
+ "Could not find Nicira Nvp device with id: "
+ + niciraNvpDevice);
- }
- responseList.add(niciraNvpDevice);
+ }
+ responseList.add(niciraNvpDevice);
- }
- else {
- PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
+ } else {
+ PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
+ .findById(physicalNetworkId);
- if (physicalNetwork == null) {
+ if (physicalNetwork == null) {
- throw new InvalidParameterValueException("Could not find a physical network with id: " + physicalNetworkId);
+ throw new InvalidParameterValueException(
+ "Could not find a physical network with id: "
+ + physicalNetworkId);
- }
+ }
- responseList = _niciraNvpDao.listByPhysicalNetwork(physicalNetworkId);
+ responseList = _niciraNvpDao
+ .listByPhysicalNetwork(physicalNetworkId);
- }
-
- return responseList;
- }
-
- @Override
+ }
+
+ return responseList;
+ }
+
+ @Override
- public List<? extends Network> listNiciraNvpDeviceNetworks(ListNiciraNvpDeviceNetworksCmd cmd) {
+ public List<? extends Network> listNiciraNvpDeviceNetworks(
+ ListNiciraNvpDeviceNetworksCmd cmd) {
- Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
+ Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
- NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao.findById(niciraDeviceId);
+ NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao
+ .findById(niciraDeviceId);
- if (niciraNvpDevice == null) {
+ if (niciraNvpDevice == null) {
- throw new InvalidParameterValueException("Could not find a nicira device with id " + niciraDeviceId);
+ throw new InvalidParameterValueException(
+ "Could not find a nicira device with id " + niciraDeviceId);
- }
-
- // Find the physical network we work for
- Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
+ }
+
+ // Find the physical network we work for
+ Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
- PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
+ PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
+ .findById(physicalNetworkId);
- if (physicalNetwork == null) {
- // No such physical network, so no provisioned networks
- return Collections.emptyList();
- }
-
- // Find the nicira networks on this physical network
+ if (physicalNetwork == null) {
+ // No such physical network, so no provisioned networks
+ return Collections.emptyList();
+ }
+
+ // Find the nicira networks on this physical network
- List<NetworkVO> networkList = _networkDao.listByPhysicalNetwork(physicalNetworkId);
+ List<NetworkVO> networkList = _networkDao
+ .listByPhysicalNetwork(physicalNetworkId);
-
- // Networks with broadcast type lswitch are ours
- List<NetworkVO> responseList = new ArrayList<NetworkVO>();
- for (NetworkVO network : networkList) {
- if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
- responseList.add(network);
- }
- }
-
- return responseList;
- }
-
- @Override
- public HostVO createHostVOForConnectedAgent(HostVO host,
- StartupCommand[] cmd) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public HostVO createHostVOForDirectConnectAgent(HostVO host,
- StartupCommand[] startup, ServerResource resource,
- Map<String, String> details, List<String> hostTags) {
- if (!(startup[0] instanceof StartupNiciraNvpCommand)) {
- return null;
- }
- host.setType(Host.Type.L2Networking);
- return host;
- }
-
- @Override
- public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
- boolean isForceDeleteStorage) throws UnableDeleteHostException {
- if (!(host.getType() == Host.Type.L2Networking)) {
- return null;
- }
- return new DeleteHostAnswer(true);
- }
+
+ // Networks with broadcast type lswitch are ours
+ List<NetworkVO> responseList = new ArrayList<NetworkVO>();
+ for (NetworkVO network : networkList) {
+ if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
+ responseList.add(network);
+ }
+ }
+
+ return responseList;
+ }
+
+ @Override
+ public HostVO createHostVOForConnectedAgent(HostVO host,
+ StartupCommand[] cmd) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public HostVO createHostVOForDirectConnectAgent(HostVO host,
+ StartupCommand[] startup, ServerResource resource,
+ Map<String, String> details, List<String> hostTags) {
+ if (!(startup[0] instanceof StartupNiciraNvpCommand)) {
+ return null;
+ }
+ host.setType(Host.Type.L2Networking);
+ return host;
+ }
+
+ @Override
+ public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
+ boolean isForceDeleteStorage) throws UnableDeleteHostException {
+ if (!(host.getType() == Host.Type.L2Networking)) {
+ return null;
+ }
+ return new DeleteHostAnswer(true);
+ }
+ /**
+ * From interface SourceNatServiceProvider
+ */
+ @Override
+ public IpDeployer getIpDeployer(Network network) {
+ return this;
+ }
+
+ /**
+ * From interface IpDeployer
+ *
+ * @param network
+ * @param ipAddress
+ * @param services
+ * @return
+ * @throws ResourceUnavailableException
+ */
+ @Override
+ public boolean applyIps(Network network,
+ List<? extends PublicIpAddress> ipAddress, Set<Service> services)
+ throws ResourceUnavailableException {
+ if (services.contains(Service.SourceNat)) {
+ // Only if we need to provide SourceNat we need to configure the logical router
+ // SourceNat is required for StaticNat and PortForwarding
+ List<NiciraNvpDeviceVO> devices = _niciraNvpDao
+ .listByPhysicalNetwork(network.getPhysicalNetworkId());
+ if (devices.isEmpty()) {
+ s_logger.error("No NiciraNvp Controller on physical network "
+ + network.getPhysicalNetworkId());
+ return false;
+ }
+ NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
+ HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
+ _hostDao.loadDetails(niciraNvpHost);
+
+ NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao
+ .findByNetworkId(network.getId());
+ if (routermapping == null) {
+ s_logger.error("No logical router uuid found for network "
+ + network.getDisplayText());
+ return false;
+ }
+
+ List<String> cidrs = new ArrayList<String>();
+ for (PublicIpAddress ip : ipAddress) {
+ cidrs.add(ip.getAddress().addr() + "/" + NetUtils.getCidrSize(ip.getNetmask()));
+ }
+ ConfigurePublicIpsOnLogicalRouterCommand cmd = new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(),
+ niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs);
+ ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
+ //FIXME answer can be null if the host is down
+ return answer.getResult();
+ }
+ else {
+ s_logger.debug("No need to provision ip addresses as we are not providing L3 services.");
+ }
+
+ return true;
+ }
+
+ /**
+ * From interface StaticNatServiceProvider
+ */
+ @Override
+ public boolean applyStaticNats(Network network,
+ List<? extends StaticNat> rules)
+ throws ResourceUnavailableException {
+ if (!canHandle(network, Service.StaticNat)) {
+ return false;
+ }
+
+ List<NiciraNvpDeviceVO> devices = _niciraNvpDao
+ .listByPhysicalNetwork(network.getPhysicalNetworkId());
+ if (devices.isEmpty()) {
+ s_logger.error("No NiciraNvp Controller on physical network "
+ + network.getPhysicalNetworkId());
+ return false;
+ }
+ NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
+ HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
+
+ NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao
+ .findByNetworkId(network.getId());
+ if (routermapping == null) {
+ s_logger.error("No logical router uuid found for network "
+ + network.getDisplayText());
+ return false;
+ }
+
+ List<StaticNatRuleTO> staticNatRules = new ArrayList<StaticNatRuleTO>();
+ for (StaticNat rule : rules) {
+ IpAddress sourceIp = _networkManager.getIp(rule.getSourceIpAddressId());
+ // Force the nat rule into the StaticNatRuleTO, no use making a new TO object
+ // we only need the source and destination ip. Unfortunately no mention if a rule
+ // is new.
+ StaticNatRuleTO ruleTO = new StaticNatRuleTO(1,
+ sourceIp.getAddress().addr(), 0, 65535,
+ rule.getDestIpAddress(), 0, 65535,
+ "any", rule.isForRevoke(), false);
+ staticNatRules.add(ruleTO);
+ }
+
+ ConfigureStaticNatRulesOnLogicalRouterCommand cmd =
+ new ConfigureStaticNatRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), staticNatRules);
+ ConfigureStaticNatRulesOnLogicalRouterAnswer answer = (ConfigureStaticNatRulesOnLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
+
+ return answer.getResult();
+ }
+
+ /**
+ * From interface PortForwardingServiceProvider
+ */
+ @Override
+ public boolean applyPFRules(Network network, List<PortForwardingRule> rules)
+ throws ResourceUnavailableException {
+ if (!canHandle(network, Service.PortForwarding)) {
+ return false;
+ }
+
+ List<NiciraNvpDeviceVO> devices = _niciraNvpDao
+ .listByPhysicalNetwork(network.getPhysicalNetworkId());
+ if (devices.isEmpty()) {
+ s_logger.error("No NiciraNvp Controller on physical network "
+ + network.getPhysicalNetworkId());
+ return false;
+ }
+ NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
+ HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
+
+ NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao
+ .findByNetworkId(network.getId());
+ if (routermapping == null) {
+ s_logger.error("No logical router uuid found for network "
+ + network.getDisplayText());
+ return false;
+ }
+
+ List<PortForwardingRuleTO> portForwardingRules = new ArrayList<PortForwardingRuleTO>();
+ for (PortForwardingRule rule : rules) {
+ IpAddress sourceIp = _networkManager.getIp(rule.getSourceIpAddressId());
+ Vlan vlan = _vlanDao.findById(sourceIp.getVlanId());
+ PortForwardingRuleTO ruleTO = new PortForwardingRuleTO((PortForwardingRule) rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
+ portForwardingRules.add(ruleTO);
+ }
+
+ ConfigurePortForwardingRulesOnLogicalRouterCommand cmd =
+ new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
+ ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
+
+ return answer.getResult();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30f2565d/plugins/network-elements/nicira-nvp/src/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30f2565d/plugins/network-elements/ovs/src/com/cloud/network/element/OvsElement.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30f2565d/plugins/user-authenticators/ldap/src/com/cloud/server/auth/LDAPUserAuthenticator.java
----------------------------------------------------------------------
diff --cc plugins/user-authenticators/ldap/src/com/cloud/server/auth/LDAPUserAuthenticator.java
index a5733ca,358605a..00b4c1f
--- a/plugins/user-authenticators/ldap/src/com/cloud/server/auth/LDAPUserAuthenticator.java
+++ b/plugins/user-authenticators/ldap/src/com/cloud/server/auth/LDAPUserAuthenticator.java
@@@ -40,10 -39,9 +39,10 @@@ import com.cloud.server.ManagementServe
import com.cloud.user.UserAccount;
import com.cloud.user.dao.UserAccountDao;
import com.cloud.utils.component.ComponentLocator;
- import com.cloud.utils.crypt.DBEncryptionUtil;
+ import com.cloud.utils.exception.CloudRuntimeException;
+@Component
@Local(value={UserAuthenticator.class})
public class LDAPUserAuthenticator extends DefaultUserAuthenticator {
public static final Logger s_logger = Logger.getLogger(LDAPUserAuthenticator.class);
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30f2565d/plugins/user-authenticators/md5/src/com/cloud/server/auth/MD5UserAuthenticator.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30f2565d/plugins/user-authenticators/plain-text/src/com/cloud/server/auth/PlainTextUserAuthenticator.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30f2565d/pom.xml
----------------------------------------------------------------------
diff --cc pom.xml
index f2b0cf2,59e3bac..1417996
--- a/pom.xml
+++ b/pom.xml
@@@ -159,11 -163,18 +163,21 @@@
<module>patches</module>
<module>client</module>
<module>test</module>
+ <module>engine</module>
+ <module>framework</module>
+ <module>tools/devcloud</module>
</modules>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>${cs.mysql.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
<dependency>
<groupId>junit</groupId>
@@@ -380,41 -310,46 +313,46 @@@
<configuration>
<source>${cs.jdk.version}</source>
<target>${cs.jdk.version}</target>
- <fork>true</fork>
- <meminitial>128m</meminitial>
- <maxmem>512m</maxmem>
+ <fork>true</fork>
+ <meminitial>128m</meminitial>
+ <maxmem>512m</maxmem>
</configuration>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.4</version>
- <configuration>
- <archive>
- <manifest>
- <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
- <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <version>1.7</version>
- <executions>
- <execution>
- <id>remove-old-installers</id>
- <goals>
- <goal>remove-project-artifact</goal>
- </goals>
- <configuration>
- <removeAll>true</removeAll>
- </configuration>
- </execution>
- </executions>
- </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.7</version>
+ <executions>
+ <execution>
+ <id>remove-old-installers</id>
+ <goals>
+ <goal>remove-project-artifact</goal>
+ </goals>
+ <configuration>
+ <removeAll>true</removeAll>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.5.1</version>
+ </plugin>
+ <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30f2565d/server/src/com/cloud/acl/DomainChecker.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/acl/DomainChecker.java
index af2798a,9bb1cce..40564fe
--- a/server/src/com/cloud/acl/DomainChecker.java
+++ b/server/src/com/cloud/acl/DomainChecker.java
@@@ -17,14 -17,12 +17,15 @@@
package com.cloud.acl;
import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.springframework.stereotype.Component;
- import com.cloud.api.BaseCmd;
+ import org.apache.cloudstack.acl.ControlledEntity;
+ import org.apache.cloudstack.acl.SecurityChecker;
+ import org.apache.cloudstack.api.BaseCmd;
import com.cloud.dc.DataCenter;
import com.cloud.domain.Domain;
- import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.network.Network;
@@@ -40,18 -38,24 +41,23 @@@ import com.cloud.user.Account
import com.cloud.user.User;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.component.AdapterBase;
-import com.cloud.utils.component.Inject;
- @Component
- @Local(value=SecurityChecker.class)
+ @Local(value = SecurityChecker.class)
public class DomainChecker extends AdapterBase implements SecurityChecker {
-
+
- @Inject DomainDao _domainDao;
- @Inject AccountDao _accountDao;
- @Inject LaunchPermissionDao _launchPermissionDao;
- @Inject ProjectManager _projectMgr;
- @Inject ProjectAccountDao _projecAccountDao;
- @Inject NetworkManager _networkMgr;
+ @Inject
+ DomainDao _domainDao;
+ @Inject
+ AccountDao _accountDao;
+ @Inject
+ LaunchPermissionDao _launchPermissionDao;
+ @Inject
+ ProjectManager _projectMgr;
+ @Inject
+ ProjectAccountDao _projecAccountDao;
+ @Inject
+ NetworkManager _networkMgr;
-
+
protected DomainChecker() {
super();
}
@@@ -86,8 -90,8 +92,8 @@@
@Override
public boolean checkAccess(Account caller, ControlledEntity entity, AccessType accessType) throws PermissionDeniedException {
if (entity instanceof VirtualMachineTemplate) {
-
+
- VirtualMachineTemplate template = (VirtualMachineTemplate)entity;
+ VirtualMachineTemplate template = (VirtualMachineTemplate) entity;
Account owner = _accountDao.findById(template.getAccountId());
// validate that the template is usable by the account
if (!template.isPublicTemplate()) {
@@@ -109,10 -113,10 +115,10 @@@
}
}
}
-
+
return true;
} else if (entity instanceof Network && accessType != null && accessType == AccessType.UseNetwork) {
- _networkMgr.checkNetworkPermissions(caller, (Network)entity);
+ _networkMgr.checkNetworkPermissions(caller, (Network) entity);
} else {
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
Account account = _accountDao.findById(entity.getAccountId());
@@@ -143,168 -147,142 +149,142 @@@
return checkAccess(account, entity, null);
}
- @Override
+ @Override
- public boolean checkAccess(Account account, DiskOffering dof) throws PermissionDeniedException
- {
- if(account == null || dof.getDomainId() == null)
- {//public offering
+ public boolean checkAccess(Account account, DiskOffering dof) throws PermissionDeniedException {
+ if (account == null || dof.getDomainId() == null) {//public offering
- return true;
+ return true;
- }
- else
- {
+ } else {
- //admin has all permissions
+ //admin has all permissions
- if(account.getType() == Account.ACCOUNT_TYPE_ADMIN)
- {
+ if (account.getType() == Account.ACCOUNT_TYPE_ADMIN) {
- return true;
- }
- //if account is normal user or domain admin
- //check if account's domain is a child of zone's domain (Note: This is made consistent with the list command for disk offering)
+ return true;
+ }
+ //if account is normal user or domain admin
+ //check if account's domain is a child of zone's domain (Note: This is made consistent with the list command for disk offering)
- else if(account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)
- {
- if(account.getDomainId() == dof.getDomainId())
- {
+ else if (account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
+ if (account.getDomainId() == dof.getDomainId()) {
- return true; //disk offering and account at exact node
+ return true; //disk offering and account at exact node
- }
- else
- {
- DomainVO domainRecord = _domainDao.findById(account.getDomainId());
- if(domainRecord != null)
- {
- while(true)
- {
- if(domainRecord.getId() == dof.getDomainId())
- {
+ } else {
+ Domain domainRecord = _domainDao.findById(account.getDomainId());
+ if (domainRecord != null) {
+ while (true) {
+ if (domainRecord.getId() == dof.getDomainId()) {
- //found as a child
- return true;
- }
+ //found as a child
+ return true;
+ }
- if(domainRecord.getParent() != null) {
+ if (domainRecord.getParent() != null) {
domainRecord = _domainDao.findById(domainRecord.getParent());
} else {
break;
}
- }
- }
- }
- }
- }
- //not found
- return false;
- }
+ }
+ }
+ }
+ }
+ }
+ //not found
+ return false;
+ }
- @Override
+ @Override
- public boolean checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException
- {
- if(account == null || so.getDomainId() == null)
- {//public offering
+ public boolean checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException {
+ if (account == null || so.getDomainId() == null) {//public offering
- return true;
+ return true;
- }
- else
- {
+ } else {
- //admin has all permissions
+ //admin has all permissions
- if(account.getType() == Account.ACCOUNT_TYPE_ADMIN)
- {
+ if (account.getType() == Account.ACCOUNT_TYPE_ADMIN) {
- return true;
- }
- //if account is normal user or domain admin
- //check if account's domain is a child of zone's domain (Note: This is made consistent with the list command for service offering)
+ return true;
+ }
+ //if account is normal user or domain admin
+ //check if account's domain is a child of zone's domain (Note: This is made consistent with the list command for service offering)
- else if(account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)
- {
- if(account.getDomainId() == so.getDomainId())
- {
+ else if (account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
+ if (account.getDomainId() == so.getDomainId()) {
- return true; //service offering and account at exact node
+ return true; //service offering and account at exact node
- }
- else
- {
- DomainVO domainRecord = _domainDao.findById(account.getDomainId());
- if(domainRecord != null)
- {
- while(true)
- {
- if(domainRecord.getId() == so.getDomainId())
- {
+ } else {
+ Domain domainRecord = _domainDao.findById(account.getDomainId());
+ if (domainRecord != null) {
+ while (true) {
+ if (domainRecord.getId() == so.getDomainId()) {
- //found as a child
- return true;
- }
+ //found as a child
+ return true;
+ }
- if(domainRecord.getParent() != null) {
+ if (domainRecord.getParent() != null) {
domainRecord = _domainDao.findById(domainRecord.getParent());
} else {
break;
}
- }
- }
- }
- }
- }
- //not found
- return false;
- }
-
- @Override
- public boolean checkAccess(Account account, DataCenter zone) throws PermissionDeniedException {
+ }
+ }
+ }
+ }
+ }
+ //not found
+ return false;
+ }
+
+ @Override
+ public boolean checkAccess(Account account, DataCenter zone) throws PermissionDeniedException {
- if(account == null || zone.getDomainId() == null){//public zone
+ if (account == null || zone.getDomainId() == null) {//public zone
- return true;
+ return true;
- }else{
+ } else {
- //admin has all permissions
+ //admin has all permissions
- if(account.getType() == Account.ACCOUNT_TYPE_ADMIN){
+ if (account.getType() == Account.ACCOUNT_TYPE_ADMIN) {
- return true;
- }
- //if account is normal user
- //check if account's domain is a child of zone's domain
+ return true;
+ }
+ //if account is normal user
+ //check if account's domain is a child of zone's domain
- else if(account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_PROJECT){
- if(account.getDomainId() == zone.getDomainId()){
+ else if (account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
+ if (account.getDomainId() == zone.getDomainId()) {
- return true; //zone and account at exact node
+ return true; //zone and account at exact node
- }else{
- DomainVO domainRecord = _domainDao.findById(account.getDomainId());
- if(domainRecord != null)
- {
- while(true){
- if(domainRecord.getId() == zone.getDomainId()){
+ } else {
+ Domain domainRecord = _domainDao.findById(account.getDomainId());
+ if (domainRecord != null) {
+ while (true) {
+ if (domainRecord.getId() == zone.getDomainId()) {
- //found as a child
- return true;
- }
+ //found as a child
+ return true;
+ }
- if(domainRecord.getParent() != null) {
+ if (domainRecord.getParent() != null) {
domainRecord = _domainDao.findById(domainRecord.getParent());
} else {
break;
}
- }
- }
- }
- //not found
- return false;
- }
- //if account is domain admin
- //check if the account's domain is either child of zone's domain, or if zone's domain is child of account's domain
+ }
+ }
+ }
+ //not found
+ return false;
+ }
+ //if account is domain admin
+ //check if the account's domain is either child of zone's domain, or if zone's domain is child of account's domain
- else if(account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN){
- if(account.getDomainId() == zone.getDomainId()){
+ else if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
+ if (account.getDomainId() == zone.getDomainId()) {
- return true; //zone and account at exact node
+ return true; //zone and account at exact node
- }else{
- DomainVO zoneDomainRecord = _domainDao.findById(zone.getDomainId());
- DomainVO accountDomainRecord = _domainDao.findById(account.getDomainId());
- if(accountDomainRecord != null)
- {
- DomainVO localRecord = accountDomainRecord;
- while(true){
- if(localRecord.getId() == zone.getDomainId()){
+ } else {
+ Domain zoneDomainRecord = _domainDao.findById(zone.getDomainId());
+ Domain accountDomainRecord = _domainDao.findById(account.getDomainId());
+ if (accountDomainRecord != null) {
+ Domain localRecord = accountDomainRecord;
+ while (true) {
+ if (localRecord.getId() == zone.getDomainId()) {
- //found as a child
- return true;
- }
+ //found as a child
+ return true;
+ }
- if(localRecord.getParent() != null) {
+ if (localRecord.getParent() != null) {
localRecord = _domainDao.findById(localRecord.getParent());
} else {
break;
}
- }
- }
- //didn't find in upper tree
+ }
+ }
+ //didn't find in upper tree
- if(zoneDomainRecord.getPath().contains(accountDomainRecord.getPath())){
+ if (zoneDomainRecord.getPath().contains(accountDomainRecord.getPath())) {
- return true;
- }
- }
- //not found
- return false;
- }
- }
- return false;
- }
+ return true;
+ }
+ }
+ //not found
+ return false;
+ }
+ }
+ return false;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30f2565d/server/src/com/cloud/agent/manager/AgentManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/agent/manager/AgentManagerImpl.java
index d37bd15,8141fdb..1ffab59
--- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java
+++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java
@@@ -218,9 -216,10 +218,10 @@@ public class AgentManagerImpl implement
protected int _pingInterval;
protected long _pingTimeout;
- protected AgentMonitor _monitor = null;
+ @Inject protected AgentMonitor _monitor = null;
protected ExecutorService _executor;
+ protected ThreadPoolExecutor _connectExecutor;
protected StateMachine2<Status, Status.Event, Host> _statusStateMachine = Status.getStateMachine();
@@@ -276,7 -275,12 +277,12 @@@
registerForHostEvents(_monitor, true, true, false);
_executor = new ThreadPoolExecutor(threads, threads, 60l, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("AgentTaskPool"));
-
+
+ _connectExecutor = new ThreadPoolExecutor(100, 500, 60l, TimeUnit.SECONDS,
+ new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("AgentConnectTaskPool"));
+ //allow core threads to time out even when there are no items in the queue
+ _connectExecutor.allowCoreThreadTimeOut(true);
+
_connection = new NioServer("AgentManager", _port, workers + 10, this);
s_logger.info("Listening on " + _port + " with " + workers + " workers");
@@@ -1087,91 -1096,37 +1098,37 @@@
return attache;
}
- //TODO: handle mycloud specific
private AgentAttache handleConnectedAgent(final Link link, final StartupCommand[] startup, Request request) {
AgentAttache attache = null;
- StartupAnswer[] answers = new StartupAnswer[startup.length];
+ ReadyCommand ready = null;
- try {
- HostVO host = _resourceMgr.createHostVOForConnectedAgent(startup);
+ try {
+ HostVO host = _resourceMgr.createHostVOForConnectedAgent(startup);
if (host != null) {
+ ready = new ReadyCommand(host.getDataCenterId(), host.getId());
attache = createAttacheForConnect(host, link);
+ attache = notifyMonitorsOfConnection(attache, startup, false);
}
- Command cmd;
- for (int i = 0; i < startup.length; i++) {
- cmd = startup[i];
- if ((cmd instanceof StartupRoutingCommand) || (cmd instanceof StartupProxyCommand) || (cmd instanceof StartupSecondaryStorageCommand) || (cmd instanceof StartupStorageCommand)) {
- answers[i] = new StartupAnswer(startup[i], attache.getId(), getPingInterval());
- break;
- }
- }
- }catch (ConnectionException e) {
- Command cmd;
- for (int i = 0; i < startup.length; i++) {
- cmd = startup[i];
- if ((cmd instanceof StartupRoutingCommand) || (cmd instanceof StartupProxyCommand) || (cmd instanceof StartupSecondaryStorageCommand) || (cmd instanceof StartupStorageCommand)) {
- answers[i] = new StartupAnswer(startup[i], e.toString());
- break;
- }
- }
- } catch (IllegalArgumentException e) {
- Command cmd;
- for (int i = 0; i < startup.length; i++) {
- cmd = startup[i];
- if ((cmd instanceof StartupRoutingCommand) || (cmd instanceof StartupProxyCommand) || (cmd instanceof StartupSecondaryStorageCommand) || (cmd instanceof StartupStorageCommand)) {
- answers[i] = new StartupAnswer(startup[i], e.toString());
- break;
- }
- }
- } catch (CloudRuntimeException e) {
- Command cmd;
- for (int i = 0; i < startup.length; i++) {
- cmd = startup[i];
- if ((cmd instanceof StartupRoutingCommand) || (cmd instanceof StartupProxyCommand) || (cmd instanceof StartupSecondaryStorageCommand) || (cmd instanceof StartupStorageCommand)) {
- answers[i] = new StartupAnswer(startup[i], e.toString());
- break;
- }
- }
+ } catch (Exception e) {
+ s_logger.debug("Failed to handle host connection: " + e.toString());
+ ready = new ReadyCommand(null);
+ ready.setDetails(e.toString());
+ } finally {
+ if (ready == null) {
+ ready = new ReadyCommand(null);
- }
+ }
}
try {
- link.send(response.toBytes());
- } catch (ClosedChannelException e) {
- s_logger.debug("Failed to send startupanswer: " + e.toString());
- return null;
- }
- if (attache == null) {
+ if (attache == null) {
- return null;
- }
-
- try {
- attache = notifyMonitorsOfConnection(attache, startup, false);
- return attache;
- } catch (ConnectionException e) {
- ReadyCommand ready = new ReadyCommand(null);
- ready.setDetails(e.toString());
- try {
+ final Request readyRequest = new Request(-1, -1, ready, false);
+ link.send(readyRequest.getBytes());
+ } else {
easySend(attache.getId(), ready);
- } catch (Exception e1) {
- s_logger.debug("Failed to send readycommand, due to " + e.toString());
}
- return null;
- } catch (CloudRuntimeException e) {
- ReadyCommand ready = new ReadyCommand(null);
- ready.setDetails(e.toString());
- try {
- easySend(attache.getId(), ready);
- } catch (Exception e1) {
- s_logger.debug("Failed to send readycommand, due to " + e.toString());
- }
- return null;
+ } catch (Exception e) {
+ s_logger.debug("Failed to send ready command:" + e.toString());
}
+ return attache;
}
protected class SimulateStartTask implements Runnable {
@@@ -1205,7 -1160,54 +1162,54 @@@
}
}
}
-
+
+ protected class HandleAgentConnectTask implements Runnable {
+ Link _link;
+ Command[] _cmds;
+ Request _request;
+
+ HandleAgentConnectTask(Link link, final Command[] cmds, final Request request) {
+ _link = link;
+ _cmds = cmds;
+ _request = request;
+ }
+
+ @Override
+ public void run() {
+ _request.logD("Processing the first command ");
+ StartupCommand[] startups = new StartupCommand[_cmds.length];
+ for (int i = 0; i < _cmds.length; i++) {
+ startups[i] = (StartupCommand) _cmds[i];
+ }
+
+ AgentAttache attache = handleConnectedAgent(_link, startups, _request);
+ if (attache == null) {
+ s_logger.warn("Unable to create attache for agent: " + _request);
+ }
+ }
+ }
+
+ protected void connectAgent(Link link, final Command[] cmds, final Request request) {
+ //send startupanswer to agent in the very beginning, so agent can move on without waiting for the answer for an undetermined time, if we put this logic into another thread pool.
+ StartupAnswer[] answers = new StartupAnswer[cmds.length];
+ Command cmd;
+ for (int i = 0; i < cmds.length; i++) {
+ cmd = cmds[i];
+ if ((cmd instanceof StartupRoutingCommand) || (cmd instanceof StartupProxyCommand) || (cmd instanceof StartupSecondaryStorageCommand) || (cmd instanceof StartupStorageCommand)) {
+ answers[i] = new StartupAnswer((StartupCommand)cmds[i], 0, getPingInterval());
+ break;
+ }
+ }
+ Response response = null;
+ response = new Response(request, answers[0], _nodeId, -1);
+ try {
+ link.send(response.toBytes());
+ } catch (ClosedChannelException e) {
+ s_logger.debug("Failed to send startupanswer: " + e.toString());
+ }
+ _connectExecutor.execute(new HandleAgentConnectTask(link, cmds, request));
+ }
+
public class AgentHandler extends Task {
public AgentHandler(Task.Type type, Link link, byte[] data) {
super(type, link, data);
@@@ -1297,18 -1291,24 +1293,24 @@@
if (cmd instanceof PingRoutingCommand) {
boolean gatewayAccessible = ((PingRoutingCommand) cmd).isGatewayAccessible();
HostVO host = _hostDao.findById(Long.valueOf(cmdHostId));
+
+ if (host != null) {
- if (!gatewayAccessible) {
- // alert that host lost connection to
- // gateway (cannot ping the default route)
- DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
- HostPodVO podVO = _podDao.findById(host.getPodId());
- String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
-
- _alertMgr.sendAlert(AlertManager.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId(), "Host lost connection to gateway, " + hostDesc, "Host [" + hostDesc
- + "] lost connection to gateway (default route) and is possibly having network connection issues.");
- } else {
- _alertMgr.clearAlert(AlertManager.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId());
- }
+ if (!gatewayAccessible) {
+ // alert that host lost connection to
+ // gateway (cannot ping the default route)
+ DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
+ HostPodVO podVO = _podDao.findById(host.getPodId());
+ String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
+
+ _alertMgr.sendAlert(AlertManager.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId(), "Host lost connection to gateway, " + hostDesc, "Host [" + hostDesc
+ + "] lost connection to gateway (default route) and is possibly having network connection issues.");
+ } else {
+ _alertMgr.clearAlert(AlertManager.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId());
+ }
+ } else {
+ s_logger.debug("Not processing " + PingRoutingCommand.class.getSimpleName() +
+ " for agent id=" + cmdHostId + "; can't find the host in the DB");
+ }
}
answer = new PingAnswer((PingCommand) cmd);
} else if (cmd instanceof ReadyAnswer) {
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30f2565d/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
index 4f09954,ca0bf5c..8c6bae8
--- a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
+++ b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
@@@ -274,10 -271,10 +275,10 @@@ public class ClusteredAgentManagerImpl
}
@Override
- protected boolean handleDisconnectWithoutInvestigation(AgentAttache attache, Status.Event event) {
+ protected boolean handleDisconnectWithoutInvestigation(AgentAttache attache, Status.Event event, boolean transitState) {
return handleDisconnect(attache, event, false, true);
}
-
+
@Override
protected boolean handleDisconnectWithInvestigation(AgentAttache attache, Status.Event event) {
return handleDisconnect(attache, event, true, true);
@@@ -856,8 -879,8 +883,8 @@@
_hostTransferDao.completeAgentTransfer(hostId);
continue;
}
-
+
- if (transferMap.getInitialOwner() != _nodeId || attache.forForward()) {
+ if (transferMap.getInitialOwner() != _nodeId || attache == null || attache.forForward()) {
s_logger.debug("Management server " + _nodeId + " doesn't own host id=" + hostId + " any more, skipping rebalance for the host");
iterator.remove();
_hostTransferDao.completeAgentTransfer(hostId);
@@@ -940,9 -963,24 +967,24 @@@
HostVO host = _hostDao.findById(hostId);
try {
if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Disconnecting host " + host.getId() + "(" + host.getName() + " as a part of rebalance process without notification");
+ }
+
+ AgentAttache attache = findAttache(hostId);
+ if (attache != null) {
+ result = handleDisconnect(attache, Event.AgentDisconnected, false, false);
+ }
+
+ if (result) {
+ if (s_logger.isDebugEnabled()) {
- s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process");
- }
- result = loadDirectlyConnectedHost(host, true);
+ s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process");
+ }
+ result = loadDirectlyConnectedHost(host, true);
+ } else {
+ s_logger.warn("Failed to disconnect " + host.getId() + "(" + host.getName() +
+ " as a part of rebalance process without notification");
+ }
+
} catch (Exception ex) {
s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process due to:", ex);
result = false;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30f2565d/server/src/com/cloud/alert/AlertManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/alert/AlertManagerImpl.java
index 9fb9a21,a4c0fac..4fbc695
--- a/server/src/com/cloud/alert/AlertManagerImpl.java
+++ b/server/src/com/cloud/alert/AlertManagerImpl.java
@@@ -72,8 -70,8 +72,7 @@@ import com.cloud.storage.StoragePoolVO
import com.cloud.storage.dao.StoragePoolDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.utils.NumbersUtil;
- import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentLocator;
-import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.SearchCriteria;
import com.sun.mail.smtp.SMTPMessage;