diff --git a/htroot/IndexExport_p.html b/htroot/IndexExport_p.html index cdbe3423f..96e32b584 100644 --- a/htroot/IndexExport_p.html +++ b/htroot/IndexExport_p.html @@ -68,17 +68,18 @@ #(dumprestore)#::
Dump and Restore of Solr Index + #(dumpRestoreEnabled)#
This feature is available only when a local embedded Solr is active.
::#(/dumpRestoreEnabled)#
 
-
+
Dump File
-
+
 
-
+
@@ -86,9 +87,17 @@ #(/dumprestore)# #(indexdump)#:: -
Stored a solr dump to file #[dumpfile]#
:: + :: + :: + #(/indexdump)# + #(indexRestore)#:: + :: + :: + + #(/indexRestore)# + #%env/templates/footer.template%# diff --git a/htroot/IndexExport_p.java b/htroot/IndexExport_p.java index 15e3f0c0c..d7142f17c 100644 --- a/htroot/IndexExport_p.java +++ b/htroot/IndexExport_p.java @@ -25,9 +25,13 @@ import java.io.File; import java.io.IOException; import java.util.List; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.SolrException.ErrorCode; + import net.yacy.cora.protocol.RequestHeader; import net.yacy.data.WorkTables; import net.yacy.search.Switchboard; +import net.yacy.search.SwitchboardConstants; import net.yacy.search.index.Fulltext; import net.yacy.search.index.Segment; import net.yacy.server.serverObjects; @@ -48,9 +52,12 @@ public class IndexExport_p { prop.put("otherHosts", ""); prop.put("reload", 0); prop.put("indexdump", 0); + prop.put("indexRestore", 0); prop.put("lurlexport", 0); prop.put("reload", 0); prop.put("dumprestore", 1); + prop.put("dumprestore_dumpRestoreEnabled", sb.getConfigBool(SwitchboardConstants.CORE_SERVICE_FULLTEXT, + SwitchboardConstants.CORE_SERVICE_FULLTEXT_DEFAULT)); List dumpFiles = segment.fulltext().dumpFiles(); prop.put("dumprestore_dumpfile", dumpFiles.size() == 0 ? "" : dumpFiles.get(dumpFiles.size() - 1).getAbsolutePath()); prop.put("dumprestore_optimizemax", 10); @@ -132,17 +139,34 @@ public class IndexExport_p { } if (post.containsKey("indexdump")) { - final File dump = segment.fulltext().dumpSolr(); - prop.put("indexdump", 1); - prop.put("indexdump_dumpfile", dump.getAbsolutePath()); - dumpFiles = segment.fulltext().dumpFiles(); - prop.put("dumprestore_dumpfile", dumpFiles.size() == 0 ? "" : dumpFiles.get(dumpFiles.size() - 1).getAbsolutePath()); - //sb.tables.recordAPICall(post, "IndexExport_p.html", WorkTables.TABLE_API_TYPE_STEERING, "solr dump generation"); + try { + final File dump = segment.fulltext().dumpEmbeddedSolr(); + prop.put("indexdump", 1); + prop.put("indexdump_dumpfile", dump.getAbsolutePath()); + dumpFiles = segment.fulltext().dumpFiles(); + prop.put("dumprestore_dumpfile", dumpFiles.size() == 0 ? "" : dumpFiles.get(dumpFiles.size() - 1).getAbsolutePath()); + // sb.tables.recordAPICall(post, "IndexExport_p.html", WorkTables.TABLE_API_TYPE_STEERING, "solr dump generation"); + } catch(final SolrException e) { + if(ErrorCode.SERVICE_UNAVAILABLE.code == e.code()) { + prop.put("indexdump", 2); + } else { + prop.put("indexdump", 3); + } + } } if (post.containsKey("indexrestore")) { - final File dump = new File(post.get("dumpfile", "")); - segment.fulltext().restoreSolr(dump); + try { + final File dump = new File(post.get("dumpfile", "")); + segment.fulltext().restoreEmbeddedSolr(dump); + prop.put("indexRestore", 1); + } catch(final SolrException e) { + if(ErrorCode.SERVICE_UNAVAILABLE.code == e.code()) { + prop.put("indexRestore", 2); + } else { + prop.put("indexRestore", 3); + } + } } // insert constants diff --git a/source/net/yacy/search/index/Fulltext.java b/source/net/yacy/search/index/Fulltext.java index e5ecf78a4..6620831d1 100644 --- a/source/net/yacy/search/index/Fulltext.java +++ b/source/net/yacy/search/index/Fulltext.java @@ -82,6 +82,7 @@ import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.core.SolrInfoMBean; import org.apache.lucene.util.Version; @@ -581,13 +582,17 @@ public final class Fulltext { } /** - * create a dump file from the current solr directory + * Create a dump file from the current embedded solr directory * @return file reference to the dump + * @throws SolrException when no embedded Solr is available */ - public File dumpSolr() { - EmbeddedInstance esc = this.solrInstances.getEmbedded(); - File storagePath = esc.getContainerPath(); - File zipOut = new File(this.archivePath, storagePath.getName() + "_" + GenericFormatter.SHORT_DAY_FORMATTER.format() + ".zip"); + public File dumpEmbeddedSolr() throws SolrException { + final EmbeddedInstance esc = this.solrInstances.getEmbedded(); + if(esc == null) { + throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "No embedded Solr available."); + } + final File storagePath = esc.getContainerPath(); + final File zipOut = new File(this.archivePath, storagePath.getName() + "_" + GenericFormatter.SHORT_DAY_FORMATTER.format() + ".zip"); synchronized (this.solrInstances) { this.disconnectLocalSolr(); try { @@ -606,12 +611,16 @@ public final class Fulltext { } /** - * restore a solr dump to the current solr directory - * @param solrDumpZipFile + * Restore a solr dump to the current embedded solr directory + * @param solrDumpZipFile the dump file to use + * @throws SolrException when no embedded Solr is available */ - public void restoreSolr(File solrDumpZipFile) { - EmbeddedInstance esc = this.solrInstances.getEmbedded(); - File storagePath = esc.getContainerPath(); + public void restoreEmbeddedSolr(final File solrDumpZipFile) { + final EmbeddedInstance esc = this.solrInstances.getEmbedded(); + if(esc == null) { + throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "No embedded Solr available."); + } + final File storagePath = esc.getContainerPath(); synchronized (this.solrInstances) { // this.disconnectLocalSolr(); // moved to (InstanceMirror) sorlInstances.close() this.solrInstances.close();