Java Code Examples for org.apache.solr.common.params.CollectionParams#CollectionAction

The following examples show how to use org.apache.solr.common.params.CollectionParams#CollectionAction . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCollectionAPIs.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp,
                  CoreContainer cores,
                  CollectionParams.CollectionAction action,
                  CollectionOperation operation) throws Exception {
  Map<String, Object> result = null;
  if (action == CollectionParams.CollectionAction.COLLECTIONPROP) {
    //Fake this action, since we don't want to write to ZooKeeper in this test
    result = new HashMap<>();
    result.put(NAME, req.getParams().required().get(NAME));
    result.put(PROPERTY_NAME, req.getParams().required().get(PROPERTY_NAME));
    result.put(PROPERTY_VALUE, req.getParams().required().get(PROPERTY_VALUE));
  } else {
    result = operation.execute(req, rsp, this);
  }
  if (result != null) {
    result.put(QUEUE_OPERATION, operation.action.toLower());
    rsp.add(ZkNodeProps.class.getName(), new ZkNodeProps(result));
  }
}
 
Example 2
Source File: NodeAddedTrigger.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(SolrResourceLoader loader, SolrCloudManager cloudManager, Map<String, Object> properties) throws TriggerValidationException {
  super.configure(loader, cloudManager, properties);
  preferredOp = (String) properties.getOrDefault(PREFERRED_OP, CollectionParams.CollectionAction.MOVEREPLICA.toLower());
  preferredOp = preferredOp.toLowerCase(Locale.ROOT);
  String replicaTypeStr = (String) properties.getOrDefault(REPLICA_TYPE, Replica.Type.NRT.name());
  // verify
  try {
    replicaType = Replica.Type.valueOf(replicaTypeStr);
  } catch (IllegalArgumentException | NullPointerException e) {
    throw new TriggerValidationException("Unsupported replicaType=" + replicaTypeStr + " specified for node added trigger");
  }

  CollectionParams.CollectionAction action = CollectionParams.CollectionAction.get(preferredOp);
  switch (action) {
    case ADDREPLICA:
    case MOVEREPLICA:
    case NONE:
      break;
    default:
      throw new TriggerValidationException("Unsupported preferredOperation=" + preferredOp + " specified for node added trigger");
  }
}
 
Example 3
Source File: ComputePlanAction.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Suggester getNodeAddedSuggester(SolrCloudManager cloudManager, Policy.Session session, TriggerEvent event) throws IOException {
  String preferredOp = (String) event.getProperty(AutoScalingParams.PREFERRED_OP, CollectionParams.CollectionAction.MOVEREPLICA.toLower());
  Replica.Type replicaType = (Replica.Type) event.getProperty(AutoScalingParams.REPLICA_TYPE, Replica.Type.NRT);
  CollectionParams.CollectionAction action = CollectionParams.CollectionAction.get(preferredOp);

  Suggester suggester = session.getSuggester(action)
      .hint(Suggester.Hint.TARGET_NODE, event.getProperty(NODE_NAMES));
  switch (action) {
    case ADDREPLICA:
      // add all collection/shard pairs and let policy engine figure out which one
      // to place on the target node
      ClusterState clusterState = cloudManager.getClusterStateProvider().getClusterState();
      Set<Pair<String, String>> collShards = new HashSet<>();
      clusterState.getCollectionStates().entrySet().stream()
              .filter(e -> collectionsPredicate.test(e.getKey()))
              .forEach(entry -> {
                DocCollection docCollection = entry.getValue().get();
                if (docCollection != null) {
                  docCollection.getActiveSlices().stream()
                          .map(slice -> new Pair<>(entry.getKey(), slice.getName()))
                          .forEach(collShards::add);
                }
              });
      suggester.hint(Suggester.Hint.COLL_SHARD, collShards);
      suggester.hint(Suggester.Hint.REPLICATYPE, replicaType);
      break;
    case MOVEREPLICA:
    case NONE:
      break;
    default:
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
          "Unsupported preferredOperation=" + preferredOp + " for node added event");
  }
  return suggester;
}
 
Example 4
Source File: ComputePlanAction.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Suggester getNodeLostSuggester(SolrCloudManager cloudManager, Policy.Session session, TriggerEvent event) throws IOException {
  String preferredOp = (String) event.getProperty(AutoScalingParams.PREFERRED_OP, CollectionParams.CollectionAction.MOVEREPLICA.toLower());
  CollectionParams.CollectionAction action = CollectionParams.CollectionAction.get(preferredOp);
  switch (action) {
    case MOVEREPLICA:
      Suggester s = session.getSuggester(action)
              .hint(Suggester.Hint.SRC_NODE, event.getProperty(NODE_NAMES));
      if (applyCollectionHints(cloudManager, s) == 0) return NoneSuggester.get(session);
      return s;
    case DELETENODE:
      int start = (Integer)event.getProperty(START, 0);
      @SuppressWarnings({"unchecked"})
      List<String> srcNodes = (List<String>) event.getProperty(NODE_NAMES);
      if (srcNodes.isEmpty() || start >= srcNodes.size()) {
        return NoneSuggester.get(session);
      }
      String sourceNode = srcNodes.get(start);
      s = session.getSuggester(action)
              .hint(Suggester.Hint.SRC_NODE, event.getProperty(NODE_NAMES));
      if (applyCollectionHints(cloudManager, s) == 0) return NoneSuggester.get(session);
      s.hint(Suggester.Hint.SRC_NODE, Collections.singletonList(sourceNode));
      event.getProperties().put(START, ++start);
      return s;
    case NONE:
      return NoneSuggester.get(session);
    default:
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unsupported preferredOperation: " + action.toLower() + " specified for node lost trigger");
  }
}
 
