Publish

Described here are the various aspects of publication that have not been covered before. There is some basic structural content, process information, and event information that comes at the end of publishing.

Target Metadata and Design Constraints

Data publication is a final opportunity to massage, process, or filter the data before it is loaded into the target system. Before publishing data to a target system, a business user has to describe how data looks in that system. To define the target system data, use the target system metadata in the extension XML document. The target metadata is presented by the following item types in Data Hub:
  • TargetSystem - defines the target systems where data can be published. This entity is mainly used to distinguish one publication destination from the other.
  • TargetItemMetadata - defines an item type in the target system. It specifies the item type name and links to a set of attributes that are specific to that item type in the target system.
  • TargetAttributeDefinition - defines a single attribute in an item type. It specifies the name, data type, validation rules, and how the canonical value is transformed for the attribute values in the target system item type.

Using this information, Data Hub determines the data to be published to the target system from the canonical format. It also determines which transformations/validations are applied to the data.

The localized attributes are assumed to be entirely localized. If an attribute is defined as localized in a canonical item type, it is localized in all target item types to which it maps. Any attribute that is not localized in a canonical type cannot be mapped to a localized attribute in any of the target types.

The set groups items together based on how they were imported into the Data Hub. Data Hub does not publish more than or less than a single set of data. However, Data Hub can publish from a single data pool to multiple targets.

Adapter Services

All target system adapters must implement the com.hybris.datahub.adapter.AdapterService interface. Any declared beans of this type are automatically added to a registry and made available to the PublicationService. Any new target system adapter can be added to the Spring context registry similar to the way the core platform adapter (/datahub/datahub-export-service/datahub-core-adapter-service/src/main/resources/META-INF/core-adapter-service-spring.xml) appears:

...
<alias name="defaultCoreAdapterService" alias="coreAdapterService" />
<bean name="defaultCoreAdapterService" class="com.hybris.datahub.core.adapter.impl.CoreAdapterService">
    <property name="targetSystemType" value="HybrisCore" />
    <property name="impexService" ref="impexService" />
    <property name="mediaStorage" ref="impexMediaStorage" />
    <property name="exportClient" ref="exportClient" />
</bean>
...

Publishing to SAP Commerce Cloud

The AdapterService implementation for SAP Commerce Cloud installation is located in the core-adapter-service module. This adapter service uses the ImpEx format to publish the data. For each TargetItem, Data Hub creates an ImpEx header for all non localized attributes, and then additional blocks for every subsequent localization of that item. Target item attributes with no value set (for example, the value is null) result in the "<ignore>" string being written to the ImpEx body. The "<ignore>" string specifies that the corresponding attribute cannot be changed. Values set with the empty string value, by default "<empty>", result in no value being written into the ImpEx body. As a result, the value for that attribute clears when the ImpEx is imported. For example, <transformationExpression /> becomes null and is interpreted as <ignore> in the ImpEx. Whereas <transformationExpression>""</transformationExpression> becomes an empty string and is an empty string in ImpEx.

ImpEx-related Metadata

Each TargetSystem has a set of strings contained in exportCodes. These publication codes appear at the top of the ImpEx file and are most commonly used to define $ macros. At the TargetItem level the exportCode field is used to designate within the ImpEx header the target item type being updated or created. Additionally, each TargetAttributeDefinition has a exportCode field. This field is used as the ImpEx header for that particular attribute and can use macros defined for the TargetSystem. TargetAttributeDefinitions may exist for fields that do not exist in the TargetItem itself. Their exportCode header strings are used in the ImpEx header (and may contain default values), but no values populate for each TargetItem.

In addition to supporting static content, the exportCode field at the TargetItem and TargetAttributeDefinition level also supports SpEL expressions. SpEL support allows it to accommodate dynamic content written to the headers within the ImpEx file created by the Core Adapter Service. Any valid SpEL expression, including any custom SpEL functions, can be used to evaluate against the canonical item that each exported target item was created from. You can configure a SpEL expression by setting the exportCode either at the TargetItem or TargetAttributeDefinition level. The resulting ImpEx file contains a header and corresponding body for each target item that is exported.

Target System Publication Events

Perform a target system publication using Data Hub to SAP Commerce Cloud. Include the Data Hub Adapter as an extension. A custom event, com.hybris.datahub.core.event.DatahubAdapterImportEvent, is fired. The event contains information related to the publication and is fired by the Data Hub Adapter through the SAP Event System. The information includes the name of the data pool containing the canonical items published as well as the status of the target system publication. The status information is reported as one of three possible states. There is SUCCESS, which indicates there were no errors encountered during the publication. There is PARTIAL_SUCCESS, which indicates there were errors during the publication, but it was able to complete. There is FAILURE, which indicates there was a fatal error preventing the publication from completing. To receive events that are sent by the Data Hub Adapter, you can create a listener to accept DatahubAdapterImportEvent events in the SAP Event System.

Publication Auto-Recovery

Standard Mode Publishing

For a pool, there are two states when Data Hub considers publication to be inactive. When there is no IN_PROGRESS publication, and if there is only one publication action, and it has a PENDING status.

When Data Hub runs the check for inactive publication, it considers how long the PENDING publication action has been waiting. If the action is within the configurable window, Data Hub doesn't consider it inactive. However, if the publication action has been there longer than the window, Data Hub considers publication is inactive, and issues a reset to start publication again.

OR

There is a previously completed publication action (SUCCESS, FAILURE, COMPLETE_W_ERRORS), and a PENDING publication action exists.

When Data Hub runs the check for an inactive publication, it considers how long the PENDING publication action has been waiting. If the PENDING action is outside the configurable window, Data Hub considers the publication inactive and issues a reset. If the PENDING action is within the configurable window, Data Hub then checks how long its been since the previous action completed. If the previous action completed within the configurable window, Data Hub doesn't consider Publication to be inactive. If the completed action is outside the window, Data Hub considers the publication is inactive and issues a reset.

For the two conditions above, Data Hub looks at the modified time of the publication actions in the database to identify inactive publications.

Configuration

Both Publication and Composition check their action queue for inactivity. Changing the values for the following properties affects both the composition and publication auto recovery logic.
  • datahub.pool.actions.inactive.reset.schedule - a cron expression that specifies when Data Hub should check for inactive publications. By default it is set to 0 */5 * * * ?, which runs every 5 minutes at the top of the minute. (For a description of cron expressions, see Scheduling the Frequency of the Cleanup Activity.)
  • datahub.pool.actions.inactive.window.millis - a window in milliseconds that indicates whether publication is stuck for a certain pool. The default is 300000 ms (5 minutes). This value is used to subtract from the current time to get a lower bound time. The lower bound time then is used to query the database for publication actions prior to it.