The 5.7 branch of Magnolia reached End-of-Life on December 31, 2023, as specified in our End-of-life policy. This means the 5.7 branch is no longer maintained or supported. Please upgrade to the latest Magnolia release. By upgrading, you will get the latest release of Magnolia featuring significant improvements to the author and developer experience. For a successful upgrade, please consult our Magnolia 6.2 documentation. If you need help, please contact info@magnolia-cms.com.

The Synchronization REST module provides a convenient REST API for publishing content from a source Magnolia instance (typically an author instance) to a target Magnolia instance (typically a public instance). It provides another way to synchronize content using the Synchronization module and start synchronization, monitor synchronizations and stop synchronizations remotely through via a REST service. 

The module allows you to publish a large amount of content selectively. Only previously published content is transferred to the target instance. You can use the module to add content to new public instances without shutting down existing instances and impacting their ability to serve content.

Command REST vs Sync REST

You could launch a launch a synchronization with the command API of the REST module, however, synchronizing using the Synchronization REST API has several advantages compared to the command REST API: 

synchronous 

  • The API will not return a result until the synchronization has finished. Synchronizations may take some time to finish depending on the amount of content. 

fixed configuration

  • Must be configured before launching a synchronization. The synchronization command uses a receiver defined in the Synchronization module's configuration. The receiver defines the target Magnolia instance to send content to and can't be passed to the synchronization command. 

uncontrolled execution

  • It is possible to launch identical synchronizations to the same instance if not carefully orchestrated. You can launch many synchronizations simultaneously. Synchronizations adds load on the source Magnolia instance; you can overload the source Magnolia instance by launching too many synchronizations at the same time.
asynchronous
  • A synchronization launched with the Synchronization REST API returns immediately with a job ID and provides calls to check on the status of the synchronization job (waiting for execution, running, finished successfully and finished with errors). 
    In addition, if you need to define a site specific receiver using workspace path mappings, you can define a template receiver in the configuration of the Synchronization REST module and use the mappings in the template to perform the synchronization. 

no configuration

  • You can specify all the details of the synchronization (URL for the Magnolia instance, workspace, path and more) when launching the synchronization. No configuration is needed to start a synchronization.

controlled execution

Using these policies, you can avoid overloading the source Magnolia instance and prevent duplicate synchronizations of the same content to a Magnolia instance.

  • The synchronization policy can be set to control synchronizations:
    • Allow only one synchronization at a time
    • Allow only one synchronization to a target Magnolia instance
    • Allow only one synchronization of a workspace to a target Magnolia instance
    • Allow all requested synchronizations

Installing

Maven is the easiest way to install the module. Add the following to your bundle. The parent POM of your webapp project should set the latest version of the module automatically. Should you need to use a specific module version, you can define it using the <version/> in the dependency.

<dependency>
  <groupId>info.magnolia.synchronization</groupId>
  <artifactId>magnolia-synchronization-rest</artifactId>
</dependency>

Synchronization REST API

This page describes the synchronization endpoint, which can be used to launch synchronization and check on their status. 

GET

Get status

Returns the status of a specified synchronization request.

Request URL

/.rest/synchronization/v1/status/{synchId}

Parameters

Parameter

Description

Parameter type

Data type

synchId

required

Specify the synchronization request ID. 

Note: the synchronization request ID is returned by synchronize or synchronizeWith.

path

String

Returns the status of a synchronization request with: 

  • jobId - the ID of the synchronization request (same as synchId)
  • status - the synchronization request status, one of: 
    • WAITING - waiting for execution
    • RUNNING - currently executing
    • DONE - completed successfully without errors
    • FAILED - completed unsuccessfully due to an error
    • CANCELLED - synchronization was cancelled before execution
    • ERROR - synchronization was completed but was unable to determine results

Clear jobs

Clears the status of all synchronization jobs.

Important

This call will not stop running synchronization jobs or synchronization jobs awaiting execution. 

Request URL

/.rest/synchronization/v1/reset

Returns an HTTP status of: 

  • 204 - the reset was successful

POST

Trigger synchronization

Launch a synchronization of designated workspace on a Magnolia instance.

Request URL

/.rest/synchronization/v1/trigger

Parameters

Parameter

Description

Parameter type

Data type

url

required

The URL of the Magnolia instance.

queryString
workspace

required

The workspace to be synchronized.

queryString
recursive

optional, default is false

Indicates if subnodes of path should also be synchronized. 

queryboolean
fromDate

optional

Specifies a Unix epoch timestamp in milliseconds.

Nodes modified since fromDate will be synchronized, nodes older than fromDate will be skipped.

If null, all node specified by path and recursive will be synchronized.

querylong
fromPath

required

Workspace path on the author instance from which content is published.

queryString
toPath

optional

Workspace path on the public instance to which the content is published.

Nodes at or below fromPath will be synchronized on the target Magnolia instance at toPath.

queryString

Returns an HTTP status of: 

  • 200 - the synchronization request was launched and awaiting execution
  • 409 - another synchronization request is running and the request cannot be launched at this time
  • 500 - an error occurred and the synchronization request was not launched

If the request was launched, the status of a synchronization request is returned with: 

  • jobId - the ID of the synchronization request (same as synchId)
  • status - the synchronization request status, one of: 
    • WAITING - waiting for execution
    • RUNNING - currently executing
    • DONE - completed successfully without errors
    • FAILED - completed unsuccessfully due to an error
    • CANCELLED - synchronization was cancelled before execution
    • ERROR - synchronization was completed but was unable to determine results

Example

Here is an example call for triggering a synchronization

curl -u superuser:superuser http://localhost:8080/magnoliaAuthor/.rest/synchronization/v1/trigger --data '
{"url" : "http://localhost:8080/magnoliaPublic", "workspace": "website", "fromPath" : "/", "fromDate" : "2012-03-29T10:05:45-06:00"}
' --header "Content-Type: application/json"

Known Issues

Due to the fact that update/install tasks are not run from beta to final versions there will be some manual steps if you were using one of the beta releases.

Import manager config

Remove command config

  • RestSynchronizationCommand removed from final module. This is harmless but the command node configuration will have to be removed manually from the JCR configuration. (i.e. /modules/synchronization-rest/commands)

    2020-06-25 15:10:19,851 WARN magnolia.transformer.ClassPropertyBasedTypeResolver: Encountered the 'class' property but failed to resolved the type from its value: [info.magnolia.synchronization.commands.RestSynchronizationCommand]

Remove sender config

  • In case 1.9-beta3 was installed, the synchronization sender node will have to be removed manually from JCR configuration. (i.e. /modules/synchronization-core/commands/synchronization/synchronize/synchronizationSenderClass).

  • No labels