-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solves #3148: Add cloud bundle + cloud all package containing dispatc…
…her flush rules fixes
- Loading branch information
Roy Teeuwen
committed
Aug 4, 2023
1 parent
944e0bd
commit 609714b
Showing
8 changed files
with
452 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ ACS AEM Commons | ||
~ | ||
~ Copyright (C) 2013 - 2023 Adobe | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<!-- ====================================================================== --> | ||
<!-- P A R E N T P R O J E C T D E S C R I P T I O N --> | ||
<!-- ====================================================================== --> | ||
<parent> | ||
<groupId>com.adobe.acs</groupId> | ||
<artifactId>acs-aem-commons</artifactId> | ||
<version>6.0.15-SNAPSHOT</version> | ||
</parent> | ||
|
||
<!-- ====================================================================== --> | ||
<!-- P R O J E C T D E S C R I P T I O N --> | ||
<!-- ====================================================================== --> | ||
<artifactId>acs-aem-commons-bundle-cloud</artifactId> | ||
<name>ACS AEM Commons Bundle - Core Cloud Fragment</name> | ||
<description>OSGi Core bundle fragment for ACS AEM Commons (only AEMaaCS)</description> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.sling</groupId> | ||
<artifactId>sling-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>biz.aQute.bnd</groupId> | ||
<artifactId>bnd-maven-plugin</artifactId> | ||
<configuration> | ||
<bnd><![CDATA[ | ||
Bundle-Name: ACS AEM Commons - Bundle Fragment (for AEMaaCS) | ||
Bundle-Description: ACS AEM Commons Core OSGi bundle fragment containing AEM server-side logic requiring AEMaaCS | ||
Fragment-Host: com.adobe.acs.acs-aem-commons-bundle | ||
]]></bnd> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>biz.aQute.bnd</groupId> | ||
<artifactId>bnd-baseline-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.sling</groupId> | ||
<artifactId>sling-maven-plugin</artifactId> | ||
<configuration> | ||
<slingUrl>${crx.protocol}://${crx.host}:${crx.port}${crx.contextRoot}</slingUrl> | ||
<slingUrlSuffix>/apps/acs-commons/install</slingUrlSuffix> | ||
<deploymentMethod>SlingPostServlet</deploymentMethod> | ||
<user>${crx.user}</user> | ||
<password>${crx.password}</password> | ||
<failOnError>true</failOnError> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<!-- annotations --> | ||
<dependency> | ||
<groupId>com.google.code.findbugs</groupId> | ||
<artifactId>jsr305</artifactId> | ||
<scope>provided</scope><!-- should not transitively be exposed --> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.adobe.acs</groupId> | ||
<artifactId>acs-aem-commons-bundle</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- Start Test dependencies --> | ||
<dependency> | ||
<groupId>com.adobe.acs</groupId> | ||
<artifactId>acs-aem-commons-bundle</artifactId> | ||
<version>${project.version}</version> | ||
<classifier>tests</classifier> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.sling</groupId> | ||
<artifactId>org.apache.sling.testing.osgi-mock.junit4</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.sling</groupId> | ||
<artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.wcm</groupId> | ||
<artifactId>io.wcm.testing.aem-mock.junit4</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- End Test dependencies --> | ||
<!-- the aem-sdk-api should be the last dependency, as other dependencies should take precedence in case of package clashes --> | ||
<dependency> | ||
<groupId>com.adobe.aem</groupId> | ||
<artifactId>aem-sdk-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
87 changes: 87 additions & 0 deletions
87
.../com/adobe/acs/commons/replication/dispatcher/impl/CloudDispatcherFlushRulesExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> dispatcherFlushRules; | ||
|
||
|
||
@Override | ||
public void process(Map<String, Object> props) { | ||
ReplicationActionType actionType = getReplicationActionType(props); | ||
List<String> distributionPaths = (List<String>) 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<String, Object> 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<String> list) { | ||
if (list == null) | ||
return null; | ||
Iterator<String> 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(); | ||
} | ||
|
||
} |
Oops, something went wrong.