Skip to content

Commit

Permalink
#582 Remove intermediateSaves option in OSGi config (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghenzler authored Jun 9, 2021
1 parent d090030 commit b8f5453
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ public interface AceBeanInstaller {
* @param pathBasedAceMapFromConfig map containing the ACE data from the merged configurations path based
* @param session the jcr session
* @param installationLog the installation log
* @param authorizablesToRemoveAcesFor
* @param intermediateSaves whether the session should be saved after each path (for each ACL) */
* @param authorizablesToRemoveAcesFor */
void installPathBasedACEs(final Map<String, Set<AceBean>> pathBasedAceMapFromConfig, final AcConfiguration acConfiguration, final Session session,
final InstallationLogger installationLog, Set<String> authorizablesToRemoveAcesFor, boolean intermediateSaves) throws Exception;
final InstallationLogger installationLog, Set<String> authorizablesToRemoveAcesFor) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public void installPathBasedACEs(
final Map<String, Set<AceBean>> pathBasedAceMapFromConfig,
final AcConfiguration acConfiguration,
final Session session,
final InstallationLogger history, Set<String> principalsToRemoveAcesFor,
boolean intermediateSaves) throws Exception {
final InstallationLogger history, Set<String> principalsToRemoveAcesFor) throws Exception {

StopWatch stopWatch = new StopWatch();
stopWatch.start();
Expand All @@ -65,11 +64,6 @@ public void installPathBasedACEs(

paths = filterReadOnlyPaths(paths, history, session);

if (intermediateSaves) {
history.addMessage(LOG, "Will save ACL for each path to session due to configuration option intermediateSaves=true - "
+ "rollback functionality is disabled.");
}

// loop through all nodes from config
for (final String path : paths) {

Expand All @@ -96,10 +90,6 @@ public void installPathBasedACEs(
acConfiguration.getGlobalConfiguration().getDefaultUnmanagedAcePathsRegex());
installAcl(orderedAceBeanSetFromConfig, path, principalsToRemoveAcesForAtThisPath, session, history);

if (intermediateSaves && session.hasPendingChanges()) {
history.addVerboseMessage(LOG, "Saved session for path " + path);
session.save();
}
}

if (history.getMissingParentPathsForInitialContent() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public class AcInstallationServiceImpl implements AcInstallationService, AcInsta
private static final String CONFIG_PID = "biz.netcentric.cq.tools.actool.impl.AcInstallationServiceImpl";
private static final String LEGACY_CONFIG_PID = "biz.netcentric.cq.tools.actool.aceservice.impl.AceServiceImpl";
private static final String LEGACY_PROPERTY_CONFIGURATION_PATH = "AceService.configurationPath";
private static final String LEGACY_PROPERTY_INTERMEDIATE_SAVES = "intermediateSaves";

@Reference(policyOption = ReferencePolicyOption.GREEDY)
AuthorizableInstallerService authorizableCreatorService;
Expand Down Expand Up @@ -129,18 +128,13 @@ public class AcInstallationServiceImpl implements AcInstallationService, AcInsta

private List<String> configurationRootPaths;

private boolean intermediateSaves;

@ObjectClassDefinition(name = "AC Tool Installation Service",
description="Service that installs groups & ACEs according to textual configuration files",
id = CONFIG_PID)
protected static @interface Configuration {

@AttributeDefinition(name="Configuration path(s)", description="JCR path(s) where the config files reside (usually it's just one, can be multiple for multitenant setups)")
String[] configurationRootPaths() default {};

@AttributeDefinition(name="Use intermediate saves", description="Saves ACLs for each path individually - this can be used to avoid problems with large changesets and MongoDB (OAK-5557), however the rollback is disabled then.")
boolean intermediateSaves() default false;
}

@Activate
Expand All @@ -157,16 +151,13 @@ public void activate(Configuration configuration, BundleContext bundleContext) t
configurationRootPaths.add(PropertiesUtil.toString(configDict.get(LEGACY_PROPERTY_CONFIGURATION_PATH), ""));
}
}

intermediateSaves = configuration.intermediateSaves();

// Fallback to old PID: only fall back to legacy config if new config does not exist
if (configDict == null) {
Dictionary<String, Object> legacyProps = configAdmin.getConfiguration(LEGACY_CONFIG_PID).getProperties();
if (legacyProps != null) {
LOG.warn("Using legacy configuration PID '{}'. Please remove this and switch to the new one with PID '{}',", LEGACY_CONFIG_PID, CONFIG_PID);
configurationRootPaths = Arrays.asList(PropertiesUtil.toString(legacyProps.get(LEGACY_PROPERTY_CONFIGURATION_PATH), ""));
intermediateSaves = PropertiesUtil.toBoolean(legacyProps.get(LEGACY_PROPERTY_INTERMEDIATE_SAVES), false);
}
}

Expand Down Expand Up @@ -484,7 +475,7 @@ private void installAces(InstallationLogger installLog,
+ aceBeanInstaller.getClass().getSimpleName() + "...");

aceBeanInstaller.installPathBasedACEs(filteredPathBasedAceMapFromConfig, acConfiguration, session, installLog,
principalsToRemoveAcesFor, intermediateSaves);
principalsToRemoveAcesFor);
} else {
installLog.addMessage(LOG, "No relevant ACEs to install");
}
Expand Down Expand Up @@ -543,17 +534,6 @@ private void installAuthorizables(InstallationLogger installLog, AcConfiguration
try {
// only save session if no exceptions occurred
authorizableCreatorService.installAuthorizables(acConfiguration, authorizablesConfig, session, installLog);

if (intermediateSaves) {
if (session.hasPendingChanges()) {
session.save();
installLog.addVerboseMessage(LOG, "Saved session after installing authorizables.");
} else {
installLog.addVerboseMessage(LOG,
"After installing authorizables, intermediateSaves is turned on but there are no pending changes.");
}
}

} catch (Exception e) {
throw new AuthorizableCreatorException(e);
}
Expand Down
8 changes: 0 additions & 8 deletions docs/AdvancedFeatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,3 @@ The following examples shows a legitimate example of using `keepOrder: true`:
```
This example gives the group `myproj-editor` edit rights for all content in folder `myproj`, except for the iframe component.

## Intermediate save() calls during ACL installation

For large installations (> 1000 groups) that use MongoDB, the system possibly may get into an invalid state as older versions of OAK (AEM 6.1/6.2 ootb) do not always correctly fire the post commit hook for very large change sets (OAK-5557). To circumvent this issue it is possible since v1.9.2 to configure the OSGi property `intermediateSaves=true` of PID `biz.netcentric.cq.tools.actool.impl.AcInstallationServiceImpl`.

NOTE: This is never necessary when using TarMK and also it should only be used for MongoMK for large installations that do not contain a fix for OAK-5557 yet as the rollback functionality is lost when enabling intermediate saves.

[i257]: https://github.com/Netcentric/accesscontroltool/issues/257
[felix-interpolation-plugin]: https://github.com/apache/felix-dev/blob/master/configadmin-plugins/interpolation/README.md

0 comments on commit b8f5453

Please sign in to comment.