Java源码示例:org.apache.solr.client.solrj.response.SolrPingResponse

示例1
private void pingSolr(int count, SolrClient solrClient) {
  try {
    logger.info("Pinging Solr server.");
    SolrPingResponse response = solrClient.ping();
    if (response.getStatus() == 0) {
      logger.info("Ping to Solr server is successful for worker=" + count);
    } else {
      logger.warn(
          String.format("Ping to Solr server failed. It would check again. worker=%d, collection=%s, " +
              "response=%s", count, collection, response));
    }
  } catch (Throwable t) {
    logger.warn(String.format(
        "Ping to Solr server failed. It would check again. worker=%d, collection=%s", count, collection), t);
  }
}
 
示例2
@Override
public StatusResult getBackendStatus() {

    try {
        SolrPingResponse ping = solrClient.ping();

        int statusCode = ping.getStatus();

        if(statusCode != 0) {
            return StatusResult.down().setDetail("status", statusCode);
        } else {
            return StatusResult.up().setDetail("status", statusCode);
        }

    } catch (SolrServerException | IOException e) {
        log.error("Cannot ping server");
        throw new SearchServerException("Cannot ping server", e);
    }
}
 
示例3
@Test
public void solrCloudPingTest() throws IOException, SolrServerException {
    // solrContainerUsage {
    // Create the solr container.
    SolrContainer container = new SolrContainer();

    // Start the container. This step might take some time...
    container.start();

    // Do whatever you want with the client ...
    SolrClient client = new Http2SolrClient.Builder("http://" + container.getContainerIpAddress() + ":" + container.getSolrPort() + "/solr").build();
    SolrPingResponse response = client.ping("dummy");

    // Stop the container.
    container.stop();
    // }
}
 
示例4
public String test() {
	try {
		if (StringUtils.isNotBlank(this.getProviderUrl())) {
			SolrServer httpSolrServer = new HttpSolrServer(this.getProviderUrl());
			SolrPingResponse ping = httpSolrServer.ping();
			String time = String.valueOf(ping.getElapsedTime());
			String[] args = {time};
			this.addActionMessage(this.getText("note.provider.success", args));
		}
	} catch (SolrServerException slr) {
		_logger.error("error in test", slr);
		this.addActionError(this.getText("error.connection"));
		return SUCCESS;
	} catch (Throwable t) {
		_logger.error("error in test", t);
		return FAILURE;
	}
	return SUCCESS;
}
 
示例5
private void waitUntilSolrIsUp() throws Exception {
  int maxTries = 30;
  boolean solrIsUp = false;
  String lastExceptionMessage = null;
  for (int tries = 1; tries < maxTries; tries++) {
    try {
      SolrClient solrClient = new LBHttpSolrClient.Builder()
        .withBaseSolrUrl(String.format("http://%s:%d/solr/%s_shard1_replica_n1",
          StoryDataRegistry.INSTANCE.getDockerHost(),
          StoryDataRegistry.INSTANCE.getSolrPort(),
          StoryDataRegistry.INSTANCE.getServiceLogsCollection()))
        .build();
      StoryDataRegistry.INSTANCE.setSolrClient(solrClient);
      SolrPingResponse pingResponse = solrClient.ping();
      if (pingResponse.getStatus() != 0) {
        LOG.info("Solr is not up yet, Retrying... ({} tries)", tries);
        Thread.sleep(2000);
      } else {
        solrIsUp = true;
        LOG.info("Solr is up and running");
        break;
      }
    } catch (Exception e) {
      LOG.info("Error occurred during pinging solr. Retrying... ({} tries)", tries);
      lastExceptionMessage = e.getMessage();
      Thread.sleep(2000);
    }
  }

  if (!solrIsUp) {
    throw new IllegalStateException(String.format("Solr is not up after %d tries. Exception: %s", maxTries, lastExceptionMessage));
  }
}
 
示例6
/**
 * Creates an instance of SolrSearch server allowing to avoid the schema validity check.
 * @param client SolrClient to connect to.
 * @param check true to perform local schema validity check against remote schema, false otherwise.
 */
