mirror of https://github.com/apache/lucene.git
SOLR-5023: Add support for deleteInstanceDir to be passed from SolrJ for Core Unload action
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1546793 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7b7339d733
commit
1460d8c9d5
|
@ -109,6 +109,9 @@ New Features
|
|||
* SOLR-5506: Support docValues in CollationField and ICUCollationField.
|
||||
(Robert Muir)
|
||||
|
||||
* SOLR-5023: Add support for deleteInstanceDir to be passed from SolrJ for Core
|
||||
Unload action. (shalin)
|
||||
|
||||
Bug Fixes
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -18,9 +18,14 @@
|
|||
package org.apache.solr.handler.admin;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
||||
import org.apache.commons.codec.Charsets;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
|
||||
import org.apache.solr.client.solrj.impl.HttpSolrServer;
|
||||
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
import org.apache.solr.common.params.CoreAdminParams;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
|
@ -221,4 +226,52 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
|
|||
FileUtils.deleteDirectory(workDir);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteInstanceDir() throws Exception {
|
||||
File solrHomeDirectory = new File(TEMP_DIR, getClass().getName() + "-corex-"
|
||||
+ System.currentTimeMillis());
|
||||
solrHomeDirectory.mkdirs();
|
||||
copySolrHomeToTemp(solrHomeDirectory, "corex", true);
|
||||
File corex = new File(solrHomeDirectory, "corex");
|
||||
FileUtils.write(new File(corex, "core.properties"), "", Charsets.UTF_8.toString());
|
||||
JettySolrRunner runner = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), "/solr", 0);
|
||||
HttpSolrServer server = null;
|
||||
try {
|
||||
runner.start();
|
||||
server = new HttpSolrServer("http://localhost:" + runner.getLocalPort() + "/solr/corex");
|
||||
server.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
|
||||
server.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
|
||||
SolrInputDocument doc = new SolrInputDocument();
|
||||
doc.addField("id", "123");
|
||||
server.add(doc);
|
||||
server.commit();
|
||||
server.shutdown();
|
||||
|
||||
server = new HttpSolrServer("http://localhost:" + runner.getLocalPort() + "/solr");
|
||||
server.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
|
||||
server.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
|
||||
CoreAdminRequest.Unload req = new CoreAdminRequest.Unload(false);
|
||||
req.setDeleteInstanceDir(true);
|
||||
req.setCoreName("corex");
|
||||
req.process(server);
|
||||
server.shutdown();
|
||||
|
||||
runner.stop();
|
||||
|
||||
assertFalse("Instance directory exists after core unload with deleteInstanceDir=true : " + corex,
|
||||
corex.exists());
|
||||
} catch (Exception e) {
|
||||
log.error("Exception testing core unload with deleteInstanceDir=true", e);
|
||||
} finally {
|
||||
if (server != null) {
|
||||
server.shutdown();
|
||||
}
|
||||
if (!runner.isStopped()) {
|
||||
runner.stop();
|
||||
}
|
||||
recurseDelete(solrHomeDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -371,7 +371,8 @@ public class CoreAdminRequest extends SolrRequest
|
|||
|
||||
public static class Unload extends CoreAdminRequest {
|
||||
protected boolean deleteIndex;
|
||||
private boolean deleteDataDir;
|
||||
protected boolean deleteDataDir;
|
||||
protected boolean deleteInstanceDir;
|
||||
|
||||
public Unload(boolean deleteIndex) {
|
||||
action = CoreAdminAction.UNLOAD;
|
||||
|
@ -390,11 +391,24 @@ public class CoreAdminRequest extends SolrRequest
|
|||
this.deleteDataDir = deleteDataDir;
|
||||
}
|
||||
|
||||
public void setDeleteInstanceDir(boolean deleteInstanceDir){
|
||||
this.deleteInstanceDir = deleteInstanceDir;
|
||||
}
|
||||
|
||||
public boolean isDeleteDataDir() {
|
||||
return deleteDataDir;
|
||||
}
|
||||
|
||||
public boolean isDeleteInstanceDir() {
|
||||
return deleteInstanceDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrParams getParams() {
|
||||
ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
|
||||
params.set(CoreAdminParams.DELETE_INDEX, deleteIndex);
|
||||
params.set(CoreAdminParams.DELETE_DATA_DIR, deleteDataDir);
|
||||
params.set(CoreAdminParams.DELETE_INSTANCE_DIR, deleteInstanceDir);
|
||||
return params;
|
||||
}
|
||||
|
||||
|
@ -489,11 +503,15 @@ public class CoreAdminRequest extends SolrRequest
|
|||
return unloadCore(name, false, server);
|
||||
}
|
||||
|
||||
public static CoreAdminResponse unloadCore( String name, boolean deleteIndex, SolrServer server ) throws SolrServerException, IOException
|
||||
{
|
||||
public static CoreAdminResponse unloadCore(String name, boolean deleteIndex, SolrServer server) throws SolrServerException, IOException {
|
||||
return unloadCore(name, deleteIndex, false, server);
|
||||
}
|
||||
|
||||
public static CoreAdminResponse unloadCore(String name, boolean deleteIndex, boolean deleteInstanceDir, SolrServer server) throws SolrServerException, IOException {
|
||||
Unload req = new Unload(deleteIndex);
|
||||
req.setCoreName( name );
|
||||
return req.process( server );
|
||||
req.setCoreName(name);
|
||||
req.setDeleteInstanceDir(deleteInstanceDir);
|
||||
return req.process(server);
|
||||
}
|
||||
|
||||
public static CoreAdminResponse renameCore(String coreName, String newName, SolrServer server ) throws SolrServerException, IOException
|
||||
|
|
Loading…
Reference in New Issue