diff --git a/config/alfresco/subsystems/Search/solr/solr-search-context.xml b/config/alfresco/subsystems/Search/solr/solr-search-context.xml index ff06d1cbe3..400d816552 100644 --- a/config/alfresco/subsystems/Search/solr/solr-search-context.xml +++ b/config/alfresco/subsystems/Search/solr/solr-search-context.xml @@ -81,7 +81,7 @@ solrHttpClientFactory - /solr/alfresco + ${solr.baseUrl}/alfresco workspace @@ -98,7 +98,7 @@ solrHttpClientFactory - /solr/archive + ${solr.baseUrl}/archive archive @@ -133,14 +133,16 @@ - - - + + + + + diff --git a/config/alfresco/subsystems/Search/solr/solr-search.properties b/config/alfresco/subsystems/Search/solr/solr-search.properties index faa1b110e1..9c0fbae172 100644 --- a/config/alfresco/subsystems/Search/solr/solr-search.properties +++ b/config/alfresco/subsystems/Search/solr/solr-search.properties @@ -2,4 +2,5 @@ solr.host=localhost solr.port=8080 solr.port.ssl=8443 solr.query.includeGroupsForRoleAdmin=false -solr.query.maximumResultsFromUnlimitedQuery=${system.acl.maxPermissionChecks} \ No newline at end of file +solr.query.maximumResultsFromUnlimitedQuery=${system.acl.maxPermissionChecks} +solr.baseUrl=/solr diff --git a/config/alfresco/subsystems/Search/solr4/solr-backup-context.xml b/config/alfresco/subsystems/Search/solr4/solr-backup-context.xml index 879ab8b32d..ab77a3488d 100644 --- a/config/alfresco/subsystems/Search/solr4/solr-backup-context.xml +++ b/config/alfresco/subsystems/Search/solr4/solr-backup-context.xml @@ -49,6 +49,9 @@ + + true + diff --git a/config/alfresco/subsystems/Search/solr4/solr-backup.properties b/config/alfresco/subsystems/Search/solr4/solr-backup.properties index ca7660f150..41fd1397a4 100644 --- a/config/alfresco/subsystems/Search/solr4/solr-backup.properties +++ b/config/alfresco/subsystems/Search/solr4/solr-backup.properties @@ -1,7 +1,7 @@ solr.backup.alfresco.cronExpression=0 0 2 * * ? solr.backup.archive.cronExpression=0 0 4 * * ? -solr.backup.alfresco.remoteBackupLocation=${dir.root}/solrBackup/alfresco -solr.backup.archive.remoteBackupLocation=${dir.root}/solrBackup/archive +solr.backup.alfresco.remoteBackupLocation=${dir.root}/solr4Backup/alfresco +solr.backup.archive.remoteBackupLocation=${dir.root}/solr4Backup/archive solr.backup.alfresco.numberToKeep=3 solr.backup.archive.numberToKeep=3 diff --git a/config/alfresco/subsystems/Search/solr4/solr-search-context.xml b/config/alfresco/subsystems/Search/solr4/solr-search-context.xml index 8c1be741d7..b90325f37f 100644 --- a/config/alfresco/subsystems/Search/solr4/solr-search-context.xml +++ b/config/alfresco/subsystems/Search/solr4/solr-search-context.xml @@ -81,7 +81,7 @@ solrHttpClientFactory - /solr4/alfresco + ${solr.baseUrl}/alfresco workspace @@ -98,7 +98,7 @@ solrHttpClientFactory - /solr4/archive + ${solr.baseUrl}/archive archive @@ -133,14 +133,16 @@ - - - + + + + + diff --git a/config/alfresco/subsystems/Search/solr4/solr-search.properties b/config/alfresco/subsystems/Search/solr4/solr-search.properties index 635357bd12..8526fabf6d 100644 --- a/config/alfresco/subsystems/Search/solr4/solr-search.properties +++ b/config/alfresco/subsystems/Search/solr4/solr-search.properties @@ -2,4 +2,5 @@ solr.host=localhost solr.port=8083 solr.port.ssl=8446 solr.query.includeGroupsForRoleAdmin=false -solr.query.maximumResultsFromUnlimitedQuery=${system.acl.maxPermissionChecks} \ No newline at end of file +solr.query.maximumResultsFromUnlimitedQuery=${system.acl.maxPermissionChecks} +solr.baseUrl=/solr4 diff --git a/source/java/org/alfresco/repo/search/impl/solr/SolrAdminHTTPClient.java b/source/java/org/alfresco/repo/search/impl/solr/SolrAdminHTTPClient.java index 336507973f..30e6557ff1 100644 --- a/source/java/org/alfresco/repo/search/impl/solr/SolrAdminHTTPClient.java +++ b/source/java/org/alfresco/repo/search/impl/solr/SolrAdminHTTPClient.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -42,6 +42,7 @@ import org.alfresco.service.cmr.search.SearchParameters.FieldFacetMethod; import org.alfresco.service.cmr.search.SearchParameters.FieldFacetSort; import org.alfresco.service.cmr.search.SearchParameters.SortDefinition; import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.util.ParameterCheck; import org.apache.commons.codec.net.URLCodec; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; @@ -51,6 +52,7 @@ import org.apache.commons.httpclient.URI; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; +import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.logging.Log; @@ -68,6 +70,8 @@ public class SolrAdminHTTPClient { static Log s_logger = LogFactory.getLog(SolrAdminHTTPClient.class); + private String adminUrl; + private String baseUrl; private HttpClient httpClient; @@ -77,11 +81,19 @@ public class SolrAdminHTTPClient { } + + public void setBaseUrl(String baseUrl) + { + this.baseUrl = baseUrl; + } + public void init() { + ParameterCheck.mandatory("baseUrl", baseUrl); + StringBuilder sb = new StringBuilder(); - sb.append("/solr/admin/cores"); - this.baseUrl = sb.toString(); + sb.append(baseUrl + "/admin/cores"); + this.adminUrl = sb.toString(); httpClient = httpClientFactory.getHttpClient(); HttpClientParams params = httpClient.getParams(); @@ -106,7 +118,7 @@ public class SolrAdminHTTPClient String value = args.get(key); if(url.length() == 0) { - url.append(baseUrl); + url.append(adminUrl); url.append("?"); url.append(encoder.encode(key, "UTF-8")); url.append("="); @@ -122,36 +134,37 @@ public class SolrAdminHTTPClient } - PostMethod post = new PostMethod(url.toString()); + //PostMethod post = new PostMethod(url.toString()); + GetMethod get = new GetMethod(url.toString()); try { - httpClient.executeMethod(post); + httpClient.executeMethod(get); - if(post.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY || post.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) + if(get.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY || get.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { - Header locationHeader = post.getResponseHeader("location"); + Header locationHeader = get.getResponseHeader("location"); if (locationHeader != null) { String redirectLocation = locationHeader.getValue(); - post.setURI(new URI(redirectLocation, true)); - httpClient.executeMethod(post); + get.setURI(new URI(redirectLocation, true)); + httpClient.executeMethod(get); } } - if (post.getStatusCode() != HttpServletResponse.SC_OK) + if (get.getStatusCode() != HttpServletResponse.SC_OK) { - throw new LuceneQueryParserException("Request failed " + post.getStatusCode() + " " + url.toString()); + throw new LuceneQueryParserException("Request failed " + get.getStatusCode() + " " + url.toString()); } - Reader reader = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream())); + Reader reader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream())); // TODO - replace with streaming-based solution e.g. SimpleJSON ContentHandler JSONObject json = new JSONObject(new JSONTokener(reader)); return json; } finally { - post.releaseConnection(); + get.releaseConnection(); } } catch (UnsupportedEncodingException e) diff --git a/source/java/org/alfresco/repo/search/impl/solr/SolrBackupClient.java b/source/java/org/alfresco/repo/search/impl/solr/SolrBackupClient.java index 689914228f..f984566dbb 100644 --- a/source/java/org/alfresco/repo/search/impl/solr/SolrBackupClient.java +++ b/source/java/org/alfresco/repo/search/impl/solr/SolrBackupClient.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -51,10 +51,22 @@ public class SolrBackupClient implements InitializingBean private int numberToKeep; private String core; + + private boolean fixNumberToKeepOffByOneError = false; private SOLRAdminClient solrAdminClient; + + + /** + * @param fixNumberToKeepOffByOneError the fixNumberToKeepOffByOneError to set + */ + public void setFixNumberToKeepOffByOneError(boolean fixNumberToKeepOffByOneError) + { + this.fixNumberToKeepOffByOneError = fixNumberToKeepOffByOneError; + } + public void setSolrAdminClient(SOLRAdminClient solrAdminClient) { this.solrAdminClient = solrAdminClient; @@ -142,7 +154,14 @@ public class SolrBackupClient implements InitializingBean params.set("qt", "/"+core+"/replication"); params.set("command", "backup"); params.set("location", remoteBackupLocation); - params.set("numberToKeep", numberToKeep); + if(fixNumberToKeepOffByOneError) + { + params.set("numberToKeep", numberToKeep > 1 ? (numberToKeep + 1) : numberToKeep); + } + else + { + params.set("numberToKeep", numberToKeep); + } try { diff --git a/source/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java b/source/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java index 1df8edab2f..53b7b9f2d6 100644 --- a/source/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java +++ b/source/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -114,26 +114,26 @@ public class SolrChildApplicationContextFactory extends ChildApplicationContextF Date now = new Date(); - JSONObject alfresco = summary.getJSONObject("alfresco"); - String alfrescoLag = alfresco.getString("TX Lag"); - String alfrescoActive = alfresco.getString("Active"); - String alfrescoDuration = alfresco.getString("TX Duration"); - String alfrescoLastIndexedTxn = alfresco.getString("Id for last TX in index"); - String alfrescoApproxTxnsReminaing = alfresco.getString("Approx transactions remaining"); - String alfrescoApproxIndexingTimeReminaing = alfresco.getString("Approx transaction indexing time remaining"); - String alfrescoDisk = alfresco.getString("On disk (GB)"); - String alfrescoMemory = alfresco.getString("Total Searcher Cache (GB)"); + JSONObject alfresco = summary.has("alfresco") ? summary.getJSONObject("alfresco") : null; + String alfrescoLag = alfresco == null ? "Unavailable" : alfresco.getString("TX Lag"); + String alfrescoActive = alfresco == null ? "false" : alfresco.getString("Active"); + String alfrescoDuration = alfresco == null ? "Unavailable" : alfresco.getString("TX Duration"); + String alfrescoLastIndexedTxn = alfresco == null ? "Unavailable" : alfresco.getString("Id for last TX in index"); + String alfrescoApproxTxnsReminaing = alfresco == null ? "Unavailable" : alfresco.getString("Approx transactions remaining"); + String alfrescoApproxIndexingTimeReminaing = alfresco == null ? "Unavailable" : alfresco.getString("Approx transaction indexing time remaining"); + String alfrescoDisk = alfresco == null ? "Unavailable" : alfresco.getString("On disk (GB)"); + String alfrescoMemory = alfresco == null ? "Unavailable" : alfresco.getString("Total Searcher Cache (GB)"); - JSONObject archive = summary.getJSONObject("archive"); - String archiveLag = archive.getString("TX Lag"); - String archiveActive = archive.getString("Active"); - String archiveDuration = archive.getString("TX Duration"); - String archiveLastIndexedTxn = archive.getString("Id for last TX in index"); - String archiveApproxTxnsReminaing = archive.getString("Approx transactions remaining"); - String archiveApproxIndexingTimeReminaing = archive.getString("Approx transaction indexing time remaining"); - String archiveDisk = archive.getString("On disk (GB)"); - String archiveMemory = archive.getString("Total Searcher Cache (GB)"); + JSONObject archive = summary.has("archive") ? summary.getJSONObject("archive") : null; + String archiveLag = archive == null ? "Unavailable" : archive.getString("TX Lag"); + String archiveActive = archive == null ? "false" : archive.getString("Active"); + String archiveDuration = archive == null ? "Unavailable" : archive.getString("TX Duration"); + String archiveLastIndexedTxn = archive == null ? "Unavailable" : archive.getString("Id for last TX in index"); + String archiveApproxTxnsReminaing = archive == null ? "Unavailable" : archive.getString("Approx transactions remaining"); + String archiveApproxIndexingTimeReminaing = archive == null ? "Unavailable" : archive.getString("Approx transaction indexing time remaining"); + String archiveDisk = archive == null ? "Unavailable" : archive.getString("On disk (GB)"); + String archiveMemory = archive == null ? "Unavailable" : archive.getString("Total Searcher Cache (GB)"); if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_ACTIVE)) { diff --git a/source/java/org/alfresco/repo/solr/SOLRAdminClient.java b/source/java/org/alfresco/repo/solr/SOLRAdminClient.java index 9b32d25644..cebb2d2beb 100644 --- a/source/java/org/alfresco/repo/solr/SOLRAdminClient.java +++ b/source/java/org/alfresco/repo/solr/SOLRAdminClient.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2011 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -65,6 +65,7 @@ public class SOLRAdminClient implements ApplicationEventPublisherAware, Disposab private String solrUser; private String solrPassword; private String solrPingCronExpression; + private String baseUrl; private CommonsHttpSolrServer server; private int solrConnectTimeout = 30000; // ms @@ -123,8 +124,13 @@ public class SOLRAdminClient implements ApplicationEventPublisherAware, Disposab { this.httpClientFactory = httpClientFactory; } - - /** + + public void setBaseUrl(String baseUrl) + { + this.baseUrl = baseUrl; + } + + /** * @param scheduler the scheduler to set */ public void setScheduler(Scheduler scheduler) @@ -148,7 +154,7 @@ public class SOLRAdminClient implements ApplicationEventPublisherAware, Disposab sb.append(solrHost); sb.append(":"); sb.append(httpClientFactory.isSSL() ? solrSSLPort: solrPort); - sb.append("/solr"); + sb.append(baseUrl); this.solrUrl = sb.toString(); HttpClient httpClient = httpClientFactory.getHttpClient();