Search in sources :

Example 71 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class ReplicationHandler method restore.

private void restore(SolrParams params, SolrQueryResponse rsp, SolrQueryRequest req) throws IOException {
    if (restoreFuture != null && !restoreFuture.isDone()) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "Restore in progress. Cannot run multiple restore operations" + "for the same core");
    }
    String name = params.get(NAME);
    String location = params.get(CoreAdminParams.BACKUP_LOCATION);
    String repoName = params.get(CoreAdminParams.BACKUP_REPOSITORY);
    CoreContainer cc = core.getCoreContainer();
    BackupRepository repo = null;
    if (repoName != null) {
        repo = cc.newBackupRepository(Optional.of(repoName));
        location = repo.getBackupLocation(location);
        if (location == null) {
            throw new IllegalArgumentException("location is required");
        }
    } else {
        repo = new LocalFileSystemRepository();
    }
    //If location is not provided then assume that the restore index is present inside the data directory.
    if (location == null) {
        location = core.getDataDir();
    }
    URI locationUri = repo.createURI(location);
    //snapshot folder since we allow snapshots to be taken without providing a name. Pick the latest timestamp.
    if (name == null) {
        String[] filePaths = repo.listAll(locationUri);
        List<OldBackupDirectory> dirs = new ArrayList<>();
        for (String f : filePaths) {
            OldBackupDirectory obd = new OldBackupDirectory(locationUri, f);
            if (obd.getTimestamp().isPresent()) {
                dirs.add(obd);
            }
        }
        Collections.sort(dirs);
        if (dirs.size() == 0) {
            throw new SolrException(ErrorCode.BAD_REQUEST, "No backup name specified and none found in " + core.getDataDir());
        }
        name = dirs.get(0).getDirName();
    } else {
        //"snapshot." is prefixed by snapshooter
        name = "snapshot." + name;
    }
    RestoreCore restoreCore = new RestoreCore(repo, core, locationUri, name);
    try {
        MDC.put("RestoreCore.core", core.getName());
        MDC.put("RestoreCore.backupLocation", location);
        MDC.put("RestoreCore.backupName", name);
        restoreFuture = restoreExecutor.submit(restoreCore);
        currentRestoreName = name;
    } finally {
        MDC.remove("RestoreCore.core");
        MDC.remove("RestoreCore.backupLocation");
        MDC.remove("RestoreCore.backupName");
    }
}
Also used : BackupRepository(org.apache.solr.core.backup.repository.BackupRepository) CoreContainer(org.apache.solr.core.CoreContainer) LocalFileSystemRepository(org.apache.solr.core.backup.repository.LocalFileSystemRepository) ArrayList(java.util.ArrayList) URI(java.net.URI) SolrException(org.apache.solr.common.SolrException)

Example 72 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class IndexFetcher method getLatestVersion.

/**
   * Gets the latest commit version and generation from the master
   */
@SuppressWarnings("unchecked")
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).build()) {
        client.setSoTimeout(soTimeout);
        client.setConnectionTimeout(connTimeout);
        return client.request(req);
    } catch (SolrServerException e) {
        throw new SolrException(ErrorCode.SERVER_ERROR, e.getMessage(), e);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) Builder(org.apache.solr.client.solrj.impl.HttpSolrClient.Builder) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException)

Example 73 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class ConfigSetsHandler method handleResponse.

private void handleResponse(String operation, ZkNodeProps m, SolrQueryResponse rsp, long timeout) throws KeeperException, InterruptedException {
    long time = System.nanoTime();
    QueueEvent event = coreContainer.getZkController().getOverseerConfigSetQueue().offer(Utils.toJSON(m), timeout);
    if (event.getBytes() != null) {
        SolrResponse response = SolrResponse.deserialize(event.getBytes());
        rsp.getValues().addAll(response.getResponse());
        SimpleOrderedMap exp = (SimpleOrderedMap) response.getResponse().get("exception");
        if (exp != null) {
            Integer code = (Integer) exp.get("rspCode");
            rsp.setException(new SolrException(code != null && code != -1 ? ErrorCode.getErrorCode(code) : ErrorCode.SERVER_ERROR, (String) exp.get("msg")));
        }
    } else {
        if (System.nanoTime() - time >= TimeUnit.NANOSECONDS.convert(timeout, TimeUnit.MILLISECONDS)) {
            throw new SolrException(ErrorCode.SERVER_ERROR, operation + " the configset time out:" + timeout / 1000 + "s");
        } else if (event.getWatchedEvent() != null) {
            throw new SolrException(ErrorCode.SERVER_ERROR, operation + " the configset error [Watcher fired on path: " + event.getWatchedEvent().getPath() + " state: " + event.getWatchedEvent().getState() + " type " + event.getWatchedEvent().getType() + "]");
        } else {
            throw new SolrException(ErrorCode.SERVER_ERROR, operation + " the configset unknown case");
        }
    }
}
Also used : QueueEvent(org.apache.solr.cloud.OverseerTaskQueue.QueueEvent) OverseerSolrResponse(org.apache.solr.cloud.OverseerSolrResponse) SolrResponse(org.apache.solr.client.solrj.SolrResponse) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SolrException(org.apache.solr.common.SolrException)

