Get replication agent id in Replication EventHandler | Community
Skip to main content
Level 2
April 19, 2018
Solved

Get replication agent id in Replication EventHandler

  • April 19, 2018
  • 15 replies
  • 8526 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

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

15 replies

Vijayalakshmi_S
Level 10
April 25, 2018

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)

Level 2
April 26, 2018

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
Vijayalakshmi_S
Level 10
April 26, 2018

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

}

}

}

joerghoh
Adobe Employee
Adobe Employee
April 26, 2018

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

Level 2
May 10, 2018

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