Search in sources :

Example 16 with IndexMetadata

use of org.apache.stanbol.commons.solr.managed.IndexMetadata in project stanbol by apache.

the class ManagedSolrServerImpl method createSolrIndex.

@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;
}
Also used : IndexMetadata(org.apache.stanbol.commons.solr.managed.IndexMetadata)

Example 17 with IndexMetadata

use of org.apache.stanbol.commons.solr.managed.IndexMetadata in project stanbol by apache.

the class StandaloneManagedSolrServer method updateIndex.

@Override
public IndexMetadata updateIndex(String name, ArchiveInputStream ais, String archiveCoreName) throws IOException {
    if (name == null || name.isEmpty()) {
        throw new IllegalArgumentException("The parsed index name MUST NOT be NULL nor empty!");
    }
    IndexMetadata metadata = new IndexMetadata();
    metadata.setIndexName(name);
    metadata.setServerName(DEFAULT_SERVER_NAME);
    metadata.setSynchronized(false);
    metadata.setState(ManagedIndexState.ACTIVE);
    if (archiveCoreName != null) {
        metadata.setArchive(archiveCoreName);
    }
    return updateCore(metadata, ais);
}
Also used : IndexMetadata(org.apache.stanbol.commons.solr.managed.IndexMetadata)

Example 18 with IndexMetadata

use of org.apache.stanbol.commons.solr.managed.IndexMetadata in project stanbol by apache.

the class StandaloneManagedSolrServer method deactivateIndex.

@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;
}
Also used : SolrCore(org.apache.solr.core.SolrCore) IndexMetadata(org.apache.stanbol.commons.solr.managed.IndexMetadata)

Example 19 with IndexMetadata

use of org.apache.stanbol.commons.solr.managed.IndexMetadata in project stanbol by apache.

the class StandaloneManagedSolrServer method getIndexMetadata.

@Override
public IndexMetadata getIndexMetadata(String indexName) {
    IndexMetadata metadata;
    SolrCore core = server.getCore(indexName);
    if (core != null) {
        metadata = getMetadata(core, serverName);
        core.close();
    } else {
        metadata = null;
    }
    return metadata;
}
Also used : SolrCore(org.apache.solr.core.SolrCore) IndexMetadata(org.apache.stanbol.commons.solr.managed.IndexMetadata)

Example 20 with IndexMetadata

use of org.apache.stanbol.commons.solr.managed.IndexMetadata in project stanbol by apache.

the class ManagementUtils method getMetadata.

// /**
// * Parses the name of the Core from an IndexReference (file url, file path,
// * index name or server:indexname)
// * @param indexRef the parsed indexRef
// * @return
// */
// public static String getCoreNameForIndexRef(String indexRef,String serverName) {
// 
// String[] parsedRef = ConfigUtils.parseSolrServerReference(indexRef);
// String coreName;
// if(parsedRef[0] != null && !parsedRef[0].equals(serverName)){
// coreName = null; //other server
// } else {
// coreName = parsedRef[1];
// if(coreName == null || coreName.isEmpty()){
// log.warn("The parsed index reference '"+indexRef+"' does not define a valid core name!");
// }
// }
// return coreName;
// }
/**
 * 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;
}
Also used : IndexMetadata(org.apache.stanbol.commons.solr.managed.IndexMetadata)

Aggregations

IndexMetadata (org.apache.stanbol.commons.solr.managed.IndexMetadata)21 IOException (java.io.IOException)7 File (java.io.File)3 HashMap (java.util.HashMap)3 ManagedIndexState (org.apache.stanbol.commons.solr.managed.ManagedIndexState)3 SAXException (org.xml.sax.SAXException)3 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 SolrCore (org.apache.solr.core.SolrCore)2 IndexReference (org.apache.stanbol.commons.solr.IndexReference)2 FileInputStream (java.io.FileInputStream)1 EnumMap (java.util.EnumMap)1 Map (java.util.Map)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 ArchiveException (org.apache.commons.compress.archivers.ArchiveException)1 ArchiveInputStream (org.apache.commons.compress.archivers.ArchiveInputStream)1 SuffixFileFilter (org.apache.commons.io.filefilter.SuffixFileFilter)1 Activate (org.apache.felix.scr.annotations.Activate)1 SolrServer (org.apache.solr.client.solrj.SolrServer)1 HttpSolrServer (org.apache.solr.client.solrj.impl.HttpSolrServer)1