| | |
| | | */ |
| | | package org.opends.guitools.controlpanel.task; |
| | | |
| | | import static org.opends.guitools.controlpanel.util.Utilities.*; |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | */ |
| | | public class DeleteIndexTask extends Task |
| | | { |
| | | private Set<String> backendSet; |
| | | private ArrayList<AbstractIndexDescriptor> indexesToDelete = |
| | | new ArrayList<AbstractIndexDescriptor>(); |
| | | private ArrayList<AbstractIndexDescriptor> deletedIndexes = |
| | | new ArrayList<AbstractIndexDescriptor>(); |
| | | private final Set<String> backendSet; |
| | | private final List<AbstractIndexDescriptor> indexesToDelete = new ArrayList<AbstractIndexDescriptor>(); |
| | | private final List<AbstractIndexDescriptor> deletedIndexes = new ArrayList<AbstractIndexDescriptor>(); |
| | | |
| | | /** |
| | | * Constructor of the task. |
| | | * @param info the control panel information. |
| | | * @param dlg the progress dialog where the task progress will be displayed. |
| | | * @param indexesToDelete the indexes that must be deleted. |
| | | * |
| | | * @param info |
| | | * the control panel information. |
| | | * @param dlg |
| | | * the progress dialog where the task progress will be displayed. |
| | | * @param indexesToDelete |
| | | * the indexes that must be deleted. |
| | | */ |
| | | public DeleteIndexTask(ControlPanelInfo info, ProgressDialog dlg, |
| | | ArrayList<AbstractIndexDescriptor> indexesToDelete) |
| | | public DeleteIndexTask(ControlPanelInfo info, ProgressDialog dlg, List<AbstractIndexDescriptor> indexesToDelete) |
| | | { |
| | | super(info, dlg); |
| | | backendSet = new HashSet<String>(); |
| | | for (AbstractIndexDescriptor index : indexesToDelete) |
| | | for (final AbstractIndexDescriptor index : indexesToDelete) |
| | | { |
| | | backendSet.add(index.getBackend().getBackendID()); |
| | | } |
| | | this.indexesToDelete.addAll(indexesToDelete); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Type getType() |
| | | { |
| | | return Type.DELETE_INDEX; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Set<String> getBackends() |
| | | { |
| | | return backendSet; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public LocalizableMessage getTaskDescription() |
| | | { |
| | | if (backendSet.size() == 1) |
| | | { |
| | | return INFO_CTRL_PANEL_DELETE_INDEX_TASK_DESCRIPTION.get( |
| | | Utilities.getStringFromCollection(backendSet, ", ")); |
| | | return INFO_CTRL_PANEL_DELETE_INDEX_TASK_DESCRIPTION.get(getStringFromCollection(backendSet, ", ")); |
| | | } |
| | | else |
| | | { |
| | | return INFO_CTRL_PANEL_DELETE_INDEX_IN_BACKENDS_TASK_DESCRIPTION.get( |
| | | Utilities.getStringFromCollection(backendSet, ", ")); |
| | | return INFO_CTRL_PANEL_DELETE_INDEX_IN_BACKENDS_TASK_DESCRIPTION.get(getStringFromCollection(backendSet, ", ")); |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | public boolean canLaunch(Task taskToBeLaunched, |
| | | Collection<LocalizableMessage> incompatibilityReasons) |
| | | @Override |
| | | public boolean canLaunch(Task taskToBeLaunched, Collection<LocalizableMessage> incompatibilityReasons) |
| | | { |
| | | boolean canLaunch = true; |
| | | if (state == State.RUNNING && runningOnSameServer(taskToBeLaunched)) |
| | |
| | | // All the operations are incompatible if they apply to this |
| | | // backend for safety. This is a short operation so the limitation |
| | | // has not a lot of impact. |
| | | Set<String> backends = |
| | | new TreeSet<String>(taskToBeLaunched.getBackends()); |
| | | final Set<String> backends = new TreeSet<String>(taskToBeLaunched.getBackends()); |
| | | backends.retainAll(getBackends()); |
| | | if (backends.size() > 0) |
| | | { |
| | | incompatibilityReasons.add(getIncompatibilityMessage(this, |
| | | taskToBeLaunched)); |
| | | incompatibilityReasons.add(getIncompatibilityMessage(this, taskToBeLaunched)); |
| | | canLaunch = false; |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * Update the configuration in the server. |
| | | * @throws OpenDsException if an error occurs. |
| | | * |
| | | * @throws OpenDsException |
| | | * if an error occurs. |
| | | */ |
| | | private void updateConfiguration() throws OpenDsException |
| | | { |
| | |
| | | DirectoryServer.deregisterBaseDN(DN.valueOf("cn=config")); |
| | | } |
| | | DirectoryServer.getInstance().initializeConfiguration( |
| | | org.opends.server.extensions.ConfigFileHandler.class.getName(), |
| | | ConfigReader.configFile); |
| | | org.opends.server.extensions.ConfigFileHandler.class.getName(), ConfigReader.configFile); |
| | | getInfo().setMustDeregisterConfig(true); |
| | | } |
| | | boolean isFirst = true; |
| | |
| | | { |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | getProgressDialog().appendProgressHtml("<br><br>"); |
| | |
| | | { |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | List<String> args = |
| | | getObfuscatedCommandLineArguments( |
| | | getDSConfigCommandLineArguments(index)); |
| | | final List<String> args = getObfuscatedCommandLineArguments(getDSConfigCommandLineArguments(index)); |
| | | args.removeAll(getConfigCommandLineArguments()); |
| | | printEquivalentCommandLine(getConfigCommandLineName(index), |
| | | args, INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_INDEX.get()); |
| | | printEquivalentCommandLine(getConfigCommandLineName(index), args, |
| | | INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_INDEX.get()); |
| | | } |
| | | }); |
| | | } |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | if (isVLVIndex(index)) |
| | | { |
| | | getProgressDialog().appendProgressHtml( |
| | | Utilities.getProgressWithPoints( |
| | | INFO_CTRL_PANEL_DELETING_VLV_INDEX.get( |
| | | index.getName()), |
| | | Utilities.getProgressWithPoints(INFO_CTRL_PANEL_DELETING_VLV_INDEX.get(index.getName()), |
| | | ColorAndFontConstants.progressFont)); |
| | | } |
| | | else |
| | | { |
| | | getProgressDialog().appendProgressHtml( |
| | | Utilities.getProgressWithPoints( |
| | | INFO_CTRL_PANEL_DELETING_INDEX.get( |
| | | index.getName()), |
| | | Utilities.getProgressWithPoints(INFO_CTRL_PANEL_DELETING_INDEX.get(index.getName()), |
| | | ColorAndFontConstants.progressFont)); |
| | | } |
| | | } |
| | |
| | | { |
| | | deleteIndex(index); |
| | | } |
| | | numberDeleted ++; |
| | | numberDeleted++; |
| | | final int fNumberDeleted = numberDeleted; |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | getProgressDialog().getProgressBar().setIndeterminate(false); |
| | | getProgressDialog().getProgressBar().setValue( |
| | | (fNumberDeleted * 100) / totalNumber); |
| | | getProgressDialog().appendProgressHtml( |
| | | Utilities.getProgressDone(ColorAndFontConstants.progressFont)); |
| | | getProgressDialog().getProgressBar().setValue((fNumberDeleted * 100) / totalNumber); |
| | | getProgressDialog().appendProgressHtml(Utilities.getProgressDone(ColorAndFontConstants.progressFont)); |
| | | } |
| | | }); |
| | | deletedIndexes.add(index); |
| | |
| | | { |
| | | if (configHandlerUpdated) |
| | | { |
| | | DirectoryServer.getInstance().initializeConfiguration( |
| | | ConfigReader.configClassName, ConfigReader.configFile); |
| | | DirectoryServer.getInstance().initializeConfiguration(ConfigReader.configClassName, ConfigReader.configFile); |
| | | getInfo().startPooling(); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * Returns <CODE>true</CODE> if the index is a VLV index and |
| | | * <CODE>false</CODE> otherwise. |
| | | * @param index the index. |
| | | * |
| | | * @param index |
| | | * the index. |
| | | * @return <CODE>true</CODE> if the index is a VLV index and |
| | | * <CODE>false</CODE> otherwise. |
| | | * <CODE>false</CODE> otherwise. |
| | | */ |
| | | private boolean isVLVIndex(AbstractIndexDescriptor index) |
| | | { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Deletes an index. The code assumes that the server is not running |
| | | * and that the configuration file can be edited. |
| | | * @param index the index to be deleted. |
| | | * @throws OpenDsException if an error occurs. |
| | | * Deletes an index. The code assumes that the server is not running and that |
| | | * the configuration file can be edited. |
| | | * |
| | | * @param index |
| | | * the index to be deleted. |
| | | * @throws OpenDsException |
| | | * if an error occurs. |
| | | */ |
| | | private void deleteIndex(AbstractIndexDescriptor index) throws OpenDsException |
| | | { |
| | | String backendId = Utilities.getRDNString("ds-cfg-backend-id", index.getBackend().getBackendID()); |
| | | final String backendId = Utilities.getRDNString("ds-cfg-backend-id", index.getBackend().getBackendID()); |
| | | String dn; |
| | | if (isVLVIndex(index)) |
| | | { |
| | | dn = Utilities.getRDNString("ds-cfg-name", index.getName()) |
| | | + ",cn=VLV Index," + backendId + ",cn=Backends,cn=config"; |
| | | dn = getRDNString("ds-cfg-name", index.getName()) + ",cn=VLV Index," + backendId + ",cn=Backends,cn=config"; |
| | | } |
| | | else |
| | | { |
| | | dn = Utilities.getRDNString("ds-cfg-attribute", index.getName()) |
| | | + ",cn=Index," + backendId + ",cn=Backends,cn=config"; |
| | | dn = getRDNString("ds-cfg-attribute", index.getName()) + ",cn=Index," + backendId + ",cn=Backends,cn=config"; |
| | | } |
| | | DirectoryServer.getConfigHandler().deleteEntry(DN.valueOf(dn), null); |
| | | } |
| | | |
| | | /** |
| | | * Deletes an index. The code assumes that the server is running |
| | | * and that the provided connection is active. |
| | | * @param index the index to be deleted. |
| | | * @param ctx the connection to the server. |
| | | * @throws OpenDsException if an error occurs. |
| | | * Deletes an index. The code assumes that the server is running and that the |
| | | * provided connection is active. |
| | | * |
| | | * @param index |
| | | * the index to be deleted. |
| | | * @param ctx |
| | | * the connection to the server. |
| | | * @throws OpenDsException |
| | | * if an error occurs. |
| | | */ |
| | | private void deleteIndex(InitialLdapContext ctx, |
| | | AbstractIndexDescriptor index) throws OpenDsException |
| | | private void deleteIndex(InitialLdapContext ctx, AbstractIndexDescriptor index) throws OpenDsException |
| | | { |
| | | ManagementContext mCtx = LDAPManagementContext.createFromContext( |
| | | JNDIDirContextAdaptor.adapt(ctx)); |
| | | RootCfgClient root = mCtx.getRootConfiguration(); |
| | | LocalDBBackendCfgClient backend = |
| | | (LocalDBBackendCfgClient)root.getBackend( |
| | | index.getBackend().getBackendID()); |
| | | final ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(ctx)); |
| | | final RootCfgClient root = mCtx.getRootConfiguration(); |
| | | final LocalDBBackendCfgClient backend = |
| | | (LocalDBBackendCfgClient) root.getBackend(index.getBackend().getBackendID()); |
| | | if (isVLVIndex(index)) |
| | | { |
| | | backend.removeLocalDBVLVIndex(index.getName()); |
| | |
| | | backend.commit(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | protected String getCommandLinePath() |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | protected ArrayList<String> getCommandLineArguments() |
| | | { |
| | | return new ArrayList<String>(); |
| | |
| | | /** |
| | | * Returns the path of the command line to be used to delete the specified |
| | | * index. |
| | | * @param index the index to be deleted. |
| | | * |
| | | * @param index |
| | | * the index to be deleted. |
| | | * @return the path of the command line to be used to delete the specified |
| | | * index. |
| | | * index. |
| | | */ |
| | | private String getConfigCommandLineName(AbstractIndexDescriptor index) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void runTask() |
| | | { |
| | | state = State.RUNNING; |
| | |
| | | updateConfiguration(); |
| | | state = State.FINISHED_SUCCESSFULLY; |
| | | } |
| | | catch (Throwable t) |
| | | catch (final Throwable t) |
| | | { |
| | | lastException = t; |
| | | state = State.FINISHED_WITH_ERROR; |
| | | } |
| | | finally |
| | | { |
| | | for (AbstractIndexDescriptor index : deletedIndexes) |
| | | for (final AbstractIndexDescriptor index : deletedIndexes) |
| | | { |
| | | getInfo().unregisterModifiedIndex(index); |
| | | } |
| | |
| | | |
| | | /** |
| | | * Return the dsconfig arguments required to delete an index. |
| | | * @param index the index to be deleted. |
| | | * |
| | | * @param index |
| | | * the index to be deleted. |
| | | * @return the dsconfig arguments required to delete an index. |
| | | */ |
| | | private ArrayList<String> getDSConfigCommandLineArguments( |
| | | AbstractIndexDescriptor index) |
| | | private List<String> getDSConfigCommandLineArguments(AbstractIndexDescriptor index) |
| | | { |
| | | ArrayList<String> args = new ArrayList<String>(); |
| | | final List<String> args = new ArrayList<String>(); |
| | | if (isVLVIndex(index)) |
| | | { |
| | | args.add("delete-local-db-vlv-index"); |
| | |
| | | args.addAll(getConnectionCommandLineArguments()); |
| | | args.add("--no-prompt"); |
| | | args.add(getNoPropertiesFileArgument()); |
| | | |
| | | return args; |
| | | } |
| | | } |