Skip to content

Commit

Permalink
Move SerialNumberUpdateTask.updateSerialNumbers() to CAEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
edewata committed Oct 5, 2024
1 parent da36e97 commit 76267d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,19 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

import com.netscape.cmscore.request.RequestRepository;
import org.dogtagpki.server.ca.CAEngine;

public class SerialNumberUpdateTask implements Runnable {

public static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SerialNumberUpdateTask.class);

CertificateRepository certRepository;
RequestRepository requestRepository;

CAEngine engine;
int interval;

ScheduledExecutorService executorService;

public SerialNumberUpdateTask(
CertificateRepository certRepository,
RequestRepository requestRepository,
int interval) {

this.certRepository = certRepository;
this.requestRepository = requestRepository;
public SerialNumberUpdateTask(CAEngine engine, int interval) {
this.engine = engine;
this.interval = interval;
}

Expand All @@ -56,22 +49,10 @@ public Thread newThread(Runnable r) {
executorService.scheduleWithFixedDelay(this, 0, interval, TimeUnit.SECONDS);
}

public synchronized void updateSerialNumbers() throws Exception {

logger.info("SerialNumberUpdateTask: Updating serial number counter");
certRepository.updateCounter();

logger.info("SerialNumberUpdateTask: Checking serial number ranges");
certRepository.checkRanges();

logger.info("SerialNumberUpdateTask: Checking request ID ranges");
requestRepository.checkRanges();
}

@Override
public void run() {
try {
updateSerialNumbers();
engine.updateSerialNumbers();

} catch (Exception e) {
logger.warn("SerialNumberUpdateTask: " + e.getMessage(), e);
Expand Down
17 changes: 13 additions & 4 deletions base/ca/src/main/java/org/dogtagpki/server/ca/CAEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -991,13 +991,22 @@ public void startSerialNumberUpdateTask() throws Exception {

logger.info("CAEngine: Starting serial number update task");

serialNumberUpdateTask = new SerialNumberUpdateTask(
certificateRepository,
requestRepository,
interval);
serialNumberUpdateTask = new SerialNumberUpdateTask(this, interval);
serialNumberUpdateTask.start();
}

public synchronized void updateSerialNumbers() throws Exception {

logger.info("CAEngine: Updating serial number counter");
certificateRepository.updateCounter();

logger.info("CAEngine: Checking serial number ranges");
certificateRepository.checkRanges();

logger.info("CAEngine: Checking request ID ranges");
requestRepository.checkRanges();
}

@Override
public void initSubsystems() throws Exception {

Expand Down

0 comments on commit 76267d9

Please sign in to comment.