diff --git a/server/src/com/cloud/api/commands/AddCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/AddCiscoNexusVSMCmd.java index f8950fd91fe..412891bf1ed 100644 --- a/server/src/com/cloud/api/commands/AddCiscoNexusVSMCmd.java +++ b/server/src/com/cloud/api/commands/AddCiscoNexusVSMCmd.java @@ -129,16 +129,6 @@ public class AddCiscoNexusVSMCmd extends BaseCmd { throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); } } - - //@Override - //public String getEventDescription() { - // return "Adding a Cisco Nexus VSM device"; - //} - - //@Override - //public String getEventType() { - // return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_ADD; - //} @Override public String getCommandName() { diff --git a/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java index e2ea2cb90f3..aca0dc89425 100644 --- a/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java +++ b/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java @@ -51,15 +51,15 @@ public class DeleteCiscoNexusVSMCmd extends BaseCmd { ///////////////////////////////////////////////////// @IdentityMapper(entityTableName="virtual_supervisor_module") - @Parameter(name=ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_ID, type=CommandType.LONG, required=true, description="Cisco Nexus 1000v VSM device ID") - private Long vsmDeviceId; + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Id of the Cisco Nexus 1000v VSM device to be deleted") + private Long id; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// public Long getCiscoNexusVSMDeviceId() { - return vsmDeviceId; + return id; } ///////////////////////////////////////////////////// @@ -84,16 +84,6 @@ public class DeleteCiscoNexusVSMCmd extends BaseCmd { } } - @Override - public String getEventDescription() { - return "Deleting a Cisco Nexus 1000v VSM device"; - } - - @Override - public String getEventType() { - return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE; - } - @Override public String getCommandName() { return s_name; diff --git a/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java b/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java index ea040d32dcb..52a368994a7 100644 --- a/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java +++ b/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java @@ -188,12 +188,12 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase { // Next, check if this VSM is reachable. Use the XML-RPC VSM API Java bindings to talk to // the VSM. //NetconfHelper (String ip, String username, String password) - + CiscoNexusVSM vsmObj = new CiscoNexusVSM(ipaddress, username, password); if (!vsmObj.connectToVSM()) { throw new CloudRuntimeException("Couldn't login to the specified VSM"); } - + // Now, go ahead and associate the cluster with this VSM. // First, check if VSM already exists in the table "virtual_supervisor_module". // If it's not there already, create it. @@ -213,8 +213,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase { //CiscoNexusVSMDeviceVO VSMObj = _ciscoNexusVSMDeviceDao.getVSMbyDomainId(1); - if (VSMObj == null) { - s_logger.info("no record found.. will create one"); + if (VSMObj == null) { // Create the VSM record. For now, we aren't using the vsmName field. VSMObj = new CiscoNexusVSMDeviceVO(ipaddress, username, password, vCenterIpaddr, vCenterDcName); Transaction txn = Transaction.currentTxn(); @@ -253,8 +252,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase { // into each host's resource. Also, we first configure each resource's // entries in the database to contain this VSM information before the injection. - for (HostVO host : hosts) { - s_logger.info("inside for loop!"); + for (HostVO host : hosts) { // Create a host details VO object and write it out for this hostid. long vsmId = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress).getId(); Long hostid = new Long(vsmId); @@ -281,7 +279,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase { } @DB - public boolean deleteCiscoNexusVSM(long vsmId) throws ResourceInUseException { + public boolean deleteCiscoNexusVSM(long vsmId) throws ResourceInUseException { CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId); if (cisconexusvsm == null) { // This entry is already not present. Return success. @@ -290,14 +288,21 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase { // First, check whether this VSM is part of any non-empty cluster. // Search ClusterVSMMap's table for a list of clusters using this vsmId. + List clusterList = _clusterVSMDao.listByVSMId(vsmId); - for (ClusterVSMMapVO record : clusterList) { - // If this cluster id has any hosts in it, fail this operation. - Long clusterId = record.getClusterId(); - List hosts = _resourceMgr.listAllHostsInCluster(clusterId); - if (hosts != null && hosts.size() > 0) { - throw new ResourceInUseException("Non-empty cluster with id" + clusterId + "still uses VSM. Please empty the cluster first"); + if (clusterList != null) { + for (ClusterVSMMapVO record : clusterList) { + // If this cluster id has any hosts in it, fail this operation. + Long clusterId = record.getClusterId(); + List hosts = _resourceMgr.listAllHostsInCluster(clusterId); + if (hosts != null && hosts.size() > 0) { + for (Host host: hosts) { + if (host.getType() == Host.Type.Routing) { + throw new ResourceInUseException("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first"); + } + } + } } } @@ -305,19 +310,17 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase { Transaction txn = Transaction.currentTxn(); try { txn.start(); - for (ClusterVSMMapVO record : clusterList) { - // Remove the VSM entry in CiscoNexusVSMDeviceVO's table. - _ciscoNexusVSMDeviceDao.remove(vsmId); - // Remove the current record as well from ClusterVSMMapVO's table. - _clusterVSMDao.removeByVsmId(vsmId); - // There are no hosts at this stage in the cluster, so we don't need - // to notify any resources or remove host details. - } - txn.commit(); - } catch (CloudRuntimeException e) { - throw e; - } - + // Remove the VSM entry in CiscoNexusVSMDeviceVO's table. + _ciscoNexusVSMDeviceDao.remove(vsmId); + // Remove the current record as well from ClusterVSMMapVO's table. + _clusterVSMDao.removeByVsmId(vsmId); + // There are no hosts at this stage in the cluster, so we don't need + // to notify any resources or remove host details. + txn.commit(); + } catch (Exception e) { + s_logger.info("Caught exception when trying to delete VSM record.." + e.getMessage()); + throw new CloudRuntimeException("Failed to delete VSM"); + } return true; } diff --git a/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java b/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java index 9686d0156b9..c4c7e5c8fca 100644 --- a/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java +++ b/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java @@ -63,7 +63,7 @@ public class CiscoNexusVSMDeviceDaoImpl extends GenericDaoBase sc = domainIdSearch.create(); sc.setParameters("vsmSwitchDomainId", domId); diff --git a/server/src/com/cloud/network/element/CiscoNexusVSMElement.java b/server/src/com/cloud/network/element/CiscoNexusVSMElement.java index a32fed2291d..653a10502d2 100644 --- a/server/src/com/cloud/network/element/CiscoNexusVSMElement.java +++ b/server/src/com/cloud/network/element/CiscoNexusVSMElement.java @@ -45,7 +45,6 @@ import com.cloud.network.Network.Service; import com.cloud.network.dao.NetworkDao; import com.cloud.network.dao.NetworkServiceMapDao; import com.cloud.network.dao.PhysicalNetworkDao; -import com.cloud.resource.ServerResource; import com.cloud.utils.component.Inject; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; @@ -55,6 +54,8 @@ import com.cloud.network.PortProfile; import com.cloud.network.element.NetworkElement; import com.cloud.offering.NetworkOffering; import com.cloud.utils.component.Manager; +import com.cloud.exception.ResourceInUseException; +import com.cloud.utils.exception.CloudRuntimeException; @Local(value = NetworkElement.class) public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl implements CiscoNexusVSMElementService, NetworkElement, Manager { @@ -186,7 +187,15 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme @Override public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd) { - return true; + boolean result; + try { + result = deleteCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId()); + } catch (ResourceInUseException e) { + s_logger.info("VSM could not be deleted"); + // TODO: Throw a better exception here. + throw new CloudRuntimeException("Failed to delete specified VSM"); + } + return result; }