Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ca-cert-find server command to paged search #4651

Merged
merged 1 commit into from
Jan 9, 2024

Conversation

fmarco76
Copy link
Member

@fmarco76 fmarco76 commented Jan 2, 2024

No description provided.

@fmarco76 fmarco76 requested a review from edewata January 2, 2024 09:13
@fmarco76 fmarco76 force-pushed the CACertFindCLIFreeVLV branch 3 times, most recently from 11db1c9 to 4accfaf Compare January 3, 2024 15:25
Copy link
Contributor

@edewata edewata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good in general, but please see my comments below.

Comment on lines 27 to 31
* Contain all records in a page for a paged search.
*
* @author Marco Fargetta {@literal <[email protected]>}
*/
public class CertRecordPage implements Iterable<CertRecord> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC this class seems to be analogous to CertRecordList which represents the entire results of the cert search operation (instead of just a single page implied by this class name), so would it be better to call it CertRecordPagedList instead? Later the original CertRecordList probably could be renamed into CertRecordVirtualList, and we could have a new CertRecordList as the base class for both paged & virtual list classes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is OK to rename the class to make more clear its behaviour. However, the classes CertRecordList and CertRecordPage have no common methods/interfaces so there is not need for the abstraction and since we have to drop the VLV I would not spend time to re-factoring the old code.

if (revokedBy != null) {
System.out.println(" Revoked By: " + revokedBy);
}
System.out.println();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will add an extra blank line at the end of the output. The original code in line 135 will only add blank lines between records, but not at the end of the output. Usually we use a flag like this:
https://github.com/dogtagpki/pki/blob/master/base/tools/src/main/java/com/netscape/cmstools/ca/CACertFindCLI.java#L237-L241

*
* @author Marco Fargetta {@literal <[email protected]>}
*/
public class DBPagedSearch<E extends IDBObj> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class seems to be analogous to DBVirtualList which represents the list of results instead of the search operation itself (as implied by the class name). Would it be better to call it something like DBPagedList or DBPagedSearchResults instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure on this change. I was thinking DBVirtualList takes its name from the Virtual List mechanism so I used DBPagedSearch beacuse it uses Paged Seach. Therefore the name should indicate the mechanism used to interact with the DB. Currently, they are too different to merge in a single DBList with two LDAP*List implementation.
The idea of this class (in its implementation) is not to collect the results but in performing the query so I do not like the version with Results suffix.

*
* @author Marco Fargetta {@literal <[email protected]>}
*/
public class LDAPPagedSearch<E extends IDBObj> extends DBPagedSearch<E> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, would it be better to call it something like LDAPPagedList or LDAPPagedSearchResults?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

List<CertRecord> newPage = pages.getPage();
pageEntries = newPage.iterator();
} catch (EBaseException e) {
logger.error("CertRecordPage: Error to get a new page", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's throw a RuntimeException so that we'll know if there's an error. Please also append the original exception message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The equivalent class for VirtualList does not throw exception if no more entries can be accessed, IIUC but return a null value. However, I agee on throwing an exception here, I think it is better in case of problem

try {
pageEntries = pages.getPage().iterator();
} catch (EBaseException e) {
logger.error("CertRecordPage: Error to get a new page", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here.

Comment on lines 66 to 67
throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
e.toString()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's chain the original exception object so we can get the full stack trace.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same here

throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
.

I am fixing only in this class for this PR.

} catch (LDAPException e) {
if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
throw new EDBNotAvailException(
CMS.getUserMessage("CMS_DBS_INTERNAL_DIR_UNAVAILABLE"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here.

@fmarco76 fmarco76 force-pushed the CACertFindCLIFreeVLV branch 3 times, most recently from 4a780a0 to aa0dfd7 Compare January 9, 2024 10:22
@fmarco76 fmarco76 force-pushed the CACertFindCLIFreeVLV branch from aa0dfd7 to d829749 Compare January 9, 2024 11:53
Copy link

sonarqubecloud bot commented Jan 9, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

8 New issues
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@fmarco76 fmarco76 requested a review from edewata January 9, 2024 12:28
Copy link
Contributor

@edewata edewata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable. Thanks for the update!

@fmarco76 fmarco76 merged commit 6cbeda8 into dogtagpki:master Jan 9, 2024
131 checks passed
@fmarco76
Copy link
Member Author

fmarco76 commented Jan 9, 2024

@edewata Thanks!

@fmarco76 fmarco76 deleted the CACertFindCLIFreeVLV branch January 9, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants