/** * 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; }
/** * Checks if this index is in the {@link ManagedIndexState#ACTIVE} state * @return if this index is active or not * @see #getState() */ public boolean isActive(){ ManagedIndexState state = getState(); return state != null && state == ManagedIndexState.ACTIVE; } /**
/** * Checks if this index is in the {@link ManagedIndexState#INACTIVE} state * @return if this index is inactive or not * @see #getState() */ public boolean isInactive(){ ManagedIndexState state = getState(); return state != null && state == ManagedIndexState.INACTIVE; } /**
/** * Checks if this index is in the {@link ManagedIndexState#ACTIVE} state * @return if this index is active or not * @see #getState() */ public boolean isActive(){ ManagedIndexState state = getState(); return state != null && state == ManagedIndexState.ACTIVE; } /**
/** * Checks if this index is in the {@link ManagedIndexState#INACTIVE} state * @return if this index is inactive or not * @see #getState() */ public boolean isInactive(){ ManagedIndexState state = getState(); return state != null && state == ManagedIndexState.INACTIVE; } /**
/** * Checks if this index is in the {@link ManagedIndexState#ERROR} state * @return if this index has an error or not * @see #getState() */ public boolean isError(){ ManagedIndexState state = getState(); return state != null && state == ManagedIndexState.ERROR; } /**
/** * Checks if this index is in the {@link ManagedIndexState#ERROR} state * @return if this index has an error or not * @see #getState() */ public boolean isError(){ ManagedIndexState state = getState(); return state != null && state == ManagedIndexState.ERROR; } /**
/** * 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; }
managed.get(entry.getValue().getState()).put( entry.getKey(), entry.getValue()); for(String archiveName : entry.getValue().getIndexArchives()){
managed.get(entry.getValue().getState()).put( entry.getKey(), entry.getValue()); for(String archiveName : entry.getValue().getIndexArchives()){
/** * 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!"); } }
/** * 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!"); } }
@Override public IndexMetadata deactivateIndex(String indexName) { IndexMetadata metadata = managedCores.getIndexMetadata(indexName); if(metadata != null && metadata.getState() == ManagedIndexState.ACTIVE){ try { deactivateCore(indexName, server); metadata.setState(ManagedIndexState.INACTIVE); } catch (RuntimeException e) { metadata.setError(e); } finally { managedCores.store(metadata); } } return metadata; } @Override
@Override public IndexMetadata deactivateIndex(String indexName) { IndexMetadata metadata = managedCores.getIndexMetadata(indexName); if(metadata != null && metadata.getState() == ManagedIndexState.ACTIVE){ try { deactivateCore(indexName, server); metadata.setState(ManagedIndexState.INACTIVE); } catch (RuntimeException e) { metadata.setError(e); } finally { managedCores.store(metadata); } } return metadata; } @Override
@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
@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
+ 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());
+ 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());
@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
@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