-
Notifications
You must be signed in to change notification settings - Fork 692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SOLR-16391: Convert create-core, core-status, /luke to JAX-RS #3054
base: main
Are you sure you want to change the base?
Changes from 8 commits
9bd4177
f21a7ff
72d5e2a
4b3f561
efc080a
faaf869
d13f62f
420a752
1f92fb8
8cc55d6
ba14d85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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.apache.solr.client.api.endpoint; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.QueryParam; | ||
import org.apache.solr.client.api.model.CoreStatusResponse; | ||
import org.apache.solr.client.api.model.CreateCoreParams; | ||
import org.apache.solr.client.api.model.CreateCoreResponse; | ||
|
||
public interface CoreApis { | ||
|
||
/** V2 API definition for creating a core on the receiving Solr node */ | ||
@Path("/cores") | ||
interface Create { | ||
@POST | ||
@Operation(summary = "Create a new core on the receiving Solr node.", tags = "cores") | ||
CreateCoreResponse createCore(CreateCoreParams requestBody) throws Exception; | ||
} | ||
|
||
@Path("/cores") | ||
interface GetStatus { | ||
|
||
@GET | ||
@Operation(summary = "Fetch status info for all cores hosted on this node.", tags = "cores") | ||
CoreStatusResponse getAllCoreStatus(@QueryParam("indexInfo") Boolean indexInfo) | ||
throws Exception; | ||
|
||
@GET | ||
@Operation( | ||
summary = "Fetch status info for the core hosted on this node with the specified name.", | ||
tags = "cores") | ||
@Path("/{coreName}") | ||
CoreStatusResponse getCoreStatus( | ||
@PathParam("coreName") String coreName, @QueryParam("indexInfo") Boolean indexInfo) | ||
throws Exception; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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.apache.solr.client.api.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
public class CoreStatusResponse extends SolrJerseyResponse { | ||
|
||
// NOCOMMIT In the v1 code this is a Map of Exception instances by core name. How are exceptions | ||
// serialized out by things though, that's what I'd have to mirror on the v2 side. | ||
@JsonProperty public Map<String, Object> initFailures; | ||
|
||
@JsonProperty public Map<String, SingleCoreData> status; | ||
|
||
public static class SingleCoreData { | ||
@JsonProperty public String name; | ||
|
||
@JsonProperty public Boolean isLoaded; | ||
@JsonProperty public Boolean isLoading; | ||
|
||
@JsonProperty public String instanceDir; | ||
@JsonProperty public String dataDir; | ||
@JsonProperty public String config; | ||
@JsonProperty public String schema; | ||
@JsonProperty public Date startTime; | ||
@JsonProperty public Long uptime; | ||
@JsonProperty public String lastPublished; | ||
@JsonProperty public Integer configVersion; | ||
@JsonProperty public CloudDetails cloud; | ||
@JsonProperty public IndexDetails index; | ||
} | ||
|
||
public static class CloudDetails { | ||
@JsonProperty public String collection; | ||
@JsonProperty public String shard; | ||
@JsonProperty public String replica; | ||
@JsonProperty public String replicaType; // TODO enum? | ||
} | ||
|
||
public static class IndexDetails { | ||
@JsonProperty public Integer numDocs; | ||
@JsonProperty public Integer maxDoc; | ||
@JsonProperty public Integer deletedDocs; | ||
@JsonProperty public Long version; | ||
@JsonProperty public Integer segmentCount; | ||
@JsonProperty public Boolean current; | ||
@JsonProperty public Boolean hasDeletions; | ||
@JsonProperty public String directory; | ||
@JsonProperty public String segmentsFile; | ||
@JsonProperty public Long segmentsFileSizeInBytes; | ||
@JsonProperty public Map<String, String> userData; | ||
@JsonProperty public Date lastModified; | ||
@JsonProperty public Long sizeInBytes; | ||
@JsonProperty public String size; // Human readable representation of 'sizeInBytes' | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ | |
|
||
import static org.apache.solr.common.SolrException.ErrorCode.FORBIDDEN; | ||
import static org.apache.solr.common.SolrException.ErrorCode.UNAUTHORIZED; | ||
import static org.apache.solr.common.params.CommonParams.NAME; | ||
import static org.apache.solr.common.params.CommonParams.SYSTEM_INFO_PATH; | ||
|
||
import java.io.IOException; | ||
|
@@ -45,7 +44,7 @@ | |
import org.apache.solr.client.solrj.impl.Http2SolrClient; | ||
import org.apache.solr.client.solrj.impl.SolrZkClientTimeout; | ||
import org.apache.solr.client.solrj.request.CollectionAdminRequest; | ||
import org.apache.solr.client.solrj.request.CoreAdminRequest; | ||
import org.apache.solr.client.solrj.request.CoresApi; | ||
import org.apache.solr.client.solrj.request.GenericSolrRequest; | ||
import org.apache.solr.common.SolrException; | ||
import org.apache.solr.common.cloud.SolrZkClient; | ||
|
@@ -321,16 +320,15 @@ public static boolean safeCheckCoreExists(String solrUrl, String coreName, Strin | |
final int clamPeriodForStatusPollMs = 1000; | ||
Thread.sleep(clamPeriodForStatusPollMs); | ||
} | ||
NamedList<Object> existsCheckResult = | ||
CoreAdminRequest.getStatus(coreName, solrClient).getResponse(); | ||
NamedList<Object> status = (NamedList<Object>) existsCheckResult.get("status"); | ||
NamedList<Object> coreStatus = (NamedList<Object>) status.get(coreName); | ||
Map<String, Object> failureStatus = | ||
(Map<String, Object>) existsCheckResult.get("initFailures"); | ||
String errorMsg = (String) failureStatus.get(coreName); | ||
final boolean hasName = coreStatus != null && coreStatus.get(NAME) != null; | ||
exists = hasName || errorMsg != null; | ||
wait = hasName && errorMsg == null && "true".equals(coreStatus.get("isLoading")); | ||
final var coreStatusReq = new CoresApi.GetCoreStatus(coreName); | ||
final var coreStatusRsp = coreStatusReq.process(solrClient).getParsed(); | ||
final var coreStatusByName = coreStatusRsp.status; | ||
final var coreStatus = coreStatusByName.get(coreName); | ||
final var failureStatus = coreStatusRsp.initFailures; | ||
final var initFailureForCore = failureStatus.get(coreName); | ||
final boolean hasName = coreStatus != null && coreStatus.name != null; | ||
exists = hasName || initFailureForCore != null; | ||
wait = hasName && initFailureForCore == null && "true".equals(coreStatus.isLoading); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. boo that we are string comparing versus using a boolean... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like I see boolean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} while (wait && System.nanoTime() - startWaitAt < MAX_WAIT_FOR_CORE_LOAD_NANOS); | ||
} catch (Exception exc) { | ||
// just ignore it since we're only interested in a positive result here | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these
var
are a lot more readable...