UI: Zone wizard fix (#7588)

Co-authored-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
dahn 2023-07-03 11:56:52 +02:00 committed by GitHub
parent 31dbdd0f5c
commit 1275db4081
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 25 deletions

View File

@ -274,7 +274,7 @@ public interface ConfigurationService {
/** /**
* Edits a zone in the database. Will not allow you to edit DNS values if there are VMs in the specified zone. * Edits a zone in the database. Will not allow you to edit DNS values if there are VMs in the specified zone.
* *
* @param UpdateZoneCmd * @param cmd command object containing the id of the zone to update and relevant attributes
* @return Updated zone * @return Updated zone
*/ */
DataCenter editZone(UpdateZoneCmd cmd); DataCenter editZone(UpdateZoneCmd cmd);
@ -282,8 +282,7 @@ public interface ConfigurationService {
/** /**
* Deletes a zone from the database. Will not allow you to delete zones that are being used anywhere in the system. * Deletes a zone from the database. Will not allow you to delete zones that are being used anywhere in the system.
* *
* @param userId * @param cmd command object containg the zoneid
* @param zoneId
*/ */
boolean deleteZone(DeleteZoneCmd cmd); boolean deleteZone(DeleteZoneCmd cmd);
@ -319,13 +318,12 @@ public interface ConfigurationService {
Vlan updateVlanAndPublicIpRange(UpdateVlanIpRangeCmd cmd) throws ConcurrentOperationException, Vlan updateVlanAndPublicIpRange(UpdateVlanIpRangeCmd cmd) throws ConcurrentOperationException,
ResourceUnavailableException, ResourceAllocationException; ResourceUnavailableException, ResourceAllocationException;
/** /**
* Marks the the account with the default zone-id. * Marks the account with the default zone-id.
* *
* @param accountName * @param accountName
* @param domainId * @param domainId
* @param zoneId * @param defaultZoneId
* @return The new account object * @return The new account object
* @throws ,
*/ */
Account markDefaultZone(String accountName, long domainId, long defaultZoneId); Account markDefaultZone(String accountName, long domainId, long defaultZoneId);

View File

@ -41,6 +41,7 @@ import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import javax.persistence.EntityExistsException;
import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd; import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
import org.apache.cloudstack.api.command.admin.zone.ImportVsphereStoragePoliciesCmd; import org.apache.cloudstack.api.command.admin.zone.ImportVsphereStoragePoliciesCmd;
@ -1171,12 +1172,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
// Association of VMware DC to zone is not allowed if zone already has resources added. // Association of VMware DC to zone is not allowed if zone already has resources added.
validateZoneWithResources(zoneId, "add VMware datacenter to zone"); validateZoneWithResources(zoneId, "add VMware datacenter to zone");
// Check if DC is already part of zone checkIfDcIsUsed(vCenterHost, vmwareDcName, zoneId);
// In that case vmware_data_center table should have the DC
vmwareDc = vmwareDcDao.getVmwareDatacenterByGuid(vmwareDcName + "@" + vCenterHost);
if (vmwareDc != null) {
throw new ResourceInUseException("This DC is already part of other CloudStack zone(s). Cannot add this DC to more zones.");
}
VmwareContext context = null; VmwareContext context = null;
DatacenterMO dcMo = null; DatacenterMO dcMo = null;
@ -1210,11 +1206,9 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
throw new ResourceInUseException("This DC is being managed by other CloudStack deployment. Cannot add this DC to zone."); throw new ResourceInUseException("This DC is being managed by other CloudStack deployment. Cannot add this DC to zone.");
} }
// Add DC to database into vmware_data_center table vmwareDc = createOrUpdateDc(guid, vmwareDcName, vCenterHost, userName, password);
vmwareDc = new VmwareDatacenterVO(guid, vmwareDcName, vCenterHost, userName, password);
vmwareDc = vmwareDcDao.persist(vmwareDc);
// Map zone with vmware datacenter // Map zone with vmware datacenter
vmwareDcZoneMap = new VmwareDatacenterZoneMapVO(zoneId, vmwareDc.getId()); vmwareDcZoneMap = new VmwareDatacenterZoneMapVO(zoneId, vmwareDc.getId());
vmwareDcZoneMap = vmwareDatacenterZoneMapDao.persist(vmwareDcZoneMap); vmwareDcZoneMap = vmwareDatacenterZoneMapDao.persist(vmwareDcZoneMap);
@ -1243,6 +1237,41 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
return vmwareDc; return vmwareDc;
} }
VmwareDatacenterVO createOrUpdateDc(String guid, String name, String host, String user, String password) {
VmwareDatacenterVO vmwareDc = new VmwareDatacenterVO(guid, name, host, user, password);
// Add DC to database into vmware_data_center table
try {
vmwareDc = vmwareDcDao.persist(vmwareDc);
} catch (EntityExistsException e) {
// if that fails just get the record as is
vmwareDc = vmwareDcDao.getVmwareDatacenterByGuid(guid);
// we could now update the `vmwareDC` with the user supplied `password`, `user`, `name` and `host`,
// but let's assume user error for now
}
return vmwareDc;
}
/**
* Check if DC is already part of zone
* In that case vmware_data_center table should have the DC and a dc zone mapping should exist
*
* @param vCenterHost
* @param vmwareDcName
* @param zoneId
* @throws ResourceInUseException if the DC can not be used.
*/
private void checkIfDcIsUsed(String vCenterHost, String vmwareDcName, Long zoneId) throws ResourceInUseException {
VmwareDatacenterVO vmwareDc;
vmwareDc = vmwareDcDao.getVmwareDatacenterByGuid(vmwareDcName + "@" + vCenterHost);
if (vmwareDc != null) {
VmwareDatacenterZoneMapVO mapping = vmwareDatacenterZoneMapDao.findByVmwareDcId(vmwareDc.getId());
if (mapping != null && Long.compare(zoneId, mapping.getZoneId()) == 0) {
throw new ResourceInUseException(String.format("This DC (%s) is already part of other CloudStack zone (%d). Cannot add this DC to more zones.", vmwareDc.getUuid(), zoneId));
}
}
}
@Override @Override
@ActionEvent(eventType = EventTypes.EVENT_ZONE_EDIT, eventDescription = "updating VMware datacenter") @ActionEvent(eventType = EventTypes.EVENT_ZONE_EDIT, eventDescription = "updating VMware datacenter")
public VmwareDatacenter updateVmwareDatacenter(UpdateVmwareDcCmd cmd) { public VmwareDatacenter updateVmwareDatacenter(UpdateVmwareDcCmd cmd) {

View File

@ -2367,10 +2367,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new CloudRuntimeException(errorMsg + "there are Secondary storages in this zone"); throw new CloudRuntimeException(errorMsg + "there are Secondary storages in this zone");
} }
// Check if there are any non-removed VMware datacenters in the zone. // We could check if there are any non-removed VMware datacenters in the zone. EWe don´t care.
//if (_vmwareDatacenterZoneMapDao.findByZoneId(zoneId) != null) { // These can continu to exist as long as the mapping will be gone (see line deleteZone
// throw new CloudRuntimeException(errorMsg + "there are VMware datacenters in this zone.");
//}
} }
private void checkZoneParameters(final String zoneName, final String dns1, final String dns2, final String internalDns1, final String internalDns2, final boolean checkForDuplicates, final Long domainId, private void checkZoneParameters(final String zoneName, final String dns1, final String dns2, final String internalDns1, final String internalDns2, final boolean checkForDuplicates, final Long domainId,
@ -2510,6 +2508,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
for (final VlanVO vlan : vlans) { for (final VlanVO vlan : vlans) {
_vlanDao.remove(vlan.getId()); _vlanDao.remove(vlan.getId());
} }
// we should actually find the mapping and remove if it exists
// but we don't know about vmware/plugin/hypervisors at this point
final boolean success = _zoneDao.remove(zoneId); final boolean success = _zoneDao.remove(zoneId);

View File

@ -546,7 +546,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
} }
// save cluster details for later cluster/host cross-checking // save cluster details for later cluster/host cross-checking
final Map<String, String> details = new HashMap<String, String>(); final Map<String, String> details = new HashMap<>();
details.put("url", url); details.put("url", url);
details.put("username", StringUtils.defaultString(username)); details.put("username", StringUtils.defaultString(username));
details.put("password", StringUtils.defaultString(password)); details.put("password", StringUtils.defaultString(password));

