Expand my Community achievements bar.

SOLVED

Repoinit configuration for Property set on AEM as cloud service

Avatar

Level 4

Hello,

I am trying to add property sling:configRef to a root page property through RepoInit Script in OSGI config. We are using AEM as cloud service and below is RepoInit script

 

RepoInit Script:

**********************************************************************

set properties on /content/myproject/us/jcr:content
    set sling:configRef{String} to /conf/myprojectconfi
end

**********************************************************************

 

But with this above code, getting below error:

28.01.2022 11:22:44.141 *INFO* [Apache Sling Repository Startup Thread #1] org.apache.sling.jcr.repoinit.impl.NodePropertiesVisitor Setting properties on nodePath '/content/myproject/us/jcr:content'
28.01.2022 11:22:44.141 *ERROR* [Apache Sling Repository Startup Thread #1] com.adobe.granite.repository.impl.SlingRepositoryManager Exception in a SlingRepositoryInitializer, SlingRepository service registration aborted
java.lang.RuntimeException: Unable to set properties on path [/content/myproject/us/jcr:content]:javax.jcr.PathNotFoundException: Node with path /content/myproject/us/jcr:content does not exist.
at org.apache.sling.jcr.repoinit.impl.DoNothingVisitor.report(DoNothingVisitor.java:63) [org.apache.sling.jcr.repoinit:1.1.36]
at org.apache.sling.jcr.repoinit.impl.NodePropertiesVisitor.visitSetProperties(NodePropertiesVisitor.java:217) [org.apache.sling.jcr.repoinit:1.1.36]
at org.apache.sling.repoinit.parser.operations.SetProperties.accept(SetProperties.java:44) [org.apache.sling.repoinit.parser:1.6.10]
at org.apache.sling.jcr.repoinit.impl.JcrRepoInitOpsProcessorImpl.apply(JcrRepoInitOpsProcessorImpl.java:56) [org.apache.sling.jcr.repoinit:1.1.36]
at org.apache.sling.jcr.repoinit.impl.RepositoryInitializerFactory.lambda$applyOperations$0(RepositoryInitializerFactory.java:151) [org.apache.sling.jcr.repoinit:1.1.36]
at org.apache.sling.jcr.repoinit.impl.RetryableOperation.apply(RetryableOperation.java:57) [org.apache.sling.jcr.repoinit:1.1.36]
at org.apache.sling.jcr.repoinit.impl.RepositoryInitializerFactory.applyOperations(RepositoryInitializerFactory.java:149) [org.apache.sling.jcr.repoinit:1.1.36]
at org.apache.sling.jcr.repoinit.impl.RepositoryInitializerFactory.processRepository(RepositoryInitializerFactory.java:129) [org.apache.sling.jcr.repoinit:1.1.36]
at org.apache.sling.jcr.base.AbstractSlingRepositoryManager.executeRepositoryInitializers(AbstractSlingRepositoryManager.java:627) [org.apache.sling.jcr.base:3.1.10]
at org.apache.sling.jcr.base.AbstractSlingRepositoryManager.initializeAndRegisterRepositoryService(AbstractSlingRepositoryManager.java:575) [org.apache.sling.jcr.base:3.1.10]
at org.apache.sling.jcr.base.AbstractSlingRepositoryManager.access$300(AbstractSlingRepositoryManager.java:96) [org.apache.sling.jcr.base:3.1.10]
at org.apache.sling.jcr.base.AbstractSlingRepositoryManager$4.run(AbstractSlingRepositoryManager.java:544) [org.apache.sling.jcr.base:3.1.10]
Caused by: javax.jcr.PathNotFoundException: Node with path /content/myproject/us/jcr:content does not exist.
at org.apache.jackrabbit.oak.jcr.session.SessionImpl.getNode(SessionImpl.java:341) [org.apache.jackrabbit.oak-jcr:1.40.0.T20220110121513-be5e04f]
at com.adobe.granite.repository.impl.CRX3SessionImpl.getNode(CRX3SessionImpl.java:185) [com.adobe.granite.repository:1.8.8]
at org.apache.sling.jcr.repoinit.impl.NodePropertiesVisitor.setNodeProperties(NodePropertiesVisitor.java:185) [org.apache.sling.jcr.repoinit:1.1.36]
at org.apache.sling.jcr.repoinit.impl.NodePropertiesVisitor.visitSetProperties(NodePropertiesVisitor.java:214) [org.apache.sling.jcr.repoinit:1.1.36]
... 10 common frames omitted

 

 

and there is way to create /content/myproject/jcr:content using script:

create path /content/myproject/jcr:content

 

Will this create jcr:content node on every deployment on AEM as CS environment ? 

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@pradeepmoolemane - Please follow the below steps to create a repoinit script in AEMaaCS:

  1. Create a script within ui.config module of the maven project
    e.g. /ui.config/src/main/content/jcr_root/apps/<myproject>/osgiconfig/config/org.apache.sling.jcr.repoinit.RepositoryInitializer~<myproject>.cfg.json
  2. Within this script add below to create paths and set properties:
    {
        "scripts": [
            "create path (cq:Page) /content/<myproject>",
            "create path (cq:PageContent) /content/<myproject>/jcr:content",
            "create path (cq:Page) /content/<myproject>/us",
            "create path (cq:PageContent) /content/<myproject>/us/jcr:content",
            "set properties on /content/<myproject>/us/jcr:content\n  set sling:configRef{String} to /conf/myprojectconfig\nend",
        ]
    }
  3. The script will create the paths only if they are not existing which means that for re-deployment they won't be recreated again and again.

This script can further be optimized and more details can be found here: https://sling.apache.org/documentation/bundles/repository-initialization.html

 

Jineet

View solution in original post

2 Replies

Avatar

Level 1

Have you created as json.cfg file? Also, json.cfg does not support multi line script so please try to move it to single line and check.

Avatar

Correct answer by
Community Advisor

@pradeepmoolemane - Please follow the below steps to create a repoinit script in AEMaaCS:

  1. Create a script within ui.config module of the maven project
    e.g. /ui.config/src/main/content/jcr_root/apps/<myproject>/osgiconfig/config/org.apache.sling.jcr.repoinit.RepositoryInitializer~<myproject>.cfg.json
  2. Within this script add below to create paths and set properties:
    {
        "scripts": [
            "create path (cq:Page) /content/<myproject>",
            "create path (cq:PageContent) /content/<myproject>/jcr:content",
            "create path (cq:Page) /content/<myproject>/us",
            "create path (cq:PageContent) /content/<myproject>/us/jcr:content",
            "set properties on /content/<myproject>/us/jcr:content\n  set sling:configRef{String} to /conf/myprojectconfig\nend",
        ]
    }
  3. The script will create the paths only if they are not existing which means that for re-deployment they won't be recreated again and again.

This script can further be optimized and more details can be found here: https://sling.apache.org/documentation/bundles/repository-initialization.html

 

Jineet