Skip to content

Commit f1128a0

Browse files
committed
Merge branch '4.20' of https://github.com/apache/cloudstack into support-xen84-py3
2 parents 3059871 + 603cd84 commit f1128a0

File tree

16 files changed

+164
-124
lines changed

16 files changed

+164
-124
lines changed

plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,17 @@ private List<Host> findSuitableHosts(VirtualMachineProfile vmProfile, Deployment
9494
return suitableHosts;
9595
}
9696
String offeringHostTag = offering.getHostTag();
97+
9798
VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate();
9899
String templateTag = template.getTemplateTag();
99100
String hostTag = null;
100-
if (ObjectUtils.anyNull(offeringHostTag, templateTag)) {
101-
hostTag = offeringHostTag;
102-
hostTag = hostTag == null ? templateTag : String.format("%s, %s", hostTag, templateTag);
103-
logger.debug(String.format("Looking for hosts in dc [%s], pod [%s], cluster [%s] and complying with host tag(s): [%s]", dcId, podId, clusterId, hostTag));
101+
if (ObjectUtils.anyNotNull(offeringHostTag, templateTag)) {
102+
hostTag = ObjectUtils.allNotNull(offeringHostTag, templateTag) ?
103+
String.format("%s, %s", offeringHostTag, templateTag) :
104+
ObjectUtils.firstNonNull(offeringHostTag, templateTag);
105+
logger.debug("Looking for hosts in dc [{}], pod [{}], cluster [{}] and complying with host tag(s): [{}]", dcId, podId, clusterId, hostTag);
104106
} else {
105-
logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId);
107+
logger.debug("Looking for hosts in dc: {} pod: {} cluster: {}", dcId , podId, clusterId);
106108
}
107109
if (hosts != null) {
108110
// retain all computing hosts, regardless of whether they support routing...it's random after all

plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,8 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal
776776

777777
if (answer != null && answer.getResult()) {
778778
// successfully downloaded template to primary storage
779-
answer = createVolumeSnapshot(cmd, size, conn, volName, dstTO);
779+
TemplateObjectTO templ = (TemplateObjectTO) ((CopyCmdAnswer) answer).getNewData();
780+
answer = createVolumeSnapshot(cmd, size, conn, volName, templ);
780781
} else {
781782
err = answer != null ? answer.getDetails() : "Unknown error while downloading template. Null answer returned.";
782783
}
@@ -983,7 +984,6 @@ private Answer createVolumeSnapshot(StorageSubSystemCommand cmd, Long size, SpCo
983984
} else {
984985
dstTO.setPath(StorPoolUtil.devPath(
985986
StorPoolUtil.getSnapshotNameFromResponse(resp, false, StorPoolUtil.GLOBAL_ID)));
986-
dstTO.setSize(size);
987987
answer = new CopyCmdAnswer(dstTO);
988988
}
989989
return answer;

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import javax.inject.Inject;
2626
import javax.naming.ConfigurationException;
2727

28-
import com.cloud.utils.exception.CloudRuntimeException;
2928
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3029
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
3130
import org.springframework.stereotype.Component;
@@ -130,8 +129,8 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
130129
// FirstFitAllocator should be used for user VMs only since it won't care whether the host is capable of routing or not
131130
return new ArrayList<>();
132131
}
133-
134-
logger.debug("Looking for hosts in zone [{}], pod [{}], cluster [{}]", dcId, podId, clusterId);
132+
String paramAsStringToLog = String.format("zone [%s], pod [%s], cluster [%s]", dcId, podId, clusterId);
133+
logger.debug("Looking for hosts in {}", paramAsStringToLog);
135134

136135
String hostTagOnOffering = offering.getHostTag();
137136
String hostTagOnTemplate = template.getTemplateTag();
@@ -203,8 +202,8 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
203202

204203

205204
if (clusterHosts.isEmpty()) {
206-
logger.error("No suitable host found for vm [{}] with tags [{}].", vmProfile, hostTagOnOffering);
207-
throw new CloudRuntimeException(String.format("No suitable host found for vm [%s].", vmProfile));
205+
logger.warn("No suitable host found for VM [{}] with tags {} in {}.", vmProfile, hostTagOnOffering, paramAsStringToLog);
206+
return null;
208207
}
209208
// add all hosts that we are not considering to the avoid list
210209
List<HostVO> allhostsInCluster = _hostDao.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId, null);