Example 5
Source File: TriggerEvent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public static Op fromMap(Map<String, Object> map) {
  if (!map.containsKey("action")) {
    return null;
  }
  CollectionParams.CollectionAction action = CollectionParams.CollectionAction.get(String.valueOf(map.get("action")));
  if (action == null) {
    return null;
  }
  Op op = new Op(action);
  Map<Object, Object> hints = (Map<Object, Object>)map.get("hints");
  if (hints != null && !hints.isEmpty()) {
    hints.forEach((k, v) ->  {
      Suggester.Hint h = Suggester.Hint.get(k.toString());
      if (h == null) {
        return;
      }
      if (!(v instanceof Collection)) {
        v = Collections.singletonList(v);
      }
      ((Collection)v).forEach(vv -> {
        if (vv instanceof Map) {
          // maybe it's a Pair?
          Map<String, Object> m = (Map<String, Object>)vv;
          if (m.containsKey("first") && m.containsKey("second")) {
            Pair p = Pair.parse(m);
            if (p != null) {
              op.addHint(h, p);
              return;
            }
          }
        }
        op.addHint(h, vv);
      });
    });
  }
  return op;
}
 
Example 6
Source File: CollectionsHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: LockTree.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public Lock lock(CollectionParams.CollectionAction action, List<String> path) {
  if (action.lockLevel == LockLevel.NONE) return FREELOCK;
  synchronized (LockTree.this) {
    if (root.isBusy(action.lockLevel, path)) return null;
    Lock lockObject = LockTree.this.root.lock(action.lockLevel, path);
    if (lockObject == null) root.markBusy(action.lockLevel, path);
    return lockObject;
  }
}
 
Example 8
Source File: Overseer.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private List<ZkWriteCommand> processMessage(ClusterState clusterState,
    final ZkNodeProps message, final String operation) {
  CollectionParams.CollectionAction collectionAction = CollectionParams.CollectionAction.get(operation);
  if (collectionAction != null) {
    switch (collectionAction) {
      case CREATE:
        return Collections.singletonList(new ClusterStateMutator(getSolrCloudManager()).createCollection(clusterState, message));
      case DELETE:
        return Collections.singletonList(new ClusterStateMutator(getSolrCloudManager()).deleteCollection(clusterState, message));
      case CREATESHARD:
        return Collections.singletonList(new CollectionMutator(getSolrCloudManager()).createShard(clusterState, message));
      case DELETESHARD:
        return Collections.singletonList(new CollectionMutator(getSolrCloudManager()).deleteShard(clusterState, message));
      case ADDREPLICA:
        return Collections.singletonList(new SliceMutator(getSolrCloudManager()).addReplica(clusterState, message));
      case ADDREPLICAPROP:
        return Collections.singletonList(new ReplicaMutator(getSolrCloudManager()).addReplicaProperty(clusterState, message));
      case DELETEREPLICAPROP:
        return Collections.singletonList(new ReplicaMutator(getSolrCloudManager()).deleteReplicaProperty(clusterState, message));
      case BALANCESHARDUNIQUE:
        ExclusiveSliceProperty dProp = new ExclusiveSliceProperty(clusterState, message);
        if (dProp.balanceProperty()) {
          String collName = message.getStr(ZkStateReader.COLLECTION_PROP);
          return Collections.singletonList(new ZkWriteCommand(collName, dProp.getDocCollection()));
        }
        break;
      case MODIFYCOLLECTION:
        CollectionsHandler.verifyRuleParams(zkController.getCoreContainer() ,message.getProperties());
        return Collections.singletonList(new CollectionMutator(getSolrCloudManager()).modifyCollection(clusterState,message));
      default:
        throw new RuntimeException("unknown operation:" + operation
            + " contents:" + message.getProperties());
    }
  } else {
    OverseerAction overseerAction = OverseerAction.get(operation);
    if (overseerAction == null) {
      throw new RuntimeException("unknown operation:" + operation + " contents:" + message.getProperties());
    }
    switch (overseerAction) {
      case STATE:
        return Collections.singletonList(new ReplicaMutator(getSolrCloudManager()).setState(clusterState, message));
      case LEADER:
        return Collections.singletonList(new SliceMutator(getSolrCloudManager()).setShardLeader(clusterState, message));
      case DELETECORE:
        return Collections.singletonList(new SliceMutator(getSolrCloudManager()).removeReplica(clusterState, message));
      case ADDROUTINGRULE:
        return Collections.singletonList(new SliceMutator(getSolrCloudManager()).addRoutingRule(clusterState, message));
      case REMOVEROUTINGRULE:
        return Collections.singletonList(new SliceMutator(getSolrCloudManager()).removeRoutingRule(clusterState, message));
      case UPDATESHARDSTATE:
        return Collections.singletonList(new SliceMutator(getSolrCloudManager()).updateShardState(clusterState, message));
      case QUIT:
        if (myId.equals(message.get(ID))) {
          if (log.isInfoEnabled()) {
            log.info("Quit command received {} {}", message, LeaderElector.getNodeName(myId));
          }
          overseerCollectionConfigSetProcessor.close();
          close();
        } else {
          log.warn("Overseer received wrong QUIT message {}", message);
        }
        break;
      case DOWNNODE:
        return new NodeMutator().downNode(clusterState, message);
      default:
        throw new RuntimeException("unknown operation:" + operation + " contents:" + message.getProperties());
    }
  }

  return Collections.singletonList(ZkStateWriter.NO_OP);
}
 
