Java Code Examples for org.apache.solr.client.solrj.SolrServerException#getMessage()

The following examples show how to use org.apache.solr.client.solrj.SolrServerException#getMessage() . 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: IndexFetcher.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the latest commit version and generation from the master
 */
@SuppressWarnings({"unchecked", "rawtypes"})
NamedList getLatestVersion() throws IOException {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(COMMAND, CMD_INDEX_VERSION);
  params.set(CommonParams.WT, JAVABIN);
  params.set(CommonParams.QT, ReplicationHandler.PATH);
  QueryRequest req = new QueryRequest(params);

  // TODO modify to use shardhandler
  try (HttpSolrClient client = new Builder(masterUrl)
      .withHttpClient(myHttpClient)
      .withConnectionTimeout(connTimeout)
      .withSocketTimeout(soTimeout)
      .build()) {

    return client.request(req);
  } catch (SolrServerException e) {
    throw new SolrException(ErrorCode.SERVER_ERROR, e.getMessage(), e);
  }
}
 
Example 2
Source File: SolrCLI.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected void deleteCore(CommandLine cli, CloseableHttpClient httpClient, String solrUrl) throws Exception {
  String coreName = cli.getOptionValue(NAME);
  String deleteCoreUrl =
      String.format(Locale.ROOT,
          "%sadmin/cores?action=UNLOAD&core=%s&deleteIndex=true&deleteDataDir=true&deleteInstanceDir=true",
          solrUrl,
          coreName);

  echo("\nDeleting core '" + coreName + "' using command:\n" + deleteCoreUrl + "\n");

  Map<String,Object> json = null;
  try {
    json = getJson(deleteCoreUrl);
  } catch (SolrServerException sse) {
    throw new Exception("Failed to delete core '"+coreName+"' due to: "+sse.getMessage());
  }

  if (json != null) {
    CharArr arr = new CharArr();
    new JSONWriter(arr, 2).write(json);
    echoIfVerbose(arr.toString(), cli);
    echoIfVerbose("\n", cli);
  }
}
 
Example 3
Source File: MtasSolrTestSearchConsistency.java    From mtas with Apache License 2.0 6 votes vote down vote up
/**
 * Cql query parser.
 *
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 */
@org.junit.Test
public void cqlQueryParser() throws IOException {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("q",
      "{!mtas_cql field=\"mtas\" query=\"[pos=\\\"ADJ\\\"]{2}[pos=\\\"N\\\"]\"}");
  try {
    QueryResponse qResp1 = server.query("collection1", params);
    QueryResponse qResp2 = server.query("collection2", params);
    QueryResponse qResp3 = server.query("collection3", params);
    SolrDocumentList docList1 = qResp1.getResults();
    SolrDocumentList docList2 = qResp2.getResults();
    SolrDocumentList docList3 = qResp3.getResults();
    assertFalse(docList1.isEmpty());
    assertEquals(docList1.size(), (long) docList2.size() + docList3.size());
  } catch (SolrServerException e) {
    throw new IOException(e.getMessage(), e);
  }
}
 
Example 4
Source File: MtasSolrTestSearchConsistency.java    From mtas with Apache License 2.0 6 votes vote down vote up
/**
 * Cql query parser filter.
 *
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 */
@org.junit.Test
public void cqlQueryParserFilter() throws IOException {
  ModifiableSolrParams params1 = new ModifiableSolrParams();
  ModifiableSolrParams params2 = new ModifiableSolrParams();
  params1.set("q",
      "{!mtas_cql field=\"mtas\" query=\"[pos=\\\"ADJ\\\"]{2}[pos=\\\"N\\\"]\"}");
  params2.set("q", "*");
  params2.set("fq",
      "{!mtas_cql field=\"mtas\" query=\"[pos=\\\"ADJ\\\"]{2}[pos=\\\"N\\\"]\"}");
  try {
    QueryResponse qResp1 = server.query("collection1", params1);
    QueryResponse qResp2 = server.query("collection1", params2);
    SolrDocumentList docList1 = qResp1.getResults();
    SolrDocumentList docList2 = qResp2.getResults();
    assertFalse(docList1.isEmpty());
    assertEquals(docList1.size(), docList2.size());
  } catch (SolrServerException e) {
    throw new IOException(e.getMessage(), e);
  }
}
 
