diff options
author | awnuk <awnuk@c9f7a03b-bd48-0410-a16d-cbbf54688b0b> | 2010-12-21 07:42:50 +0000 |
---|---|---|
committer | awnuk <awnuk@c9f7a03b-bd48-0410-a16d-cbbf54688b0b> | 2010-12-21 07:42:50 +0000 |
commit | 5a467a1aa4e26db85e25a35275c5dfd0d320d7b2 (patch) | |
tree | b0d2c21179fd12ed3bfc2da154b03e201c39a25a /pki/base/common/src | |
parent | 9a945471f8dcf20441f18ae28b610f52905e51c5 (diff) | |
download | pki-5a467a1aa4e26db85e25a35275c5dfd0d320d7b2.tar.gz pki-5a467a1aa4e26db85e25a35275c5dfd0d320d7b2.tar.xz pki-5a467a1aa4e26db85e25a35275c5dfd0d320d7b2.zip |
Fixed bugzilla bug #649343.
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@1659 c9f7a03b-bd48-0410-a16d-cbbf54688b0b
Diffstat (limited to 'pki/base/common/src')
10 files changed, 193 insertions, 14 deletions
diff --git a/pki/base/common/src/com/netscape/certsrv/dbs/repository/IRepositoryRecord.java b/pki/base/common/src/com/netscape/certsrv/dbs/repository/IRepositoryRecord.java index 41be3c09f..5e6db669f 100644 --- a/pki/base/common/src/com/netscape/certsrv/dbs/repository/IRepositoryRecord.java +++ b/pki/base/common/src/com/netscape/certsrv/dbs/repository/IRepositoryRecord.java @@ -36,11 +36,14 @@ import com.netscape.certsrv.dbs.*; public interface IRepositoryRecord extends IDBObj { public final static String ATTR_SERIALNO = "serialNo"; - + public final static String ATTR_PUB_STATUS = "publishingStatus"; + /** * Retrieves serial number. * * @return serial number */ public BigInteger getSerialNumber(); + + public String getPublishingStatus(); } diff --git a/pki/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java b/pki/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java index bad0a99eb..956a30e26 100644 --- a/pki/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java +++ b/pki/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java @@ -19,6 +19,7 @@ package com.netscape.certsrv.request; import java.util.*; +import java.math.*; import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.apps.*; @@ -46,6 +47,9 @@ public class ARequestNotifier implements IRequestNotifier { private int mPublishingQueuePriority = 0; private int mMaxPublishingQueuePageSize = 1; private IRequestQueue mRequestQueue = null; + private String mPublishingStatus = null; + private int mSavePublishingStatus = 0; + private int mSavePublishingCounter = 0; public ARequestNotifier() { @@ -60,7 +64,8 @@ public class ARequestNotifier implements IRequestNotifier { public void setPublishingQueue (boolean isPublishingQueueEnabled, int publishingQueuePriorityLevel, int maxNumberOfPublishingThreads, - int publishingQueuePageSize) { + int publishingQueuePageSize, + int savePublishingStatus) { CMS.debug("setPublishingQueue: Publishing Queue Enabled: " + isPublishingQueueEnabled+ " Priority Level: " + publishingQueuePriorityLevel+ " Maximum Number of Threads: " + maxNumberOfPublishingThreads+ @@ -68,6 +73,7 @@ public class ARequestNotifier implements IRequestNotifier { mIsPublishingQueueEnabled = isPublishingQueueEnabled; mMaxThreads = maxNumberOfPublishingThreads; mMaxRequests = publishingQueuePageSize; + mSavePublishingStatus = savePublishingStatus; // Publishing Queue Priority Levels: 2 - maximum, 1 - higher, 0 - normal, -1 - lower, -2 - minimum if (publishingQueuePriorityLevel > 1) { @@ -81,6 +87,20 @@ public class ARequestNotifier implements IRequestNotifier { } else { mPublishingQueuePriority = Thread.currentThread().getPriority(); } + + if (mCA != null && mRequestQueue == null) mRequestQueue = mCA.getRequestQueue(); + if (mIsPublishingQueueEnabled && mSavePublishingStatus > 0 && mRequestQueue != null) { + mPublishingStatus = mRequestQueue.getPublishingStatus(); + BigInteger status = new BigInteger("-2"); + try { + status = new BigInteger(mPublishingStatus); + if (status.compareTo(BigInteger.ZERO) > -1) { + recoverPublishingQueue(mPublishingStatus); + } + } catch (Exception e) { + } + } + } /** @@ -152,6 +172,28 @@ public class ARequestNotifier implements IRequestNotifier { return mListeners.elements(); } + + private Object publishingCounterMonitor = new Object(); + + private void updatePublishingStatus(String id) { + if (mRequestQueue != null) { + synchronized (publishingCounterMonitor) { + if (mSavePublishingCounter == 0) { + CMS.debug("updatePublishingStatus requestId: "+id); + mRequestQueue.setPublishingStatus(id); + } + mSavePublishingCounter++; + CMS.debug("updatePublishingStatus mSavePublishingCounter: "+mSavePublishingCounter+ + " mSavePublishingStatus: "+mSavePublishingStatus); + if (mSavePublishingCounter >= mSavePublishingStatus) { + mSavePublishingCounter = 0; + } + } + } else { + CMS.debug("updatePublishingStatus mRequestQueue == null"); + } + } + /** * Gets request from publishing queue. * @@ -163,10 +205,12 @@ public class ARequestNotifier implements IRequestNotifier { CMS.debug("getRequest mRequests=" + mRequests.size() + " mSearchForRequests=" + mSearchForRequests); if (mSearchForRequests && mRequests.size() == 1) { + id = (String)mRequests.elementAt(0); if (mCA != null && mRequestQueue == null) mRequestQueue = mCA.getRequestQueue(); - if (mRequestQueue != null) { + if (id != null && mRequestQueue != null) { + CMS.debug("getRequest request id=" + id); IRequestVirtualList list = mRequestQueue.getPagedRequestsByFilter( - new RequestId((String)mRequests.elementAt(0)), + new RequestId(id), "(requeststate=complete)", mMaxRequests, "requestId"); int s = list.getSize() - list.getCurrentIndex(); CMS.debug("getRequest list size: "+s); @@ -191,7 +235,7 @@ public class ARequestNotifier implements IRequestNotifier { requestType.equals(IRequest.UNREVOCATION_REQUEST))) { continue; } - if (i == 0 && ((String)mRequests.elementAt(0)).equals(r.getRequestId().toString())) { + if (i == 0 && id.equals(r.getRequestId().toString())) { if (s == 1) { break; } else { @@ -221,6 +265,7 @@ public class ARequestNotifier implements IRequestNotifier { r = mRequestQueue.findRequest(new RequestId(id)); mRequests.remove(0); CMS.debug("getRequest request "+ id + ((r != null)?" found":" not found")); + updatePublishingStatus(id); } catch (EBaseException e) { CMS.debug("getRequest EBaseException " + e.toString()); } @@ -263,6 +308,9 @@ public class ARequestNotifier implements IRequestNotifier { public void removeNotifierThread(Thread notifierThread) { if (mNotifierThreads.size() > 0) { mNotifierThreads.remove(notifierThread); + if (mNotifierThreads.size() == 0) { + mRequestQueue.setPublishingStatus("-1"); + } } CMS.debug("Number of publishing threads: " + mNotifierThreads.size()); } @@ -395,6 +443,38 @@ public class ARequestNotifier implements IRequestNotifier { } } } + + + /** + * Recovers publishing queue. + * + * @param id request request + */ + public void recoverPublishingQueue(String id) { + CMS.debug("recoverPublishingQueue mRequests.size()="+mRequests.size()+"("+mMaxRequests+")"+ + " requests by adding request "+id); + if (mRequests.size() == 0) { + mRequests.addElement(id); + CMS.debug("recoverPublishingQueue extended buffer to "+mRequests.size()+"("+mMaxRequests+")"+ + " requests by adding request "+id); + if (morePublishingThreads()) { + mSearchForRequests = true; + try { + Thread notifierThread = new Thread(new RunListeners((IRequestNotifier)this)); + if (notifierThread != null) { + mNotifierThreads.addElement(notifierThread); + CMS.debug("Number of publishing threads: " + mNotifierThreads.size()); + if (mPublishingQueuePriority > 0) { + notifierThread.setPriority(mPublishingQueuePriority); + } + notifierThread.start(); + } + } catch (Throwable e) { + CMS.debug("recoverPublishingQueue exception: " + e.toString()); + } + } + } + } } @@ -438,6 +518,7 @@ class RunListeners implements Runnable { do { if (mRequestNotifier != null) mRequest = (IRequest)mRequestNotifier.getRequest(); if (mListeners != null && mRequest != null) { + CMS.debug("RunListeners: mRequest = " + mRequest.getRequestId().toString()); while (mListeners.hasMoreElements()) { IRequestListener l = (IRequestListener) mListeners.nextElement(); CMS.debug("RunListeners: IRequestListener = " + l.getClass().getName()); diff --git a/pki/base/common/src/com/netscape/certsrv/request/IRequestNotifier.java b/pki/base/common/src/com/netscape/certsrv/request/IRequestNotifier.java index b6af76584..91cb7544a 100644 --- a/pki/base/common/src/com/netscape/certsrv/request/IRequestNotifier.java +++ b/pki/base/common/src/com/netscape/certsrv/request/IRequestNotifier.java @@ -126,6 +126,7 @@ public interface IRequestNotifier extends INotify { public void setPublishingQueue (boolean isPublishingQueueEnabled, int publishingQueuePriorityLevel, int maxNumberOfPublishingThreads, - int publishingQueuePageSize); + int publishingQueuePageSize, + int savePublishingStatus); } diff --git a/pki/base/common/src/com/netscape/certsrv/request/IRequestQueue.java b/pki/base/common/src/com/netscape/certsrv/request/IRequestQueue.java index 5467b6018..9b2edf9b4 100644 --- a/pki/base/common/src/com/netscape/certsrv/request/IRequestQueue.java +++ b/pki/base/common/src/com/netscape/certsrv/request/IRequestQueue.java @@ -407,4 +407,8 @@ public interface IRequestQueue { * @return request repository */ public IRepository getRequestRepository(); + + public String getPublishingStatus(); + + public void setPublishingStatus(String status); } diff --git a/pki/base/common/src/com/netscape/cmscore/dbs/DBSubsystem.java b/pki/base/common/src/com/netscape/cmscore/dbs/DBSubsystem.java index 84744af36..797dd8324 100644 --- a/pki/base/common/src/com/netscape/cmscore/dbs/DBSubsystem.java +++ b/pki/base/common/src/com/netscape/cmscore/dbs/DBSubsystem.java @@ -792,10 +792,15 @@ public class DBSubsystem implements IDBSubsystem { reg.registerObjectClass( RepositoryRecord.class.getName(), repRecordOC); } - if (!reg.isAttributeRegistered(RepositoryRecord.ATTR_SERIALNO)) { - reg.registerAttribute(RepositoryRecord.ATTR_SERIALNO, + if (!reg.isAttributeRegistered(IRepositoryRecord.ATTR_SERIALNO)) { + reg.registerAttribute(IRepositoryRecord.ATTR_SERIALNO, new BigIntegerMapper(RepositorySchema.LDAP_ATTR_SERIALNO)); } + if (!reg.isAttributeRegistered(IRepositoryRecord.ATTR_PUB_STATUS)) { + reg.registerAttribute(IRepositoryRecord.ATTR_PUB_STATUS, + new StringMapper(RepositorySchema.LDAP_ATTR_PUB_STATUS)); + } + } catch (EBaseException e) { if (CMS.isPreOpMode()) return; diff --git a/pki/base/common/src/com/netscape/cmscore/dbs/RepositoryRecord.java b/pki/base/common/src/com/netscape/cmscore/dbs/RepositoryRecord.java index e177f8d2e..7aa63fa1d 100644 --- a/pki/base/common/src/com/netscape/cmscore/dbs/RepositoryRecord.java +++ b/pki/base/common/src/com/netscape/cmscore/dbs/RepositoryRecord.java @@ -39,13 +39,13 @@ import com.netscape.certsrv.dbs.repository.*; */ public class RepositoryRecord implements IRepositoryRecord { - public final static String ATTR_SERIALNO = "serialNo"; - private BigInteger mSerialNo = null; + private String mPublishingStatus = null; protected static Vector mNames = new Vector(); static { - mNames.addElement(ATTR_SERIALNO); + mNames.addElement(IRepositoryRecord.ATTR_SERIALNO); + mNames.addElement(IRepositoryRecord.ATTR_PUB_STATUS); } /** @@ -59,8 +59,10 @@ public class RepositoryRecord implements IRepositoryRecord { * Sets attribute. */ public void set(String name, Object obj) throws EBaseException { - if (name.equalsIgnoreCase(ATTR_SERIALNO)) { + if (name.equalsIgnoreCase(IRepositoryRecord.ATTR_SERIALNO)) { mSerialNo = (BigInteger) obj; + } else if (name.equalsIgnoreCase(IRepositoryRecord.ATTR_PUB_STATUS)) { + mPublishingStatus = (String) obj; } else { throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_ATTRIBUTE", name)); } @@ -70,8 +72,10 @@ public class RepositoryRecord implements IRepositoryRecord { * Retrieves attribute from this record. */ public Object get(String name) throws EBaseException { - if (name.equalsIgnoreCase(ATTR_SERIALNO)) { + if (name.equalsIgnoreCase(IRepositoryRecord.ATTR_SERIALNO)) { return mSerialNo; + } else if (name.equalsIgnoreCase(IRepositoryRecord.ATTR_PUB_STATUS)) { + return mPublishingStatus; } else { throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_ATTRIBUTE", name)); } @@ -101,4 +105,8 @@ public class RepositoryRecord implements IRepositoryRecord { public BigInteger getSerialNumber() { return mSerialNo; } + + public String getPublishingStatus() { + return mPublishingStatus; + } } diff --git a/pki/base/common/src/com/netscape/cmscore/dbs/RepositorySchema.java b/pki/base/common/src/com/netscape/cmscore/dbs/RepositorySchema.java index 70bb7d4be..436c8633e 100644 --- a/pki/base/common/src/com/netscape/cmscore/dbs/RepositorySchema.java +++ b/pki/base/common/src/com/netscape/cmscore/dbs/RepositorySchema.java @@ -40,4 +40,5 @@ public class RepositorySchema { public static final String LDAP_OC_TOP = "top"; public static final String LDAP_OC_REPOSITORY = "repository"; public static final String LDAP_ATTR_SERIALNO = "serialno"; + public static final String LDAP_ATTR_PUB_STATUS = "publishingStatus"; } diff --git a/pki/base/common/src/com/netscape/cmscore/ldap/PublisherProcessor.java b/pki/base/common/src/com/netscape/cmscore/ldap/PublisherProcessor.java index 3ae3380e5..7d7b8e9b5 100644 --- a/pki/base/common/src/com/netscape/cmscore/ldap/PublisherProcessor.java +++ b/pki/base/common/src/com/netscape/cmscore/ldap/PublisherProcessor.java @@ -418,6 +418,7 @@ public class PublisherProcessor implements int publishingQueuePriorityLevel = queueConfig.getInteger("priorityLevel", 0); int maxNumberOfPublishingThreads = queueConfig.getInteger("maxNumberOfThreads", 1); int publishingQueuePageSize = queueConfig.getInteger("pageSize", 100); + int savePublishingStatus = queueConfig.getInteger("saveStatus", 0); CMS.debug("PublisherProcessor: startup: Publishing Queue Enabled: " + isPublishingQueueEnabled + " Priority Level: " + publishingQueuePriorityLevel + " Maximum Number of Threads: " + maxNumberOfPublishingThreads + @@ -426,7 +427,8 @@ public class PublisherProcessor implements reqNotifier.setPublishingQueue (isPublishingQueueEnabled, publishingQueuePriorityLevel, maxNumberOfPublishingThreads, - publishingQueuePageSize); + publishingQueuePageSize, + savePublishingStatus); } } } diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java index ff9ceb4f6..f390d436d 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java @@ -602,6 +602,14 @@ public class RequestQueue return (IRepository) mRepository; } + public String getPublishingStatus() { + return mRepository.getPublishingStatus(); + } + + public void setPublishingStatus(String status) { + mRepository.setPublishingStatus(status); + } + protected String mBaseDN; protected IDBSubsystem mDB; protected RequestRepository mRepository; diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java b/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java index db77f41ac..c6ab7129e 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java @@ -23,6 +23,7 @@ import java.math.*; import com.netscape.certsrv.dbs.EDBException; import com.netscape.certsrv.dbs.IDBSubsystem; import com.netscape.certsrv.dbs.*; +import com.netscape.certsrv.dbs.repository.*; import com.netscape.certsrv.request.*; import com.netscape.certsrv.base.*; import com.netscape.certsrv.apps.*; @@ -145,4 +146,69 @@ class RequestRepository * the LDAP base DN for this repository */ protected String mBaseDN; + + + public String getPublishingStatus() { + RepositoryRecord record = null; + Object obj = null; + IDBSSession dbs = null; + String status = null; + + try { + dbs = mDB.createSession(); + obj = dbs.read(mBaseDN); + } catch (Exception e) { + CMS.debug("RequestRepository: getPublishingStatus: Error: " + e); + CMS.debugStackTrace(); + } finally { + // Close session - ignoring errors (UTIL) + if (dbs != null) { + try { + dbs.close(); + } catch (Exception ex) { + CMS.debug("RequestRepository: getPublishingStatus: Error: " + ex); + } + } + } + + if (obj != null || (obj instanceof RepositoryRecord)) { + record = (RepositoryRecord) obj; + status = record.getPublishingStatus(); + } else { + CMS.debug("RequestRepository: obj is NOT instanceof RepositoryRecord"); + } + CMS.debug("RequestRepository: getPublishingStatus mBaseDN: " + mBaseDN + + " status: " + ((status != null)?status:"null")); + + return status; + } + + public void setPublishingStatus(String status) { + IDBSSession dbs = null; + + CMS.debug("RequestRepository: setPublishingStatus mBaseDN: " + mBaseDN + " status: " + status); + ModificationSet mods = new ModificationSet(); + + if (status != null && status.length() > 0) { + mods.add(IRepositoryRecord.ATTR_PUB_STATUS, + Modification.MOD_REPLACE, status); + + try { + dbs = mDB.createSession(); + dbs.modify(mBaseDN, mods); + } catch (Exception e) { + CMS.debug("RequestRepository: setPublishingStatus: Error: " + e); + CMS.debugStackTrace(); + } finally { + // Close session - ignoring errors (UTIL) + if (dbs != null) { + try { + dbs.close(); + } catch (Exception ex) { + CMS.debug("RequestRepository: setPublishingStatus: Error: " + ex); + } + } + } + } + } } |