Search in sources :

Example 6 with Aliases

use of org.apache.solr.common.cloud.Aliases in project lucene-solr by apache.

the class TupleStream method getSlices.

public static Collection<Slice> getSlices(String collectionName, ZkStateReader zkStateReader, boolean checkAlias) throws IOException {
    ClusterState clusterState = zkStateReader.getClusterState();
    Map<String, DocCollection> collectionsMap = clusterState.getCollectionsMap();
    // Check collection case sensitive
    if (collectionsMap.containsKey(collectionName)) {
        return collectionsMap.get(collectionName).getActiveSlices();
    }
    // Check collection case insensitive
    for (String collectionMapKey : collectionsMap.keySet()) {
        if (collectionMapKey.equalsIgnoreCase(collectionName)) {
            return collectionsMap.get(collectionMapKey).getActiveSlices();
        }
    }
    if (checkAlias) {
        // check for collection alias
        Aliases aliases = zkStateReader.getAliases();
        String alias = aliases.getCollectionAlias(collectionName);
        if (alias != null) {
            Collection<Slice> slices = new ArrayList<>();
            List<String> aliasList = StrUtils.splitSmart(alias, ",", true);
            for (String aliasCollectionName : aliasList) {
                // Add all active slices for this alias collection
                slices.addAll(collectionsMap.get(aliasCollectionName).getActiveSlices());
            }
            return slices;
        }
    }
    throw new IOException("Slices not found for " + collectionName);
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) Aliases(org.apache.solr.common.cloud.Aliases) IOException(java.io.IOException)

Example 7 with Aliases

use of org.apache.solr.common.cloud.Aliases in project lucene-solr by apache.

the class CloudSolrStream method getSlices.

public static Collection<Slice> getSlices(String collectionName, ZkStateReader zkStateReader, boolean checkAlias) throws IOException {
    ClusterState clusterState = zkStateReader.getClusterState();
    Map<String, DocCollection> collectionsMap = clusterState.getCollectionsMap();
    // Check collection case sensitive
    if (collectionsMap.containsKey(collectionName)) {
        return collectionsMap.get(collectionName).getActiveSlices();
    }
    // Check collection case insensitive
    for (String collectionMapKey : collectionsMap.keySet()) {
        if (collectionMapKey.equalsIgnoreCase(collectionName)) {
            return collectionsMap.get(collectionMapKey).getActiveSlices();
        }
    }
    if (checkAlias) {
        // check for collection alias
        Aliases aliases = zkStateReader.getAliases();
        String alias = aliases.getCollectionAlias(collectionName);
        if (alias != null) {
            Collection<Slice> slices = new ArrayList<>();
            List<String> aliasList = StrUtils.splitSmart(alias, ",", true);
            for (String aliasCollectionName : aliasList) {
                // Add all active slices for this alias collection
                slices.addAll(collectionsMap.get(aliasCollectionName).getActiveSlices());
            }
            return slices;
        }
    }
    throw new IOException("Slices not found for " + collectionName);
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) Aliases(org.apache.solr.common.cloud.Aliases) IOException(java.io.IOException)

Example 8 with Aliases

use of org.apache.solr.common.cloud.Aliases in project lucene-solr by apache.

the class DeleteAliasCmd method checkForAliasAbsence.

private void checkForAliasAbsence(String name) {
    TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS);
    boolean success = false;
    Aliases aliases = null;
    while (!timeout.hasTimedOut()) {
        aliases = ocmh.zkStateReader.getAliases();
        String collections = aliases.getCollectionAlias(name);
        if (collections == null) {
            success = true;
            break;
        }
    }
    if (!success) {
        log.warn("Timeout waiting to be notified of Alias change...");
    }
}
Also used : TimeOut(org.apache.solr.util.TimeOut) Aliases(org.apache.solr.common.cloud.Aliases)

Example 9 with Aliases

use of org.apache.solr.common.cloud.Aliases in project lucene-solr by apache.

the class DeleteAliasCmd method call.

@Override
public void call(ClusterState state, ZkNodeProps message, NamedList results) throws Exception {
    String aliasName = message.getStr(NAME);
    Map<String, Map<String, String>> newAliasesMap = new HashMap<>();
    Map<String, String> newCollectionAliasesMap = new HashMap<>();
    ZkStateReader zkStateReader = ocmh.zkStateReader;
    newCollectionAliasesMap.putAll(zkStateReader.getAliases().getCollectionAliasMap());
    newCollectionAliasesMap.remove(aliasName);
    newAliasesMap.put("collection", newCollectionAliasesMap);
    Aliases newAliases = new Aliases(newAliasesMap);
    byte[] jsonBytes = null;
    if (newAliases.collectionAliasSize() > 0) {
        // only sub map right now
        jsonBytes = Utils.toJSON(newAliases.getAliasMap());
    }
    try {
        zkStateReader.getZkClient().setData(ZkStateReader.ALIASES, jsonBytes, true);
        checkForAliasAbsence(aliasName);
        // some fudge for other nodes
        Thread.sleep(100);
    } catch (KeeperException e) {
        log.error("", e);
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
    } catch (InterruptedException e) {
        log.warn("", e);
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) HashMap(java.util.HashMap) Aliases(org.apache.solr.common.cloud.Aliases) HashMap(java.util.HashMap) Map(java.util.Map) KeeperException(org.apache.zookeeper.KeeperException) SolrException(org.apache.solr.common.SolrException)

Example 10 with Aliases

use of org.apache.solr.common.cloud.Aliases in project lucene-solr by apache.

the class ScoreJoinQParserPlugin method resolveAlias.

private static String resolveAlias(String fromIndex, ZkController zkController) {
    final Aliases aliases = zkController.getZkStateReader().getAliases();
    if (aliases != null) {
        final String resolved;
        Map<String, String> collectionAliases = aliases.getCollectionAliasMap();
        resolved = (collectionAliases != null) ? collectionAliases.get(fromIndex) : null;
        if (resolved != null) {
            if (resolved.split(",").length > 1) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "SolrCloud join: Collection alias '" + fromIndex + "' maps to multiple collections (" + resolved + "), which is not currently supported for joins.");
            }
            return resolved;
        }
    }
    return null;
}
Also used : Aliases(org.apache.solr.common.cloud.Aliases) SolrException(org.apache.solr.common.SolrException)

Aggregations

Aliases (org.apache.solr.common.cloud.Aliases)10 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 SolrException (org.apache.solr.common.SolrException)4 ClusterState (org.apache.solr.common.cloud.ClusterState)4 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 DocCollection (org.apache.solr.common.cloud.DocCollection)3 Slice (org.apache.solr.common.cloud.Slice)3 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)2 TimeOut (org.apache.solr.util.TimeOut)2 KeeperException (org.apache.zookeeper.KeeperException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 HashSet (java.util.HashSet)1