Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions usage/src/main/java/com/cloud/usage/UsageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public boolean start() {
_sanity = _sanityExecutor.scheduleAtFixedRate(new SanityCheck(), 1, _sanityCheckInterval, TimeUnit.DAYS);
}

Runtime.getRuntime().addShutdownHook(new AbandonJob());
TransactionLegacy usageTxn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
try {
if (_heartbeatLock.lock(3)) { // 3 second timeout
Expand Down Expand Up @@ -345,9 +346,11 @@ public boolean stop() {
if (_sanity != null) {
_sanity.cancel(true);
}

return true;
}


@Override
public void run() {
(new ManagedContextRunnable() {
Expand Down Expand Up @@ -2183,4 +2186,17 @@ protected void runInContext() {
}
}
}
private class AbandonJob extends Thread {
@Override
public void run() {
s_logger.info("exitting Usage Manager");
deleteOpenjob();
}
private void deleteOpenjob() {
UsageJobVO job = _usageJobDao.isOwner(_hostname, _pid);
if (job != null) {
_usageJobDao.remove(job.getId());
}
}
}
}