Search in sources :

Example 31 with SolrException

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

the class ManagedIndexSchemaFactory method inform.

@Override
public void inform(SolrCore core) {
    this.core = core;
    if (loader instanceof ZkSolrResourceLoader) {
        this.zkIndexSchemaReader = new ZkIndexSchemaReader(this, core);
        ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) loader;
        zkLoader.setZkIndexSchemaReader(this.zkIndexSchemaReader);
        try {
            // update immediately if newer is available
            zkIndexSchemaReader.refreshSchemaFromZk(-1);
            core.setLatestSchema(getSchema());
        } catch (KeeperException e) {
            String msg = "Error attempting to access " + zkLoader.getConfigSetZkPath() + "/" + managedSchemaResourceName;
            log.error(msg, e);
            throw new SolrException(ErrorCode.SERVER_ERROR, msg, e);
        } catch (InterruptedException e) {
            // Restore the interrupted status
            Thread.currentThread().interrupt();
            log.warn("", e);
        }
    } else {
        this.zkIndexSchemaReader = null;
    }
}
Also used : ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) KeeperException(org.apache.zookeeper.KeeperException) SolrException(org.apache.solr.common.SolrException)

Example 32 with SolrException

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

the class TrieDateFieldSource method getSortField.

@Override
public SortField getSortField(SchemaField field, boolean top) {
    field.checkSortability();
    Object missingValue = null;
    boolean sortMissingLast = field.sortMissingLast();
    boolean sortMissingFirst = field.sortMissingFirst();
    SortField sf;
    switch(type) {
        case INTEGER:
            if (sortMissingLast) {
                missingValue = top ? Integer.MIN_VALUE : Integer.MAX_VALUE;
            } else if (sortMissingFirst) {
                missingValue = top ? Integer.MAX_VALUE : Integer.MIN_VALUE;
            }
            sf = new SortField(field.getName(), SortField.Type.INT, top);
            sf.setMissingValue(missingValue);
            return sf;
        case FLOAT:
            if (sortMissingLast) {
                missingValue = top ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;
            } else if (sortMissingFirst) {
                missingValue = top ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
            }
            sf = new SortField(field.getName(), SortField.Type.FLOAT, top);
            sf.setMissingValue(missingValue);
            return sf;
        // fallthrough
        case DATE:
        case LONG:
            if (sortMissingLast) {
                missingValue = top ? Long.MIN_VALUE : Long.MAX_VALUE;
            } else if (sortMissingFirst) {
                missingValue = top ? Long.MAX_VALUE : Long.MIN_VALUE;
            }
            sf = new SortField(field.getName(), SortField.Type.LONG, top);
            sf.setMissingValue(missingValue);
            return sf;
        case DOUBLE:
            if (sortMissingLast) {
                missingValue = top ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
            } else if (sortMissingFirst) {
                missingValue = top ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
            }
            sf = new SortField(field.getName(), SortField.Type.DOUBLE, top);
            sf.setMissingValue(missingValue);
            return sf;
        default:
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + field.name);
    }
}
Also used : SortField(org.apache.lucene.search.SortField) SolrException(org.apache.solr.common.SolrException)

Example 33 with SolrException

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

the class TextField method analyzeMultiTerm.

public static BytesRef analyzeMultiTerm(String field, String part, Analyzer analyzerIn) {
    if (part == null || analyzerIn == null)
        return null;
    try (TokenStream source = analyzerIn.tokenStream(field, part)) {
        source.reset();
        TermToBytesRefAttribute termAtt = source.getAttribute(TermToBytesRefAttribute.class);
        if (!source.incrementToken())
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "analyzer returned no terms for multiTerm term: " + part);
        BytesRef bytes = BytesRef.deepCopyOf(termAtt.getBytesRef());
        if (source.incrementToken())
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "analyzer returned too many terms for multiTerm term: " + part);
        source.end();
        return bytes;
    } catch (IOException e) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "error analyzing range part: " + part, e);
    }
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) TermToBytesRefAttribute(org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException) BytesRef(org.apache.lucene.util.BytesRef)

