public ManagedIndexState getState(){ String state = getProperty(STATE); if(state == null){ log.warn("No ManagedIndexState (key: '"+STATE+"') present in the" + "IndexMetadata for '"+getIndexReference()+"'! -> return null"); return null; } else { try { return ManagedIndexState.valueOf(state); } catch (IllegalArgumentException e) { log.error("Unable to parse ManagedIndexState from value '"+ state+"'! -> return null",e); return null; } } } /**
/** * validates the values of the IndexProperties * @throws IOException */ private void validate(boolean store) throws IOException { if(isSynchronized() && getIndexArchives().isEmpty()){ throw new IOException("Unable to "+(store?"store":"read")+ " IndexPropertis where Synchronized=true and no Index-Archives are defined!"); } ManagedIndexState state = getState(); if(state == null){ throw new IOException("Unable to "+(store?"store":"read")+ " IndexMetadata without the required key '"+STATE+ "' set to one of the values '"+ Arrays.toString(ManagedIndexState.values())+"'!"); } if(isActive()){ if(getDirectory() == null){ throw new IOException("Unable to "+(store?"store":"read")+ " IndexPropertis where Active=true and no Directory is defined!"); } } String name = getIndexName(); if(name == null || name.isEmpty()){ throw new IOException("Unable to "+(store?"store":"read")+ " IndexPropertis where the required key '"+ INDEX_NAME+"' is not defined or empty!"); } }
public void addUninitialisedIndex(String indexName, String indexArchiveName, Boolean sync) throws IOException { IndexMetadata config = new IndexMetadata(); config = new IndexMetadata(); config.setIndexName(indexName); config.setServerName(serverName); config.setState(ManagedIndexState.UNINITIALISED); if(sync != null){ config.setSynchronized(sync); } //no need to clone, because we have created the instance updateIndexProperties(null, config, false); } public void store(IndexMetadata properties){
/** * Getter for the {@link IndexReference} based on the {@link #getServerName()} and * {@link #getIndexName()} values * @return the {@link IndexReference} to the index described by this metadata */ public IndexReference getIndexReference(){ return new IndexReference(getServerName(), getIndexName()); } /**
/** * @param indexName */ public void addTracking(IndexMetadata metadata) { if(metadata != null){ //may be removed in the meantime if(!(metadata.isActive() || metadata.isInactive()) || metadata.isSynchronized()){ String archive = metadata.getArchive(); boolean found = false; //only track higher priority files as the current for(String indexArchive : metadata.getIndexArchives()){ if(!found){ if(indexArchive.equals(archive)){ found = true; } tracker.add(this, indexArchive, IndexMetadata.toStringMap(metadata)); } // else higher priority archive present -> no tracking } } //else (active || inactive) and not syncronized -> no tracking } }; /**
@Override public IndexMetadata updateIndex(String indexName, String resourceName, Properties properties) throws IOException { //NOTE: this does not deactivate the current index version, but only updates //the metadata and re-registers the DataFileTracking IndexMetadata oldMetadata = managedCores.getIndexMetadata(indexName); IndexMetadata metadata = new IndexMetadata(); if(properties != null){ metadata.putAll(properties); } metadata.setServerName(serverName); metadata.setIndexName(indexName); metadata.setIndexArchives(Collections.singletonList(resourceName)); if(oldMetadata != null){ //we need to metadata.setState(oldMetadata.getState()); //same as for the old version metadata.setDirectory(oldMetadata.getDirectory()); } else { metadata.setState(ManagedIndexState.UNINITIALISED); } //TODO: we need to deal with the synchronised property! // now add the index to the list of uninitialised managedCores.store(metadata); indexArchiveTracker.updateTracking(oldMetadata,metadata); return metadata; } @Override
SolrServerAdapter server = this.server; File coreDir = null; if(metadata.isActive()){ coreDir = deactivateCore(metadata.getIndexName(), server); String coreDirName = metadata.getDirectory(); if(coreDirName != null){ coreDir = new File(coreDirName); metadata.setDirectory(null); //no directory assigned metadata.setArchive(null); //no archive used for the index if(coreDir != null){ try { "removed index '%s' of the managed SolrServer '{}'. " + "Please try to delete this directory manually!", coreDir.getAbsolutePath(),metadata.getIndexName(), serverName),e); metadata.setState(ManagedIndexState.UNINITIALISED);
return null; if(name != null && properties != null && !name.equals(properties.getIndexName())){ throw new IllegalArgumentException("The value of the Index-Name property '"+ properties.getIndexName()+"' is not the same as the parsed name '"+ name+"'!"); name = properties.getIndexName(); saveIndexConfig(name, properties); } catch (IOException e) { log.error("Unable to store Properties (see Exception below): {}",properties.toString()); throw new IllegalStateException("Unable to save Index metadata for index '"+ name+"'!",e); properties = new IndexMetadata(); properties.putAll(tmp); ManagedIndexState newState = properties.getState(); toAdd = managed.get(newState); for(String indexArchive : oldMetadata.getIndexArchives()){ Collection<String> indexes = archiveName2CoreName.get(indexArchive); if(indexes.remove(name) && indexes.isEmpty()){ for(String indexArchive : properties.getIndexArchives()){ Collection<String> indexes = archiveName2CoreName.get(indexArchive); if(indexes == null){
IndexMetadata metadata = managedCores.getIndexMetadata(indexName); if(metadata != null){ //the core might be deleted in the meantime List<String> archives = metadata.getIndexArchives(); String currentArchive = metadata.getArchive(); if(currentArchive == null || archives.indexOf(resourceName) < archives.indexOf(currentArchive)){ metadata.setArchive(resourceName); managedCores.store(metadata); indexUpdateDaemon.update(ManagedIndexState.ACTIVE,metadata, ais); keepTracking = keepTracking || metadata.isSynchronized(); } else { //currently used Archive is of higher priority as keepTracking = keepTracking || metadata.isSynchronized();
@Override public IndexMetadata createSolrIndex(String indexName, String resourceName, Properties properties) throws IOException { if(indexName == null || indexName.isEmpty()){ throw new IllegalArgumentException("The parsed index name MUST NOT be NULL nor empty!"); } if(!ConfigUtils.isValidSolrIndexFileName(resourceName)){ log.debug("add SolrIndexFileExtension to parsed indexArchive {}",resourceName); resourceName = ConfigUtils.appandSolrIndexFileExtension(resourceName, null); } if(isManagedIndex(indexName)){ throw new IllegalArgumentException("An index with the parsed name '"+ indexName+"' already exists on this managed Solr server '"+serverName+"'!"); } IndexMetadata metadata = new IndexMetadata(); if(properties != null){ metadata.putAll(properties); } metadata.setServerName(serverName); metadata.setIndexName(indexName); metadata.setIndexArchives(Collections.singletonList(resourceName)); metadata.setState(ManagedIndexState.UNINITIALISED); //TODO: we need to deal with the synchronised property! // now add the index to the list of uninitialised managedCores.store(metadata); //now start tracking this archive file indexArchiveTracker.addTracking(metadata); dataFileTracker.add(indexArchiveTracker, resourceName, IndexMetadata.toStringMap(metadata)); return metadata; }
+ managedServer.getServerName()+"!",e); } else if(metadata.getState() != ManagedIndexState.ACTIVE){ log.info(" ... activating Managed SolrIndex {} on Server {} (current state: {})", new Object[]{solrIndexRef.getIndex(),managedServer.getServerName(),metadata.getState()}); try { managedServer.activateIndex(metadata.getIndexName()); } catch (IOException e) { throw new IllegalStateException("Unable to activate Managed SolrIndex " solrIndexRef = metadata.getIndexReference();
log.info(" ... index {} successfully started!",indexName); } catch (IOException e) { metadata.setError(e); log.error("Unable to activate previously active SolrIndex '"+ metadata.getIndexReference()+"'!",e); } catch (SAXException e) { metadata.setError(e); log.error("Unable to activate previously active SolrIndex '"+ metadata.getIndexReference()+"'!",e); } catch (RuntimeException e) { metadata.setError(e); log.error("Unable to activate previously active SolrIndex '"+ metadata.getIndexReference()+"'!",e); for(String indexName : activeOnSolrServer){ IndexMetadata metadata = managedCores.getIndexMetadata(indexName); ManagedIndexState state = metadata != null ? metadata.getState() : null; log.info(" - {} has state {}",indexName, state != null ? state : "UNKNOWN"); if(metadata == null){ metadata.setState(ManagedIndexState.ACTIVE); managedCores.store(metadata); log.info(" ... successfully ACTIVATED SolrCore {} on managed Solr Server {}", metadata.setState(ManagedIndexState.ACTIVE); managedCores.store(metadata); log.info(" ... successfully ACTIVATED SolrCore {} on managed Solr Server {}",
throw new IllegalArgumentException("The parsed metadata for the Solr index MUST NOT be NULL"); if (metadata.isEmpty()) { throw new IllegalArgumentException("The parsed metadata for the Solr index MUST NOT be empty"); String coreName = metadata.getIndexName(); if(coreName == null || coreName.isEmpty()){ throw new IllegalArgumentException("The parse metadata do not contain a valid value for the '"+ count++; metadata.setDirectory(coreDir.getName()); //TODO maybe we need to call getAbsolute path metadata.setError(e); throw e; metadata.setState(ManagedIndexState.ACTIVE); if(currentCoreDir != null){ metadata.setError(e); throw e; } catch (SAXException e) { metadata.setError(e); throw e; } catch (RuntimeException e) { metadata.setError(e); throw e;
@Override public IndexMetadata activateIndex(String indexName) throws IOException, SAXException { IndexMetadata metadata = managedCores.getIndexMetadata(indexName); if(metadata != null && metadata.getState() == ManagedIndexState.INACTIVE){ try { activateCore(metadata, server); metadata.setState(ManagedIndexState.ACTIVE); } catch (IOException e) { metadata.setError(e); throw e; } catch (SAXException e) { metadata.setError(e); throw e; } catch (RuntimeException e) { metadata.setError(e); throw e; } finally { managedCores.store(metadata); } } return metadata; } @Override
String indexName = file.substring(0, file.indexOf('.')); File configFile = new File(uninstalledConfigDir, file); IndexMetadata props = new IndexMetadata(); InputStream is = null; try { is = new FileInputStream(configFile); props.load(is); if(!indexName.equals(props.getIndexName())){ throw new IOException("The IndexName '"+props.getIndexName()+ "within the IndexConfig file does not correspond to the file name '"+ file+"'!"); if(!serverName.equals(props.getServerName())){ throw new IOException("The Name of the Referenced Solr server '"+ serverName+" does not correspond with the Server-Name value '"+ props.getServerName()+"' within the property file '"+ file+"'!");
/** * Checks if this index is in the {@link ManagedIndexState#UNINITIALISED} state * @return if this index is still not initialised * @see #getState() */ public boolean isUninitialised(){ ManagedIndexState state = getState(); return state != null && state == ManagedIndexState.UNINITIALISED; }
throw new IllegalArgumentException("The parsed IndexMetadata MUST NOT be NULL"); String name = metadata.getIndexName(); if(name == null || name.isEmpty()){ throw new IllegalArgumentException("The parsed IndexMetadata MUST contain a valid name (NOT NULL and NOT empty)!"); new Object[]{metadata.getIndexName(), metadata.getServerName(), desiredState.name(), metadata.getArchive()}); switch (desiredState) { case ACTIVE:
if(isManagedIndex(entry.getKey())){ if(info.action == ManagedIndexState.ACTIVE){ log.info(" ... start to ACTIVATE Index {} on ManagedSolrServer",entry.getKey(),info.metadata.getServerName()); try { updateCore(info.metadata, info.ais); log.info(" ... Index {} on ManagedSolrServer {} is now ACTIVE",entry.getKey(),info.metadata.getServerName()); } catch (IOException e) { log.error("IOException while activating Index '"+ info.metadata.getServerName()+':'+ info.metadata.getIndexName()+"'!",e); info.metadata.setError(e); } catch (SAXException e) { log.error("SAXException while activating Index '"+ info.metadata.getServerName()+':'+ info.metadata.getIndexName()+"'!",e); info.metadata.setError(e); } catch (RuntimeException e) { log.error("Exception while activating Index '"+ info.metadata.getServerName()+':'+ info.metadata.getIndexName()+"'!",e); info.metadata.setError(e); } finally { managedCores.store(info.metadata); log.info(" ... start to UNINITIALISE Index {} on ManagedSolrServer",entry.getKey(),info.metadata.getServerName()); try { uninitialiseCore(info.metadata,true); log.info(" ... Index {} on ManagedSolrServer {} is now UNINITIALISED",entry.getKey(),info.metadata.getServerName()); } catch (RuntimeException e) {
/** * Creates and initialises a {@link IndexMetadata} instance based on the * parsed {@link SolrCore} * @param core the {@link SolrCore} * @param serverName the name of the server * @return the initialised {@link IndexMetadata} */ public static IndexMetadata getMetadata(SolrCore core, String serverName){ if(core == null){ return null; } IndexMetadata metadata = new IndexMetadata(); if(serverName != null){ metadata.setServerName(serverName); } metadata.setSynchronized(false); updateMetadata(metadata, core); return metadata; } /**
/** * Getter for the name of the index within the current * {@link IndexMetadata#getArchive() archive} set to load the index data * from. If no archive is set (e.g. if the {@link ArchiveInputStream} was * directly parsed, than the {@link IndexMetadata#getIndexName() index name} * directly is used as default. * @param metadata the {@link IndexMetadata} * @return the name of the index within the indexArchive used to load the * data from. In other words the relative path to the index data within the * index archive. */ public static String getArchiveCoreName(final IndexMetadata metadata) { String name = metadata.getIndexName(); String archiveCoreName = metadata.getArchive(); if(archiveCoreName == null){ archiveCoreName = name; } else { //the name of the core in the archive MUST BE the same as //the name of the archive excluding .solrindex.{archive-format} int split = archiveCoreName.indexOf('.'); if(split>0){ archiveCoreName = archiveCoreName.substring(0,split); } } return archiveCoreName; } // /**