Package com.adobe.cq.testing.client
Class ReplicationClient
- java.lang.Object
-
- org.apache.sling.testing.clients.AbstractSlingClient
-
- org.apache.sling.testing.clients.SlingClient
-
- com.adobe.cq.testing.client.CQClient
-
- com.adobe.cq.testing.client.ReplicationClient
-
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.http.client.HttpClient
public class ReplicationClient extends CQClient
Client for all replication related actions: activate, deactivate, agents management.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classReplicationClient.EmptyReplicationQueuePoller-
Nested classes/interfaces inherited from class com.adobe.cq.testing.client.CQClient
CQClient.Builder, CQClient.InternalBuilder<T extends CQClient>
-
-
Field Summary
Fields Modifier and Type Field Description static StringAUTHOR_GROUP_PATHstatic StringDIST_AGENTS_PATHstatic StringPUBLISH_REPLICATION_DEFAULT_AGENTstatic StringPUBLISH_REVERSE_REPLICATION_DEFAULT_AGENT-
Fields inherited from class com.adobe.cq.testing.client.CQClient
LOG, STATISTICS_ROOT, wcmCommands
-
-
Constructor Summary
Constructors Constructor Description ReplicationClient(URI serverUrl, String user, String password)ReplicationClient(org.apache.http.impl.client.CloseableHttpClient http, org.apache.sling.testing.clients.SlingClientConfig config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.sling.testing.clients.SlingHttpResponseactivate(String nodePath, int... expectedStatus)Activates (publish) a node.org.apache.sling.testing.clients.SlingHttpResponseactivate(String agent, String nodePath, int... expectedStatus)Activates(publish) a node on the given agent.org.apache.sling.testing.clients.SlingHttpResponseactivateLater(String nodePath, long timeMilliseconds, int... expectedStatus)Activates a page after a period of time.com.fasterxml.jackson.databind.JsonNodeadaptReplicationAgent(String agentPath, org.apache.http.message.BasicNameValuePair... properties)Adapts an existing agent's propertiesBooleancheckContentDistributionAgentExists(String agent)Checks whether the given agent exists.com.fasterxml.jackson.databind.JsonNodecreateReplicationAgent(String name, String title, String parentPath, String template, org.apache.http.message.BasicNameValuePair... properties)Creates a replication agent, if not already presentorg.apache.sling.testing.clients.SlingHttpResponsedeactivate(String pagePath, int... expectedStatus)Deactivates (un-publish) a node.org.apache.sling.testing.clients.SlingHttpResponsedeactivate(String agent, String pagePath, int... expectedStatus)Deactivates (un-publish) a node on the specified agent.org.apache.sling.testing.clients.SlingHttpResponsedeactivateLater(String nodePath, long timeMilliseconds, int... expectedStatus)Deactivates a page after a period of time.booleanfindInLog(String agentLocation, String[] patterns, Date startTime)Returns true if the specific at least one pattern was found in the log or false otherwise.com.fasterxml.jackson.databind.JsonNodegetAgentReplicationQueue(String agentPath)Returns the agent replication queue.com.fasterxml.jackson.databind.JsonNodegetPublishReplicationQueue()Returns the default replication agent queue.com.fasterxml.jackson.databind.JsonNodegetReverseReplicationQueue()Returns the reverse replication agent queue.booleanisConnectionSuccessful(String agentLocation)voidwaitAgentReplicationQueueIsEmpty(String agentPath)Waits until the queue of the requested agent is emptyvoidwaitPublishReplicationQueueIsEmpty()booleanwaitQueueEmptyOfPath(String agentPath, String replicatedPath)Checks if the item is empty or if not whether the replicated path is in the list of packages.voidwaitReversePublishReplicationQueueIsEmpty()-
Methods inherited from class com.adobe.cq.testing.client.CQClient
copyLanguages, copyPage, createPage, createPageWithRetry, createVersion, deletePage, deletePageWithRetry, getAuthorSitesPage, lockPage, movePage, movePage, pageExists, pageExistsWithRetry, pageExistsWithRetry, resetPageStatistics, restoreTree, restoreVersion, rolloutPage, searchAndReplaceInPages, searchInPages, setPageProperties, setPageProperty, setPagePropertyImage, unlockPage, uploadFileCQStyle
-
Methods inherited from class org.apache.sling.testing.clients.SlingClient
createFolder, createNode, createNodeRecursive, deletePath, doGetJson, endImpersonation, exists, getJsonNode, getJsonNode, getNodeNameFromPath, getParentPath, getUser, getUUId, getUUID, impersonate, importContent, importContent, importJson, move, setPropertiesString, setPropertyString, setPropertyStringArray, upload, waitExists, waitUntilExists
-
Methods inherited from class org.apache.sling.testing.clients.AbstractSlingClient
adaptTo, addValue, close, doDelete, doGet, doGet, doGet, doHead, doPatch, doPost, doPost, doPut, doRawRequest, doRequest, doStreamGet, doStreamPost, doStreamRequest, execute, execute, execute, execute, execute, execute, execute, execute, getClientId, getConnectionManager, getCookieStore, getCredentialsProvider, getParams, getPassword, getPath, getPath, getUrl, getUrl, getUrl, getValue, getValues, hasValue
-
-
-
-
Field Detail
-
AUTHOR_GROUP_PATH
public static final String AUTHOR_GROUP_PATH
- See Also:
- Constant Field Values
-
PUBLISH_REPLICATION_DEFAULT_AGENT
public static final String PUBLISH_REPLICATION_DEFAULT_AGENT
- See Also:
- Constant Field Values
-
PUBLISH_REVERSE_REPLICATION_DEFAULT_AGENT
public static final String PUBLISH_REVERSE_REPLICATION_DEFAULT_AGENT
- See Also:
- Constant Field Values
-
DIST_AGENTS_PATH
public static final String DIST_AGENTS_PATH
- See Also:
- Constant Field Values
-
-
Method Detail
-
activate
public org.apache.sling.testing.clients.SlingHttpResponse activate(String agent, String nodePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Activates(publish) a node on the given agent.- Parameters:
agent- agent to send the replication requestnodePath- path of the node to activateexpectedStatus- list of expected HTTP status to be returned, if not set, 200 is assumed.- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
activate
public org.apache.sling.testing.clients.SlingHttpResponse activate(String nodePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Activates (publish) a node.- Parameters:
nodePath- path of the node to activateexpectedStatus- list of expected HTTP status to be returned, if not set, 200 is assumed.- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
deactivate
public org.apache.sling.testing.clients.SlingHttpResponse deactivate(String agent, String pagePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Deactivates (un-publish) a node on the specified agent.- Parameters:
agent- agent to send the replication requestpagePath- path of the node to deactivateexpectedStatus- list of expected HTTP status to be returned, if not set, 200 is assumed.- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
deactivate
public org.apache.sling.testing.clients.SlingHttpResponse deactivate(String pagePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Deactivates (un-publish) a node.- Parameters:
pagePath- path of the node to deactivateexpectedStatus- list of expected HTTP status to be returned, if not set, 200 is assumed.- Returns:
- the response
- Throws:
org.apache.sling.testing.clients.ClientException- if something fails during the request/response cycle
-
activateLater
public org.apache.sling.testing.clients.SlingHttpResponse activateLater(String nodePath, long timeMilliseconds, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Activates a page after a period of time.- Parameters:
nodePath- The path to the node which is activatedtimeMilliseconds- The time interval, in milliseconds, from current timestamp, after which the node will be activatedexpectedStatus- list of expected statuses- Returns:
- the http response
- Throws:
org.apache.sling.testing.clients.ClientException- if the request fails
-
deactivateLater
public org.apache.sling.testing.clients.SlingHttpResponse deactivateLater(String nodePath, long timeMilliseconds, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
Deactivates a page after a period of time.- Parameters:
nodePath- The path to the node which is deactivatedtimeMilliseconds- The time interval, in milliseconds, from current timestamp, after which the node will be deactivatedexpectedStatus- list of expected statuses- Returns:
- the http response
- Throws:
org.apache.sling.testing.clients.ClientException- if the request fails
-
createReplicationAgent
public com.fasterxml.jackson.databind.JsonNode createReplicationAgent(String name, String title, String parentPath, String template, org.apache.http.message.BasicNameValuePair... properties) throws org.apache.sling.testing.clients.ClientException, InterruptedException
Creates a replication agent, if not already present- Parameters:
name- name of the agenttitle- title of the agent (page)parentPath- where to create the agent. Typical paths for CQ are/etc/replication/agents.author/and/etc/replication/agents.publish/template- template of the agent. Typical value is/libs/cq/replication/templates/agentproperties- list of properties to be set on the agent- Returns:
- the json representation of agent's (jcr:content) node
- Throws:
org.apache.sling.testing.clients.ClientException- if the request failsInterruptedException- to mark this method as waiting
-
adaptReplicationAgent
public com.fasterxml.jackson.databind.JsonNode adaptReplicationAgent(String agentPath, org.apache.http.message.BasicNameValuePair... properties) throws org.apache.sling.testing.clients.ClientException, InterruptedException
Adapts an existing agent's properties- Parameters:
agentPath- the path of the agentproperties- list of properties to be set on the agent- Returns:
- the json representation of the agent's (jcr:content) node
- Throws:
org.apache.sling.testing.clients.ClientException- if the request failsInterruptedException- to mark this method as waiting
-
getAgentReplicationQueue
public com.fasterxml.jackson.databind.JsonNode getAgentReplicationQueue(String agentPath) throws org.apache.sling.testing.clients.ClientException, InterruptedException
Returns the agent replication queue.- Parameters:
agentPath- The location in jcr where the agent is stored.- Returns:
- the queue as json node
- Throws:
org.apache.sling.testing.clients.ClientException- if the request failsInterruptedException- to mark this method as waiting
-
checkContentDistributionAgentExists
public Boolean checkContentDistributionAgentExists(String agent) throws org.apache.sling.testing.clients.ClientException
Checks whether the given agent exists.- Parameters:
agent- to check- Returns:
- true if the given agent exists
- Throws:
org.apache.sling.testing.clients.ClientException- if an error occurred
-
waitQueueEmptyOfPath
public boolean waitQueueEmptyOfPath(String agentPath, String replicatedPath) throws Exception
Checks if the item is empty or if not whether the replicated path is in the list of packages. Sample HTTP response{ "name": "publish", "queues": { "items": [ "7ece8e2c-d641-4d50-a0ff-6fcd3c52f7d8-publishSubscriber", "0c77809c-cb61-437b-981b-0424c042fd92-publishSubscriber" ], "7ece8e2c-d641-4d50-a0ff-6fcd3c52f7d8-publishSubscriber": { "state": "BLOCKED", "items": [ "package-0@52734825" ], "itemsCount": 1, "empty": false, "package-0@52734825": { "size": 6073, "paths": [ "/content/test-site/testpage_8e57dec8-40e8-4e42-a267-ff5142f5c472" ], "errorMessage": "Failed attempt (12/infinite) to import the distribution package" }, "0c77809c-cb61-437b-981b-0424c042fd92-publishSubscriber": { "sling:resourceType": "sling/distribution/service/agent/queue", "state": "IDLE", "items": [], "itemsCount": 0, "empty": true } }, "log": { "sling:resourceType": "sling/distribution/service/log" }, "status": { "state": "BLOCKED" } }- Parameters:
agentPath- the agent path for which queues to be assertedreplicatedPath- the path replicated- Returns:
- true if path empty
- Throws:
Exception- the exception
-
getPublishReplicationQueue
public com.fasterxml.jackson.databind.JsonNode getPublishReplicationQueue() throws org.apache.sling.testing.clients.ClientException, InterruptedExceptionReturns the default replication agent queue.- Returns:
- the queue as json node
- Throws:
org.apache.sling.testing.clients.ClientException- if the request failsInterruptedException- to mark this method as waiting
-
getReverseReplicationQueue
public com.fasterxml.jackson.databind.JsonNode getReverseReplicationQueue() throws org.apache.sling.testing.clients.ClientException, InterruptedExceptionReturns the reverse replication agent queue.- Returns:
- the queue as json node
- Throws:
org.apache.sling.testing.clients.ClientException- if the request failsInterruptedException- to mark this method as waiting
-
waitAgentReplicationQueueIsEmpty
public void waitAgentReplicationQueueIsEmpty(String agentPath) throws InterruptedException, org.apache.sling.testing.clients.ClientException
Waits until the queue of the requested agent is empty- Parameters:
agentPath- path to the agent- Throws:
org.apache.sling.testing.clients.ClientException- if the queue is not empty after the default timeout (2 min) expiresInterruptedException- to mark this method as waiting
-
waitPublishReplicationQueueIsEmpty
public void waitPublishReplicationQueueIsEmpty() throws InterruptedException, org.apache.sling.testing.clients.ClientException- Throws:
InterruptedExceptionorg.apache.sling.testing.clients.ClientException
-
waitReversePublishReplicationQueueIsEmpty
public void waitReversePublishReplicationQueueIsEmpty() throws InterruptedException, org.apache.sling.testing.clients.ClientException- Throws:
InterruptedExceptionorg.apache.sling.testing.clients.ClientException
-
isConnectionSuccessful
public boolean isConnectionSuccessful(String agentLocation) throws org.apache.sling.testing.clients.ClientException
- Throws:
org.apache.sling.testing.clients.ClientException
-
findInLog
public boolean findInLog(String agentLocation, String[] patterns, Date startTime) throws org.apache.sling.testing.clients.ClientException
Returns true if the specific at least one pattern was found in the log or false otherwise.- Parameters:
agentLocation- agent pathpatterns- list of patternsstartTime- start time- Returns:
- true if the pattern was found
- Throws:
org.apache.sling.testing.clients.ClientException- if the request fails
-
-