View File

@ -345,7 +345,7 @@ export default {
params.internaldns1 = this.prefillContent?.internalDns1 || null params.internaldns1 = this.prefillContent?.internalDns1 || null
params.internaldns2 = this.prefillContent?.internalDns2 || null params.internaldns2 = this.prefillContent?.internalDns2 || null
params.domain = this.prefillContent?.networkDomain || null params.domain = this.prefillContent?.networkDomain || null
params.isedge = this.prefillContent?.zoneSuperType === 'Edge' || false params.isedge = this.isEdgeZone
try { try {
if (!this.stepData.stepMove.includes('createZone')) { if (!this.stepData.stepMove.includes('createZone')) {
@ -835,7 +835,10 @@ export default {
const params = {} const params = {}
params.zoneId = this.stepData.zoneReturned.id params.zoneId = this.stepData.zoneReturned.id
params.name = this.prefillContent?.podName || this.stepData.zoneReturned.type === 'Edge' ? 'Pod-' + this.stepData.zoneReturned.name : null params.name = this.prefillContent?.podName || null
if (this.isEdgeZone) {
params.name = 'Pod-' + this.stepData.zoneReturned.name
}
params.gateway = this.prefillContent?.podReservedGateway || null params.gateway = this.prefillContent?.podReservedGateway || null
params.netmask = this.prefillContent?.podReservedNetmask || null params.netmask = this.prefillContent?.podReservedNetmask || null
params.startIp = this.prefillContent?.podReservedStartIp || null params.startIp = this.prefillContent?.podReservedStartIp || null
@ -1218,7 +1221,10 @@ export default {
} }
params.clustertype = clusterType params.clustertype = clusterType
params.podId = this.stepData.podReturned.id params.podId = this.stepData.podReturned.id
let clusterName = this.prefillContent.clusterName || this.stepData.zoneReturned.type === 'Edge' ? 'Cluster-' + this.stepData.zoneReturned.name : null let clusterName = this.prefillContent?.clusterName || null
if (this.isEdgeZone) {
clusterName = 'Cluster-' + this.stepData.zoneReturned.name
}
if (hypervisor === 'VMware') { if (hypervisor === 'VMware') {
params.username = this.prefillContent?.vCenterUsername || null params.username = this.prefillContent?.vCenterUsername || null
@ -2051,7 +2057,7 @@ export default {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let message = '' let message = ''
api('addCluster', args).then(json => { api('addCluster', args, 'POST').then(json => {
const result = json.addclusterresponse.cluster[0] const result = json.addclusterresponse.cluster[0]
resolve(result) resolve(result)
}).catch(error => { }).catch(error => {