Java Code Examples for org.apache.solr.common.SolrException#getMessage()

The following examples show how to use org.apache.solr.common.SolrException#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: SolrCore.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void checkVersionFieldExistsInSchema(IndexSchema schema, CoreDescriptor coreDescriptor) {
  if (null != coreDescriptor.getCloudDescriptor()) {
    // we are evidently running in cloud mode.  
    //
    // In cloud mode, version field is required for correct consistency
    // ideally this check would be more fine grained, and individual features
    // would assert it when they initialize, but DistributedUpdateProcessor
    // is currently a big ball of wax that does more then just distributing
    // updates (ie: partial document updates), so it needs to work in no cloud
    // mode as well, and can't assert version field support on init.

    try {
      VersionInfo.getAndCheckVersionField(schema);
    } catch (SolrException e) {
      throw new SolrException(ErrorCode.SERVER_ERROR,
          "Schema will not work with SolrCloud mode: " +
              e.getMessage(), e);
    }
  }
}
 
Example 2
Source File: TestCoreDiscovery.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testDuplicateNames() throws Exception {
  setMeUp();

  // name, isLazy, loadOnStartup
  addCoreWithProps("core1", makeCoreProperties("core1", false, true));
  addCoreWithProps("core2", makeCoreProperties("core2", false, false, "name=core1"));
  SolrException thrown = expectThrows(SolrException.class, () -> {
    CoreContainer cc = null;
    try { cc = init(); }
    finally { if (cc != null) cc.shutdown(); }
  });
  final String message = thrown.getMessage();
  assertTrue("Wrong exception thrown on duplicate core names",
      message.indexOf("Found multiple cores with the name [core1]") != -1);
  assertTrue(File.separator + "core1 should have been mentioned in the message: " + message,
      message.indexOf(File.separator + "core1") != -1);
  assertTrue(File.separator + "core2 should have been mentioned in the message:" + message,
      message.indexOf(File.separator + "core2") != -1);
}
 
Example 3
Source File: SolrExceptionTranslator.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
	if (ex.getCause() instanceof SolrServerException) {
		SolrServerException solrServerException = (SolrServerException) ex.getCause();
		if (solrServerException.getCause() instanceof SolrException) {
			SolrException solrException = (SolrException) solrServerException.getCause();
			// solr 4.x moved ParseExecption from
			// org.apache.lucene.queryParser to
			// org.apache.lucene.queryparser.classic
			// therefore compare ShortClassName instead of using instanceof
			// expression
			if (solrException.getCause() != null && ClassUtils.getShortName(solrException.getCause().getClass())
					.equalsIgnoreCase("ParseException")) {
				return new InvalidDataAccessApiUsageException((solrException.getCause()).getMessage(),
						solrException.getCause());
			} else {
				ErrorCode errorCode = ErrorCode.getErrorCode(solrException.code());
				switch (errorCode) {
				case NOT_FOUND:
				case SERVICE_UNAVAILABLE:
				case SERVER_ERROR:
					return new DataAccessResourceFailureException(solrException.getMessage(), solrException);
				case FORBIDDEN:
				case UNAUTHORIZED:
					return new PermissionDeniedDataAccessException(solrException.getMessage(), solrException);
				case BAD_REQUEST:
					return new InvalidDataAccessApiUsageException(solrException.getMessage(), solrException);
				case UNKNOWN:
					return new UncategorizedSolrException(solrException.getMessage(), solrException);
				default:
					break;
				}
			}
		} else if (solrServerException.getCause() instanceof ConnectException) {
			return new DataAccessResourceFailureException(solrServerException.getCause().getMessage(),
					solrServerException.getCause());
		}
	}
	return null;
}
 
