Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Detect instance runmode programmatically in AEM as cloud service

rampai
Level 4
Level 4

Hi All,

 

Is there any alternative to detect run-mode of instance in AEM as cloud service as slingSettingsService shows as deprecated?

 

The use case is to execute code only on author or publish instances but not both.

 

Thanks,

Ram

1 Accepted Solution
Jörg_Hoh
Correct answer by
Employee
Employee

Not sure if this blog article has been specifically been written for you 🙂 But it adresses your question quite good:

 

https://blog.osoco.de/2021/07/the-truth-about-aem-run-modes/

 

 

View solution in original post

3 Replies
asutosh_jena
Community Advisor
Community Advisor

Hi @rampai 

 

The solution is still in planning phase and no API is exposed like SlingSettingService to get the run mode.

https://github.com/Adobe-Consulting-Services/acs-aem-commons/issues/2476

 

In the mean time you can create an OSGi service and set the run mode config value in OSGi configuration and read it in your code. That should resolve the issue.

Here is an article which will give a good idea:

https://cqdump.joerghoh.de/2018/09/12/referencing-runmodes-in-java/

 

Thanks!

snbaem
Community Advisor
Community Advisor

Hello,

 

Please check https://medium.com/adobetech/custom-runmodes-on-aem-as-a-cloud-service-79b757f51a6b for custom runmodes (not to be used or used cautiously) which discusses about some good practices.

It seems to provide an example of refactored code.

From the reference above, we can try this

@Property(label = "Environment Type",
        description = "Should be dev/stage/prod/local - default is local")
private static final String ENVIRONMENT_TYPE = "environment.type";
private String environmentType;

@Activate
@Modified
protected void activate(final Map<String, String> config) {
    environmentType = PropertiesUtil.toString(config.get(ENVIRONMENT_TYPE), DEFAULT_ENVIRONMENT_TYPE);
    log.debug("Environment Type Service Activated with Environment Type of {}", environmentType);
}



public String getEnvironmentType() {
    return environmentType;
}
Jörg_Hoh
Correct answer by
Employee
Employee

Not sure if this blog article has been specifically been written for you 🙂 But it adresses your question quite good:

 

https://blog.osoco.de/2021/07/the-truth-about-aem-run-modes/

 

 

View solution in original post