(CommandLine cli, SolrClient solrClient)
| 132 | } |
| 133 | } |
| 134 | |
| 135 | protected void createCore(CommandLine cli, SolrClient solrClient) throws Exception { |
| 136 | String coreName = cli.getOptionValue(COLLECTION_NAME_OPTION); |
| 137 | String solrUrl = CLIUtils.normalizeSolrUrl(cli); |
| 138 | |
| 139 | final String solrInstallDir = EnvUtils.getProperty("solr.install.dir"); |
| 140 | final String confDirName = |
| 141 | cli.getOptionValue(CONF_DIR_OPTION, DefaultValues.DEFAULT_CONFIG_SET); |
| 142 | |
| 143 | // we allow them to pass a directory instead of a configset name |
| 144 | Path configsetDir = Path.of(confDirName); |
| 145 | Path solrInstallDirPath = Path.of(solrInstallDir); |
| 146 | |
| 147 | if (!Files.isDirectory(configsetDir)) { |
| 148 | ensureConfDirExists(solrInstallDirPath, configsetDir); |
| 149 | } |
| 150 | printDefaultConfigsetWarningIfNecessary(cli); |
| 151 | |
| 152 | SystemInfoResponse sysResponse = (new SystemInfoRequest()).process(solrClient); |
| 153 | // usually same as solr home, but not always |
| 154 | String coreRootDirectory = sysResponse.getCoreRoot(); |
| 155 | |
| 156 | if (CLIUtils.safeCheckCoreExists( |
| 157 | solrUrl, coreName, cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION))) { |
| 158 | throw new IllegalArgumentException( |
| 159 | "\nCore '" |
| 160 | + coreName |
| 161 | + "' already exists!\nChecked core existence using Core API command"); |
| 162 | } |
| 163 | |
| 164 | Path coreInstanceDir = Path.of(coreRootDirectory, coreName); |
| 165 | Path confDir = getFullConfDir(solrInstallDirPath, configsetDir).resolve("conf"); |
| 166 | if (!Files.isDirectory(coreInstanceDir)) { |
| 167 | Files.createDirectories(coreInstanceDir); |
| 168 | if (!Files.isDirectory(coreInstanceDir)) { |
| 169 | throw new IOException( |
| 170 | "Failed to create new core instance directory: " + coreInstanceDir.toAbsolutePath()); |
| 171 | } |
| 172 | |
| 173 | PathUtils.copyDirectory(confDir, coreInstanceDir, StandardCopyOption.COPY_ATTRIBUTES); |
| 174 | |
| 175 | echoIfVerbose( |
| 176 | "\nCopying configuration to new core instance directory:\n" |
| 177 | + coreInstanceDir.toAbsolutePath()); |
| 178 | } |
| 179 | |
| 180 | echoIfVerbose("\nCreating new core '" + coreName + "' using V2 Cores API"); |
| 181 | |
| 182 | try { |
| 183 | var req = new CoresApi.CreateCore(); |
| 184 | req.setName(coreName); |
| 185 | req.setInstanceDir(coreName); |
| 186 | req.process(solrClient); |
| 187 | echo(String.format(Locale.ROOT, "\nCreated new core '%s'", coreName)); |
| 188 | |
| 189 | } catch (Exception e) { |
| 190 | /* create-core failed, cleanup the copied configset before propagating the error. */ |
| 191 | PathUtils.deleteDirectory(coreInstanceDir); |
no test coverage detected