Merge pull request #193 from Alfresco/fix/SEARCH-2602_MissedInformationSearchPage

Fix/search 2602 missed information search page
This commit is contained in:
Angel Borroy
2020-12-04 12:58:08 +01:00
committed by GitHub
4 changed files with 278 additions and 149 deletions

View File

@@ -124,6 +124,12 @@ jobs:
- docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:2.3.6
script: travis_wait 20 mvn -B test -pl repository -Dtest=MiscContextTestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco -Dalfresco-pdf-renderer.url=http://localhost:8090/ -Djodconverter.url=http://localhost:8090/ -Dimg.url=http://localhost:8090/ -Dtika.url=http://localhost:8090/ -Dtransform.misc.url=http://localhost:8090/
- name: "Repository - SearchTestSuite"
before_script:
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:11.7 postgres -c 'max_connections=300'
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.8
script: travis_wait 20 mvn -B test -pl repository -Dtest=SearchTestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco -Dindex.subsystem.name=solr6
- name: "Repository - MySQL tests"
if: commit_message !~ /\[skip db\]/
before_script:

View File

@@ -26,14 +26,13 @@
package org.alfresco.repo.search.impl.solr;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
import org.alfresco.repo.search.QueryParserException;
import org.alfresco.service.cmr.repository.datatype.Duration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.context.ApplicationContext;
@@ -43,40 +42,63 @@ import org.springframework.context.ApplicationContext;
*/
public class SolrChildApplicationContextFactory extends ChildApplicationContextFactory
{
private static final Log LOGGER = LogFactory.getLog(SolrChildApplicationContextFactory.class);
private static String ALFRESCO_ACTIVE = "tracker.alfresco.active";
protected static final String ALFRESCO_ACTIVE = "tracker.alfresco.active";
protected static final String ALFRESCO_LAG = "tracker.alfresco.lag";
protected static final String ALFRESCO_LAG_DURATION = "tracker.alfresco.lag.duration";
protected static final String ALFRESCO_LAST_INDEXED_TXN = "tracker.alfresco.last.indexed.txn";
protected static final String ALFRESCO_APPROX_TXNS_REMAINING = "tracker.alfresco.approx.txns.remaining";
protected static final String ALFRESCO_APPROX_INDEXING_TIME_REMAINING = "tracker.alfresco.approx.indexing.time.remaining";
protected static final String ALFRESCO_DISK = "tracker.alfresco.disk";
protected static final String ALFRESCO_MEMORY = "tracker.alfresco.memory";
private static String ALFRESCO_LAG = "tracker.alfresco.lag";
protected static final String ARCHIVE_ACTIVE = "tracker.archive.active";
protected static final String ARCHIVE_LAG = "tracker.archive.lag";
protected static final String ARCHIVE_LAG_DURATION = "tracker.archive.lag.duration";
protected static final String ARCHIVE_LAST_INDEXED_TXN = "tracker.archive.last.indexed.txn";
protected static final String ARCHIVE_APPROX_TXNS_REMAINING = "tracker.archive.approx.txns.remaining";
protected static final String ARCHIVE_APPROX_INDEXING_TIME_REMAINING = "tracker.archive.approx.indexing.time.remaining";
protected static final String ARCHIVE_DISK = "tracker.archive.disk";
protected static final String ARCHIVE_MEMORY = "tracker.archive.memory";
private static final String SUMMARY_FIELD_TOTAL_SEARCHER_CACHE_GB = "Total Searcher Cache (GB)";
private static final String SUMMARY_FIELD_ON_DISK_GB = "On disk (GB)";
private static final String SUMMARY_FIELD_APPROX_TRANSACTION_INDEXING_TIME_REMAINING = "Approx transaction indexing time remaining";
private static final String SUMMARY_FIELD_APPROX_TRANSACTIONS_REMAINING = "Approx transactions remaining";
private static final String SUMMARY_FIELD_ID_FOR_LAST_TX_IN_INDEX = "Id for last TX in index";
private static final String SUMMARY_FIELD_TX_DURATION = "TX Duration";
private static final String SUMMARY_FIELD_TX_LAG = "TX Lag";
private static final String SUMMARY_FIELD_ACTIVE = "Active";
private static String ALFRESCO_LAG_DURATION = "tracker.alfresco.lag.duration";
private SolrAdminHTTPClient adminClient;
private static String ALFRESCO_LAST_INDEXED_TXN = "tracker.alfresco.last.indexed.txn";
public void setAdminClient(SolrAdminHTTPClient adminClient)
{
this.adminClient = adminClient;
}
private static String ALFRESCO_APPROX_TXNS_REMAINING = "tracker.alfresco.approx.txns.remaining";
public SolrAdminHTTPClient getAdminClient()
{
if (adminClient == null)
{
ApplicationContext ctx = getApplicationContext();
adminClient = (SolrAdminHTTPClient) ctx.getBean("search.solrAdminHTTPCLient");
}
return adminClient;
}
private static String ALFRESCO_APPROX_INDEXING_TIME_REMAINING = "tracker.alfresco.approx.indexing.time.remaining";
private static String ALFRESCO_DISK = "tracker.alfresco.disk";
private static String ALFRESCO_MEMORY = "tracker.alfresco.memory";
private static boolean isAlfrescoCoreProperty(String name)
{
return name.startsWith("tracker.alfresco.");
}
private static String ARCHIVE_ACTIVE = "tracker.archive.active";
private static String ARCHIVE_LAG = "tracker.archive.lag";
private static String ARCHIVE_LAG_DURATION = "tracker.archive.lag.duration";
private static boolean isArchiveCoreProperty(String name)
{
return name.startsWith("tracker.archive.");
}
private static String ARCHIVE_LAST_INDEXED_TXN = "tracker.archive.last.indexed.txn";
private static String ARCHIVE_APPROX_TXNS_REMAINING = "tracker.archive.approx.txns.remaining";
private static String ARCHIVE_APPROX_INDEXING_TIME_REMAINING = "tracker.archive.approx.indexing.time.remaining";
private static String ARCHIVE_DISK = "tracker.archive.disk";
private static String ARCHIVE_MEMORY = "tracker.archive.memory";
@Override
public boolean isUpdateable(String name)
{
@@ -101,118 +123,96 @@ public class SolrChildApplicationContextFactory extends ChildApplicationContextF
&& !name.equals(SolrChildApplicationContextFactory.ARCHIVE_MEMORY)
;
}
private String getPropertyValue(JSONObject core, String name)
{
switch (name)
{
case SolrChildApplicationContextFactory.ALFRESCO_ACTIVE:
case SolrChildApplicationContextFactory.ARCHIVE_ACTIVE:
return core.getBoolean(SUMMARY_FIELD_ACTIVE) ? "true" : "false";
case SolrChildApplicationContextFactory.ALFRESCO_LAG:
case SolrChildApplicationContextFactory.ARCHIVE_LAG:
return core.getString(SUMMARY_FIELD_TX_LAG);
case SolrChildApplicationContextFactory.ALFRESCO_LAG_DURATION:
case SolrChildApplicationContextFactory.ARCHIVE_LAG_DURATION:
return core.getString(SUMMARY_FIELD_TX_DURATION);
case SolrChildApplicationContextFactory.ALFRESCO_LAST_INDEXED_TXN:
case SolrChildApplicationContextFactory.ARCHIVE_LAST_INDEXED_TXN:
return core.getNumber(SUMMARY_FIELD_ID_FOR_LAST_TX_IN_INDEX).toString();
case SolrChildApplicationContextFactory.ALFRESCO_APPROX_TXNS_REMAINING:
case SolrChildApplicationContextFactory.ARCHIVE_APPROX_TXNS_REMAINING:
return core.getNumber(SUMMARY_FIELD_APPROX_TRANSACTIONS_REMAINING).toString();
case SolrChildApplicationContextFactory.ALFRESCO_APPROX_INDEXING_TIME_REMAINING:
case SolrChildApplicationContextFactory.ARCHIVE_APPROX_INDEXING_TIME_REMAINING:
return core.getString(SUMMARY_FIELD_APPROX_TRANSACTION_INDEXING_TIME_REMAINING);
case SolrChildApplicationContextFactory.ALFRESCO_DISK:
case SolrChildApplicationContextFactory.ARCHIVE_DISK:
return core.getNumber(SUMMARY_FIELD_ON_DISK_GB).toString();
case SolrChildApplicationContextFactory.ALFRESCO_MEMORY:
case SolrChildApplicationContextFactory.ARCHIVE_MEMORY:
return core.getNumber(SUMMARY_FIELD_TOTAL_SEARCHER_CACHE_GB).toString();
default:
return null;
}
}
private JSONObject getSolrSummary()
{
HashMap<String, String> args = new HashMap<String, String>();
args.put("action", "SUMMARY");
args.put("wt", "json");
JSONObject json = getAdminClient().execute(args);
return json.getJSONObject("Summary");
}
@Override
public String getProperty(String name)
{
// MNT-9254 fix, use search.solrAdminHTTPCLient bean to retrive property value only if sorl subsystem is active and started (application context in state should be not null)
// MNT-9254 fix, use search.solrAdminHTTPCLient bean to retrieve property value only if sorl subsystem is active and started (application context in state should be not null)
if (false == isUpdateable(name) && ((ApplicationContextState) getState(false)).getApplicationContext(false) != null)
{
try
{
ApplicationContext ctx = getApplicationContext();
SolrAdminHTTPClient adminClient = (SolrAdminHTTPClient) ctx.getBean("search.solrAdminHTTPCLient");
HashMap<String, String> args = new HashMap<String, String>();
args.put("action", "SUMMARY");
args.put("wt", "json");
JSONObject json = adminClient.execute(args);
JSONObject summary = json.getJSONObject("Summary");
JSONObject alfresco = null;
try
JSONObject summary = getSolrSummary();
if (isAlfrescoCoreProperty(name))
{
alfresco = summary.getJSONObject("alfresco");
}
catch (JSONException e)
{
// The core might be absent.
}
if (alfresco != null)
{
if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_ACTIVE))
JSONObject alfresco = null;
try
{
String alfrescoActive = alfresco.getString("Active");
if (alfrescoActive == null || alfrescoActive.isEmpty())
{
// Admin Console is expecting a true/false value, not blank
return "false";
}
return alfrescoActive;
alfresco = summary.getJSONObject("alfresco");
}
else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_LAG))
catch (JSONException e)
{
return alfresco.getString("TX Lag");
// The core might be absent.
LOGGER.debug("Node alfresco not found", e);
}
else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_LAG_DURATION))
if (alfresco != null)
{
return alfresco.getString("TX Duration");
}
else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_LAST_INDEXED_TXN))
{
return alfresco.getString("Id for last TX in index");
}
else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_APPROX_TXNS_REMAINING))
{
return alfresco.getString("Approx transactions remaining");
}
else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_APPROX_INDEXING_TIME_REMAINING))
{
return alfresco.getString("Approx transaction indexing time remaining");
}
else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_DISK))
{
return alfresco.getString("On disk (GB)");
}
else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_MEMORY))
{
return alfresco.getString("Total Searcher Cache (GB)");
return getPropertyValue(alfresco, name);
}
}
JSONObject archive = null;
try
if (isArchiveCoreProperty(name))
{
archive = summary.getJSONObject("archive");
}
catch (JSONException e)
{
// The core might be absent.
}
if (archive != null)
{
if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_ACTIVE))
JSONObject archive = null;
try
{
return archive.getString("Active");
archive = summary.getJSONObject("archive");
}
else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_LAG))
catch (JSONException e)
{
return archive.getString("TX Lag");
// The core might be absent.
LOGGER.debug("Node archive not found", e);
}
else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_LAG_DURATION))
if (archive != null)
{
return archive.getString("TX Duration");
}
else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_LAST_INDEXED_TXN))
{
return archive.getString("Id for last TX in index");
}
else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_APPROX_TXNS_REMAINING))
{
return archive.getString("Approx transactions remaining");
}
else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_APPROX_INDEXING_TIME_REMAINING))
{
return archive.getString("Approx transaction indexing time remaining");
}
else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_DISK))
{
return archive.getString("On disk (GB)");
}
else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_MEMORY))
{
return archive.getString("Total Searcher Cache (GB)");
return getPropertyValue(archive, name);
}
}

