dsmiley commented on a change in pull request #264:
URL: https://github.com/apache/solr/pull/264#discussion_r697653753



##########
File path: solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
##########
@@ -342,7 +342,7 @@ private Path checkPathIsSafe(Path pathToCheck) throws 
IOException {
    */
   @Override
   public InputStream openResource(String resource) throws IOException {
-

Review comment:
       revert since you didn't need to touch this file

##########
File path: 
solr/core/src/test/org/apache/solr/schema/TestFallbackToLegacyManagedSchema.java
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.schema;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.solr.common.util.Utils;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.core.SolrResourceNotFoundException;
+import org.apache.solr.util.RestTestBase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Test updating a Managed Schema that is the legacy "managed-schema" instead 
of the
+ * default "managed-schema.xml" file properly falls back to "managed-schema"
+ */
+
+public class TestFallbackToLegacyManagedSchema extends RestTestBase {

Review comment:
       Why RestTestBase?  Oh, because, to easily post schema changes.  Maybe 
SolrJ does a fine job with that already? (not sure).  BTW SolrJ clients can be 
easily had via `SolrClient client = new 
EmbeddedSolrServer(h.getCoreContainer(), h.coreName);` in Solr tests.
   Eventually I'm hoping more of our tests might be SolrJ based in general.

##########
File path: solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
##########
@@ -89,13 +89,13 @@
   @Override public boolean isMutable() { return isMutable; }
 
   final String managedSchemaResourceName;
-  

Review comment:
       It appears all changes in this file, ManagedIndexSchema, are merely 
formatting so please revert.

##########
File path: 
solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java
##########
@@ -91,6 +95,63 @@ public void init(NamedList<?> args) {
   public String getSchemaResourceName(String cdResourceName) {
     return managedSchemaResourceName; // actually a guess; reality depends on 
the actual files in the config set :-(
   }
+  
+  /**
+   * Lookup the path to the managed schema, dealing with falling back to the
+   * legacy managed-schema file, instead of the expected managed-schema.xml 
file if the legacy file exists.
+   * 
+   * This method is duplicated in ManagedIndexSchema.
+   */
+  public String lookupZKManagedSchemaPath() {
+    final ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader)loader;
+    final ZkController zkController = zkLoader.getZkController();
+    final SolrZkClient zkClient = zkController.getZkClient();
+    String managedSchemaPath = zkLoader.getConfigSetZkPath() + "/" + 
managedSchemaResourceName;
+    final String legacyManagedSchemaPath = zkLoader.getConfigSetZkPath() + "/" 
+ ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME;
+    try {
+      // check if we are using the legacy managed-schema file name.
+      if (zkClient.exists(legacyManagedSchemaPath, true)){
+        log.debug("Legacy managed schema resource {} found - loading legacy 
managed schema instead of {} file."
+            , ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME, 
managedSchemaResourceName);
+        managedSchemaPath = legacyManagedSchemaPath;
+      }
+    } catch (KeeperException e) {
+      throw new RuntimeException(e);
+    } catch (InterruptedException e) {
+      // Restore the interrupted status
+      Thread.currentThread().interrupt();
+      throw new RuntimeException(e);
+    }
+    return managedSchemaPath;
+  }  
+  
+  /**
+   * Lookup the path to the managed schema, dealing with falling back to the
+   * legacy managed-schema file, instead of the expected managed-schema.xml 
file if the legacy file exists.
+   */
+  public Path lookupLocalManagedSchemaPath() {
+    final Path legacyManagedSchemaPath = 
Paths.get(loader.getConfigPath().toString(), 
ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME);
+    
+    Path managedSchemaPath = Paths.get(loader.getConfigPath().toString(), 
managedSchemaResourceName);
+    
+    // check if we are using the legacy managed-schema file name.    
+    if (Files.exists(legacyManagedSchemaPath)){
+      log.debug("Legacy managed schema resource {} found - loading legacy 
managed schema instead of {} file."
+          , ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME, 
managedSchemaResourceName);
+      managedSchemaPath = legacyManagedSchemaPath;
+    }
+    
+    File parentDir = managedSchemaPath.toFile().getParentFile(); // Do we need 
this clause?   A managed file that is in a dir that doesn't exist?

Review comment:
       Can you please not convert to File; isn't necessary.

##########
File path: solr/core/src/java/org/apache/solr/schema/SchemaManager.java
##########
@@ -428,17 +428,22 @@ private ManagedIndexSchema getFreshManagedSchema(SolrCore 
core) throws IOExcepti
 
     SolrResourceLoader resourceLoader = core.getResourceLoader();
     String name = core.getLatestSchema().getResourceName();

Review comment:
       I also prefer your suggestion; not too verbose I think.

##########
File path: 
solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java
##########
@@ -91,6 +95,63 @@ public void init(NamedList<?> args) {
   public String getSchemaResourceName(String cdResourceName) {
     return managedSchemaResourceName; // actually a guess; reality depends on 
the actual files in the config set :-(
   }
+  
+  /**
+   * Lookup the path to the managed schema, dealing with falling back to the
+   * legacy managed-schema file, instead of the expected managed-schema.xml 
file if the legacy file exists.
+   * 
+   * This method is duplicated in ManagedIndexSchema.
+   */
+  public String lookupZKManagedSchemaPath() {
+    final ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader)loader;
+    final ZkController zkController = zkLoader.getZkController();
+    final SolrZkClient zkClient = zkController.getZkClient();
+    String managedSchemaPath = zkLoader.getConfigSetZkPath() + "/" + 
managedSchemaResourceName;
+    final String legacyManagedSchemaPath = zkLoader.getConfigSetZkPath() + "/" 
+ ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME;
+    try {
+      // check if we are using the legacy managed-schema file name.
+      if (zkClient.exists(legacyManagedSchemaPath, true)){
+        log.debug("Legacy managed schema resource {} found - loading legacy 
managed schema instead of {} file."
+            , ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME, 
managedSchemaResourceName);
+        managedSchemaPath = legacyManagedSchemaPath;
+      }
+    } catch (KeeperException e) {
+      throw new RuntimeException(e);
+    } catch (InterruptedException e) {
+      // Restore the interrupted status
+      Thread.currentThread().interrupt();
+      throw new RuntimeException(e);
+    }
+    return managedSchemaPath;
+  }  
+  
+  /**
+   * Lookup the path to the managed schema, dealing with falling back to the
+   * legacy managed-schema file, instead of the expected managed-schema.xml 
file if the legacy file exists.
+   */
+  public Path lookupLocalManagedSchemaPath() {
+    final Path legacyManagedSchemaPath = 
Paths.get(loader.getConfigPath().toString(), 
ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME);
+    
+    Path managedSchemaPath = Paths.get(loader.getConfigPath().toString(), 
managedSchemaResourceName);
+    
+    // check if we are using the legacy managed-schema file name.    
+    if (Files.exists(legacyManagedSchemaPath)){
+      log.debug("Legacy managed schema resource {} found - loading legacy 
managed schema instead of {} file."
+          , ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME, 
managedSchemaResourceName);
+      managedSchemaPath = legacyManagedSchemaPath;
+    }
+    
+    File parentDir = managedSchemaPath.toFile().getParentFile(); // Do we need 
this clause?   A managed file that is in a dir that doesn't exist?

Review comment:
       Oh and I agree with your comment...  but can't we simply check that the 
Path exists as a simplification (no need to look at parent dir in particular)?




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

Reply via email to