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 4 commits
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
40 changes: 19 additions & 21 deletions src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3514,7 +3514,7 @@ public boolean reindex(Session session, List<Identifier> identifiers, boolean al
String notAuthorizedError ="The provided identity does not have permission to reindex "
+ "objects on the Node: ";
if (session == null) {
throw new NotAuthorized(notAuthorizedCode,notAuthorizedError + "public");
throw new NotAuthorized(notAuthorizedCode, notAuthorizedError + "public");
}
try {
Identifier identifier = null;
Expand All @@ -3523,10 +3523,10 @@ public boolean reindex(Session session, List<Identifier> identifiers, boolean al
authDel.doAdminAuthorization(session);
} catch (NotAuthorized na) {
if (session.getSubject() != null) {
throw new NotAuthorized(notAuthorizedCode,notAuthorizedError
throw new NotAuthorized(notAuthorizedCode, notAuthorizedError
+ session.getSubject().getValue());
} else {
throw new NotAuthorized(notAuthorizedCode,notAuthorizedError + "public");
throw new NotAuthorized(notAuthorizedCode, notAuthorizedError + "public");
}
}

Expand All @@ -3547,8 +3547,7 @@ protected void handleReindexAction(List<Identifier> pids) {
if (pids == null) {
return;
}
for (int i = 0; i < pids.size(); i++) {
Identifier identifier = pids.get(i);
for (Identifier identifier : pids) {
if (identifier != null) {
logMetacat.debug("MNodeService.handleReindexAction: queueing doc index for pid "
+ identifier.getValue());
Expand All @@ -3564,7 +3563,6 @@ protected void handleReindexAction(List<Identifier> pids) {
} catch (Exception e) {
logMetacat.info("MNodeService.handleReindexAction: Error submitting to "
+ "index for pid " + identifier.getValue());
continue;
}
}
}
Expand All @@ -3577,7 +3575,7 @@ protected void handleReindexAction(List<Identifier> pids) {
protected void handleReindexAllAction() {
// Process all of the documents
logMetacat.debug("MNodeService.handleReindexAllAction - "
+ "reindexl all objects in this Metacat instance");
+ "reindex all objects in this Metacat instance");
Runnable indexAll = new Runnable() {
public void run() {
List<String> resourceMapFormats = ResourceMapNamespaces.getNamespaces();
Expand All @@ -3595,23 +3593,24 @@ public void run() {
*/
private void buildAllNonResourceMapIndex(List<String> resourceMapFormatList) {
boolean firstTime = true;
String sql = "select guid from systemmetadata";
StringBuilder sql = new StringBuilder("select guid from systemmetadata");
if (resourceMapFormatList != null && resourceMapFormatList.size() > 0) {
for (String format : resourceMapFormatList) {
if (format != null && !format.trim().equals("")) {
if (firstTime) {
sql = sql + " where object_format !='" + format + "'";
sql.append(" where object_format !='" + format + "'");
Copy link
Contributor

Choose a reason for hiding this comment

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

Still has string concatenation

firstTime = false;
} else {
sql = sql + " and object_format !='" + format + "'";
sql.append(" and object_format !='" + format + "'");
Copy link
Contributor

Choose a reason for hiding this comment

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

Still has string concatenation

}
}
}
sql = sql + " order by date_uploaded asc";
sql.append(" order by date_uploaded asc");
}
logMetacat.debug("MNodeService.buildAllNonResourceMapIndex - the final query is " + sql);
logMetacat.debug("MNodeService.buildAllNonResourceMapIndex - the final query is "
+ sql.toString());
try {
long size = buildIndexFromQuery(sql);
long size = buildIndexFromQuery(sql.toString());
logMetacat.info(
"MNodeService.buildAllNonResourceMapIndex - the number of non-resource map "
+ "objects is "
Expand All @@ -3628,24 +3627,25 @@ private void buildAllNonResourceMapIndex(List<String> resourceMapFormatList) {
* @param resourceMapFormatList
*/
private void buildAllResourceMapIndex(List<String> resourceMapFormatList) {
String sql = "select guid from systemmetadata";
StringBuilder sql = new StringBuilder("select guid from systemmetadata");
if (resourceMapFormatList != null && resourceMapFormatList.size() > 0) {
boolean firstTime = true;
for (String format : resourceMapFormatList) {
if (format != null && !format.trim().equals("")) {
if (firstTime) {
sql = sql + " where object_format ='" + format + "'";
sql.append(" where object_format ='" + format + "'");
Copy link
Contributor

Choose a reason for hiding this comment

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

Still has string concatenation

firstTime = false;
} else {
sql = sql + " or object_format ='" + format + "'";
sql.append(" or object_format ='" + format + "'");
Copy link
Contributor

Choose a reason for hiding this comment

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

Still has string concatenation

}
}
}
sql = sql + " order by date_uploaded asc";
sql.append(" order by date_uploaded asc");
}
logMetacat.info("MNodeService.buildAllResourceMapIndex - the final query is " + sql);
logMetacat.info("MNodeService.buildAllResourceMapIndex - the final query is "
+ sql.toString());
try {
long size = buildIndexFromQuery(sql);
long size = buildIndexFromQuery(sql.toString());
logMetacat.info(
"MNodeService.buildAllResourceMapIndex - the number of resource map objects is "
+ size + " being submitted to the index queue.");
Expand Down Expand Up @@ -3699,8 +3699,6 @@ private long buildIndexFromQuery(String sql) throws SQLException {
}
rs.close();
stmt.close();
} catch (SQLException e) {
throw e;
} finally {
// Return database connection to the pool
DBConnectionPool.returnDBConnection(dbConn, serialNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,7 @@ protected void reindex() throws InvalidRequest, ServiceFailure, NotAuthorized, N
String[] allValueArray = params.get("all");
if (allValueArray != null) {
if (allValueArray.length != 1) {
throw new InvalidRequest("5903", "The \"all\" should only have one vaule");
throw new InvalidRequest("5903", "The \"all\" should only have one value");
} else {
String allValue = allValueArray[0];
if (allValue != null && allValue.equalsIgnoreCase("true")) {
Expand All @@ -1893,7 +1893,7 @@ protected void reindex() throws InvalidRequest, ServiceFailure, NotAuthorized, N
}
}
} else {
throw new InvalidRequest("5903", "Users should specify the \"pid\" vaule "
throw new InvalidRequest("5903", "Users should specify the \"pid\" value "
+ "for reindexing");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import edu.ucsb.nceas.metacat.database.DBConnection;
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
import edu.ucsb.nceas.metacat.doi.DOIServiceFactory;
import edu.ucsb.nceas.metacat.index.queue.FailedIndexResubmitTimerTaskTestIT;
import edu.ucsb.nceas.metacat.index.queue.FailedIndexResubmitTimerTaskIT;
import edu.ucsb.nceas.metacat.object.handler.JsonLDHandlerTest;
import edu.ucsb.nceas.metacat.object.handler.NonXMLMetadataHandlers;
import edu.ucsb.nceas.metacat.properties.PropertyService;
Expand Down Expand Up @@ -88,7 +88,7 @@
*
* @author cjones
*/
public class MNodeServiceTest extends D1NodeServiceTest {
public class MNodeServiceIT extends D1NodeServiceTest {

private static String unmatchingEncodingFilePath = "test/incorrect-encoding-declaration.xml";

Expand Down Expand Up @@ -119,68 +119,68 @@ public void tearDown() {
public static Test suite() {

TestSuite suite = new TestSuite();
suite.addTest(new MNodeServiceTest("initialize"));
suite.addTest(new MNodeServiceIT("initialize"));
// MNStorage tests
suite.addTest(new MNodeServiceTest("testMissMatchMetadataCreate"));
suite.addTest(new MNodeServiceTest("testMissMatchChecksumInCreate"));
suite.addTest(new MNodeServiceTest("testCreate"));
suite.addTest(new MNodeServiceTest("testCreateInvalidIdentifier"));
suite.addTest(new MNodeServiceTest("testUpdate"));
suite.addTest(new MNodeServiceTest("testMissMatchedCheckSumUpdate"));
suite.addTest(new MNodeServiceTest("testMissMatchedChecksumUpdateSciMetadata"));
suite.addTest(new MNodeServiceTest("testUpdateSystemMetadata"));
suite.addTest(new MNodeServiceTest("testUpdateObsoletesAndObsoletedBy"));
suite.addTest(new MNodeServiceTest("testArchive"));
suite.addTest(new MNodeServiceTest("testUpdateSciMetadata"));
suite.addTest(new MNodeServiceIT("testMissMatchMetadataCreate"));
suite.addTest(new MNodeServiceIT("testMissMatchChecksumInCreate"));
suite.addTest(new MNodeServiceIT("testCreate"));
suite.addTest(new MNodeServiceIT("testCreateInvalidIdentifier"));
suite.addTest(new MNodeServiceIT("testUpdate"));
suite.addTest(new MNodeServiceIT("testMissMatchedCheckSumUpdate"));
suite.addTest(new MNodeServiceIT("testMissMatchedChecksumUpdateSciMetadata"));
suite.addTest(new MNodeServiceIT("testUpdateSystemMetadata"));
suite.addTest(new MNodeServiceIT("testUpdateObsoletesAndObsoletedBy"));
suite.addTest(new MNodeServiceIT("testArchive"));
suite.addTest(new MNodeServiceIT("testUpdateSciMetadata"));
// this requires MN certificate
suite.addTest(new MNodeServiceTest("testDelete"));
suite.addTest(new MNodeServiceIT("testDelete"));

// MNRead tests
suite.addTest(new MNodeServiceTest("testGet"));
suite.addTest(new MNodeServiceTest("testGetChecksum"));
suite.addTest(new MNodeServiceTest("testGetSystemMetadata"));
suite.addTest(new MNodeServiceTest("testDescribe"));
suite.addTest(new MNodeServiceTest("testListObjects"));
suite.addTest(new MNodeServiceTest("testGetSID"));
suite.addTest(new MNodeServiceIT("testGet"));
suite.addTest(new MNodeServiceIT("testGetChecksum"));
suite.addTest(new MNodeServiceIT("testGetSystemMetadata"));
suite.addTest(new MNodeServiceIT("testDescribe"));
suite.addTest(new MNodeServiceIT("testListObjects"));
suite.addTest(new MNodeServiceIT("testGetSID"));
// this requires CN certificate
suite.addTest(new MNodeServiceTest("testSynchronizationFailed"));
suite.addTest(new MNodeServiceIT("testSynchronizationFailed"));

// MNCore tests
suite.addTest(new MNodeServiceTest("testPing"));
suite.addTest(new MNodeServiceTest("testGetLogRecords"));
suite.addTest(new MNodeServiceTest("testGetCapabilities"));
suite.addTest(new MNodeServiceIT("testPing"));
suite.addTest(new MNodeServiceIT("testGetLogRecords"));
suite.addTest(new MNodeServiceIT("testGetCapabilities"));

// MNAuthorization tests
suite.addTest(new MNodeServiceTest("testIsAuthorized"));
suite.addTest(new MNodeServiceTest("testIsEquivIdentityAuthorized"));
suite.addTest(new MNodeServiceTest("testSetAccessPolicy"));
suite.addTest(new MNodeServiceIT("testIsAuthorized"));
suite.addTest(new MNodeServiceIT("testIsEquivIdentityAuthorized"));
suite.addTest(new MNodeServiceIT("testSetAccessPolicy"));
// MNreplication tests
suite.addTest(new MNodeServiceTest("testReplicate"));
suite.addTest(new MNodeServiceIT("testReplicate"));
// MN packaging tests
suite.addTest(new MNodeServiceTest("testGetPackage"));
suite.addTest(new MNodeServiceTest("testGetOREPackage"));
suite.addTest(new MNodeServiceTest("testReadDeletedObject"));
suite.addTest(new MNodeServiceTest("testCreateAndUpdateXMLWithUnmatchingEncoding"));
suite.addTest(new MNodeServiceTest("testListViews"));
suite.addTest(new MNodeServiceTest("testCreateNOAAObject"));

suite.addTest(new MNodeServiceTest("testPermissionOfUpdateSystemmeta"));

suite.addTest(new MNodeServiceTest("testUpdateSystemMetadataWithCircularObsoletesChain"));

suite.addTest(new MNodeServiceTest("testUpdateSystemMetadataWithCircularObsoletedByChain"));
suite.addTest(new MNodeServiceTest("testUpdateSystemMetadataImmutableFields"));
suite.addTest(new MNodeServiceTest("testUpdateAuthoritativeMN"));
suite.addTest(new MNodeServiceTest("testInvalidIds"));
suite.addTest(new MNodeServiceTest("testPublishPackage"));
suite.addTest(new MNodeServiceTest("testPublishPrivatePackage"));
suite.addTest(new MNodeServiceTest("testAllowList"));
suite.addTest(new MNodeServiceTest("testInsertJson_LD"));
suite.addTest(new MNodeServiceTest("testCreateAndUpdateEventLog"));
suite.addTest(new MNodeServiceTest("testUpdateSystemMetadataPermission"));
suite.addTest(new MNodeServiceTest("testCreateAndUpdateWithDoiDisabled"));
suite.addTest(new MNodeServiceTest("testCreateAndUpdateFGDC"));
suite.addTest(new MNodeServiceTest("testReindex"));
suite.addTest(new MNodeServiceIT("testGetPackage"));
suite.addTest(new MNodeServiceIT("testGetOREPackage"));
suite.addTest(new MNodeServiceIT("testReadDeletedObject"));
suite.addTest(new MNodeServiceIT("testCreateAndUpdateXMLWithUnmatchingEncoding"));
suite.addTest(new MNodeServiceIT("testListViews"));
suite.addTest(new MNodeServiceIT("testCreateNOAAObject"));

suite.addTest(new MNodeServiceIT("testPermissionOfUpdateSystemmeta"));

suite.addTest(new MNodeServiceIT("testUpdateSystemMetadataWithCircularObsoletesChain"));

suite.addTest(new MNodeServiceIT("testUpdateSystemMetadataWithCircularObsoletedByChain"));
suite.addTest(new MNodeServiceIT("testUpdateSystemMetadataImmutableFields"));
suite.addTest(new MNodeServiceIT("testUpdateAuthoritativeMN"));
suite.addTest(new MNodeServiceIT("testInvalidIds"));
suite.addTest(new MNodeServiceIT("testPublishPackage"));
suite.addTest(new MNodeServiceIT("testPublishPrivatePackage"));
suite.addTest(new MNodeServiceIT("testAllowList"));
suite.addTest(new MNodeServiceIT("testInsertJson_LD"));
suite.addTest(new MNodeServiceIT("testCreateAndUpdateEventLog"));
suite.addTest(new MNodeServiceIT("testUpdateSystemMetadataPermission"));
suite.addTest(new MNodeServiceIT("testCreateAndUpdateWithDoiDisabled"));
suite.addTest(new MNodeServiceIT("testCreateAndUpdateFGDC"));
suite.addTest(new MNodeServiceIT("testReindex"));
return suite;

}
Expand All @@ -190,7 +190,7 @@ public static Test suite() {
*
* @param name - the name of the test
*/
public MNodeServiceTest(String name) {
public MNodeServiceIT(String name) {
super(name);

}
Expand Down Expand Up @@ -4518,7 +4518,7 @@ public void testReindex() throws Exception {
stream = MNodeService.getInstance(request).query(session, "solr", query);
resultStr = IOUtils.toString(stream, "UTF-8");
}
String version = FailedIndexResubmitTimerTaskTestIT.getSolrDocVersion(resultStr);
String version = FailedIndexResubmitTimerTaskIT.getSolrDocVersion(resultStr);
//second object
Identifier guid1 = new Identifier();
guid1.setValue("testCreateFailure." + System.currentTimeMillis());
Expand All @@ -4540,7 +4540,7 @@ public void testReindex() throws Exception {
stream = MNodeService.getInstance(request).query(session, "solr", query1);
resultStr = IOUtils.toString(stream, "UTF-8");
}
String version1 = FailedIndexResubmitTimerTaskTestIT.getSolrDocVersion(resultStr);
String version1 = FailedIndexResubmitTimerTaskIT.getSolrDocVersion(resultStr);

List<Identifier> identifiers = new ArrayList<Identifier>();
identifiers.add(guid);
Expand Down Expand Up @@ -4575,7 +4575,7 @@ public void testReindex() throws Exception {
count++;
stream = MNodeService.getInstance(request).query(session, "solr", query);
resultStr = IOUtils.toString(stream, "UTF-8");
newVersion = FailedIndexResubmitTimerTaskTestIT.getSolrDocVersion(resultStr);
newVersion = FailedIndexResubmitTimerTaskIT.getSolrDocVersion(resultStr);
versionChanged = !newVersion.equals(version);
}
assertTrue(versionChanged);
Expand All @@ -4590,7 +4590,7 @@ public void testReindex() throws Exception {
count++;
stream = MNodeService.getInstance(request).query(session, "solr", query1);
resultStr = IOUtils.toString(stream, "UTF-8");
newVersion1 = FailedIndexResubmitTimerTaskTestIT.getSolrDocVersion(resultStr);
newVersion1 = FailedIndexResubmitTimerTaskIT.getSolrDocVersion(resultStr);
versionChanged = !newVersion1.equals(version1);
}
assertTrue(versionChanged);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* @author tao
*
*/
public class FailedIndexResubmitTimerTaskTestIT {
public class FailedIndexResubmitTimerTaskIT {
private Session session = null;
private Identifier guid = null;
private String query = null;
Expand Down
4 changes: 2 additions & 2 deletions test/edu/ucsb/nceas/metacat/util/AuthUtilIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.dataone.service.util.TypeMarshaller;

import edu.ucsb.nceas.metacat.dataone.MNodeService;
import edu.ucsb.nceas.metacat.dataone.MNodeServiceTest;
import edu.ucsb.nceas.metacat.dataone.MNodeServiceIT;
import edu.ucsb.nceas.metacat.properties.PropertyService;
import junit.framework.Test;
import junit.framework.TestSuite;
Expand All @@ -57,7 +57,7 @@
* @author tao
*
*/
public class AuthUtilIT extends MNodeServiceTest {
public class AuthUtilIT extends MNodeServiceIT {

private File tmpPasswordFile = null;
private String thirdUser = null;
Expand Down