Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Get replication agent id in Replication EventHandler

Avatar

Level 2

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.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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

View solution in original post

15 Replies

Avatar

Community Advisor

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.")

Avatar

Level 2

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

Avatar

Level 3

And you have an active replication agent? And whatever you publish actually gets replicated?

Avatar

Level 10

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.

Avatar

Level 2

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?

Avatar

Correct answer by
Employee Advisor

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

Avatar

Community Advisor

HI,

  • I tried writing Replication event handler and could reproduce the scenario you mentioned. (AgentConfig retrieved via Replication action is always null) Even another method getLog which returns ReplicationLog is also always null.
  • If we could observe the ReplicationAction API - ReplicationAction ("The Adobe AEM Quickstart and Web Application.") , constructors have params like action, path userId etc which we are able to successfully pull out on a Replication Event, while getConfig and getLog is more like setters and getters(from method summary) and not something that comes as is from action captured on a replication event.

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

Avatar

Level 2

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.

Avatar

Community Advisor

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?

Avatar

Level 2

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)

1473581_pastedImage_2.png

So, if I publish a page, it hits the various configured agents and I see as many log entries.

Hope this helps.

Avatar

Community Advisor

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)

Avatar

Level 2

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 PMorg/apache/sling/event/notification/job/START
:time100045212
replicationContentReplicationContentFacade{path='/var/replication/data/ba086918-77f4-4ea2-ad00-de563ab068d5/8e/8e60417c-46a9-4211-b4af-0fd75b7671e1', contentType='application/cq5-replication-durbo', contentLength=3117}
event.job.retrydelay6000
cq:typeACTIVATE
slingevent:applicationba086918-77f4-4ea2-ad00-de563ab068d5
jcr:createdjava.util.GregorianCalendar[time=1524090581394,areFieldsSet=true,areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id="GMT-07:00",offset=-25200000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2018,MONTH=3,WEEK_OF_YEAR=16,WEEK_OF_MONTH=3,DAY_OF_MONTH=18,DAY_OF_YEAR=108,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=3,AM_PM=1,HOUR=3,HOUR_OF_DAY=15,MINUTE=29,SECOND=41,MILLISECOND=394,ZONE_OFFSET=-25200000,DST_OFFSET=0]
slingevent:createdjava.util.GregorianCalendar[time=1493116623330,areFieldsSet=true,areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id="GMT-07:00",offset=-25200000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2017,MONTH=3,WEEK_OF_YEAR=17,WEEK_OF_MONTH=5,DAY_OF_MONTH=25,DAY_OF_YEAR=115,DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0,HOUR=3,HOUR_OF_DAY=3,MINUTE=37,SECOND=3,MILLISECOND=330,ZONE_OFFSET=-25200000,DST_OFFSET=0]
event.job.queuenamecom_day_cq_replication_job_sample_replication_agent
event.job.queued.timejava.util.GregorianCalendar[time=1524589709441,areFieldsSet=true,areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id="GMT-07:00",offset=-25200000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2018,MONTH=3,WEEK_OF_YEAR=17,WEEK_OF_MONTH=4,DAY_OF_MONTH=24,DAY_OF_YEAR=114,DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0,HOUR=10,HOUR_OF_DAY=10,MINUTE=8,SECOND=29,MILLISECOND=441,ZONE_OFFSET=-25200000,DST_OFFSET=0]
jcr:createdByadmin
sling:resourceTypeslingevent:Job
slingevent:eventId2017/4/25/3/37/ba086918-77f4-4ea2-ad00-de563ab068d5_3200
event.job.applicationba086918-77f4-4ea2-ad00-de563ab068d5
event.job.retries-1
cq:path/content/dam/cts/us/js/functions-benefits-for-companies.min.js
cq:userandyc
event.topicsorg/apache/sling/event/notification/job/START
event.job.started.timejava.util.GregorianCalendar[time=1524689754651,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Phoenix",offset=-25200000,dstSavings=0,useDaylight=false,transitions=12,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2018,MONTH=3,WEEK_OF_YEAR=17,WEEK_OF_MONTH=4,DAY_OF_MONTH=25,DAY_OF_YEAR=115,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=1,HOUR_OF_DAY=13,MINUTE=55,SECOND=54,MILLISECOND=651,ZONE_OFFSET=-25200000,DST_OFFSET=0]
jcr:primaryTypeslingevent:Job
event.job.retrycount2196766
event.job.topiccom/day/cq/replication/job/sample_replication_agent
cq:time1493116623156
timestamp1524689754653

Avatar

Community Advisor

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");

}

}

}

Avatar

Employee Advisor

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

Avatar

Level 2

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!!!