Search in sources :

Example 11 with CommandOperation

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

the class RuleBasedAuthorizationPlugin method edit.

@Override
public Map<String, Object> edit(Map<String, Object> latestConf, List<CommandOperation> commands) {
    for (CommandOperation op : commands) {
        AutorizationEditOperation operation = ops.get(op.name);
        if (operation == null) {
            op.unknownOperation();
            return null;
        }
        latestConf = operation.edit(latestConf, op);
        if (latestConf == null)
            return null;
    }
    return latestConf;
}
Also used : CommandOperation(org.apache.solr.common.util.CommandOperation)

Example 12 with CommandOperation

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

the class TestCollectionAPIs method makeCall.

public static Pair<SolrQueryRequest, SolrQueryResponse> makeCall(final ApiBag apiBag, String path, final SolrRequest.METHOD method, final String payload, final CoreContainer cc) throws Exception {
    SolrParams queryParams = new MultiMapSolrParams(Collections.emptyMap());
    if (path.indexOf('?') > 0) {
        String queryStr = path.substring(path.indexOf('?') + 1);
        path = path.substring(0, path.indexOf('?'));
        queryParams = SolrRequestParsers.parseQueryString(queryStr);
    }
    final HashMap<String, String> parts = new HashMap<>();
    Api api = apiBag.lookup(path, method.toString(), parts);
    if (api == null)
        throw new RuntimeException("No handler at path :" + path);
    SolrQueryResponse rsp = new SolrQueryResponse();
    LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, queryParams) {

        @Override
        public List<CommandOperation> getCommands(boolean validateInput) {
            if (payload == null)
                return Collections.emptyList();
            return ApiBag.getCommandOperations(new StringReader(payload), api.getCommandSchema(), true);
        }

        @Override
        public Map<String, String> getPathTemplateValues() {
            return parts;
        }

        @Override
        public String getHttpMethod() {
            return method.toString();
        }
    };
    try {
        api.call(req, rsp);
    } catch (ApiBag.ExceptionWithErrObject e) {
        throw new RuntimeException(e.getMessage() + Utils.toJSONString(e.getErrs()), e);
    }
    return new Pair<>(req, rsp);
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MultiMapSolrParams(org.apache.solr.common.params.MultiMapSolrParams) HashMap(java.util.HashMap) CommandOperation(org.apache.solr.common.util.CommandOperation) ApiBag(org.apache.solr.api.ApiBag) Utils.fromJSONString(org.apache.solr.common.util.Utils.fromJSONString) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) StringReader(java.io.StringReader) SolrParams(org.apache.solr.common.params.SolrParams) MultiMapSolrParams(org.apache.solr.common.params.MultiMapSolrParams) Api(org.apache.solr.api.Api) Pair(org.apache.solr.common.util.Pair)

Example 13 with CommandOperation

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

the class SchemaManager method doOperations.

private List doOperations(List<CommandOperation> operations) throws InterruptedException, IOException, KeeperException {
    //The default timeout is 10 minutes when no BaseSolrResource.UPDATE_TIMEOUT_SECS is specified
    int timeout = req.getParams().getInt(BaseSolrResource.UPDATE_TIMEOUT_SECS, 600);
    //If BaseSolrResource.UPDATE_TIMEOUT_SECS=0 or -1 then end time then we'll try for 10 mins ( default timeout )
    if (timeout < 1) {
        timeout = 600;
    }
    TimeOut timeOut = new TimeOut(timeout, TimeUnit.SECONDS);
    SolrCore core = req.getCore();
    String errorMsg = "Unable to persist managed schema. ";
    List errors = Collections.emptyList();
    int latestVersion = -1;
    synchronized (req.getSchema().getSchemaUpdateLock()) {
        while (!timeOut.hasTimedOut()) {
            managedIndexSchema = getFreshManagedSchema(req.getCore());
            for (CommandOperation op : operations) {
                OpType opType = OpType.get(op.name);
                if (opType != null) {
                    opType.perform(op, this);
                } else {
                    op.addError("No such operation : " + op.name);
                }
            }
            errors = CommandOperation.captureErrors(operations);
            if (!errors.isEmpty())
                break;
            SolrResourceLoader loader = req.getCore().getResourceLoader();
            if (loader instanceof ZkSolrResourceLoader) {
                ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) loader;
                StringWriter sw = new StringWriter();
                try {
                    managedIndexSchema.persist(sw);
                } catch (IOException e) {
                    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "unable to serialize schema");
                //unlikely
                }
                try {
                    latestVersion = ZkController.persistConfigResourceToZooKeeper(zkLoader, managedIndexSchema.getSchemaZkVersion(), managedIndexSchema.getResourceName(), sw.toString().getBytes(StandardCharsets.UTF_8), true);
                    req.getCore().getCoreContainer().reload(req.getCore().getName());
                    break;
                } catch (ZkController.ResourceModifiedInZkException e) {
                    log.info("Schema was modified by another node. Retrying..");
                }
            } else {
                try {
                    //only for non cloud stuff
                    managedIndexSchema.persistManagedSchema(false);
                    core.setLatestSchema(managedIndexSchema);
                } catch (SolrException e) {
                    log.warn(errorMsg);
                    errors = singletonList(errorMsg + e.getMessage());
                }
                break;
            }
        }
    }
    if (req.getCore().getResourceLoader() instanceof ZkSolrResourceLoader) {
        // Don't block further schema updates while waiting for a pending update to propagate to other replicas.
        // This reduces the likelihood of a (time-limited) distributed deadlock during concurrent schema updates.
        waitForOtherReplicasToUpdate(timeOut, latestVersion);
    }
    if (errors.isEmpty() && timeOut.hasTimedOut()) {
        log.warn(errorMsg + "Timed out.");
        errors = singletonList(errorMsg + "Timed out.");
    }
    return errors;
}
Also used : TimeOut(org.apache.solr.util.TimeOut) SolrCore(org.apache.solr.core.SolrCore) CommandOperation(org.apache.solr.common.util.CommandOperation) IOException(java.io.IOException) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) StringWriter(java.io.StringWriter) ZkController(org.apache.solr.cloud.ZkController) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) SolrException(org.apache.solr.common.SolrException)

Aggregations

CommandOperation (org.apache.solr.common.util.CommandOperation)13 Map (java.util.Map)5 SolrException (org.apache.solr.common.SolrException)5 LinkedHashMap (java.util.LinkedHashMap)4 HashMap (java.util.HashMap)3 Api (org.apache.solr.api.Api)3 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 Collections.singletonList (java.util.Collections.singletonList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 List (java.util.List)2 SolrParams (org.apache.solr.common.params.SolrParams)2 ValidatingJsonMap (org.apache.solr.common.util.ValidatingJsonMap)2 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)2 File (java.io.File)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ApiBag (org.apache.solr.api.ApiBag)1