Example 9
Source File: TriggerEvent.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public CollectionParams.CollectionAction getAction() {
  return action;
}
 
Example 10
Source File: TriggerEvent.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public Op(CollectionParams.CollectionAction action, Suggester.Hint hint, Object hintValue) {
  this.action = action;
  addHint(hint, hintValue);
}
 
Example 11
Source File: TriggerEvent.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public Op(CollectionParams.CollectionAction action) {
  this.action = action;
}
 
Example 12
Source File: ComputePlanAction.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
protected Suggester getSuggester(Policy.Session session, TriggerEvent event, ActionContext context, SolrCloudManager cloudManager) throws IOException {
  Suggester suggester;
  switch (event.getEventType()) {
    case NODEADDED:
      suggester = getNodeAddedSuggester(cloudManager, session, event);
      break;
    case NODELOST:
      suggester = getNodeLostSuggester(cloudManager, session, event);
      break;
    case SEARCHRATE:
    case METRIC:
    case INDEXSIZE:
      @SuppressWarnings({"unchecked"})
      List<TriggerEvent.Op> ops = (List<TriggerEvent.Op>)event.getProperty(TriggerEvent.REQUESTED_OPS, Collections.emptyList());
      int start = (Integer)event.getProperty(START, 0);
      if (ops.isEmpty() || start >= ops.size()) {
        return NoneSuggester.get(session);
      }
      TriggerEvent.Op op = ops.get(start);
      suggester = session.getSuggester(op.getAction());
      if (suggester instanceof UnsupportedSuggester) {
        @SuppressWarnings({"unchecked"})
        List<TriggerEvent.Op> unsupportedOps = (List<TriggerEvent.Op>)context.getProperties().computeIfAbsent(TriggerEvent.UNSUPPORTED_OPS, k -> new ArrayList<TriggerEvent.Op>());
        unsupportedOps.add(op);
      }
      for (Map.Entry<Suggester.Hint, Object> e : op.getHints().entrySet()) {
        suggester = suggester.hint(e.getKey(), e.getValue());
      }
      if (applyCollectionHints(cloudManager, suggester) == 0) return NoneSuggester.get(session);
      suggester = suggester.forceOperation(true);
      event.getProperties().put(START, ++start);
      break;
    case SCHEDULED:
      String preferredOp = (String) event.getProperty(AutoScalingParams.PREFERRED_OP, CollectionParams.CollectionAction.MOVEREPLICA.toLower());
      CollectionParams.CollectionAction action = CollectionParams.CollectionAction.get(preferredOp);
      suggester = session.getSuggester(action);
      if (applyCollectionHints(cloudManager, suggester) == 0) return NoneSuggester.get(session);
      break;
    default:
      throw new UnsupportedOperationException("No support for events other than nodeAdded, nodeLost, searchRate, metric, scheduled and indexSize. Received: " + event.getEventType());
  }
  return suggester;
}
 
Example 13
Source File: DeleteNodeSuggester.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public CollectionParams.CollectionAction getAction() {
  return CollectionParams.CollectionAction.DELETENODE;
}
 
Example 14
Source File: Suggester.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public CollectionParams.CollectionAction getAction() {
  return null;
}
 
Example 15
Source File: AddReplicaSuggester.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public CollectionParams.CollectionAction getAction() {
  return ADDREPLICA;
}
 
Example 16
Source File: UnsupportedSuggester.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public CollectionParams.CollectionAction getAction() {
  return action;
}
 
Example 17
Source File: UnsupportedSuggester.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public UnsupportedSuggester(CollectionParams.CollectionAction action) {
  this.action = action;
}
 
Example 18
Source File: UnsupportedSuggester.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public static UnsupportedSuggester get(Policy.Session session, CollectionParams.CollectionAction action) {
  UnsupportedSuggester suggester = new UnsupportedSuggester(action);
  suggester._init(session);
  return suggester;
}
 
Example 19
Source File: MoveReplicaSuggester.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public CollectionParams.CollectionAction getAction() {
  return MOVEREPLICA;
}
 
Example 20
Source File: SplitShardSuggester.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public CollectionParams.CollectionAction getAction() {
  return CollectionParams.CollectionAction.SPLITSHARD;
}