Skip to content

Commit

Permalink
Rename RuntimeHelper methods to match their implementations closer
Browse files Browse the repository at this point in the history
  • Loading branch information
gicig committed Sep 9, 2024
1 parent df9c737 commit d6b570e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public void installPathBasedACEs(

private Set<String> filterReadOnlyPaths(Set<String> paths, InstallationLogger history, Session session) {

boolean isCompositeNodeStore = RuntimeHelper.isCompositeNodeStore(session);
if (isCompositeNodeStore) {
boolean isAppsReadOnly = RuntimeHelper.isAppsReadOnly(session);
if (isAppsReadOnly) {
Set<String> pathsToKeep = new TreeSet<String>();
Set<String> readOnlyPaths = new TreeSet<String>();
for (final String path : paths) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class RuntimeHelper {

private static final String INSTALLER_CORE_BUNDLE_SYMBOLIC_ID = "org.apache.sling.installer.core";

public static boolean isCompositeNodeStore(Session session) {
public static boolean isAppsReadOnly(Session session) {

try {
String pathToCheck = "/apps";
Expand Down Expand Up @@ -60,7 +60,7 @@ public static int getCurrentStartLevel(BundleContext bundleContext) {
return bundleContext.getBundle(Constants.SYSTEM_BUNDLE_ID).adapt(FrameworkStartLevel.class).getStartLevel();
}

public static boolean isCloudReadyInstance() {
public static boolean isCompositeNodeStore() {

boolean isCloudReadyInstance = true;
Bundle[] bundles = FrameworkUtil.getBundle(RuntimeHelper.class).getBundleContext().getBundles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public static Node persistHistory(final Session session,
trigger = "startup_hook_pckmgr)";
} else {
// if the history is not yet copied to apps, it's the image build
boolean isImageBuild = RuntimeHelper.isCloudReadyInstance() && !session.itemExists(AC_HISTORY_PATH_IN_APPS);
if(isImageBuild) {
boolean isCompositeNodeStore = RuntimeHelper.isCompositeNodeStore() && !session.itemExists(AC_HISTORY_PATH_IN_APPS);
if(isCompositeNodeStore) {
trigger = "startup_hook_image_build";
} else {
trigger = "startup_hook";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public boolean configIsUnchangedComparedToLastExecution(Map<String, String> conf
}

private String createExecutionKey(Map<String, String> configFiles, String[] restrictedToPaths, Session session) {
boolean isCompositeNodeStore= RuntimeHelper.isCompositeNodeStore(session);
boolean isAppsReadOnly= RuntimeHelper.isAppsReadOnly(session);
String restrictedToPathsKey = restrictedToPaths==null || restrictedToPaths.length==0 ? "ALL_PATHS" : StringUtils.join(restrictedToPaths, "+").replace("$", "").replace("^", "");
String effectiveRootPathOfConfigs = getEffectiveConfigRootPath(configFiles);
String executionKey = "hash("+StringUtils.removeEnd(effectiveRootPathOfConfigs, "/").replace('/', '\\') + "," + restrictedToPathsKey.replace('/', '\\').replace(':', '_')+","+(isCompositeNodeStore?"compNodeStore":"stdRepo")+")";
String executionKey = "hash("+StringUtils.removeEnd(effectiveRootPathOfConfigs, "/").replace('/', '\\') + "," + restrictedToPathsKey.replace('/', '\\').replace(':', '_')+","+(isAppsReadOnly?"compNodeStore":"stdRepo")+")";
return executionKey;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void install(InstallContext context) throws PackageException {
}
alreadyRan = true;

if (RuntimeHelper.isCloudReadyInstance()) {
if (RuntimeHelper.isCompositeNodeStore()) {
log("InstallHook is skipped by default in cloud (use package property 'actool.forceInstallHookInCloud = true' to force run)",
listener);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public void activate(Config config) {
Set<String> defaultRunmodes = slingSettingsService.getRunModes();
extendedRunmodes = new HashSet<>();
extendedRunmodes.addAll(defaultRunmodes);
boolean isCloudReady = RuntimeHelper.isCloudReadyInstance();
if(isCloudReady) {
boolean isCompositeNodeStore = RuntimeHelper.isCompositeNodeStore();
if(isCompositeNodeStore) {
extendedRunmodes.add(ADDITIONAL_RUNMODE_CLOUD);
}

Expand All @@ -90,7 +90,7 @@ public void activate(Config config) {
extendedRunmodes.addAll(additionalRunmodes);
}

LOG.info("Default runmodes: {} Extended Runmodes: {} isCloudReady: {}", defaultRunmodes, extendedRunmodes, isCloudReady);
LOG.info("Default runmodes: {} Extended Runmodes: {} isCompositeNodeStore: {}", defaultRunmodes, extendedRunmodes, isCompositeNodeStore);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,40 +67,40 @@ public enum StartupHookActivation {
@Reference(policyOption = ReferencePolicyOption.GREEDY)
private SlingRepository repository;

private boolean isCompositeNodeStore;
private boolean isAppsReadOnly;

@Activate
public void activate(BundleContext bundleContext, Config config) {

boolean isCloudReady = RuntimeHelper.isCloudReadyInstance();
boolean isCompositeNodeStore = RuntimeHelper.isCompositeNodeStore();
Config.StartupHookActivation activationMode = config.activationMode();
boolean runAsyncForMutableConent = config.runAsyncForMutableConent();
int currentStartLevel = RuntimeHelper.getCurrentStartLevel(bundleContext);
LOG.info("AcTool Startup Hook (start level: {} isCloudReady: {} activationMode: {} runAsyncForMutableConent: {})",
LOG.info("AcTool Startup Hook (start level: {} isCompositeNodeStore: {} activationMode: {} runAsyncForMutableConent: {})",
currentStartLevel,
isCloudReady,
isCompositeNodeStore,
activationMode,
runAsyncForMutableConent);

boolean applyOnStartup = (activationMode == Config.StartupHookActivation.ALWAYS)
|| (isCloudReady && activationMode == Config.StartupHookActivation.CLOUD_ONLY);
|| (isCompositeNodeStore && activationMode == Config.StartupHookActivation.CLOUD_ONLY);

if (applyOnStartup) {

List<String> relevantPathsForInstallation = getRelevantPathsForInstallation();
LOG.info("Running AcTool with "
+ (relevantPathsForInstallation.isEmpty() ? "all paths" : "paths " + relevantPathsForInstallation) + "...");

if (runAsyncForMutableConent && isCompositeNodeStore) {
if (runAsyncForMutableConent && isAppsReadOnly) {
LOG.info(
"Running AcTool asynchronously on mutable content of composite node store (config runAsyncForMutableConent=true)...");
runAcToolAsync(relevantPathsForInstallation, currentStartLevel, isCloudReady);
runAcToolAsync(relevantPathsForInstallation, currentStartLevel, isCompositeNodeStore);
} else {
runAcTool(relevantPathsForInstallation, currentStartLevel, isCloudReady);
runAcTool(relevantPathsForInstallation, currentStartLevel, isCompositeNodeStore);
}

} else {
LOG.debug("Skipping AcTool Startup Hook: activationMode: {} isCloudReady: {}", activationMode, isCloudReady);
LOG.debug("Skipping AcTool Startup Hook: activationMode: {} isCompositeNodeStore: {}", activationMode, isCompositeNodeStore);
}

}
Expand Down Expand Up @@ -131,10 +131,10 @@ private List<String> getRelevantPathsForInstallation() {
try {
session = repository.loginService(null, null);

isCompositeNodeStore = RuntimeHelper.isCompositeNodeStore(session);
LOG.info("Repo is running with Composite NodeStore: {}", isCompositeNodeStore);
isAppsReadOnly = RuntimeHelper.isAppsReadOnly(session);
LOG.info("Repo is running with Composite NodeStore: {}", isAppsReadOnly);

if(!isCompositeNodeStore) {
if(!isAppsReadOnly) {
return Collections.emptyList();
}

Expand All @@ -149,7 +149,7 @@ private List<String> getRelevantPathsForInstallation() {
AccessControlConstants.REP_REPO_POLICY).contains(node.getName())) {
continue;
}
if (isCompositeNodeStore && Arrays.asList("apps", "libs").contains(node.getName())) {
if (isAppsReadOnly && Arrays.asList("apps", "libs").contains(node.getName())) {
continue;
}
relevantPathsForInstallation.add(node.getPath());
Expand Down Expand Up @@ -179,7 +179,7 @@ private void copyAcHistoryToOrFromApps(boolean isCloudReady) {
try {
session = repository.loginService(null, null);

if(isCompositeNodeStore) {
if(isAppsReadOnly) {
LOG.info("Restoring history from /apps to /var");

if(session.nodeExists(HistoryUtils.AC_HISTORY_PATH_IN_APPS)) {
Expand Down

0 comments on commit d6b570e

Please sign in to comment.