Java Code Examples for org.apache.solr.client.solrj.SolrRequest#getParams()

The following examples show how to use org.apache.solr.client.solrj.SolrRequest#getParams() . 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: Http2SolrClient.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
boolean belongToThisStream(@SuppressWarnings({"rawtypes"})SolrRequest solrRequest, String collection) {
  ModifiableSolrParams solrParams = new ModifiableSolrParams(solrRequest.getParams());
  if (!origParams.toNamedList().equals(solrParams.toNamedList()) || !StringUtils.equals(origCollection, collection)) {
    return false;
  }
  return true;
}
 
Example 2
Source File: DelegationTokenHttpSolrClient.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected HttpRequestBase createMethod(@SuppressWarnings({"rawtypes"})final SolrRequest request, String collection) throws IOException, SolrServerException {
  SolrParams params = request.getParams();
  if (params != null && params.getParams(DELEGATION_TOKEN_PARAM) != null) {
    throw new IllegalArgumentException(DELEGATION_TOKEN_PARAM + " parameter not supported");
  }
  return super.createMethod(request, collection);
}
 
Example 3
Source File: SystemLogListener.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes"})
private void addOperations(SolrInputDocument doc, List<SolrRequest> operations) {
  if (operations == null || operations.isEmpty()) {
    return;
  }
  Set<String> collections = new HashSet<>();
  for (SolrRequest req : operations) {
    SolrParams params = req.getParams();
    if (params == null) {
      continue;
    }
    if (params.get(CollectionAdminParams.COLLECTION) != null) {
      collections.add(params.get(CollectionAdminParams.COLLECTION));
    }
    // build a whitespace-separated param string
    StringJoiner paramJoiner = new StringJoiner(" ");
    paramJoiner.setEmptyValue("");
    for (Iterator<String> it = params.getParameterNamesIterator(); it.hasNext(); ) {
      final String name = it.next();
      final String [] values = params.getParams(name);
      for (String value : values) {
        paramJoiner.add(name + "=" + value);
      }
    }
    String paramString = paramJoiner.toString();
    if (!paramString.isEmpty()) {
      doc.addField("operations.params_ts", paramString);
    }
  }
  if (!collections.isEmpty()) {
    doc.addField(COLLECTIONS_FIELD, collections);
  }
}
 
Example 4
Source File: LBSolrClient.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * @return time allowed in nanos, returns -1 if no time_allowed is specified.
 */
private long getTimeAllowedInNanos(@SuppressWarnings({"rawtypes"})final SolrRequest req) {
  SolrParams reqParams = req.getParams();
  return reqParams == null ? -1 :
      TimeUnit.NANOSECONDS.convert(reqParams.getInt(CommonParams.TIME_ALLOWED, -1), TimeUnit.MILLISECONDS);
}
 
Example 5
Source File: SimScenario.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(SimScenario scenario) throws Exception {
  @SuppressWarnings({"unchecked"})
  List<Suggester.SuggestionInfo> suggestions = (List<Suggester.SuggestionInfo>) scenario.context.getOrDefault(SUGGESTIONS_CTX_PROP, Collections.emptyList());
  int unresolvedCount = 0;
  for (Suggester.SuggestionInfo suggestion : suggestions) {
    @SuppressWarnings({"rawtypes"})
    SolrRequest operation = suggestion.getOperation();
    if (operation == null) {
      unresolvedCount++;
      if (suggestion.getViolation() == null) {
        log.error("       -- ignoring suggestion without violation and without operation: {}", suggestion);
      }
      continue;
    }
    SolrParams params = operation.getParams();
    if (operation instanceof V2Request) {
      params = SimUtils.v2AdminRequestToV1Params((V2Request)operation);
    }
    Map<String, Object> paramsMap = new LinkedHashMap<>();
    params.toMap(paramsMap);
    ReplicaInfo info = scenario.cluster.getSimClusterStateProvider().simGetReplicaInfo(
        params.get(CollectionAdminParams.COLLECTION), params.get("replica"));
    if (info == null) {
      log.error("Could not find ReplicaInfo for params: {}", params);
    } else if (scenario.verbose) {
      paramsMap.put("replicaInfo", info);
    } else if (info.getVariable(Variable.Type.CORE_IDX.tagName) != null) {
      paramsMap.put(Variable.Type.CORE_IDX.tagName, info.getVariable(Variable.Type.CORE_IDX.tagName));
    }
    try {
      scenario.cluster.request(operation);
    } catch (Exception e) {
      log.error("Aborting - error executing suggestion {}", suggestion, e);
      break;
    }
  }
  if (suggestions.size() > 0 && unresolvedCount == suggestions.size()) {
    log.info("        -- aborting simulation, only {} unresolved violations remain.", unresolvedCount);
    scenario.abortLoop = true;
  }
}
 