Example 74 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class ConfigSetsHandler method handleRequestBody.

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    if (coreContainer == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Core container instance missing");
    }
    // Make sure that the core is ZKAware
    if (!coreContainer.isZooKeeperAware()) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "Solr instance is not running in SolrCloud mode.");
    }
    // Pick the action
    SolrParams params = req.getParams();
    String a = params.get(ConfigSetParams.ACTION);
    if (a != null) {
        ConfigSetAction action = ConfigSetAction.get(a);
        if (action == null)
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown action: " + a);
        if (action == ConfigSetAction.UPLOAD) {
            handleConfigUploadRequest(req, rsp);
            return;
        }
        invokeAction(req, rsp, action);
    } else {
        throw new SolrException(ErrorCode.BAD_REQUEST, "action is a required param");
    }
    rsp.setHttpCaching(false);
}
Also used : ConfigSetAction(org.apache.solr.common.params.ConfigSetParams.ConfigSetAction) SolrParams(org.apache.solr.common.params.SolrParams) SolrException(org.apache.solr.common.SolrException)

Example 75 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class ConfigSetsHandler method handleConfigUploadRequest.

private void handleConfigUploadRequest(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    String configSetName = req.getParams().get(NAME);
    if (StringUtils.isBlank(configSetName)) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "The configuration name should be provided in the \"name\" parameter");
    }
    SolrZkClient zkClient = coreContainer.getZkController().getZkClient();
    String configPathInZk = ZkConfigManager.CONFIGS_ZKNODE + Path.SEPARATOR + configSetName;
    if (zkClient.exists(configPathInZk, true)) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "The configuration " + configSetName + " already exists in zookeeper");
    }
    Iterator<ContentStream> contentStreamsIterator = req.getContentStreams().iterator();
    if (!contentStreamsIterator.hasNext()) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "No stream found for the config data to be uploaded");
    }
    InputStream inputStream = contentStreamsIterator.next().getStream();
    // Create a node for the configuration in zookeeper
    boolean trusted = getTrusted(req);
    zkClient.makePath(configPathInZk, ("{\"trusted\": " + Boolean.toString(trusted) + "}").getBytes(StandardCharsets.UTF_8), true);
    ZipInputStream zis = new ZipInputStream(inputStream, StandardCharsets.UTF_8);
    ZipEntry zipEntry = null;
    while ((zipEntry = zis.getNextEntry()) != null) {
        String filePathInZk = configPathInZk + "/" + zipEntry.getName();
        if (zipEntry.isDirectory()) {
            zkClient.makePath(filePathInZk, true);
        } else {
            createZkNodeIfNotExistsAndSetData(zkClient, filePathInZk, IOUtils.toByteArray(zis));
        }
    }
    zis.close();
}
Also used : ContentStream(org.apache.solr.common.util.ContentStream) ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrException (org.apache.solr.common.SolrException)617 IOException (java.io.IOException)172 ArrayList (java.util.ArrayList)100 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)80 NamedList (org.apache.solr.common.util.NamedList)79 HashMap (java.util.HashMap)75 Map (java.util.Map)70 SolrParams (org.apache.solr.common.params.SolrParams)64 KeeperException (org.apache.zookeeper.KeeperException)60 Test (org.junit.Test)55 Replica (org.apache.solr.common.cloud.Replica)48 Slice (org.apache.solr.common.cloud.Slice)45 DocCollection (org.apache.solr.common.cloud.DocCollection)41 SolrInputDocument (org.apache.solr.common.SolrInputDocument)39 SchemaField (org.apache.solr.schema.SchemaField)39 List (java.util.List)38 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)38 SolrServerException (org.apache.solr.client.solrj.SolrServerException)37 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)34 SolrCore (org.apache.solr.core.SolrCore)33