Run modes in AEM
Run modes allow you to configure AEM instances for specific purpose.
Two types of run modes in AEM-
1. Standard Run modes: Run modes provided by AEM. They cannot be changed once AEM instance is installed. Mainly they are Author and Publish.
2. Custom Run modes: Along with standard run modes we can add our custom run modes. Custom run modes can be environment specific. Mainly they are development, QA, staging and production. They can be changed on every instance re-start.
Examples :
1. author, dev
2. publish, test
Problem:: How to check active run mode of AEM instance?
Solution::
Step 1 - Goto http://localhost:4502/aem/start.html
Step 2 - Goto Tools section.
Step 3 - Goto Operation and then System Overview as below screenshot.
Problem:: How to utilize these run modes in AEM development?
Solution::
We can utilize these run modes to do any development specific to particular run mode.
Ways to utilize-
1. By creating environment specific configurations. Example:: config.author, config.author.dev etc.
2. By creating environment specific install folders for bundles. Example:: install.author, install.publish, install.author.dev etc.
3. By creating environment specific mapping folders for resource resolution. Example:: map.dev.publish, map.uat.publish etc.
Use SlingSettingsService OSGi service to get the run modes in Java-
1. To get active run mode in Sling model::
import java.util.Set;
import javax.annotation.PostConstruct;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import org.apache.sling.settings.SlingSettingsService;
@Model(adaptables=Resource.class)
public class CustomSlingModel {
@OSGiService
private SlingSettingsService slingservice;
private String mode;
public String getMode() {
return mode;
}
@PostConstruct
protected void init(){
Set<String> modes = slingservice.getRunModes();
mode = modes.contains("author") ? "author" : "publish";
}
}
import java.util.Set;
import org.apache.sling.settings.SlingSettingsService;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.customproject.core.services.SimpleService;
@Component(service = SimpleService.class, immediate=true)
public class SimpleServiceImpl implements SimpleService{
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
@Reference
SlingSettingsService slingSettingService;
@Override
public void doSimpleService(){
//getting run modes
Set<String> runmodes = slingSettingService.getRunModes();
//printing runmodes
LOGGER.info("Runmodes::"+ runmodes);
}
}
Problem:: How to include clientlibs based on run mode.
Solution:: Use Sling model to get the active run mode and check for specific environment in active run mode. In Sightly use that sing model and do the conditional inclusion of clientlibs.
Comments
Post a Comment