List of usage examples for org.apache.solr.client.solrj.request CoreAdminRequest createCore
public static CoreAdminResponse createCore(String name, String instanceDir, SolrClient client) throws SolrServerException, IOException
From source file:io.redlink.solrlib.standalone.SolrServerConnector.java
License:Apache License
@Override @SuppressWarnings("squid:S3776") protected void init(ExecutorService executorService) throws IOException, SolrServerException { Preconditions.checkState(initialized.compareAndSet(false, true)); Preconditions.checkArgument(Objects.nonNull(solrBaseUrl)); if (configuration.isDeployCores() && Objects.nonNull(configuration.getSolrHome())) { final Path solrHome = configuration.getSolrHome(); Files.createDirectories(solrHome); final Path libDir = solrHome.resolve("lib"); Files.createDirectories(libDir); try (HttpSolrClient solrClient = new HttpSolrClient.Builder(solrBaseUrl).build()) { for (SolrCoreDescriptor coreDescriptor : coreDescriptors) { final String coreName = coreDescriptor.getCoreName(); if (availableCores.containsKey(coreName)) { log.warn("CoreName-Clash: {} already initialized. Skipping {}", coreName, coreDescriptor.getClass()); continue; }/*from w ww . j a va 2 s . c o m*/ final String remoteName = createRemoteName(coreName); final Path coreHome = solrHome.resolve(remoteName); coreDescriptor.initCoreDirectory(coreHome, libDir); final Path corePropertiesFile = coreHome.resolve("core.properties"); // core.properties is created by the CreateCore-Command. Files.deleteIfExists(corePropertiesFile); if (coreDescriptor.getNumShards() > 1 || coreDescriptor.getReplicationFactor() > 1) { log.warn("Deploying {} to SolrServerConnector, ignoring config of shards={},replication={}", coreName, coreDescriptor.getNumShards(), coreDescriptor.getReplicationFactor()); } // Create or reload the core if (CoreAdminRequest.getStatus(remoteName, solrClient).getStartTime(remoteName) == null) { final CoreAdminResponse adminResponse = CoreAdminRequest.createCore(remoteName, coreHome.toAbsolutePath().toString(), solrClient); } else { final CoreAdminResponse adminResponse = CoreAdminRequest.reloadCore(remoteName, solrClient); } // schedule client-side core init final boolean isNewCore = findInNamedList( CoreAdminRequest.getStatus(remoteName, solrClient).getCoreStatus(remoteName), "index", "lastModified") == null; scheduleCoreInit(executorService, coreDescriptor, isNewCore); availableCores.put(coreName, coreDescriptor); } } } else { try (HttpSolrClient solrClient = new HttpSolrClient.Builder(solrBaseUrl).build()) { for (SolrCoreDescriptor coreDescriptor : coreDescriptors) { final String coreName = coreDescriptor.getCoreName(); if (availableCores.containsKey(coreName)) { log.warn("CoreName-Clash: {} already initialized. Skipping {}", coreName, coreDescriptor.getClass()); continue; } final String remoteName = createRemoteName(coreName); if (CoreAdminRequest.getStatus(remoteName, solrClient).getStartTime(remoteName) == null) { // Core does not exists log.warn("Collection {} (remote: {}) not available in Solr '{}' " + "but deployCores is set to false", coreName, remoteName, solrBaseUrl); } else { log.debug("Collection {} exists in Solr '{}' as {}", coreName, solrBaseUrl, remoteName); scheduleCoreInit(executorService, coreDescriptor, false); availableCores.put(coreName, coreDescriptor); } } } } }
From source file:org.act.index.server.MetaService.java
License:Apache License
@Override public int createCore(int coreId) { // TODO Auto-generated method stub try {//from w ww. ja v a2 s .co m if (indexServer.getSolrServers().containsKey(coreId)) return GlobalMessage.ISS_ERROR; String dir = indexServer.getUrl() + "/core" + String.valueOf(coreId); //LOG.debug("dir:" + dir); indexServer.addSolrServer(coreId); FileUtils.forceMkdir(new File(dir)); FileUtils.forceMkdir(new File(dir + "/conf")); String configPath = dir + "/conf/solrconfig.xml"; String schemaPath = dir + "/conf/schema.xml"; createSolrConfig(configPath); createSchema(schemaPath, coreId); //indexServer.addSolrServer(coreId); //CoreAdminRequest.createCore(String.valueOf(coreId), "core" // + String.valueOf(coreId), indexServer.getSolrServer()); CoreAdminRequest.createCore(String.valueOf(coreId), "core" + String.valueOf(coreId), indexServer.getSolrServer()); //CoreAdminRequest.createCore("10", "core10", server, configPath, schemaPath); FileUtils.forceMkdir(new File(dir + "/data")); FileUtils.forceMkdir(new File(dir + "/data/index")); SolrService service = new SolrService(indexServer.getSolrServer(coreId)); //solrServices.put(coreId, service); //int port = ServerParam.LOCAL_SERVER_PORT + serverId * ServerParam.MAX_CORE_COUNT_PER_SERVER + coreId + 1; int serverId = indexServer.getServerInfo().getServerId(); String ip = Inet4Address.getLocalHost().getHostAddress(); int port = indexServer.getServerAddr().getPort() + coreId + 1; LocateRegistry.createRegistry(port); String name = "rmi://" + ip + ":" + port + "/core" + coreId + "@server" + serverId; Naming.rebind(name, service); LOG.info("rmi:solrserver( " + name + ") is ready!"); } catch (SolrServerException e) { // TODO: handle exception e.printStackTrace(); } catch (IOException e) { // TODO: handle exception e.printStackTrace(); } return GlobalMessage.ISS_SUCCESS; }
From source file:org.act.index.server.MetaService.java
License:Apache License
public int createCoreWithNoSegment(int coreId) { // TODO Auto-generated method stub try {//ww w .j av a 2s . co m if (indexServer.getSolrServers().containsKey(coreId)) return GlobalMessage.ISS_ERROR; String dir = indexServer.getUrl() + "/core" + String.valueOf(coreId); //LOG.debug("dir:" + dir); indexServer.addSolrServer(coreId); FileUtils.forceMkdir(new File(dir)); FileUtils.forceMkdir(new File(dir + "/conf")); String configPath = dir + "/conf/solrconfig.xml"; String schemaPath = dir + "/conf/schema.xml"; createSolrConfig(configPath); createSchema(schemaPath, coreId); //indexServer.addSolrServer(coreId); //CoreAdminRequest.createCore(String.valueOf(coreId), "core" // + String.valueOf(coreId), indexServer.getSolrServer()); CoreAdminRequest.createCore(String.valueOf(coreId), "core" + String.valueOf(coreId), indexServer.getSolrServer()); //CoreAdminRequest.createCore("10", "core10", server, configPath, schemaPath); //FileUtils.forceMkdir(new File(dir + "/data")); //FileUtils.forceMkdir(new File(dir + "/data/index")); FileUtils.cleanDirectory(new File(dir + "/data/index")); SolrService service = new SolrService(indexServer.getSolrServer(coreId)); //solrServices.put(coreId, service); //int port = ServerParam.LOCAL_SERVER_PORT + serverId * ServerParam.MAX_CORE_COUNT_PER_SERVER + coreId + 1; int serverId = indexServer.getServerInfo().getServerId(); String ip = Inet4Address.getLocalHost().getHostAddress(); int port = indexServer.getServerAddr().getPort() + coreId + 1; LocateRegistry.createRegistry(port); String name = "rmi://" + ip + ":" + port + "/core" + coreId + "@server" + serverId; Naming.rebind(name, service); LOG.info("rmi:solrserver( " + name + ") is ready!"); } catch (SolrServerException e) { // TODO: handle exception e.printStackTrace(); } catch (IOException e) { // TODO: handle exception e.printStackTrace(); } return GlobalMessage.ISS_SUCCESS; }