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

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


        }
        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) {
            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

                ais = null;
            }
            if(ais != null){
                boolean keepTracking = false;
                for(String indexName : managedCores.getIndexNames(resourceName)){
                    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);
                            //if synchronised do not remove this listener
                            keepTracking = keepTracking || metadata.isSynchronized();
                        } else { //currently used Archive is of higher priority as
                            // this one.
                            //keep tracking if synchronised
                            keepTracking = keepTracking || metadata.isSynchronized();
                        }
                    } //else managed core was deleted in the meantime ...
                }
                return !keepTracking;
            } else { //unable to create an ArchiveInputStrem
View Full Code Here

                                                                              SAXException {
        // if the solr core is managed, check that the index is properly activated
        if (managedSolrServer != null && indexReference.checkServer(managedSolrServer.getServerName())
            && context != null) {
            String indexName = indexReference.getIndex();
            IndexMetadata indexMetadata = managedSolrServer.getIndexMetadata(indexName);
            if (indexMetadata == null) {
                // TODO: debug the DataFileProvider init race conditions instead
                // indexMetadata = managedSolrServer.createSolrIndex(indexName, indexArchiveName, null);
                URL archiveUrl = context.getBundleContext().getBundle()
                        .getEntry("/data-files/" + indexArchiveName + ".solrindex.zip");
                if (archiveUrl == null) {
                    throw new ConfigurationException(solrCoreId, "Could not find index archive for "
                                                                 + indexArchiveName);
                }
                ZipArchiveInputStream zis = new ZipArchiveInputStream(archiveUrl.openStream());
                indexMetadata = managedSolrServer.updateIndex(indexName, zis, indexArchiveName);
            }
            if (!indexMetadata.isActive()) {
                managedSolrServer.activateIndex(indexName);
            }
            indexReference = indexMetadata.getIndexReference();
        }
        return indexReference;
    }
View Full Code Here

            IndexReference indexReference = IndexReference.parse(solrCoreId);
            if (!indexReference.checkServer(managedSolrServer.getServerName())) {
                return;
            }
            String indexName = indexReference.getIndex();
            IndexMetadata indexMetadata = managedSolrServer.getIndexMetadata(indexName);
            if (indexMetadata != null && indexMetadata.isActive()) {
                managedSolrServer.deactivateIndex(indexName);
            }
            this.managedSolrServer = null;
        }
    }
View Full Code Here

            return null;
        }
        Collection<IndexMetadata> clones = new HashSet<IndexMetadata>();
        synchronized (inMemoryModelLock) {
            for(IndexMetadata metadata : managed.get(state).values()){
                IndexMetadata clone = new IndexMetadata();
                clone.putAll(metadata);
                clones.add(clone);
            }
        }
        return clones;
       
View Full Code Here

        }
        return clones;
       
    }
    public IndexMetadata getIndexMetadata(String indexName){
        IndexMetadata metadata = null;
        synchronized (inMemoryModelLock) {
            Iterator<Map<String,IndexMetadata>> inStateIt = managed.values().iterator();
            while(metadata == null && inStateIt.hasNext()) {
                metadata = inStateIt.next().get(indexName);
            }
        }
        //we need to return a clone to prevent changes by external changes to
        //the internal state!
        if(metadata != null){
            IndexMetadata clone = new IndexMetadata();
            clone.putAll(metadata);
            return clone;
        } else {
            return null;
        }
    }
View Full Code Here

                        Collections.unmodifiableCollection(indexNames);
        }
    }
   
    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);
    }
View Full Code Here

        } else {
            removeIndexConfig(name);
        }
        //clone is meaningless if properties are NULL
        if(clone && properties != null){
            IndexMetadata tmp = properties;
            properties = new IndexMetadata();
            properties.putAll(tmp);
        }
        Map<String,IndexMetadata> toAdd,toRemove;
        IndexMetadata oldMetadata = null;
        synchronized (inMemoryModelLock ) {
            ManagedIndexState currentState = getState(name);
            if(currentState != null){
                toRemove = managed.get(currentState);
            } else {
                toRemove = null;
            }
            if(properties == null){
                toAdd = null; //remove
            } else {
                ManagedIndexState newState = properties.getState();
                toAdd = managed.get(newState);
            }
            //now update in-memory state
            if(toRemove != null){
                oldMetadata = toRemove.remove(name);
            }
            if(toAdd != null){
                toAdd.put(name, properties);
            }
            //now update the archive name to core name mappings
            if(oldMetadata != null){
                for(String indexArchive : oldMetadata.getIndexArchives()){
                    Collection<String> indexes = archiveName2CoreName.get(indexArchive);
                    if(indexes.remove(name) && indexes.isEmpty()){
                        archiveName2CoreName.remove(indexArchive);
                    }
                }
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.