protected SolrSearchServer(SolrClient client, boolean check) {

    if(SearchConfiguration.get(SearchConfiguration.SERVER_COLLECTION_AUTOCREATE, false)) {
        log.warn("AutoGeneration of solr collection is not implemented, use collection management tool instead");
    }

    solrClient = client;

    //In order to perform unit tests with mocked solrClient, we do not need to do the schema check.
    if(check && client != null) {
        try {
            final SolrPingResponse ping = solrClient.ping();
            if (ping.getStatus() == 0) {
                log.debug("Pinged Solr in {}", ping.getQTime());
            }
        } catch (SolrServerException | IOException e) {
            log.error("Cannot connect to solr server", e);
            throw new RuntimeException();
        }
        log.info("Connection to solr server successful");

        checkVersionAndSchema();
    } else {
        log.warn("Solr ping and schema validity check has been deactivated.");
    }
}
 
示例7
@Override
public SolrPingResponse ping() {
	return execute(new SolrCallback<SolrPingResponse>() {
		@Override
		public SolrPingResponse doInSolr(SolrClient solrClient) throws SolrServerException, IOException {
			return solrClient.ping();
		}
	});
}
 
示例8
public static boolean isSolrWebappPingOkRaw(HttpSolrClient client) throws Exception {
    SolrPing solrPing = new SolrPing();
    SolrPingResponse rsp = solrPing.process(client);
    int status = rsp.getStatus();
    if (status == 0) {
        if (Debug.verboseOn()) Debug.logVerbose("isSolrWebappPingOk: ping response status: " + status, module);
        return true;
    } else {
        Debug.logInfo("Solr: isSolrWebappPingOk: Solr webapp not pingable; status: " + status, module);
        return false;
    }
}
 
示例9
@Test
public void testEnabledSolrPing() throws Exception {
  SolrPing ping = new SolrPing();
  SolrPingResponse rsp = null;
  ping.setActionEnable();
  ping.process(getSolrClient());
  ping.removeAction();
  rsp = ping.process(getSolrClient());
  Assert.assertNotNull(rsp);
}
 
示例10
@Test(expected = SolrException.class)
public void testDisabledSolrPing() throws Exception {
  SolrPing ping = new SolrPing();
  SolrPingResponse rsp = null;
  ping.setActionDisable();
  try {
    ping.process(getSolrClient());
  } catch (Exception e) {
    throw new Exception("disable action failed!");
  }
  ping.setActionPing();
  rsp = ping.process(getSolrClient());
  // the above line should fail with a 503 SolrException.
  Assert.assertNotNull(rsp);
}
 
示例11
@Test
public void testPing() throws Exception {
  final String testCollection = "ping_test";
  CollectionAdminRequest.createCollection(testCollection, "conf", 2, 1).process(cluster.getSolrClient());
  cluster.waitForActiveCollection(testCollection, 2, 2);
  final SolrClient clientUnderTest = getRandomClient();

  final SolrPingResponse response = clientUnderTest.ping(testCollection);

  assertEquals("This should be OK", 0, response.getStatus());
}
 
示例12
public void testPingInClusterWithNoHealthCheck() throws Exception {

    MiniSolrCloudCluster miniCluster = new MiniSolrCloudCluster(NUM_SERVERS, createTempDir(), buildJettyConfig("/solr"));

    final CloudSolrClient cloudSolrClient = miniCluster.getSolrClient();

    try {
      assertNotNull(miniCluster.getZkServer());
      List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
      assertEquals(NUM_SERVERS, jettys.size());
      for (JettySolrRunner jetty : jettys) {
        assertTrue(jetty.isRunning());
      }

      // create collection
      String collectionName = "testSolrCloudCollection";
      String configName = "solrCloudCollectionConfig";
      miniCluster.uploadConfigSet(SolrTestCaseJ4.TEST_PATH().resolve("collection1").resolve("conf"), configName);
      CollectionAdminRequest.createCollection(collectionName, configName, NUM_SHARDS, REPLICATION_FACTOR)
          .process(miniCluster.getSolrClient());

      // Send distributed and non-distributed ping query
      SolrPingWithDistrib reqDistrib = new SolrPingWithDistrib();
      reqDistrib.setDistrib(true);
      SolrPingResponse rsp = reqDistrib.process(cloudSolrClient, collectionName);
      assertEquals(0, rsp.getStatus()); 
      assertTrue(rsp.getResponseHeader().getBooleanArg(("zkConnected")));

      
      SolrPing reqNonDistrib = new SolrPing();
      rsp = reqNonDistrib.process(cloudSolrClient, collectionName);
      assertEquals(0, rsp.getStatus());   
      assertTrue(rsp.getResponseHeader().getBooleanArg(("zkConnected")));

    }
    finally {
      miniCluster.shutdown();
    } 
  }
 
