org.apache.solr.common.SolrException.ErrorCode Java Examples

The following examples show how to use org.apache.solr.common.SolrException.ErrorCode. 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: RestManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Overrides the parent impl to handle FileNotFoundException better
 */
@Override
protected synchronized void reloadFromStorage() throws SolrException {
  String resourceId = getResourceId();
  Object data = null;
  try {
    data = storage.load(resourceId);
  } catch (FileNotFoundException fnf) {
    // this is ok - simply means there are no managed components added yet
  } catch (IOException ioExc) {
    throw new SolrException(ErrorCode.SERVER_ERROR,
        "Failed to load stored data for "+resourceId+" due to: "+ioExc, ioExc);
  }

  Object managedData = processStoredData(data);

  if (managedInitArgs == null)
    managedInitArgs = new NamedList<>();

  if (managedData != null)
    onManagedDataLoadedFromStorage(managedInitArgs, managedData);
}
 
Example #2
Source File: IndexSchemaFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an index schema created from a local resource.  The input is usually from the core descriptor.
 */
public IndexSchema create(String resourceName, SolrConfig config) {
  SolrResourceLoader loader = config.getResourceLoader();
  InputStream schemaInputStream = null;

  if (null == resourceName) {
    resourceName = IndexSchema.DEFAULT_SCHEMA_FILE;
  }

  try {
    schemaInputStream = loader.openResource(resourceName);
  } catch (Exception e) {
    final String msg = "Error loading schema resource " + resourceName;
    log.error(msg, e);
    throw new SolrException(ErrorCode.SERVER_ERROR, msg, e);
  }
  InputSource inputSource = new InputSource(schemaInputStream);
  inputSource.setSystemId(SystemIdResolver.createSystemIdFromResourceName(resourceName));
  IndexSchema schema = new IndexSchema(resourceName, inputSource, config.luceneMatchVersion, loader, config.getSubstituteProperties());
  return schema;
}
 
Example #3
Source File: StatelessScriptUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private boolean invokeFunctionUnsafe(String name, Object... cmd) {

      for (EngineInfo engine : engines) {
        try {
          Object result = engine.getEngine().invokeFunction(name, cmd);
          if (null != result && result instanceof Boolean) {
            if (! ((Boolean)result).booleanValue() ) {
              return false;
            }
          }

        } catch (ScriptException | NoSuchMethodException e) {
          throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, 
                                  "Unable to invoke function " + name + 
                                  " in script: " + 
                                  engine.getScriptFile().getFileName() + 
                                  ": " + e.getMessage(), e);
        }
      }

      return true;
    }
 
Example #4
Source File: DefaultPackageRepository.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public Path download(String artifactName) throws SolrException, IOException {
  Path tmpDirectory = Files.createTempDirectory("solr-packages");
  tmpDirectory.toFile().deleteOnExit();
  URL url = new URL(new URL(repositoryURL.endsWith("/")? repositoryURL: repositoryURL+"/"), artifactName);
  String fileName = FilenameUtils.getName(url.getPath());
  Path destination = tmpDirectory.resolve(fileName);

  switch (url.getProtocol()) {
    case "http":
    case "https":
    case "ftp":
      FileUtils.copyURLToFile(url, destination.toFile());
      break;
    default:
      throw new SolrException(ErrorCode.BAD_REQUEST, "URL protocol " + url.getProtocol() + " not supported");
  }
  
  return destination;
}
 
Example #5
Source File: ManagedWordSetResource.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Implements the GET request to provide the list of words to the client.
 * Alternatively, if a specific word is requested, then it is returned
 * or a 404 is raised, indicating that the requested word does not exist.
 */
@Override
public void doGet(BaseSolrResource endpoint, String childId) {
  SolrQueryResponse response = endpoint.getSolrResponse();
  if (childId != null) {
    // downcase arg if we're configured to ignoreCase
    String key = getIgnoreCase() ? childId.toLowerCase(Locale.ROOT) : childId;       
    if (!managedWords.contains(key))
      throw new SolrException(ErrorCode.NOT_FOUND, 
          String.format(Locale.ROOT, "%s not found in %s", childId, getResourceId()));
      
    response.add(childId, key);
  } else {
    response.add(WORD_SET_JSON_FIELD, buildMapToStore(managedWords));      
  }
}
 
Example #6
Source File: SplitShardCmd.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static boolean lockForSplit(SolrCloudManager cloudManager, String collection, String shard) throws Exception {
  String path = ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection + "/" + shard + "-splitting";
  final DistribStateManager stateManager = cloudManager.getDistribStateManager();
  synchronized (stateManager) {
    if (stateManager.hasData(path)) {
      VersionedData vd = stateManager.getData(path);
      return false;
    }
    Map<String, Object> map = new HashMap<>();
    map.put(ZkStateReader.STATE_TIMESTAMP_PROP, String.valueOf(cloudManager.getTimeSource().getEpochTimeNs()));
    byte[] data = Utils.toJSON(map);
    try {
      cloudManager.getDistribStateManager().makePath(path, data, CreateMode.EPHEMERAL, true);
    } catch (Exception e) {
      throw new SolrException(SolrException.ErrorCode.INVALID_STATE, "Can't lock parent slice for splitting (another split operation running?): " +
          collection + "/" + shard, e);
    }
    return true;
  }
}
 
Example #7
Source File: AnalyticsRequestParser.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static EnumSet<FacetRangeOther> constructOthers(List<String> othersRequest, String facetName) throws SolrException {
  EnumSet<FacetRangeOther> others = EnumSet.noneOf(FacetRangeOther.class);
  for (String rawOther : othersRequest) {
    if (!others.add(FacetRangeOther.get(rawOther))) {
      throw new SolrException(ErrorCode.BAD_REQUEST, "Duplicate include value '" + rawOther + "' found in range facet '" + facetName + "'");
    }
  }
  if (others.contains(FacetRangeOther.NONE)) {
    if (others.size() > 1) {
      throw new SolrException(ErrorCode.BAD_REQUEST, "Include value 'NONE' is used with other includes in a range facet '" + facetName + "'. "
          + "If 'NONE' is used, it must be the only include.");
    }
    return EnumSet.noneOf(FacetRangeOther.class);
  }
  if (others.contains(FacetRangeOther.ALL)) {
    if (others.size() > 1) {
      throw new SolrException(ErrorCode.BAD_REQUEST, "Include value 'ALL' is used with other includes in a range facet '" + facetName + "'. "
          + "If 'ALL' is used, it must be the only include.");
    }
    return EnumSet.of(FacetRangeOther.BEFORE, FacetRangeOther.BETWEEN, FacetRangeOther.AFTER);
  }
  return others;
}
 
Example #8
Source File: Sparql11UpdateRdfDataLoaderTestCase.java    From SolRDF with Apache License 2.0 6 votes vote down vote up
/** 
 * In case of a null query a {@link QueryParseException} must be raised.
 */
@Test
@Ignore
public void nullOrEmptyQuery() {
	final String [] invalidQueries = {"", "   "};
	for (final String invalidQuery : invalidQueries) {
		parameters.set(CommonParams.Q, invalidQuery);
		try {
			cut.load(request, response, stream, processor);
			fail();
		} catch (final Exception expected) {
			assertTrue(expected instanceof SolrException);
			assertEquals(ErrorCode.BAD_REQUEST.code, ((SolrException)expected).code());
		}
	}
}
 
Example #9
Source File: AbstractFullDistribZkTestBase.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static String getUrlFromZk(ClusterState clusterState, String collection) {
  Map<String,Slice> slices = clusterState.getCollection(collection).getSlicesMap();

  if (slices == null) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not find collection:" + collection);
  }

  for (Map.Entry<String,Slice> entry : slices.entrySet()) {
    Slice slice = entry.getValue();
    Map<String,Replica> shards = slice.getReplicasMap();
    Set<Map.Entry<String,Replica>> shardEntries = shards.entrySet();
    for (Map.Entry<String,Replica> shardEntry : shardEntries) {
      final ZkNodeProps node = shardEntry.getValue();
      if (clusterState.liveNodesContain(node.getStr(ZkStateReader.NODE_NAME_PROP))) {
        return ZkCoreNodeProps.getCoreUrl(node.getStr(ZkStateReader.BASE_URL_PROP), collection); //new ZkCoreNodeProps(node).getCoreUrl();
      }
    }
  }

  throw new RuntimeException("Could not find a live node for collection:" + collection);
}
 
Example #10
Source File: ZkStateReader.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Get shard leader properties, with retry if none exist.
 */
public Replica getLeaderRetry(String collection, String shard, int timeout) throws InterruptedException {

  AtomicReference<Replica> leader = new AtomicReference<>();
  try {
    waitForState(collection, timeout, TimeUnit.MILLISECONDS, (n, c) -> {
      if (c == null)
        return false;
      Replica l = getLeader(n, c, shard);
      if (l != null) {
        leader.set(l);
        return true;
      }
      return false;
    });
  } catch (TimeoutException e) {
    throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "No registered leader was found after waiting for "
        + timeout + "ms " + ", collection: " + collection + " slice: " + shard + " saw state=" + clusterState.getCollectionOrNull(collection)
        + " with live_nodes=" + clusterState.getLiveNodes());
  }
  return leader.get();
}
 
Example #11
Source File: PackageManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Given a package, return a map of collections where this package is
 * installed to the installed version (which can be {@link PackagePluginHolder#LATEST})
 */
public Map<String, String> getDeployedCollections(String packageName) {
  List<String> allCollections;
  try {
    allCollections = zkClient.getChildren(ZkStateReader.COLLECTIONS_ZKNODE, null, true);
  } catch (KeeperException | InterruptedException e) {
    throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, e);
  }
  Map<String, String> deployed = new HashMap<String, String>();
  for (String collection: allCollections) {
    // Check package version installed
    String paramsJson = PackageUtils.getJsonStringFromUrl(solrClient.getHttpClient(), solrBaseUrl + PackageUtils.getCollectionParamsPath(collection) + "/PKG_VERSIONS?omitHeader=true");
    String version = null;
    try {
      version = JsonPath.parse(paramsJson, PackageUtils.jsonPathConfiguration())
          .read("$['response'].['params'].['PKG_VERSIONS'].['"+packageName+"'])");
    } catch (PathNotFoundException ex) {
      // Don't worry if PKG_VERSION wasn't found. It just means this collection was never touched by the package manager.
    }
    if (version != null) {
      deployed.put(collection, version);
    }
  }
  return deployed;
}
 
Example #12
Source File: TolerantUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public void init( NamedList args ) {

  Object maxErrorsObj = args.get(MAX_ERRORS_PARAM); 
  if (maxErrorsObj != null) {
    try {
      defaultMaxErrors = Integer.parseInt(maxErrorsObj.toString());
    } catch (Exception e) {
      throw new SolrException(ErrorCode.SERVER_ERROR, "Unnable to parse maxErrors parameter: " + maxErrorsObj, e);
    }
    if (defaultMaxErrors < -1) {
      throw new SolrException(ErrorCode.SERVER_ERROR, "Config option '"+MAX_ERRORS_PARAM + "' must either be non-negative, or -1 to indicate 'unlimiited': " + maxErrorsObj.toString());
    }
  }
}
 
Example #13
Source File: RepositoryManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private List<Path> downloadPackageArtifacts(String packageName, String version) throws SolrException {
  try {
    SolrPackageRelease release = getPackageRelease(packageName, version);
    List<Path> downloadedPaths = new ArrayList<Path>(release.artifacts.size());

    for (PackageRepository repo: getRepositories()) {
      if (repo.hasPackage(packageName)) {
        for (Artifact art: release.artifacts) {
          downloadedPaths.add(repo.download(art.url));
        }
        return downloadedPaths;
      }
    }
  } catch (IOException e) {
    throw new SolrException(ErrorCode.SERVER_ERROR, "Error during download of package " + packageName, e);
  }
  throw new SolrException(ErrorCode.NOT_FOUND, "Package not found in any repository.");
}
 
Example #14
Source File: SubQueryAugmenterFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void transform(SolrDocument doc, int docid) {

  final SolrParams docWithDeprefixed = SolrParams.wrapDefaults(
      new DocRowParams(doc, prefix, separator), baseSubParams);
  try {
    QueryResponse rsp = server.query(coreName, docWithDeprefixed);
    SolrDocumentList docList = rsp.getResults();
    doc.setField(getName(), new Result(docList));
  } catch (Exception e) {
    String docString = doc.toString();
    throw new SolrException(ErrorCode.BAD_REQUEST, "while invoking " +
        name + ":[subquery"+ (coreName!=null ? "fromIndex="+coreName : "") +"] on doc=" +
          docString.substring(0, Math.min(100, docString.length())), e.getCause());
  }
}
 
Example #15
Source File: StatsField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** special for percentiles **/
boolean parseParams(StatsField sf) {
  String percentileParas = sf.localParams.get(this.name());
  if (percentileParas != null) {
    List<Double> percentiles = new ArrayList<Double>();
    try {
      for (String percentile : StrUtils.splitSmart(percentileParas, ',')) {
        percentiles.add(Double.parseDouble(percentile));
      }
      if (!percentiles.isEmpty()) {
        sf.percentilesList.addAll(percentiles);
        sf.tdigestCompression = sf.localParams.getDouble("tdigestCompression", 
                                                         sf.tdigestCompression);
        return true;
      }
    } catch (NumberFormatException e) {
      throw new SolrException(ErrorCode.BAD_REQUEST, "Unable to parse "
          + StatsParams.STATS_FIELD + " local params: " + sf.localParams + " due to: "
          + e.getMessage(), e);
    }

  }
  return false;
}
 
Example #16
Source File: ZkController.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void waitForShardId(CoreDescriptor cd) {
  if (log.isDebugEnabled()) {
    log.debug("waiting to find shard id in clusterstate for {}", cd.getName());
  }
  int retryCount = 320;
  while (retryCount-- > 0) {
    final String shardId = zkStateReader.getClusterState().getShardId(cd.getCollectionName(), getNodeName(), cd.getName());
    if (shardId != null) {
      cd.getCloudDescriptor().setShardId(shardId);
      return;
    }
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }

  throw new SolrException(ErrorCode.SERVER_ERROR,
      "Could not get shard id for core: " + cd.getName());
}
 
Example #17
Source File: SolrConfig.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static final Version parseLuceneVersionString(final String matchVersion) {
  final Version version;
  try {
    version = Version.parseLeniently(matchVersion);
  } catch (ParseException pe) {
    throw new SolrException(ErrorCode.SERVER_ERROR,
        "Invalid luceneMatchVersion.  Should be of the form 'V.V.V' (e.g. 4.8.0)", pe);
  }

  if (version == Version.LATEST && !versionWarningAlreadyLogged.getAndSet(true)) {
    log.warn("You should not use LATEST as luceneMatchVersion property: "
        + "if you use this setting, and then Solr upgrades to a newer release of Lucene, "
        + "sizable changes may happen. If precise back compatibility is important "
        + "then you should instead explicitly specify an actual Lucene version.");
  }

  return version;
}
 
Example #18
Source File: FieldTypeXmlAdapter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected static Element transformSimilarity(Document doc, Map<String,?> json, String jsonFieldName) {
  Object jsonField = json.get(jsonFieldName);
  if (jsonField == null)
    return null; // it's ok for this field to not exist in the JSON map

  if (!(jsonField instanceof Map))
    throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid fieldType definition! Expected JSON object for "+
        jsonFieldName+" not a "+jsonField.getClass().getName());

  Element similarity = doc.createElement("similarity");
  Map<String,?> config = (Map<String,?>)jsonField;
  similarity.setAttribute(SimilarityFactory.CLASS_NAME, (String)config.remove(SimilarityFactory.CLASS_NAME));
  for (Map.Entry<String,?> entry : config.entrySet()) {
    Object val = entry.getValue();
    if (val != null) {
      Element child = doc.createElement(classToXmlTag(val.getClass()));
      child.setAttribute(CommonParams.NAME, entry.getKey());
      child.setTextContent(entry.getValue().toString());
      similarity.appendChild(child);
    }
  }
  return similarity;
}
 
Example #19
Source File: ExpressionFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Get the name of the top function used in the given expression.
 *
 * @param expression the expression to find the function name of
 * @return the name of the function
 * @throws SolrException if the expression has incorrect syntax
 */
private static String getFunctionName(String expression) throws SolrException {
  Matcher m = functionNamePattern.matcher(expression);
  if (!m.matches()) {
    throw new SolrException(ErrorCode.BAD_REQUEST,"The following function has no name: " + expression);
  }
  String name = m.group(1);
  return name;
}
 
Example #20
Source File: GeoJSONResponseWriter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
  
  String geofield = req.getParams().get(FIELD, null);
  if(geofield==null || geofield.length()==0) {
    throw new SolrException(ErrorCode.BAD_REQUEST, "GeoJSON.  Missing parameter: '"+FIELD+"'");
  }
  
  SchemaField sf = req.getSchema().getFieldOrNull(geofield);
  if(sf==null) {
    throw new SolrException(ErrorCode.BAD_REQUEST, "GeoJSON.  Unknown field: '"+FIELD+"'="+geofield);
  }
  
  SupportedFormats formats = null;
  if(sf.getType() instanceof AbstractSpatialFieldType) {
    SpatialContext ctx = ((AbstractSpatialFieldType)sf.getType()).getSpatialContext();
    formats = ctx.getFormats();
  }

  JSONWriter w = new GeoJSONWriter(writer, req, rsp, 
      geofield,
      formats); 
  
  try {
    w.writeResponse();
  } finally {
    w.close();
  }
}
 
Example #21
Source File: SolrRequestParsers.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static int digit16(int b) {
  if (b == -1) {
    throw new SolrException(ErrorCode.BAD_REQUEST, "URLDecoder: Incomplete trailing escape (%) pattern");
  }
  if (b >= '0' && b <= '9') {
    return b - '0';
  }
  if (b >= 'A' && b <= 'F') {
    return b - ('A' - 10);
  }
  if (b >= 'a' && b <= 'f') {
    return b - ('a' - 10);
  }
  throw new SolrException(ErrorCode.BAD_REQUEST, "URLDecoder: Invalid digit (" + ((char) b) + ") in escape (%) pattern");
}
 
Example #22
Source File: ZkController.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Verifies if /clusterstate.json exists in Zookeepeer, and if it does and is not empty, refuses to start and outputs
 * a helpful message regarding collection migration.</p>
 *
 * <p>If /clusterstate.json exists and is empty, it is removed.</p>
 */
private void checkNoOldClusterstate(final SolrZkClient zkClient) throws InterruptedException {
  try {
    if (!zkClient.exists(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, true)) {
      return;
    }

    final byte[] data = zkClient.getData(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, null, null, true);

    if (Arrays.equals("{}".getBytes(StandardCharsets.UTF_8), data)) {
      // Empty json. This log will only occur once.
      log.warn("{} no longer supported starting with Solr 9. Found empty file on Zookeeper, deleting it.", ZkStateReader.UNSUPPORTED_CLUSTER_STATE);
      zkClient.delete(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, -1, true);
    } else {
      // /clusterstate.json not empty: refuse to start but do not automatically delete. A bit of a pain but user shouldn't
      // have older collections at this stage anyway.
      String message = ZkStateReader.UNSUPPORTED_CLUSTER_STATE + " no longer supported starting with Solr 9. "
          + "It is present and not empty. Cannot start Solr. Please first migrate collections to stateFormat=2 using an "
          + "older version of Solr or if you don't care about the data then delete the file from "
          + "Zookeeper using a command line tool, for example: bin/solr zk rm /clusterstate.json -z host:port";
      log.error(message);
      throw new SolrException(SolrException.ErrorCode.INVALID_STATE, message);
    }
  } catch (KeeperException e) {
    // Convert checked exception to one acceptable by the caller (see also init() further down)
    log.error("", e);
    throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
  }
}
 
Example #23
Source File: OverseerSolrResponseSerializer.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * This method serializes the content of an {@code OverseerSolrResponse}. Note that:
 * <ul>
 * <li>The elapsed time is not serialized</li>
 * <li>"Unknown" elements for the Javabin format will be serialized as Strings. See {@link org.apache.solr.common.util.JavaBinCodec#writeVal}</li>
 * </ul>
 */
@SuppressWarnings("deprecation")
public static byte[] serialize(OverseerSolrResponse responseObject) {
  Objects.requireNonNull(responseObject);
  if (useUnsafeSerialization()) {
    return SolrResponse.serializable(responseObject);
  }
  try {
    return Utils.toJavabin(responseObject.getResponse()).readAllBytes();
  } catch (IOException|RuntimeException e) {
    throw new SolrException(ErrorCode.SERVER_ERROR, "Exception serializing response to Javabin", e);
  }
}
 
Example #24
Source File: OverseerConfigSetMessageHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void deleteConfigSet(ZkNodeProps message) throws IOException {
  String configSetName = getTaskKey(message);
  if (configSetName == null || configSetName.length() == 0) {
    throw new SolrException(ErrorCode.BAD_REQUEST, "ConfigSet name not specified");
  }

  deleteConfigSet(configSetName, false);
}
 
Example #25
Source File: DistributedZkUpdateProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private String getLeaderUrlZk(String id) {
  // An update we're dependent upon didn't arrive! This is unexpected. Perhaps likely our leader is
  // down or partitioned from us for some reason. Lets force refresh cluster state, and request the
  // leader for the update.
  if (zkController == null) { // we should be in cloud mode, but wtf? could be a unit test
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Can't find document with id=" + id + ", but fetching from leader "
        + "failed since we're not in cloud mode.");
  }
  try {
    return zkController.getZkStateReader().getLeaderRetry(collection, cloudDesc.getShardId()).getCoreUrl();
  } catch (InterruptedException e) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Exception during fetching from leader.", e);
  }
}
 
Example #26
Source File: ReplicationHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected String validateFilenameOrError(String filename) {
  if (filename != null) {
    Path filePath = Paths.get(filename);
    filePath.forEach(subpath -> {
      if ("..".equals(subpath.toString())) {
        throw new SolrException(ErrorCode.FORBIDDEN, "File name cannot contain ..");
      }
    });
    if (filePath.isAbsolute()) {
      throw new SolrException(ErrorCode.FORBIDDEN, "File name must be relative");
    }
    return filename;
  } else return null;
}
 
Example #27
Source File: CoreAdminOperationTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testRequestBufferUpdatesUnexpectedFailuresResultIn500Exception() {
  final Throwable cause = new NullPointerException();
  whenUnexpectedErrorOccursDuringCoreAdminOp(cause);

  Exception ex = expectThrows(Exception.class, () ->  CoreAdminOperation.REQUESTBUFFERUPDATES_OP.execute(callInfo));
  assertSolrExceptionWithCodeAndCause(ex, ErrorCode.SERVER_ERROR.code, cause);
}
 
Example #28
Source File: DelegatingComparator.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static FacetResultsComparator joinComparators(Collection<FacetResultsComparator> comparators) throws SolrException {
  if (comparators.size() == 0) {
    throw new SolrException(ErrorCode.BAD_REQUEST,"A sort must have at least 1 comparator criteria.");
  } else if (comparators.size() == 1) {
    return comparators.iterator().next();
  } else {
    return new DelegatingComparator(comparators);
  }
}
 
Example #29
Source File: ExplainAugmenterFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static Style getStyle( String str ) {
  try {
    return Style.valueOf( str );
  }
  catch( Exception ex ) {
    throw new SolrException( ErrorCode.BAD_REQUEST,
        "Unknown Explain Style: "+str );
  }
}
 
Example #30
Source File: OntologyUpdateProcessorFactory.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
	if (isEnabled()) {
		try {
			// Look up ontology data for document
			OntologyHelper helper = initialiseHelper();
			String iri = (String)cmd.getSolrInputDocument().getFieldValue(getAnnotationField());

			if (StringUtils.isNotBlank(iri)) {
				OntologyData data = findOntologyData(helper, iri);

				if (data == null) {
					LOGGER.debug("Cannot find OWL class for IRI {}", iri);
				} else {
					addDataToSolrDoc(cmd.getSolrInputDocument(), data);
				}
			}
		} catch (OntologyHelperException e) {
			throw new SolrException(ErrorCode.SERVER_ERROR,
					"Cannot load ontology: " + e.getMessage());
		}
	}

	// Run the next processor in the chain
	if (next != null) {
		next.processAdd(cmd);
	}
}