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

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


                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


        }
        IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
        if(config.isAllowInitialisation()){ //are we allowed to create the SolrServer
            //get the name of the config to be used (default: default.solrindex.zip")
            String configName = config.getIndexConfigurationName();
            IndexMetadata metadata = managedServer.getIndexMetadata(solrIndexRef.getIndex());
            if(metadata == null){ //create a new index
                log.info(" ... creating Managed SolrIndex {} (configName: {}) on Server {}",
                    new Object[]{solrIndexRef.getIndex(),configName,managedServer.getServerName()});
                try {
                    metadata = managedServer.createSolrIndex(solrIndexRef.getIndex(), configName, null);
                } catch (IOException e) {
                    throw new IllegalStateException("Unable to create Managed SolrIndex "
                        + solrIndexRef.getIndex()+" (configName: "+configName+") on Server "
                        + 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.getIndex()+" (configName: "+configName+") on Server "
                            + managedServer.getServerName()+"!",e);
                } catch (SAXException e) {
                    throw new IllegalStateException("Unable to activate Managed SolrIndex "
                            + solrIndexRef.getIndex()+" (configName: "+configName+") on Server "
                            + managedServer.getServerName()+"!",e);
                }
            } //else already active nothing todo
            solrIndexRef = metadata.getIndexReference();
        } //else the SolrServer will be supplied (e.g. created by installing a full index)
        try {
            registeredServerTracker = new RegisteredSolrServerTracker(
                context, solrIndexRef,null){
                   
View Full Code Here

        // if the solr core is managed, check that the index is properly activated
        if (managedSolrServer != null && indexReference.checkServer(managedSolrServer.getServerName())
            && context != null && solrCoreConfig != null) {
            log.info(" > check/init index {} on ManagedSolrServer {}", indexReference, managedSolrServer.getServerName());
            String indexName = indexReference.getIndex();
            final IndexMetadata indexMetadata;
            ManagedIndexState indexState = managedSolrServer.getIndexState(indexName);
            if(indexState == null){
                if(solrCoreConfig.indexOf(".solrindex.") < 0){ //if the suffix is missing
                    solrCoreConfig = solrCoreConfig + ".solrindex.zip"; //append it
                }
                log.info("Create SolrCore {} (config: {}) on ManagedSolrServer {} ...",
                    new Object[]{indexName,solrCoreConfig,managedSolrServer.getServerName()});
                indexMetadata = managedSolrServer.createSolrIndex(indexName,
                    solrCoreConfig, null);
                if(indexMetadata != null)
                log.info("  ... created {}", indexMetadata.getIndexReference());
            } else {
                indexMetadata = managedSolrServer.getIndexMetadata(indexName);
                if(indexState != ManagedIndexState.ACTIVE){
                    log.info("  ... activate {}", indexMetadata.getIndexReference());
                    managedSolrServer.activateIndex(indexName);
                } else {
                    log.info("  ... index {} already active", indexMetadata.getIndexReference());
                }
            }
//            IndexMetadata indexMetadata = managedSolrServer.getIndexMetadata(indexName);
//            if (indexMetadata == null) {
//                // TODO: debug the DataFileProvider init race conditions instead
//                // indexMetadata = managedSolrServer.createSolrIndex(indexName, indexArchiveName, null);
//                dfp.getInputStream(context.getBundleContext().getBundle().getSymbolicName(),
//                    indexArchiveName + ".solrindex.zip", 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

                    config.getSolrServerLocation());
                return null; //indicate that the server is not yet active
            } else if(indexReference.getServer() == null ||
                        indexReference.getServer().equals(managedSolrServer.getServerName())){
                //check if the referenced Index is Managed
                IndexMetadata indexMetadata = managedSolrServer.getIndexMetadata(indexReference.getIndex());
                if(indexMetadata == null){
                    // not managed -> try to create
                    IndexReference createdIndexRef = createSolrIndex(managedSolrServer,config, indexReference.getIndex());
                    if(context == null){
                        //in that case we need to replace the parse SolrServerLocation
                        //with the name of the created solr index
                        config.setSolrServerLocation(createdIndexRef.getIndex());
                    }
                    //return the created IndexReference
                    return createdIndexRef;
                } else if(!indexMetadata.isActive()){ //already managed, but not active
                    //try to activate
                    try {
                        IndexMetadata activatedMetadata = managedSolrServer.activateIndex(indexReference.getIndex());
                        if(activatedMetadata == null){
                            throw new YardException(String.format(
                                "Unable to actiate SolrIndex '%s' for SolrYard '%s" +
                                "on MnagedSolrServer '%s'!",indexReference,
                                getConfig().getName(),managedSolrServer.getServerName()));
                        } else {
                            return activatedMetadata.getIndexReference();
                        }
                    } catch (IOException e) {
                        throw new YardException("Unable to actiate SolrIndex for SolrYard "+getConfig().getName(),e);
                    } catch (SAXException e) {
                        throw new YardException("Unable to actiate SolrIndex for SolrYard "+getConfig().getName(),e);
View Full Code Here

            configName = config.getIndexConfigurationName();
        }
        log.info(" ... initialise new SolrDirectory Index with name {} by using Index Configuration {}",
            solrIndexLocation,configName);
        try {
            IndexMetadata metadata = managedServer.createSolrIndex(solrIndexLocation,configName,null);
            if (metadata == null) {
                throw new YardException("SolrIndex "+ config.getSolrServerLocation() +
                        " is not available" + (config.isDefaultInitialisation() ?
                                " and could not be initialised!" :
                                    ". The necessary Index is not yet installed."));
            } else {
                log.info(" ... created IndexDirectory {} for SolrIndex {} by using config {}",
                    new Object[]{metadata.getDirectory(),solrIndexLocation,configName});
            }
            return metadata.getIndexReference();
        } catch (IOException e) {
            throw new YardException("SolrIndex "+ config.getSolrServerLocation() +
                    " could not be initialised!",e);
        }
    }
View Full Code Here

                    config.getSolrServerLocation());
                return null; //indicate that the server is not yet active
            } else if(indexReference.getServer() == null ||
                        indexReference.getServer().equals(managedSolrServer.getServerName())){
                //check if the referenced Index is Managed
                IndexMetadata indexMetadata = managedSolrServer.getIndexMetadata(indexReference.getIndex());
                if(indexMetadata == null){
                    // not managed -> try to create
                    IndexReference createdIndexRef = createSolrIndex(managedSolrServer,config, indexReference.getIndex());
                    if(context == null){
                        //in that case we need to replace the parse SolrServerLocation
                        //with the name of the created solr index
                        config.setSolrServerLocation(createdIndexRef.getIndex());
                    }
                    //return the created IndexReference
                    return createdIndexRef;
                } else if(!indexMetadata.isActive()){ //already managed, but not active
                    //try to activate
                    try {
                        IndexMetadata activatedMetadata = managedSolrServer.activateIndex(indexReference.getIndex());
                        if(activatedMetadata == null){
                            throw new YardException(String.format(
                                "Unable to actiate SolrIndex '%s' for SolrYard '%s" +
                                "on MnagedSolrServer '%s'!",indexReference,
                                getConfig().getName(),managedSolrServer.getServerName()));
                        } else {
                            return activatedMetadata.getIndexReference();
                        }
                    } catch (IOException e) {
                        throw new YardException("Unable to actiate SolrIndex for SolrYard "+getConfig().getName(),e);
                    } catch (SAXException e) {
                        throw new YardException("Unable to actiate SolrIndex for SolrYard "+getConfig().getName(),e);
View Full Code Here

            configName = config.getIndexConfigurationName();
        }
        log.info(" ... initialise new SolrDirectory Index with name {} by using Index Configuration {}",
            solrIndexLocation,configName);
        try {
            IndexMetadata metadata = managedServer.createSolrIndex(solrIndexLocation,configName,null);
            if (metadata == null) {
                throw new YardException("SolrIndex "+ config.getSolrServerLocation() +
                        " is not available" + (config.isDefaultInitialisation() ?
                                " and could not be initialised!" :
                                    ". The necessary Index is not yet installed."));
            } else {
                log.info(" ... created IndexDirectory {} for SolrIndex {} by using config {}",
                    new Object[]{metadata.getDirectory(),solrIndexLocation,configName});
            }
            return metadata.getIndexReference();
        } catch (IOException e) {
            throw new YardException("SolrIndex "+ config.getSolrServerLocation() +
                    " could not be initialised!",e);
        }
    }
View Full Code Here

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

        }
    }

    @Override
    public IndexMetadata getIndexMetadata(String indexName) {
        IndexMetadata metadata;
        SolrCore core  = server.getCore(indexName);
        if(core != null){
             metadata = getMetadata(core,serverName);
            core.close();
        } else {
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.