Example usage for org.apache.solr.client.solrj.request CoreAdminRequest renameCore

List of usage examples for org.apache.solr.client.solrj.request CoreAdminRequest renameCore

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.request CoreAdminRequest renameCore.

Prototype

public static CoreAdminResponse renameCore(String coreName, String newName, SolrClient client)
        throws SolrServerException, IOException 

Source Link

Document

Rename an existing core.

Usage

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  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();
}