AEM Workflows allow you to automate a series of steps that are performed on (one or more) pages and/or assets.
How can we make sure workflow won’t impact AEM performance (CPU or Heap memory) / throttle the system?
Introduction:
AEM Workflows allow you to automate a series of steps that are performed on (one or more) pages and/or assets.
For example, when publishing, an editor has to review the content – before a site administrator activates the page. A workflow that automates this example notifies each participant when it is time to perform their required work:
The author applies the workflow to the page.
The editor receives a work item that indicates that they are required to review the page content. When finished, they indicate that their work item is complete.
The site administrator then receives a work item that requests the activation of the page. When finished, they indicate that their work item is complete.
Typically:
Content authors apply workflows to pages as well as participate in workflows.
The workflows that you use are specific to the business processes of your organization.
ACS Commons Throttled Task Runner is built on Java management API for managing and monitoring the Java VM and can be used to pause tasks and terminate the tasks based on stats.
Throttled Task Runner (a managed thread pool) provides a convenient way to run many AEM-specific activities in bulk it basically checks for the Throttled Task Runner bean and gets current running stats of the actual work being done.
OSGi Configuration:
The Throttled Task Runner is OSGi configurable, but please note that changing configuration while work is being processed results in resetting the worker pool and can lose active work.
Throttled task runner OSGi
Max threads: Recommended not to exceed the number of CPU cores. Default 4.
Max CPU %: Used to throttle activity when CPU exceeds this amount. Range is 0..1; -1 means disable this check.
Max Heap %: Used to throttle activity when heap usage exceeds this amount. Range is 0..1; -1 means disable this check.
Cooldown time: Time to wait for CPU/MEM cooldown between throttle checks (in milliseconds)
Watchdog time: Maximum time allowed (in ms) per action before it is interrupted forcefully.
JMX MBeans
Throttled Task Runner MBean
This is the core worker pool. All action managers share the same task runner pool, at least in the current implementation. The task runner can be paused or halted entirely, throwing out any unfinished work.
AEM Schedulers are commonly used to run bulk tasks at an off time (nonbusiness hours) and some tasks are run periodically to fetch results cached and fetched by the front end.
How can we make sure bulk tasks won’t impact AEM performance (CPU or Heap memory) / throttle the system?
Introduction:
In Computer Software, Scheduling is a paradigm of planning for the execution of a task at a certain point in time and it can be broadly classified into two types:
1. Scheduled Task – executing once at a particular future point in time
2. Frequent scheduling – repeat periodically at a fixed interval
The use case for the scheduler:
1. Sitemap generation
2. Synching product data from AEM Commerce
3. Fetch DB content and place it in the repository to be picked up by frontend and in turn cached in Dispatcher
4. Fetch Stats or reports and place them in the repository to be picked up by frontend and in turn cached in Dispatcher
ACS Commons Throttled Task Runner is built on Java management API for managing and monitoring the Java VM and can be used to pause tasks and terminate the tasks based on stats.
Throttled Task Runner (a managed thread pool) provides a convenient way to run many AEM-specific activities in bulk it basically checks for the Throttled Task Runner bean and gets current running stats of the actual work being done.
OSGi Configuration:
The Throttled Task Runner is OSGi configurable, but please note that changing configuration while work is being processed results in resetting the worker pool and can lose active work.
Throttled task runner OSGi
Max threads: Recommended not to exceed the number of CPU cores. Default 4.
Max CPU %: Used to throttle activity when CPU exceeds this amount. Range is 0..1; -1 means disable this check.
Max Heap %: Used to throttle activity when heap usage exceeds this amount. Range is 0..1; -1 means disable this check.
Cooldown time: Time to wait for CPU/MEM cooldown between throttle checks (in milliseconds)
Watchdog time: Maximum time allowed (in ms) per action before it is interrupted forcefully.
JMX MBeans
Throttled Task Runner MBean
This is the core worker pool. All action managers share the same task runner pool, at least in the current implementation. The task runner can be paused or halted entirely, throwing out any unfinished work.
How to access the CRX package manager in AEM PROD or AEM as Cloud services?
User cases:
Latest content package from PROD to lowers or local for debugging purposes
Install the content package on PROD
Continue the PROD deployment during CM outage in between deployment
Introduction:
AEM OOTB comes with multiple tools in AEM and to access all the tools you need to navigate to the tool section and select the appropriate sections to perform all the operations
For example:
AEM operations
Managing templates
Cloud configurations
ACS Commons tools etc..
Tools are an essential part of AEM and avoid any dependency on Groovy scripts or any add scripts and can be managed or extended at any given point in time.
Package handler can be used to upload, install, build or delete packages and we are using JCR Package manager to achieve all the above options.
Usually, if want to perform any operations on AEM as managed services are AEMaaCS we need to go through CAB, and AMS resources will perform all the operations as mentioned on the CAB. However, if your project has shared resources then all the priority package operations will take more time on PROD or any other environments.
Once the code is built and deployed you will be able to access the tool by navigating the:
Tools -> {Tool Section} -> {Tool Name}
Package Handler Tool Section
Now you can access the package handler and upload the packages to AEM as an upload or upload and install.
Package Handler Page
If you’re building any existing packages then you can build, install or delete packages. Provide package name, version, and group details to pull the package.
Provide the desired package name and Description and you can see the package path will be prompted and you will be able to download the built package by clicking on the link:
Note: You can access this package over domain on AEM / AEMaaCS and over any environments and architects can handle the permissions by adding appropriate rep:policy on cq generator node or conf page
Can we Publish / Un Publish / Delete the list of paths mentioned in an excel sheet? Or provided has a linefeed
Introduction:
AEM OOTB comes with multiple tools in AEM and to access all the tools you need to navigate to the tool section and select the appropriate sections to perform all the operations
For example:
AEM operations
Managing templates
Cloud configurations
ACS Commons tools etc..
Tools are an essential part of AEM and avoid any dependency on Groovy scripts or any add scripts and can be managed or extended at any given point in time.
Usually, product owners or authors would like to Publish certain pages like offer/product/article pages based on business requirements and also would like to unpublish and delete to clean up the pages which are unnecessary.
This process will be really helpful during excel sheet based migration.
The list Replication process usually validates the paths and if it exists then activates or deactivates or deletes pages or content paths. It accepts an excel sheet or list of paths as a line feed.
You can also provide a list of agents to be activated/deactivated to for example only to Brightspot or Brightcove connector.
Once the code is built and deployed you will be able to access the tool by navigating the:
Tools -> {Tool Section} -> {Tool Name}
List Process Section
Now you can input the page paths as a line feed (no need to separate the paths using commas or any characters)
List Process Page
Upload the excel sheet or paths and select the queue method it’s recommended to use MCP Queue if you are activating more than 10K pages then it’s recommended to select MCP After 10K.
Note: You can access this package over domain on AEM / AEMaaCS and over any environments and architects can handle the permissions by adding appropriate rep:policy on cq generator node or conf page
Create a perfect content backup package in AEM, whenever we want to create any package in AEM we provide the content paths in the package filter manually and what do we get?
We get only content pages.
What about images and referenced pages?
What about header/footer experience fragment pages or XF page-related context hub variations?
Introduction:
AEM OOTB comes with multiple tools in AEM and to access all the tools you need to navigate to the tool section and select the appropriate sections to perform all the operations
For example:
AEM operations
Managing templates
Cloud configurations
ACS Commons tools etc..
Tools are an essential part of AEM and avoid any dependency on Groovy scripts or any add scripts and can be managed or extended at any given point in time.
Perfect packager pulls the current page resource and iterates on each node and gets the referenced images, pages, and XF’s. Once all the paths are pulled it reiterates to find all the referenced pages to get all the images, XF’s, and pages.
Once the code is built and deployed you will be able to access the tool by navigating the:
Tools -> {Tool Section} -> {Tool Name}
Perfect Package section
Now you can input the page paths as a line feed (no need to separate the paths using commas or any characters)
Perfect Package Result
Provide the desired package name and description and you can see the package path will be prompted and you will be able to download the built package by clicking on the link:
Perfect Package resultPerfect package built and has all the references
Note: You can access this package over domain on AEM / AEMaaCS and over any environments and architects can handle the permissions by adding appropriate rep:policy on cq generator node or conf page
Avoid adding individual paths manually in the CRX Package manager
Option to package current page or pull children
Introduction:
AEM OOTB comes with multiple tools in AEM and to access all the tools you need to navigate to the tool section and select the appropriate sections to perform all the operations
For example:
AEM operations
Managing templates
Cloud configurations
ACS Commons tools etc..
Tools are an essential part of AEM and avoid any dependency on Groovy scripts or any add scripts and can be managed or extended at any given point in time.
Package Creator is an extension of the ACS Commons Package handler, but it’s UI friendly and easy to access. You can input the paths to be packaged as a line feed and no need to separate them by a comma. Once the package is ready it will be built and prompted with a download option.
Once the code is built and deployed you will be able to access the tool by navigating the:
Tools -> {Tool Section} -> {Tool Name}
Package Creator
Now you can input the page paths as a line feed (no need to separate the paths using commas or any characters)
Creator Page
Provide the list paths to be backed up, desired package name, and description and select the dropdown to pull children or not. Once the package is built you can see the package path will be prompted and you will be able to download the package by clicking on the built package link:
Package Creator ResultsThe package is built with the exact page location
Note: You can access this package over domain on AEM / AEMaaCS and over any environments and architects can handle the permissions by adding appropriate rep:policy on cq generator node or conf page
Create a tool similar to AEM Operations or ACS Commons for easy access and to run any maintenance process/tasks.
Introduction:
AEM OOTB comes with multiple tools in AEM and to access all the tools you need to navigate to the tool section and select the appropriate sections to perform all the operations
For example:
AEM operations
Managing templates
Cloud configurations
ACS Commons tools etc..
Tools are an essential part of AEM and avoid any dependency on Groovy scripts or any add scripts and can be managed or extended at any given point in time.
In order to create any tool from scratch takes a lot of time and man hours and once all the configs are ready then it takes more time to develop the services and servlet to handle the business logic.
By using this tool, you can avoid all kinds of configurations and initialsetup and kick start with your own first tool from scratch
The tool generator consists of the:
Sling model – to generate fields and handle inputs
Servlet – to process request
Component – to handle view (HTL), CSS, and JS
All the above sample scratch setups along with ready to check-in code will be added to the code base.
How to use the tool?
1. Click on the link to download the tool generator package and install it into your local instance
2. Once the package is installed go to sites -> tools -> and select the Tool Generator section
tool section
3. Select Tool Settings on the top right hand corner and provide your local repository paths like sling model path, servlet path, apps path, conf path, and CQ path if it already exists
tool page
4. Once all the settings are authored save the settings
tool settings
5. After coming to the generator page provide your tool name and tool description
tool authoring
6. If you have an existing tool then select Yes else Select No and provide the Tool Section name
7. Click on Create tool to create your new tool from scratch
tool result
Check your repository for all the file changes as shown below:
You can also check your new tool component and other configs on CRXDE
You can also visit your new tool by accessing the tool section (sites -> Tools -> {Your section name})
For more info on how to add a Sling model field please visit the below link:
Once your Sling model, servlet, and other things are ready make sure you add the following filter in your META-INF folder and keep it merge as shown below:
This would avoid replacing/overriding any other tools like ACS Commons or your other repo tools.
Retry posting the data at least some time until the response is 200
Retry any OAK operations, when the exception occurs
Introduction:
Usually, with respect to AEM, we don’t have Retry Utils which can retry the particular operation whenever an exception occurred.
If we are doing multiple transactions on the AEM repository, especially on a particular node like updating properties or updating references, the OAK operation would through exceptions like your operation is blocked by another operation or invalid modification.
If we are connecting to external services through REST API and the connection has failed or timeout and if we want to connect to the external system then we don’t have the option to retry out of the box
Create a Retry Utils as shown below:
Retry on Exception:
package com.test.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RetryOnException {
private static final Logger log = LoggerFactory.getLogger(RetryOnException.class);
public static interface CallToRetry {
void process() throws Exception;
}
public static boolean withRetry(int maxTimes, long intervalWait, CallToRetry call) throws Exception {
if (maxTimes <= 0) {
throw new IllegalArgumentException("Must run at least one time");
}
if (intervalWait <= 0) {
throw new IllegalArgumentException("Initial wait must be at least 1");
}
Exception thrown = null;
for (int counter = 0; counter < maxTimes; counter++) {
try {
call.process();
return true;
} catch (Exception e) {
thrown = e;
log.info("Encountered failure on {} due to {}, attempt retry {} of {}", call.getClass().getName() , e.getMessage(), (counter + 1), maxTimes, e);
}
try {
Thread.sleep(intervalWait);
} catch (InterruptedException wakeAndAbort) {
break;
}
}
throw thrown;
}
}
The above Util can be used in any code as shown below and the retry will happen only when the exception occurs during operations
package com.test.utils;
import java.util.concurrent.atomic.AtomicInteger;
import org.aarp.www.mcp.utils.RetryOnException;
public class ExampleOne {
public static void main(String[] args) {
AtomicInteger atomicCounter = new AtomicInteger(0);
try {
RetryOnException.withRetry(3, 500, () -> {
if(atomicCounter.getAndIncrement() < 2) {
System.out.println("Retring count with Exception" + atomicCounter.get());
throw new Exception("Throwing New Exception to test");
} else {
System.out.println("Retring count without Exception " + atomicCounter.get());
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
Exception Result
Retry on the condition:
package com.test.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RetryOnCondition {
private static final Logger log = LoggerFactory.getLogger(RetryOnCondition.class);
public static interface CallToRetry {
boolean process() throws Exception;
}
public static boolean withRetry(int maxTimes, long intervalWait, CallToRetry call) throws Exception {
if (maxTimes <= 0) {
throw new IllegalArgumentException("Must run at least one time");
}
if (intervalWait <= 0) {
throw new IllegalArgumentException("Initial wait must be at least 1");
}
Exception thrown = null;
for (int counter = 0; counter < maxTimes; counter++) {
try {
boolean status = call.process();
if(status) {
return true;
}
} catch (Exception e) {
thrown = e;
log.info("Encountered failure on {} due to {}, attempt retry {} of {}", call.getClass().getName() , e.getMessage(), (counter + 1), maxTimes, e);
}
try {
Thread.sleep(intervalWait);
} catch (InterruptedException wakeAndAbort) {
break;
}
}
throw thrown;
}
}
The above Util can be used to retry based on the condition like if the connection is successful or the response code is 200
Create a perfect package in AEM, whenever we want to create any package in AEM we provide the content paths in the package filter we get only content pages. But what about images and reference pages? What about experience fragment pages or XF page-related context hub variations?
Introduction:
MCP (Manage Controlled Processes) is both a dashboard for performing complex tasks and a rich API for defining these tasks as process definitions. In addition to kicking off new processes, users can also monitor running tasks, retrieve information about completed tasks, halt work, and so on.
Add the following maven dependency to your pom to extend MCP
In order to create a perfect content package in AEM, please create an MCP as shown below:
Create Process Definition factory – PackageCreatorFactory
This class tells ACS Commons MCP to pick the process definition and process name getName and you need to mention the implementation class inside the createProcessDefinitionInstance method as shown below:
How to access the CRX package manager in PROD or AEM as Cloud services?
User cases:
Latest content package from PROD to lowers or local for debugging purposes
Install the content package on PROD
Continue the PROD deployment during CM outage in between deployment
Introduction:
Packages enable the importing and exporting of repository content. For example, you can use packages to install new functionality, transfer content between instances, and back up repository content.
A package is a zip file holding repository content in the form of a file-system serialization (called “vault” serialization). This provides an easy-to-use-and-edit representation of files and folders.
Packages include content, both page content and project-related content, selected using filters.
A package also contains vault meta information, including the filter definitions and import configuration information. Additional content properties (that are not used for package extraction) can be included in the package, such as a description, a visual image, or an icon; these properties are for the content package consumer and for informational purposes only.
In order to access packages in AEM:
MCP (Manage Controlled Processes) is both a dashboard for performing complex tasks and a rich API for defining these tasks as process definitions. In addition to kicking off new processes, users can also monitor running tasks, retrieve information about completed tasks, halt work, and so on.
Add the following maven dependency to your pom to extend MCP
Create Process Definition factory – PackageHandlerFactory
This class tells ACS Commons MCP to pick the process definition and process name getName and you need to mention the implementation class inside the createProcessDefinitionInstance method as shown below: