OSGi config(Environment variable) not picked up in cloud
Hi Community,
I have a simple service with an OSGi config. After deploying, the service always uses defaults what I have in code - not picking from the environment valiables.
Here is my code
package com.acme.core.schedulers;
import org.apache.sling.commons.scheduler.Scheduler;
import org.osgi.service.component.annotations.*;
import org.osgi.service.metatype.annotations.*;
@8220494(service = Runnable.class, immediate = true)
@Designate(ocd = ACLCleanpSchedulerConfig.class) // not a factory
public class ACLCleanpScheduler implements Runnable {
@ObjectClassDefinition(name = "Acme - ACL Cleanp Scheduler")
public @interface ACLCleanpSchedulerConfig {
@AttributeDefinition(name="Enabled")
boolean enabled() default false;
@AttributeDefinition(name="Cron")
String cron() default "0/10 * * * * ?";
@AttributeDefinition(name="Base Path")
String base_path() default "/content/dam";
}
@3214626 private Scheduler scheduler;
private volatile ACLCleanpSchedulerConfig cfg;
@580286 @9182423
protected void activate(ACLCleanpSchedulerConfig cfg) throws Exception {
this.cfg = cfg;
scheduler.unschedule("acme-aclcleanp");
if (cfg.enabled()) {
scheduler.schedule(this, scheduler.EXPR(cfg.cron()), true);
}
}
@3038739
protected void deactivate() throws Exception {
scheduler.unschedule("acme-aclcleanp");
}
@9944223 public void run() {
// cleanup work using cfg.base_path()
}
}
/apps/acme/osgiconfig/config/com.acme.core.schedulers.ACLCleanpScheduler.cfg.json
{
"enabled":"$[env:ACL_ENABLED;default=false]",
"cron": "$[env:ACL_CRON;default=0/50 * * * * ?]",
"base_path": "$[env:ACL_BASE_PATH;default=/content/dam/]"
}
Note: I have set the environment variables on the configurations already.
