mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 18:17:43 +00:00
Keeping track of new Solr cores and creating names for them
This commit is contained in:
parent
79d00eedb3
commit
056bf25a2d
@ -26,12 +26,14 @@ class Index {
|
|||||||
private final String indexPath;
|
private final String indexPath;
|
||||||
private final String schemaVersion;
|
private final String schemaVersion;
|
||||||
private final String solrVersion;
|
private final String solrVersion;
|
||||||
|
private boolean newIndex;
|
||||||
|
|
||||||
Index(String indexPath, String solrVersion, String schemaVersion) {
|
Index(String indexPath, String solrVersion, String schemaVersion) {
|
||||||
this.indexPath = indexPath;
|
this.indexPath = indexPath;
|
||||||
this.solrVersion = solrVersion;
|
this.solrVersion = solrVersion;
|
||||||
this.schemaVersion = schemaVersion;
|
this.schemaVersion = schemaVersion;
|
||||||
}
|
newIndex = false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the indexPath
|
* @return the indexPath
|
||||||
@ -63,4 +65,18 @@ class Index {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the newIndex
|
||||||
|
*/
|
||||||
|
boolean isNewIndex() {
|
||||||
|
return newIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param newIndex the newIndex to set
|
||||||
|
*/
|
||||||
|
void setNewIndex(boolean newIndex) {
|
||||||
|
this.newIndex = newIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,11 @@ import java.nio.charset.Charset;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -724,7 +726,7 @@ public class Server {
|
|||||||
* creating/opening the core.
|
* creating/opening the core.
|
||||||
*/
|
*/
|
||||||
private Core openCore(Case theCase, Index index) throws KeywordSearchModuleException {
|
private Core openCore(Case theCase, Index index) throws KeywordSearchModuleException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (theCase.getCaseType() == CaseType.SINGLE_USER_CASE) {
|
if (theCase.getCaseType() == CaseType.SINGLE_USER_CASE) {
|
||||||
currentSolrServer = this.localSolrServer;
|
currentSolrServer = this.localSolrServer;
|
||||||
@ -739,8 +741,75 @@ public class Server {
|
|||||||
throw new KeywordSearchModuleException(NbBundle.getMessage(Server.class, "Server.connect.exception.msg"), ex);
|
throw new KeywordSearchModuleException(NbBundle.getMessage(Server.class, "Server.connect.exception.msg"), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
String coreName = theCase.getTextIndexName();
|
try {
|
||||||
return this.openCore(coreName.isEmpty() ? DEFAULT_CORE_NAME : coreName, index, theCase.getCaseType());
|
CaseType caseType = theCase.getCaseType();
|
||||||
|
String coreName;
|
||||||
|
if (index.isNewIndex()) {
|
||||||
|
// come up with a new core name
|
||||||
|
coreName = createCoreName(theCase.getName());
|
||||||
|
} else {
|
||||||
|
// ELTODO get core name
|
||||||
|
coreName = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
File dataDir = new File(new File(index.getIndexPath()).getParent()); // "data dir" is the parent of the index directory
|
||||||
|
if (!dataDir.exists()) {
|
||||||
|
dataDir.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.isRunning()) {
|
||||||
|
logger.log(Level.SEVERE, "Core create/open requested, but server not yet running"); //NON-NLS
|
||||||
|
throw new KeywordSearchModuleException(NbBundle.getMessage(this.getClass(), "Server.openCore.exception.msg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!coreIsLoaded(coreName)) {
|
||||||
|
/*
|
||||||
|
* The core either does not exist or it is not loaded. Make a
|
||||||
|
* request that will cause the core to be created if it does not
|
||||||
|
* exist or loaded if it already exists.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// In single user mode, if there is a core.properties file already,
|
||||||
|
// we've hit a solr bug. Compensate by deleting it.
|
||||||
|
if (caseType == CaseType.SINGLE_USER_CASE) {
|
||||||
|
Path corePropertiesFile = Paths.get(solrFolder.toString(), SOLR, coreName, CORE_PROPERTIES);
|
||||||
|
if (corePropertiesFile.toFile().exists()) {
|
||||||
|
try {
|
||||||
|
corePropertiesFile.toFile().delete();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.log(Level.INFO, "Could not delete pre-existing core.properties prior to opening the core."); //NON-NLS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CoreAdminRequest.Create createCoreRequest = new CoreAdminRequest.Create();
|
||||||
|
createCoreRequest.setDataDir(dataDir.getAbsolutePath());
|
||||||
|
createCoreRequest.setCoreName(coreName);
|
||||||
|
createCoreRequest.setConfigSet("AutopsyConfig"); //NON-NLS
|
||||||
|
createCoreRequest.setIsLoadOnStartup(false);
|
||||||
|
createCoreRequest.setIsTransient(true);
|
||||||
|
currentSolrServer.request(createCoreRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!coreIndexFolderExists(coreName)) {
|
||||||
|
throw new KeywordSearchModuleException(NbBundle.getMessage(this.getClass(), "Server.openCore.exception.noIndexDir.msg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Core(coreName, caseType, index);
|
||||||
|
|
||||||
|
} catch (SolrServerException | SolrException | IOException ex) {
|
||||||
|
throw new KeywordSearchModuleException(NbBundle.getMessage(this.getClass(), "Server.openCore.exception.cantOpen.msg"), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createCoreName(String caseName) {
|
||||||
|
if (caseName.isEmpty()) {
|
||||||
|
caseName = DEFAULT_CORE_NAME;
|
||||||
|
}
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
||||||
|
Date date = new Date();
|
||||||
|
String coreName = caseName + "_" + dateFormat.format(date);
|
||||||
|
return coreName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1083,73 +1152,6 @@ public class Server {
|
|||||||
return Long.toString(parentID) + Server.CHUNK_ID_SEPARATOR + Integer.toString(childID);
|
return Long.toString(parentID) + Server.CHUNK_ID_SEPARATOR + Integer.toString(childID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates/opens a Solr core (index) for a case.
|
|
||||||
*
|
|
||||||
* @param coreName The core name.
|
|
||||||
* @param index The text index object for the core.
|
|
||||||
* @param caseType The type of the case (single-user or multi-user) for
|
|
||||||
* which the core is being created/opened.
|
|
||||||
*
|
|
||||||
* @return An object representing the created/opened core.
|
|
||||||
*
|
|
||||||
* @throws KeywordSearchModuleException If an error occurs while
|
|
||||||
* creating/opening the core.
|
|
||||||
*/
|
|
||||||
private Core openCore(String coreName, Index index, CaseType caseType) throws KeywordSearchModuleException {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
File dataDir = new File(new File(index.getIndexPath()).getParent()); // "data dir" is the parent of the index directory
|
|
||||||
if (!dataDir.exists()) {
|
|
||||||
dataDir.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.isRunning()) {
|
|
||||||
logger.log(Level.SEVERE, "Core create/open requested, but server not yet running"); //NON-NLS
|
|
||||||
throw new KeywordSearchModuleException(NbBundle.getMessage(this.getClass(), "Server.openCore.exception.msg"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!coreIsLoaded(coreName)) {
|
|
||||||
/*
|
|
||||||
* The core either does not exist or it is not loaded. Make a
|
|
||||||
* request that will cause the core to be created if it does not
|
|
||||||
* exist or loaded if it already exists.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// In single user mode, if there is a core.properties file already,
|
|
||||||
// we've hit a solr bug. Compensate by deleting it.
|
|
||||||
if (caseType == CaseType.SINGLE_USER_CASE) {
|
|
||||||
Path corePropertiesFile = Paths.get(solrFolder.toString(), SOLR, coreName, CORE_PROPERTIES);
|
|
||||||
if (corePropertiesFile.toFile().exists()) {
|
|
||||||
try {
|
|
||||||
corePropertiesFile.toFile().delete();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.log(Level.INFO, "Could not delete pre-existing core.properties prior to opening the core."); //NON-NLS
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CoreAdminRequest.Create createCoreRequest = new CoreAdminRequest.Create();
|
|
||||||
createCoreRequest.setDataDir(dataDir.getAbsolutePath());
|
|
||||||
createCoreRequest.setCoreName(coreName);
|
|
||||||
createCoreRequest.setConfigSet("AutopsyConfig"); //NON-NLS
|
|
||||||
createCoreRequest.setIsLoadOnStartup(false);
|
|
||||||
createCoreRequest.setIsTransient(true);
|
|
||||||
currentSolrServer.request(createCoreRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!coreIndexFolderExists(coreName)) {
|
|
||||||
throw new KeywordSearchModuleException(NbBundle.getMessage(this.getClass(), "Server.openCore.exception.noIndexDir.msg"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Core(coreName, caseType, index);
|
|
||||||
|
|
||||||
} catch (SolrServerException | SolrException | IOException ex) {
|
|
||||||
throw new KeywordSearchModuleException(NbBundle.getMessage(this.getClass(), "Server.openCore.exception.cantOpen.msg"), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to connect to the given Solr server.
|
* Attempts to connect to the given Solr server.
|
||||||
*
|
*
|
||||||
|
@ -165,6 +165,7 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService
|
|||||||
if (indexes.isEmpty()) {
|
if (indexes.isEmpty()) {
|
||||||
// new case that doesn't have an existing index. create new index folder
|
// new case that doesn't have an existing index. create new index folder
|
||||||
currentVersionIndex = IndexFinder.createLatestVersionIndexDir(context.getCase());
|
currentVersionIndex = IndexFinder.createLatestVersionIndexDir(context.getCase());
|
||||||
|
currentVersionIndex.setNewIndex(true);
|
||||||
} else {
|
} else {
|
||||||
// check if one of the existing indexes is for latest Solr version and schema
|
// check if one of the existing indexes is for latest Solr version and schema
|
||||||
currentVersionIndex = IndexFinder.findLatestVersionIndexDir(indexes);
|
currentVersionIndex = IndexFinder.findLatestVersionIndexDir(indexes);
|
||||||
@ -220,6 +221,7 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService
|
|||||||
|
|
||||||
// set the upgraded index as the index to be used for this case
|
// set the upgraded index as the index to be used for this case
|
||||||
currentVersionIndex = new Index(newIndexDir, IndexFinder.getCurrentSolrVersion(), indexToUpgrade.getSchemaVersion());
|
currentVersionIndex = new Index(newIndexDir, IndexFinder.getCurrentSolrVersion(), indexToUpgrade.getSchemaVersion());
|
||||||
|
currentVersionIndex.setNewIndex(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user