Package org.apache.stanbol.commons.solr.managed

Examples of org.apache.stanbol.commons.solr.managed.IndexMetadata


            return updateIndex(indexName, null);
        }
    }
    @Override
    public IndexMetadata deactivateIndex(String indexName) {
        IndexMetadata metadata;
        SolrCore core = server.remove(indexName);
        if(core != null){
            metadata = getMetadata(core,serverName);
            core.close();
            metadata.setState(ManagedIndexState.INACTIVE);
        } else {
            metadata = null;
        }
        return metadata;
    }
View Full Code Here


        //(1) Try to activate missing cores on the CoreContainer
        if(!activeByMetadata.isEmpty()){
            log.info("The following active managed Cores are not available on " +
                "the SolrServer: {}",activeByMetadata);
            for(String indexName : activeByMetadata){
                IndexMetadata metadata = managedCores.getIndexMetadata(indexName);
                try {
                    activateCore(metadata, server);
                    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);
                //} finally { The metadata are not modified anyway!
                //    managedCores.store(metadata);
                }
            }
        }
        //(2) Process active SolrCores on the CoreContainer that are not active
        //    based on the configuration
        if(!activeOnSolrServer.isEmpty()){
            log.info("The following Cores active on the SolrServer are not " +
                "marked as active in the Metadata: {}",activeOnSolrServer);
            log.info("Based on the Metadata (UNKNOWN ... no Index for that name):");
            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){
                    //unknown core ... deactivate
                    deactivateCore(indexName, server);
                    log.info("  ... deactiaved UNKOWN SolrCore {} on managed Solr Server {}",
                        indexName, serverName);
                } else if(state == ManagedIndexState.INACTIVE){
                    ////the metadata way this core should be deactivated!
                    deactivateCore(indexName, server);
                    log.info("  ... deactiaved INACTIVE SolrCore {} on managed Solr Server {}",
                        indexName, serverName);
                } else if(state == ManagedIndexState.ERROR){
                    //looks like that the error was resolved ...
                    // ... maybe someone has manually edited some files and
                    //     restarted this server
                    metadata.setState(ManagedIndexState.ACTIVE);
                    managedCores.store(metadata);
                    log.info("  ... successfully ACTIVATED SolrCore {} on managed Solr Server {}",
                        indexName, serverName);
                } else if(state == ManagedIndexState.UNINITIALISED){
                    //looks like someone has copied the required files manually
                    //to the solrServer ... update the metadata an activate
                    ManagementUtils.updateMetadata(metadata, server.getCore(indexName));
                    metadata.setState(ManagedIndexState.ACTIVE);
                    managedCores.store(metadata);
                    log.info("  ... successfully ACTIVATED SolrCore {} on managed Solr Server {}",
                        indexName, serverName);
                }
            }
View Full Code Here

        }
        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);
View Full Code Here

    public void removeIndex(String indexName, boolean deleteFiles) {
        if(indexName == null || indexName.isEmpty()){
            throw new IllegalArgumentException("The parsed index name MUST NOT be NULL nor empty!");
        }
        //remove the index from the metadata
        IndexMetadata metadata = managedCores.remove(indexName);
        if(metadata != null){
            //and also tracked index archives from the DataFileTracker
            indexArchiveTracker.removeTracking(metadata);
            uninitialiseCore(metadata,deleteFiles);
        }
View Full Code Here

                "be NULL nor empty!");
        }
        if(ais == null){
            throw new IOException("The parsed ArchiveInputStream MUST NOT be NULL!");
        }
        IndexMetadata metadata = new IndexMetadata();
        metadata.setServerName(serverName);
        metadata.setIndexName(indexName);
        metadata.setSynchronized(false);
        if (archiveCoreName != null) {
            metadata.setArchive(archiveCoreName);
        }
        try {
            updateCore(metadata, ais);
        } finally {
            managedCores.store(metadata);
View Full Code Here

    @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);
View Full Code Here

        indexArchiveTracker.updateTracking(oldMetadata,metadata);
        return metadata;
    }
    @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;
View Full Code Here

        }
        return metadata;
    }
    @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);
            }
        }
View Full Code Here

        synchronized (serverInUser) {
            serverInUser.add(token);
        }
        try {
            server.swap(indexName1, indexName2);
            IndexMetadata core1Metadata = getIndexMetadata(indexName1);
            IndexMetadata core2Metadata = getIndexMetadata(indexName2);
            String core2Directory = core2Metadata.getDirectory();
            core2Metadata.setDirectory(core1Metadata.getDirectory());
            core1Metadata.setDirectory(core2Directory);
            managedCores.store(core1Metadata);
            managedCores.store(core2Metadata);
        } finally {
            synchronized (serverInUser) {
View Full Code Here

       
        @Override
        public boolean unavailable(String resource) {
            log.info("IndexArchive {} unavailable ...",resource);
            for(String indexName : managedCores.getIndexNames(resource)){
                IndexMetadata metadata = managedCores.getIndexMetadata(indexName);
                if(metadata != null){ //may be removed in the meantime
                    String currentArchive = metadata.getArchive();
                    boolean inSync = metadata.isSynchronized();
                    if(resource.equals(currentArchive)){ //current archive may be null
                        currentArchive = null; //reset the current archive to null (none)
                        ArchiveInputStream ais = null;
                        for(String archive : metadata.getIndexArchives()){
                            if(!archive.equals(resource)) {
                                if(currentArchive == null){
                                    try {
                                        InputStream is = provider.getInputStream(null, archive, null);
                                        if(is != null){
                                            ais = ManagementUtils.getArchiveInputStream(archive, is);
                                        } else {
                                            ais = null;
                                        }
                                    } catch (IOException e) {
                                       //not available
                                        ais = null;
                                    } catch (ArchiveException e) {
                                        log.error("Unable to open ArchiveInputStream for Resource '"+
                                            archive+"'!",e);
                                        ais = null;
                                    }
                                    if(ais != null){ //ais != null also
                                        currentArchive = archive; //currentArchive != null
                                    }
                                }
                                //if resource become unavailable we might need to
                                //add resources for tracking
                                if(!tracker.isTracked(this, null, archive) && //if not already tracked
                                        (currentArchive == null || ( //and no archive found
                                                currentArchive != null && inSync))){ //or found but inSync
                                        tracker.add(this, archive,
                                            IndexMetadata.toStringMap(metadata));
                                } // else already tracked or no tracking needed
                            }
                        }
                        //If we have now a currentArchive and an ais we can
                        //switch to an alternate archive.
                        //If not we need to switch this in index in the UNAVAILABLE
                        // state
                        metadata.setArchive(currentArchive);//update the metadata
                        managedCores.store(metadata);
                        //if the parsed ais is NULL the index will be uninitialised
                        indexUpdateDaemon.update(
                            currentArchive == null ? ManagedIndexState.UNINITIALISED :
                                    ManagedIndexState.ACTIVE,
View Full Code Here

TOP

Related Classes of org.apache.stanbol.commons.solr.managed.IndexMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.