Skip to content

Commit 988012f

Browse files
committed
changes in similar code
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 98d0e57 commit 988012f

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

server/src/main/java/com/cloud/alert/AlertManagerImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,13 @@ protected void recalculateHostCapacities() {
294294
Math.min(CapacityManager.CapacityCalculateWorkers.value(), hostIds.size())));
295295
for (Long hostId : hostIds) {
296296
futures.put(hostId, executorService.submit(() -> {
297-
final HostVO host = hostDao.findById(hostId);
298-
_capacityMgr.updateCapacityForHost(host);
297+
Transaction.execute(new TransactionCallbackNoReturn() {
298+
@Override
299+
public void doInTransactionWithoutResult(TransactionStatus status) {
300+
final HostVO host = hostDao.findById(hostId);
301+
_capacityMgr.updateCapacityForHost(host);
302+
}
303+
});
299304
return null;
300305
}));
301306
}

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257
import com.cloud.utils.db.SearchCriteria.Op;
258258
import com.cloud.utils.db.Transaction;
259259
import com.cloud.utils.db.TransactionCallbackNoReturn;
260+
import com.cloud.utils.db.TransactionCallbackWithExceptionNoReturn;
260261
import com.cloud.utils.db.TransactionLegacy;
261262
import com.cloud.utils.db.TransactionStatus;
262263
import com.cloud.utils.exception.CloudRuntimeException;
@@ -1591,22 +1592,27 @@ public void connectHostsToPool(DataStore primaryStore, List<Long> hostIds, Scope
15911592
if (exceptionOccurred.get()) {
15921593
return null;
15931594
}
1594-
HostVO host = _hostDao.findById(hostId);
1595-
try {
1596-
connectHostToSharedPool(host, primaryStore.getId());
1597-
poolHostIds.add(hostId);
1598-
} catch (Exception e) {
1599-
if (handleExceptionsPartially && e.getCause() instanceof StorageConflictException) {
1600-
exceptionOccurred.set(true);
1601-
throw e;
1602-
}
1603-
logger.warn("Unable to establish a connection between {} and {}", host, primaryStore, e);
1604-
String reason = getStoragePoolMountFailureReason(e.getMessage());
1605-
if (handleExceptionsPartially && reason != null) {
1606-
exceptionOccurred.set(true);
1607-
throw new CloudRuntimeException(reason);
1595+
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<Exception>() {
1596+
@Override
1597+
public void doInTransactionWithoutResult(TransactionStatus status) throws Exception {
1598+
HostVO host = _hostDao.findById(hostId);
1599+
try {
1600+
connectHostToSharedPool(host, primaryStore.getId());
1601+
poolHostIds.add(hostId);
1602+
} catch (Exception e) {
1603+
if (handleExceptionsPartially && e.getCause() instanceof StorageConflictException) {
1604+
exceptionOccurred.set(true);
1605+
throw e;
1606+
}
1607+
logger.warn("Unable to establish a connection between {} and {}", host, primaryStore, e);
1608+
String reason = getStoragePoolMountFailureReason(e.getMessage());
1609+
if (handleExceptionsPartially && reason != null) {
1610+
exceptionOccurred.set(true);
1611+
throw new CloudRuntimeException(reason);
1612+
}
1613+
}
16081614
}
1609-
}
1615+
});
16101616
return null;
16111617
}));
16121618
}

0 commit comments

Comments
 (0)