Remove support for Solr as it is not compatible with Jetty 11

Closes gh-31054
This commit is contained in:
Andy Wilkinson
2022-05-18 11:28:46 +01:00
parent c4beca3e01
commit 96c2d08fc4
23 changed files with 2 additions and 705 deletions

View File

@@ -1,136 +0,0 @@
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.solr;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.BaseHttpSolrClient.RemoteSolrException;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.common.params.CoreAdminParams;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.Status;
/**
* {@link HealthIndicator} for Apache Solr.
*
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Markus Schuch
* @author Phillip Webb
* @since 2.0.0
*/
public class SolrHealthIndicator extends AbstractHealthIndicator {
private static final int HTTP_NOT_FOUND_STATUS = 404;
private final SolrClient solrClient;
private volatile StatusCheck statusCheck;
public SolrHealthIndicator(SolrClient solrClient) {
super("Solr health check failed");
this.solrClient = solrClient;
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
int statusCode = initializeStatusCheck();
Status status = (statusCode != 0) ? Status.DOWN : Status.UP;
builder.status(status).withDetail("status", statusCode).withDetail("detectedPathType",
this.statusCheck.getPathType());
}
private int initializeStatusCheck() throws Exception {
StatusCheck statusCheck = this.statusCheck;
if (statusCheck != null) {
// Already initialized
return statusCheck.getStatus(this.solrClient);
}
try {
return initializeStatusCheck(new RootStatusCheck());
}
catch (RemoteSolrException ex) {
// 404 is thrown when SolrClient has a baseUrl pointing to a particular core.
if (ex.code() == HTTP_NOT_FOUND_STATUS) {
return initializeStatusCheck(new ParticularCoreStatusCheck());
}
throw ex;
}
}
private int initializeStatusCheck(StatusCheck statusCheck) throws Exception {
int result = statusCheck.getStatus(this.solrClient);
this.statusCheck = statusCheck;
return result;
}
/**
* Strategy used to perform the status check.
*/
private abstract static class StatusCheck {
private final String pathType;
StatusCheck(String pathType) {
this.pathType = pathType;
}
abstract int getStatus(SolrClient client) throws Exception;
String getPathType() {
return this.pathType;
}
}
/**
* {@link StatusCheck} used when {@code baseUrl} points to the root context.
*/
private static class RootStatusCheck extends StatusCheck {
RootStatusCheck() {
super("root");
}
@Override
public int getStatus(SolrClient client) throws Exception {
CoreAdminRequest request = new CoreAdminRequest();
request.setAction(CoreAdminParams.CoreAdminAction.STATUS);
return request.process(client).getStatus();
}
}
/**
* {@link StatusCheck} used when {@code baseUrl} points to the particular core.
*/
private static class ParticularCoreStatusCheck extends StatusCheck {
ParticularCoreStatusCheck() {
super("particular core");
}
@Override
public int getStatus(SolrClient client) throws Exception {
return client.ping().getStatus();
}
}
}

View File

@@ -1,20 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Actuator support for Solr.
*/
package org.springframework.boot.actuate.solr;

View File

@@ -1,145 +0,0 @@
/*
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.solr;
import java.io.IOException;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.BaseHttpSolrClient.RemoteSolrException;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.response.SolrPingResponse;
import org.apache.solr.common.util.NamedList;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
/**
* Tests for {@link SolrHealthIndicator}
*
* @author Andy Wilkinson
* @author Markus Schuch
* @author Phillip Webb
*/
class SolrHealthIndicatorTests {
@Test
void healthWhenSolrStatusUpAndBaseUrlPointsToRootReturnsUp() throws Exception {
SolrClient solrClient = mock(SolrClient.class);
given(solrClient.request(any(CoreAdminRequest.class), isNull())).willReturn(mockResponse(0));
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
assertHealth(healthIndicator, Status.UP, 0, "root");
then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
then(solrClient).shouldHaveNoMoreInteractions();
}
@Test
void healthWhenSolrStatusDownAndBaseUrlPointsToRootReturnsDown() throws Exception {
SolrClient solrClient = mock(SolrClient.class);
given(solrClient.request(any(CoreAdminRequest.class), isNull())).willReturn(mockResponse(400));
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
assertHealth(healthIndicator, Status.DOWN, 400, "root");
then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
then(solrClient).shouldHaveNoMoreInteractions();
}
@Test
void healthWhenSolrStatusUpAndBaseUrlPointsToParticularCoreReturnsUp() throws Exception {
SolrClient solrClient = mock(SolrClient.class);
given(solrClient.request(any(CoreAdminRequest.class), isNull()))
.willThrow(new RemoteSolrException("mock", 404, "", null));
given(solrClient.ping()).willReturn(mockPingResponse(0));
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
assertHealth(healthIndicator, Status.UP, 0, "particular core");
then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
then(solrClient).should().ping();
then(solrClient).shouldHaveNoMoreInteractions();
}
@Test
void healthWhenSolrStatusDownAndBaseUrlPointsToParticularCoreReturnsDown() throws Exception {
SolrClient solrClient = mock(SolrClient.class);
given(solrClient.request(any(CoreAdminRequest.class), isNull()))
.willThrow(new RemoteSolrException("mock", 404, "", null));
given(solrClient.ping()).willReturn(mockPingResponse(400));
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
assertHealth(healthIndicator, Status.DOWN, 400, "particular core");
then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
then(solrClient).should().ping();
then(solrClient).shouldHaveNoMoreInteractions();
}
@Test
void healthWhenSolrConnectionFailsReturnsDown() throws Exception {
SolrClient solrClient = mock(SolrClient.class);
given(solrClient.request(any(CoreAdminRequest.class), isNull()))
.willThrow(new IOException("Connection failed"));
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat((String) health.getDetails().get("error")).contains("Connection failed");
then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
then(solrClient).shouldHaveNoMoreInteractions();
}
@Test
void healthWhenMakingMultipleCallsRemembersStatusStrategy() throws Exception {
SolrClient solrClient = mock(SolrClient.class);
given(solrClient.request(any(CoreAdminRequest.class), isNull()))
.willThrow(new RemoteSolrException("mock", 404, "", null));
given(solrClient.ping()).willReturn(mockPingResponse(0));
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
healthIndicator.health();
then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
then(solrClient).should().ping();
then(solrClient).shouldHaveNoMoreInteractions();
healthIndicator.health();
then(solrClient).should(times(2)).ping();
then(solrClient).shouldHaveNoMoreInteractions();
}
private void assertHealth(SolrHealthIndicator healthIndicator, Status expectedStatus, int expectedStatusCode,
String expectedPathType) {
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(expectedStatus);
assertThat(health.getDetails().get("status")).isEqualTo(expectedStatusCode);
assertThat(health.getDetails().get("detectedPathType")).isEqualTo(expectedPathType);
}
private NamedList<Object> mockResponse(int status) {
NamedList<Object> response = new NamedList<>();
NamedList<Object> headers = new NamedList<>();
headers.add("status", status);
response.add("responseHeader", headers);
return response;
}
private SolrPingResponse mockPingResponse(int status) {
SolrPingResponse pingResponse = new SolrPingResponse();
pingResponse.setResponse(mockResponse(status));
return pingResponse;
}
}