diff --git a/cloud.startup.hook/src/main/java/de/valtech/aecu/startuphook/AecuCloudStartupService.java b/cloud.startup.hook/src/main/java/de/valtech/aecu/startuphook/AecuCloudStartupService.java index a8a3e5c4..67713677 100644 --- a/cloud.startup.hook/src/main/java/de/valtech/aecu/startuphook/AecuCloudStartupService.java +++ b/cloud.startup.hook/src/main/java/de/valtech/aecu/startuphook/AecuCloudStartupService.java @@ -29,6 +29,7 @@ import javax.jcr.Session; import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.event.jobs.JobManager; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.service.component.annotations.Activate; @@ -67,6 +68,9 @@ public class AecuCloudStartupService { @Reference private ServiceComponentRuntime serviceComponentRuntime; + @Reference + private JobManager jobManager; + private BundleContext bundleContext; @Activate @@ -170,13 +174,7 @@ private boolean servicesAreOk() { * Starts the AECU migration */ void startAecuMigration() { - try { - LOGGER.info("AECU migration started"); - aecuService.executeWithInstallHookHistory(AecuService.AECU_APPS_PATH_PREFIX); - LOGGER.info("AECU migration finished"); - } catch (AecuException ae) { - LOGGER.error("Error while executing AECU migration", ae); - } + jobManager.addJob(AecuStartupJobConsumer.JOB_TOPIC, null); } /** diff --git a/cloud.startup.hook/src/main/java/de/valtech/aecu/startuphook/AecuStartupJobConsumer.java b/cloud.startup.hook/src/main/java/de/valtech/aecu/startuphook/AecuStartupJobConsumer.java new file mode 100644 index 00000000..47bf3235 --- /dev/null +++ b/cloud.startup.hook/src/main/java/de/valtech/aecu/startuphook/AecuStartupJobConsumer.java @@ -0,0 +1,41 @@ +package de.valtech.aecu.startuphook; + +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import de.valtech.aecu.api.service.AecuException; +import de.valtech.aecu.api.service.AecuService; +import de.valtech.aecu.api.service.HistoryEntry; + +import org.apache.sling.event.jobs.Job; +import org.apache.sling.event.jobs.consumer.JobConsumer; + + +@Component(service=JobConsumer.class, property= { + JobConsumer.PROPERTY_TOPICS + "=" + AecuStartupJobConsumer.JOB_TOPIC +}) +public class AecuStartupJobConsumer implements JobConsumer { + + protected static final String JOB_TOPIC = "de/valtech/aecu/cloud/AecuStartupJobTopic"; + + private static final Logger LOGGER = LoggerFactory.getLogger(AecuStartupJobConsumer.class); + + @Reference + private AecuService aecuService; + + + public JobResult process(final Job job) { + try { + LOGGER.info("AECU migration started"); + HistoryEntry result = aecuService.executeWithInstallHookHistory(AecuService.AECU_APPS_PATH_PREFIX); + LOGGER.info("AECU migration finished with result "+result.getResult()); + return JobResult.OK; + } catch (AecuException ae) { + LOGGER.error("Error while executing AECU migration", ae); + // Do not retry job, hence status CANCEL (=failed permanently) and not FAILED (=can be retried) + return JobResult.CANCEL; + } + } +} \ No newline at end of file diff --git a/complete-cloud/src/main/content/jcr_root/apps/valtech/aecu-complete/config/org.apache.sling.event.jobs.QueueConfiguration~aecu-startup-hook-job-consumer.xml b/complete-cloud/src/main/content/jcr_root/apps/valtech/aecu-complete/config/org.apache.sling.event.jobs.QueueConfiguration~aecu-startup-hook-job-consumer.xml new file mode 100644 index 00000000..8573f631 --- /dev/null +++ b/complete-cloud/src/main/content/jcr_root/apps/valtech/aecu-complete/config/org.apache.sling.event.jobs.QueueConfiguration~aecu-startup-hook-job-consumer.xml @@ -0,0 +1,10 @@ + + \ No newline at end of file