List of usage examples for org.apache.solr.client.solrj.request CoreAdminRequest unloadCore
public static CoreAdminResponse unloadCore(String name, SolrClient client) throws SolrServerException, IOException
From source file:com.github.fengtan.sophie.toolbars.CoresToolbar.java
License:Open Source License
/** * Populate toolbar with buttons.//from w w w .j a v a 2s . co 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.act.index.server.MetaService.java
License:Apache License
@Override public int removeCore(int coreId) { // TODO Auto-generated method stub try {/*from w w w . ja v a 2 s . c o m*/ CoreAdminRequest.unloadCore(String.valueOf(coreId), indexServer.getSolrServer(coreId)); indexServer.removeSolrServer(coreId); } catch (SolrServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return 0; }
From source file:org.apache.gora.solr.store.SolrStore.java
License:Apache License
@Override public void deleteSchema() { // XXX should this be only in truncateSchema ??? try {/*from w ww .jav a 2 s . co m*/ server.deleteByQuery("*:*"); server.commit(); } catch (Exception e) { // ignore? // LOG.error(e.getMessage(), e); } try { CoreAdminRequest.unloadCore(mapping.getCoreName(), adminServer); } catch (Exception e) { if (e.getMessage().contains("No such core")) { return; // it's ok, the core is not there } else { LOG.error(e.getMessage(), e); } } }