Run Modes with Use Cases in AEM 6.2

Avatar

Avatar
Validate 1
Level 2
saurabhg4318802
Level 2

Likes

11 likes

Total Posts

14 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 2
saurabhg4318802
Level 2

Likes

11 likes

Total Posts

14 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
saurabhg4318802
Level 2

22-03-2017

Hi,

 

Run Modes is the most interesting feature in AEM. This allows you to tune your AEM instance for a specific purpose; for e.g., author/publish, QA, development, intranet or others.

 

Why Run Modes?

  • Uniquely identify an environment and instances

  • Unique configurations based on environment

  • OSGI Component Creation for a specific environment

  • Bundle Creation for a specific environment

 

There are two types of run modes:

  • Primary Run Mode

  • Secondary Run  Mode

 

Primary Run Modes are:

  • Author: This instance is used for the complete development and authoring purpose.

  • Publish: This is the actual environment which can be accessed by end users.

  • nosamplecontent: This instance is having no sample content(like geometrixx,we-retail  not available).It is highly recommended in production environment because it is very secure and it provides no sample configurations.lt makes your instance production ready, by disabling CRXDE lite, webdav etc

  • samplecontent: having sample content like geometrixx-all package.This is just for the help of developers,not required on any server.

 

Note: Primary Run Modes can’t be change once the aem jar is started.So at the time of AEM instance startup only, we need to finalize which primary run mode is required.

 

Combination of primary run modes also happen:

  • Author+samplecontent

  • Author+nosamplecontent

  • Publish+samplecontent

  • Publish+nosamplecontent

 

Secondary Run Modes are:

  • Dev Server

  • QA Server

  • UAT Server

  • Prod Server

We can create our own customized run modes on the basis of location( i.e., us,uk), language or any other basis.

 

Where we define Run mode?

  • By Changing  in sling:properties file

Steps to follow:

  1. Go to crx-quickstart/conf directory of aem instance and add the below line:

            sling.run.modes= author,dev

 

       

sking-properties.PNG

Fig- Set the run mode in sling.properties file

  • Using the -r option: When you start the AEM instance by command prompt then set “-r” option in the command.

Example:  java -jar jar-name -r dev,sameplecontent

  • By Renaming Jar: cq5-<run-mode>-p<port-number>

Example: publish instance :  cq5-publish -p4503.jar

               Author instance :  cq5-author-p4502.jar

 

Note: Only primary run modes  (ex: author,publish) are applicable for renaming jar.

 

  • By adding JVM arguments:  When you start the AEM instance by command prompt then set the jvm parameter in the command. This will be something like this:

Java -jar JAR_NAME -Dsling.run.modes=publish,prod,us  

 

How to check the run mode of a running AEM instances?

  • Go to Status tab in Navigation and click on sling settings option.

  • Here you can see the Run Modes

 

       

sling-settings.PNG

Fig - Check the run mode of running AEM instance

 

 

USE CASE OF RUN MODE IN THE PROJECT

 

Problem Statement:

In Felix Configurations, there is a configuration named as DAY CQ MAIL SERVICE. Now lets say we have a requirement of using smtp.port=25 in author, Dev,US server but smtp.port=465 in Author,QA,UK  Server. (Here US and UK are the location of servers)

 

Solution:

Create Run Modes:

  • Go to Crxde.

  • Go to /apps/my-project

Create Configurations for Author,Dev Server which is in US:

  • Create a folder (sling:folder) with the name config.author.dev.us

  • Create a sling:osgiConfig type of node named com.day.cq.mailer.DefaultMailService.config.

Note:Node name should be the same name as the Persistent Identity (PID) of the                configuration in the OSGi Console.

  • Add the following properties in this config for Dev Server:

 

       

crx-dev-confg.PNG

Fig - Adding the mail service configuration for DEV,US run mode

 

 

  • Run an AEM instance on Author,Dev,US Environment by using any of the option explained above.

  • Check the run mode of running AEM instance

       

Dev Config-sling-settings.PNG

Fig- AEM instance is in AUTHOR,DEV,US run mode

 

  • Now Check the mail Configurations

       

dev-config-mail.PNG

    

Fig- Check the configuration in felix console for DEV,US run mode aem instance

Create Configurations for Author,QA Server which is in UK:

 

  • Create a folder (sling:folder) with the name config.author.qa

  • Create a sling:osgiConfig type of node named com.day.cq.mailer.DefaultMailService.config

  • Add the following properties in this config  for QA Server:

 

       

qa-crx-config.PNG

Fig - Adding the mail service configuration for QA,UK run mode

 

  • Run an AEM instance on Author, QA,UK Environment by using any of the option explained above.

  • Check the run mode of running AEM instance

 

       

qa-config-sling.PNG

Fig- AEM instance is in AUTHOR,QA,UK run mode

 

 
  • Now Check the mail Configurations in Felix Console

       

qa-config-mail.PNG

Fig- Check the configuration in felix console for QA,UK run mode aem instance

 

The minimum possible configurations for AEM environments.

       

configs.PNG

Fig- Minimal possible configuration in any AEM project

Note: Every run mode tries to find out the best possible match available for configuration.

If multiple configurations for the same PID are applicable, the configuration with the highest number of matching run modes is applied.

 

OSGi Component Creation for a specific environment

Run Modes helps to create OSGi component for the specific environment.

Problem Statement: To make OSGi Component to be available only for publish instance.

Solution: To solve this problem, follow these two steps:

  • Annotate the component with “ConfigurationPolicy.REQUIRE

  • Make this configuration available under config.publish.

 

