Search in sources :

Example 1 with CollectionAction

use of org.apache.solr.common.params.CollectionParams.CollectionAction in project lucene-solr by apache.

the class CollectionsHandler method getPermissionName.

@Override
public PermissionNameProvider.Name getPermissionName(AuthorizationContext ctx) {
    String action = ctx.getParams().get("action");
    if (action == null)
        return PermissionNameProvider.Name.COLL_READ_PERM;
    CollectionParams.CollectionAction collectionAction = CollectionParams.CollectionAction.get(action);
    if (collectionAction == null)
        return null;
    return collectionAction.isWrite ? PermissionNameProvider.Name.COLL_EDIT_PERM : PermissionNameProvider.Name.COLL_READ_PERM;
}
Also used : CollectionParams(org.apache.solr.common.params.CollectionParams) CollectionAction(org.apache.solr.common.params.CollectionParams.CollectionAction) StrUtils.formatString(org.apache.solr.common.util.StrUtils.formatString)

Example 2 with CollectionAction

use of org.apache.solr.common.params.CollectionParams.CollectionAction in project lucene-solr by apache.

the class OverseerCollectionMessageHandler method processMessage.

@Override
@SuppressWarnings("unchecked")
public SolrResponse processMessage(ZkNodeProps message, String operation) {
    log.debug("OverseerCollectionMessageHandler.processMessage : " + operation + " , " + message.toString());
    NamedList results = new NamedList();
    try {
        CollectionAction action = getCollectionAction(operation);
        Cmd command = commandMap.get(action);
        if (command != null) {
            command.call(zkStateReader.getClusterState(), message, results);
        } else {
            throw new SolrException(ErrorCode.BAD_REQUEST, "Unknown operation:" + operation);
        }
    } catch (Exception e) {
        String collName = message.getStr("collection");
        if (collName == null)
            collName = message.getStr(NAME);
        if (collName == null) {
            SolrException.log(log, "Operation " + operation + " failed", e);
        } else {
            SolrException.log(log, "Collection: " + collName + " operation: " + operation + " failed", e);
        }
        results.add("Operation " + operation + " caused exception:", e);
        SimpleOrderedMap nl = new SimpleOrderedMap();
        nl.add("msg", e.getMessage());
        nl.add("rspCode", e instanceof SolrException ? ((SolrException) e).code() : -1);
        results.add("exception", nl);
    }
    return new OverseerSolrResponse(results);
}
Also used : NamedList(org.apache.solr.common.util.NamedList) CollectionAction(org.apache.solr.common.params.CollectionParams.CollectionAction) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) SolrException(org.apache.solr.common.SolrException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with CollectionAction

use of org.apache.solr.common.params.CollectionParams.CollectionAction in project lucene-solr by apache.

the class TestLockTree method testLocks.

public void testLocks() throws Exception {
    LockTree lockTree = new LockTree();
    Lock coll1Lock = lockTree.getSession().lock(CollectionAction.CREATE, Arrays.asList("coll1"));
    assertNotNull(coll1Lock);
    assertNull("Should not be able to lock coll1/shard1", lockTree.getSession().lock(CollectionAction.BALANCESHARDUNIQUE, Arrays.asList("coll1", "shard1")));
    assertNull(lockTree.getSession().lock(ADDREPLICAPROP, Arrays.asList("coll1", "shard1", "core_node2")));
    coll1Lock.unlock();
    Lock shard1Lock = lockTree.getSession().lock(CollectionAction.BALANCESHARDUNIQUE, Arrays.asList("coll1", "shard1"));
    assertNotNull(shard1Lock);
    shard1Lock.unlock();
    Lock replica1Lock = lockTree.getSession().lock(ADDREPLICAPROP, Arrays.asList("coll1", "shard1", "core_node2"));
    assertNotNull(replica1Lock);
    List<Pair<CollectionAction, List<String>>> operations = new ArrayList<>();
    operations.add(new Pair<>(ADDREPLICAPROP, Arrays.asList("coll1", "shard1", "core_node2")));
    operations.add(new Pair<>(MODIFYCOLLECTION, Arrays.asList("coll1")));
    operations.add(new Pair<>(SPLITSHARD, Arrays.asList("coll1", "shard1")));
    operations.add(new Pair<>(SPLITSHARD, Arrays.asList("coll2", "shard2")));
    operations.add(new Pair<>(MODIFYCOLLECTION, Arrays.asList("coll2")));
    operations.add(new Pair<>(DELETEREPLICA, Arrays.asList("coll2", "shard1")));
    List<Set<String>> orderOfExecution = Arrays.asList(ImmutableSet.of("coll1/shard1/core_node2", "coll2/shard2"), ImmutableSet.of("coll1", "coll2"), ImmutableSet.of("coll1/shard1", "coll2/shard1"));
    lockTree = new LockTree();
    for (int counter = 0; counter < orderOfExecution.size(); counter++) {
        LockTree.Session session = lockTree.getSession();
        List<Pair<CollectionAction, List<String>>> completedOps = new CopyOnWriteArrayList<>();
        List<Lock> locks = new CopyOnWriteArrayList<>();
        List<Thread> threads = new ArrayList<>();
        for (int i = 0; i < operations.size(); i++) {
            Pair<CollectionAction, List<String>> operation = operations.get(i);
            final Lock lock = session.lock(operation.first(), operation.second());
            if (lock != null) {
                Thread thread = new Thread(getRunnable(completedOps, operation, locks, lock));
                threads.add(thread);
                thread.start();
            }
        }
        for (Thread thread : threads) thread.join();
        if (locks.isEmpty())
            throw new RuntimeException("Could not attain lock for anything " + operations);
        Set<String> expectedOps = orderOfExecution.get(counter);
        log.info("counter : {} , expected : {}, actual : {}", counter, expectedOps, locks);
        assertEquals(expectedOps.size(), locks.size());
        for (Lock lock : locks) assertTrue("locks : " + locks + " expectedOps : " + expectedOps, expectedOps.contains(lock.toString()));
        locks.clear();
        for (Pair<CollectionAction, List<String>> completedOp : completedOps) {
            operations.remove(completedOp);
        }
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Lock(org.apache.solr.cloud.OverseerMessageHandler.Lock) CollectionAction(org.apache.solr.common.params.CollectionParams.CollectionAction) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Pair(org.apache.solr.common.util.Pair) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 4 with CollectionAction

use of org.apache.solr.common.params.CollectionParams.CollectionAction in project lucene-solr by apache.

the class CollectionsHandler method handleRequestBody.

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    // Make sure the cores is enabled
    CoreContainer cores = getCoreContainer();
    if (cores == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Core container instance missing");
    }
    // Make sure that the core is ZKAware
    if (!cores.isZooKeeperAware()) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "Solr instance is not running in SolrCloud mode.");
    }
    // Pick the action
    SolrParams params = req.getParams();
    String a = params.get(CoreAdminParams.ACTION);
    if (a != null) {
        CollectionAction action = CollectionAction.get(a);
        if (action == null) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown action: " + a);
        }
        CollectionOperation operation = CollectionOperation.get(action);
        log.info("Invoked Collection Action :{} with params {} and sendToOCPQueue={}", action.toLower(), req.getParamString(), operation.sendToOCPQueue);
        invokeAction(req, rsp, cores, action, operation);
    } else {
        throw new SolrException(ErrorCode.BAD_REQUEST, "action is a required param");
    }
    rsp.setHttpCaching(false);
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) CollectionAction(org.apache.solr.common.params.CollectionParams.CollectionAction) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) StrUtils.formatString(org.apache.solr.common.util.StrUtils.formatString) SolrException(org.apache.solr.common.SolrException)

Aggregations

CollectionAction (org.apache.solr.common.params.CollectionParams.CollectionAction)4 SolrException (org.apache.solr.common.SolrException)2 StrUtils.formatString (org.apache.solr.common.util.StrUtils.formatString)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 RemoteSolrException (org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException)1 Lock (org.apache.solr.cloud.OverseerMessageHandler.Lock)1 CollectionParams (org.apache.solr.common.params.CollectionParams)1 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)1 SolrParams (org.apache.solr.common.params.SolrParams)1 NamedList (org.apache.solr.common.util.NamedList)1 Pair (org.apache.solr.common.util.Pair)1 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)1 CoreContainer (org.apache.solr.core.CoreContainer)1 KeeperException (org.apache.zookeeper.KeeperException)1