Merge branch 'feature/SEARCH-2014_SolrAdminAPI' into 'master'

Add missing parameter messages to responses instead of throwing Exceptions.

See merge request search_discovery/insightengine!376
This commit is contained in:
Angel Borroy
2020-02-14 06:46:24 +00:00
3 changed files with 696 additions and 227 deletions
@@ -984,18 +984,22 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler
* - core, The name of the SOLR Core or "null" to get the report for every core
* @return Response including the action result:
* - report: An Object with the report details
* - error: When mandatory parameters are not set, an error node is returned
*
* @throws JSONException
*/
private NamedList<Object> actionNODEREPORTS(SolrParams params) throws JSONException
{
Long dbid =
ofNullable(params.get(ARG_NODEID))
.map(Long::valueOf)
.orElseThrow(() -> new AlfrescoRuntimeException("No dbid parameter set."));
NamedList<Object> report = new SimpleOrderedMap<>();
if (params.get(ARG_NODEID) == null)
{
report.add(ACTION_STATUS_ERROR, "No " + ARG_NODEID +" parameter set.");
return report;
}
Long nodeid = Long.valueOf(params.get(ARG_NODEID));
String requestedCoreName = coreName(params);
coreNames().stream()
@@ -1006,7 +1010,7 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler
.forEach(coreNameAndPublisher ->
report.add(
coreNameAndPublisher.getFirst(),
buildNodeReport(coreNameAndPublisher.getSecond(), dbid)));
buildNodeReport(coreNameAndPublisher.getSecond(), nodeid)));
return report;
}
@@ -1020,18 +1024,21 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler
* - core, The name of the SOLR Core or "null" to get the report for every core
* @return Response including the action result:
* - report: an Object with the details of the report
*
* - error: When mandatory parameters are not set, an error node is returned
*
* @throws JSONException
*/
private NamedList<Object> actionACLREPORT(SolrParams params) throws JSONException
{
Long aclid =
ofNullable(params.get(ARG_ACLID))
.map(Long::valueOf)
.orElseThrow(() -> new AlfrescoRuntimeException("No " + ARG_ACLID + " parameter set."));
NamedList<Object> report = new SimpleOrderedMap<>();
if (params.get(ARG_ACLID) == null)
{
report.add(ACTION_STATUS_ERROR, "No " + ARG_ACLID + " parameter set.");
return report;
}
Long aclid = Long.valueOf(params.get(ARG_ACLID));
String requestedCoreName = coreName(params);
coreNames().stream()
@@ -1062,32 +1069,43 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler
* - core, The name of the SOLR Core or "null" to get the report for every core
* @return Response including the action result:
* - report: an Object with the details of the report
* - error: When mandatory parameters are not set, an error node is returned
*
* @throws JSONException
*/
private NamedList<Object> actionTXREPORT(SolrParams params) throws JSONException
{
String coreName =
ofNullable(coreName(params))
.orElseThrow(() -> new AlfrescoRuntimeException("No " + CoreAdminParams.CORE + " parameter set."));
NamedList<Object> report = new SimpleOrderedMap<>();
if (isMasterOrStandalone(coreName))
if (params.get(ARG_TXID) == null)
{
MetadataTracker tracker = trackerRegistry.getTrackerForCore(coreName, MetadataTracker.class);
Long txid =
ofNullable(params.get(ARG_TXID))
.map(Long::valueOf)
.orElseThrow(() -> new AlfrescoRuntimeException("No " + ARG_TXID + " parameter set."));
report.add(coreName, buildTxReport(trackerRegistry, informationServers.get(coreName), coreName, tracker, txid));
report.add(ACTION_STATUS_ERROR, "No " + ARG_TXID + " parameter set.");
return report;
}
else
Long txid = Long.valueOf(params.get(ARG_TXID));
String requestedCoreName = coreName(params);
coreNames().stream()
.filter(coreName -> requestedCoreName == null || coreName.equals(requestedCoreName))
.map(coreName -> new Pair<>(coreName, trackerRegistry.getTrackerForCore(coreName, MetadataTracker.class)))
.filter(coreNameAndMetadataTracker -> coreNameAndMetadataTracker.getSecond() != null)
.forEach(coreNameAndMetadataTracker ->
report.add(
coreNameAndMetadataTracker.getFirst(),
buildTxReport(
trackerRegistry,
informationServers.get(coreNameAndMetadataTracker.getFirst()),
coreNameAndMetadataTracker.getFirst(),
coreNameAndMetadataTracker.getSecond(),
txid)));
if (report.size() == 0)
{
addAlertMessage(report);
}
return report;
}
/**
@@ -1100,18 +1118,21 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler
* - acltxid, mandatory, the number of the ACL TX Id to build the report
* @return Response including the action result:
* - report: an Object with the details of the report
* - error: When mandatory parameters are not set, an error node is returned
*
* @throws JSONException
*/
private NamedList<Object> actionACLTXREPORT(SolrParams params) throws JSONException
{
Long acltxid =
ofNullable(params.get(ARG_ACLTXID))
.map(Long::valueOf)
.orElseThrow(() -> new AlfrescoRuntimeException("No " + ARG_ACLTXID + " parameter set."));
NamedList<Object> report = new SimpleOrderedMap<>();
if (params.get(ARG_ACLTXID) == null)
{
report.add(ACTION_STATUS_ERROR, "No " + ARG_ACLTXID + " parameter set.");
return report;
}
Long acltxid = Long.valueOf(params.get(ARG_ACLTXID));
String requestedCoreName = coreName(params);
coreNames().stream()
@@ -1145,17 +1166,21 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler
* - core, The name of the SOLR Core
* @return Response including the action result:
* - report: An Object with the report details
* - error: When mandatory parameters are not set, an error node is returned
*
* @throws IOException
*/
private NamedList<Object> rangeCheck(SolrParams params) throws IOException
{
String coreName =
ofNullable(coreName(params))
.orElseThrow(() -> new AlfrescoRuntimeException("No " + CoreAdminParams.CORE + " parameter set."));
NamedList<Object> response = new SimpleOrderedMap<>();
String coreName = coreName(params);
if (coreName == null)
{
response.add(ACTION_STATUS_ERROR, "No " + CoreAdminParams.CORE + " parameter set.");
return response;
}
if (isMasterOrStandalone(coreName))
{
InformationServer informationServer = informationServers.get(coreName);
@@ -1235,7 +1260,7 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler
else
{
response.add("expand", -1);
response.add("exception", "ERROR: Wrong document router type:"+docRouter.getClass().getSimpleName());
response.add("exception", "ERROR: Wrong document router type:" + docRouter.getClass().getSimpleName());
}
}
else
@@ -1257,17 +1282,21 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler
* @return Response including the action result:
* - expand: The number of the new End Range limit or -1 if the action failed
* - exception: Error message if expand is -1
* - error: When mandatory parameters are not set, an error node is returned
*
* @throws IOException
*/
private synchronized NamedList<Object> expand(SolrParams params) throws IOException
{
String coreName =
ofNullable(coreName(params))
.orElseThrow(() -> new AlfrescoRuntimeException("No " + CoreAdminParams.CORE + " parameter set."));
NamedList<Object> response = new SimpleOrderedMap<>();
String coreName = coreName(params);
if (coreName == null)
{
response.add(ACTION_STATUS_ERROR, "No " + CoreAdminParams.CORE + " parameter set.");
return response;
}
if (isMasterOrStandalone(coreName))
{
InformationServer informationServer = informationServers.get(coreName);
@@ -290,23 +290,6 @@ public class AlfrescoCoreAdminHandlerIT
when(params.get(CoreAdminParams.ACTION)).thenReturn(TXREPORT);
when(params.get(CoreAdminParams.CORE)).thenReturn(CORE_NAME);
when(params.get(ARG_TXID)).thenReturn(TX_ID);
// Set up the mock ACL tracker.
when(trackerRegistry.getTrackerForCore(CORE_NAME, AclTracker.class)).thenReturn(aclTracker);
when(aclTracker.checkIndex(Long.valueOf(TX_ID), 0L, null, null)).thenReturn(indexHealthReport);
when(indexHealthReport.getDuplicatedAclTxInIndex()).thenReturn(iOpenBitSet);
when(indexHealthReport.getAclTxInIndexButNotInDb()).thenReturn(iOpenBitSet);
when(indexHealthReport.getMissingAclTxFromIndex()).thenReturn(iOpenBitSet);
when(aclTracker.getTrackerState()).thenReturn(trackerState);
// Set up the mock metadata tracker.
when(trackerRegistry.getTrackerForCore(CORE_NAME, MetadataTracker.class)).thenReturn(metadataTracker);
when(metadataTracker.checkIndex(Long.valueOf(TX_ID), 0L, null, null)).thenReturn(metaReport);
when(metaReport.getDuplicatedTxInIndex()).thenReturn(iOpenBitSet);
when(metaReport.getTxInIndexButNotInDb()).thenReturn(iOpenBitSet);
when(metaReport.getMissingTxFromIndex()).thenReturn(iOpenBitSet);
when(metaReport.getDuplicatedLeafInIndex()).thenReturn(iOpenBitSet);
when(metaReport.getDuplicatedErrorInIndex()).thenReturn(iOpenBitSet);
when(metaReport.getDuplicatedUnindexedInIndex()).thenReturn(iOpenBitSet);
when(metadataTracker.getTrackerState()).thenReturn(trackerState);
// Call the method under test.
alfrescoCoreAdminHandler.handleCustomAction(req, rsp);
@@ -315,24 +298,27 @@ public class AlfrescoCoreAdminHandlerIT
verify(rsp).add(eq("report"), any(NamedList.class));
}
/** Check that when the transaction id is missing we get an exception. */
@Test(expected = SolrException.class)
/** Check that when the transaction id is missing we get an error message. */
@Test
public void handleCustomActionTXReportMissingTXId()
{
when(params.get(CoreAdminParams.ACTION)).thenReturn(TXREPORT);
alfrescoCoreAdminHandler.handleCustomAction(req, rsp);
verify(rsp, never()).add(anyString(), any());
verify(rsp).add(eq("report"), any(NamedList.class));
}
/** Check that when the core name is missing we get an exception. */
@Test(expected = SolrException.class)
/** Check that when the core name is missing we get a report for every core. */
@Test
public void handleCustomActionTXReportMissingCoreName()
{
when(params.get(CoreAdminParams.ACTION)).thenReturn(TXREPORT);
when(params.get(CoreAdminParams.CORE)).thenReturn(null);
alfrescoCoreAdminHandler.handleCustomAction(req, rsp);
// Check that a report was generated (don't look at the contents of the report though).
verify(rsp).add(eq("report"), any(NamedList.class));
}
/** Check that when an unknown action is provided we don't generate a report. */