epugh commented on code in PR #3054:
URL: https://github.com/apache/solr/pull/3054#discussion_r1925318212
##########
solr/core/src/java/org/apache/solr/cli/CLIUtils.java:
##########
@@ -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);
Review Comment:
these `var` are a lot more readable...
##########
solr/core/src/java/org/apache/solr/cli/CLIUtils.java:
##########
@@ -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);
Review Comment:
boo that we are string comparing versus using a boolean...
##########
solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java:
##########
@@ -92,32 +82,12 @@ public enum CoreAdminOperation implements CoreAdminOp {
CREATE_OP(
CREATE,
it -> {
- assert TestInjection.injectRandomDelayInCoreCreation();
Review Comment:
take it we don't need this in the future? Or a pattern we don't want to
continue?
##########
solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java:
##########
@@ -327,70 +298,65 @@ public boolean isExpensive() {
* @return - a named list of key/value pairs from the core.
* @throws IOException - LukeRequestHandler can throw an I/O exception
*/
- @SuppressWarnings({"unchecked", "rawtypes"})
- public static NamedList<Object> getCoreStatus(
+ public static CoreStatusResponse.SingleCoreData getCoreStatus(
CoreContainer cores, String cname, boolean isIndexInfoNeeded) throws
IOException {
- NamedList<Object> info = new SimpleOrderedMap<>();
-
+ final var info = new CoreStatusResponse.SingleCoreData();
if (cores.isCoreLoading(cname)) {
- info.add(NAME, cname);
- info.add("isLoaded", "false");
- info.add("isLoading", "true");
+ info.name = cname;
+ info.isLoaded = false;
+ info.isLoading = true;
} else {
if (!cores.isLoaded(cname)) { // Lazily-loaded core, fill in what we can.
// It would be a real mistake to load the cores just to get the status
CoreDescriptor desc = cores.getCoreDescriptor(cname);
if (desc != null) {
- info.add(NAME, desc.getName());
- info.add("instanceDir", desc.getInstanceDir());
+ info.name = desc.getName();
+ info.instanceDir = desc.getInstanceDir().toString();
// None of the following are guaranteed to be present in a
not-yet-loaded core.
String tmp = desc.getDataDir();
- if (StrUtils.isNotBlank(tmp)) info.add("dataDir", tmp);
+ if (StrUtils.isNotBlank(tmp)) info.dataDir = tmp;
tmp = desc.getConfigName();
- if (StrUtils.isNotBlank(tmp)) info.add("config", tmp);
+ if (StrUtils.isNotBlank(tmp)) info.config = tmp;
tmp = desc.getSchemaName();
- if (StrUtils.isNotBlank(tmp)) info.add("schema", tmp);
- info.add("isLoaded", "false");
+ if (StrUtils.isNotBlank(tmp)) info.schema = tmp;
+ info.isLoaded = false;
}
} else {
try (SolrCore core = cores.getCore(cname)) {
if (core != null) {
- info.add(NAME, core.getName());
- info.add("instanceDir", core.getInstancePath().toString());
- info.add("dataDir", normalizePath(core.getDataDir()));
- info.add("config", core.getConfigResource());
- info.add("schema", core.getSchemaResource());
- info.add("startTime", core.getStartTimeStamp());
- info.add("uptime", core.getUptimeMs());
+ info.name = core.getName();
Review Comment:
so much nicer
##########
solr/core/src/java/org/apache/solr/handler/admin/api/CreateCore.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * 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.handler.admin.api;
+
+import static org.apache.solr.cloud.ZkController.COLLECTION_PARAM_PREFIX;
+import static
org.apache.solr.common.params.CollectionAdminParams.PROPERTY_PREFIX;
+import static org.apache.solr.common.params.CommonAdminParams.ASYNC;
+import static org.apache.solr.common.params.CoreAdminParams.ACTION;
+import static org.apache.solr.common.params.CoreAdminParams.ROLES;
+import static org.apache.solr.handler.admin.CoreAdminHandler.paramToProp;
+import static
org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import jakarta.inject.Inject;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.solr.client.api.endpoint.CoreApis;
+import org.apache.solr.client.api.model.CreateCoreParams;
+import org.apache.solr.client.api.model.CreateCoreResponse;
+import org.apache.solr.cloud.ZkController;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.CollectionUtil;
+import org.apache.solr.common.util.PropertiesUtil;
+import org.apache.solr.common.util.StrUtils;
+import org.apache.solr.common.util.Utils;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.handler.admin.CoreAdminHandler;
+import org.apache.solr.jersey.PermissionName;
+import org.apache.solr.jersey.SolrJacksonMapper;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.util.TestInjection;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * V2 API for creating a new core on the receiving node.
+ *
+ * <p>This API (POST /api/cores {...}) is analogous to the v1
/admin/cores?action=CREATE command.
+ */
+public class CreateCore extends CoreAdminAPIBase implements CoreApis.Create {
+ private static final Logger log =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @Inject
+ public CreateCore(
+ CoreContainer coreContainer,
+ CoreAdminHandler.CoreAdminAsyncTracker coreAdminAsyncTracker,
+ SolrQueryRequest solrQueryRequest,
+ SolrQueryResponse solrQueryResponse) {
+ super(coreContainer, coreAdminAsyncTracker, solrQueryRequest,
solrQueryResponse);
+ }
+
+ @Override
+ @PermissionName(CORE_EDIT_PERM)
+ public CreateCoreResponse createCore(CreateCoreParams requestBody) throws
Exception {
+ final var response = instantiateJerseyResponse(CreateCoreResponse.class);
+
+ assert TestInjection.injectRandomDelayInCoreCreation();
+ ensureRequiredRequestBodyProvided(requestBody);
+ ensureRequiredParameterProvided("name", requestBody.name);
+
+ return handlePotentiallyAsynchronousTask(
+ response,
+ requestBody.name,
+ requestBody.async,
+ "create",
+ () -> {
+ return doCreate(requestBody, response);
+ });
+ }
+
+ private CreateCoreResponse doCreate(CreateCoreParams requestBody,
CreateCoreResponse response) {
+ assert TestInjection.injectRandomDelayInCoreCreation();
Review Comment:
Huh.. Okay, maybe thsi line explains why the other had it removed!
##########
solr/core/src/java/org/apache/solr/cli/CLIUtils.java:
##########
@@ -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);
Review Comment:
I feel like I see boolean `true` used elsewhere for `isLoading`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]