Example 5
Source File: SolrCLI.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
protected void runCloudTool(CloudSolrClient cloudSolrClient, CommandLine cli) throws Exception {

      Set<String> liveNodes = cloudSolrClient.getZkStateReader().getClusterState().getLiveNodes();
      if (liveNodes.isEmpty())
        throw new IllegalStateException("No live nodes found! Cannot create a collection until " +
            "there is at least 1 live node in the cluster.");

      String baseUrl = cli.getOptionValue("solrUrl");
      if (baseUrl == null) {
        String firstLiveNode = liveNodes.iterator().next();
        baseUrl = cloudSolrClient.getZkStateReader().getBaseUrlForNodeName(firstLiveNode);
      }

      String collectionName = cli.getOptionValue(NAME);

      // build a URL to create the collection
      int numShards = optionAsInt(cli, "shards", 1);
      int replicationFactor = optionAsInt(cli, "replicationFactor", 1);
      int maxShardsPerNode = -1;

      if (cli.hasOption("maxShardsPerNode")) {
        maxShardsPerNode = Integer.parseInt(cli.getOptionValue("maxShardsPerNode"));
      }

      String confname = cli.getOptionValue("confname");
      String confdir = cli.getOptionValue("confdir");
      String configsetsDir = cli.getOptionValue("configsetsDir");

      boolean configExistsInZk = confname != null && !"".equals(confname.trim()) &&
          cloudSolrClient.getZkStateReader().getZkClient().exists("/configs/" + confname, true);

      if (CollectionAdminParams.SYSTEM_COLL.equals(collectionName)) {
        //do nothing
      } else if (configExistsInZk) {
        echo("Re-using existing configuration directory "+confname);
      } else if (confdir != null && !"".equals(confdir.trim())){
        if (confname == null || "".equals(confname.trim())) {
          confname = collectionName;
        }
        Path confPath = ZkConfigManager.getConfigsetPath(confdir,
            configsetsDir);

        echoIfVerbose("Uploading " + confPath.toAbsolutePath().toString() +
            " for config " + confname + " to ZooKeeper at " + cloudSolrClient.getZkHost(), cli);
        ((ZkClientClusterStateProvider) cloudSolrClient.getClusterStateProvider()).uploadConfig(confPath, confname);
      }

      // since creating a collection is a heavy-weight operation, check for existence first
      String collectionListUrl = baseUrl+"/admin/collections?action=list";
      if (safeCheckCollectionExists(collectionListUrl, collectionName)) {
        throw new IllegalStateException("\nCollection '"+collectionName+
            "' already exists!\nChecked collection existence using Collections API command:\n"+
            collectionListUrl);
      }

      // doesn't seem to exist ... try to create
      String createCollectionUrl =
          String.format(Locale.ROOT,
              "%s/admin/collections?action=CREATE&name=%s&numShards=%d&replicationFactor=%d&maxShardsPerNode=%d",
              baseUrl,
              collectionName,
              numShards,
              replicationFactor,
              maxShardsPerNode);
      if (confname != null && !"".equals(confname.trim())) {
        createCollectionUrl = createCollectionUrl + String.format(Locale.ROOT, "&collection.configName=%s", confname);
      }

      echoIfVerbose("\nCreating new collection '"+collectionName+"' using command:\n"+createCollectionUrl+"\n", cli);

      Map<String,Object> json = null;
      try {
        json = getJson(createCollectionUrl);
      } catch (SolrServerException sse) {
        throw new Exception("Failed to create collection '"+collectionName+"' due to: "+sse.getMessage());
      }

      if (cli.hasOption("verbose")) {
        CharArr arr = new CharArr();
        new JSONWriter(arr, 2).write(json);
        echo(arr.toString());
      } else {
        String endMessage = String.format(Locale.ROOT, "Created collection '%s' with %d shard(s), %d replica(s)",
            collectionName, numShards, replicationFactor);
        if (confname != null && !"".equals(confname.trim())) {
          endMessage += String.format(Locale.ROOT, " with config-set '%s'", confname);
        }

        echo(endMessage);
      }
    }