Detect instance runmode programmatically in AEM as cloud service | Community
Skip to main content
rampai
Level 1
Aug 11, 2021 3:42 PM UTC
Solved

Detect instance runmode programmatically in AEM as cloud service

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
joerghoh
joerghohAccepted solution
Employee
Aug 16, 2021 3:14 PM UTC

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/

 

 

3 replies

joerghoh
joerghohAccepted solution
Employee
Aug 16, 2021 3:14 PM UTC

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/

 

 

Translate
Shubham_borole
New Participant
Aug 11, 2021 4:43 PM UTC

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;
}
Translate
Asutosh_Jena_
New Participant
Aug 11, 2021 4:01 PM UTC

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!

Translate