What happens in case some repository paths are missing also a property value already have some value | Community
Skip to main content
Level 6
September 11, 2023
Solved

What happens in case some repository paths are missing also a property value already have some value

  • September 11, 2023
  • 4 replies
  • 2452 views

Hi,

we are having Repository Initializer from Sling to perform some initial setup of eg paths and permissions: 

This is how I have 


{
"scripts": [
"create path (sling:Folder) /content/dam/brands/ceccatocluster",
"create path (nt:unstructured) /content/dam/brands/ceccatocluster/jcr:content",
"create path (cq:Page) /content/brands/ceccatocluster",
"create path (nt:unstructured) /content/brands/ceccatocluster/jcr:content",
"create group CeccatoCluster-template with path /home/groups/brandsv2",
"set ACL for CeccatoCluster-template \r\n allow jcr:all on /conf/brandsv2/ceccatocluster \r\nend",
"add CeccatoCluster-template to group template-authors",
"create group CeccatoCluster-content with path /home/groups/brandsv2",
"set ACL for CeccatoCluster-content \r\n allow jcr:all on /content/brands/ceccatocluster \r\nend",
"set ACL for CeccatoCluster-content \r\n allow jcr:all on /content/dam/brands/ceccatocluster \r\nend",
"add CeccatoCluster-content to group contributor",
"add CeccatoCluster-content to group workflow-users",
"set properties on /content/brands/ceccatocluster/jcr:content \r\n set cq:allowedTemplates{String[]} to \"/conf/brandsv2/ceccatocluster/settings/wcm/templates/(?!xf-).*\" \r\n set cq:conf{String} to /conf/brandsv2/ceccatocluster \r\n set cq:deviceGroups{String[]} to /etc/mobile/groups/archetype \r\n set cq:redirectTarget{String} to /content/brands/ceccatocluster/en \r\n set cq:template{String} to /conf/brandsv2/ceccatocluster/settings/wcm/templates/content-page \r\n set jcr:title{String} to \"Ceccato Cluster\" \r\n set scene7Enabled{Boolean} to true \r\n set sling:configRef{String} to /conf/brandsv2/ceccatocluster \r\n set sling:redirect{Boolean} to true \r\n set sling:redirectStatus{Long} to 302 \r\n set sling:resourceType{String} to brandsv2/components/structure/page \r\nend"
]
}

 

what happens if in case some repository paths are missing, in case some of the properties already have some value (single value / multi value), etc.
is there anyway to check if the property has this value set this, if the path is missing what to do in order to not effect repositoy initializer.


Please share some inputs how we can improve the config files.

 

Thanks,

Vani.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by EstebanBustamante

Hi @vani1012 , 

 

The repo-init runs before the SlingRepository service is registered, which briefly means that it will run before your code runs and usually, it is used as an "initial" setup for your code to work properly. 

According to the official documentation, these are the preferred scenarios for the usage of repo-init:

  • Create/delete/disable service users

  • Create/delete groups

  • Create/delete users

  • Add ACLs

There is a a big NOTE also, You must create the path statements you will be using in your repoinit configurations, because they won't be available at the time the config runs.

 

You could also test what happen with your repoinit configurations by adding a custom logger and check how these will affect your repository. Add an INFO logger for the packages:

  • org.apache.sling.repoinit 
  • org.apache.sling.jcr.repoinit
  •  

Here are good resources to deep dive into the understanding of how and when to use the repo init:

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/deploying/overview.html?lang=en#repoinit 

https://www.bounteous.com/insights/2021/11/16/adobe-experience-managers-sling-repoinit-when-should-you-use-it 

https://www.bounteous.com/insights/2021/11/16/adobe-experience-managers-sling-repoinit-have-you-tried-it-yet 

4 replies

EstebanBustamante
Community Advisor and Adobe Champion
EstebanBustamanteCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
September 11, 2023

Hi @vani1012 , 

 

The repo-init runs before the SlingRepository service is registered, which briefly means that it will run before your code runs and usually, it is used as an "initial" setup for your code to work properly. 

According to the official documentation, these are the preferred scenarios for the usage of repo-init:

  • Create/delete/disable service users

  • Create/delete groups

  • Create/delete users

  • Add ACLs

There is a a big NOTE also, You must create the path statements you will be using in your repoinit configurations, because they won't be available at the time the config runs.

 

You could also test what happen with your repoinit configurations by adding a custom logger and check how these will affect your repository. Add an INFO logger for the packages:

  • org.apache.sling.repoinit 
  • org.apache.sling.jcr.repoinit
  •  

Here are good resources to deep dive into the understanding of how and when to use the repo init:

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/deploying/overview.html?lang=en#repoinit 

https://www.bounteous.com/insights/2021/11/16/adobe-experience-managers-sling-repoinit-when-should-you-use-it 

https://www.bounteous.com/insights/2021/11/16/adobe-experience-managers-sling-repoinit-have-you-tried-it-yet 

Esteban Bustamante
aanchal-sikka
Community Advisor
Community Advisor
September 11, 2023

Hello @vani1012 

 

The entire concept of repo-init fits the concept of mutable and immutable area.

This is generally used in context of AEM as a Cloud Service (AaaCS).

 

For ACLs defined for nodes underneath /apps or /libs the repoinit, execution starts on a blank repository. The packages are installed after repoinit so statements cannot rely on anything defined in the packages but must define the preconditions like the parent structures underneath.

 

In AaaCS, since the repoinit works on a blank repository, you don't have conflicts around arrays. However, the situation changes in case of AEM 6.5.

- All paths, code and content already exists.

So, when repo-init runs on start up we see issues related to arrays.

 

This would have been resolved if we were able to enforce arrays. Currently, it is only working for multiple values. Example following is documented on https://sling.apache.org/documentation/bundles/repository-initialization.html

set properties on /forcedMultiValue set singleMultiValue{String[]} to "single" set emptyMultiValue{String[]} to set singleLongMultiValue{Long[]} to 1243 set emptyLongMultiValue{Long[]} to end

 

Requesting you to please raise 2 support tickets for following:

  • Unable to enforce array for single values via repo-init
  • To explain how failures in repo-init are affecting your startup. This is more like an FYI to the team.

 

For more debugging, @estebanbustamante  has shared more info with us

Aanchal Sikka
Vani1012Author
Level 6
September 11, 2023

should I raise daycare for support ticket,
also what about that acl permission issue if path doesnt exist, how to make this not to throw exception

aanchal-sikka
Community Advisor
Community Advisor
September 11, 2023

@vani1012 

 

Please raise a support ticket to report about multi-field.

 

For ACLs, it is an expected behaviour:

- We cannot add ACL (rep:policy node) without having the parent, which is a resource

- Also we need to assure that we are using the correct jcr:primaryType while creating structures. I guess these cannot be changed later (unless we replace via a deployment).

Aanchal Sikka
kautuk_sahni
Community Manager
Community Manager
September 12, 2023

@vani1012 Do you find the suggestions from users useful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. 

Kautuk Sahni
arunpatidar
Community Advisor
Community Advisor
September 12, 2023

you have an issue with the jcr:content node types

please correct the types of all the nodes otherwise there will be violation of the node definition rule..

Arun Patidar