View File

@@ -25,39 +25,28 @@
*/
package org.alfresco.repo.search;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.alfresco.repo.search.impl.parsers.CMISTest;
import org.alfresco.repo.search.impl.parsers.CMIS_FTSTest;
import org.alfresco.repo.search.impl.parsers.FTSTest;
import org.alfresco.repo.search.impl.solr.SolrChildApplicationContextFactoryTest;
import org.alfresco.util.NumericEncodingTest;
import org.junit.experimental.categories.Categories;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* @author Andy Hind
*
*/
public class SearchTestSuite extends TestSuite
@RunWith(Categories.class)
@Suite.SuiteClasses({
MLAnaysisModeExpansionTest.class,
QueryRegisterComponentTest.class,
SearcherComponentTest.class,
DocumentNavigatorTest.class,
NumericEncodingTest.class,
CMIS_FTSTest.class,
CMISTest.class,
FTSTest.class,
SolrChildApplicationContextFactoryTest.class
})
public class SearchTestSuite
{
/**
* Creates the test suite
*
* @return the test suite
*/
public static Test suite()
{
TestSuite suite = new TestSuite();
suite.addTestSuite(MLAnaysisModeExpansionTest.class);
suite.addTestSuite(QueryRegisterComponentTest.class);
suite.addTestSuite(SearcherComponentTest.class);
suite.addTestSuite(SearchServiceTest.class);
suite.addTestSuite(DocumentNavigatorTest.class);
suite.addTestSuite(NumericEncodingTest.class);
suite.addTestSuite(CMIS_FTSTest.class);
suite.addTestSuite(CMISTest.class);
suite.addTestSuite(FTSTest.class);
return suite;
}
}