Example 4
Source File: TestCoreAdmin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidCoreNamesAreRejectedWhenCreatingCore() {
  final Create createRequest = new Create();
  SolrException e = expectThrows(SolrException.class, () -> createRequest.setCoreName("invalid$core@name"));
  final String exceptionMessage = e.getMessage();
  assertTrue(exceptionMessage.contains("Invalid core"));
  assertTrue(exceptionMessage.contains("invalid$core@name"));
  assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
 
Example 5
Source File: TestCoreAdmin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidCoreNamesAreRejectedWhenRenamingExistingCore() throws Exception {
  SolrException e = expectThrows(SolrException.class,
      () -> CoreAdminRequest.renameCore("validExistingCoreName", "invalid$core@name", null));
  final String exceptionMessage = e.getMessage();
  assertTrue(e.getMessage(), exceptionMessage.contains("Invalid core"));
  assertTrue(exceptionMessage.contains("invalid$core@name"));
  assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
 
Example 6
Source File: TestCollectionAdminRequest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
// commented out on: 24-Dec-2018   @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018
public void testInvalidCollectionNameRejectedWhenCreatingCollection() {
  final SolrException e = expectThrows(SolrException.class, () -> {
      CollectionAdminRequest.createCollection("invalid$collection@name", null, 1, 1);
    });
  final String exceptionMessage = e.getMessage();
  assertTrue(exceptionMessage.contains("Invalid collection"));
  assertTrue(exceptionMessage.contains("invalid$collection@name"));
  assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
 
Example 7
Source File: TestCollectionAdminRequest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
// commented out on: 24-Dec-2018   @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018
public void testInvalidShardNamesRejectedWhenCreatingImplicitCollection() {
  final SolrException e = expectThrows(SolrException.class, () -> {
      CollectionAdminRequest.createCollectionWithImplicitRouter("fine", "fine", "invalid$shard@name",1,0,0);
    });
  final String exceptionMessage = e.getMessage();
  assertTrue(exceptionMessage.contains("Invalid shard"));
  assertTrue(exceptionMessage.contains("invalid$shard@name"));
  assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
 
Example 8
Source File: TestCollectionAdminRequest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
// commented out on: 24-Dec-2018   @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018
public void testInvalidShardNamesRejectedWhenCallingSetShards() {
  CollectionAdminRequest.Create request = CollectionAdminRequest.createCollectionWithImplicitRouter("fine",null,"fine",1);
  final SolrException e = expectThrows(SolrException.class, () -> {
      request.setShards("invalid$shard@name");
    });
  final String exceptionMessage = e.getMessage();
  assertTrue(exceptionMessage.contains("Invalid shard"));
  assertTrue(exceptionMessage.contains("invalid$shard@name"));
  assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
 
Example 9
Source File: TestCollectionAdminRequest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
// commented out on: 24-Dec-2018   @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018
public void testInvalidAliasNameRejectedWhenCreatingAlias() {
  final SolrException e = expectThrows(SolrException.class, () -> {
      CreateAlias createAliasRequest = CollectionAdminRequest.createAlias("invalid$alias@name","ignored");
    });
  final String exceptionMessage = e.getMessage();
  assertTrue(exceptionMessage.contains("Invalid alias"));
  assertTrue(exceptionMessage.contains("invalid$alias@name"));
  assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
 
Example 10
Source File: TestCollectionAdminRequest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
// commented out on: 24-Dec-2018   @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018
public void testInvalidShardNameRejectedWhenCreatingShard() {
  final SolrException e = expectThrows(SolrException.class, () -> {
      CreateShard createShardRequest = CollectionAdminRequest.createShard("ignored","invalid$shard@name");
    });
  final String exceptionMessage = e.getMessage();
  assertTrue(exceptionMessage.contains("Invalid shard"));
  assertTrue(exceptionMessage.contains("invalid$shard@name"));
  assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
 
Example 11
Source File: AtomicUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void processAddWithRetry(AddUpdateCommand cmd, int attempts, SolrInputDocument clonedOriginalDoc) throws IOException {
  try {
    super.processAdd(cmd);
  } catch (SolrException e) {
    if (attempts++ >= MAX_ATTEMPTS) {//maximum number of attempts allowed: 25
      throw new SolrException(SERVER_ERROR,
          "Atomic update failed after multiple attempts due to " + e.getMessage());
    }
    if (e.code() == ErrorCode.CONFLICT.code) { // version conflict
      log.warn("Atomic update failed due to {} Retrying with new version .... ({})"
          , e.getMessage(), attempts);

      Long lastVersion = vinfo.lookupVersion(cmd.getIndexedId());
      // if lastVersion is null then we put -1 to assert that document must not exist
      lastVersion = lastVersion == null ? -1 : lastVersion;

      // The AtomicUpdateDocumentMerger modifies the AddUpdateCommand.solrDoc to populate the real values of the
      // modified fields. We don't want those absolute values because they are out-of-date due to the conflict
      // so we restore the original document created in processAdd method and set the right version on it
      cmd.solrDoc = clonedOriginalDoc;
      clonedOriginalDoc = clonedOriginalDoc.deepCopy(); // copy again because the old cloned ref will be modified during processAdd
      cmd.solrDoc.setField(VERSION, lastVersion);

      processAddWithRetry(cmd, attempts, clonedOriginalDoc);
    }
  }
}
 
Example 12
Source File: FieldMutatingUpdateProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Calls <code>mutate</code> on any fields identified by the selector 
 * before forwarding the command down the chain.  Any SolrExceptions 
 * thrown by <code>mutate</code> will be logged with the Field name, 
 * wrapped and re-thrown.
 */
@Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
  final SolrInputDocument doc = cmd.getSolrInputDocument();

  // make a copy we can iterate over while mutating the doc
  final Collection<String> fieldNames 
    = new ArrayList<>(doc.getFieldNames());

  for (final String fname : fieldNames) {

    if (! selector.shouldMutate(fname)) continue;
    
    final SolrInputField src = doc.get(fname);

    SolrInputField dest = null;
    try { 
      dest = mutate(src);
    } catch (SolrException e) {
      String msg = "Unable to mutate field '"+fname+"': "+e.getMessage();
      SolrException.log(log, msg, e);
      throw new SolrException(BAD_REQUEST, msg, e);
    }
    if (null == dest) {
      doc.remove(fname);
    } else {
      // semantics of what happens if dest has diff name are hard
      // we could treat it as a copy, or a rename
      // for now, don't allow it.
      if (! fname.equals(dest.getName()) ) {
        throw new SolrException(SERVER_ERROR,
                                "mutate returned field with different name: " 
                                + fname + " => " + dest.getName());
      }
      doc.put(dest.getName(), dest);
    }
  }
  super.processAdd(cmd);
}
 
Example 13
Source File: FacetProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void handleDomainChanges() throws IOException {
  if (freq.domain == null) return;

  if (null != freq.domain.explicitQueries) {
    try {
      final List<Query> domainQs = evalJSONFilterQueryStruct(fcontext, freq.domain.explicitQueries);
      if (domainQs.isEmpty()) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                                "'query' domain must not evaluate to an empty list of queries");
      }
      fcontext.base = fcontext.searcher.getDocSet(domainQs);
    } catch (SolrException e) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                              "Unable to parse domain 'query': " + freq.domain.explicitQueries +
                              " -- reason: " + e.getMessage(),
                              e);
    }
  } else {
    // mutualy exclusive to freq.domain.explicitQueries
    handleFilterExclusions();
  }

  // Check filters... if we do have filters they apply after domain changes.
  // We still calculate them first because we can use it in a parent->child domain change.
  evalFilters();

  handleJoinField();
  handleGraphField();

  boolean appliedFilters = handleBlockJoin();

  if (this.filter != null && !appliedFilters) {
    fcontext.base = fcontext.base.intersection( filter );
  }
}
 
Example 14
Source File: DimensionalRoutedAliasUpdateProcessorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void testFailedDocument(String category, String timestamp, String errorMsg) throws SolrServerException, IOException {
  try {
    final UpdateResponse resp = solrClient.add(getAlias(), newDoc(category, timestamp));
    // if we have a TolerantUpdateProcessor then we see it there)
    final Object errors = resp.getResponseHeader().get("errors"); // Tolerant URP
    assertTrue(errors != null && errors.toString().contains(errorMsg));
  } catch (SolrException e) {
    String message = e.getMessage();
    assertTrue("expected message to contain" + errorMsg + " but message was " + message , message.contains(errorMsg));
  }
  numDocsDeletedOrFailed++;
}
 
Example 15
Source File: BasicFunctionalityTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testClientErrorOnMalformedDate() throws Exception {
  final String BAD_VALUE = "NOT_A_DATE";
  ignoreException(BAD_VALUE);

  final List<String> FIELDS = new LinkedList<>();
  for (String type : new String[] {
      "tdt", "tdt1", "tdtdv", "tdtdv1",
      "dt_dv", "dt_dvo", "dt", "dt1", "dt_os"
      }) {
    FIELDS.add("malformed_" + type);
  }

  // test that malformed numerics cause client error not server error
  for (String field : FIELDS) {
    SolrException e1 = expectThrows(SolrException.class,
        "Didn't encounter an error trying to add a bad date: " + field,
        () -> h.update(add( doc("id","100", field, BAD_VALUE))));
    String msg1 = e1.getMessage();
    assertTrue("not an (update) client error on field: " + field +" : "+ msg1,
        400 <= e1.code() && e1.code() < 500);
    assertTrue("(update) client error does not mention bad value: " + msg1,
        msg1.contains(BAD_VALUE));
    assertTrue("client error does not mention document id: " + msg1,
        msg1.contains("[doc=100]"));
    SchemaField sf = h.getCore().getLatestSchema().getField(field);
    if (!sf.hasDocValues() && !sf.indexed()) {
      continue;
    }
    SolrException e2 = expectThrows(SolrException.class,
        "Didn't encounter an error trying to add a bad date: " + field,
        () -> h.query(req("q",field + ":" + BAD_VALUE))
    );
    String msg2 = e2.toString();
    assertTrue("not a (search) client error on field: " + field +" : "+ msg2,
        400 <= e2.code() && e2.code() < 500);
    assertTrue("(search) client error does not mention bad value: " + msg2,
        msg2.contains(BAD_VALUE));

    SolrException e3 = expectThrows(SolrException.class,
        "Didn't encounter an error trying to add a bad date: " + field,
        () -> h.query(req("q",field + ":[NOW TO " + BAD_VALUE + "]"))
    );
    String msg3 = e3.toString();
    assertTrue("not a (search) client error on field: " + field +" : "+ msg3,
        400 <= e3.code() && e3.code() < 500);
    assertTrue("(search) client error does not mention bad value: " + msg3,
        msg3.contains(BAD_VALUE));
  }
}