GutoVeronezi commented on code in PR #7132:
URL: https://github.com/apache/cloudstack/pull/7132#discussion_r1086675808
##########
server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java:
##########
@@ -100,9 +111,53 @@ public class ConsoleAccessManagerImpl extends ManagerBase
implements ConsoleAcce
@Override
public boolean configure(String name, Map<String, Object> params) throws
ConfigurationException {
ConsoleAccessManagerImpl.secretKeysManager = keysManager;
+ executorService = Executors.newScheduledThreadPool(1, new
NamedThreadFactory("ConsoleSession-Scavenger"));
return super.configure(name, params);
}
+ @Override
+ public boolean start() {
+ Integer consoleCleanupInterval =
ConsoleAccessManager.ConsoleSessionCleanupInterval.value();
+ Boolean consoleCleanupEnabled =
ConsoleAccessManager.ConsoleSessionCleanupEnabled.value();
+ if (BooleanUtils.isTrue(consoleCleanupEnabled)) {
+ s_logger.info(String.format("The ConsoleSessionCleanupTask will
run every %s hours", consoleCleanupInterval));
+ executorService.scheduleWithFixedDelay(new
ConsoleSessionCleanupTask(), consoleCleanupInterval, consoleCleanupInterval,
TimeUnit.HOURS);
+ }
+ return true;
+ }
+
+ public class ConsoleSessionCleanupTask extends ManagedContextRunnable {
+ @Override
+ protected void runInContext() {
+ final GlobalLock gcLock =
GlobalLock.getInternLock("ConsoleSession.Cleanup.Lock");
+ try {
+ if (gcLock.lock(3)) {
+ try {
+ reallyRun();
+ } finally {
+ gcLock.unlock();
+ }
+ }
+ } finally {
+ gcLock.releaseRef();
+ }
+ }
+
+ private void reallyRun() {
+ s_logger.info("Starting ConsoleSessionCleanupTask...");
+ Integer retentionDays =
ConsoleAccessManager.ConsoleSessionCleanupRetentionDays.value();
+ Date date = GregorianCalendar.getInstance().getTime();
Review Comment:
Why use `GregorianCalendar.getInstance().getTime()` instead of a `new
Date()` here?
##########
server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java:
##########
@@ -100,9 +111,53 @@ public class ConsoleAccessManagerImpl extends ManagerBase
implements ConsoleAcce
@Override
public boolean configure(String name, Map<String, Object> params) throws
ConfigurationException {
ConsoleAccessManagerImpl.secretKeysManager = keysManager;
+ executorService = Executors.newScheduledThreadPool(1, new
NamedThreadFactory("ConsoleSession-Scavenger"));
return super.configure(name, params);
}
+ @Override
+ public boolean start() {
+ Integer consoleCleanupInterval =
ConsoleAccessManager.ConsoleSessionCleanupInterval.value();
+ Boolean consoleCleanupEnabled =
ConsoleAccessManager.ConsoleSessionCleanupEnabled.value();
+ if (BooleanUtils.isTrue(consoleCleanupEnabled)) {
+ s_logger.info(String.format("The ConsoleSessionCleanupTask will
run every %s hours", consoleCleanupInterval));
+ executorService.scheduleWithFixedDelay(new
ConsoleSessionCleanupTask(), consoleCleanupInterval, consoleCleanupInterval,
TimeUnit.HOURS);
+ }
+ return true;
+ }
+
+ public class ConsoleSessionCleanupTask extends ManagedContextRunnable {
+ @Override
+ protected void runInContext() {
+ final GlobalLock gcLock =
GlobalLock.getInternLock("ConsoleSession.Cleanup.Lock");
+ try {
+ if (gcLock.lock(3)) {
+ try {
+ reallyRun();
+ } finally {
+ gcLock.unlock();
+ }
+ }
+ } finally {
+ gcLock.releaseRef();
+ }
+ }
+
+ private void reallyRun() {
+ s_logger.info("Starting ConsoleSessionCleanupTask...");
+ Integer retentionDays =
ConsoleAccessManager.ConsoleSessionCleanupRetentionDays.value();
+ Date date = GregorianCalendar.getInstance().getTime();
+ Date dateBefore = new Date(date.getTime() - retentionDays * 24 *
3600 * 1000);
+ List<ConsoleSessionVO> sessionsToExpunge =
consoleSessionDao.listRemovedSessionsOlderThanDate(dateBefore);
+ if (CollectionUtils.isNotEmpty(sessionsToExpunge)) {
+ s_logger.info(String.format("Expunging %s removed console
session records"));
Review Comment:
An argument is missing for the format.
--
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]