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

Feature 1716-mn-reindex #1738

Merged
merged 13 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3509,8 +3509,8 @@ public void publishIdentifier(Session session, Identifier identifier)
public boolean reindex(Session session, List<Identifier> identifiers, boolean all)
Copy link
Contributor

Choose a reason for hiding this comment

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

throws ServiceFailure, NotAuthorized, NotImplemented, InvalidRequest {
boolean scheduled = true;
String serviceFailureCode = "5900";
String notAuthorizedCode = "5901";
String serviceFailureCode = "5901";
String notAuthorizedCode = "5902";
String notAuthorizedError ="The provided identity does not have permission to reindex "
+ "objects on the Node.";
if (session == null) {
Expand Down Expand Up @@ -3538,6 +3538,7 @@ public boolean reindex(Session session, List<Identifier> identifiers, boolean al
* @param pids the list of identifier whose solr doc needs to be rebuilt
*/
protected void handleReindexAction(List<Identifier> pids) {
logMetacat.debug("MNodeService.handleReindexAction - reindex some objects");
if (pids == null) {
return;
}
Expand Down Expand Up @@ -3570,7 +3571,8 @@ protected void handleReindexAction(List<Identifier> pids) {
*/
protected void handleReindexAllAction() {
// Process all of the documents
logMetacat.debug("MNodeService.handleReindexAllActionqueueing doc index for all documents");
logMetacat.debug("MNodeService.handleReindexAllAction - "
+ "reindexl all objects in this Metacat instance");
taojing2002 marked this conversation as resolved.
Show resolved Hide resolved
Runnable indexAll = new Runnable() {
public void run() {
List<String> resourceMapFormats = ResourceMapNamespaces.getNamespaces();
Expand Down
57 changes: 56 additions & 1 deletion src/edu/ucsb/nceas/metacat/restservice/v2/MNResourceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
Expand Down Expand Up @@ -137,7 +138,10 @@
*
* MNReplication
* replicate() - POST /d1/mn/replicate
* getReplica() - GET /d1/mn/replica
* getReplica() - GET /d1/mn/replica
*
* MNAdmin
* reindex() - GET /d1/mn/reindex
*
* ******************
* @author leinfelder
Expand All @@ -159,6 +163,7 @@ public class MNResourceHandler extends D1ResourceHandler {
protected static final String RESOURCE_WHOAMI = "whoami";
//make the status of identifier (e.g. DOI) public
protected static final String RESOURCE_PUBLISH_IDENTIFIER = "publishIdentifier";
protected static final String RESOURCE_REINDEX = "reindex";



Expand Down Expand Up @@ -527,6 +532,14 @@ public void handle(byte httpVerb) {
publishIdentifier(extra);
status = true;
}
} else if (resource.startsWith(RESOURCE_REINDEX)) {
logMetacat.debug("Using resource: " + RESOURCE_REINDEX);
// GET
if (httpVerb == GET) {
// after the command
reindex();
status = true;
}
} else {
throw new InvalidRequest("0000", "No resource matched for " + resource);
}
Expand Down Expand Up @@ -1845,5 +1858,47 @@ protected void updateSystemMetadata() throws ServiceFailure, InvalidRequest,
MNodeService.getInstance(request).updateSystemMetadata(session, pid, systemMetadata);
}

/**
* Handle the reindex request
* @throws InvalidRequest
* @throws ServiceFailure
* @throws NotAuthorized
* @throws NotImplemented
*/
protected void reindex() throws InvalidRequest, ServiceFailure, NotAuthorized, NotImplemented {
boolean all = false;
List<Identifier> identifiers = new ArrayList<Identifier>();
String[] allValueArray = params.get("all");
logMetacat.debug("MNResourceHandler.reindex - the allValueArray in the request is "
+ allValueArray);
if (allValueArray != null) {
if (allValueArray.length != 1) {
throw new InvalidRequest("5903", "The \"all\" should only have one vaule");
taojing2002 marked this conversation as resolved.
Show resolved Hide resolved
} else {
String allValue = allValueArray[0];
if (allValue != null && allValue.equalsIgnoreCase("true")) {
all = true;
}
}
}
if (!all) {
String[] ids = params.get("pid");
logMetacat.debug("MNResourceHandler.reindex - the pid list in the request is " + ids);
if (ids != null) {
for (String id : ids) {
if (id != null && !id.trim().equals("")) {
Identifier identifier = new Identifier();
identifier.setValue(id);
identifiers.add(identifier);
}
}
} else {
throw new InvalidRequest("5903", "Users should specify the \"pid\" vaule "
taojing2002 marked this conversation as resolved.
Show resolved Hide resolved
+ "for reindexing");
}
}
MNodeService.getInstance(request).reindex(session, identifiers, all);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's almost always bad practice to have a boolean parameter in a public method if that method is not a setter.

When reading this calling code, it's not obvious what the boolean stands for without looking at the source or documentation. (also known as the boolean trap).

I think it would be much clearer if this code called the handleReindexAllAction() or the handleReindexAction() directly, instead of passing the boolean.

}

}