mirror of https://github.com/apache/cloudstack.git
Cleaning up code and enhancing a few IP management logs (#4714)
* Cleanup unnecessary code and enhance a few log messages at IpAddressManagerImpl * Add toString method for DataCenterVO * line too long
This commit is contained in:
parent
66e7bdedac
commit
0d8b4de1b2
|
|
@ -476,5 +476,4 @@ public class DataCenterVO implements DataCenter {
|
|||
public String toString() {
|
||||
return String.format("Zone {\"id\": \"%s\", \"name\": \"%s\", \"uuid\": \"%s\"}", id, name, uuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,7 +129,6 @@ public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase<NetworkOffe
|
|||
@Override
|
||||
public List<String> listProvidersForServiceForNetworkOffering(long networkOfferingId, Service service) {
|
||||
SearchCriteria<String> sc = ProvidersSearch.create();
|
||||
;
|
||||
|
||||
sc.setParameters("networkOfferingId", networkOfferingId);
|
||||
sc.setParameters("service", service.getName());
|
||||
|
|
@ -140,21 +139,16 @@ public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase<NetworkOffe
|
|||
@Override
|
||||
public boolean isProviderForNetworkOffering(long networkOfferingId, Provider provider) {
|
||||
SearchCriteria<NetworkOfferingServiceMapVO> sc = AllFieldsSearch.create();
|
||||
;
|
||||
|
||||
sc.setParameters("networkOfferingId", networkOfferingId);
|
||||
sc.setParameters("provider", provider.getName());
|
||||
|
||||
if (findOneBy(sc) != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return findOneBy(sc) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listServicesForNetworkOffering(long networkOfferingId) {
|
||||
SearchCriteria<String> sc = ServicesSearch.create();
|
||||
;
|
||||
sc.setParameters("networkOfferingId", networkOfferingId);
|
||||
return customSearch(sc, null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -840,11 +840,11 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||
}
|
||||
|
||||
if (vlanUse == VlanType.VirtualNetwork) {
|
||||
if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
|
||||
if (!dedicatedVlanDbIds.isEmpty()) {
|
||||
fetchFromDedicatedRange = true;
|
||||
sc.setParameters("vlanId", dedicatedVlanDbIds.toArray());
|
||||
errorMessage.append(", vlanId id=" + Arrays.toString(dedicatedVlanDbIds.toArray()));
|
||||
} else if (nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
|
||||
} else if (!nonDedicatedVlanDbIds.isEmpty()) {
|
||||
sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
|
||||
errorMessage.append(", vlanId id=" + Arrays.toString(nonDedicatedVlanDbIds.toArray()));
|
||||
} else {
|
||||
|
|
@ -904,7 +904,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||
if ((!lockOneRow || (lockOneRow && addrs.size() == 0)) && fetchFromDedicatedRange && vlanUse == VlanType.VirtualNetwork) {
|
||||
// Verify if account is allowed to acquire IPs from the system
|
||||
boolean useSystemIps = UseSystemPublicIps.valueIn(owner.getId());
|
||||
if (useSystemIps && nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
|
||||
if (useSystemIps && !nonDedicatedVlanDbIds.isEmpty()) {
|
||||
fetchFromDedicatedRange = false;
|
||||
sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
|
||||
errorMessage.append(", vlanId id=" + Arrays.toString(nonDedicatedVlanDbIds.toArray()));
|
||||
|
|
@ -1130,6 +1130,10 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||
return success;
|
||||
}
|
||||
|
||||
private String generateErrorMessageForOperationOnDisabledZone(String operation, DataCenter zone) {
|
||||
return String.format("Cannot %s, %s is currently disabled.", operation, zone);
|
||||
}
|
||||
|
||||
@DB
|
||||
@Override
|
||||
public AcquirePodIpCmdResponse allocatePodIp(String zoneId, String podId) throws ConcurrentOperationException, ResourceAllocationException {
|
||||
|
|
@ -1137,8 +1141,8 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||
DataCenter zone = _entityMgr.findByUuid(DataCenter.class, zoneId);
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) {
|
||||
ResourceAllocationException ex = new ResourceAllocationException("Cannot perform this operation, " + "Zone is currently disabled" + "zoneId=" + zone.getUuid(),
|
||||
ResourceType.network);
|
||||
ResourceAllocationException ex = new ResourceAllocationException(
|
||||
generateErrorMessageForOperationOnDisabledZone("allocate Pod IP addresses", zone), ResourceType.network);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -1148,7 +1152,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||
HostPodVO podvo = null;
|
||||
podvo = _hpDao.findByUuid(podId);
|
||||
if (podvo == null)
|
||||
throw new ResourceAllocationException("No sush pod exists", ResourceType.network);
|
||||
throw new ResourceAllocationException("No such pod exists", ResourceType.network);
|
||||
|
||||
vo = _privateIPAddressDao.takeIpAddress(zone.getId(), podvo.getId(), 0, caller.getId() + "", false);
|
||||
if(vo == null)
|
||||
|
|
@ -1187,7 +1191,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||
DataCenter zone = _entityMgr.findById(DataCenter.class, ipVO.getDataCenterId());
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) {
|
||||
throw new CloudRuntimeException("Cannot perform this operation, " + "Zone is currently disabled" + "zoneId=" + ipVO.getDataCenterId());
|
||||
throw new CloudRuntimeException(generateErrorMessageForOperationOnDisabledZone("release Pod IP", zone));
|
||||
}
|
||||
try {
|
||||
_privateIPAddressDao.releasePodIpAddress(id);
|
||||
|
|
@ -1207,7 +1211,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||
|
||||
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) {
|
||||
// zone is of type DataCenter. See DataCenterVO.java.
|
||||
PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, " + "Zone is currently disabled");
|
||||
PermissionDeniedException ex = new PermissionDeniedException(generateErrorMessageForOperationOnDisabledZone("allocate IP addresses", zone));
|
||||
ex.addProxyObject(zone.getUuid(), "zoneId");
|
||||
throw ex;
|
||||
}
|
||||
|
|
@ -1391,7 +1395,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||
}
|
||||
|
||||
if (ipToAssoc.getAssociatedWithNetworkId() != null) {
|
||||
s_logger.debug("IP " + ipToAssoc + " is already assocaited with network id" + networkId);
|
||||
s_logger.debug("IP " + ipToAssoc + " is already associated with network id" + networkId);
|
||||
return ipToAssoc;
|
||||
}
|
||||
|
||||
|
|
@ -1469,7 +1473,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||
s_logger.warn("Failed to associate ip address, so releasing ip from the database " + ip);
|
||||
_ipAddressDao.markAsUnavailable(ip.getId());
|
||||
if (!applyIpAssociations(network, true)) {
|
||||
// if fail to apply ip assciations again, unassign ip address without updating resource
|
||||
// if fail to apply ip associations again, unassign ip address without updating resource
|
||||
// count and generating usage event as there is no need to keep it in the db
|
||||
_ipAddressDao.unassignIpAddress(ip.getId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1554,6 +1554,7 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel, Confi
|
|||
if (!checkedProvider.contains(providerName)) {
|
||||
result = result && isProviderEnabledInPhysicalNetwork(physicalNtwkId, providerName);
|
||||
}
|
||||
checkedProvider.add(providerName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue