Java Code Examples for org.apache.solr.common.SolrException.ErrorCode#INVALID_STATE

The following examples show how to use org.apache.solr.common.SolrException.ErrorCode#INVALID_STATE . 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: CreateCollectionCmd.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Copies the _default configset to the specified configset name (overwrites if pre-existing)
 */
private void copyDefaultConfigSetTo(List<String> configNames, String targetConfig) {
  ZkConfigManager configManager = new ZkConfigManager(ocmh.zkStateReader.getZkClient());

  // if a configset named collection exists, re-use it
  if (configNames.contains(targetConfig)) {
    log.info("There exists a configset by the same name as the collection we're trying to create: {}, re-using it.", targetConfig);
    return;
  }
  // Copy _default into targetConfig
  try {
    configManager.copyConfigDir(ConfigSetsHandlerApi.DEFAULT_CONFIGSET_NAME, targetConfig, new HashSet<>());
  } catch (Exception e) {
    throw new SolrException(ErrorCode.INVALID_STATE, "Error while copying _default to " + targetConfig, e);
  }
}
 
Example 2
Source File: DefaultPackageRepository.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void initPackages() {
  try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
    SolrPackage[] items = PackageUtils.getJson(client, repositoryURL + "/repository.json", SolrPackage[].class);

    packages = new HashMap<>(items.length);
    for (SolrPackage pkg : items) {
      pkg.setRepository(name);
      packages.put(pkg.name, pkg);
    }
  } catch (IOException ex) {
    throw new SolrException(ErrorCode.INVALID_STATE, ex);
  }
  if (log.isDebugEnabled()) {
    log.debug("Found {} packages in repository '{}'", packages.size(), name);
  }
}
 
Example 3
Source File: Grouping.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
protected void finish() throws IOException {
  if (secondPass != null) {
    result = secondPass.getTopGroups(0);
    populateScoresIfNecessary();
  }
  if (main) {
    mainResult = createSimpleResponse();
    return;
  }

  @SuppressWarnings({"rawtypes"})
  NamedList groupResult = commonResponse();

  if (format == Format.simple) {
    groupResult.add("doclist", createSimpleResponse());
    return;
  }

  @SuppressWarnings({"rawtypes"})
  List groupList = new ArrayList();
  groupResult.add("groups", groupList);        // grouped={ key={ groups=[

  if (result == null) {
    return;
  }

  // handle case of rows=0
  if (numGroups == 0) return;

  for (GroupDocs<BytesRef> group : result.groups) {
    @SuppressWarnings({"rawtypes"})
    NamedList nl = new SimpleOrderedMap();
    groupList.add(nl);                         // grouped={ key={ groups=[ {


    // To keep the response format compatable with trunk.
    // In trunk MutableValue can convert an indexed value to its native type. E.g. string to int
    // The only option I currently see is the use the FieldType for this
    if (group.groupValue != null) {
      SchemaField schemaField = searcher.getSchema().getField(groupBy);
      FieldType fieldType = schemaField.getType();
      // use createFields so that fields having doc values are also supported
      // TODO: currently, this path is called only for string field, so
      // should we just use fieldType.toObject(schemaField, group.groupValue) here?
      List<IndexableField> fields = schemaField.createFields(group.groupValue.utf8ToString());
      if (CollectionUtils.isNotEmpty(fields)) {
        nl.add("groupValue", fieldType.toObject(fields.get(0)));
      } else {
        throw new SolrException(ErrorCode.INVALID_STATE,
            "Couldn't create schema field for grouping, group value: " + group.groupValue.utf8ToString()
            + ", field: " + schemaField);
      }
    } else {
      nl.add("groupValue", null);
    }

    addDocList(nl, group);
  }
}