| | |
| | | */ |
| | | package org.opends.server.tasks; |
| | | |
| | | import static org.opends.server.config.ConfigConstants.ATTR_BACKEND_ID; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.adapter.server3x.Converters; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.opends.messages.TaskMessages; |
| | | import org.forgerock.opendj.config.server.ServerManagementContext; |
| | | import org.forgerock.opendj.server.config.server.BackendCfg; |
| | | import org.forgerock.opendj.server.config.server.RootCfg; |
| | | import org.opends.server.api.Backend; |
| | | import org.opends.server.tools.BackendToolUtils; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.config.StringConfigAttribute; |
| | | import org.opends.server.core.ConfigurationHandler; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.types.Attribute; |
| | |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | import static org.opends.messages.TaskMessages.*; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | |
| | | { |
| | | try |
| | | { |
| | | StringConfigAttribute idStub = |
| | | new StringConfigAttribute( |
| | | ATTR_BACKEND_ID, |
| | | INFO_CONFIG_BACKEND_ATTR_DESCRIPTION_BACKEND_ID.get(), |
| | | true, false, true); |
| | | StringConfigAttribute idAttr = |
| | | (StringConfigAttribute) configEntry.getConfigAttribute(idStub); |
| | | return idAttr.activeValue(); |
| | | } |
| | | catch (org.opends.server.config.ConfigException ce) |
| | | { |
| | | logger.error(ERR_CANNOT_DETERMINE_BACKEND_ID, configEntry.getName(), ce.getMessage()); |
| | | return null; |
| | | return BackendToolUtils.getStringSingleValuedAttribute(configEntry, ATTR_BACKEND_ID); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | return configEntries; |
| | | } |
| | | |
| | | Entry baseEntry; |
| | | try |
| | | { |
| | | baseEntry = DirectoryServer.getConfigEntry(backendBaseDN); |
| | | } |
| | | catch (ConfigException ce) |
| | | { |
| | | logger.error(ERR_CANNOT_RETRIEVE_BACKEND_BASE_ENTRY, DN_BACKEND_BASE, ce.getMessage()); |
| | | return configEntries; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.error(ERR_CANNOT_RETRIEVE_BACKEND_BASE_ENTRY, DN_BACKEND_BASE, getExceptionMessage(e)); |
| | | return configEntries; |
| | | } |
| | | |
| | | |
| | | // Iterate through the immediate children, attempting to parse them as |
| | | // backends. |
| | | for (Entry configEntry : baseEntry.getChildren().values()) |
| | | try |
| | | { |
| | | // Get the backend ID attribute from the entry. If there isn't one, then |
| | | // skip the entry. |
| | | String backendID; |
| | | try |
| | | ConfigurationHandler configHandler = DirectoryServer.getConfigurationHandler(); |
| | | for (DN childrenDn : configHandler.getChildren(backendBaseDN)) |
| | | { |
| | | StringConfigAttribute idStub = |
| | | new StringConfigAttribute( |
| | | ATTR_BACKEND_ID, |
| | | INFO_CONFIG_BACKEND_ATTR_DESCRIPTION_BACKEND_ID.get(), |
| | | true, false, true); |
| | | StringConfigAttribute idAttr = |
| | | (StringConfigAttribute) configEntry.getConfigAttribute(idStub); |
| | | if (idAttr == null) |
| | | // Get the backend ID attribute from the entry. If there isn't one, then |
| | | // skip the entry. |
| | | Entry configEntry = null; |
| | | String backendID; |
| | | try |
| | | { |
| | | configEntry = Converters.to(configHandler.getEntry(childrenDn)); |
| | | backendID = BackendToolUtils.getStringSingleValuedAttribute(configEntry, ATTR_BACKEND_ID); |
| | | if (backendID == null) |
| | | { |
| | | continue; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.error(ERR_CANNOT_DETERMINE_BACKEND_ID, childrenDn, getExceptionMessage(e)); |
| | | continue; |
| | | } |
| | | backendID = idAttr.activeValue(); |
| | | } |
| | | catch (org.opends.server.config.ConfigException ce) |
| | | { |
| | | logger.error(ERR_CANNOT_DETERMINE_BACKEND_ID, configEntry.getName(), ce.getMessage()); |
| | | continue; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.error(ERR_CANNOT_DETERMINE_BACKEND_ID, configEntry.getName(), getExceptionMessage(e)); |
| | | continue; |
| | | } |
| | | |
| | | configEntries.put(backendID, configEntry); |
| | | configEntries.put(backendID, configEntry); |
| | | } |
| | | } |
| | | catch (ConfigException e) |
| | | { |
| | | logger.error(ERR_CANNOT_RETRIEVE_BACKEND_BASE_ENTRY, DN_BACKEND_BASE, e.getMessage()); |
| | | } |
| | | |
| | | return configEntries; |
| | |
| | | */ |
| | | public static BackendCfg getConfigEntry(Backend<?> backend) |
| | | { |
| | | RootCfg root = ServerManagementContext.getInstance(). |
| | | getRootConfiguration(); |
| | | RootCfg root = getServerManagementContext().getRootConfiguration(); |
| | | try |
| | | { |
| | | return root.getBackend(backend.getBackendID()); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | private static ServerManagementContext getServerManagementContext() |
| | | { |
| | | return DirectoryServer.getInstance().getServerContext().getServerManagementContext(); |
| | | } |
| | | |
| | | /** |
| | | * Enables a backend using an internal modify operation on the |
| | |
| | | throws DirectoryException |
| | | { |
| | | DN configEntryDN; |
| | | RootCfg root = serverContext.getServerManagementContext().getRootConfiguration(); |
| | | RootCfg root = getServerManagementContext().getRootConfiguration(); |
| | | try |
| | | { |
| | | BackendCfg cfg = root.getBackend(backendID); |
| | |
| | | public static void disableBackend(String backendID) throws DirectoryException |
| | | { |
| | | DN configEntryDN; |
| | | RootCfg root = serverContext.getServerManagementContext().getRootConfiguration(); |
| | | RootCfg root = getServerManagementContext().getRootConfiguration(); |
| | | try |
| | | { |
| | | BackendCfg cfg = root.getBackend(backendID); |