Search in sources :

Example 1 with SimpleSolrResponse

use of org.apache.solr.client.solrj.response.SimpleSolrResponse in project lucene-solr by apache.

the class RulesTest method testInvokeApi.

@Test
public void testInvokeApi() throws Exception {
    JettySolrRunner jetty = cluster.getRandomJetty(random());
    try (SolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString())) {
        GenericSolrRequest req = new GenericSolrRequest(GET, "/____v2/node/invoke", new ModifiableSolrParams().add("class", ImplicitSnitch.class.getName()).add("cores", "1").add("freedisk", "1"));
        SimpleSolrResponse rsp = req.process(client);
        assertNotNull(((Map) rsp.getResponse().get(ImplicitSnitch.class.getName())).get("cores"));
        assertNotNull(((Map) rsp.getResponse().get(ImplicitSnitch.class.getName())).get("freedisk"));
    }
}
Also used : GenericSolrRequest(org.apache.solr.client.solrj.request.GenericSolrRequest) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) SimpleSolrResponse(org.apache.solr.client.solrj.response.SimpleSolrResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 2 with SimpleSolrResponse

use of org.apache.solr.client.solrj.response.SimpleSolrResponse in project lucene-solr by apache.

the class DistributedUpdateProcessor method fetchFullUpdateFromLeader.

/**
   * This method is used when an update on which a particular in-place update has been lost for some reason. This method
   * sends a request to the shard leader to fetch the latest full document as seen on the leader.
   * @return AddUpdateCommand containing latest full doc at shard leader for the given id, or null if not found.
   */
private UpdateCommand fetchFullUpdateFromLeader(AddUpdateCommand inplaceAdd, long versionOnUpdate) throws IOException {
    String id = inplaceAdd.getPrintableId();
    UpdateShardHandler updateShardHandler = inplaceAdd.getReq().getCore().getCoreContainer().getUpdateShardHandler();
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(DISTRIB, false);
    params.set("getInputDocument", id);
    params.set("onlyIfActive", true);
    SolrRequest<SimpleSolrResponse> ur = new GenericSolrRequest(METHOD.GET, "/get", params);
    String leaderUrl = req.getParams().get(DISTRIB_FROM);
    if (leaderUrl == null) {
        // leader for the update.
        if (zkController == null) {
            // we should be in cloud mode, but wtf? could be a unit test
            throw new SolrException(ErrorCode.SERVER_ERROR, "Can't find document with id=" + id + ", but fetching from leader " + "failed since we're not in cloud mode.");
        }
        Replica leader;
        try {
            leader = zkController.getZkStateReader().getLeaderRetry(cloudDesc.getCollectionName(), cloudDesc.getShardId());
        } catch (InterruptedException e) {
            throw new SolrException(ErrorCode.SERVER_ERROR, "Exception during fetching from leader.", e);
        }
        leaderUrl = leader.getCoreUrl();
    }
    HttpSolrClient hsc = new HttpSolrClient.Builder(leaderUrl).withHttpClient(updateShardHandler.getHttpClient()).build();
    NamedList rsp = null;
    try {
        rsp = hsc.request(ur);
    } catch (SolrServerException e) {
        throw new SolrException(ErrorCode.SERVER_ERROR, "Error during fetching [" + id + "] from leader (" + leaderUrl + "): ", e);
    } finally {
        hsc.close();
    }
    Object inputDocObj = rsp.get("inputDocument");
    Long version = (Long) rsp.get("version");
    SolrInputDocument leaderDoc = (SolrInputDocument) inputDocObj;
    if (leaderDoc == null) {
        // this doc was not found (deleted) on the leader. Lets delete it here as well.
        DeleteUpdateCommand del = new DeleteUpdateCommand(inplaceAdd.getReq());
        del.setIndexedId(inplaceAdd.getIndexedId());
        del.setId(inplaceAdd.getIndexedId().utf8ToString());
        del.setVersion((version == null || version == 0) ? -versionOnUpdate : version);
        return del;
    }
    AddUpdateCommand cmd = new AddUpdateCommand(req);
    cmd.solrDoc = leaderDoc;
    cmd.setVersion((long) leaderDoc.getFieldValue(CommonParams.VERSION_FIELD));
    return cmd;
}
Also used : GenericSolrRequest(org.apache.solr.client.solrj.request.GenericSolrRequest) NamedList(org.apache.solr.common.util.NamedList) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SimpleSolrResponse(org.apache.solr.client.solrj.response.SimpleSolrResponse) UpdateShardHandler(org.apache.solr.update.UpdateShardHandler) Replica(org.apache.solr.common.cloud.Replica) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrInputDocument(org.apache.solr.common.SolrInputDocument) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) SolrException(org.apache.solr.common.SolrException)

