Tutorial: Manual Retry Publication for Failed Items
Here you have the opportunity to retry a failed publication. This tutorial allows you to observe how you can trigger a publication that includes only failed items, while excluding any new canonical items.
Procedure
- Stop Data Hub.
- Return Data Hub processing to standard mode in your local.properties file.
#Tell DH to use in-memory processing datahub.config.mode=STANDARD
- Configure your target.xml for publication to SAP Commerce Cloud, and place the resultant JAR file into the /opt/datahub/extensions directory.
- Remove the Test Adapter, if installed, to enable publication.
- Go to /opt/datahub/extensions.
- Move the hybris-test-adapter-6.1.0.0-RC3.jar file to /opt/datahub.
- Start Data Hub.
Check the log output during startup to ensure that Data Hub has actually started in standard mode. You should see output similar to the following:
2016-08-01 16:39:56,732 [INFO] [c.h.d.s.c.i.DefaultDataHubExtendedConfigService] STANDARD mode selected.
- Install and start SAP Commerce Cloud.
- Initialize SAP Commerce Cloud to remove any project data from its database, but do not load any ImpEx catalog.
- Prepare two small data sets, approximately 5 items each.
Ensure that these data sets contain distinct items that you can easily tell apart. For example, the first of the following contains all apparel items, while the second contains electronics. You may choose to provide your own data.
Data set 1 (apparel items):
sourceId,isoCode,baseName,baseDescription,ean,manufacturerName,manufacturerAid,unit,style,size,sku,category,styleName,styleDescription 100124,en,Panorama Pants Women,baseDescription_1,NULL,NULL,NULL,Piece,,,,,, 100125,en,Close-up Pants Women,baseDescription_2,NULL,NULL,NULL,Piece,,,,,, 100745,en,Ace Straight Pant Women,baseDescription_3,NULL,NULL,NULL,Piece,,,,,, 100746,en,Anzere Pant Women,baseDescription_4,NULL,NULL,NULL,Piece,,,,,, 100747,en,Camouflage Pant Women,baseDescription_5,NULL,NULL,NULL,Piece,,,,,,
Data set 2 (electronics items):
sourceId,isoCode,baseName,baseDescription,ean,manufacturerName,manufacturerAid,unit,style,size,sku,category,styleName,styleDescription 355516,en,EOS 500D + 18-55mm IS + EF-S 55-250 IS,baseDescription_6,8714570000000,Canon,3820B046AA,Piece,,,,,, 356788,en,"LCD Cleaning Kit KK-CA",baseDescription_7,NULL,Sony,KK-CA,Piece,,,,,, 356970,en,DSC-N1 DEU 8.3Mpix USB2.0,baseDescription_8,NULL,Sony,DSC-M1,Piece,,,,,, 359572,en,EF 100mm f/2.8L Macro IS USM,baseDescription_9,13803108620,Canon,3554B005AA,Piece,,,,,, 360308,en,Photosmart Quick Recharge Kit for HP M-series cameras,baseDescription_10,NULL,HP,L1815B,Piece,,,,,,
Save these two datasets to separate files, with unique names. For example, datafile1 and datafile2.
- If you don't already have it from previous tutorials, create a new file called datafile3 containing the following.
{ "poolName": "GLOBAL", "targetSystemPublications": [ { "targetSystemName": "HybrisCoreInstallation" } ] }This JSON object is the payload of the RESTful call that triggers publication. If using a REST client, such as Postman, you can skip this step and simply include the content in the payload field of your client interface.
- Load the apparel items in datafile1 into Data Hub.
curl -k -u admin:<password> --data-binary @datafile1 -H "Content-Type:application/octet-stream" https://localhost:8443/datahub-webapp/v1/data-feeds/DEFAULT_FEED/items/RawProduct
- Compose the apparel items.
curl -k -u admin:<password> --request POST https://localhost:8443/datahub-webapp/v1/pools/GLOBAL/compositions
- Publish the data.
curl -k -u admin:<password> --data-binary @datafile3 -H "Content-Type:application/json" --request POST https://localhost:8443/datahub-webapp/v1/pools/GLOBAL/publications
This results in a failed publication, due to the lack of an appropriate catalog in the target system. You should see the following in the Data Hub log output.
2016-08-02 14:08:22,560 [DEBUG] [c.h.d.s.i.DefaultPublicationActionService] Publication Result for publication 503 with status COMPLETE_W_ERRORS
This line is followed by another indicating that the DefaultPublicationRetryService has created retries for each of the failed items.
2016-08-02 14:08:25,446 [DEBUG] [c.h.d.s.p.i.DefaultPublicationRetryService] Creating 5 retries for items not published in CompositeTargetSystemPublicationEntity{id=502, status=IN_PROGRESS, publicationType=null, publicationAction=PublicationActionEntity{id=502, pool=DataHubPoolEntity{id=0, name=GLOBAL}}, targetSystem=TargetSystemEntity{id=1, targetSystemName='HybrisCoreInstallation', targetSystemType='HybrisCore'}} - Check the publication state.
curl -k -u admin:<password> --request GET https://localhost:8443/datahub-webapp/v1/target-system-publications
You should see output similar to the following, showing the publication status COMPLETE_W_ERRORS:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <targetSystemPublicationDatas> <targetSystemPublicationData> <publicationId>502</publicationId> <startTime>2016-08-02T14:08:20+02:00</startTime> <endTime>2016-08-02T14:08:25+02:00</endTime> <status>COMPLETE_W_ERRORS</status> <targetSystemName>HybrisCoreInstallation</targetSystemName> <actionId>502</actionId> <poolName>GLOBAL</poolName> <numberOfErrors>5</numberOfErrors> <canonicalItemCount>5</canonicalItemCount> </targetSystemPublicationData> </targetSystemPublicationDatas>
- Check the Canonical Item publication statuses in the database.
You should see your items, as follows:
mysql> select * from CanItemPubStatus; +---------------------+--------------+-------------------------+---------------+----+---------------------+---------+--------------------------------+--------+------------------+ | modifiedtime | statusdetail | targetsystempublication | canonicalitem | id | creationtime | status | typecode | tenant | schemaless_attrs | +---------------------+--------------+-------------------------+---------------+----+---------------------+---------+--------------------------------+--------+------------------+ | 2016-08-02 14:08:24 | INCOMPLETE | 502 | 2796 | 1 | 2016-08-02 14:08:20 | FAILURE | CanonicalItemPublicationStatus | NULL | NULL | | 2016-08-02 14:08:24 | INCOMPLETE | 502 | 2758 | 2 | 2016-08-02 14:08:20 | FAILURE | CanonicalItemPublicationStatus | NULL | NULL | | 2016-08-02 14:08:24 | INCOMPLETE | 502 | 2724 | 3 | 2016-08-02 14:08:20 | FAILURE | CanonicalItemPublicationStatus | NULL | NULL | | 2016-08-02 14:08:24 | INCOMPLETE | 502 | 2955 | 4 | 2016-08-02 14:08:20 | FAILURE | CanonicalItemPublicationStatus | NULL | NULL | | 2016-08-02 14:08:24 | INCOMPLETE | 502 | 2790 | 5 | 2016-08-02 14:08:20 | FAILURE | CanonicalItemPublicationStatus | NULL | NULL | +---------------------+--------------+-------------------------+---------------+----+---------------------+---------+--------------------------------+--------+------------------+ 5 rows in set (0.00 sec)
You may also query the PublicationRetry table. You should see five items there.
- Load and compose the data set containing the electronics items.
curl -k -u admin:<password> --data-binary @datafile2 -H "Content-Type:application/octet-stream" https://localhost:8443/datahub-webapp/v1/data-feeds/DEFAULT_FEED/items/RawProduct
Followed by:
curl -k -u admin:<password> --request POST https://localhost:8443/datahub-webapp/v1/pools/GLOBAL/compositions
At this stage, you should have two sets of canonical items in Data Hub. The first contains the set of items you published, with a canonical item publication status of FAILURE. The second set contains new items with no publication status. In the steps that follow, we demonstrate that only the failed items get picked up for a retry publication.
- Import the following ImpEx into SAP Commerce Cloud using the SAP Commerce Cloud Administration Console. The import is done by selecting
Console
ImpEx Import
.
$productCatalog=apparelProductCatalog $catalogVersion=catalogversion(catalog(id[default=$productCatalog]),version[default='Staged'])[unique=true,default=$productCatalog:Staged] $languages=en,de # Product catalog INSERT_UPDATE Catalog;id[unique=true] ;$productCatalog # Product versions for product catalogs INSERT_UPDATE CatalogVersion;catalog(id)[unique=true];version[unique=true];active;languages(isoCode);readPrincipals(uid) ;$productCatalog;Staged;false;$languages;employeegroup ;$productCatalog;Online;true;$languages;employeegroup
This step creates the catalog, allowing your retry publication to be successful.
- Edit your datafile3, the JSON, to include the highlighted line.
{ "poolName": "GLOBAL", "type":"RETRY_ITEMS_PUBLICATION", "targetSystemPublications": [ { "targetSystemName": "HybrisCoreInstallation" } ] }This line tells Data Hub that the publication is a retry publication, so that only canonical items that previously failed get picked up for publication.
- Initiate a publication.
curl -k -u admin:<password> --data-binary @datafile3 -H "Content-Type:application/json" --request POST https://localhost:8443/datahub-webapp/v1/pools/GLOBAL/publications
You should see the following line in the log output, towards the start of the publication log output. It indicates that the publication event type is a retry publication.
2016-08-02 14:40:06,317 [DEBUG] [c.h.d.s.i.DefaultEventPublicationService] Publishing data hub event : PerformPublicationRetryEvent{actionId=503, systemUrl='https://localhost:8443/datahub-webapp/v1', targetPublicationIds=[505]}The publication then proceeds as normal, with a status of SUCCESS.
- Check the items published to SAP Commerce Cloud using the SAP Commerce Cloud Backoffice.
Here, you see only the previously failed items, and none of the newly composed items.
At this stage, you have successfully demonstrated that a retry publication only picks up those items that have a status of FAILURE from a previous publication. The remaining canonical items are still in the pool, ready for future publication.
- Restore the datafile3 JSON content by removing the RETRY_ITEMS_PUBLICATION type flag, then run publication again.
A standard publication is initiated, picking up the new canonical items with no status, and publishing them to SAP Commerce Cloud. You should now see ten items in the product catalog.