示例13
@Test
public void solrCloudTest() throws IOException, SolrServerException {
    try (SolrContainer container = new SolrContainer()) {
        container.start();
        SolrPingResponse response = getClient(container).ping("dummy");
        assertThat(response.getStatus(), is(0));
        assertThat(response.jsonStr(), containsString("zkConnected\":true"));
    }
}
 
示例14
@Test
public void solrStandaloneTest() throws IOException, SolrServerException {
    try (SolrContainer container = new SolrContainer().withZookeeper(false)) {
        container.start();
        SolrPingResponse response = getClient(container).ping("dummy");
        assertThat(response.getStatus(), is(0));
        assertThat(response.jsonStr(), containsString("zkConnected\":null"));
    }
}
 
示例15
@Override
public SolrPingResponse ping() throws SolrServerException, IOException {
  return respond(SolrPingResponse.class, new Command() {
    public void process() throws Exception {
      client().ping();
    }
  });
}
 
示例16
@Test
public void isReady_nonZeroResponseStatus() throws Exception {
	final SolrConfiguration config = mock(SolrConfiguration.class);

	SolrPingResponse response = mock(SolrPingResponse.class);
	when(response.getStatus()).thenReturn(1);

	SolrClient server = mock(SolrClient.class);
	when(server.ping()).thenReturn(response);

	StorageEngine engine = new SolrStorageEngine(config, server);
	assertFalse(engine.isReady());

	verify(server).ping();
}
 
示例17
@Test
public void isReady_zeroResponseStatus() throws Exception {
	final SolrConfiguration config = mock(SolrConfiguration.class);

	SolrPingResponse response = mock(SolrPingResponse.class);
	when(response.getStatus()).thenReturn(SolrStorageEngine.STATUS_OK);

	SolrClient server = mock(SolrClient.class);
	when(server.ping()).thenReturn(response);

	StorageEngine engine = new SolrStorageEngine(config, server);
	assertTrue(engine.isReady());

	verify(server).ping();
}
 
示例18
@Override
protected SolrPingResponse createResponse(SolrClient client) {
  return new SolrPingResponse();
}
 
示例19
@Override
public SolrPingResponse ping() throws SolrServerException, IOException {
  return new SolrPingResponse();
}
 
示例20
@Override
public SolrPingResponse ping() {
  return new SolrPingResponse();
}
 
示例21
@Override
public SolrPingResponse ping() throws SolrServerException, IOException {
  LOGGER.trace("ping");
  return server.ping();
}
 
示例22
@Override
public SolrPingResponse ping() {
  LOGGER.trace("ping");
  return new SolrPingResponse();
}
 
示例23
/**
 * Execute ping against SolrClient and return duration in msec
 * 
 * @return
 */
SolrPingResponse ping();
 
示例24
/**
 * Issues a ping request to check if the collection's replicas are alive
 *
 * @param collection collection to ping
 *
 * @return a {@link org.apache.solr.client.solrj.response.SolrPingResponse} containing the response
 *         from the server
 *
 * @throws IOException If there is a low-level I/O error.
 * @throws SolrServerException if there is an error on the server
 */
public SolrPingResponse ping(String collection) throws SolrServerException, IOException {
  return new SolrPing().process(this, collection);
}
 
示例25
/**
 * Issues a ping request to check if the server is alive
 *
 * @return a {@link org.apache.solr.client.solrj.response.SolrPingResponse} containing the response
 *         from the server
 *
 * @throws IOException If there is a low-level I/O error.
 * @throws SolrServerException if there is an error on the server
 */
public SolrPingResponse ping() throws SolrServerException, IOException {
  return new SolrPing().process(this, null);
}
 
示例26
/**
 * Issues a ping request to check if the server is alive
 * 
 * @throws IOException
 *           If there is a low-level I/O error.
 */
public SolrPingResponse ping() throws IOException, SolrServerException;