server/src/main/java/com/cloud/network/IpAddressManagerImpl.java

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,36 +1038,48 @@ public List<IPAddressVO> listAvailablePublicIps(final long dcId, final Long podI
10381038
@Override
10391039
public void markPublicIpAsAllocated(final IPAddressVO addr) {
10401040
synchronized (allocatedLock) {
1041-
Transaction.execute(new TransactionCallbackNoReturn() {
1041+
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<CloudRuntimeException>() {
10421042
@Override
10431043
public void doInTransactionWithoutResult(TransactionStatus status) {
10441044
Account owner = _accountMgr.getAccount(addr.getAllocatedToAccountId());
1045-
if (_ipAddressDao.lockRow(addr.getId(), true) != null) {
1046-
final IPAddressVO userIp = _ipAddressDao.findById(addr.getId());
1047-
if (userIp.getState() == IpAddress.State.Allocating || addr.getState() == IpAddress.State.Free || addr.getState() == IpAddress.State.Reserved) {
1048-
boolean shouldUpdateIpResourceCount = checkIfIpResourceCountShouldBeUpdated(addr);
1049-
addr.setState(IpAddress.State.Allocated);
1050-
if (_ipAddressDao.update(addr.getId(), addr)) {
1051-
// Save usage event
1052-
if (owner.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
1053-
VlanVO vlan = _vlanDao.findById(addr.getVlanId());
1054-
String guestType = vlan.getVlanType().toString();
1055-
if (!isIpDedicated(addr)) {
1056-
final boolean usageHidden = isUsageHidden(addr);
1057-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(),
1058-
addr.getAddress().toString(), addr.isSourceNat(), guestType, addr.getSystem(), usageHidden,
1059-
addr.getClass().getName(), addr.getUuid());
1060-
}
1061-
if (shouldUpdateIpResourceCount) {
1062-
_resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.public_ip);
1063-
}
1064-
}
1065-
} else {
1066-
logger.error("Failed to mark public IP as allocated: {}", addr);
1045+
final IPAddressVO userIp = _ipAddressDao.lockRow(addr.getId(), true);
1046+
if (userIp == null) {
1047+
logger.error(String.format("Failed to acquire row lock to mark public IP as allocated with ID [%s] and address [%s]", addr.getId(), addr.getAddress()));
1048+
return;
1049+
}
1050+
1051+
List<IpAddress.State> expectedIpAddressStates = List.of(IpAddress.State.Allocating, IpAddress.State.Free, IpAddress.State.Reserved);
1052+
if (!expectedIpAddressStates.contains(userIp.getState())) {
1053+
logger.debug(String.format("Not marking public IP with ID [%s] and address [%s] as allocated, since it is in the [%s] state.", addr.getId(), addr.getAddress(), userIp.getState()));
1054+
return;
1055+
}
1056+
1057+
boolean shouldUpdateIpResourceCount = checkIfIpResourceCountShouldBeUpdated(addr);
1058+
addr.setState(IpAddress.State.Allocated);
1059+
boolean updatedIpAddress = _ipAddressDao.update(addr.getId(), addr);
1060+
if (!updatedIpAddress) {
1061+
logger.error(String.format("Failed to mark public IP as allocated with ID [%s] and address [%s]", addr.getId(), addr.getAddress()));
1062+
return;
1063+
}
1064+
1065+
if (owner.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
1066+
if (shouldUpdateIpResourceCount) {
1067+
try (CheckedReservation publicIpReservation = new CheckedReservation(owner, ResourceType.public_ip, 1L, reservationDao, _resourceLimitMgr)) {
1068+
_resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.public_ip);
1069+
} catch (Exception e) {
1070+
_ipAddressDao.unassignIpAddress(addr.getId());
1071+
throw new CloudRuntimeException(e);
10671072
}
10681073
}
1069-
} else {
1070-
logger.error("Failed to acquire row lock to mark public IP as allocated: {}", addr);
1074+
1075+
VlanVO vlan = _vlanDao.findById(addr.getVlanId());
1076+
String guestType = vlan.getVlanType().toString();
1077+
if (!isIpDedicated(addr)) {
1078+
final boolean usageHidden = isUsageHidden(addr);
1079+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(),
1080+
addr.getAddress().toString(), addr.isSourceNat(), guestType, addr.getSystem(), usageHidden,
1081+
addr.getClass().getName(), addr.getUuid());
1082+
}
10711083
}
10721084
}
10731085
});
@@ -1553,27 +1565,31 @@ public IPAddressVO associateIPToGuestNetwork(long ipId, long networkId, boolean
15531565

15541566
boolean isSourceNat = isSourceNatAvailableForNetwork(owner, ipToAssoc, network);
15551567

1556-
logger.debug("Associating ip " + ipToAssoc + " to network " + network);
1568+
logger.debug(String.format("Associating IP [%s] to network [%s].", ipToAssoc, network));
15571569

15581570
boolean success = false;
15591571
IPAddressVO ip = null;
1560-
try (CheckedReservation publicIpReservation = new CheckedReservation(owner, ResourceType.public_ip, 1l, reservationDao, _resourceLimitMgr)) {
1561-
ip = _ipAddressDao.findById(ipId);
1562-
//update ip address with networkId
1563-
ip.setAssociatedWithNetworkId(networkId);
1564-
ip.setSourceNat(isSourceNat);
1565-
_ipAddressDao.update(ipId, ip);
1566-
1567-
success = applyIpAssociations(network, false);
1572+
try {
1573+
Pair<IPAddressVO, Boolean> updatedIpAddress = Transaction.execute((TransactionCallbackWithException<Pair<IPAddressVO, Boolean>, Exception>) status -> {
1574+
IPAddressVO ipAddress = _ipAddressDao.findById(ipId);
1575+
ipAddress.setAssociatedWithNetworkId(networkId);
1576+
ipAddress.setSourceNat(isSourceNat);
1577+
_ipAddressDao.update(ipId, ipAddress);
1578+
return new Pair<>(_ipAddressDao.findById(ipId), applyIpAssociations(network, false));
1579+
});
1580+
1581+
ip = updatedIpAddress.first();
1582+
success = updatedIpAddress.second();
15681583
if (success) {
1569-
logger.debug("Successfully associated ip address " + ip.getAddress().addr() + " to network " + network);
1584+
logger.debug(String.format("Successfully associated IP address [%s] to network [%s]", ip.getAddress().addr(), network));
15701585
} else {
1571-
logger.warn("Failed to associate ip address " + ip.getAddress().addr() + " to network " + network);
1586+
logger.warn(String.format("Failed to associate IP address [%s] to network [%s]", ip.getAddress().addr(), network));
15721587
}
1573-
return _ipAddressDao.findById(ipId);
1588+
return ip;
15741589
} catch (Exception e) {
1575-
logger.error(String.format("Failed to associate ip address %s to network %s", ipToAssoc, network), e);
1576-
throw new CloudRuntimeException(String.format("Failed to associate ip address %s to network %s", ipToAssoc, network), e);
1590+
String errorMessage = String.format("Failed to associate IP address [%s] to network [%s]", ipToAssoc, network);
1591+
logger.error(errorMessage, e);
1592+
throw new CloudRuntimeException(errorMessage, e);
15771593
} finally {
15781594
if (!success && releaseOnFailure) {
15791595
if (ip != null) {

server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import com.cloud.dc.Vlan;
5151
import com.cloud.network.dao.NsxProviderDao;
5252
import com.cloud.network.element.NsxProviderVO;
53-
import com.cloud.resourcelimit.CheckedReservation;
5453
import com.google.common.collect.Sets;
5554
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
5655
import org.apache.cloudstack.alert.AlertService;
@@ -3191,32 +3190,27 @@ public IpAddress associateIPToVpc(final long ipId, final long vpcId) throws Reso
31913190
// check permissions
31923191
_accountMgr.checkAccess(caller, null, false, owner, vpc);
31933192

3194-
logger.debug("Associating ip " + ipToAssoc + " to vpc " + vpc);
3193+
logger.debug(String.format("Associating IP [%s] to VPC [%s]", ipToAssoc, vpc));
31953194

31963195
final boolean isSourceNatFinal = isSrcNatIpRequired(vpc.getVpcOfferingId()) && getExistingSourceNatInVpc(vpc.getAccountId(), vpcId, false) == null;
3197-
try (CheckedReservation publicIpReservation = new CheckedReservation(owner, ResourceType.public_ip, 1l, reservationDao, _resourceLimitMgr)) {
3198-
Transaction.execute(new TransactionCallbackNoReturn() {
3199-
@Override
3200-
public void doInTransactionWithoutResult(final TransactionStatus status) {
3196+
try {
3197+
IPAddressVO updatedIpAddress = Transaction.execute((TransactionCallbackWithException<IPAddressVO, CloudRuntimeException>) status -> {
32013198
final IPAddressVO ip = _ipAddressDao.findById(ipId);
3202-
// update ip address with networkId
32033199
ip.setVpcId(vpcId);
32043200
ip.setSourceNat(isSourceNatFinal);
3205-
32063201
_ipAddressDao.update(ipId, ip);
3207-
3208-
// mark ip as allocated
32093202
_ipAddrMgr.markPublicIpAsAllocated(ip);
3210-
}
3203+
return _ipAddressDao.findById(ipId);
32113204
});
3205+
3206+
logger.debug(String.format("Successfully assigned IP [%s] to VPC [%s]", ipToAssoc, vpc));
3207+
CallContext.current().putContextParameter(IpAddress.class, ipToAssoc.getUuid());
3208+
return updatedIpAddress;
32123209
} catch (Exception e) {
3213-
logger.error("Failed to associate ip " + ipToAssoc + " to vpc " + vpc, e);
3214-
throw new CloudRuntimeException("Failed to associate ip " + ipToAssoc + " to vpc " + vpc, e);
3210+
String errorMessage = String.format("Failed to associate IP address [%s] to VPC [%s]", ipToAssoc, vpc);
3211+
logger.error(errorMessage, e);
3212+
throw new CloudRuntimeException(errorMessage, e);
32153213
}
3216-
3217-
logger.debug("Successfully assigned ip " + ipToAssoc + " to vpc " + vpc);
3218-
CallContext.current().putContextParameter(IpAddress.class, ipToAssoc.getUuid());
3219-
return _ipAddressDao.findById(ipId);
32203214
}
32213215

32223216
@Override

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.Locale;
3333
import java.util.Map;
3434
import java.util.Random;
35-
import java.util.Set;
3635
import java.util.stream.Collectors;
3736

3837
import javax.inject.Inject;
@@ -60,10 +59,8 @@
6059
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
6160
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
6261
import org.apache.cloudstack.utils.identity.ManagementServerNode;
63-
6462
import org.apache.commons.collections.CollectionUtils;
6563
import org.apache.commons.lang.ObjectUtils;
66-
6764
import org.springframework.stereotype.Component;
6865

6966
import com.cloud.agent.AgentManager;
@@ -175,6 +172,7 @@
175172
import com.cloud.storage.dao.VolumeDao;
176173
import com.cloud.user.Account;
177174
import com.cloud.user.AccountManager;
175+
import com.cloud.utils.StringUtils;
178176
import com.cloud.utils.Ternary;
179177
import com.cloud.utils.UriUtils;
180178
import com.cloud.utils.component.Manager;
@@ -201,7 +199,6 @@
201199
import com.cloud.utils.ssh.SSHCmdHelper;
202200
import com.cloud.utils.ssh.SshException;
203201
import com.cloud.vm.UserVmManager;
204-
import com.cloud.utils.StringUtils;
205202
import com.cloud.vm.VMInstanceVO;
206203
import com.cloud.vm.VirtualMachine;
207204
import com.cloud.vm.VirtualMachine.State;
@@ -3266,12 +3263,16 @@ public List<HostVO> listAllHostsInAllZonesByType(final Type type) {
32663263

32673264
@Override
32683265
public List<HypervisorType> listAvailHypervisorInZone(final Long zoneId) {
3269-
List<VMTemplateVO> systemVMTemplates = _templateDao.listAllReadySystemVMTemplates(zoneId);
3270-
final Set<HypervisorType> hypervisors = new HashSet<>();
3271-
for (final VMTemplateVO systemVMTemplate : systemVMTemplates) {
3272-
hypervisors.add(systemVMTemplate.getHypervisorType());
3266+
final SearchCriteria<String> sc = _hypervisorsInDC.create();
3267+
if (zoneId != null) {
3268+
sc.setParameters("dataCenter", zoneId);
32733269
}
3274-
return new ArrayList<>(hypervisors);
3270+
sc.setParameters("type", Host.Type.Routing);
3271+
3272+
return _hostDao.customSearch(sc, null).stream()
3273+
// The search is not able to return list of enums, so getting
3274+
// list of hypervisors as strings and then converting them to enum
3275+
.map(HypervisorType::getType).collect(Collectors.toList());
32753276
}
32763277

32773278
@Override

0 commit comments

Comments
 (0)