View File

@@ -0,0 +1,134 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.search.impl.solr;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import org.alfresco.repo.management.subsystems.SwitchableApplicationContextFactory;
import org.alfresco.util.BaseSpringTest;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.context.ApplicationContext;
public class SolrChildApplicationContextFactoryTest extends BaseSpringTest
{
/**
* Sample partial response from http://127.0.0.1:8983/solr/admin/cores?action=SUMMARY&wt=json
*/
private static JSONObject json = new JSONObject(
"{\n"
+ " \"responseHeader\":{\n"
+ " \"status\":0,\n"
+ " \"QTime\":1221\n"
+ " },\n"
+ " \"Summary\":{\n"
+ " \"alfresco\":{\n"
+ " \"Total Searcher Cache (GB)\":0,\n"
+ " \"On disk (GB)\":\"0.006584\",\n"
+ " \"Active\":false,\n"
+ " \"TX Lag\":\"0 s\",\n"
+ " \"TX Duration\":\"P0Y\",\n"
+ " \"Approx transactions remaining\":0,\n"
+ " \"Approx transaction indexing time remaining\":\"0 Seconds\",\n"
+ " \"Id for last TX in index\":16\n"
+ " },\n"
+ " \"archive\":{\n"
+ " \"Total Searcher Cache (GB)\":1,\n"
+ " \"On disk (GB)\":\"0.001554\",\n"
+ " \"Active\":true,\n"
+ " \"TX Lag\":\"1 s\",\n"
+ " \"TX Duration\":\"P1Y\",\n"
+ " \"Approx transactions remaining\":1,\n"
+ " \"Approx transaction indexing time remaining\":\"30 Seconds\",\n"
+ " \"Id for last TX in index\":15\n"
+ " }\n"
+ " }\n"
+ "}");
private SolrChildApplicationContextFactory solrChildApplicationContextFactory;
@Mock
private SolrAdminHTTPClient adminClient;
@Before
public void before()
{
SwitchableApplicationContextFactory subsystemManager = ((SwitchableApplicationContextFactory) applicationContext
.getBean("Search"));
ApplicationContext solrContext = subsystemManager.getApplicationContext();
solrChildApplicationContextFactory = (SolrChildApplicationContextFactory) solrContext.getBean("solr6");
adminClient = Mockito.mock(SolrAdminHTTPClient.class);
when(adminClient.execute(any())).thenReturn(json);
solrChildApplicationContextFactory.setAdminClient(adminClient);
}
@Test
public void test()
{
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ALFRESCO_ACTIVE), "false");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ALFRESCO_LAG), "0 s");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ALFRESCO_LAG_DURATION), "P0Y");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ALFRESCO_LAST_INDEXED_TXN), "16");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ALFRESCO_APPROX_TXNS_REMAINING), "0");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ALFRESCO_APPROX_INDEXING_TIME_REMAINING), "0 Seconds");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ALFRESCO_DISK), "0.006584");
assertEquals(solrChildApplicationContextFactory.getProperty(SolrChildApplicationContextFactory.ALFRESCO_MEMORY), "0");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ARCHIVE_ACTIVE), "true");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ARCHIVE_LAG), "1 s");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ARCHIVE_LAG_DURATION), "P1Y");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ARCHIVE_LAST_INDEXED_TXN), "15");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ARCHIVE_APPROX_TXNS_REMAINING), "1");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ARCHIVE_APPROX_INDEXING_TIME_REMAINING), "30 Seconds");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ARCHIVE_DISK), "0.001554");
assertEquals(solrChildApplicationContextFactory.getProperty(
SolrChildApplicationContextFactory.ARCHIVE_MEMORY), "1");
}
}