diff options
author | Denes Nemeth <denes.nemeth@nokia.com> | 2018-04-09 15:04:03 +0200 |
---|---|---|
committer | Denes Nemeth <denes.nemeth@nokia.com> | 2018-04-09 18:09:33 +0200 |
commit | a995e82e01a3315940051ca55133c9cb14eccc6b (patch) | |
tree | 60cfaba3195e70eee199c8ce78533397b18a1ca3 /nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java | |
parent | 21e822781382c89f125b030c6fe96eea2a5ad087 (diff) |
Fix container startup
Change-Id: I5e7f9fb4bc83b113b5d27c5cd26e19cdc42e2c57
Issue-ID: VFC-728
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Diffstat (limited to 'nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java')
-rw-r--r-- | nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java index 6296d4b2..ceb0335d 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java @@ -16,7 +16,12 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -28,6 +33,9 @@ import org.springframework.context.annotation.Profile; import org.springframework.context.event.ContextClosedEvent; import org.springframework.stereotype.Component; +import static java.util.concurrent.Executors.newCachedThreadPool; + +import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions; import static org.slf4j.LoggerFactory.getLogger; /** @@ -43,7 +51,7 @@ public class NokiaSvnfmApplication { * @param args arguments for the application (not used) */ public static void main(String[] args) { - SpringApplication.run(NokiaSvnfmApplication.class, args); + systemFunctions().newSpringApplication(NokiaSvnfmApplication.class).run(args); } /** @@ -55,19 +63,45 @@ public class NokiaSvnfmApplication { @Component @Profile("!test") public static class SelfRegistrationTrigger implements ApplicationListener<ApplicationReadyEvent> { + private final SelfRegistrationManager selfRegistrationManager; + private final JobManager jobManager; + /** + * Runs the registration process + */ + private ExecutorService executorService = newCachedThreadPool(); + @Autowired - private SelfRegistrationManager selfRegistrationManager; + SelfRegistrationTrigger(SelfRegistrationManager selfRegistrationManager, JobManager jobManager){ + this.jobManager = jobManager; + this.selfRegistrationManager = selfRegistrationManager; + } @Override public void onApplicationEvent(ApplicationReadyEvent contextRefreshedEvent) { - logger.info("Self registration started"); - try { - selfRegistrationManager.register(); - logger.info("Self registration finished"); - } catch (RuntimeException e) { - logger.error("Self registration failed", e); - throw e; - } + Callable<Boolean> singleRegistration = () -> { + logger.info("Self registration started"); + try { + selfRegistrationManager.register(); + logger.info("Self registration finished"); + } catch (RuntimeException e) { + logger.error("Self registration failed", e); + throw e; + } + return true; + }; + executorService.submit(() -> { + while(!jobManager.isPreparingForShutDown()){ + try{ + executorService.submit(singleRegistration).get(); + //registration successful + return; + } + catch (Exception e){ + logger.warn("Unable to execute self registration process", e); + } + systemFunctions().sleep(5000); + } + }); } } @@ -79,10 +113,14 @@ public class NokiaSvnfmApplication { @Component @Profile("!test") public static class SelfDeRegistrationTrigger implements ApplicationListener<ContextClosedEvent> { + private final SelfRegistrationManager selfRegistrationManager; + private final JobManager jobManager; + @Autowired - private SelfRegistrationManager selfRegistrationManager; - @Autowired - private JobManager jobManager; + SelfDeRegistrationTrigger(SelfRegistrationManager selfRegistrationManager, JobManager jobManager){ + this.jobManager = jobManager; + this.selfRegistrationManager = selfRegistrationManager; + } @Override public void onApplicationEvent(ContextClosedEvent contextClosedEvent) { |