Extending the Readiness Check

There are several ways to extend the readiness check. The option described in this topic lets you extend the readiness check with an AddOn extension.

Prerequisites

  • You ran ant extgen to generate an AddOn using the yaddon template with the following criteria:
    • extension name is readinesscheckaddon
    • package name is com.example.readinesscheck
    • AddOn is installed in yacceleratorstorefront, which runs electronicsstore
  • If you plan to test in a local environment, you set up the mock extension. For more information, see Preparing a Mock Extension to Deploy Locally.

Context

You can also leverage the out-of-the-box Spring event listener used by the node warmer to trigger your own readiness check, instead of using your own event listener. If you want to do this, declare a bean to implement the de.hybris.platform.modelt.readinesscheck.PerformableReadinessCheck interface.

Procedure

  1. Update the extensioninfo.xml for the AddOn so that it requires the modelt extension:

    extensioninfo.xml

    <requires-extension name="modelt"/>
  2. Navigate to the acceleratoraddon/web/src/com/example/ directory and place these classes under the com.example.readinesscheck package.

    MyReadinessCheck.java

    package com.example.readinesscheck;
    
    import de.hybris.platform.modelt.readinesscheck.PerformableReadinessCheck;
    import de.hybris.platform.modelt.readinesscheck.ReadinessCheckResult;
    
    public class MyReadinessCheck implements PerformableReadinessCheck
    {
        private ReadinessCheckResult result = ReadinessCheckResult.notReady();
    
        @Override
        public boolean isEnabled() {
            return true;
        }
    
        public void perform() {
            // Add your own logic there, and once it finishes successfully, set the result to "ready"
            result = ReadinessCheckResult.ready();
            // Also don't forget about error handling and decide what result to set in case of error
        }
    
        @Override
        public ReadinessCheckResult getResult()
        {
            return result;
        }
    }
  3. Update resources/readinesscheckaddon/web/spring/readinesscheckaddon-web-spring.xml to register myReadinessCheck into the list of readiness checks.

    Refer to the following sample code:

    <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:aop="http://www.springframework.org/schema/aop"
          xmlns:context="http://www.springframework.org/schema/context"
          xmlns:task="http://www.springframework.org/schema/task"
          xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans.xsd
               http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context.xsd">
        ...
        <bean id="myReadinessCheck" class="com.example.readinesscheck.MyReadinessCheck"/>
    
        <bean id="myReadinessCheckListMergeDirective" depends-on="readinessChecks" parent="listMergeDirective" >
           <property name="add" ref="myReadinessCheck" />
        </bean>
    </beans>
  4. Configure your Commerce Cloud manifest file to add the readinesscheckaddon to the list of extensions and install it into yacceleratorstorefront.

    See the following sample code in the following file:

    manifest.json:

    {
        "commerceSuiteVersion": "2205",
        "extensions": [
            ....
            "readinesscheckaddon",
            ....
        ],
        "storefrontAddons": [{
            "addon": "readinesscheckaddon",
            "storefront": "yacceleratorstorefront",
            "template": "yacceleratorstorefront"
        }],
        "properties": [....],
        "aspects": [...],
        "tests": {
            "extensions": [...],
            "annotations": [...],
            "packages": [...]
        }
    }
  5. Create a build and deploy it to Commerce Cloud and test it to ensure that there are no errors.