Example 34 with SolrException

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

the class HadoopAuthPlugin method init.

@Override
public void init(Map<String, Object> pluginConfig) {
    try {
        String delegationTokenEnabled = (String) pluginConfig.getOrDefault(DELEGATION_TOKEN_ENABLED_PROPERTY, "false");
        authFilter = (Boolean.parseBoolean(delegationTokenEnabled)) ? new HadoopAuthFilter() : new AuthenticationFilter();
        // Initialize kerberos before initializing curator instance.
        boolean initKerberosZk = Boolean.parseBoolean((String) pluginConfig.getOrDefault(INIT_KERBEROS_ZK, "false"));
        if (initKerberosZk) {
            (new Krb5HttpClientBuilder()).getBuilder();
        }
        FilterConfig conf = getInitFilterConfig(pluginConfig);
        authFilter.init(conf);
    } catch (ServletException e) {
        throw new SolrException(ErrorCode.SERVER_ERROR, "Error initializing " + getClass().getName() + ": " + e);
    }
}
Also used : ServletException(javax.servlet.ServletException) AuthenticationFilter(org.apache.hadoop.security.authentication.server.AuthenticationFilter) FilterConfig(javax.servlet.FilterConfig) SolrException(org.apache.solr.common.SolrException) Krb5HttpClientBuilder(org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder)

Example 35 with SolrException

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

the class KerberosPlugin method getInitFilterConfig.

