Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Run mode specific OSGI configuration issue

Avatar

Level 2

Hi Everyone,

I have a requirement where we need to create a service which creates OSGI configuration and also reads it and send it sightly for further processing.

For this I have created an interface with a method and implementation class of that interface.

I have declared a properties with initial values in the implementation which are configurable.

@Property(

label="my first property", description="my first property", value="my value1"

)

private static final String FIRST_PROPERTY = "first.property";

@Property(

label="my second property", description="my second property", value="my value2"

)

private static final String SECOND_PROPERTY = "second.property";

In the activate method, I am retrieving the values to local (private) variables using componentContent

@Activate

@Modified

Protected void activate(final ComponentContext componentContext){

private String myVal1 = PropertiesUtil.toString(componentContext.getProperties().get( FIRST_PROPERTY),"");

------

}

It is working fine and able to retrieve the values without issues. However when i create a run mode specific file (local, preprod and prod) and any changes to these run mode files are not reflecting.

Can anyone please adivse me on that

Thanks,

Sak

4 Replies

Avatar

Community Advisor

Hi,

There are few thing keep in mind when you create repository based config.

1. Changes are applied as soon as the node is updated by restarting the service (as with changes made in the Web console).

2. If you'll update the changes from web console , repository based config will be changed to flat file inside repository, and will be required changes from web console only.

3. On modification, repository changes won't be reflect, you need to restart service. or you can read osgi config directly inside sightly whenever component is loaded means read repo based config whenever it is used.

4. check run mode http://localhost:4502/system/console/status-slingsettings

E.g.

public String getOsgiData() {

pid ="org.apache.sling.commons.log.LogManager.factory.config.5451fd43-b723-4265-8ea8-5856a58b32ee"; 

String msg = "Log level details not available, Please check " + pid + " configMGR";

  Configuration conf = null;

  propsSize = 0;

  try {

  conf = configAdmin.getConfiguration(pid);

  Dictionary<String, Object> props = conf.getProperties();

  propsSize = props.size();

  /*

  * Enumeration<String> e = props.keys();

  * while (e.hasMoreElements()) {

  * String k = e.nextElement(); log.info(k + ": " + props.get(k));

  * }

  */

  if (propsSize > 0) {

  msg = "Log Lvel is : ";

  msg += (String) props.get("org.apache.sling.commons.log.level");

  }

  } catch (Exception e1) {

  // TODO Auto-generated catch block

  e1.printStackTrace();

  }

  return msg;

  }

runmode config works for me, I can see the value from correct config in Sightly.

Thanks

Arun



Arun Patidar

Avatar

Level 2

Hi Arun,

Thank your for your quick response.

It is still little confusing. I have couple of observations/questions.

a. I created run mode specific configuration file under 'config' with some values. However when i update any property here thats not reflecting in neither console nor in sightly code.

b. you have mentioned  here that If we modify the configuration from web console, it will create a flat file. I did modify the file initially. Is there a way we can identify and delete that flat file?

Thanks,

Sak

Avatar

Community Advisor

Hi Sak,

a. You need to restart service after updating value in repository based config.

b. Yes you can delete that you can find those config under /apps/system/config or inside your /apps/yourApp/config

Thanks

Arun



Arun Patidar

Avatar

Level 3

There is a possibility that you have configured the service configuration in OSGi console before making any run mode specific config file and the configuration is stored under '/apps/system/config'. Because '/apps/system/config' has precedence over '/apps/project/config', the configuration value is always picked from '/apps/system/config'. So, I would suggest you to check '/apps/system/config' path and if the configuration exists there for your service, delete it.