From 609714b57af91cb749452ebb2709fd5d37c01d55 Mon Sep 17 00:00:00 2001 From: Roy Teeuwen Date: Fri, 4 Aug 2023 16:21:45 +0200 Subject: [PATCH] solves #3148: Add cloud bundle + cloud all package containing dispatcher flush rules fixes --- all/pom.xml | 104 +++++++++++++ bundle-cloud/pom.xml | 141 ++++++++++++++++++ .../CloudDispatcherFlushRulesExecutor.java | 87 +++++++++++ .../impl/ImportPostProcessorMultiplexer.java | 56 +++++++ bundle/pom.xml | 34 ++++- .../dispatcher/DispatcherFlushRules.java | 11 ++ .../impl/DispatcherFlushRulesImpl.java | 3 +- pom.xml | 23 ++- 8 files changed, 452 insertions(+), 7 deletions(-) create mode 100644 bundle-cloud/pom.xml create mode 100644 bundle-cloud/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/CloudDispatcherFlushRulesExecutor.java create mode 100644 bundle-cloud/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/ImportPostProcessorMultiplexer.java create mode 100644 bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/DispatcherFlushRules.java diff --git a/all/pom.xml b/all/pom.xml index 316f7f5b33..7d717ce3ee 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -46,6 +46,7 @@ filevault-package-maven-plugin container + acs-aem-commons-all ${project.groupId} @@ -213,5 +214,108 @@ + + + cloud + + false + + + + + org.apache.jackrabbit + filevault-package-maven-plugin + false + + + generate-metadata-cloud + + generate-metadata + + + cloud + acs-aem-commons-all-cloud + container + + all + + + + ${project.groupId} + acs-aem-commons-bundle + /apps/acs-commons/install + true + true + + + ${project.groupId} + acs-aem-commons-bundle-cloud + /apps/acs-commons/install + + + + + ${project.groupId} + acs-aem-commons-ui.apps + true + true + + + ${project.groupId} + acs-aem-commons-ui.content + true + true + + + + + + package-cloud + + package + + + cloud + + + + default-validate-package + + cloud + + + + + + com.adobe.aem + aemanalyser-maven-plugin + 1.5.8 + + + aem-analyser + + project-analyse + + + + + + com.day.jcr.vault + content-package-maven-plugin + + ${project.build.directory}/${project.build.finalName}-cloud.zip + + + + + + + com.adobe.acs + acs-aem-commons-bundle-cloud + ${project.version} + jar + + + diff --git a/bundle-cloud/pom.xml b/bundle-cloud/pom.xml new file mode 100644 index 0000000000..963addfe2e --- /dev/null +++ b/bundle-cloud/pom.xml @@ -0,0 +1,141 @@ + + + + 4.0.0 + + + + + + com.adobe.acs + acs-aem-commons + 6.0.15-SNAPSHOT + + + + + + acs-aem-commons-bundle-cloud + ACS AEM Commons Bundle - Core Cloud Fragment + OSGi Core bundle fragment for ACS AEM Commons (only AEMaaCS) + + + + org.apache.sling + sling-maven-plugin + + + biz.aQute.bnd + bnd-maven-plugin + + + + + + biz.aQute.bnd + bnd-baseline-maven-plugin + + + org.apache.sling + sling-maven-plugin + + ${crx.protocol}://${crx.host}:${crx.port}${crx.contextRoot} + /apps/acs-commons/install + SlingPostServlet + ${crx.user} + ${crx.password} + true + + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + + + + + + com.google.code.findbugs + jsr305 + provided + + + com.adobe.acs + acs-aem-commons-bundle + ${project.version} + provided + + + + com.adobe.acs + acs-aem-commons-bundle + ${project.version} + tests + test-jar + test + + + junit + junit + test + + + org.mockito + mockito-core + test + + + org.apache.sling + org.apache.sling.testing.osgi-mock.junit4 + test + + + org.apache.sling + org.apache.sling.testing.sling-mock.junit4 + test + + + io.wcm + io.wcm.testing.aem-mock.junit4 + test + + + + + com.adobe.aem + aem-sdk-api + provided + + + diff --git a/bundle-cloud/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/CloudDispatcherFlushRulesExecutor.java b/bundle-cloud/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/CloudDispatcherFlushRulesExecutor.java new file mode 100644 index 0000000000..8e6eb48a8a --- /dev/null +++ b/bundle-cloud/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/CloudDispatcherFlushRulesExecutor.java @@ -0,0 +1,87 @@ +package com.adobe.acs.commons.replication.dispatcher.impl; + +import com.adobe.acs.commons.replication.dispatcher.DispatcherFlushRules; +import com.adobe.acs.commons.util.RequireAem; +import com.day.cq.replication.ReplicationAction; +import com.day.cq.replication.ReplicationActionType; +import com.day.cq.replication.ReplicationOptions; +import org.apache.sling.distribution.DistributionRequestType; +import org.apache.sling.distribution.ImportPostProcessor; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.propertytypes.ServiceRanking; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +@Component(immediate = true) +@ServiceRanking(5) +public class CloudDispatcherFlushRulesExecutor implements ImportPostProcessor { + + private static final Logger log = LoggerFactory.getLogger(CloudDispatcherFlushRulesExecutor.class); + + @Reference(target = "(distribution=cloud-ready)") + private RequireAem requireAem; + + @Reference + private volatile List dispatcherFlushRules; + + + @Override + public void process(Map props) { + ReplicationActionType actionType = getReplicationActionType(props); + List distributionPaths = (List) props.get("distribution.paths"); + if (actionType == null || actionType.equals(ReplicationActionType.TEST) || distributionPaths == null || distributionPaths.isEmpty()) { + log.debug("Skipping processing because the distribution paths are empty"); + return; + } + try { + ReplicationAction action = new ReplicationAction(actionType, distributionPaths.toArray(new String[0]), 0L, "", null); + ReplicationOptions opts = new ReplicationOptions(); + for (DispatcherFlushRules dispatcherFlushRule : dispatcherFlushRules) { + dispatcherFlushRule.preprocess(action, opts); + } + if (log.isInfoEnabled()) { + log.info("Invalidated resources [{}]", abbreviate(distributionPaths)); + } + } catch (Exception ex) { + log.warn("Could not invalidate request ", ex); + } + } + + + private ReplicationActionType getReplicationActionType(Map props) { + Object requestTypeObject = props.get("distribution.type"); + DistributionRequestType requestType = (requestTypeObject instanceof DistributionRequestType) ? (DistributionRequestType) requestTypeObject : DistributionRequestType.fromName((String) requestTypeObject); + if (DistributionRequestType.ADD.equals(requestType)) + return ReplicationActionType.ACTIVATE; + if (DistributionRequestType.DELETE.equals(requestType)) + return ReplicationActionType.DEACTIVATE; + if (DistributionRequestType.TEST.equals(requestType)) + return ReplicationActionType.TEST; + log.debug("Distribution request type {} not supported", requestType); + return null; + } + + protected static String abbreviate(List list) { + if (list == null) + return null; + Iterator iter = list.iterator(); + StringBuilder abbr = new StringBuilder(); + abbr.append("["); + if (iter.hasNext()) { + abbr.append(iter.next()); + } + if (iter.hasNext()) { + abbr.append(", ... "); + abbr.append(list.size() - 1); + abbr.append(" more"); + } + abbr.append("]"); + return abbr.toString(); + } + +} diff --git a/bundle-cloud/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/ImportPostProcessorMultiplexer.java b/bundle-cloud/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/ImportPostProcessorMultiplexer.java new file mode 100644 index 0000000000..006dd8b228 --- /dev/null +++ b/bundle-cloud/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/ImportPostProcessorMultiplexer.java @@ -0,0 +1,56 @@ +package com.adobe.acs.commons.replication.dispatcher.impl; + +import com.adobe.acs.commons.util.RequireAem; +import org.apache.sling.commons.osgi.Order; +import org.apache.sling.commons.osgi.RankedServices; +import org.apache.sling.distribution.ImportPostProcessException; +import org.apache.sling.distribution.ImportPostProcessor; +import org.osgi.service.component.annotations.*; +import org.osgi.service.component.propertytypes.ServiceRanking; + +import java.util.Map; + +@Component( + reference = { + @Reference( + name = "importPostProcessor", + service = ImportPostProcessor.class, + bind = "bindImportPostProcessor", unbind = "unbindImportPostProcessor", + target = "(!(component.name=com.adobe.acs.commons.replication.dispatcher.impl.ImportPostProcessorMultiplexer))", + cardinality = ReferenceCardinality.MULTIPLE, + policy = ReferencePolicy.DYNAMIC, + policyOption = ReferencePolicyOption.GREEDY + ) + }, + // The multiplexer is required as long as https://issues.apache.org/jira/browse/SLING-11991 is not solved + // to make sure the imports don't happen twice once solved, this component has to be explicitly enabled + configurationPolicy = ConfigurationPolicy.REQUIRE +) +@ServiceRanking(100) +public class ImportPostProcessorMultiplexer implements ImportPostProcessor { + + @Reference(target = "(distribution=cloud-ready)") + private RequireAem requireAem; + + private final RankedServices items = new RankedServices<>(Order.DESCENDING); + + protected void bindImportPostProcessor(ImportPostProcessor item, Map props) { + if (this != item) { + items.bind(item, props); + } + } + + protected void unbindImportPostProcessor(ImportPostProcessor item, Map props) { + if (this != item) { + items.unbind(item, props); + } + } + + @Override + public void process(Map props) throws ImportPostProcessException { + if (items.iterator().hasNext()) { + items.iterator().next().process(props); + } + } + +} diff --git a/bundle/pom.xml b/bundle/pom.xml index 43f83c3c3e..a99e36bd8e 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -53,11 +53,23 @@ org.apache.maven.plugins maven-jar-plugin - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - + + + default-jar + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + + generate-test-jar + + test-jar + + + biz.aQute.bnd @@ -371,6 +383,18 @@ org.osgi.service.cm provided + + org.apache.sling + org.apache.sling.distribution.api + 0.7.0 + provided + + + * + * + + + org.slf4j slf4j-api diff --git a/bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/DispatcherFlushRules.java b/bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/DispatcherFlushRules.java new file mode 100644 index 0000000000..2b8bbdc1f3 --- /dev/null +++ b/bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/DispatcherFlushRules.java @@ -0,0 +1,11 @@ +package com.adobe.acs.commons.replication.dispatcher; + +import com.day.cq.replication.ReplicationAction; +import com.day.cq.replication.ReplicationException; +import com.day.cq.replication.ReplicationOptions; + +public interface DispatcherFlushRules { + + void preprocess(final ReplicationAction replicationAction, + final ReplicationOptions replicationOptions) throws ReplicationException; +} diff --git a/bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImpl.java b/bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImpl.java index 5c7e5f67d5..5309028875 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImpl.java +++ b/bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImpl.java @@ -20,6 +20,7 @@ import com.adobe.acs.commons.replication.dispatcher.DispatcherFlushFilter; import com.adobe.acs.commons.replication.dispatcher.DispatcherFlusher; +import com.adobe.acs.commons.replication.dispatcher.DispatcherFlushRules; import com.adobe.acs.commons.replication.dispatcher.DispatcherFlushFilter.FlushType; import com.adobe.acs.commons.util.ParameterUtil; import com.day.cq.replication.AgentManager; @@ -71,7 +72,7 @@ name = "webconsole.configurationFactory.nameHint", value = "Rule: {prop.replication-action-type}, for Hierarchy: [{prop.rules.hierarchical}] or Resources: [{prop.rules.resource-only}]") }) -public class DispatcherFlushRulesImpl implements Preprocessor { +public class DispatcherFlushRulesImpl implements Preprocessor, DispatcherFlushRules { private static final Logger log = LoggerFactory.getLogger(DispatcherFlushRulesImpl.class); private static final String OPTION_INHERIT = "INHERIT"; diff --git a/pom.xml b/pom.xml index df76f9f47d..ca9bbeabd5 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,11 @@ oakpal-checks/pom.xml + + 6.5.10.0002 + + 2023.6.12255.20230608T053118Z-230400 + 0.8.7 1.8 @@ -501,11 +506,17 @@ Bundle-DocURL: https://adobe-consulting-services.github.io/acs-aem-commons/ ${project.version} test + + com.adobe.aem + aem-sdk-api + ${aem.sdk.api.version} + provided + io.wcm.maven io.wcm.maven.aem-dependencies - 6.5.10.0002 + ${aem.classic.api.version} pom import @@ -866,6 +877,15 @@ Bundle-DocURL: https://adobe-consulting-services.github.io/acs-aem-commons/ + + + + cloud + + bundle-cloud + + @@ -878,6 +898,7 @@ Bundle-DocURL: https://adobe-consulting-services.github.io/acs-aem-commons/ bundle + bundle-cloud oakpal-checks ui.apps ui.content