Example 6
Source File: ScheduledTriggerIntegrationTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
// commented 15-Sep-2018 @LuceneTestCase.BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 2-Aug-2018
// commented out on: 17-Feb-2019   @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 14-Oct-2018
public void testScheduledTrigger() throws Exception {
  CloudSolrClient solrClient = cluster.getSolrClient();

  // this collection will place 2 cores on 1st node and 1 core on 2nd node
  String collectionName = "testScheduledTrigger";
  CollectionAdminRequest.createCollection(collectionName, 1, 3)
      .setMaxShardsPerNode(5).process(solrClient);
  
  cluster.waitForActiveCollection(collectionName, 1, 3);

  // create a policy which allows only 1 core per node thereby creating a violation for the above collection
  String setClusterPolicy = "{\n" +
      "  \"set-cluster-policy\" : [\n" +
      "    {\"cores\" : \"<2\", \"node\" : \"#EACH\"}\n" +
      "  ]\n" +
      "}";
  @SuppressWarnings({"rawtypes"})
  SolrRequest req = AutoScalingRequest.create(SolrRequest.METHOD.POST, setClusterPolicy);
  NamedList<Object> response = solrClient.request(req);
  assertEquals(response.get("result").toString(), "success");

  // start a new node which can be used to balance the cluster as per policy
  JettySolrRunner newNode = cluster.startJettySolrRunner();
  cluster.waitForAllNodes(30);

  String setTriggerCommand = "{" +
      "'set-trigger' : {" +
      "'name' : 'sched_trigger_integration1'," +
      "'event' : 'scheduled'," +
      "'startTime' : '" + new Date().toInstant().toString() + "'" +
      "'every' : '+3SECONDS'" +
      "'actions' : [" +
      "{'name' : 'compute','class':'" + ComputePlanAction.class.getName() + "'}," +
      "{'name' : 'execute','class':'" + ExecutePlanAction.class.getName() + "'}," +
      "{'name' : 'recorder', 'class': '" + ContextPropertiesRecorderAction.class.getName() + "'}" +
      "]}}";
  req = AutoScalingRequest.create(SolrRequest.METHOD.POST, setTriggerCommand);
  response = solrClient.request(req);
  assertEquals(response.get("result").toString(), "success");

  assertTrue("ScheduledTrigger did not fire in time", triggerFiredLatch.await(45, TimeUnit.SECONDS));
  assertEquals(1, events.size());
  Map<String, Object> actionContextProps = actionContextPropertiesRef.get();
  assertNotNull(actionContextProps);
  TriggerEvent event = events.iterator().next();
  @SuppressWarnings({"unchecked", "rawtypes"})
  List<SolrRequest> operations = (List<SolrRequest>) actionContextProps.get("operations");
  assertNotNull(operations);
  assertEquals(1, operations.size());
  for (@SuppressWarnings({"rawtypes"})SolrRequest operation : operations) {
    SolrParams params = operation.getParams();
    assertEquals(newNode.getNodeName(), params.get("targetNode"));
  }
}