@VisibleForTesting
protected FilterConfig getInitFilterConfig(Map<String, Object> pluginConfig, boolean skipKerberosChecking) {
    Map<String, String> params = new HashMap();
    params.put("type", "kerberos");
    putParam(params, "kerberos.name.rules", NAME_RULES_PARAM, "DEFAULT");
    putParam(params, "token.valid", TOKEN_VALID_PARAM, "30");
    putParam(params, "cookie.path", COOKIE_PATH_PARAM, "/");
    if (!skipKerberosChecking) {
        putParam(params, "kerberos.principal", PRINCIPAL_PARAM, null);
        putParam(params, "kerberos.keytab", KEYTAB_PARAM, null);
    } else {
        putParamOptional(params, "kerberos.principal", PRINCIPAL_PARAM);
        putParamOptional(params, "kerberos.keytab", KEYTAB_PARAM);
    }
    String delegationTokenStr = System.getProperty(DELEGATION_TOKEN_ENABLED, null);
    boolean delegationTokenEnabled = (delegationTokenStr == null) ? false : Boolean.parseBoolean(delegationTokenStr);
    ZkController controller = coreContainer.getZkController();
    if (delegationTokenEnabled) {
        putParam(params, "delegation-token.token-kind", DELEGATION_TOKEN_KIND, DELEGATION_TOKEN_TYPE_DEFAULT);
        if (coreContainer.isZooKeeperAware()) {
            putParam(params, "signer.secret.provider", DELEGATION_TOKEN_SECRET_PROVIDER, "zookeeper");
            if ("zookeeper".equals(params.get("signer.secret.provider"))) {
                String zkHost = controller.getZkServerAddress();
                putParam(params, "token.validity", DELEGATION_TOKEN_VALIDITY, "36000");
                params.put("zk-dt-secret-manager.enable", "true");
                String chrootPath = zkHost.contains("/") ? zkHost.substring(zkHost.indexOf("/")) : "";
                String znodeWorkingPath = chrootPath + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH + "/zkdtsm";
                // Note - Curator complains if the znodeWorkingPath starts with /
                znodeWorkingPath = znodeWorkingPath.startsWith("/") ? znodeWorkingPath.substring(1) : znodeWorkingPath;
                putParam(params, "zk-dt-secret-manager.znodeWorkingPath", DELEGATION_TOKEN_SECRET_MANAGER_ZNODE_WORKING_PATH, znodeWorkingPath);
                putParam(params, "signer.secret.provider.zookeeper.path", DELEGATION_TOKEN_SECRET_PROVIDER_ZK_PATH, "/token");
                // ensure krb5 is setup properly before running curator
                getHttpClientBuilder(SolrHttpClientBuilder.create());
            }
        } else {
            log.info("CoreContainer is not ZooKeeperAware, not setting ZK-related delegation token properties");
        }
    }
    // Special handling for the "cookie.domain" based on whether port should be
    // appended to the domain. Useful for situations where multiple solr nodes are
    // on the same host.
    String usePortStr = System.getProperty(COOKIE_PORT_AWARE_PARAM, null);
    boolean needPortAwareCookies = (usePortStr == null) ? false : Boolean.parseBoolean(usePortStr);
    if (!needPortAwareCookies || !coreContainer.isZooKeeperAware()) {
        putParam(params, "cookie.domain", COOKIE_DOMAIN_PARAM, null);
    } else {
        // we need port aware cookies and we are in SolrCloud mode.
        String host = System.getProperty(COOKIE_DOMAIN_PARAM, null);
        if (host == null) {
            throw new SolrException(ErrorCode.SERVER_ERROR, "Missing required parameter '" + COOKIE_DOMAIN_PARAM + "'.");
        }
        int port = controller.getHostPort();
        params.put("cookie.domain", host + ":" + port);
    }
    // check impersonator config
    for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements(); ) {
        String key = e.nextElement().toString();
        if (key.startsWith(IMPERSONATOR_PREFIX)) {
            if (!delegationTokenEnabled) {
                throw new SolrException(ErrorCode.SERVER_ERROR, "Impersonator configuration requires delegation tokens to be enabled: " + key);
            }
            params.put(key, System.getProperty(key));
        }
    }
    final ServletContext servletContext = new AttributeOnlyServletContext();
    if (controller != null) {
        servletContext.setAttribute(DELEGATION_TOKEN_ZK_CLIENT, controller.getZkClient());
    }
    if (delegationTokenEnabled) {
        kerberosFilter = new DelegationTokenKerberosFilter();
    // pass an attribute-enabled context in order to pass the zkClient
    // and because the filter may pass a curator instance.
    } else {
        kerberosFilter = new KerberosFilter();
    }
    log.info("Params: " + params);
    FilterConfig conf = new FilterConfig() {

        @Override
        public ServletContext getServletContext() {
            return servletContext;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return new IteratorEnumeration(params.keySet().iterator());
        }

        @Override
        public String getInitParameter(String param) {
            return params.get(param);
        }

        @Override
        public String getFilterName() {
            return "KerberosFilter";
        }
    };
    return conf;
}
Also used : Enumeration(java.util.Enumeration) IteratorEnumeration(org.apache.commons.collections.iterators.IteratorEnumeration) HashMap(java.util.HashMap) IteratorEnumeration(org.apache.commons.collections.iterators.IteratorEnumeration) ZkController(org.apache.solr.cloud.ZkController) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig) SolrException(org.apache.solr.common.SolrException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

SolrException (org.apache.solr.common.SolrException)617 IOException (java.io.IOException)172 ArrayList (java.util.ArrayList)100 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)80 NamedList (org.apache.solr.common.util.NamedList)79 HashMap (java.util.HashMap)75 Map (java.util.Map)70 SolrParams (org.apache.solr.common.params.SolrParams)64 KeeperException (org.apache.zookeeper.KeeperException)60 Test (org.junit.Test)55 Replica (org.apache.solr.common.cloud.Replica)48 Slice (org.apache.solr.common.cloud.Slice)45 DocCollection (org.apache.solr.common.cloud.DocCollection)41 SolrInputDocument (org.apache.solr.common.SolrInputDocument)39 SchemaField (org.apache.solr.schema.SchemaField)39 List (java.util.List)38 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)38 SolrServerException (org.apache.solr.client.solrj.SolrServerException)37 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)34 SolrCore (org.apache.solr.core.SolrCore)33