List of usage examples for org.apache.solr.client.solrj.request CoreAdminRequest createCore
public static CoreAdminResponse createCore(String name, String instanceDir, SolrClient client, String configFile, String schemaFile, String dataDir, String tlogDir) throws SolrServerException, IOException
From source file:com.github.fengtan.sophie.toolbars.CoresToolbar.java
License:Open Source License
/** * Populate toolbar with buttons.// ww w .ja v a 2 s . c o m * * @param composite * Parent composite. */ private void initToolbar(final Composite composite) { Display display = composite.getDisplay(); ClassLoader loader = getClass().getClassLoader(); // Instantiate toolbar. ToolBar toolBar = new ToolBar(composite, SWT.BORDER); // Instantiate images. imgRefresh = new Image(display, loader.getResourceAsStream("toolbar/refresh.png")); imgAdd = new Image(display, loader.getResourceAsStream("toolbar/add.png")); imgDelete = new Image(display, loader.getResourceAsStream("toolbar/delete.png")); imgRename = new Image(display, loader.getResourceAsStream("toolbar/rename.png")); imgSwap = new Image(display, loader.getResourceAsStream("toolbar/swap.png")); imgReload = new Image(display, loader.getResourceAsStream("toolbar/restore.png")); imgReloadAll = new Image(display, loader.getResourceAsStream("toolbar/restore.png")); // Instantiate buttons. itemRefresh = new ToolItem(toolBar, SWT.PUSH); itemRefresh.setImage(imgRefresh); itemRefresh.setText("Refresh"); itemRefresh.setToolTipText("Refresh list of cores"); itemRefresh.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { try { table.refresh(); } catch (SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to refresh list of cores", e)); } } }); new ToolItem(toolBar, SWT.SEPARATOR); itemAdd = new ToolItem(toolBar, SWT.PUSH); itemAdd.setImage(imgAdd); itemAdd.setText("Add"); itemAdd.setToolTipText("Add new core"); itemAdd.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { String[] labels = new String[] { "Name:", "Instance Directory:", "Config file:", "Schema file:", "Data Directory:", "Transaction log directory:" }; String[] defaultValues = new String[] { "collectionX", "/path/to/solr/collectionX", "solrconfig.xml", "schema.xml", "/path/to/solr/collectionX/data", "/path/to/solr/collectionX/tlog" }; MultipleInputDialog dialog = new MultipleInputDialog(composite.getShell(), "Add new core", labels, defaultValues); dialog.open(); if (dialog.getReturnCode() != IDialogConstants.OK_ID) { return; } try { CoreAdminRequest.createCore(dialog.getValue(0), dialog.getValue(1), Sophie.client, dialog.getValue(2), dialog.getValue(3), dialog.getValue(4), dialog.getValue(5)); table.refresh(); } catch (SolrServerException | IOException | SolrException | SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to add new core \"" + dialog.getValue(0) + "\"", e)); } } }); itemDelete = new ToolItem(toolBar, SWT.PUSH); itemDelete.setImage(imgDelete); itemDelete.setText("Delete"); itemDelete.setToolTipText("Delete core"); itemDelete.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { String coreName = table.getSelectedCore(); MessageBox messageBox = new MessageBox(composite.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); messageBox.setText("Delete core"); messageBox.setMessage("Do you really want to delete this core (\"" + coreName + "\") ?"); int response = messageBox.open(); if (response == SWT.YES) { try { CoreAdminRequest.unloadCore(coreName, Sophie.client); table.refresh(); } catch (SolrServerException | IOException | SolrException | SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to delete core \"" + coreName + "\"", e)); } } } }); itemDelete.setEnabled(false); itemRename = new ToolItem(toolBar, SWT.PUSH); itemRename.setImage(imgRename); itemRename.setText("Rename"); itemRename.setToolTipText("Rename core"); itemRename.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { String oldCoreName = table.getSelectedCore(); InputDialog newCoreName = new InputDialog(composite.getShell(), "Rename core", "New name (\"" + oldCoreName + "\"):", oldCoreName, null); newCoreName.open(); if (newCoreName.getReturnCode() != IDialogConstants.OK_ID) { return; } try { CoreAdminRequest.renameCore(oldCoreName, newCoreName.getValue(), Sophie.client); table.refresh(); } catch (SolrServerException | IOException | SolrException | SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException( "Unable to rename core \"" + oldCoreName + "\" into \"" + newCoreName + "\"", e)); } } }); itemRename.setEnabled(false); new ToolItem(toolBar, SWT.SEPARATOR); itemSwap = new ToolItem(toolBar, SWT.PUSH); itemSwap.setImage(imgSwap); itemSwap.setText("Swap"); itemSwap.setToolTipText("Swap cores"); itemSwap.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { String coreName = table.getSelectedCore(); Map<String, NamedList<Object>> cores; try { cores = SolrUtils.getCores(); } catch (SophieException e) { Sophie.log.error("Unable to suggest list of cores", e); cores = Collections.emptyMap(); } Object[] coreObjects = cores.keySet().toArray(); String[] coreStrings = Arrays.copyOf(coreObjects, coreObjects.length, String[].class); CComboDialog dialog = new CComboDialog(composite.getShell(), "Swap cores", "Swap core \"" + coreName + "\" with:", coreStrings, null); dialog.open(); if (dialog.getReturnCode() != IDialogConstants.OK_ID) { return; } CoreAdminRequest request = new CoreAdminRequest(); request.setCoreName(coreName); request.setOtherCoreName(dialog.getValue()); request.setAction(CoreAdminAction.SWAP); try { request.process(Sophie.client); table.refresh(); } catch (SolrServerException | IOException | SolrException | SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException( "Unable to swap cores \"" + coreName + "\" and \"" + dialog.getValue() + "\"", e)); } } }); itemSwap.setEnabled(false); itemReload = new ToolItem(toolBar, SWT.PUSH); itemReload.setImage(imgReload); itemReload.setText("Reload"); itemReload.setToolTipText( "Reload core - this will reload any configuration changes you may have made to solrconfig.xml or schema.xml"); itemReload.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { String coreName = table.getSelectedCore(); try { CoreAdminRequest.reloadCore(coreName, Sophie.client); table.refresh(); } catch (SolrServerException | IOException | SolrException | SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to reload core \"" + coreName + "\"", e)); } } }); itemReload.setEnabled(false); itemReloadAll = new ToolItem(toolBar, SWT.PUSH); itemReloadAll.setImage(imgReloadAll); itemReloadAll.setText("Reload all"); itemReloadAll.setToolTipText("Reload all cores"); itemReloadAll.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { try { for (String coreName : SolrUtils.getCores().keySet()) { CoreAdminRequest.reloadCore(coreName, Sophie.client); } table.refresh(); } catch (SolrServerException | IOException | SolrException | SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to reload all cores", e)); } } }); toolBar.pack(); }
From source file:org.codice.solr.factory.impl.HttpSolrClientFactory.java
License:Open Source License
private static void createSolrCore(String url, String coreName, String configFileName, HttpClient httpClient) throws IOException, SolrServerException { HttpSolrClient client;/* w ww . j a v a2 s. c o m*/ if (httpClient != null) { client = new HttpSolrClient(url, httpClient); } else { client = new HttpSolrClient(url); } HttpResponse ping = client.getHttpClient().execute(new HttpHead(url)); if (ping != null && ping.getStatusLine().getStatusCode() == 200) { ConfigurationFileProxy configProxy = new ConfigurationFileProxy(ConfigurationStore.getInstance()); configProxy.writeSolrConfiguration(coreName); if (!solrCoreExists(client, coreName)) { LOGGER.debug("Creating Solr core {}", coreName); String configFile = StringUtils.defaultIfBlank(configFileName, DEFAULT_SOLRCONFIG_XML); String solrDir; if (System.getProperty("solr.data.dir") != null) { solrDir = System.getProperty("solr.data.dir"); } else { solrDir = Paths.get(System.getProperty("karaf.home"), "data", "solr").toString(); } String instanceDir = Paths.get(solrDir, coreName).toString(); String dataDir = Paths.get(instanceDir, "data").toString(); CoreAdminRequest.createCore(coreName, instanceDir, client, configFile, DEFAULT_SCHEMA_XML, dataDir, dataDir); } else { LOGGER.debug("Solr core ({}) already exists - reloading it", coreName); CoreAdminRequest.reloadCore(coreName, client); } } else { LOGGER.debug("Unable to ping Solr core {}", coreName); throw new SolrServerException("Unable to ping Solr core"); } }