3131import org .apache .solr .cloud .ZkController ;
3232import org .apache .solr .common .ConfigNode ;
3333import org .apache .solr .common .SolrException ;
34- import org .apache .solr .common .util .EnvUtils ;
3534import org .apache .solr .common .util .NamedList ;
35+ import org .apache .solr .common .util .StrUtils ;
3636import org .apache .solr .handler .admin .ConfigSetsHandler ;
3737import org .apache .solr .schema .IndexSchema ;
3838import org .apache .solr .schema .IndexSchemaFactory ;
@@ -85,17 +85,22 @@ private static ConfigSetService instantiate(CoreContainer coreContainer) {
8585 }
8686
8787 private void bootstrapConfigSet (CoreContainer coreContainer ) {
88- // bootstrap _default conf and solr.configset.bootstrap.confdir if specified.
88+ // bootstrap _default conf, bootstrap_confdir and bootstrap_conf if provided via system property
8989 try {
9090 // _default conf
9191 bootstrapDefaultConf ();
9292
93- // solr.configset.bootstrap.confdir
94- String confDir = EnvUtils .getProperty ("solr.configset.bootstrap.confdir " );
93+ // bootstrap_confdir
94+ String confDir = System .getProperty ("bootstrap_confdir " );
9595 if (confDir != null ) {
9696 bootstrapConfDir (confDir );
9797 }
9898
99+ // bootstrap_conf
100+ boolean boostrapConf = Boolean .getBoolean ("bootstrap_conf" );
101+ if (boostrapConf == true ) {
102+ bootstrapConf (coreContainer );
103+ }
99104 } catch (IOException e ) {
100105 throw new SolrException (
101106 SolrException .ErrorCode .SERVER_ERROR , "Config couldn't be uploaded " , e );
@@ -109,22 +114,23 @@ private void bootstrapDefaultConf() throws IOException {
109114 log .warn (
110115 "The _default configset could not be uploaded. Please provide 'solr.configset.default.confdir' parameter that points to a configset {} {}" ,
111116 "intended to be the default. Current 'solr.configset.default.confdir' value:" ,
112- EnvUtils .getProperty (SolrDispatchFilter .SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE ));
117+ System .getProperty (SolrDispatchFilter .SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE ));
113118 } else {
114119 this .uploadConfig (ConfigSetsHandler .DEFAULT_CONFIGSET_NAME , configDirPath );
115120 }
116121 }
117122 }
118123
119124 private void bootstrapConfDir (String confDir ) throws IOException {
120- Path configPath = resolvePathWithSolrInstallDir (confDir );
121-
125+ Path configPath = Path .of (confDir );
122126 if (!Files .isDirectory (configPath )) {
123127 throw new IllegalArgumentException (
124- "solr.configset.bootstrap.confdir must be a directory of configuration files, configPath: "
128+ "bootstrap_confdir must be a directory of configuration files, configPath: "
125129 + configPath );
126130 }
127- String confName = EnvUtils .getProperty ("solr.collection.config.name" , "configuration1" );
131+ String confName =
132+ System .getProperty (
133+ ZkController .COLLECTION_PARAM_PREFIX + ZkController .CONFIGNAME_PROP , "configuration1" );
128134 this .uploadConfig (confName , configPath );
129135 }
130136
@@ -133,23 +139,23 @@ private void bootstrapConfDir(String confDir) throws IOException {
133139 * sysprop "solr.configset.default.confdir". If not found, tries to find the _default dir relative
134140 * to the sysprop "solr.install.dir". Returns null if not found anywhere.
135141 *
142+ * @lucene.internal
136143 * @see SolrDispatchFilter#SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE
137144 */
138145 public static Path getDefaultConfigDirPath () {
139146 String confDir =
140- EnvUtils .getProperty (SolrDispatchFilter .SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE );
147+ System .getProperty (SolrDispatchFilter .SOLR_CONFIGSET_DEFAULT_CONFDIR_ATTRIBUTE );
141148 if (confDir != null ) {
142- Path path = resolvePathWithSolrInstallDir (confDir );
149+ Path path = Path . of (confDir );
143150 if (Files .exists (path )) {
144151 return path ;
145152 }
146153 }
147154
148- String installDir = EnvUtils .getProperty (SolrDispatchFilter .SOLR_INSTALL_DIR_ATTRIBUTE );
155+ String installDir = System .getProperty (SolrDispatchFilter .SOLR_INSTALL_DIR_ATTRIBUTE );
149156 if (installDir != null ) {
150- Path installPath = resolvePathWithSolrInstallDir (installDir );
151157 Path subPath = Path .of ("server" , "solr" , "configsets" , "_default" , "conf" );
152- Path path = installPath .resolve (subPath );
158+ Path path = Path . of ( installDir ) .resolve (subPath );
153159 if (Files .exists (path )) {
154160 return path ;
155161 }
@@ -158,27 +164,6 @@ public static Path getDefaultConfigDirPath() {
158164 return null ;
159165 }
160166
161- /**
162- * Resolves a path string into a Path object, handling both absolute and relative paths. If the
163- * path is relative then it resolves it against Solr installation directory by looking up the
164- * solr.install.dir system property.
165- *
166- * @param pathStr The path of the directory to resolve
167- * @return The resolved Path object
168- * @see SolrDispatchFilter#SOLR_INSTALL_DIR_ATTRIBUTE
169- */
170- public static Path resolvePathWithSolrInstallDir (String pathStr ) {
171- Path path = Path .of (pathStr );
172-
173- // Convert to absolute path if it's relative
174- if (!path .isAbsolute ()) {
175- String installDir = EnvUtils .getProperty (SolrDispatchFilter .SOLR_INSTALL_DIR_ATTRIBUTE );
176- path = Path .of (installDir ).resolve (path ).normalize ();
177- }
178-
179- return path ;
180- }
181-
182167 // Order is important here since "confDir" may be
183168 // 1> a full path to the parent of a solrconfig.xml or parent of /conf/solrconfig.xml
184169 // 2> one of the canned config sets only, e.g. _default
@@ -213,6 +198,28 @@ public static Path getConfigsetPath(String confDir, String configSetDir) {
213198 Path .of (configSetDir , confDir , "conf" , "solrconfig.xml" ).normalize ().toAbsolutePath ()));
214199 }
215200
201+ /** If in SolrCloud mode, upload configSets for each SolrCore in solr.xml. */
202+ public static void bootstrapConf (CoreContainer cc ) throws IOException {
203+ // List<String> allCoreNames = cfg.getAllCoreNames();
204+ List <CoreDescriptor > cds = cc .getCoresLocator ().discover (cc );
205+
206+ if (log .isInfoEnabled ()) {
207+ log .info (
208+ "bootstrapping config for {} cores into ZooKeeper using solr.xml from {}" ,
209+ cds .size (),
210+ cc .getSolrHome ());
211+ }
212+
213+ for (CoreDescriptor cd : cds ) {
214+ String coreName = cd .getName ();
215+ String confName = cd .getCollectionName ();
216+ if (StrUtils .isNullOrEmpty (confName )) confName = coreName ;
217+ Path udir = cd .getInstanceDir ().resolve ("conf" );
218+ log .info ("Uploading directory {} with name {} for solrCore {}" , udir , confName , coreName );
219+ cc .getConfigSetService ().uploadConfig (confName , udir );
220+ }
221+ }
222+
216223 /**
217224 * Load the ConfigSet for a core
218225 *
0 commit comments