Skip to content
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 to JAX-RS #3054

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion solr/api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dependencies {
runtimeOnly libs.slf4j.api

implementation libs.jakarta.ws.rsapi
implementation libs.fasterxml.jackson.core.annotations
api libs.fasterxml.jackson.core.annotations
api libs.swagger3.annotations.jakarta
implementation libs.semver4j.semver4j

Expand Down
4 changes: 2 additions & 2 deletions solr/api/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.8.1=jarValidation,testCompileClasspath,testRuntimeClasspath
com.carrotsearch:hppc:0.10.0=jarValidation,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.16.2=swaggerDeps
com.fasterxml.jackson.core:jackson-annotations:2.18.2=compileClasspath,jarValidation,runtimeClasspath,swaggerBuild,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.18.2=apiHelper,compileClasspath,jarValidation,runtimeClasspath,swaggerBuild,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-core:2.16.2=swaggerDeps
com.fasterxml.jackson.core:jackson-core:2.18.2=jarValidation,swaggerBuild,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.16.2=swaggerDeps
Expand All @@ -22,7 +22,7 @@ com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.16.2=swaggerDeps
com.fasterxml.jackson.module:jackson-module-jakarta-xmlbind-annotations:2.18.2=jarValidation,swaggerBuild,testRuntimeClasspath
com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.16.2=swaggerDeps
com.fasterxml.jackson:jackson-bom:2.16.2=swaggerDeps
com.fasterxml.jackson:jackson-bom:2.18.2=compileClasspath,jarValidation,runtimeClasspath,swaggerBuild,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson:jackson-bom:2.18.2=apiHelper,compileClasspath,jarValidation,runtimeClasspath,swaggerBuild,testCompileClasspath,testRuntimeClasspath
com.fasterxml.woodstox:woodstox-core:7.0.0=jarValidation,testRuntimeClasspath
com.github.ben-manes.caffeine:caffeine:3.1.8=annotationProcessor,errorprone,jarValidation,testAnnotationProcessor,testRuntimeClasspath
com.github.kevinstern:software-and-algorithms:1.0=annotationProcessor,errorprone,testAnnotationProcessor
Expand Down
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,71 @@
/*
* 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 {

// Map values are often exceptions on the server side, but often serialized as strings.
@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
Expand Up @@ -14,15 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.client.api.model;

package org.apache.solr.client.solrj.request.beans;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import java.util.Map;
import org.apache.solr.common.annotation.JsonProperty;
import org.apache.solr.common.util.ReflectMapWriter;

public class CreateCorePayload implements ReflectMapWriter {
public class CreateCoreParams {
@JsonProperty(required = true)
public String name;

Expand All @@ -40,21 +39,21 @@ public class CreateCorePayload implements ReflectMapWriter {

@JsonProperty public Boolean loadOnStartup;

// If our JsonProperty clone was more feature-rich here we could specify the property be called
// 'transient', but without that support it needs to be named something else to avoid conflicting
// with the 'transient' keyword in Java
@JsonProperty public Boolean isTransient;
@Schema(name = "isTransient")
@JsonProperty("transient")
public Boolean isTransient;

@JsonProperty public String shard;

@JsonProperty public String collection;

// TODO - what type is 'roles' expected to be?
@JsonProperty public List<String> roles;

@JsonProperty public String replicaType;

@JsonProperty public Map<String, Object> properties;
@JsonProperty public Map<String, String> properties;

@JsonProperty public Map<String, String> collectionProperties;

@JsonProperty public String coreNodeName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.client.api.model;

package org.apache.solr.client.solrj.request;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Date;
import org.apache.solr.common.util.NamedList;

public class CoreStatus {

private final NamedList<Object> response;

public CoreStatus(NamedList<Object> response) {
this.response = response;
}

public String getDataDirectory() {
return (String) response.get("dataDir");
}

public String getInstanceDirectory() {
return (String) response.findRecursive("instanceDir");
}

@Override
public String toString() {
return response.toString();
}

public Date getCoreStartTime() {
return (Date) response.get("startTime");
}
/** Response for {@link org.apache.solr.client.api.endpoint.CoreApis} 'create' API */
public class CreateCoreResponse extends SolrJerseyResponse {
@JsonProperty public String core;
}
4 changes: 2 additions & 2 deletions solr/benchmark/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# This file is expected to be part of source control.
com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.8.1=compileClasspath,jarValidation,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.carrotsearch:hppc:0.10.0=jarValidation,runtimeClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.18.2=jarValidation,runtimeClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.18.2=compileClasspath,jarValidation,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-core:2.18.2=jarValidation,runtimeClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.18.2=jarValidation,runtimeClasspath,testRuntimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.18.2=jarValidation,runtimeClasspath,testRuntimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.18.2=jarValidation,runtimeClasspath,testRuntimeClasspath
com.fasterxml.jackson.module:jackson-module-jakarta-xmlbind-annotations:2.18.2=jarValidation,runtimeClasspath,testRuntimeClasspath
com.fasterxml.jackson:jackson-bom:2.18.2=jarValidation,runtimeClasspath,testRuntimeClasspath
com.fasterxml.jackson:jackson-bom:2.18.2=compileClasspath,jarValidation,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.woodstox:woodstox-core:7.0.0=jarValidation,runtimeClasspath,testRuntimeClasspath
com.github.ben-manes.caffeine:caffeine:3.1.8=annotationProcessor,errorprone,jarValidation,runtimeClasspath,testAnnotationProcessor,testRuntimeClasspath
com.github.kevinstern:software-and-algorithms:1.0=annotationProcessor,errorprone,testAnnotationProcessor
Expand Down
22 changes: 10 additions & 12 deletions solr/core/src/java/org/apache/solr/cli/CLIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Contributor

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...

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 && Boolean.TRUE.equals(coreStatus.isLoading);
} 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
Expand Down
Loading
Loading