sureshanaparti commented on code in PR #12409:
URL: https://github.com/apache/cloudstack/pull/12409#discussion_r2767676397
##########
framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java:
##########
@@ -1284,6 +1296,74 @@ private void
cleanupFailedSnapshotsCreatedWithDefaultStrategy(final long msid) {
}
}
+ /**
+ * Cleanup networks that are stuck in Implementing state without
associated async jobs.
+ * This only processes networks that have been stuck for longer than the
job expiration threshold.
+ */
+ private void cleanupOrphanedNetworks() {
+ try {
+ SearchCriteria<NetworkVO> sc = networkDao.createSearchCriteria();
+ sc.addAnd("state", SearchCriteria.Op.EQ,
Network.State.Implementing);
+ sc.addAnd("removed", SearchCriteria.Op.NULL);
+ List<NetworkVO> implementingNetworks = networkDao.search(sc, null);
+
+ if (implementingNetworks == null ||
implementingNetworks.isEmpty()) {
+ return;
+ }
+
+ logger.debug("Found {} networks in Implementing state, checking
for orphaned networks", implementingNetworks.size());
+
+ final long expireMinutes = JobExpireMinutes.value();
+ final Date cutoffTime = new Date(System.currentTimeMillis() -
(expireMinutes * 60 * 1000));
+
+ for (NetworkVO network : implementingNetworks) {
+ if (network.getCreated().after(cutoffTime)) {
+ logger.trace("Network {} in Implementing state is only {}
minutes old (threshold: {} minutes), skipping cleanup",
+ network.getId(),
+ (System.currentTimeMillis() -
network.getCreated().getTime()) / 60000,
+ expireMinutes);
+ continue;
+ }
+
+ List<AsyncJobVO> jobs =
_jobDao.findInstancePendingAsyncJobs("Network", network.getAccountId());
+ boolean hasActiveJob = false;
+ for (AsyncJobVO job : jobs) {
+ if (job.getInstanceId() != null &&
job.getInstanceId().equals(network.getId())) {
Review Comment:
can pass these checks to jobDao and find the active job?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]