Sample code of OSGi Component

package com.aem.sgaem.project.services; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.ConfigurationPolicy; import org.apache.felix.scr.annotations.Service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Component(label = "SGAEM - OSGi Configuration for Publish Run Mode", immediate = true, policy = ConfigurationPolicy.REQUIRE) @Service(ComponentPublish.class) public class ComponentPublish { private static final Logger LOGGER = LoggerFactory.getLogger(ComponentPublish.class); @Activate protected void activate() { LOGGER.debug("Run Modes Activated"); } }

�� Here “policy= ConfigurationPolicy.REQUIRE”  means that this component should be available as configuration created under config nodes. But Initially, this configuration will not exist  in felix console components

So, to make it visible in Felix console of publish instance, You need to create configuration of this component (using Pid of OSGi Component) under config.publish node.

 

       

component-config.jpg

Fig- Node name same as Pid of OSGi Component

 

After addition of this configuration, you can see, the component will be available in Felix console in publish instance.

Note: In other run modes, this component will not get executed because it is specified only for publish instance. If you want to use it in other run modes, you need to make it in other config as well. (eg: config.author,config.qa)

 

Bundle Creation for a specific environment

Run Modes is not only used for configurations, they can also be used to differentiate bundles based on the environments.

Isn’t it sounds interesting??

Problem Statement: Let Suppose, You have multiple bundles in a single project. like

Bundle A” for  “Author” Environment.

Bundle Bfor  “Publish” Environment

Solution: So we need to make environment specific configuration for install folder.

Install.author  (nt:folder)

                => Bundle A.jar

Install.publish (nt:folder)

                => Bundle B.jar

       

crx.PNG

Fig- sgaem-test.jar for author and sgaem-bundle.jar for publish instance

 

Note: If you are in publish instance, You will not able to see bundle "sgaem-test" in felix console and vice-Versa for author instance.

Replies

Avatar

Avatar
Boost 5
Level 6
JK_Kendall
Level 6

Likes

36 likes

Total Posts

379 posts

Correct reply

105 solutions
Top badges earned
Boost 5
Boost 3
Boost 25
Boost 10
Boost 1
View profile

Avatar
Boost 5
Level 6
JK_Kendall
Level 6

Likes

36 likes

Total Posts

379 posts

Correct reply

105 solutions
Top badges earned
Boost 5
Boost 3
Boost 25
Boost 10
Boost 1
View profile
JK_Kendall
Level 6

22-03-2017

Hi,

This is good information for the AEM platform, so I'm moving the post to the platform topic.

This topic is specific to the Communities capability.

- JK

Avatar

Avatar
Validate 1
Level 2
saurabhg4318802
Level 2

Likes

11 likes

Total Posts

14 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 2
saurabhg4318802
Level 2

Likes

11 likes

Total Posts

14 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
saurabhg4318802
Level 2

05-04-2017

Thanks JK Kendall

Avatar

Avatar
Validate 10
Level 4
Var
Level 4

Likes

44 likes

Total Posts

113 posts

Correct reply

5 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 25
View profile

Avatar
Validate 10
Level 4
Var
Level 4

Likes

44 likes

Total Posts

113 posts

Correct reply

5 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 25
View profile
Var
Level 4

06-04-2017

Good one Saurabh to put all together related to Run modes at one shot. smiley

Avatar

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,198 likes

Total Posts

6,383 posts

Correct reply

1,147 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,198 likes

Total Posts

6,383 posts

Correct reply

1,147 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile
kautuk_sahni
Community Manager

06-04-2017

Thanks a lot for sharing the information with the community.

Looking foreword to many more such content here.

~kautuk 

Avatar

Avatar
Springboard
Level 3
Sh1ju
Level 3

Likes

13 likes

Total Posts

56 posts

Correct reply

4 solutions
Top badges earned
Springboard
Validate 1
Establish
Ignite 1
Give Back 5
View profile

Avatar
Springboard
Level 3
Sh1ju
Level 3

Likes

13 likes

Total Posts

56 posts

Correct reply

4 solutions
Top badges earned
Springboard
Validate 1
Establish
Ignite 1
Give Back 5
View profile
Sh1ju
Level 3

07-04-2017

Thanks for sharing the information

Avatar

Avatar
Boost 1
Level 1
phoolc94036637
Level 1

Like

1 like

Total Posts

4 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
phoolc94036637
Level 1

Like

1 like

Total Posts

4 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
phoolc94036637
Level 1

07-04-2017

Thanks.

Avatar

Avatar
Validate 10
Level 3
gargsahil099
Level 3

Likes

13 likes

Total Posts

57 posts

Correct reply

4 solutions
Top badges earned
Validate 10
Validate 1
Ignite 3
Ignite 1
Give Back 5
View profile

Avatar
Validate 10
Level 3
gargsahil099
Level 3

Likes

13 likes

Total Posts

57 posts

Correct reply

4 solutions
Top badges earned
Validate 10
Validate 1
Ignite 3
Ignite 1
Give Back 5
View profile
gargsahil099
Level 3

05-09-2017

hi Saurabh,

Thanks for this knowledgeable article can you please add how to read the properties from sling:osgiConfig nodes. I have tried it using the help of ConfigurationAdmin is this only way to read the properties or do we have some other way as well.

Thanks

Sahil Garg

Avatar

Avatar
Boost 1
Level 1
anand-andy
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
anand-andy
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
anand-andy
Level 1

04-01-2018

Nice one but it would be wise to see how you could address cloud configuration with run mode such like S&P or facebook or google etc.