Example 3 with SimpleSolrResponse

use of org.apache.solr.client.solrj.response.SimpleSolrResponse in project lucene-solr by apache.

the class ServerSnitchContext method invokeRemote.

public void invokeRemote(String node, ModifiableSolrParams params, String klas, RemoteCallback callback) {
    if (callback == null)
        callback = this;
    String url = coreContainer.getZkController().getZkStateReader().getBaseUrlForNodeName(node);
    params.add("class", klas);
    params.add(ACTION, INVOKE.toString());
    try {
        SimpleSolrResponse rsp = invoke(coreContainer.getUpdateShardHandler(), url, CommonParams.CORES_HANDLER_PATH, params);
        Map<String, Object> returnedVal = (Map<String, Object>) rsp.getResponse().get(klas);
        if (exception == null) {
        //        log this
        } else {
            callback.remoteCallback(ServerSnitchContext.this, returnedVal);
        }
        callback.remoteCallback(this, returnedVal);
    } catch (Exception e) {
        log.error("Unable to invoke snitch counterpart", e);
        exception = e;
    }
}
Also used : SimpleSolrResponse(org.apache.solr.client.solrj.response.SimpleSolrResponse) Map(java.util.Map) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException)

Example 4 with SimpleSolrResponse

use of org.apache.solr.client.solrj.response.SimpleSolrResponse in project lucene-solr by apache.

the class ForceLeaderTest method getLastPublishedState.

/*protected void setLastPublishedState(String collection, String slice, Replica replica, Replica.State state) throws SolrServerException, IOException,
  KeeperException, InterruptedException {
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    String baseUrl = zkStateReader.getBaseUrlForNodeName(replica.getNodeName());

    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(CoreAdminParams.ACTION, CoreAdminAction.FORCEPREPAREFORLEADERSHIP.toString());
    params.set(CoreAdminParams.CORE, replica.getStr("core"));
    params.set(ZkStateReader.STATE_PROP, state.toString());

    SolrRequest<SimpleSolrResponse> req = new GenericSolrRequest(METHOD.GET, "/admin/cores", params);
    NamedList resp = null;
    try (HttpSolrClient hsc = new HttpSolrClient(baseUrl)) {
       resp = hsc.request(req);
    }
  }*/
protected Replica.State getLastPublishedState(String collection, String slice, Replica replica) throws SolrServerException, IOException, KeeperException, InterruptedException {
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    String baseUrl = zkStateReader.getBaseUrlForNodeName(replica.getNodeName());
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(CoreAdminParams.ACTION, CoreAdminAction.STATUS.toString());
    params.set(CoreAdminParams.CORE, replica.getStr("core"));
    SolrRequest<SimpleSolrResponse> req = new GenericSolrRequest(METHOD.GET, "/admin/cores", params);
    NamedList resp = null;
    try (HttpSolrClient hsc = getHttpSolrClient(baseUrl)) {
        resp = hsc.request(req);
    }
    String lastPublished = (((NamedList<NamedList<String>>) resp.get("status")).get(replica.getStr("core"))).get("lastPublished");
    return Replica.State.getState(lastPublished);
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) GenericSolrRequest(org.apache.solr.client.solrj.request.GenericSolrRequest) NamedList(org.apache.solr.common.util.NamedList) SimpleSolrResponse(org.apache.solr.client.solrj.response.SimpleSolrResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

SimpleSolrResponse (org.apache.solr.client.solrj.response.SimpleSolrResponse)4 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)3 GenericSolrRequest (org.apache.solr.client.solrj.request.GenericSolrRequest)3 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 NamedList (org.apache.solr.common.util.NamedList)2 IOException (java.io.IOException)1 Map (java.util.Map)1 CharsRefBuilder (org.apache.lucene.util.CharsRefBuilder)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)1 SolrException (org.apache.solr.common.SolrException)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 Replica (org.apache.solr.common.cloud.Replica)1 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)1 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)1 DeleteUpdateCommand (org.apache.solr.update.DeleteUpdateCommand)1 UpdateShardHandler (org.apache.solr.update.UpdateShardHandler)1 Test (org.junit.Test)1