Hello All,
I am implementing a replication event handler and one of the requirements is to get the replication agent id for each of the activate processes.
This is snippet of what I have written in the handleEvent method
ReplicationAction replicationAction = ReplicationAction.fromEvent(event);
if (null != replicationAction) {
String path = replicationAction.getPath();
String type = replicationAction.getType() != null ? replicationAction.getType().toString() : "";
LOG.info("Replication triggered {} for {} ", type, path);
String strReplicationAgentId = replicationAction.getConfig() != null ? replicationAction.getConfig().getAgentId() : "";
LOG.info("ReplicationAgentId: {}", strReplicationAgentId);
}
The issue is that the strReplicationAgentIdis always null.
I know that this is based on the runmodes, but not sure how to get the agent ids involved in the replication event.
Any guidance on how to achieve this will be very helpful.
Solved! Go to Solution.
Views
Replies
Total Likes
When you check the information available for a replication event (localhost:4502/system/console/events), you can see that there is no agentID contained in it.
I think, that the replication event is sent per replication action (for example per page), and not per agent ID. That means a single replication event stands for the replication of a single resource via all available/configured replication agents.
Jörg
Views
Replies
Total Likes
Hi,
Can you try accessing any other methods of AgentConfig instead of getAgentId and see if you are able to get the result. Based on this, we can then narrow down to why we are not able to get the agentId.
AgentConfig ("The Adobe AEM Quickstart and Web Application.")
Views
Replies
Total Likes
Hi,
I did some more debugging and see that the AgentConfig object returned by replicationAction.getConfig() itself is null.
So all methods for the AgentConfig return null.
That is very strange and I am clueless
Views
Replies
Total Likes
And you have an active replication agent? And whatever you publish actually gets replicated?
Views
Replies
Total Likes
We have an older community artilce that show how to create a Rep Event Handler -- Adobe CQ Help | Creating Replication Event Handlers for Adobe Experience Manager
We will update this soon to a more recent version of AEM.
Views
Replies
Total Likes
Yes, my replication agents are active and content is getting replicated successfully.
One thing I did notice in the logs further is that some how the event handler is getting invoked few seconds earlier than the actual replication happening.
Is this a possibility?
Views
Replies
Total Likes
When you check the information available for a replication event (localhost:4502/system/console/events), you can see that there is no agentID contained in it.
I think, that the replication event is sent per replication action (for example per page), and not per agent ID. That means a single replication event stands for the replication of a single resource via all available/configured replication agents.
Jörg
Views
Replies
Total Likes
HI,
Given this, If you could share the exact use case/requirement you are trying to achieve with agent configs, perhaps we can see if there are any other ways
Views
Replies
Total Likes
Thank you for looking into it.
We have a event audit functionality that feeds an audit log for page create/update/delete, asset create/delete, workflow start, active, deactivate events that in turn is fed to ELK where we have custom ops dashboards.
Specifically to the activate event, when a reviewer approves a workflow task, a series of activate events are triggered corresponding to the targeted replication agents.
As an example, I have publish, flush, test_target as the 3 configured agents. I see 3 events corresponding to page activate.
For proper reporting, I want to filter on only the "publish" events and filter the flush and test_target events, therefore trying to get the agentId from the replication action config.
Views
Replies
Total Likes
HI,
Could you please help clarify the inline comments(in italics)
Specifically to the activate event, when a reviewer approves a workflow task, a series of activate events are triggered corresponding to the targeted replication agents. - - Are you using custom process step for approval/ replicating wherein you explicitly set the replication agents via "setFilter" of ReplicationOptions for replicator.replicate?
As an example, I have publish, flush, test_target as the 3 configured agents. I see 3 events corresponding to page activate. - Can you elaborate on this, especially - 3 events for page activate?
Views
Replies
Total Likes
Are you using custom process step for approval/ replicating wherein you explicitly set the replication agents via "setFilter" of ReplicationOptions for replicator.replicate?
Yes, I have a custom process step. The agent names are fetched from the process args and then we set to ReplicationOptions
for(String agentId : agentIdsArray) {
try{
agentIdFilter = new AgentIdFilter(agentId);
replicationOptions = new ReplicationOptions();
replicationOptions.setFilter(agentIdFilter);
Can you elaborate on this, especially - 3 events for page activate?
This is in the step properties for my generic replicator (as we call it)
So, if I publish a page, it hits the various configured agents and I see as many log entries.
Hope this helps.
Views
Replies
Total Likes
HI,
By the term "many log entries", does it lists agent related information/custom log entries or what exact information we are able to pull from it on "page publish".
The reason why I ask is I tried setting specific replication agent for replicating a page (via replicationOptions) and if we try to capture this replication event, even then it will not be able to pull the agent information via ReplicationAction. - With this, I was able to conclude that irrespective of what agents we explicitly specify, respective replication event will not be able to pull those details. (per the reasoning mentioned in the previous comment)
Views
Replies
Total Likes
There are custom logs, and on an activate we do print the agent ids that is referred to in the agent filter.
Another question, when I check system/console/events I see detailed information on the actual event, as an example:
How can I read either the event.job.queuename or event.job.topic for ACTIVATE and job/FINISHED.
This way I can probably extract the agent ids.
4/25/2018, 1:55:54 PM | org/apache/sling/event/notification/job/START |
|
Views
Replies
Total Likes
Hi,
We are setting 4 agents -> replicationOptions and hence replicator.replicate is called in a loop -> comes as 4 separate Jobs (snapshot you have shared from system/console/events)
Each will have Job/START and Job/FINISHED.
As such we will be able to listen to these event topics and in handleEvent(event) -> event Object will have the properties accessible and not the actual agentId itself.
Sample snippet for reference:
@Component(service=EventHandler.class, property=EventConstants.EVENT_TOPIC+"=org/apache/sling/event/notification/job/START")
public class JobStartFinishListener implements EventHandler {
private Logger log = LoggerFactory.getLogger(this.getClass());
@Override
public void handleEvent(Event event) {
String replicationAgentName = event.getProperty("event.job.queuename").toString();
if(replicationAgentName.contains("publish"))
{
log.info("Publish agent in job start and end");
}
}
}
Views
Replies
Total Likes
If you need this information only for audit purposes, and if the replication runs in a workflow anyway, why don't you create a workflow step which creats this kind of audit information, and attach it to the workflow?
Parsing the data out of the queue name seems to work, but it's not guaranteed to work.
Jörg
Views
Replies
Total Likes
Thank you All for the guidance. As a quick fix I am now listening to the org/apache/sling/event/notification/job/FINISHED topic and further filtering on the ACTIVATE and DEACTIVATE event types.
In the long run will follow the suggestion from Jorg Hoh and add this logging as a workflow step.
Thank you again!!!
Views
Replies
Total Likes
Views
Like
Replies
Views
Likes
Replies