*
* @see org.ejbca.core.model.services.IWorker#work()
*/
public void work(Map<Class<?>, Object> ejbs) throws ServiceExecutionFailedException {
log.trace(">Worker started");
final CAAdminSessionLocal caAdminSession = ((CAAdminSessionLocal)ejbs.get(CAAdminSessionLocal.class));
// Find CAs with expire date that is less than configured number of days
// ahead in the future
long millistoexpire = getTimeBeforeExpire();
long now = new Date().getTime();
long expiretime = now + millistoexpire;
// Renew these CAs using the CAAdminSessionBean
// Check the "Generate new keys" checkbox so we can pass the correct parameter to CAAdminSessionBean
Collection<Integer> caids = getCAIdsToCheck(false);
log.debug("Checking renewal for "+caids.size()+" CAs");
Iterator<Integer> iter = caids.iterator();
while (iter.hasNext()) {
Integer caid = iter.next();
CAInfo info = caAdminSession.getCAInfo(getAdmin(), caid.intValue());
String caname = null;
if (info != null) {
caname = info.getName();
Date expire = info.getExpireTime();
log.debug("CA "+caname+" expires on "+expire);
if (expire.before(new Date(expiretime))) {
try {
// Only try to renew active CAs
// There should be other monitoring available to check if CAs that should not be off-line are off-line (HealthCheck)
CATokenInfo tokeninfo = info.getCATokenInfo();
log.debug("CA status is "+info.getStatus()+", CA token status is "+tokeninfo.getCATokenStatus());
if ( (info.getStatus() == SecConst.CA_ACTIVE) && (tokeninfo.getCATokenStatus() == ICAToken.STATUS_ACTIVE) ) {
caAdminSession.renewCA(getAdmin(), info.getCAId(), null, isRenewKeys());
} else {
log.debug("Not trying to renew CA because CA and token status are not on-line.");
}
} catch (CADoesntExistsException e) {
log.error("Error renewing CA: ", e);